2929 * @author Martin Zeitler
3030 */
3131public class ColorPickerPreference extends Preference implements
32- Preference .OnPreferenceChangeListener ,
33- Preference .OnPreferenceClickListener ,
32+ Preference .OnPreferenceChangeListener , Preference .OnPreferenceClickListener ,
3433 OnColorChangedListener {
3534
3635 /** {@link Log} Tag */
@@ -90,9 +89,7 @@ private void init(@NonNull Context context, @Nullable AttributeSet attrs) {
9089
9190 this .prefs = PreferenceManager .getDefaultSharedPreferences (context );
9291 this .mCurrentValue = this .prefs .getInt (this .getKey (), this .mCurrentValue );
93- if (mDebug ) {
94- Log .d (LOG_TAG , String .format ("%s: %s" , this .getKey (), convertToARGB (this .mCurrentValue )));
95- }
92+ if (mDebug ) {Log .d (LOG_TAG , this .getKey () + ": " + convertToARGB (this .mCurrentValue ));}
9693 this .setOnPreferenceClickListener (this );
9794 }
9895
@@ -105,11 +102,9 @@ private void init(@NonNull Context context, @Nullable AttributeSet attrs) {
105102 @ NonNull
106103 @ Override
107104 protected Object onGetDefaultValue (@ NonNull TypedArray a , int index ) {
108- int colorInt ;
109105 String mHexDefaultValue = a .getString (index );
110106 if (mHexDefaultValue != null && mHexDefaultValue .startsWith ("#" )) {
111- colorInt = convertToColorInt (mHexDefaultValue );
112- return colorInt ;
107+ return convertToColorInt (mHexDefaultValue );
113108 } else {
114109 return a .getColor (index , this .mCurrentValue );
115110 }
@@ -160,7 +155,7 @@ public void onColorChanged(int color) {
160155 try {
161156 this .onPreferenceChange (this , color );
162157 } catch (NullPointerException e ) {
163- if (mDebug ) {Log .e (LOG_TAG , String . format ( "%s" , e .getMessage () ));}
158+ if (mDebug ) {Log .e (LOG_TAG , "NullPointerException: " + e .getMessage ());}
164159 }
165160 }
166161
@@ -185,7 +180,7 @@ public void setHexValueEnabled(boolean value) {
185180 }
186181
187182 /**
188- * String.format("#%1$02X", color)
183+ * String.format("#%1$02X", color)
189184 *
190185 * @param color the color value to convert.
191186 */
@@ -226,7 +221,9 @@ static String convertToRGB(int color) {
226221 * @param argb the ARGB string to convert.
227222 */
228223 static int convertToColorInt (@ NonNull String argb ) {
229- if (! argb .startsWith ("#" )) {argb = String .format ("#%s" , argb );}
224+ if (! argb .startsWith ("#" )) {
225+ argb = String .format ("#%s" , argb );
226+ }
230227 return Color .parseColor (argb );
231228 }
232229
0 commit comments