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.LoginTask;
import net.kdt.pojavlaunch.authenticator.mojang.RefreshListener;
import net.kdt.pojavlaunch.colorselector.ColorSelector;
import net.kdt.pojavlaunch.customcontrols.CustomControls;
import net.kdt.pojavlaunch.multirt.MultiRTConfigDialog;
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.content.Context;
import android.graphics.Color;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import net.kdt.pojavlaunch.R;
public class ColorSelector implements HueSelectionListener, RectangleSelectionListener {
public class ColorSelector implements HueSelectionListener, RectangleSelectionListener{
HueView mHueView;
SVRectangleView mLuminosityIntensityView;
TextView mTextView;
EditText mTextView;
ColorSelectionListener mColorSelectionListener;
float[] mHueTemplate = new float[] {0,1,1};
float[] mHsvSelected = new float[] {360,1,1};
AlertDialog mDialog;
@ -23,7 +27,11 @@ public class ColorSelector implements HueSelectionListener, RectangleSelectionLi
mHueView.setHueSelectionListener(this);
mLuminosityIntensityView = view.findViewById(R.id.color_selector_rectangle_view);
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);
mDialog = bldr.create();
}
@ -33,16 +41,20 @@ public class ColorSelector implements HueSelectionListener, RectangleSelectionLi
}
@Override
public void onHueSelected(float hue) {
mHueTemplate[0] = hue;
public void onHueSelected(float hue, boolean tapping) {
mHsvSelected[0] = mHueTemplate[0] = hue;
mLuminosityIntensityView.setColor(Color.HSVToColor(mHueTemplate));
dispatchColorChange(Color.HSVToColor(mHsvSelected),tapping);
}
@Override
public void onLuminosityIntensityChanged(float luminosity, float intensity) {
mHsvSelected[0] = mHueTemplate[0];
mHsvSelected[1] = (intensity -1)*-1 ;
public void onLuminosityIntensityChanged(float luminosity, float intensity, boolean tapping) {
mHsvSelected[1] = intensity;
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;
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) {
mHueSelectionListener = listener;
}
public void setHue(float hue) {
mSelectionHue = hue;
if(mHueSelectionListener != null) mHueSelectionListener.onHueSelected(mSelectionHue, false);
invalidate();
}
@SuppressLint("ClickableViewAccessibility")
@Override
public boolean onTouchEvent(MotionEvent event) {
mSelectionHue = event.getX() * mWidthHueRatio;
invalidate();
if(mHueSelectionListener != null) mHueSelectionListener.onHueSelected(mSelectionHue);
if(mHueSelectionListener != null) mHueSelectionListener.onHueSelected(mSelectionHue, true);
return true;
}

View File

@ -1,5 +1,5 @@
package net.kdt.pojavlaunch.colorselector;
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.Canvas;
import android.graphics.Color;
import android.graphics.LinearGradient;
import android.graphics.Paint;
import android.graphics.RectF;
import android.graphics.Shader;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
@ -49,11 +51,18 @@ public class SVRectangleView extends View {
if(mFingerPosY < 0) mFingerPosY = 0;
else if(mFingerPosY > 1) mFingerPosY = 1;
if(mRectSeelctionListener != null) mRectSeelctionListener.onLuminosityIntensityChanged(mFingerPosY,mFingerPosX);
if(mRectSeelctionListener != null) mRectSeelctionListener.onLuminosityIntensityChanged(mFingerPosY,mFingerPosX, true);
invalidate();
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) {
mColorPaint.setColor(color);
invalidate();
@ -62,7 +71,6 @@ public class SVRectangleView extends View {
public void setRectSelectionListener(RectangleSelectionListener listener) {
mRectSeelctionListener = listener;
}
protected void drawCrosshair(Canvas canvas, float x, float y) {
canvas.drawLine(mCrosshairSize * 2 + x, y, mCrosshairSize + x, y, mCrosshairPaint);
canvas.drawLine(x - mCrosshairSize * 2, y, x - mCrosshairSize, y, mCrosshairPaint);
@ -94,13 +102,14 @@ public class SVRectangleView extends View {
if(mSvRectangle != null)
mSvRectangle.recycle();
mSvRectangle = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
float intensityRatio = 255f / h;
float luminosityRatio = 255f / w;
for(int x = 0; x < w; x++) {
for(int y = 0; y < h; y++) {
int intensity = (int)(y * intensityRatio);
mSvRectangle.setPixel(x,y,Color.argb((int)(x * luminosityRatio), intensity, intensity, intensity));
}
}
Paint rectPaint = new Paint();
Canvas canvas = new Canvas(mSvRectangle);
float h2f = h/2f;
float w2f = w/2f;
rectPaint.setShader(new LinearGradient(0,h2f, w, h2f, Color.WHITE,0, Shader.TileMode.CLAMP));
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:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="match_parent">
<net.kdt.pojavlaunch.colorselector.HueView
android:id="@+id/color_selector_hue_view"
android:layout_width="0dp"
android:layout_height="55dp"
android:layout_height="40dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
android:focusable="true"
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
android:id="@+id/color_selector_rectangle_view"
@ -23,17 +24,21 @@
android:layout_marginStart="8dp"
android:layout_marginTop="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_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/color_selector_color_text_view"
<EditText
android:id="@+id/color_selector_hex_edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:text="TextView"
app:layout_constraintBottom_toTopOf="@+id/color_selector_hue_view"
app:layout_constraintStart_toStartOf="@+id/color_selector_hue_view" />
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:digits="0123456789ABCDEF"
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>