Color picker: allow to activate ongoing led light as color preview
needs this: 1fb051a04a
Signed-off-by: xyyx <xyyx@mail.ru>
This commit is contained in:
@@ -23,7 +23,9 @@
|
||||
</declare-styleable>
|
||||
|
||||
<!-- Value to pass to callback when restore button is pressed -->
|
||||
<declare-styleable name="ColorPreference">
|
||||
<declare-styleable name="ColorPickerPreference">
|
||||
<attr name="defaultColorValue" format="integer" />
|
||||
<attr name="ledPreview" format="boolean" />
|
||||
<attr name="alphaSlider" format="boolean" />
|
||||
</declare-styleable>
|
||||
</resources>
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
package net.margaritov.preference.colorpicker;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.NotificationManager;
|
||||
import android.content.Context;
|
||||
import android.graphics.PixelFormat;
|
||||
import android.os.Bundle;
|
||||
@@ -39,15 +40,21 @@ public class ColorPickerDialog extends AlertDialog implements ColorPickerView.On
|
||||
private ColorPickerPanelView mNewColor;
|
||||
private EditText mHex;
|
||||
|
||||
private boolean mShowLedPreview;
|
||||
|
||||
private NotificationManager mNoMan;
|
||||
private Context mContext;
|
||||
|
||||
private OnColorChangedListener mListener;
|
||||
|
||||
public interface OnColorChangedListener {
|
||||
void onColorChanged(int color);
|
||||
}
|
||||
|
||||
ColorPickerDialog(Context context, int initialColor) {
|
||||
ColorPickerDialog(Context context, int initialColor, boolean showLedPreview) {
|
||||
super(context);
|
||||
|
||||
mContext = context;
|
||||
mShowLedPreview = showLedPreview;
|
||||
init(initialColor);
|
||||
}
|
||||
|
||||
@@ -72,6 +79,8 @@ public class ColorPickerDialog extends AlertDialog implements ColorPickerView.On
|
||||
|
||||
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(
|
||||
Context.LAYOUT_INFLATER_SERVICE);
|
||||
mNoMan = (NotificationManager)
|
||||
mContext.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
|
||||
assert inflater != null;
|
||||
View layout = inflater.inflate(R.layout.dui_dialog_color_picker, null);
|
||||
@@ -90,6 +99,7 @@ public class ColorPickerDialog extends AlertDialog implements ColorPickerView.On
|
||||
mColorPicker.setOnColorChangedListener(this);
|
||||
mOldColor.setColor(color);
|
||||
mColorPicker.setColor(color, true);
|
||||
showLed(color);
|
||||
|
||||
if (mHex != null) {
|
||||
mHex.setText(ColorPickerPreference.convertToRGB(color));
|
||||
@@ -109,6 +119,23 @@ public class ColorPickerDialog extends AlertDialog implements ColorPickerView.On
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
showLed(color);
|
||||
}
|
||||
|
||||
private void showLed(int color) {
|
||||
if (mShowLedPreview) {
|
||||
if (color == 0xFFFFFFFF) {
|
||||
// argb white doesn't work
|
||||
color = 0xffffff;
|
||||
}
|
||||
mNoMan.forceShowLedLight(color);
|
||||
}
|
||||
}
|
||||
|
||||
private void switchOffLed() {
|
||||
if (mShowLedPreview) {
|
||||
mNoMan.forceShowLedLight(-1);
|
||||
}
|
||||
}
|
||||
|
||||
void setAlphaSliderVisible(boolean visible) {
|
||||
@@ -146,8 +173,16 @@ public class ColorPickerDialog extends AlertDialog implements ColorPickerView.On
|
||||
}
|
||||
}
|
||||
dismiss();
|
||||
switchOffLed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
super.onStop();
|
||||
switchOffLed();
|
||||
}
|
||||
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Bundle onSaveInstanceState() {
|
||||
@@ -155,6 +190,7 @@ public class ColorPickerDialog extends AlertDialog implements ColorPickerView.On
|
||||
state.putInt("old_color", mOldColor.getColor());
|
||||
state.putInt("new_color", mNewColor.getColor());
|
||||
dismiss();
|
||||
switchOffLed();
|
||||
return state;
|
||||
}
|
||||
|
||||
|
||||
@@ -60,6 +60,8 @@ public class ColorPickerPreference extends Preference implements
|
||||
boolean mUsesDefaultButton = false;
|
||||
int mDefValue = -1;
|
||||
|
||||
private boolean mShowLedPreview;
|
||||
|
||||
private EditText mEditText;
|
||||
|
||||
public ColorPickerPreference(Context context) {
|
||||
@@ -97,6 +99,7 @@ public class ColorPickerPreference extends Preference implements
|
||||
mUsesDefaultButton = true;
|
||||
mDefValue = defVal;
|
||||
}
|
||||
mShowLedPreview = attrs.getAttributeBooleanValue(null, "ledPreview", false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -234,7 +237,7 @@ public class ColorPickerPreference extends Preference implements
|
||||
}
|
||||
|
||||
protected void showDialog(Bundle state) {
|
||||
mDialog = new ColorPickerDialog(getContext(), mValue);
|
||||
mDialog = new ColorPickerDialog(getContext(), mValue, mShowLedPreview);
|
||||
mDialog.setOnColorChangedListener(this);
|
||||
if (mAlphaSliderEnabled) {
|
||||
mDialog.setAlphaSliderVisible(true);
|
||||
|
||||
Reference in New Issue
Block a user