Apply theme to grid selector time picker

This commit is contained in:
Phillip Hsu 2016-09-20 23:29:33 -07:00
parent 42137d8ae2
commit 020ffc921d
4 changed files with 16 additions and 2 deletions

View File

@ -280,7 +280,7 @@ public class Utils {
* @return true if dark mode, false if light.
*/
public static boolean isDarkTheme(Context context, boolean current) {
return resolveBoolean(context, R.attr.theme_dark, current);
return resolveBoolean(context, R.attr.themeDark, current);
}
/**

View File

@ -70,6 +70,7 @@ public class NumberGridTimePickerDialog extends BaseTimePickerDialog implements
private static final String KEY_IN_KB_MODE = "in_kb_mode";
private static final String KEY_TYPED_TIMES = "typed_times";
private static final String KEY_DARK_THEME = "dark_theme";
private static final String KEY_THEME_SET_AT_RUNTIME = "theme_set_at_runtime";
public static final int HOUR_INDEX = 0;
public static final int MINUTE_INDEX = 1;
@ -112,6 +113,7 @@ public class NumberGridTimePickerDialog extends BaseTimePickerDialog implements
private int mInitialMinute;
private boolean mIs24HourMode;
private boolean mThemeDark;
private boolean mThemeSetAtRuntime;
// For hardware IME input.
private char mPlaceholderText;
@ -243,6 +245,7 @@ public class NumberGridTimePickerDialog extends BaseTimePickerDialog implements
mIs24HourMode = is24HourMode;
mInKbMode = false;
mThemeDark = false;
mThemeSetAtRuntime = false;
}
/**
@ -250,6 +253,7 @@ public class NumberGridTimePickerDialog extends BaseTimePickerDialog implements
*/
public void setThemeDark(boolean dark) {
mThemeDark = dark;
mThemeSetAtRuntime = true;
}
public boolean isThemeDark() {
@ -278,6 +282,7 @@ public class NumberGridTimePickerDialog extends BaseTimePickerDialog implements
mIs24HourMode = savedInstanceState.getBoolean(KEY_IS_24_HOUR_VIEW);
mInKbMode = savedInstanceState.getBoolean(KEY_IN_KB_MODE);
mThemeDark = savedInstanceState.getBoolean(KEY_DARK_THEME);
mThemeSetAtRuntime = savedInstanceState.getBoolean(KEY_THEME_SET_AT_RUNTIME);
}
}
@ -292,6 +297,10 @@ public class NumberGridTimePickerDialog extends BaseTimePickerDialog implements
View view = super.onCreateView(inflater, container, savedInstanceState);
if (!mThemeSetAtRuntime) {
mThemeDark = Utils.isDarkTheme(getActivity(), mThemeDark);
}
Resources res = getResources();
mHourPickerDescription = res.getString(R.string.hour_picker_description);
mSelectHours = res.getString(R.string.select_hours);
@ -575,6 +584,7 @@ public class NumberGridTimePickerDialog extends BaseTimePickerDialog implements
outState.putIntegerArrayList(KEY_TYPED_TIMES, mTypedTimes);
}
outState.putBoolean(KEY_DARK_THEME, mThemeDark);
outState.putBoolean(KEY_THEME_SET_AT_RUNTIME, mThemeSetAtRuntime);
}
}

View File

@ -15,7 +15,7 @@
-->
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<attr name="theme_dark" format="boolean">false</attr>
<attr name="themeDark" format="boolean">false</attr>
<style name="time_label">
<item name="android:textSize">@dimen/time_label_size</item>

View File

@ -19,6 +19,8 @@
<item name="themedIconTint">@color/icon_color_active_light</item>
<item name="android:textColorHint">@color/text_color_disabled_light</item>
<item name="themedPopupOverlay">@style/ThemeOverlay.AppCompat.Light</item>
<!-- For BottomSheetTimePickers -->
<item name="themeDark">false</item>
</style>
<style name="AppTheme.Dark" parent="Theme.AppCompat.NoActionBar">
@ -40,6 +42,8 @@
<item name="themedIconTint">@color/icon_color_active_dark</item>
<item name="android:textColorHint">@color/text_color_disabled_dark</item>
<item name="themedPopupOverlay">@style/ThemeOverlay.AppCompat.Dark</item>
<!-- For BottomSheetTimePickers -->
<item name="themeDark">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar"/>