mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-17 16:47:14 -04:00
Implement a checkboard pattern for the background color of buttons
This commit is contained in:
parent
52f23f33a9
commit
7a49cadaaa
@ -125,6 +125,7 @@ dependencies {
|
||||
implementation "androidx.constraintlayout:constraintlayout:2.0.4"
|
||||
|
||||
implementation 'com.rarepebble:colorpicker:3.0.1'
|
||||
implementation 'com.github.duanhong169:checkerboarddrawable:1.0.2'
|
||||
|
||||
|
||||
// implementation 'com.intuit.sdp:sdp-android:1.0.5'
|
||||
|
@ -20,6 +20,7 @@
|
||||
package net.kdt.pojavlaunch.customcontrols.handleview;
|
||||
|
||||
import android.content.*;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.view.*;
|
||||
import android.view.ViewGroup.*;
|
||||
import android.widget.*;
|
||||
@ -152,7 +153,9 @@ public class ActionPopupWindow extends PinnedPopupWindow implements OnClickListe
|
||||
}
|
||||
|
||||
|
||||
public static void showColorPicker(Context ctx,String title, boolean showAlpha, int startColor, View v){
|
||||
public static void showColorPicker(Context ctx,String title, boolean showAlpha, ImageView v){
|
||||
int startColor = ((ColorDrawable)v.getDrawable()).getColor();
|
||||
|
||||
ColorPickerView picker = new ColorPickerView(ctx);
|
||||
picker.setColor(startColor);
|
||||
picker.showAlpha(showAlpha);
|
||||
@ -161,7 +164,7 @@ public class ActionPopupWindow extends PinnedPopupWindow implements OnClickListe
|
||||
dialog.setTitle(title);
|
||||
dialog.setView(picker);
|
||||
dialog.setNegativeButton(android.R.string.cancel, null);
|
||||
dialog.setPositiveButton(android.R.string.ok, (dialogInterface, i) -> v.setBackgroundColor(picker.getColor()));
|
||||
dialog.setPositiveButton(android.R.string.ok, (dialogInterface, i) -> v.setImageDrawable(new ColorDrawable(picker.getColor())));
|
||||
|
||||
dialog.show();
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package net.kdt.pojavlaunch.customcontrols.handleview;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@ -17,9 +18,12 @@ import androidx.appcompat.app.AlertDialog;
|
||||
|
||||
import net.kdt.pojavlaunch.EfficientAndroidLWJGLKeycode;
|
||||
import net.kdt.pojavlaunch.R;
|
||||
import net.kdt.pojavlaunch.Tools;
|
||||
import net.kdt.pojavlaunch.customcontrols.buttons.ControlButton;
|
||||
import net.kdt.pojavlaunch.customcontrols.ControlData;
|
||||
|
||||
import top.defaults.checkerboarddrawable.CheckerboardDrawable;
|
||||
|
||||
import static net.kdt.pojavlaunch.customcontrols.handleview.ActionPopupWindow.setPercentageText;
|
||||
|
||||
public class EditControlButtonPopup {
|
||||
@ -171,8 +175,8 @@ public class EditControlButtonPopup {
|
||||
}
|
||||
|
||||
//Set color imageButton behavior
|
||||
buttonBackgroundColor.setOnClickListener(view -> ActionPopupWindow.showColorPicker(ctx, "Edit background color", true, ((ColorDrawable) buttonBackgroundColor.getBackground()).getColor(), buttonBackgroundColor));
|
||||
buttonStrokeColor.setOnClickListener(view -> ActionPopupWindow.showColorPicker(ctx, "Edit stroke color", false, ((ColorDrawable) buttonStrokeColor.getBackground()).getColor(), buttonStrokeColor));
|
||||
buttonBackgroundColor.setOnClickListener(view -> ActionPopupWindow.showColorPicker(ctx, "Edit background color", true, buttonBackgroundColor));
|
||||
buttonStrokeColor.setOnClickListener(view -> ActionPopupWindow.showColorPicker(ctx, "Edit stroke color", false, buttonStrokeColor));
|
||||
|
||||
|
||||
//Set dialog buttons behavior
|
||||
@ -180,6 +184,7 @@ public class EditControlButtonPopup {
|
||||
|
||||
hideUselessViews();
|
||||
|
||||
setupCheckerboards();
|
||||
}
|
||||
|
||||
protected void setupDialogButtons(){
|
||||
@ -196,6 +201,17 @@ public class EditControlButtonPopup {
|
||||
(v.findViewById(R.id.editOrientation_textView)).setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
private void setupCheckerboards(){
|
||||
CheckerboardDrawable drawable = new CheckerboardDrawable.Builder()
|
||||
.colorEven(Color.LTGRAY)
|
||||
.colorOdd(Color.WHITE)
|
||||
.size((int) Tools.dpToPx(20))
|
||||
.build();
|
||||
|
||||
buttonBackgroundColor.setBackground(drawable);
|
||||
buttonStrokeColor.setBackground(drawable);
|
||||
}
|
||||
|
||||
protected void setEditDialogValues(){
|
||||
|
||||
editName.setText(properties.name);
|
||||
@ -218,8 +234,8 @@ public class EditControlButtonPopup {
|
||||
seekBarStrokeWidth.setProgress(properties.strokeWidth);
|
||||
seekBarCornerRadius.setProgress((int)properties.cornerRadius);
|
||||
|
||||
buttonBackgroundColor.setBackgroundColor(properties.bgColor);
|
||||
buttonStrokeColor.setBackgroundColor(properties.strokeColor);
|
||||
buttonBackgroundColor.setImageDrawable(new ColorDrawable(properties.bgColor));
|
||||
buttonStrokeColor.setImageDrawable(new ColorDrawable(properties.strokeColor));
|
||||
|
||||
setPercentageText(textCornerRadius,seekBarCornerRadius.getProgress());
|
||||
setPercentageText(textOpacity,seekBarOpacity.getProgress());
|
||||
@ -280,8 +296,8 @@ public class EditControlButtonPopup {
|
||||
properties.strokeWidth = seekBarStrokeWidth.getProgress();
|
||||
properties.cornerRadius = seekBarCornerRadius.getProgress();
|
||||
|
||||
properties.bgColor = ((ColorDrawable) buttonBackgroundColor.getBackground()).getColor();
|
||||
properties.strokeColor = ((ColorDrawable) buttonStrokeColor.getBackground()).getColor();
|
||||
properties.bgColor = ((ColorDrawable)buttonBackgroundColor.getDrawable()).getColor();
|
||||
properties.strokeColor = ((ColorDrawable) buttonStrokeColor.getDrawable()).getColor();
|
||||
|
||||
properties.isToggle = checkToggle.isChecked();
|
||||
properties.passThruEnabled = checkPassThrough.isChecked();
|
||||
|
Loading…
x
Reference in New Issue
Block a user