diff options
Diffstat (limited to 'main/src')
5 files changed, 111 insertions, 77 deletions
diff --git a/main/src/com/google/android/setupdesign/GlifLayout.java b/main/src/com/google/android/setupdesign/GlifLayout.java index c9e159e..829e3d7 100644 --- a/main/src/com/google/android/setupdesign/GlifLayout.java +++ b/main/src/com/google/android/setupdesign/GlifLayout.java @@ -458,6 +458,12 @@ public class GlifLayout extends PartnerCustomizationLayout { /** Updates the background color of this layout with the partner-customizable background color. */ private void updateContentBackgroundColorWithPartnerConfig() { + // If full dynamic color enabled which means this activity is running outside of setup + // flow, the colors should refer to R.style.SudFullDynamicColorThemeGlifV3. + if (useFullDynamicColor()) { + return; + } + @ColorInt int color = PartnerConfigHelper.get(getContext()) diff --git a/main/src/com/google/android/setupdesign/items/ItemViewHolder.java b/main/src/com/google/android/setupdesign/items/ItemViewHolder.java index f79b2b6..3cffddd 100644 --- a/main/src/com/google/android/setupdesign/items/ItemViewHolder.java +++ b/main/src/com/google/android/setupdesign/items/ItemViewHolder.java @@ -20,7 +20,11 @@ import androidx.recyclerview.widget.RecyclerView; import android.view.View; import com.google.android.setupdesign.DividerItemDecoration; -class ItemViewHolder extends RecyclerView.ViewHolder +/** + * ViewHolder for the RecyclerItemAdapter that describes an item view and metadata about its place + * within the RecyclerView. + */ +public class ItemViewHolder extends RecyclerView.ViewHolder implements DividerItemDecoration.DividedViewHolder { private boolean isEnabled; diff --git a/main/src/com/google/android/setupdesign/items/RecyclerItemAdapter.java b/main/src/com/google/android/setupdesign/items/RecyclerItemAdapter.java index 2492a9b..dbbda29 100644 --- a/main/src/com/google/android/setupdesign/items/RecyclerItemAdapter.java +++ b/main/src/com/google/android/setupdesign/items/RecyclerItemAdapter.java @@ -61,6 +61,7 @@ public class RecyclerItemAdapter extends RecyclerView.Adapter<ItemViewHolder> private final ItemHierarchy itemHierarchy; @VisibleForTesting public final boolean applyPartnerHeavyThemeResource; + @VisibleForTesting public final boolean useFullDynamicColor; private OnItemSelectedListener listener; public RecyclerItemAdapter(ItemHierarchy hierarchy) { @@ -68,7 +69,15 @@ public class RecyclerItemAdapter extends RecyclerView.Adapter<ItemViewHolder> } public RecyclerItemAdapter(ItemHierarchy hierarchy, boolean applyPartnerHeavyThemeResource) { + this(hierarchy, applyPartnerHeavyThemeResource, /* useFullDynamicColor= */ false); + } + + public RecyclerItemAdapter( + ItemHierarchy hierarchy, + boolean applyPartnerHeavyThemeResource, + boolean useFullDynamicColor) { this.applyPartnerHeavyThemeResource = applyPartnerHeavyThemeResource; + this.useFullDynamicColor = useFullDynamicColor; itemHierarchy = hierarchy; itemHierarchy.registerObserver(this); } @@ -118,7 +127,9 @@ public class RecyclerItemAdapter extends RecyclerView.Adapter<ItemViewHolder> } else { background = view.getBackground(); if (background == null) { - if (applyPartnerHeavyThemeResource) { + // If full dynamic color enabled which means this activity is running outside of setup + // flow, the colors should refer to R.style.SudFullDynamicColorThemeGlifV3. + if (applyPartnerHeavyThemeResource && !useFullDynamicColor) { int color = PartnerConfigHelper.get(view.getContext()) .getColor(view.getContext(), PartnerConfig.CONFIG_LAYOUT_BACKGROUND_COLOR); diff --git a/main/src/com/google/android/setupdesign/template/RecyclerMixin.java b/main/src/com/google/android/setupdesign/template/RecyclerMixin.java index 169e995..b327060 100644 --- a/main/src/com/google/android/setupdesign/template/RecyclerMixin.java +++ b/main/src/com/google/android/setupdesign/template/RecyclerMixin.java @@ -127,13 +127,15 @@ public class RecyclerMixin implements Mixin { final ItemHierarchy inflated = new ItemInflater(context).inflate(entries); boolean applyPartnerHeavyThemeResource = false; + boolean useFullDynamicColor = false; if (templateLayout instanceof GlifLayout) { applyPartnerHeavyThemeResource = ((GlifLayout) templateLayout).shouldApplyPartnerHeavyThemeResource(); + useFullDynamicColor = ((GlifLayout) templateLayout).useFullDynamicColor(); } final RecyclerItemAdapter adapter = - new RecyclerItemAdapter(inflated, applyPartnerHeavyThemeResource); + new RecyclerItemAdapter(inflated, applyPartnerHeavyThemeResource, useFullDynamicColor); adapter.setHasStableIds(a.getBoolean(R.styleable.SudRecyclerMixin_sudHasStableIds, false)); setAdapter(adapter); } diff --git a/main/src/com/google/android/setupdesign/util/ItemStyler.java b/main/src/com/google/android/setupdesign/util/ItemStyler.java index b58945d..ecddfd4 100644 --- a/main/src/com/google/android/setupdesign/util/ItemStyler.java +++ b/main/src/com/google/android/setupdesign/util/ItemStyler.java @@ -18,18 +18,17 @@ package com.google.android.setupdesign.util; import android.annotation.TargetApi; import android.content.Context; -import android.graphics.Typeface; +import android.os.Build; import android.os.Build.VERSION_CODES; -import android.util.TypedValue; import android.view.Gravity; import android.view.View; -import android.view.ViewGroup; import android.widget.LinearLayout; import android.widget.TextView; import androidx.annotation.Nullable; import com.google.android.setupcompat.partnerconfig.PartnerConfig; import com.google.android.setupcompat.partnerconfig.PartnerConfigHelper; import com.google.android.setupdesign.R; +import com.google.android.setupdesign.util.TextViewPartnerStyler.TextPartnerConfigs; /** * Applies the partner style of layout to the given View {@code view}. The user needs to check if @@ -38,92 +37,92 @@ import com.google.android.setupdesign.R; public final class ItemStyler { /** - * Applies the heavy theme partner configs to the given view {@code view}. The user needs to check - * before calling this method: + * Applies the heavy theme partner configs to the given listItemView {@code listItemView}. The + * user needs to check before calling this method: * - * <p>1) If the {@code view} should apply heavy theme resource by calling {@link + * <p>1) If the {@code listItemView} should apply heavy theme resource by calling {@link * PartnerStyleHelper#shouldApplyPartnerHeavyThemeResource}. * - * <p>2) If the layout of the {@code view} contains fixed resource IDs which attempts to apply - * heavy theme resources (The resource ID of the title is "sud_items_title" and the resource ID of - * the summary is "sud_items_summary"), refer to {@link R.layout#sud_items_default}. + * <p>2) If the layout of the {@code listItemView} contains fixed resource IDs which attempts to + * apply heavy theme resources (The resource ID of the title is "sud_items_title" and the resource + * ID of the summary is "sud_items_summary"), refer to {@link R.layout#sud_items_default}. * - * @param view A view would be applied heavy theme styles + * @param listItemView A view would be applied heavy theme styles */ @TargetApi(VERSION_CODES.JELLY_BEAN_MR1) - public static void applyPartnerCustomizationItemStyle(@Nullable View view) { - if (view == null) { + public static void applyPartnerCustomizationItemStyle(@Nullable View listItemView) { + if (listItemView == null) { return; } - - final Context context = view.getContext(); - - if (!PartnerStyleHelper.shouldApplyPartnerHeavyThemeResource(view)) { + if (!PartnerStyleHelper.shouldApplyPartnerHeavyThemeResource(listItemView)) { return; } - // TODO: Move to TextViewPartnerStyler in ItemStyler - final TextView titleView = view.findViewById(R.id.sud_items_title); + final TextView titleTextView = listItemView.findViewById(R.id.sud_items_title); + // apply title text style + applyPartnerCustomizationItemTitleStyle(titleTextView); - if (PartnerConfigHelper.get(context) - .isPartnerConfigAvailable(PartnerConfig.CONFIG_ITEMS_TITLE_TEXT_SIZE)) { - final float titleSize = - PartnerConfigHelper.get(context) - .getDimension(context, PartnerConfig.CONFIG_ITEMS_TITLE_TEXT_SIZE); - titleView.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize); + // adjust list item view gravity + TextView summaryTextView = listItemView.findViewById(R.id.sud_items_summary); + if (summaryTextView.getVisibility() == View.GONE && listItemView instanceof LinearLayout) { + // Set list items to vertical center when there is no summary. + ((LinearLayout) listItemView).setGravity(Gravity.CENTER_VERTICAL); } - if (PartnerConfigHelper.get(context) - .isPartnerConfigAvailable(PartnerConfig.CONFIG_ITEMS_TITLE_FONT_FAMILY)) { + // apply summary text style + applyPartnerCustomizationItemSummaryStyle(summaryTextView); - final String textFont = - PartnerConfigHelper.get(context) - .getString(context, PartnerConfig.CONFIG_ITEMS_TITLE_FONT_FAMILY); - - final Typeface typeface = Typeface.create(textFont, Typeface.NORMAL); - - titleView.setTypeface(typeface); - } - - TextView summaryView = view.findViewById(R.id.sud_items_summary); - if (summaryView.getVisibility() == View.GONE && view instanceof LinearLayout) { - // Set list items to vertical center when no summary. - ((LinearLayout) view).setGravity(Gravity.CENTER_VERTICAL); - } + // apply list item view style + applyPartnerCustomizationItemViewLayoutStyle(listItemView); + } - if (PartnerConfigHelper.get(context) - .isPartnerConfigAvailable(PartnerConfig.CONFIG_ITEMS_SUMMARY_TEXT_SIZE)) { - final float summarySize = - PartnerConfigHelper.get(context) - .getDimension(context, PartnerConfig.CONFIG_ITEMS_SUMMARY_TEXT_SIZE); - summaryView.setTextSize(TypedValue.COMPLEX_UNIT_PX, summarySize); + /** + * Applies the partner heavy style to the given list item title text view. Will check the current + * text view enabled the partner customized heavy theme configurations before applying. + * + * @param titleTextView A textView of a list item title text. + */ + public static void applyPartnerCustomizationItemTitleStyle(TextView titleTextView) { + if (!PartnerStyleHelper.shouldApplyPartnerHeavyThemeResource(titleTextView)) { + return; } + TextViewPartnerStyler.applyPartnerCustomizationStyle( + titleTextView, + new TextPartnerConfigs( + null, + null, + PartnerConfig.CONFIG_ITEMS_TITLE_TEXT_SIZE, + PartnerConfig.CONFIG_ITEMS_TITLE_FONT_FAMILY, + null, + null, + PartnerStyleHelper.getLayoutGravity(titleTextView.getContext()))); + } - if (PartnerConfigHelper.get(context) - .isPartnerConfigAvailable(PartnerConfig.CONFIG_ITEMS_SUMMARY_FONT_FAMILY)) { - - final String textFont = - PartnerConfigHelper.get(context) - .getString(context, PartnerConfig.CONFIG_ITEMS_SUMMARY_FONT_FAMILY); - - final Typeface typeface = Typeface.create(textFont, Typeface.NORMAL); - - summaryView.setTypeface(typeface); + /** + * Applies the partner heavy style to the given summary text view. Will check the current text + * view enabled the partner customized heavy theme configurations before applying. + * + * @param summaryTextView A textView of a list item summary text. + */ + public static void applyPartnerCustomizationItemSummaryStyle(TextView summaryTextView) { + if (!PartnerStyleHelper.shouldApplyPartnerHeavyThemeResource(summaryTextView)) { + return; } - if (PartnerConfigHelper.get(context) - .isPartnerConfigAvailable(PartnerConfig.CONFIG_ITEMS_SUMMARY_MARGIN_TOP)) { - float summaryMarginTop = - PartnerConfigHelper.get(context) - .getDimension(context, PartnerConfig.CONFIG_ITEMS_SUMMARY_MARGIN_TOP); - final ViewGroup.LayoutParams lp = summaryView.getLayoutParams(); - if (lp instanceof LinearLayout.LayoutParams) { - final LinearLayout.LayoutParams mlp = (LinearLayout.LayoutParams) lp; - mlp.setMargins(mlp.leftMargin, (int) summaryMarginTop, mlp.rightMargin, mlp.bottomMargin); - summaryView.setLayoutParams(lp); - } - } + TextViewPartnerStyler.applyPartnerCustomizationStyle( + summaryTextView, + new TextPartnerConfigs( + null, + null, + PartnerConfig.CONFIG_ITEMS_SUMMARY_TEXT_SIZE, + PartnerConfig.CONFIG_ITEMS_SUMMARY_FONT_FAMILY, + PartnerConfig.CONFIG_ITEMS_SUMMARY_MARGIN_TOP, + null, + PartnerStyleHelper.getLayoutGravity(summaryTextView.getContext()))); + } + private static void applyPartnerCustomizationItemViewLayoutStyle(@Nullable View listItemView) { + Context context = listItemView.getContext(); float paddingTop; if (PartnerConfigHelper.get(context) .isPartnerConfigAvailable(PartnerConfig.CONFIG_ITEMS_PADDING_TOP)) { @@ -131,7 +130,7 @@ public final class ItemStyler { PartnerConfigHelper.get(context) .getDimension(context, PartnerConfig.CONFIG_ITEMS_PADDING_TOP); } else { - paddingTop = view.getPaddingTop(); + paddingTop = listItemView.getPaddingTop(); } float paddingBottom; @@ -141,12 +140,24 @@ public final class ItemStyler { PartnerConfigHelper.get(context) .getDimension(context, PartnerConfig.CONFIG_ITEMS_PADDING_BOTTOM); } else { - paddingBottom = view.getPaddingBottom(); + paddingBottom = listItemView.getPaddingBottom(); } - if (paddingTop != view.getPaddingTop() || paddingBottom != view.getPaddingBottom()) { - view.setPadding( - view.getPaddingStart(), (int) paddingTop, view.getPaddingEnd(), (int) paddingBottom); + if (paddingTop != listItemView.getPaddingTop() + || paddingBottom != listItemView.getPaddingBottom()) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { + listItemView.setPadding( + listItemView.getPaddingStart(), + (int) paddingTop, + listItemView.getPaddingEnd(), + (int) paddingBottom); + } else { + listItemView.setPadding( + listItemView.getPaddingLeft(), + (int) paddingTop, + listItemView.getPaddingRight(), + (int) paddingBottom); + } } if (PartnerConfigHelper.get(context) @@ -154,7 +165,7 @@ public final class ItemStyler { float minHeight = PartnerConfigHelper.get(context) .getDimension(context, PartnerConfig.CONFIG_ITEMS_MIN_HEIGHT); - view.setMinimumHeight((int) minHeight); + listItemView.setMinimumHeight((int) minHeight); } } |