Changed up the layout
Now both sliders return color events
Made the luminosity/intensity square actually represent what will be selected
Added the ability for hue/lim/int listeners to check if the event was generated by tapping, or by setting the value.
This commit is contained in:
artdeell 2022-04-19 23:05:01 +03:00
parent d1a7fd11e0
commit 8590786d1f
8 changed files with 71 additions and 34 deletions

View File

@ -47,6 +47,7 @@ import net.kdt.pojavlaunch.authenticator.mojang.InvalidateTokenTask;
import net.kdt.pojavlaunch.authenticator.mojang.LoginListener; import net.kdt.pojavlaunch.authenticator.mojang.LoginListener;
import net.kdt.pojavlaunch.authenticator.mojang.LoginTask; import net.kdt.pojavlaunch.authenticator.mojang.LoginTask;
import net.kdt.pojavlaunch.authenticator.mojang.RefreshListener; import net.kdt.pojavlaunch.authenticator.mojang.RefreshListener;
import net.kdt.pojavlaunch.colorselector.ColorSelector;
import net.kdt.pojavlaunch.customcontrols.CustomControls; import net.kdt.pojavlaunch.customcontrols.CustomControls;
import net.kdt.pojavlaunch.multirt.MultiRTConfigDialog; import net.kdt.pojavlaunch.multirt.MultiRTConfigDialog;
import net.kdt.pojavlaunch.multirt.MultiRTUtils; import net.kdt.pojavlaunch.multirt.MultiRTUtils;

View File

@ -0,0 +1,5 @@
package net.kdt.pojavlaunch.colorselector;
public interface ColorSelectionListener {
void onColorSelected(int color);
}

View File

@ -3,16 +3,20 @@ package net.kdt.pojavlaunch.colorselector;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.content.Context; import android.content.Context;
import android.graphics.Color; import android.graphics.Color;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.widget.EditText;
import android.widget.TextView; import android.widget.TextView;
import net.kdt.pojavlaunch.R; import net.kdt.pojavlaunch.R;
public class ColorSelector implements HueSelectionListener, RectangleSelectionListener { public class ColorSelector implements HueSelectionListener, RectangleSelectionListener{
HueView mHueView; HueView mHueView;
SVRectangleView mLuminosityIntensityView; SVRectangleView mLuminosityIntensityView;
TextView mTextView; EditText mTextView;
ColorSelectionListener mColorSelectionListener;
float[] mHueTemplate = new float[] {0,1,1}; float[] mHueTemplate = new float[] {0,1,1};
float[] mHsvSelected = new float[] {360,1,1}; float[] mHsvSelected = new float[] {360,1,1};
AlertDialog mDialog; AlertDialog mDialog;
@ -23,7 +27,11 @@ public class ColorSelector implements HueSelectionListener, RectangleSelectionLi
mHueView.setHueSelectionListener(this); mHueView.setHueSelectionListener(this);
mLuminosityIntensityView = view.findViewById(R.id.color_selector_rectangle_view); mLuminosityIntensityView = view.findViewById(R.id.color_selector_rectangle_view);
mLuminosityIntensityView.setRectSelectionListener(this); mLuminosityIntensityView.setRectSelectionListener(this);
mTextView = view.findViewById(R.id.color_selector_color_text_view); mLuminosityIntensityView.setLuminosityIntensity(1,1);
mTextView = view.findViewById(R.id.color_selector_hex_edit);
mColorSelectionListener = (color)->{
mTextView.setTextColor(color);
};
bldr.setView(view); bldr.setView(view);
mDialog = bldr.create(); mDialog = bldr.create();
} }
@ -33,16 +41,20 @@ public class ColorSelector implements HueSelectionListener, RectangleSelectionLi
} }
@Override @Override
public void onHueSelected(float hue) { public void onHueSelected(float hue, boolean tapping) {
mHueTemplate[0] = hue; mHsvSelected[0] = mHueTemplate[0] = hue;
mLuminosityIntensityView.setColor(Color.HSVToColor(mHueTemplate)); mLuminosityIntensityView.setColor(Color.HSVToColor(mHueTemplate));
dispatchColorChange(Color.HSVToColor(mHsvSelected),tapping);
} }
@Override @Override
public void onLuminosityIntensityChanged(float luminosity, float intensity) { public void onLuminosityIntensityChanged(float luminosity, float intensity, boolean tapping) {
mHsvSelected[0] = mHueTemplate[0]; mHsvSelected[1] = intensity;
mHsvSelected[1] = (intensity -1)*-1 ;
mHsvSelected[2] = luminosity; mHsvSelected[2] = luminosity;
mTextView.setTextColor(Color.HSVToColor(mHsvSelected)); dispatchColorChange(Color.HSVToColor(mHsvSelected),tapping);
}
protected void dispatchColorChange(int color, boolean tapping) {
if(mColorSelectionListener != null) mColorSelectionListener.onColorSelected(Color.HSVToColor(mHsvSelected));
} }
} }

