Skip to content

Commit 29176ce

Browse files
XXMrHydeusmcamgrimm
authored andcommitted
ColorPicker: Fix preference preview drawable and alpha slider by default
Signed-off-by: mydongistiny <[email protected]>
1 parent 86c3caf commit 29176ce

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

src/net/margaritov/preference/colorpicker/ColorPickerPreference.java

+11-13
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ public class ColorPickerPreference extends Preference implements
5555
private static final String sAndroidns = "http://schemas.android.com/apk/res/android";
5656

5757
private PreferenceViewHolder mViewHolder;
58-
private View mPreview;
5958

6059
private ColorPickerFragment mPickerFragment;
6160

@@ -66,7 +65,7 @@ public class ColorPickerPreference extends Preference implements
6665
private String mResetColor1Title = null;
6766
private String mResetColor2Title = null;
6867
private int mValue;
69-
private boolean mAlphaSliderVisible = false;
68+
private boolean mAlphaSliderVisible = true;
7069

7170
public ColorPickerPreference(Context context) {
7271
this(context, null);
@@ -150,6 +149,7 @@ private void setPreview() {
150149
return;
151150
}
152151

152+
widgetFrameView.removeAllViews();
153153
float density = mResources.getDisplayMetrics().density;
154154
final int size = (int) mResources.getDimension(
155155
R.dimen.color_picker_preference_preview_width_height);
@@ -163,18 +163,18 @@ private void setPreview() {
163163
borderColor = mResources.getColor(tv.resourceId);
164164
}
165165

166-
mPreview = new View(getContext());
166+
View preview = new View(getContext());
167167
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(size, size);
168168
ColorViewCircleDrawable drawable = new ColorViewCircleDrawable(getContext(), size);
169169

170170
widgetFrameView.setVisibility(View.VISIBLE);
171171
widgetFrameView.setPadding(widgetFrameView.getPaddingLeft(), widgetFrameView.getPaddingTop(),
172172
(int) (density * 8), widgetFrameView.getPaddingBottom());
173-
mPreview.setLayoutParams(lp);
174-
drawable.setColor(getValue());
173+
preview.setLayoutParams(lp);
174+
drawable.setColor(mValue);
175175
drawable.setBorderColor(borderColor);
176-
mPreview.setBackground(drawable);
177-
widgetFrameView.addView(mPreview);
176+
preview.setBackground(drawable);
177+
widgetFrameView.addView(preview);
178178
widgetFrameView.setMinimumWidth(0);
179179
}
180180

@@ -196,13 +196,11 @@ public void onColorChanged(int color) {
196196
persistInt(color);
197197
}
198198
mValue = color;
199-
if (mPreview != null) {
200-
((ColorViewCircleDrawable) mPreview.getBackground()).setColor(color);
201-
}
202199
try {
203200
getOnPreferenceChangeListener().onPreferenceChange(this, color);
204201
} catch (NullPointerException e) {
205202
}
203+
setPreview();
206204
}
207205

208206
@Override
@@ -254,11 +252,11 @@ private void showFragment(Bundle state) {
254252
boolean showHelpScreen = prefs.getBoolean("show_help_screen", true);
255253
arguments = new Bundle();
256254

257-
arguments.putInt("new_color", getValue());
258-
arguments.putInt("old_color", getValue());
255+
arguments.putInt("new_color", mValue);
256+
arguments.putInt("old_color", mValue);
259257
arguments.putBoolean("help_screen_visible", showHelpScreen);
260258
}
261-
arguments.putInt("initial_color", getValue());
259+
arguments.putInt("initial_color", mValue);
262260
arguments.putInt("reset_color_1", mResetColor1);
263261
arguments.putInt("reset_color_2", mResetColor2);
264262
arguments.putCharSequence("reset_color_1_title", mResetColor1Title);

0 commit comments

Comments
 (0)