summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorSetup Wizard Team <android-setup-team-eng@google.com>2019-04-01 10:27:47 +0800
committerpastychang <pastychang@google.com>2019-04-01 14:23:59 +0800
commit88b04cc935a6f481c86043bc0030615155db3804 (patch)
tree7a653d60c6f23efc3a3f79aa33aca46e3756b353 /main
parent0b2f33bd2e3eb589d575e0413597e60cd88a90ea (diff)
downloadsetupdesign-88b04cc935a6f481c86043bc0030615155db3804.tar.gz
Import updated Android Setupdesign Library 241248644
Copied from google3/third_party/java_src/android_libs/setupdesign Test: mm Included changes: - 241248644 Recycleview apply light theme. - 241010758 Make ThemeResolver.resolve(String, boolean) public - 240935991 Move SystemBarHelper from setupdesign to setupcompat. - 240907444 Update dark mode text field color - 240262587 Move the minSDK version declaration to BUILD file - 240093474 Lint error - NewApi getMaxHeight. PiperOrigin-RevId: 241248644 Change-Id: Ida272f4332920d07fb56fd2bd7a4a9c9798d5f8f
Diffstat (limited to 'main')
-rw-r--r--main/AndroidManifest.xml4
-rw-r--r--main/res/drawable-v21/sud_edit_text_bg.xml (renamed from main/res/drawable-v21/sud_edittext_bg.xml)0
-rw-r--r--main/res/values-v21/styles.xml2
-rw-r--r--main/res/values/colors.xml3
-rw-r--r--main/res/values/styles.xml2
-rw-r--r--main/src/com/google/android/setupdesign/items/RecyclerItemAdapter.java29
-rw-r--r--main/src/com/google/android/setupdesign/template/IconMixin.java10
-rw-r--r--main/src/com/google/android/setupdesign/template/RecyclerMixin.java7
-rw-r--r--main/src/com/google/android/setupdesign/util/SystemBarHelper.java274
-rw-r--r--main/src/com/google/android/setupdesign/util/ThemeResolver.java40
10 files changed, 80 insertions, 291 deletions
diff --git a/main/AndroidManifest.xml b/main/AndroidManifest.xml
index e59c74a..245db97 100644
--- a/main/AndroidManifest.xml
+++ b/main/AndroidManifest.xml
@@ -16,6 +16,6 @@
-->
<manifest package="com.google.android.setupdesign">
- <!-- Set in the BUILD or gradle file -->
- <uses-sdk />
+ <!-- Set in the BUILD or gradle file -->
+ <uses-sdk />
</manifest>
diff --git a/main/res/drawable-v21/sud_edittext_bg.xml b/main/res/drawable-v21/sud_edit_text_bg.xml
index 8b352b7..8b352b7 100644
--- a/main/res/drawable-v21/sud_edittext_bg.xml
+++ b/main/res/drawable-v21/sud_edit_text_bg.xml
diff --git a/main/res/values-v21/styles.xml b/main/res/values-v21/styles.xml
index ee68651..79b006a 100644
--- a/main/res/values-v21/styles.xml
+++ b/main/res/values-v21/styles.xml
@@ -92,7 +92,7 @@
</style>
<style name="SudEditText" parent="@android:style/Widget.Material.EditText">
- <item name="android:background">@drawable/sud_edittext_bg</item>
+ <item name="android:background">@drawable/sud_edit_text_bg</item>
<item name="android:minHeight">@dimen/sud_edit_text_min_height</item>
<item name="android:paddingLeft">@dimen/sud_edit_text_padding_horizontal</item>
<item name="android:paddingRight">@dimen/sud_edit_text_padding_horizontal</item>
diff --git a/main/res/values/colors.xml b/main/res/values/colors.xml
index 0621c6b..1e9c24c 100644
--- a/main/res/values/colors.xml
+++ b/main/res/values/colors.xml
@@ -45,7 +45,8 @@
<color name="sud_color_accent_glif_v3">#ff1a73e8</color>
<color name="sud_glif_background_color_dark">#ff000000</color>
<color name="sud_glif_background_color_light">#ffffffff</color>
- <color name="sud_glif_edit_text_bg_light_color">#fff1f3f4</color>
+ <color name="sud_glif_edit_text_bg_dark_color">#0affffff</color>
+ <color name="sud_glif_edit_text_bg_light_color">#0a000000</color>
<color name="sud_glif_v3_nav_bar_color_light">#ffffffff</color>
<color name="sud_glif_v3_nav_bar_divider_color_light">#1f000000</color>
diff --git a/main/res/values/styles.xml b/main/res/values/styles.xml
index 620af4a..db812d8 100644
--- a/main/res/values/styles.xml
+++ b/main/res/values/styles.xml
@@ -196,7 +196,7 @@
<item name="sudDividerInsetStartNoIcon">?attr/sudMarginSides</item>
<item name="sudGlifHeaderGravity">center_horizontal</item>
<item name="sudScrollIndicators">top|bottom</item>
- <item name="sudEditTextBackgroundColor">@color/sud_glif_edit_text_bg_light_color</item> <!-- TODO: Change color -->
+ <item name="sudEditTextBackgroundColor">@color/sud_glif_edit_text_bg_dark_color</item>
<item name="android:editTextStyle">@style/SudEditText</item>
<item name="android:alertDialogTheme" tools:targetApi="honeycomb">@style/SudAlertDialogTheme</item>
<item name="sucLightStatusBar" tools:targetApi="m">?android:attr/windowLightStatusBar</item>
diff --git a/main/src/com/google/android/setupdesign/items/RecyclerItemAdapter.java b/main/src/com/google/android/setupdesign/items/RecyclerItemAdapter.java
index b8ba8a1..3577f7e 100644
--- a/main/src/com/google/android/setupdesign/items/RecyclerItemAdapter.java
+++ b/main/src/com/google/android/setupdesign/items/RecyclerItemAdapter.java
@@ -18,6 +18,7 @@ package com.google.android.setupdesign.items;
import android.content.res.TypedArray;
import android.graphics.Rect;
+import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import androidx.annotation.VisibleForTesting;
@@ -26,6 +27,8 @@ import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
+import com.google.android.setupcompat.partnerconfig.PartnerConfig;
+import com.google.android.setupcompat.partnerconfig.PartnerConfigHelper;
import com.google.android.setupdesign.R;
/**
@@ -57,9 +60,15 @@ public class RecyclerItemAdapter extends RecyclerView.Adapter<ItemViewHolder>
}
private final ItemHierarchy itemHierarchy;
+ private final boolean applyPartnerResource;
private OnItemSelectedListener listener;
public RecyclerItemAdapter(ItemHierarchy hierarchy) {
+ this(hierarchy, false);
+ }
+
+ public RecyclerItemAdapter(ItemHierarchy hierarchy, boolean applyPartnerResource) {
+ this.applyPartnerResource = applyPartnerResource;
itemHierarchy = hierarchy;
itemHierarchy.registerObserver(this);
}
@@ -94,6 +103,7 @@ public class RecyclerItemAdapter extends RecyclerView.Adapter<ItemViewHolder>
final LayoutInflater inflater = LayoutInflater.from(parent.getContext());
final View view = inflater.inflate(viewType, parent, false);
final ItemViewHolder viewHolder = new ItemViewHolder(view);
+ Drawable background = null;
final Object viewTag = view.getTag();
if (!TAG_NO_BACKGROUND.equals(viewTag)) {
@@ -105,12 +115,19 @@ public class RecyclerItemAdapter extends RecyclerView.Adapter<ItemViewHolder>
if (selectableItemBackground == null) {
selectableItemBackground =
typedArray.getDrawable(R.styleable.SudRecyclerItemAdapter_selectableItemBackground);
- }
-
- Drawable background = view.getBackground();
- if (background == null) {
- background =
- typedArray.getDrawable(R.styleable.SudRecyclerItemAdapter_android_colorBackground);
+ } else {
+ background = view.getBackground();
+ if (background == null) {
+ if (applyPartnerResource) {
+ int color =
+ PartnerConfigHelper.get(view.getContext())
+ .getColor(view.getContext(), PartnerConfig.CONFIG_LAYOUT_BACKGROUND_COLOR);
+ background = new ColorDrawable(color);
+ } else {
+ background =
+ typedArray.getDrawable(R.styleable.SudRecyclerItemAdapter_android_colorBackground);
+ }
+ }
}
if (selectableItemBackground == null || background == null) {
diff --git a/main/src/com/google/android/setupdesign/template/IconMixin.java b/main/src/com/google/android/setupdesign/template/IconMixin.java
index d68daa4..d0a85c3 100644
--- a/main/src/com/google/android/setupdesign/template/IconMixin.java
+++ b/main/src/com/google/android/setupdesign/template/IconMixin.java
@@ -20,6 +20,8 @@ import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
+import android.os.Build.VERSION;
+import android.os.Build.VERSION_CODES;
import androidx.annotation.ColorInt;
import androidx.annotation.DrawableRes;
import android.util.AttributeSet;
@@ -135,10 +137,16 @@ public class IconMixin implements Mixin {
/** Forces the icon view to be as big as desired in the style. */
public void setUpscaleIcon(boolean shouldUpscaleIcon) {
+ final int maxHeight;
final ImageView iconView = getView();
if (iconView != null) {
LayoutParams layoutParams = iconView.getLayoutParams();
- layoutParams.height = shouldUpscaleIcon ? iconView.getMaxHeight() : originalHeight;
+ if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN) {
+ maxHeight = iconView.getMaxHeight();
+ } else {
+ maxHeight = (int) iconView.getResources().getDimension(R.dimen.sud_glif_icon_max_height);
+ }
+ layoutParams.height = shouldUpscaleIcon ? maxHeight : originalHeight;
iconView.setLayoutParams(layoutParams);
iconView.setScaleType(shouldUpscaleIcon ? ImageView.ScaleType.FIT_CENTER : originalScaleType);
}
diff --git a/main/src/com/google/android/setupdesign/template/RecyclerMixin.java b/main/src/com/google/android/setupdesign/template/RecyclerMixin.java
index 1432a44..d017916 100644
--- a/main/src/com/google/android/setupdesign/template/RecyclerMixin.java
+++ b/main/src/com/google/android/setupdesign/template/RecyclerMixin.java
@@ -29,6 +29,7 @@ import androidx.recyclerview.widget.RecyclerView.Adapter;
import androidx.recyclerview.widget.RecyclerView.ViewHolder;
import android.util.AttributeSet;
import android.view.View;
+import com.google.android.setupcompat.PartnerCustomizationLayout;
import com.google.android.setupcompat.internal.TemplateLayout;
import com.google.android.setupcompat.template.Mixin;
import com.google.android.setupdesign.DividerItemDecoration;
@@ -105,7 +106,11 @@ public class RecyclerMixin implements Mixin {
final int entries = a.getResourceId(R.styleable.SudRecyclerMixin_android_entries, 0);
if (entries != 0) {
final ItemHierarchy inflated = new ItemInflater(context).inflate(entries);
- final RecyclerItemAdapter adapter = new RecyclerItemAdapter(inflated);
+
+ boolean applyPartnerResource =
+ ((PartnerCustomizationLayout) templateLayout).shouldApplyPartnerResource();
+
+ final RecyclerItemAdapter adapter = new RecyclerItemAdapter(inflated, applyPartnerResource);
adapter.setHasStableIds(a.getBoolean(R.styleable.SudRecyclerMixin_sudHasStableIds, false));
setAdapter(adapter);
}
diff --git a/main/src/com/google/android/setupdesign/util/SystemBarHelper.java b/main/src/com/google/android/setupdesign/util/SystemBarHelper.java
deleted file mode 100644
index 467c4dc..0000000
--- a/main/src/com/google/android/setupdesign/util/SystemBarHelper.java
+++ /dev/null
@@ -1,274 +0,0 @@
-/*
- * Copyright (C) 2015 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.google.android.setupdesign.util;
-
-import android.annotation.TargetApi;
-import android.app.Dialog;
-import android.content.Context;
-import android.content.res.TypedArray;
-import android.os.Build.VERSION;
-import android.os.Build.VERSION_CODES;
-import android.os.Handler;
-import androidx.annotation.RequiresPermission;
-import android.view.View;
-import android.view.ViewGroup;
-import android.view.Window;
-import android.view.WindowInsets;
-import android.view.WindowManager;
-import com.google.android.setupcompat.util.SystemBarBaseHelper;
-
-/**
- * A helper class to manage the system navigation bar and status bar. This will add various
- * systemUiVisibility flags to the given Window or View to make them follow the Setup Wizard style.
- *
- * <p>When the useImmersiveMode intent extra is true, a screen in Setup Wizard should hide the
- * system bars using methods from this class. For Lollipop, {@link
- * #hideSystemBars(android.view.Window)} will completely hide the system navigation bar and change
- * the status bar to transparent, and layout the screen contents (usually the illustration) behind
- * it.
- */
-public class SystemBarHelper {
-
- private static final String TAG = "SystemBarHelper";
-
- /** Needs to be equal to View.STATUS_BAR_DISABLE_BACK */
- private static final int STATUS_BAR_DISABLE_BACK = 0x00400000;
-
- /**
- * Hide the navigation bar for a dialog.
- *
- * <p>This will only take effect in versions Lollipop or above. Otherwise this is a no-op.
- *
- * @deprecated If the layout is instance of TemplateLayout, please use
- * SystemNavBarMixin.hideSystemBars.
- */
- @Deprecated
- public static void hideSystemBars(final Dialog dialog) {
- if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
- final Window window = dialog.getWindow();
- temporarilyDisableDialogFocus(window);
- SystemBarBaseHelper.addVisibilityFlag(window, SystemBarBaseHelper.DIALOG_IMMERSIVE_FLAGS);
- SystemBarBaseHelper.addImmersiveFlagsToDecorView(
- window, SystemBarBaseHelper.DIALOG_IMMERSIVE_FLAGS);
-
- // Also set the navigation bar and status bar to transparent color. Note that this
- // doesn't work if android.R.boolean.config_enableTranslucentDecor is false.
- window.setNavigationBarColor(0);
- window.setStatusBarColor(0);
- }
- }
-
- /**
- * Hide the navigation bar, make the color of the status and navigation bars transparent, and
- * specify {@link View#SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN} flag so that the content is laid-out
- * behind the transparent status bar. This is commonly used with {@link
- * android.app.Activity#getWindow()} to make the navigation and status bars follow the Setup
- * Wizard style.
- *
- * <p>This will only take effect in versions Lollipop or above. Otherwise this is a no-op.
- *
- * @deprecated If the layout instance of TemplateLayout, please use
- * SystemNavBarMixin.hideSystemBars.
- */
- @Deprecated
- public static void hideSystemBars(final Window window) {
- if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
- SystemBarBaseHelper.addVisibilityFlag(window, SystemBarBaseHelper.DEFAULT_IMMERSIVE_FLAGS);
- SystemBarBaseHelper.addImmersiveFlagsToDecorView(
- window, SystemBarBaseHelper.DEFAULT_IMMERSIVE_FLAGS);
-
- // Also set the navigation bar and status bar to transparent color. Note that this
- // doesn't work if android.R.boolean.config_enableTranslucentDecor is false.
- window.setNavigationBarColor(0);
- window.setStatusBarColor(0);
- }
- }
-
- /**
- * Revert the actions of hideSystemBars. Note that this will remove the system UI visibility flags
- * regardless of whether it is originally present. You should also manually reset the navigation
- * bar and status bar colors, as this method doesn't know what value to revert it to.
- *
- * @deprecated If the layout is instance of TemplateLayout, please use
- * SystemNavBarMixin.showSystemBars.
- */
- @Deprecated
- public static void showSystemBars(final Window window, final Context context) {
- if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
- SystemBarBaseHelper.removeVisibilityFlag(window, SystemBarBaseHelper.DEFAULT_IMMERSIVE_FLAGS);
- SystemBarBaseHelper.removeImmersiveFlagsFromDecorView(
- window, SystemBarBaseHelper.DEFAULT_IMMERSIVE_FLAGS);
-
- if (context != null) {
- //noinspection AndroidLintInlinedApi
- final TypedArray typedArray =
- context.obtainStyledAttributes(
- new int[] {android.R.attr.statusBarColor, android.R.attr.navigationBarColor});
- final int statusBarColor = typedArray.getColor(0, 0);
- final int navigationBarColor = typedArray.getColor(1, 0);
- window.setStatusBarColor(statusBarColor);
- window.setNavigationBarColor(navigationBarColor);
- typedArray.recycle();
- }
- }
- }
-
- /**
- * Convenience method to add a visibility flag in addition to the existing ones.
- *
- * @deprecated Use SystemBarBaseHelper.addVisibilityFlag(final View view, final int flag).
- */
- @Deprecated
- public static void addVisibilityFlag(final View view, final int flag) {
- SystemBarBaseHelper.addVisibilityFlag(view, flag);
- }
-
- /**
- * Convenience method to add a visibility flag in addition to the existing ones.
- *
- * @deprecated Use SystemBarBaseHelper.addVisibilityFlag(final Window window, final int flag).
- */
- @Deprecated
- public static void addVisibilityFlag(final Window window, final int flag) {
- SystemBarBaseHelper.addVisibilityFlag(window, flag);
- }
-
- /**
- * Convenience method to remove a visibility flag from the view, leaving other flags that are not
- * specified intact.
- *
- * @deprecated Use SystemBarBaseHelper.removeVisibilityFlag(final View view, final int flag).
- */
- @Deprecated
- public static void removeVisibilityFlag(final View view, final int flag) {
- SystemBarBaseHelper.removeVisibilityFlag(view, flag);
- }
-
- /**
- * Convenience method to remove a visibility flag from the window, leaving other flags that are
- * not specified intact.
- *
- * @deprecated Use SystemBarBaseHelper.removeVisibilityFlag(final Window window, final int flag).
- */
- @Deprecated
- public static void removeVisibilityFlag(final Window window, final int flag) {
- SystemBarBaseHelper.removeVisibilityFlag(window, flag);
- }
-
- /**
- * Sets whether the back button on the software navigation bar is visible. This only works if you
- * have the STATUS_BAR permission. Otherwise framework will filter out this flag and this method
- * call will not have any effect.
- *
- * <p>IMPORTANT: Do not assume that users have no way to go back when the back button is hidden.
- * Many devices have physical back buttons, and accessibility services like TalkBack may have
- * gestures mapped to back. Please use onBackPressed, onKeyDown, or other similar ways to make
- * sure back button events are still handled (or ignored) properly.
- */
- @RequiresPermission("android.permission.STATUS_BAR")
- public static void setBackButtonVisible(final Window window, final boolean visible) {
- if (VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB) {
- if (visible) {
- SystemBarBaseHelper.removeVisibilityFlag(window, STATUS_BAR_DISABLE_BACK);
- SystemBarBaseHelper.removeImmersiveFlagsFromDecorView(window, STATUS_BAR_DISABLE_BACK);
- } else {
- SystemBarBaseHelper.addVisibilityFlag(window, STATUS_BAR_DISABLE_BACK);
- SystemBarBaseHelper.addImmersiveFlagsToDecorView(window, STATUS_BAR_DISABLE_BACK);
- }
- }
- }
-
- /**
- * Set a view to be resized when the keyboard is shown. This will set the bottom margin of the
- * view to be immediately above the keyboard, and assumes that the view sits immediately above the
- * navigation bar.
- *
- * <p>Note that you must set {@link android.R.attr#windowSoftInputMode} to {@code adjustResize}
- * for this class to work. Otherwise window insets are not dispatched and this method will have no
- * effect.
- *
- * <p>This will only take effect in versions Lollipop or above. Otherwise this is a no-op.
- *
- * @param view The view to be resized when the keyboard is shown.
- */
- public static void setImeInsetView(final View view) {
- if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
- view.setOnApplyWindowInsetsListener(new WindowInsetsListener());
- }
- }
-
- /**
- * Apply a hack to temporarily set the window to not focusable, so that the navigation bar will
- * not show up during the transition.
- */
- private static void temporarilyDisableDialogFocus(final Window window) {
- window.setFlags(
- WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
- WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
- // Add the SOFT_INPUT_IS_FORWARD_NAVIGATION_FLAG. This is normally done by the system when
- // FLAG_NOT_FOCUSABLE is not set. Setting this flag allows IME to be shown automatically
- // if the dialog has editable text fields.
- window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION);
- new Handler()
- .post(
- new Runnable() {
- @Override
- public void run() {
- window.clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
- }
- });
- }
-
- @TargetApi(VERSION_CODES.LOLLIPOP)
- private static class WindowInsetsListener implements View.OnApplyWindowInsetsListener {
- private int bottomOffset;
- private boolean hasCalculatedBottomOffset = false;
-
- @Override
- public WindowInsets onApplyWindowInsets(View view, WindowInsets insets) {
- if (!hasCalculatedBottomOffset) {
- bottomOffset = getBottomDistance(view);
- hasCalculatedBottomOffset = true;
- }
-
- int bottomInset = insets.getSystemWindowInsetBottom();
-
- final int bottomMargin = Math.max(insets.getSystemWindowInsetBottom() - bottomOffset, 0);
-
- final ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) view.getLayoutParams();
- // Check that we have enough space to apply the bottom margins before applying it.
- // Otherwise the framework may think that the view is empty and exclude it from layout.
- if (bottomMargin < lp.bottomMargin + view.getHeight()) {
- lp.setMargins(lp.leftMargin, lp.topMargin, lp.rightMargin, bottomMargin);
- view.setLayoutParams(lp);
- bottomInset = 0;
- }
-
- return insets.replaceSystemWindowInsets(
- insets.getSystemWindowInsetLeft(),
- insets.getSystemWindowInsetTop(),
- insets.getSystemWindowInsetRight(),
- bottomInset);
- }
- }
-
- private static int getBottomDistance(View view) {
- int[] coords = new int[2];
- view.getLocationInWindow(coords);
- return view.getRootView().getHeight() - coords[1] - view.getHeight();
- }
-}
diff --git a/main/src/com/google/android/setupdesign/util/ThemeResolver.java b/main/src/com/google/android/setupdesign/util/ThemeResolver.java
index d0264e0..03d90e5 100644
--- a/main/src/com/google/android/setupdesign/util/ThemeResolver.java
+++ b/main/src/com/google/android/setupdesign/util/ThemeResolver.java
@@ -35,6 +35,7 @@ public class ThemeResolver {
@StyleRes private final int defaultTheme;
@Nullable private final String oldestSupportedTheme;
private final boolean useDayNight;
+ @Nullable private final ThemeSupplier defaultThemeSupplier;
@Nullable private static ThemeResolver defaultResolver;
@@ -61,9 +62,13 @@ public class ThemeResolver {
}
private ThemeResolver(
- int defaultTheme, @Nullable String oldestSupportedTheme, boolean useDayNight) {
+ int defaultTheme,
+ @Nullable String oldestSupportedTheme,
+ @Nullable ThemeSupplier defaultThemeSupplier,
+ boolean useDayNight) {
this.defaultTheme = defaultTheme;
this.oldestSupportedTheme = oldestSupportedTheme;
+ this.defaultThemeSupplier = defaultThemeSupplier;
this.useDayNight = useDayNight;
}
@@ -85,18 +90,34 @@ public class ThemeResolver {
* oldest supported theme, the default will be returned instead. Note that the default theme is
* returned without processing -- it may not be a DayNight theme even if {@link #useDayNight} is
* true.
+ *
+ * @deprecated Use {@link #resolve(String, boolean)} instead
*/
+ @Deprecated
@StyleRes
public int resolve(@Nullable String theme) {
return resolve(theme, /* suppressDayNight= */ false);
}
+ /**
+ * Returns the style for the given string theme. If the specified string theme is older than the
+ * oldest supported theme, the default will be returned instead. Note that the default theme is
+ * returned without processing -- it may not be a DayNight theme even if {@link #useDayNight} is
+ * true.
+ */
@StyleRes
- private int resolve(@Nullable String theme, boolean suppressDayNight) {
+ public int resolve(@Nullable String theme, boolean suppressDayNight) {
int themeResource =
useDayNight && !suppressDayNight ? getDayNightThemeRes(theme) : getThemeRes(theme);
if (themeResource == 0) {
- return defaultTheme;
+ if (defaultThemeSupplier != null) {
+ theme = defaultThemeSupplier.getTheme();
+ themeResource =
+ useDayNight && !suppressDayNight ? getDayNightThemeRes(theme) : getThemeRes(theme);
+ }
+ if (themeResource == 0) {
+ return defaultTheme;
+ }
}
if (oldestSupportedTheme != null && compareThemes(theme, oldestSupportedTheme) < 0) {
@@ -203,6 +224,7 @@ public class ThemeResolver {
/** Builder class for {@link ThemeResolver}. */
public static class Builder {
+ private ThemeSupplier defaultThemeSupplier;
@StyleRes private int defaultTheme = R.style.SudThemeGlif_DayNight;
@Nullable private String oldestSupportedTheme = null;
private boolean useDayNight = true;
@@ -215,6 +237,11 @@ public class ThemeResolver {
this.useDayNight = themeResolver.useDayNight;
}
+ public Builder setDefaultThemeSupplier(ThemeSupplier defaultThemeSupplier) {
+ this.defaultThemeSupplier = defaultThemeSupplier;
+ return this;
+ }
+
public Builder setDefaultTheme(@StyleRes int defaultTheme) {
this.defaultTheme = defaultTheme;
return this;
@@ -231,7 +258,12 @@ public class ThemeResolver {
}
public ThemeResolver build() {
- return new ThemeResolver(defaultTheme, oldestSupportedTheme, useDayNight);
+ return new ThemeResolver(
+ defaultTheme, oldestSupportedTheme, defaultThemeSupplier, useDayNight);
}
}
+
+ public interface ThemeSupplier {
+ String getTheme();
+ }
}