mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2026-04-18 08:36:56 -04:00
Feat[color_selector]: rewrite to be a SideDialogView
This commit is contained in:
@@ -11,7 +11,6 @@ import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.animation.AccelerateDecelerateInterpolator;
|
||||
import android.view.animation.Interpolator;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
@@ -218,7 +217,7 @@ public abstract class SideDialogView {
|
||||
}
|
||||
|
||||
/** @return Whether the dialog is currently displaying */
|
||||
protected final boolean isDisplaying(){
|
||||
public final boolean isDisplaying(){
|
||||
return mDisplaying;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,76 +5,79 @@ import android.content.res.ColorStateList;
|
||||
import android.graphics.Color;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.EditText;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.kdt.SideDialogView;
|
||||
|
||||
import net.kdt.pojavlaunch.R;
|
||||
|
||||
public class ColorSelector implements HueSelectionListener, RectangleSelectionListener, AlphaSelectionListener, TextWatcher{
|
||||
public class ColorSelector extends SideDialogView implements HueSelectionListener, RectangleSelectionListener, AlphaSelectionListener, TextWatcher{
|
||||
private static final int ALPHA_MASK = ~(0xFF << 24);
|
||||
private final View mRootView;
|
||||
private final HueView mHueView;
|
||||
private final SVRectangleView mLuminosityIntensityView;
|
||||
private final AlphaView mAlphaView;
|
||||
private final ColorSideBySideView mColorView;
|
||||
private final EditText mTextView;
|
||||
private HueView mHueView;
|
||||
private SVRectangleView mLuminosityIntensityView;
|
||||
private AlphaView mAlphaView;
|
||||
private ColorSideBySideView mColorView;
|
||||
private EditText mTextView;
|
||||
|
||||
private ColorSelectionListener mColorSelectionListener;
|
||||
private final float[] mHueTemplate = new float[] {0,1,1};
|
||||
private final float[] mHsvSelected = new float[] {360,1,1};
|
||||
private int mAlphaSelected = 0xff;
|
||||
private final ColorStateList mTextColors;
|
||||
private ColorStateList mTextColors;
|
||||
private boolean mWatch = true;
|
||||
|
||||
private boolean mAlphaEnabled = true;
|
||||
|
||||
|
||||
/**
|
||||
* Creates a color selector dialog for this Context.
|
||||
* @param context Context used for this ColorSelector dialog
|
||||
* @param colorSelectionListener Color selection listener to which the events will be sent to. Can be null.
|
||||
*/
|
||||
public ColorSelector(Context context, ViewGroup parent, @Nullable ColorSelectionListener colorSelectionListener) {
|
||||
super(context, parent, R.layout.dialog_color_selector);
|
||||
mColorSelectionListener = colorSelectionListener;
|
||||
}
|
||||
|
||||
mRootView = LayoutInflater.from(context).inflate(R.layout.dialog_color_selector,parent, false);
|
||||
mHueView = mRootView.findViewById(R.id.color_selector_hue_view);
|
||||
mLuminosityIntensityView = mRootView.findViewById(R.id.color_selector_rectangle_view);
|
||||
mAlphaView = mRootView.findViewById(R.id.color_selector_alpha_view);
|
||||
mColorView = mRootView.findViewById(R.id.color_selector_color_view);
|
||||
mTextView = mRootView.findViewById(R.id.color_selector_hex_edit);
|
||||
@Override
|
||||
protected void onInflate() {
|
||||
super.onInflate();
|
||||
// Initialize the view contents
|
||||
mHueView = mDialogContent.findViewById(R.id.color_selector_hue_view);
|
||||
mLuminosityIntensityView = mDialogContent.findViewById(R.id.color_selector_rectangle_view);
|
||||
mAlphaView = mDialogContent.findViewById(R.id.color_selector_alpha_view);
|
||||
mColorView = mDialogContent.findViewById(R.id.color_selector_color_view);
|
||||
mTextView = mDialogContent.findViewById(R.id.color_selector_hex_edit);
|
||||
runColor(Color.RED);
|
||||
mHueView.setHueSelectionListener(this);
|
||||
mLuminosityIntensityView.setRectSelectionListener(this);
|
||||
mAlphaView.setAlphaSelectionListener(this);
|
||||
mTextView.addTextChangedListener(this);
|
||||
mTextColors = mTextView.getTextColors();
|
||||
mAlphaView.setVisibility(mAlphaEnabled ? View.VISIBLE : View.GONE);
|
||||
|
||||
mColorSelectionListener = colorSelectionListener;
|
||||
|
||||
parent.addView(mRootView);
|
||||
}
|
||||
|
||||
/** @return The root view, mainly for position manipulation purposes */
|
||||
public View getRootView(){
|
||||
return mRootView;
|
||||
// Set elevation to show above other side dialogs.
|
||||
// Jank, should be done better
|
||||
View contentParent = mDialogContent.findViewById(R.id.side_dialog_scrollview);
|
||||
if(contentParent != null) {
|
||||
ViewGroup dialogLayout = (ViewGroup) mDialogContent.getParent();
|
||||
dialogLayout.setElevation(11);
|
||||
dialogLayout.setTranslationZ(11);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the color selector with the default (red) color selected.
|
||||
*/
|
||||
public void show() {
|
||||
show(Color.RED);
|
||||
public void show(boolean fromRight) {
|
||||
show(fromRight, Color.RED);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the color selector with the desired ARGB color selected
|
||||
* @param previousColor the desired ARGB color
|
||||
*/
|
||||
public void show(int previousColor) {
|
||||
public void show(boolean fromRight, int previousColor) {
|
||||
appear(fromRight);
|
||||
runColor(previousColor); // initialize
|
||||
dispatchColorChange(); // set the hex text
|
||||
}
|
||||
@@ -157,8 +160,10 @@ public class ColorSelector implements HueSelectionListener, RectangleSelectionLi
|
||||
|
||||
public void setAlphaEnabled(boolean alphaEnabled){
|
||||
mAlphaEnabled = alphaEnabled;
|
||||
mAlphaView.setVisibility(alphaEnabled ? View.VISIBLE : View.GONE);
|
||||
mAlphaView.setAlpha(255);
|
||||
if(mAlphaView != null) {
|
||||
mAlphaView.setVisibility(alphaEnabled ? View.VISIBLE : View.GONE);
|
||||
mAlphaView.setAlpha(255);
|
||||
}
|
||||
}
|
||||
|
||||
private void notifyColorSelector(int color){
|
||||
|
||||
@@ -5,14 +5,12 @@ import static android.view.View.VISIBLE;
|
||||
|
||||
import static net.kdt.pojavlaunch.Tools.currentDisplayMetrics;
|
||||
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.animation.AccelerateDecelerateInterpolator;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.EditText;
|
||||
@@ -21,8 +19,6 @@ import android.widget.Spinner;
|
||||
import android.widget.Switch;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
|
||||
import com.kdt.SideDialogView;
|
||||
|
||||
import net.kdt.pojavlaunch.EfficientAndroidLWJGLKeycode;
|
||||
@@ -82,8 +78,6 @@ public class EditControlSideDialog extends SideDialogView {
|
||||
// Color selector related stuff
|
||||
private ColorSelector mColorSelector;
|
||||
private final ViewGroup mParent;
|
||||
private boolean mDisplayingColor = false;
|
||||
private ObjectAnimator mColorEditorAnimator;
|
||||
|
||||
public EditControlSideDialog(Context context, ViewGroup parent) {
|
||||
super(context, parent, R.layout.dialog_control_button_setting);
|
||||
@@ -100,58 +94,25 @@ public class EditControlSideDialog extends SideDialogView {
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
mParent.removeView(mColorSelector.getRootView());
|
||||
mColorSelector.disappear(true);
|
||||
}
|
||||
|
||||
/* While the selector could be retrofitted to side dialog, it's not worth the effort */
|
||||
private void buildColorSelector() {
|
||||
mColorSelector = new ColorSelector(mParent.getContext(), mParent, null);
|
||||
mColorSelector.getRootView().setElevation(11);
|
||||
mColorSelector.getRootView().setTranslationZ(11);
|
||||
mColorSelector.getRootView().setX(-mParent.getResources().getDimensionPixelOffset(R.dimen._280sdp));
|
||||
|
||||
mColorEditorAnimator = ObjectAnimator.ofFloat(mColorSelector.getRootView(), "x", 0).setDuration(600);
|
||||
mColorEditorAnimator.setInterpolator(new AccelerateDecelerateInterpolator());
|
||||
}
|
||||
|
||||
/**
|
||||
* Slide the layout into the visible screen area
|
||||
*/
|
||||
public void appearColor(boolean fromRight, int color) {
|
||||
if (fromRight) {
|
||||
if (!mDisplayingColor || !isAtRightColor()) {
|
||||
mColorEditorAnimator.setFloatValues(currentDisplayMetrics.widthPixels, currentDisplayMetrics.widthPixels - mDialogContent.getWidth() - mMargin);
|
||||
mColorEditorAnimator.start();
|
||||
}
|
||||
} else {
|
||||
if (!mDisplayingColor || isAtRightColor()) {
|
||||
mColorEditorAnimator.setFloatValues(-mDialogContent.getWidth(), mMargin);
|
||||
mColorEditorAnimator.start();
|
||||
}
|
||||
}
|
||||
|
||||
// Adjust the color selector to have the same size as the control settings
|
||||
ViewGroup.LayoutParams params = mColorSelector.getRootView().getLayoutParams();
|
||||
params.height = ((ViewGroup)mDialogContent.getParent()).getHeight();
|
||||
mColorSelector.getRootView().setLayoutParams(params);
|
||||
|
||||
mDisplayingColor = true;
|
||||
mColorSelector.show(color == -1 ? Color.WHITE : color);
|
||||
mColorSelector.show(fromRight, color == -1 ? Color.WHITE : color);
|
||||
}
|
||||
|
||||
/**
|
||||
* Slide out the layout
|
||||
*/
|
||||
public void disappearColor() {
|
||||
if (!mDisplayingColor) return;
|
||||
|
||||
mDisplayingColor = false;
|
||||
if (isAtRight())
|
||||
mColorEditorAnimator.setFloatValues(currentDisplayMetrics.widthPixels - mDialogContent.getWidth() - mMargin, currentDisplayMetrics.widthPixels);
|
||||
else
|
||||
mColorEditorAnimator.setFloatValues(mMargin, -mDialogContent.getWidth());
|
||||
|
||||
mColorEditorAnimator.start();
|
||||
mColorSelector.disappear(false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -160,7 +121,7 @@ public class EditControlSideDialog extends SideDialogView {
|
||||
* @return True if the last layer is disappearing
|
||||
*/
|
||||
public boolean disappearLayer() {
|
||||
if (mDisplayingColor) {
|
||||
if (mColorSelector.isDisplaying()) {
|
||||
disappearColor();
|
||||
return false;
|
||||
} else {
|
||||
@@ -176,7 +137,7 @@ public class EditControlSideDialog extends SideDialogView {
|
||||
if (mDisplaying) {
|
||||
boolean isAtRight = mCurrentlyEditedButton.getControlView().getX() + mCurrentlyEditedButton.getControlView().getWidth() / 2f < currentDisplayMetrics.widthPixels / 2f;
|
||||
appear(isAtRight);
|
||||
if (mDisplayingColor) {
|
||||
if (mColorSelector.isDisplaying()) {
|
||||
Tools.runOnUiThread(() -> appearColor(isAtRight, mCurrentlyEditedButton.getProperties().bgColor));
|
||||
}
|
||||
}
|
||||
@@ -515,10 +476,6 @@ public class EditControlSideDialog extends SideDialogView {
|
||||
return out;
|
||||
}
|
||||
|
||||
private boolean isAtRightColor() {
|
||||
return mColorSelector.getRootView().getX() > currentDisplayMetrics.widthPixels / 2f;
|
||||
}
|
||||
|
||||
public void setCurrentlyEditedButton(ControlInterface button) {
|
||||
if (mCurrentlyEditedButton != null)
|
||||
mCurrentlyEditedButton.getControlView().removeOnLayoutChangeListener(mLayoutChangedListener);
|
||||
|
||||
Reference in New Issue
Block a user