summaryrefslogtreecommitdiff
path: root/java/com/android/dialer/theme
diff options
context:
space:
mode:
authorcalderwoodra <calderwoodra@google.com>2018-05-23 12:59:03 -0700
committerCopybara-Service <copybara-piper@google.com>2018-05-29 23:26:22 -0700
commita93df43762f1539593da5f90bec16be2be01d281 (patch)
tree88c45d7ab1bd0242f6a0873158da6e5152e82ecd /java/com/android/dialer/theme
parentffd525d8eb9dbe1bc4d87909b01371743c296a16 (diff)
Converted ThemeUtil into a DaggerModule.
This enables us to have Google-Sans font in GoogleDialer and Roboto in AOSP. Bug: 79883035 Test: tap PiperOrigin-RevId: 197774497 Change-Id: I1d490ab196a444c62e439444627d659fc42973ea
Diffstat (limited to 'java/com/android/dialer/theme')
-rw-r--r--java/com/android/dialer/theme/base/Theme.java76
-rw-r--r--java/com/android/dialer/theme/base/ThemeComponent.java40
-rw-r--r--java/com/android/dialer/theme/base/impl/AospThemeImpl.java (renamed from java/com/android/dialer/theme/base/ThemeUtil.java)104
-rw-r--r--java/com/android/dialer/theme/base/impl/AospThemeModule.java36
-rw-r--r--java/com/android/dialer/theme/common/res/values/text_styles.xml23
-rw-r--r--java/com/android/dialer/theme/res/values/theme_dialer_light.xml117
6 files changed, 224 insertions, 172 deletions
diff --git a/java/com/android/dialer/theme/base/Theme.java b/java/com/android/dialer/theme/base/Theme.java
new file mode 100644
index 000000000..6e0d20a7a
--- /dev/null
+++ b/java/com/android/dialer/theme/base/Theme.java
@@ -0,0 +1,76 @@
+/*
+ * 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.support.annotation.ColorInt;
+import android.support.annotation.IntDef;
+import android.support.annotation.StyleRes;
+import android.view.LayoutInflater;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+/** Interface for theme. */
+public interface Theme {
+
+ /** IntDef for the different themes Dialer supports. */
+ @Retention(RetentionPolicy.SOURCE)
+ @IntDef({UNKNOWN, LIGHT, DARK, LIGHT_M2})
+ @interface Type {}
+
+ int UNKNOWN = 0;
+ int LIGHT = 1;
+ int DARK = 2;
+ int LIGHT_M2 = 3;
+
+ @Type
+ int getTheme();
+
+ @StyleRes
+ int getApplicationThemeRes();
+
+ Context getThemedContext(Context context);
+
+ LayoutInflater getThemedLayoutInflator(LayoutInflater inflater);
+
+ @ColorInt
+ int getColorIcon();
+
+ @ColorInt
+ int getColorIconSecondary();
+
+ @ColorInt
+ int getColorPrimary();
+
+ @ColorInt
+ int getColorPrimaryDark();
+
+ @ColorInt
+ int getColorAccent();
+
+ @ColorInt
+ int getTextColorSecondary();
+
+ @ColorInt
+ int getTextColorPrimary();
+
+ @ColorInt
+ int getColorTextOnUnthemedDarkBackground();
+
+ @ColorInt
+ int getColorIconOnUnthemedDarkBackground();
+}
diff --git a/java/com/android/dialer/theme/base/ThemeComponent.java b/java/com/android/dialer/theme/base/ThemeComponent.java
new file mode 100644
index 000000000..d9067616f
--- /dev/null
+++ b/java/com/android/dialer/theme/base/ThemeComponent.java
@@ -0,0 +1,40 @@
+/*
+ * 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 com.android.dialer.inject.HasRootComponent;
+import com.android.dialer.inject.IncludeInDialerRoot;
+import dagger.Subcomponent;
+
+/** Component for Theme. */
+@Subcomponent
+public abstract class ThemeComponent {
+
+ public abstract Theme theme();
+
+ public static ThemeComponent get(Context context) {
+ return ((HasComponent) ((HasRootComponent) context.getApplicationContext()).component())
+ .themeComponent();
+ }
+
+ /** Used to refer to the root application component. */
+ @IncludeInDialerRoot
+ public interface HasComponent {
+ ThemeComponent themeComponent();
+ }
+}
diff --git a/java/com/android/dialer/theme/base/ThemeUtil.java b/java/com/android/dialer/theme/base/impl/AospThemeImpl.java
index a2d70c951..b8c7e528f 100644
--- a/java/com/android/dialer/theme/base/ThemeUtil.java
+++ b/java/com/android/dialer/theme/base/impl/AospThemeImpl.java
@@ -14,51 +14,39 @@
* limitations under the License.
*/
-package com.android.dialer.theme.base;
+package com.android.dialer.theme.base.impl;
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;
+import com.android.dialer.theme.base.R;
+import com.android.dialer.theme.base.Theme;
+import javax.inject.Singleton;
/** 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;
+@Singleton
+public class AospThemeImpl implements Theme {
+
+ private int colorIcon = -1;
+ private int colorIconSecondary = -1;
+ private int colorPrimary = -1;
+ private int colorPrimaryDark = -1;
+ private int colorAccent = -1;
+ private int textColorPrimary = -1;
+ private int textColorSecondary = -1;
+ private int textColorPrimaryInverse = -1;
+ private int textColorHint = -1;
+ private int colorBackground = -1;
+ private int colorBackgroundFloating = -1;
+ private int colorTextOnUnthemedDarkBackground = -1;
+ private int colorIconOnUnthemedDarkBackground = -1;
+
+ public AospThemeImpl(Context context) {
context = context.getApplicationContext();
context.setTheme(getApplicationThemeRes());
@@ -102,13 +90,15 @@ public class ThemeUtil {
* 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;
+ @Override
+ public @Type int getTheme() {
+ // TODO(a bug): add share prefs check to configure this
+ return LIGHT;
}
- public static @StyleRes int getApplicationThemeRes() {
- switch (theme) {
+ @Override
+ public @StyleRes int getApplicationThemeRes() {
+ switch (getTheme()) {
case DARK:
return R.style.Dialer_Dark_ThemeBase_NoActionBar;
case LIGHT:
@@ -119,50 +109,66 @@ public class ThemeUtil {
}
}
- public static Context getThemedContext(Context context) {
+ @Override
+ public Context getThemedContext(Context context) {
return new ContextThemeWrapper(context, getApplicationThemeRes());
}
- public static LayoutInflater getThemedLayoutInflator(LayoutInflater inflater) {
+ @Override
+ public LayoutInflater getThemedLayoutInflator(LayoutInflater inflater) {
return inflater.cloneInContext(getThemedContext(inflater.getContext()));
}
- public static @ColorInt int getColorIcon() {
+ @Override
+ public @ColorInt int getColorIcon() {
Assert.checkArgument(colorIcon != -1);
return colorIcon;
}
- public static @ColorInt int getColorIconSecondary() {
+ @Override
+ public @ColorInt int getColorIconSecondary() {
Assert.checkArgument(colorIconSecondary != -1);
return colorIconSecondary;
}
- public static @ColorInt int getColorPrimary() {
+ @Override
+ public @ColorInt int getColorPrimary() {
Assert.checkArgument(colorPrimary != -1);
return colorPrimary;
}
- public static @ColorInt int getColorAccent() {
+ @Override
+ public int getColorPrimaryDark() {
+ Assert.checkArgument(colorPrimary != -1);
+ return 0;
+ }
+
+ @Override
+ public @ColorInt int getColorAccent() {
Assert.checkArgument(colorAccent != -1);
return colorAccent;
}
- public static @ColorInt int getTextColorSecondary() {
+ @Override
+ public @ColorInt int getTextColorSecondary() {
Assert.checkArgument(textColorSecondary != -1);
return textColorSecondary;
}
- public static @ColorInt int getTextColorPrimary() {
+ @Override
+ public @ColorInt int getTextColorPrimary() {
Assert.checkArgument(textColorPrimary != -1);
return textColorPrimary;
}
- public static @ColorInt int getColorTextOnUnthemedDarkBackground() {
+ @Override
+ public @ColorInt int getColorTextOnUnthemedDarkBackground() {
Assert.checkArgument(colorTextOnUnthemedDarkBackground != -1);
return colorTextOnUnthemedDarkBackground;
}
- public static @ColorInt int getColorIconOnUnthemedDarkBackground() {
+ @Override
+ public @ColorInt int getColorIconOnUnthemedDarkBackground() {
Assert.checkArgument(colorIconOnUnthemedDarkBackground != -1);
return colorIconOnUnthemedDarkBackground;
}
diff --git a/java/com/android/dialer/theme/base/impl/AospThemeModule.java b/java/com/android/dialer/theme/base/impl/AospThemeModule.java
new file mode 100644
index 000000000..7cf52cadd
--- /dev/null
+++ b/java/com/android/dialer/theme/base/impl/AospThemeModule.java
@@ -0,0 +1,36 @@
+/*
+ * 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.impl;
+
+import android.content.Context;
+import com.android.dialer.inject.ApplicationContext;
+import com.android.dialer.inject.DialerVariant;
+import com.android.dialer.inject.InstallIn;
+import com.android.dialer.theme.base.Theme;
+import dagger.Module;
+import dagger.Provides;
+
+/** Module which binds {@link AospThemeImpl}. */
+@InstallIn(variants = {DialerVariant.DIALER_TEST})
+@Module
+public class AospThemeModule {
+
+ @Provides
+ static Theme provideThemeModule(@ApplicationContext Context context) {
+ return new AospThemeImpl(context);
+ }
+}
diff --git a/java/com/android/dialer/theme/common/res/values/text_styles.xml b/java/com/android/dialer/theme/common/res/values/text_styles.xml
index 9cf4a7689..def5862d4 100644
--- a/java/com/android/dialer/theme/common/res/values/text_styles.xml
+++ b/java/com/android/dialer/theme/common/res/values/text_styles.xml
@@ -31,6 +31,12 @@
<item name="android:fontFamily">sans-serif-medium</item>
</style>
+ <style name="Dialer.TextAppearance.SubHeader" parent="TextAppearance.AppCompat">
+ <item name="android:textColor">?android:attr/textColorPrimary</item>
+ <item name="android:textSize">16sp</item>
+ <item name="android:fontFamily">sans-serif-medium</item>
+ </style>
+
<style name="Dialer.TextAppearance.Primary" parent="TextAppearance.AppCompat">
<item name="android:textColor">?android:attr/textColorPrimary</item>
<item name="android:textSize">16sp</item>
@@ -55,32 +61,37 @@
<item name="android:fontFamily">sans-serif-medium</item>
</style>
- <style name="Dialer.TextAppearance.Header1.Ellipsize" parent="Dialer.TextAppearance.Header1">
+ <style name="Dialer.TextAppearance.Header1.Ellipsize">
+ <item name="android:ellipsize">end</item>
+ <item name="android:maxLines">1</item>
+ </style>
+
+ <style name="Dialer.TextAppearance.Header2.Ellipsize">
<item name="android:ellipsize">end</item>
<item name="android:maxLines">1</item>
</style>
- <style name="Dialer.TextAppearance.Header2.Ellipsize" parent="Dialer.TextAppearance.Header2">
+ <style name="Dialer.TextAppearance.SubHeader.Ellipsize">
<item name="android:ellipsize">end</item>
<item name="android:maxLines">1</item>
</style>
- <style name="Dialer.TextAppearance.Primary.Ellipsize" parent="Dialer.TextAppearance.Primary">
+ <style name="Dialer.TextAppearance.Primary.Ellipsize">
<item name="android:ellipsize">end</item>
<item name="android:maxLines">1</item>
</style>
- <style name="Dialer.TextAppearance.Secondary.Ellipsize" parent="Dialer.TextAppearance.Secondary">
+ <style name="Dialer.TextAppearance.Secondary.Ellipsize">
<item name="android:ellipsize">end</item>
<item name="android:maxLines">1</item>
</style>
- <style name="Dialer.TextAppearance.Secondary2.Ellipsize" parent="Dialer.TextAppearance.Secondary">
+ <style name="Dialer.TextAppearance.Secondary2.Ellipsize">
<item name="android:ellipsize">end</item>
<item name="android:maxLines">1</item>
</style>
- <style name="Dialer.TextAppearance.OVERLINE.Ellipsize" parent="Dialer.TextAppearance.OVERLINE">
+ <style name="Dialer.TextAppearance.OVERLINE.Ellipsize">
<item name="android:ellipsize">end</item>
<item name="android:maxLines">1</item>
</style>
diff --git a/java/com/android/dialer/theme/res/values/theme_dialer_light.xml b/java/com/android/dialer/theme/res/values/theme_dialer_light.xml
deleted file mode 100644
index ab4ae936d..000000000
--- a/java/com/android/dialer/theme/res/values/theme_dialer_light.xml
+++ /dev/null
@@ -1,117 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- ~ 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
- -->
-<resources>
-
- <style name="Dialer"/>
-
- <!-- Should be kept in sync with the theme below (minus anything related to actionbars) -->
- <style name="Dialer.ThemeBase" parent="@style/Theme.AppCompat.Light.DarkActionBar">
- <item name="android:textAppearanceButton">@style/DialerButtonTextStyle</item>
-
- <!-- These values should be used to color all backgrounds. -->
- <item name="android:colorBackground">@color/dialer_background_light</item>
- <item name="android:colorBackgroundFloating">@color/dialer_background_floating_light</item>
-
- <!-- These values should be used to set text color. -->
- <item name="android:textColorPrimary">@color/dialer_primary_text_color</item>
- <item name="android:textColorSecondary">@color/dialer_secondary_text_color</item>
- <item name="android:textColorPrimaryInverse">@color/dialer_primary_text_color_inverse</item>
- <item name="android:textColorSecondaryInverse">@color/dialer_secondary_text_color_inverse</item>
- <item name="android:textColorHint">@color/dialer_text_hint_color</item>
-
- <!-- These will be automatically used to color most Appcompat/Material widgets. -->
- <item name="android:colorPrimary">@color/dialer_theme_color</item>
- <item name="colorPrimary">@color/dialer_theme_color</item>
- <item name="android:colorPrimaryDark">@color/dialer_theme_color</item>
- <item name="colorPrimaryDark">@color/dialer_theme_color</item>
- <item name="android:colorAccent">@color/dialer_secondary_color</item>
- <item name="colorAccent">@color/dialer_secondary_color</item>
-
- <!-- Used to automatically style check/selected checkbox, switches and radio buttons -->
- <item name="colorControlActivated">?android:attr/colorPrimary</item>
-
- <!-- Used to automatically style AlertDialogs -->
- <item name="alertDialogTheme">@style/AlertDialogTheme</item>
-
- <!-- Dialer specific attributes. -->
- <item name="colorIcon">@color/dialer_secondary_text_color</item>
-
- <!-- These are used to style the actionbar. -->
- <item name="actionBarStyle">@style/DialerActionBarBaseStyle</item>
- <item name="actionBarSize">@dimen/action_bar_height</item>
-
- <!-- Theme for the dialpad. -->
- <item name="dialpad_style">@style/Dialpad.Light</item>
- </style>
-
- <!-- Should be kept in sync with the theme above (minus anything related to actionbars) -->
- <style name="Dialer.ThemeBase.NoActionBar" parent="@style/Theme.AppCompat.Light.NoActionBar">
- <!-- These values should be used to color all backgrounds. -->
- <item name="android:colorBackground">@color/dialer_background_light</item>
- <item name="android:colorBackgroundFloating">@color/dialer_background_floating_light</item>
-
- <!-- These values should be used to set text color. -->
- <item name="android:textColorPrimary">@color/dialer_primary_text_color</item>
- <item name="android:textColorSecondary">@color/dialer_secondary_text_color</item>
- <item name="android:textColorPrimaryInverse">@color/dialer_primary_text_color_inverse</item>
- <item name="android:textColorSecondaryInverse">@color/dialer_secondary_text_color_inverse</item>
- <item name="android:textColorHint">@color/dialer_text_hint_color</item>
- <item name="android:textColorLink">@color/dialer_theme_color</item>
-
- <!-- These will be automatically used to color most Appcompat/Material widgets. -->
- <item name="android:colorPrimary">@color/dialer_theme_color</item>
- <item name="colorPrimary">@color/dialer_theme_color</item>
- <item name="android:colorPrimaryDark">@color/dialer_theme_color_dark</item>
- <item name="colorPrimaryDark">@color/dialer_theme_color_dark</item>
- <item name="android:colorAccent">@color/dialer_secondary_color</item>
- <item name="colorAccent">@color/dialer_secondary_color</item>
-
- <!-- Used for material buttons and widgets -->
- <item name="android:colorButtonNormal">@color/dialer_theme_color</item>
- <item name="android:textAppearanceButton">@style/DialerButtonTextStyle</item>
-
- <!-- Used to automatically style check/selected checkbox, switches and radio buttons -->
- <item name="colorControlActivated">?android:attr/colorPrimary</item>
-
- <!-- Used to automatically style AlertDialogs -->
- <item name="alertDialogTheme">@style/AlertDialogTheme</item>
-
- <!-- Dialer specific attributes. -->
- <item name="colorIcon">@color/dialer_secondary_text_color</item>
-
- <!-- Theme for the dialpad. -->
- <item name="dialpad_style">@style/Dialpad.Light</item>
- </style>
-
- <!-- TODO(a bug): flesh this out some more. -->
- <style name="Dialer.ThemeBase.NoActionBar.Dark" parent="Dialer.ThemeBase.NoActionBar">
- <!-- swap text colors. -->
- <item name="android:textColorPrimary">@color/dialer_primary_text_color_inverse</item>
- <item name="android:textColorSecondary">@color/dialer_secondary_text_color_inverse</item>
- <item name="android:textColorPrimaryInverse">@color/dialer_primary_text_color</item>
- <item name="android:textColorSecondaryInverse">@color/dialer_secondary_text_color</item>
- </style>
-
- <!-- TODO(a bug): investigate making this style's parent Dialer.ThemeBase.NoActionBar -->
- <style name="Theme.AppCompat.Translucent" parent="Theme.AppCompat.NoActionBar">
- <item name="android:windowNoTitle">true</item>
- <item name="android:windowBackground">@android:color/transparent</item>
- <item name="android:colorBackgroundCacheHint">@null</item>
- <item name="android:windowIsTranslucent">true</item>
- <item name="android:windowAnimationStyle">@android:style/Animation</item>
- </style>
-</resources>