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