Skip to content

Commit

Permalink
Merge pull request #13 from AHarman/use-defaultValue
Browse files Browse the repository at this point in the history
Use defaultValue
  • Loading branch information
J-Jamet authored Jun 21, 2018
2 parents 9f301af + 92e8e34 commit b93363c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,17 @@ private void loadValuesFromXml(AttributeSet attrs) {

@Override
protected void onSetInitialValue(boolean restorePersistedValue, Object defaultValue) {
super.onSetInitialValue(restorePersistedValue, defaultValue);
color = getPersistedInt(color);
if (restorePersistedValue) {
color = getPersistedInt(color);
} else {
color = (int) defaultValue;
persistInt(color);
}
}

@Override
protected Object onGetDefaultValue(TypedArray a, int index) {
return Color.parseColor(a.getString(index));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import android.support.design.widget.FloatingActionButton;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.preference.PreferenceManager;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.AdapterView;
Expand Down Expand Up @@ -52,6 +53,9 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

// Load defaultValues from prefs_v7.xml
PreferenceManager.setDefaultValues(this, R.xml.prefs_v7, false);

toolbar = (Toolbar) findViewById(R.id.toolbar);
textView = (TextView) findViewById(R.id.text_view);
spinner = (Spinner) findViewById(R.id.spinner);
Expand Down
1 change: 1 addition & 0 deletions sample/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#3e4f9e</color>
<color name="defaultPreferenceColour">#ff00ff</color>
</resources>
14 changes: 7 additions & 7 deletions sample/src/main/res/xml/prefs_v7.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<PreferenceScreen
<android.support.v7.preference.PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

Expand All @@ -13,35 +13,35 @@
android:title="ARGB sample"
android:summary="[color]"
app:chromaColorMode="ARGB"
app:chromaInitialColor="@android:color/black"/>
android:defaultValue="@android:color/black"/>

<com.kunzisoft.androidclearchroma.ChromaPreferenceCompat
android:key="argbhex"
android:title="ARGB and HEX indicator sample"
android:summary="ARGB and HEX [color]"
app:chromaColorMode="ARGB"
app:chromaIndicatorMode="HEX"
app:chromaInitialColor="#ae4f4f"/>
android:defaultValue="#ae4f4f"/>

<com.kunzisoft.androidclearchroma.ChromaPreferenceCompat
android:key="hsv"
android:title="HSV sample"
app:chromaColorMode="HSV"
app:chromaInitialColor="#649e65"/>
android:defaultValue="#649e65"/>

<com.kunzisoft.androidclearchroma.ChromaPreferenceCompat
android:key="roundedquare"
android:title="ARGB sample with rounded square sample"
app:chromaShapePreview="ROUNDED_SQUARE"
app:chromaColorMode="ARGB"
app:chromaInitialColor="#ffee00"/>
android:defaultValue="#ffee00"/>

<com.kunzisoft.androidclearchroma.ChromaPreferenceCompat
android:key="customsummary"
android:title="ARGB sample with square sample and custom summary"
android:summary="Example summary"
app:chromaShapePreview="SQUARE"
app:chromaColorMode="ARGB"
app:chromaInitialColor="#ff0004"/>
android:defaultValue="#ff0004"/>

</PreferenceScreen>
</android.support.v7.preference.PreferenceScreen>

0 comments on commit b93363c

Please # to comment.