From c5c42189eeab0389a94717de9a66c6d00068e8bf Mon Sep 17 00:00:00 2001 From: calderwoodra Date: Tue, 22 May 2018 15:30:39 -0700 Subject: Began implementation of Dialer dark theme. - README on how to properly theme Dialer going forward. - Migrated all widgets to use global colors. - Removed all activity and application themes where it wasn't necessary. - Added themeing test rule for Espresso tests. Bug: 79883035 Test: tap PiperOrigin-RevId: 197634256 Change-Id: I4b7d94d45aeeb59d484b0069fdd1e200a654910b --- .../android/dialer/theme/base/AndroidManifest.xml | 16 ++ java/com/android/dialer/theme/base/ThemeUtil.java | 169 +++++++++++++++++++++ .../android/dialer/theme/base/res/values/attr.xml | 26 ++++ .../theme/base/res/values/styles_dialer_light.xml | 53 +++++++ .../theme/base/res/values/theme_dialer_dark.xml | 64 ++++++++ .../theme/base/res/values/theme_dialer_light.xml | 81 ++++++++++ 6 files changed, 409 insertions(+) create mode 100644 java/com/android/dialer/theme/base/AndroidManifest.xml create mode 100644 java/com/android/dialer/theme/base/ThemeUtil.java create mode 100644 java/com/android/dialer/theme/base/res/values/attr.xml create mode 100644 java/com/android/dialer/theme/base/res/values/styles_dialer_light.xml create mode 100644 java/com/android/dialer/theme/base/res/values/theme_dialer_dark.xml create mode 100644 java/com/android/dialer/theme/base/res/values/theme_dialer_light.xml (limited to 'java/com/android/dialer/theme/base') diff --git a/java/com/android/dialer/theme/base/AndroidManifest.xml b/java/com/android/dialer/theme/base/AndroidManifest.xml new file mode 100644 index 000000000..ff7891055 --- /dev/null +++ b/java/com/android/dialer/theme/base/AndroidManifest.xml @@ -0,0 +1,16 @@ + + diff --git a/java/com/android/dialer/theme/base/ThemeUtil.java b/java/com/android/dialer/theme/base/ThemeUtil.java new file mode 100644 index 000000000..a2d70c951 --- /dev/null +++ b/java/com/android/dialer/theme/base/ThemeUtil.java @@ -0,0 +1,169 @@ +/* + * Copyright (C) 2018 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.dialer.theme.base; + +import android.content.Context; +import android.content.res.TypedArray; +import android.support.annotation.ColorInt; +import android.support.annotation.IntDef; +import android.support.annotation.StyleRes; +import android.view.ContextThemeWrapper; +import android.view.LayoutInflater; +import com.android.dialer.common.Assert; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +/** Utility for fetching */ +@SuppressWarnings("unused") +public class ThemeUtil { + + /** IntDef for the different themes Dialer supports. */ + @Retention(RetentionPolicy.SOURCE) + @IntDef({UNKNOWN, LIGHT, DARK}) + public @interface Theme {} + + public static final int UNKNOWN = 0; + public static final int LIGHT = 1; + public static final int DARK = 2; + + private static @Theme int theme = UNKNOWN; + + private static int colorIcon = -1; + private static int colorIconSecondary = -1; + private static int colorPrimary = -1; + private static int colorPrimaryDark = -1; + private static int colorAccent = -1; + private static int textColorPrimary = -1; + private static int textColorSecondary = -1; + private static int textColorPrimaryInverse = -1; + private static int textColorHint = -1; + private static int colorBackground = -1; + private static int colorBackgroundFloating = -1; + private static int colorTextOnUnthemedDarkBackground = -1; + private static int colorIconOnUnthemedDarkBackground = -1; + + public static void initializeTheme(Context context) { + // TODO(a bug): add share prefs check to configure this + theme = LIGHT; + + context = context.getApplicationContext(); + context.setTheme(getApplicationThemeRes()); + TypedArray array = + context + .getTheme() + .obtainStyledAttributes( + getApplicationThemeRes(), + new int[] { + android.R.attr.colorPrimary, + android.R.attr.colorPrimaryDark, + android.R.attr.colorAccent, + android.R.attr.textColorPrimary, + android.R.attr.textColorSecondary, + android.R.attr.textColorPrimaryInverse, + android.R.attr.textColorHint, + android.R.attr.colorBackground, + android.R.attr.colorBackgroundFloating, + R.attr.colorIcon, + R.attr.colorIconSecondary, + R.attr.colorTextOnUnthemedDarkBackground, + R.attr.colorIconOnUnthemedDarkBackground, + }); + colorPrimary = array.getColor(/* index= */ 0, /* defValue= */ -1); + colorPrimaryDark = array.getColor(/* index= */ 1, /* defValue= */ -1); + colorAccent = array.getColor(/* index= */ 2, /* defValue= */ -1); + textColorPrimary = array.getColor(/* index= */ 3, /* defValue= */ -1); + textColorSecondary = array.getColor(/* index= */ 4, /* defValue= */ -1); + textColorPrimaryInverse = array.getColor(/* index= */ 5, /* defValue= */ -1); + textColorHint = array.getColor(/* index= */ 6, /* defValue= */ -1); + colorBackground = array.getColor(/* index= */ 7, /* defValue= */ -1); + colorBackgroundFloating = array.getColor(/* index= */ 8, /* defValue= */ -1); + colorIcon = array.getColor(/* index= */ 9, /* defValue= */ -1); + colorIconSecondary = array.getColor(/* index= */ 10, /* defValue= */ -1); + colorTextOnUnthemedDarkBackground = array.getColor(/* index= */ 11, /* defValue= */ -1); + colorIconOnUnthemedDarkBackground = array.getColor(/* index= */ 12, /* defValue= */ -1); + array.recycle(); + } + + /** + * Returns the {@link Theme} that the application is using. Activities should check this value if + * their custom style needs to customize further based on the application theme. + */ + public static @Theme int getTheme() { + Assert.checkArgument(theme != UNKNOWN); + return theme; + } + + public static @StyleRes int getApplicationThemeRes() { + switch (theme) { + case DARK: + return R.style.Dialer_Dark_ThemeBase_NoActionBar; + case LIGHT: + return R.style.Dialer_ThemeBase_NoActionBar; + case UNKNOWN: + default: + throw Assert.createIllegalStateFailException("Theme hasn't been set yet."); + } + } + + public static Context getThemedContext(Context context) { + return new ContextThemeWrapper(context, getApplicationThemeRes()); + } + + public static LayoutInflater getThemedLayoutInflator(LayoutInflater inflater) { + return inflater.cloneInContext(getThemedContext(inflater.getContext())); + } + + public static @ColorInt int getColorIcon() { + Assert.checkArgument(colorIcon != -1); + return colorIcon; + } + + public static @ColorInt int getColorIconSecondary() { + Assert.checkArgument(colorIconSecondary != -1); + return colorIconSecondary; + } + + public static @ColorInt int getColorPrimary() { + Assert.checkArgument(colorPrimary != -1); + return colorPrimary; + } + + public static @ColorInt int getColorAccent() { + Assert.checkArgument(colorAccent != -1); + return colorAccent; + } + + public static @ColorInt int getTextColorSecondary() { + Assert.checkArgument(textColorSecondary != -1); + return textColorSecondary; + } + + public static @ColorInt int getTextColorPrimary() { + Assert.checkArgument(textColorPrimary != -1); + return textColorPrimary; + } + + public static @ColorInt int getColorTextOnUnthemedDarkBackground() { + Assert.checkArgument(colorTextOnUnthemedDarkBackground != -1); + return colorTextOnUnthemedDarkBackground; + } + + public static @ColorInt int getColorIconOnUnthemedDarkBackground() { + Assert.checkArgument(colorIconOnUnthemedDarkBackground != -1); + return colorIconOnUnthemedDarkBackground; + } +} diff --git a/java/com/android/dialer/theme/base/res/values/attr.xml b/java/com/android/dialer/theme/base/res/values/attr.xml new file mode 100644 index 000000000..41c6225ad --- /dev/null +++ b/java/com/android/dialer/theme/base/res/values/attr.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/java/com/android/dialer/theme/base/res/values/styles_dialer_light.xml b/java/com/android/dialer/theme/base/res/values/styles_dialer_light.xml new file mode 100644 index 000000000..cfdee7801 --- /dev/null +++ b/java/com/android/dialer/theme/base/res/values/styles_dialer_light.xml @@ -0,0 +1,53 @@ + + + + + + + + + + + + diff --git a/java/com/android/dialer/theme/base/res/values/theme_dialer_dark.xml b/java/com/android/dialer/theme/base/res/values/theme_dialer_dark.xml new file mode 100644 index 000000000..e01a3a282 --- /dev/null +++ b/java/com/android/dialer/theme/base/res/values/theme_dialer_dark.xml @@ -0,0 +1,64 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/java/com/android/dialer/theme/base/res/values/theme_dialer_light.xml b/java/com/android/dialer/theme/base/res/values/theme_dialer_light.xml new file mode 100644 index 000000000..667b9726d --- /dev/null +++ b/java/com/android/dialer/theme/base/res/values/theme_dialer_light.xml @@ -0,0 +1,81 @@ + + + + + + + + + + + + + + + + + + -- cgit v1.2.3