Changes for Serpent

Added access modifiers (why :despair:)
Moved the cast
Added error reporting if the tex in the HEX edit box is not a valid HEX value (by making the text red)
This commit is contained in:
artdeell 2022-04-22 23:15:33 +03:00
parent cfae15c680
commit d78b396ea7
7 changed files with 59 additions and 54 deletions

View File

@ -18,15 +18,15 @@ import net.kdt.pojavlaunch.Tools;
import top.defaults.checkerboarddrawable.CheckerboardDrawable; import top.defaults.checkerboarddrawable.CheckerboardDrawable;
public class AlphaView extends View { public class AlphaView extends View {
Drawable mCheckerboardDrawable = CheckerboardDrawable.create(); private final Drawable mCheckerboardDrawable = CheckerboardDrawable.create();
Paint mShaderPaint = new Paint(); private final Paint mShaderPaint = new Paint();
Paint mBlackPaint; private final Paint mBlackPaint;
RectF mViewSize = new RectF(0,0,0,0); private final RectF mViewSize = new RectF(0,0,0,0);
AlphaSelectionListener mAlphaSelectionListener; private AlphaSelectionListener mAlphaSelectionListener;
int mSelectedAlpha; private int mSelectedAlpha;
float mAlphaDiv; // for quick pos->alpha multiplication private float mAlphaDiv; // for quick pos->alpha multiplication
float mScreenDiv; // for quick alpha->pos multiplication private float mScreenDiv; // for quick alpha->pos multiplication
float mHeightThird; // 1/3 of the view size for cursor private float mHeightThird; // 1/3 of the view size for cursor
public AlphaView(Context ctx, AttributeSet attrs) { public AlphaView(Context ctx, AttributeSet attrs) {
super(ctx,attrs); super(ctx,attrs);
mBlackPaint = new Paint(); mBlackPaint = new Paint();

View File

@ -2,6 +2,7 @@ package net.kdt.pojavlaunch.colorselector;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.content.Context; import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.Color; import android.graphics.Color;
import android.text.Editable; import android.text.Editable;
import android.text.TextWatcher; import android.text.TextWatcher;
@ -12,18 +13,20 @@ import android.widget.EditText;
import net.kdt.pojavlaunch.R; import net.kdt.pojavlaunch.R;
public class ColorSelector implements HueSelectionListener, RectangleSelectionListener, AlphaSelectionListener, TextWatcher{ public class ColorSelector implements HueSelectionListener, RectangleSelectionListener, AlphaSelectionListener, TextWatcher{
static final int ALPHA_MASK = ~(0xFF << 24); private static final int ALPHA_MASK = ~(0xFF << 24);
HueView mHueView; private final HueView mHueView;
SVRectangleView mLuminosityIntensityView; private final SVRectangleView mLuminosityIntensityView;
AlphaView mAlphaView; private final AlphaView mAlphaView;
ColorSideBySideView mColorView; private final ColorSideBySideView mColorView;
EditText mTextView; private final EditText mTextView;
ColorSelectionListener mColorSelectionListener; private final AlertDialog mDialog;
float[] mHueTemplate = new float[] {0,1,1}; private ColorSelectionListener mColorSelectionListener;
float[] mHsvSelected = new float[] {360,1,1}; private float[] mHueTemplate = new float[] {0,1,1};
int mAlphaSelected = 0xff; private float[] mHsvSelected = new float[] {360,1,1};
boolean mWatch = true; private int mAlphaSelected = 0xff;
AlertDialog mDialog; private ColorStateList mTextColors;
private boolean mWatch = true;
/** /**
* Creates a color selector dialog for this Context. * Creates a color selector dialog for this Context.
@ -43,6 +46,7 @@ public class ColorSelector implements HueSelectionListener, RectangleSelectionLi
mLuminosityIntensityView.setRectSelectionListener(this); mLuminosityIntensityView.setRectSelectionListener(this);
mAlphaView.setAlphaSelectionListener(this); mAlphaView.setAlphaSelectionListener(this);
mTextView.addTextChangedListener(this); mTextView.addTextChangedListener(this);
mTextColors = mTextView.getTextColors();
builder.setView(view); builder.setView(view);
builder.setPositiveButton(android.R.string.ok,(dialog,which)->{ builder.setPositiveButton(android.R.string.ok,(dialog,which)->{
if (mColorSelectionListener != null) { if (mColorSelectionListener != null) {
@ -134,8 +138,10 @@ public class ColorSelector implements HueSelectionListener, RectangleSelectionLi
if(mWatch) { if(mWatch) {
try { try {
int color = Integer.parseInt(s.toString(), 16); int color = Integer.parseInt(s.toString(), 16);
mTextView.setTextColor(mTextColors);
runColor(color); runColor(color);
}catch (NumberFormatException ignored) { }catch (NumberFormatException exception) {
mTextView.setTextColor(Color.RED);
} }
}else{ }else{
mWatch = true; mWatch = true;

View File

@ -11,13 +11,13 @@ import androidx.annotation.Nullable;
import top.defaults.checkerboarddrawable.CheckerboardDrawable; import top.defaults.checkerboarddrawable.CheckerboardDrawable;
public class ColorSideBySideView extends View { public class ColorSideBySideView extends View {
Paint mPaint; private final Paint mPaint;
CheckerboardDrawable mCheckerboardDrawable = CheckerboardDrawable.create(); private final CheckerboardDrawable mCheckerboardDrawable = CheckerboardDrawable.create();
int mColor; private int mColor;
int mAlphaColor; private int mAlphaColor;
float mWidth; private float mWidth;
float mHeight; private float mHeight;
float mHalfHeight; private float mHalfHeight;
public ColorSideBySideView(Context context, @Nullable AttributeSet attrs) { public ColorSideBySideView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs); super(context, attrs);
mPaint = new Paint(); mPaint = new Paint();

View File

@ -17,15 +17,15 @@ import net.kdt.pojavlaunch.Tools;
public class HueView extends View { public class HueView extends View {
Bitmap mGamma; private final Paint blackPaint = new Paint();
Paint blackPaint = new Paint(); private Bitmap mGamma;
float mSelectionHue; private HueSelectionListener mHueSelectionListener;
float mWidthHueRatio; private float mSelectionHue;
float mHueWidthRatio; private float mWidthHueRatio;
float mWidth; private float mHueWidthRatio;
float mHeight; private float mWidth;
float mHeightThird; private float mHeight;
HueSelectionListener mHueSelectionListener; private float mHeightThird;
public HueView(Context context, @Nullable AttributeSet attrs) { public HueView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs); super(context, attrs);
blackPaint.setColor(Color.BLACK); blackPaint.setColor(Color.BLACK);

View File

@ -18,15 +18,15 @@ import androidx.annotation.Nullable;
import net.kdt.pojavlaunch.Tools; import net.kdt.pojavlaunch.Tools;
public class SVRectangleView extends View { public class SVRectangleView extends View {
Bitmap mSvRectangle; private final Paint mColorPaint = new Paint();
Paint mColorPaint = new Paint(); private final Paint mPointerPaint = new Paint();
Paint mPointerPaint = new Paint(); private final float mPointerSize;
RectF mViewSize; private Bitmap mSvRectangle;
float mHeightInverted; private RectF mViewSize;
float mWidthInverted; private float mHeightInverted;
float mPointerSize; private float mWidthInverted;
float mFingerPosX; private float mFingerPosX;
float mFingerPosY; private float mFingerPosY;
RectangleSelectionListener mRectSelectionListener; RectangleSelectionListener mRectSelectionListener;
public SVRectangleView(Context context, @Nullable AttributeSet attrs) { public SVRectangleView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs); super(context, attrs);

View File

@ -176,8 +176,8 @@ public class EditControlButtonPopup {
mColorSelector = new ColorSelector(ctx,color -> mEditingView.setImageDrawable(new ColorDrawable(color))); mColorSelector = new ColorSelector(ctx,color -> mEditingView.setImageDrawable(new ColorDrawable(color)));
//Set color imageButton behavior //Set color imageButton behavior
mBackgroundColorButton.setOnClickListener(this::colorButtonHandler); mBackgroundColorButton.setOnClickListener(view -> showColorEditor((ImageView) view));
mStrokeColorButton.setOnClickListener(this::colorButtonHandler); mStrokeColorButton.setOnClickListener(view -> showColorEditor((ImageView) view));
//Set dialog buttons behavior //Set dialog buttons behavior
@ -190,8 +190,7 @@ public class EditControlButtonPopup {
setupCheckerboards(); setupCheckerboards();
} }
protected void colorButtonHandler(View view) { protected void showColorEditor(ImageView imgView) {
ImageView imgView = (ImageView) view;
mEditingView = imgView; mEditingView = imgView;
mColorSelector.show(((ColorDrawable)(imgView.getDrawable())).getColor()); mColorSelector.show(((ColorDrawable)(imgView.getDrawable())).getColor());
} }

View File

@ -46,12 +46,12 @@
android:layout_marginEnd="8dp" android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp" android:layout_marginBottom="8dp"
android:hint="@string/color_default_hex" android:hint="@string/color_default_hex"
android:inputType="number" android:importantForAutofill="no"
android:inputType="text"
android:minHeight="48dp" android:minHeight="48dp"
android:typeface="monospace" android:typeface="monospace"
app:layout_constraintBottom_toTopOf="@+id/color_selector_hue_view" app:layout_constraintBottom_toTopOf="@+id/color_selector_hue_view"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent" />
android:importantForAutofill="no"/>
<net.kdt.pojavlaunch.colorselector.ColorSideBySideView <net.kdt.pojavlaunch.colorselector.ColorSideBySideView
android:id="@+id/color_selector_color_view" android:id="@+id/color_selector_color_view"