Skip to content

Commit

Permalink
add color to demo app
Browse files Browse the repository at this point in the history
  • Loading branch information
ru26kif committed Aug 26, 2020
1 parent b8ea647 commit e5875fb
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 21 deletions.
18 changes: 9 additions & 9 deletions demo/src/main/java/com/example/prefsplus/PrefsPlusActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.graphics.Color;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.LayoutInflater;
Expand Down Expand Up @@ -59,11 +60,7 @@ public static class PrefsPlusFragment extends Fragment {
private TextView floatTextView;
private TextView integerListTextView;
private TextView textTextView;

private int intValue;
private float floatValue;
private int intListValue;
private String textValue;
private TextView colorTextView;

private SharedPreferences prefs;
private Resources res;
Expand All @@ -76,6 +73,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
floatTextView = (TextView) view.findViewById(R.id.float_value);
integerListTextView = (TextView) view.findViewById(R.id.integer_list_value);
textTextView = (TextView) view.findViewById(R.id.text_value);
colorTextView=(TextView) view.findViewById(R.id.tv_color_value);
prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
res = getResources();
return view;
Expand All @@ -84,19 +82,21 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
@Override
public void onResume() {
super.onResume();
intValue = prefs.getInt(res.getString(R.string.integer_key),
int intValue = prefs.getInt(res.getString(R.string.integer_key),
res.getInteger(R.integer.integer_default_value));
floatValue = prefs.getFloat(res.getString(R.string.float_key),
float floatValue = prefs.getFloat(res.getString(R.string.float_key),
res.getInteger(R.integer.integer_default_value));
intListValue = prefs.getInt(res.getString(R.string.integer_list_key),
int intListValue = prefs.getInt(res.getString(R.string.integer_list_key),
res.getInteger(R.integer.integer_default_value));
textValue = prefs.getString(res.getString(R.string.text_key),
String textValue = prefs.getString(res.getString(R.string.text_key),
res.getString(R.string.text_default_value));
int colorValue = prefs.getInt(res.getString(R.string.color_key), Color.RED);

integerTextView.setText(Integer.toString(intValue));
floatTextView.setText(Float.toString(floatValue));
integerListTextView.setText(Integer.toString(intListValue));
textTextView.setText(textValue);
colorTextView.setBackgroundColor(colorValue);
}
}
}
11 changes: 11 additions & 0 deletions demo/src/main/res/layout/fragment_prefs_plus.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,22 @@
android:layout_marginBottom="16dp"
android:textSize="16sp" />

<TextView
android:id="@+id/tv_color_value"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:textSize="16sp"
android:text="Example Text with color from settings"/>

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="16sp"
android:textStyle="italic"
android:text="@string/hint" />




</LinearLayout>
10 changes: 10 additions & 0 deletions demo/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>


<color name="DEFAULT_TV_BACKGROUND_COLOR">#F44336</color>




</resources>
2 changes: 2 additions & 0 deletions demo/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@
<string name="text_dialog_title">Enter a string</string>
<string name="hint">Update current values via Settings</string>

<string name="color_key">color_key</string>

</resources>
17 changes: 5 additions & 12 deletions demo/src/main/res/xml/preferencesx.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,12 @@
android:dialogTitle="@string/text_dialog_title"
android:defaultValue="@string/text_default_value" />

<com.mapzen.prefsplusx.EditIntPreference
android:key="lol_key1"
android:title="lol_title"
android:dialogTitle="lol_dia_title"
android:defaultValue="0"
app:minIntValue="0"
app:maxIntValue="100"/>

<com.kizitonwose.colorpreference.ColorPreference
android:key="lol_color1"
android:title="lol_color1"
android:summary="Prefixes,e.g. Dec:,Lat"
app:colorShape="circle" />

android:key="@string/color_key"
android:title="@string/color_key"
android:summary="Select text background color"
app:colorShape="circle"
android:defaultValue="@color/DEFAULT_TV_BACKGROUND_COLOR"/>

</androidx.preference.PreferenceScreen>

0 comments on commit e5875fb

Please sign in to comment.