summaryrefslogtreecommitdiff
path: root/main/src/com/google/android/setupdesign/util/HeaderAreaStyler.java
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/com/google/android/setupdesign/util/HeaderAreaStyler.java')
-rw-r--r--main/src/com/google/android/setupdesign/util/HeaderAreaStyler.java155
1 files changed, 147 insertions, 8 deletions
diff --git a/main/src/com/google/android/setupdesign/util/HeaderAreaStyler.java b/main/src/com/google/android/setupdesign/util/HeaderAreaStyler.java
index 7702eba..efeff97 100644
--- a/main/src/com/google/android/setupdesign/util/HeaderAreaStyler.java
+++ b/main/src/com/google/android/setupdesign/util/HeaderAreaStyler.java
@@ -17,11 +17,19 @@
package com.google.android.setupdesign.util;
import android.content.Context;
+import android.graphics.drawable.VectorDrawable;
+import android.os.Build;
import android.view.ViewGroup;
+import android.view.ViewGroup.LayoutParams;
+import android.view.ViewTreeObserver;
import android.widget.ImageView;
+import android.widget.ImageView.ScaleType;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.annotation.Nullable;
+import androidx.annotation.VisibleForTesting;
+import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat;
+import com.google.android.setupcompat.internal.TemplateLayout;
import com.google.android.setupcompat.partnerconfig.PartnerConfig;
import com.google.android.setupcompat.partnerconfig.PartnerConfigHelper;
import com.google.android.setupdesign.util.TextViewPartnerStyler.TextPartnerConfigs;
@@ -32,6 +40,10 @@ import com.google.android.setupdesign.util.TextViewPartnerStyler.TextPartnerConf
*/
public final class HeaderAreaStyler {
+ @VisibleForTesting
+ static final String WARNING_TO_USE_DRAWABLE =
+ "To achieve scaling icon in SetupDesign lib, should use vector drawable icon!!";
+
/**
* Applies the partner heavy style of header text to the given textView {@code header}.
*
@@ -49,10 +61,35 @@ public final class HeaderAreaStyler {
null,
PartnerConfig.CONFIG_HEADER_TEXT_SIZE,
PartnerConfig.CONFIG_HEADER_FONT_FAMILY,
+ PartnerConfig.CONFIG_HEADER_TEXT_MARGIN_TOP,
+ PartnerConfig.CONFIG_HEADER_TEXT_MARGIN_BOTTOM,
PartnerStyleHelper.getLayoutGravity(header.getContext())));
}
/**
+ * Applies the partner heavy style of description text to the given textView {@code description}.
+ *
+ * @param description A description text would apply partner heavy style
+ */
+ public static void applyPartnerCustomizationDescriptionHeavyStyle(
+ @Nullable TextView description) {
+
+ if (description == null) {
+ return;
+ }
+ TextViewPartnerStyler.applyPartnerCustomizationStyle(
+ description,
+ new TextPartnerConfigs(
+ PartnerConfig.CONFIG_DESCRIPTION_TEXT_COLOR,
+ PartnerConfig.CONFIG_DESCRIPTION_LINK_TEXT_COLOR,
+ PartnerConfig.CONFIG_DESCRIPTION_TEXT_SIZE,
+ PartnerConfig.CONFIG_DESCRIPTION_FONT_FAMILY,
+ PartnerConfig.CONFIG_DESCRIPTION_TEXT_MARGIN_TOP,
+ PartnerConfig.CONFIG_DESCRIPTION_TEXT_MARGIN_BOTTOM,
+ PartnerStyleHelper.getLayoutGravity(description.getContext())));
+ }
+
+ /**
* Applies the partner light style of header text to the given textView {@code header}.
*
* @param header A header text would apply partner light style
@@ -66,13 +103,43 @@ public final class HeaderAreaStyler {
TextViewPartnerStyler.applyPartnerCustomizationLightStyle(
header,
new TextPartnerConfigs(
- null, null, null, null, PartnerStyleHelper.getLayoutGravity(header.getContext())));
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ PartnerStyleHelper.getLayoutGravity(header.getContext())));
+ }
+
+ /**
+ * Applies the partner light style of description text to the given textView {@code description}.
+ *
+ * @param description A description text would apply partner light style
+ */
+ public static void applyPartnerCustomizationDescriptionLightStyle(
+ @Nullable TextView description) {
+
+ if (description == null) {
+ return;
+ }
+
+ TextViewPartnerStyler.applyPartnerCustomizationLightStyle(
+ description,
+ new TextPartnerConfigs(
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ PartnerStyleHelper.getLayoutGravity(description.getContext())));
}
/**
- * Applies the partner style of header background to the given layout {@code headerArea}.
+ * Applies the partner style of header area to the given layout {@code headerArea}.
*
- * @param headerArea A ViewGroup would apply the partner style of header background
+ * @param headerArea A ViewGroup would apply the partner style of header area
*/
public static void applyPartnerCustomizationHeaderAreaStyle(ViewGroup headerArea) {
@@ -84,25 +151,97 @@ public final class HeaderAreaStyler {
PartnerConfigHelper.get(context)
.getColor(context, PartnerConfig.CONFIG_HEADER_AREA_BACKGROUND_COLOR);
headerArea.setBackgroundColor(color);
+
+ if (PartnerConfigHelper.shouldApplyExtendedPartnerConfig(context)) {
+ final ViewGroup.LayoutParams lp = headerArea.getLayoutParams();
+ if (lp instanceof ViewGroup.MarginLayoutParams) {
+ final ViewGroup.MarginLayoutParams mlp = (ViewGroup.MarginLayoutParams) lp;
+
+ int bottomMargin =
+ (int)
+ PartnerConfigHelper.get(context)
+ .getDimension(context, PartnerConfig.CONFIG_HEADER_CONTAINER_MARGIN_BOTTOM);
+ mlp.setMargins(mlp.leftMargin, mlp.topMargin, mlp.rightMargin, bottomMargin);
+ headerArea.setLayoutParams(lp);
+ }
+ }
}
/**
* Applies the partner style of header icon to the given {@code iconImage}.
*
* @param iconImage A ImageView would apply the partner style of header icon
+ * @param templateLayout The template containing this mixin
*/
- public static void applyPartnerCustomizationIconStyle(@Nullable ImageView iconImage) {
-
+ public static void applyPartnerCustomizationIconStyle(
+ @Nullable ImageView iconImage, TemplateLayout templateLayout) {
if (iconImage == null) {
return;
}
- int gravity = PartnerStyleHelper.getLayoutGravity(iconImage.getContext());
- if (gravity != 0) {
- setGravity(iconImage, gravity);
+ if (PartnerStyleHelper.isPartnerLightThemeLayout(templateLayout)) {
+ Context context = iconImage.getContext();
+ int gravity = PartnerStyleHelper.getLayoutGravity(context);
+ if (gravity != 0) {
+ setGravity(iconImage, gravity);
+ }
+
+ if (!PartnerStyleHelper.isPartnerHeavyThemeLayout(templateLayout)
+ || !PartnerConfigHelper.shouldApplyExtendedPartnerConfig(context)) {
+ return;
+ }
+
+ final ViewGroup.LayoutParams lp = iconImage.getLayoutParams();
+ boolean partnerConfigAvailable =
+ PartnerConfigHelper.get(context)
+ .isPartnerConfigAvailable(PartnerConfig.CONFIG_ICON_MARGIN_TOP);
+ if (partnerConfigAvailable && lp instanceof ViewGroup.MarginLayoutParams) {
+ final ViewGroup.MarginLayoutParams mlp = (ViewGroup.MarginLayoutParams) lp;
+ int topMargin =
+ (int)
+ PartnerConfigHelper.get(context)
+ .getDimension(context, PartnerConfig.CONFIG_ICON_MARGIN_TOP);
+ mlp.setMargins(mlp.leftMargin, topMargin, mlp.rightMargin, mlp.bottomMargin);
+ }
+
+ if (PartnerConfigHelper.get(context)
+ .isPartnerConfigAvailable(PartnerConfig.CONFIG_ICON_SIZE)) {
+
+ checkImageType(iconImage);
+
+ lp.height =
+ (int)
+ PartnerConfigHelper.get(context)
+ .getDimension(context, PartnerConfig.CONFIG_ICON_SIZE);
+ lp.width = LayoutParams.WRAP_CONTENT;
+ iconImage.setScaleType(ScaleType.FIT_CENTER);
+ }
}
}
+ private static void checkImageType(ImageView imageView) {
+ ViewTreeObserver vto = imageView.getViewTreeObserver();
+ vto.addOnPreDrawListener(
+ new ViewTreeObserver.OnPreDrawListener() {
+ @Override
+ public boolean onPreDraw() {
+ imageView.getViewTreeObserver().removeOnPreDrawListener(this);
+
+ // TODO: Remove when Partners all used Drawable icon image and never use
+ // un-drawable image in Setup.
+ // Should set vector drawable icon rather than non-drawable icon(e.g. PNG)
+ if ((Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP
+ || !(imageView.getDrawable() instanceof VectorDrawable))
+ && !(imageView.getDrawable() instanceof VectorDrawableCompat)) {
+ // TODO : Use reflection to get ro.debuggable and show toast to warn.
+ MessageWarning.makeWarning(WARNING_TO_USE_DRAWABLE);
+ }
+
+ return true;
+ }
+ });
+ }
+
private static void setGravity(ImageView icon, int gravity) {
if (icon.getLayoutParams() instanceof LinearLayout.LayoutParams) {
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) icon.getLayoutParams();