View File

@ -1,5 +1,5 @@
package net.kdt.pojavlaunch.colorselector; package net.kdt.pojavlaunch.colorselector;
public interface HueSelectionListener { public interface HueSelectionListener {
void onHueSelected(float hue); void onHueSelected(float hue, boolean tappng);
} }

View File

@ -34,13 +34,18 @@ public class HueView extends View {
public void setHueSelectionListener(HueSelectionListener listener) { public void setHueSelectionListener(HueSelectionListener listener) {
mHueSelectionListener = listener; mHueSelectionListener = listener;
} }
public void setHue(float hue) {
mSelectionHue = hue;
if(mHueSelectionListener != null) mHueSelectionListener.onHueSelected(mSelectionHue, false);
invalidate();
}
@SuppressLint("ClickableViewAccessibility") @SuppressLint("ClickableViewAccessibility")
@Override @Override
public boolean onTouchEvent(MotionEvent event) { public boolean onTouchEvent(MotionEvent event) {
mSelectionHue = event.getX() * mWidthHueRatio; mSelectionHue = event.getX() * mWidthHueRatio;
invalidate(); invalidate();
if(mHueSelectionListener != null) mHueSelectionListener.onHueSelected(mSelectionHue); if(mHueSelectionListener != null) mHueSelectionListener.onHueSelected(mSelectionHue, true);
return true; return true;
} }

View File

@ -1,5 +1,5 @@
package net.kdt.pojavlaunch.colorselector; package net.kdt.pojavlaunch.colorselector;
public interface RectangleSelectionListener { public interface RectangleSelectionListener {
void onLuminosityIntensityChanged(float luminosity, float intensity); void onLuminosityIntensityChanged(float luminosity, float intensity, boolean tapping);
} }

View File

@ -5,8 +5,10 @@ import android.content.Context;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.LinearGradient;
import android.graphics.Paint; import android.graphics.Paint;
import android.graphics.RectF; import android.graphics.RectF;
import android.graphics.Shader;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
@ -49,11 +51,18 @@ public class SVRectangleView extends View {
if(mFingerPosY < 0) mFingerPosY = 0; if(mFingerPosY < 0) mFingerPosY = 0;
else if(mFingerPosY > 1) mFingerPosY = 1; else if(mFingerPosY > 1) mFingerPosY = 1;
if(mRectSeelctionListener != null) mRectSeelctionListener.onLuminosityIntensityChanged(mFingerPosY,mFingerPosX); if(mRectSeelctionListener != null) mRectSeelctionListener.onLuminosityIntensityChanged(mFingerPosY,mFingerPosX, true);
invalidate(); invalidate();
return true; return true;
} }
public void setLuminosityIntensity(float luminosity, float intensity) {
mFingerPosX = intensity;
mFingerPosY = luminosity;
if(mRectSeelctionListener != null) mRectSeelctionListener.onLuminosityIntensityChanged(mFingerPosY,mFingerPosX, false);
invalidate();
}
public void setColor(int color) { public void setColor(int color) {
mColorPaint.setColor(color); mColorPaint.setColor(color);
invalidate(); invalidate();
@ -62,7 +71,6 @@ public class SVRectangleView extends View {
public void setRectSelectionListener(RectangleSelectionListener listener) { public void setRectSelectionListener(RectangleSelectionListener listener) {
mRectSeelctionListener = listener; mRectSeelctionListener = listener;
} }
protected void drawCrosshair(Canvas canvas, float x, float y) { protected void drawCrosshair(Canvas canvas, float x, float y) {
canvas.drawLine(mCrosshairSize * 2 + x, y, mCrosshairSize + x, y, mCrosshairPaint); canvas.drawLine(mCrosshairSize * 2 + x, y, mCrosshairSize + x, y, mCrosshairPaint);
canvas.drawLine(x - mCrosshairSize * 2, y, x - mCrosshairSize, y, mCrosshairPaint); canvas.drawLine(x - mCrosshairSize * 2, y, x - mCrosshairSize, y, mCrosshairPaint);
@ -94,13 +102,14 @@ public class SVRectangleView extends View {
if(mSvRectangle != null) if(mSvRectangle != null)
mSvRectangle.recycle(); mSvRectangle.recycle();
mSvRectangle = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); mSvRectangle = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
float intensityRatio = 255f / h; Paint rectPaint = new Paint();
float luminosityRatio = 255f / w; Canvas canvas = new Canvas(mSvRectangle);
for(int x = 0; x < w; x++) { float h2f = h/2f;
for(int y = 0; y < h; y++) { float w2f = w/2f;
int intensity = (int)(y * intensityRatio); rectPaint.setShader(new LinearGradient(0,h2f, w, h2f, Color.WHITE,0, Shader.TileMode.CLAMP));
mSvRectangle.setPixel(x,y,Color.argb((int)(x * luminosityRatio), intensity, intensity, intensity)); canvas.drawRect(mViewSize, rectPaint);
} rectPaint.setShader(new LinearGradient(w2f,0, w2f, h, Color.BLACK,0, Shader.TileMode.CLAMP));
} canvas.drawRect(mViewSize, rectPaint);
} }
} }

View File

@ -3,18 +3,19 @@
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="match_parent">
<net.kdt.pojavlaunch.colorselector.HueView <net.kdt.pojavlaunch.colorselector.HueView
android:id="@+id/color_selector_hue_view" android:id="@+id/color_selector_hue_view"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="55dp" android:layout_height="40dp"
android:layout_marginStart="8dp" android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp" android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp" android:focusable="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" /> app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/color_selector_rectangle_view" />
<net.kdt.pojavlaunch.colorselector.SVRectangleView <net.kdt.pojavlaunch.colorselector.SVRectangleView
android:id="@+id/color_selector_rectangle_view" android:id="@+id/color_selector_rectangle_view"
@ -23,17 +24,21 @@
android:layout_marginStart="8dp" android:layout_marginStart="8dp"
android:layout_marginTop="8dp" android:layout_marginTop="8dp"
android:layout_marginEnd="8dp" android:layout_marginEnd="8dp"
app:layout_constraintBottom_toTopOf="@+id/color_selector_color_text_view" android:focusable="true"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
<TextView <EditText
android:id="@+id/color_selector_color_text_view" android:id="@+id/color_selector_hex_edit"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="8dp" android:layout_marginStart="8dp"
android:text="TextView" android:layout_marginTop="8dp"
app:layout_constraintBottom_toTopOf="@+id/color_selector_hue_view" android:digits="0123456789ABCDEF"
app:layout_constraintStart_toStartOf="@+id/color_selector_hue_view" /> android:ems="10"
android:inputType="textPersonName|textCapCharacters"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/color_selector_hue_view" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>