mirror of
https://gitee.com/zhangsken/AndroidIDE.git
synced 2026-10-16 07:49:44 +08:00
Apply new color value when picked from color picker
This commit is contained in:
@@ -76,6 +76,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Stack;
|
||||
|
||||
// TODO Generate and save the source code once the user leaves this activity
|
||||
public class DesignerActivity extends StudioActivity implements WidgetItemAdapter.OnDragStartListener {
|
||||
|
||||
private ActivityDesignerBinding mBinding;
|
||||
|
||||
@@ -43,6 +43,7 @@ import com.itsaky.androidide.R;
|
||||
import com.itsaky.androidide.adapters.AttributeListAdapter;
|
||||
import com.itsaky.androidide.adapters.SimpleIconTextAdapter;
|
||||
import com.itsaky.androidide.app.StudioApp;
|
||||
import com.itsaky.androidide.colorpicker.ColorPickerView;
|
||||
import com.itsaky.androidide.databinding.LayoutAttrEditorSheetBinding;
|
||||
import com.itsaky.androidide.databinding.LayoutAttrEditorSheetItemBinding;
|
||||
import com.itsaky.androidide.models.IconTextListItem;
|
||||
@@ -144,15 +145,9 @@ public class AttrEditorSheet extends BottomSheetDialogFragment implements Simple
|
||||
private void showEditorDialog (@NonNull XMLAttribute attribute) {
|
||||
final var attr = attribute.getAttr ();
|
||||
final var values = attr.possibleValues.toArray (new String[0]);
|
||||
final AttributeDialogs.OnClickListener onDone = (dialog, which, newValue) -> {
|
||||
if (!this.selectedView.updateAttribute (attribute.getNamespace (), attribute.getAttributeName (), newValue)) {
|
||||
StudioApp.getInstance ().toast ("Unable to update this attribute", Toaster.Type.ERROR);
|
||||
} else {
|
||||
// Update the view data
|
||||
// This will make sure that the attributes list has been updated
|
||||
setupViewData ();
|
||||
}
|
||||
};
|
||||
final AttributeDialogs.OnClickListener onDone = (dialog, which, newValue) -> applyNewValue (attribute, newValue);
|
||||
|
||||
final ColorPickerView.OnPickListener mPickListener = (color, hexCode) -> applyNewValue (attribute, hexCode);
|
||||
|
||||
AlertDialog dialog = null;
|
||||
if (attribute.hasFormat (DIMENSION)) {
|
||||
@@ -168,7 +163,7 @@ public class AttrEditorSheet extends BottomSheetDialogFragment implements Simple
|
||||
} else if (attribute.hasFormat (COLOR)) {
|
||||
// TODO Implement something to allow values from colors.xml or ColorStateLists
|
||||
// Make this color picker optional
|
||||
dialog = colorPicker ();
|
||||
dialog = colorPicker (mPickListener);
|
||||
}
|
||||
|
||||
if (dialog != null) {
|
||||
@@ -176,6 +171,16 @@ public class AttrEditorSheet extends BottomSheetDialogFragment implements Simple
|
||||
}
|
||||
}
|
||||
|
||||
private void applyNewValue (@NonNull XMLAttribute attribute, String newValue) {
|
||||
if (!this.selectedView.updateAttribute (attribute.getNamespace (), attribute.getAttributeName (), newValue)) {
|
||||
StudioApp.getInstance ().toast ("Unable to update this attribute", Toaster.Type.ERROR);
|
||||
} else {
|
||||
// Update the view data
|
||||
// This will make sure that the attributes list has been updated
|
||||
setupViewData ();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postBind (IconTextListItem item, @NonNull SimpleIconTextAdapter.VH holder, int position) {
|
||||
final var binding = holder.binding;
|
||||
|
||||
@@ -269,15 +269,21 @@ public class AttributeDialogs {
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static AlertDialog colorPicker () {
|
||||
public static AlertDialog colorPicker (final ColorPickerView.OnPickListener listener) {
|
||||
final var view = new ColorPickerView (mContext);
|
||||
view.setOnPickListener ((color, hexCode) -> LOG.debug ("Picked color:", color, hexCode));
|
||||
|
||||
final var builder = newMaterialDialogBuilder (mContext);
|
||||
builder.setView (view);
|
||||
|
||||
final var dialog = builder.create ();
|
||||
dialog.getWindow ().setSoftInputMode (WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
|
||||
|
||||
view.setOnPickListener ((color, hexCode) -> {
|
||||
dialog.dismiss ();
|
||||
if (listener != null) {
|
||||
listener.onPick (color, hexCode);
|
||||
}
|
||||
});
|
||||
|
||||
return dialog;
|
||||
}
|
||||
|
||||
|
||||
@@ -136,7 +136,7 @@ public class ColorPickerView extends LinearLayout {
|
||||
*/
|
||||
@NonNull
|
||||
public String getHexColor () {
|
||||
return Integer.toHexString (getColor ());
|
||||
return "#" + Integer.toHexString (getColor ());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user