forked from plusonelabs/calendar-widget
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
plusonelabs#325 Generified / unified Text Shadings - prepare for thei…
…r extension
- Loading branch information
Showing
11 changed files
with
153 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
app/src/main/java/org/andstatus/todoagenda/TextShading.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.andstatus.todoagenda; | ||
|
||
import androidx.annotation.StringRes; | ||
import androidx.annotation.StyleRes; | ||
|
||
public enum TextShading { | ||
|
||
WHITE(R.style.Theme_Calendar_White, R.string.appearance_theme_white), | ||
LIGHT(R.style.Theme_Calendar_Light, R.string.appearance_theme_light), | ||
DARK(R.style.Theme_Calendar_Dark, R.string.appearance_theme_dark), | ||
BLACK(R.style.Theme_Calendar_Black, R.string.appearance_theme_black); | ||
|
||
@StyleRes | ||
public final int themeResId; | ||
@StringRes | ||
public final int titleResId; | ||
|
||
TextShading(int themeResId, int titleResId) { | ||
this.themeResId = themeResId; | ||
this.titleResId = titleResId; | ||
} | ||
|
||
public static TextShading fromName(String themeName, TextShading defaultShading) { | ||
try { | ||
return TextShading.valueOf(themeName); | ||
} catch (Exception e) { | ||
return defaultShading; | ||
} | ||
} | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 37 additions & 1 deletion
38
app/src/main/java/org/andstatus/todoagenda/prefs/ColorsPreferencesFragment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,51 @@ | ||
package org.andstatus.todoagenda.prefs; | ||
|
||
import android.content.SharedPreferences; | ||
import android.os.Bundle; | ||
import android.preference.ListPreference; | ||
import android.preference.PreferenceFragment; | ||
|
||
import org.andstatus.todoagenda.R; | ||
import org.andstatus.todoagenda.TextShading; | ||
|
||
public class ColorsPreferencesFragment extends PreferenceFragment { | ||
public class ColorsPreferencesFragment extends PreferenceFragment | ||
implements SharedPreferences.OnSharedPreferenceChangeListener { | ||
|
||
@Override | ||
public void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
addPreferencesFromResource(R.xml.preferences_colors); | ||
} | ||
|
||
@Override | ||
public void onResume() { | ||
super.onResume(); | ||
getPreferenceManager().getSharedPreferences().registerOnSharedPreferenceChangeListener(this); | ||
showShadings(); | ||
} | ||
|
||
private void showShadings() { | ||
for (TextShadingPref shadingPref : TextShadingPref.values()) { | ||
showShading(shadingPref); | ||
} | ||
} | ||
|
||
@Override | ||
public void onPause() { | ||
super.onPause(); | ||
getPreferenceManager().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this); | ||
} | ||
|
||
@Override | ||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { | ||
showShadings(); | ||
} | ||
|
||
private void showShading(TextShadingPref prefs) { | ||
ListPreference preference = (ListPreference) findPreference(prefs.preferenceName); | ||
if (preference != null) { | ||
TextShading shading = TextShading.fromName(preference.getValue(), prefs.defaultShading); | ||
preference.setSummary(getActivity().getString(shading.titleResId)); | ||
} | ||
} | ||
} |
Oops, something went wrong.