diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/colorselector/AlphaSelectionListener.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/colorselector/AlphaSelectionListener.java new file mode 100644 index 000000000..a61055980 --- /dev/null +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/colorselector/AlphaSelectionListener.java @@ -0,0 +1,5 @@ +package net.kdt.pojavlaunch.colorselector; + +public interface AlphaSelectionListener { + void onAlphaSelected(int alpha, boolean tapping); +} diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/colorselector/AlphaView.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/colorselector/AlphaView.java new file mode 100644 index 000000000..0a085f855 --- /dev/null +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/colorselector/AlphaView.java @@ -0,0 +1,72 @@ +package net.kdt.pojavlaunch.colorselector; + +import android.annotation.SuppressLint; +import android.content.Context; +import android.graphics.Canvas; +import android.graphics.Color; +import android.graphics.LinearGradient; +import android.graphics.Paint; +import android.graphics.RectF; +import android.graphics.Shader; +import android.graphics.drawable.Drawable; +import android.util.AttributeSet; +import android.util.Log; +import android.view.MotionEvent; +import android.view.View; + +import net.kdt.pojavlaunch.Tools; + +import top.defaults.checkerboarddrawable.CheckerboardDrawable; + +public class AlphaView extends View { + Drawable mCheckerboardDrawable = CheckerboardDrawable.create(); + Paint mShaderPaint = new Paint(); + Paint mBlackPaint; + RectF mViewSize = new RectF(0,0,0,0); + AlphaSelectionListener mAlphaSelectionListener; + int mSelectedAlpha; + float mAlphaDiv; // for quick pos->alpha multiplication + float mScreenDiv; // for quick alpha->pos multiplication + float mHeightThird; // 1/3 of the view size for cursor + public AlphaView(Context ctx, AttributeSet attrs) { + super(ctx,attrs); + mBlackPaint = new Paint(); + mBlackPaint.setStrokeWidth(Tools.dpToPx(3)); + mBlackPaint.setColor(Color.BLACK); + } + + public void setAlpha(int alpha) { + if(mAlphaSelectionListener != null) mAlphaSelectionListener.onAlphaSelected(mSelectedAlpha,false); + } + + @SuppressLint("ClickableViewAccessibility") + @Override + public boolean onTouchEvent(MotionEvent event) { + mSelectedAlpha = (int) (mAlphaDiv * event.getX()); + if(mAlphaSelectionListener != null) mAlphaSelectionListener.onAlphaSelected(mSelectedAlpha,true); + invalidate(); + return true; + } + + @Override + protected void onSizeChanged(int w, int h, int oldw, int oldh) { + mViewSize.right = w; + mViewSize.bottom = h; + float h2 = mViewSize.bottom / 2f; + mShaderPaint.setShader(new LinearGradient(0,h2,w,h2, Color.BLACK, 0, Shader.TileMode.REPEAT)); + mAlphaDiv = 255f / mViewSize.right; + mScreenDiv = mViewSize.right / 255f; + mHeightThird = mViewSize.bottom / 3f; + } + + @Override + protected void onDraw(Canvas canvas) { + Log.i("onDraw","onDraw"); + mCheckerboardDrawable.draw(canvas); + canvas.drawRect(mViewSize, mShaderPaint); + float linePos = mSelectedAlpha * mScreenDiv; + Log.i("onDraw",linePos+""); + canvas.drawLine(linePos, 0 ,linePos, mHeightThird, mBlackPaint); + canvas.drawLine(linePos, mHeightThird * 2 ,linePos, mViewSize.bottom, mBlackPaint); + } +} diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/colorselector/ColorSelectionListener.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/colorselector/ColorSelectionListener.java deleted file mode 100644 index d97e0e328..000000000 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/colorselector/ColorSelectionListener.java +++ /dev/null @@ -1,5 +0,0 @@ -package net.kdt.pojavlaunch.colorselector; - -public interface ColorSelectionListener { - void onColorSelected(int color); -} diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/colorselector/ColorSelector.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/colorselector/ColorSelector.java index 24d363302..09a5f9c5e 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/colorselector/ColorSelector.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/colorselector/ColorSelector.java @@ -12,11 +12,10 @@ import android.widget.TextView; import net.kdt.pojavlaunch.R; -public class ColorSelector implements HueSelectionListener, RectangleSelectionListener{ +public class ColorSelector implements HueSelectionListener, RectangleSelectionListener, AlphaSelectionListener{ HueView mHueView; SVRectangleView mLuminosityIntensityView; EditText mTextView; - ColorSelectionListener mColorSelectionListener; float[] mHueTemplate = new float[] {0,1,1}; float[] mHsvSelected = new float[] {360,1,1}; AlertDialog mDialog; @@ -28,11 +27,11 @@ public class ColorSelector implements HueSelectionListener, RectangleSelectionLi mLuminosityIntensityView = view.findViewById(R.id.color_selector_rectangle_view); mLuminosityIntensityView.setRectSelectionListener(this); mLuminosityIntensityView.setLuminosityIntensity(1,1); - mTextView = view.findViewById(R.id.color_selector_hex_edit); - mColorSelectionListener = (color)->{ - mTextView.setTextColor(color); - }; + //mTextView = view.findViewById(R.id.color_selector_hex_edit); bldr.setView(view); + bldr.setPositiveButton(android.R.string.ok,(dialog,which)->{ + + }); mDialog = bldr.create(); } @@ -54,7 +53,12 @@ public class ColorSelector implements HueSelectionListener, RectangleSelectionLi dispatchColorChange(Color.HSVToColor(mHsvSelected),tapping); } + @Override + public void onAlphaSelected(int alpha, boolean tapping) { + + } + protected void dispatchColorChange(int color, boolean tapping) { - if(mColorSelectionListener != null) mColorSelectionListener.onColorSelected(Color.HSVToColor(mHsvSelected)); + } } diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/colorselector/HueView.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/colorselector/HueView.java index 1c6289a59..db5c92d26 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/colorselector/HueView.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/colorselector/HueView.java @@ -21,6 +21,7 @@ public class HueView extends View { Paint blackPaint = new Paint(); float mSelectionHue; float mWidthHueRatio; + float mHueWidthRatio; float mWidth; float mHeight; float mHeightThird; @@ -52,7 +53,7 @@ public class HueView extends View { @Override protected void onDraw(Canvas canvas) { canvas.drawBitmap(mGamma, 0, 0 ,null); - float linePos = mSelectionHue / mWidthHueRatio; + float linePos = mSelectionHue * mHueWidthRatio; canvas.drawLine(linePos, 0 ,linePos, mHeightThird, blackPaint); canvas.drawLine(linePos, mHeightThird * 2 ,linePos, mHeight, blackPaint); } @@ -72,7 +73,8 @@ public class HueView extends View { Paint paint = new Paint(); Canvas canvas = new Canvas(mGamma); mWidthHueRatio = 360/ mWidth; - float[] hsvFiller = new float[] {0,1,1}; + mHueWidthRatio = mWidth / 360; + float[] hsvFiller = new float[] {0, 1, 1}; for(float i = 0; i < mWidth; i++) { hsvFiller[0] = i * mWidthHueRatio; paint.setColor(Color.HSVToColor(hsvFiller)); diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/colorselector/SVRectangleView.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/colorselector/SVRectangleView.java index f7e5b661c..0256c0591 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/colorselector/SVRectangleView.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/colorselector/SVRectangleView.java @@ -82,9 +82,8 @@ public class SVRectangleView extends View { protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.drawRect(mViewSize, mColorPaint); - drawCrosshair(canvas, mViewSize.right * mFingerPosX, mViewSize.bottom * mFingerPosY); - if(mSvRectangle != null) canvas.drawBitmap(mSvRectangle, 0,0, null); + drawCrosshair(canvas, mViewSize.right * mFingerPosX, mViewSize.bottom * mFingerPosY); } @Override diff --git a/app_pojavlauncher/src/main/res/layout/dialog_color_selector.xml b/app_pojavlauncher/src/main/res/layout/dialog_color_selector.xml index 4ad04da77..0ca2433fc 100644 --- a/app_pojavlauncher/src/main/res/layout/dialog_color_selector.xml +++ b/app_pojavlauncher/src/main/res/layout/dialog_color_selector.xml @@ -1,14 +1,13 @@ -