1 package com.google.android.setupdesign.util; 2 3 import android.content.Context; 4 import android.graphics.Typeface; 5 import androidx.annotation.VisibleForTesting; 6 import android.util.TypedValue; 7 import android.widget.TextView; 8 import com.google.android.setupcompat.partnerconfig.PartnerConfig; 9 import com.google.android.setupcompat.partnerconfig.PartnerConfigHelper; 10 11 /** Applies the given style properties for the style of the given type. */ 12 public class DescriptionStyler { 13 14 public static void applyPartnerCustomizationStyle(TextView description) { 15 16 final Context context = description.getContext(); 17 18 int descriptionTextColor = 19 PartnerConfigHelper.get(context) 20 .getColor(context, PartnerConfig.CONFIG_DESCRIPTION_TEXT_COLOR); 21 if (descriptionTextColor != 0) { 22 setTextColor(description, descriptionTextColor); 23 } 24 25 int descriptionLinkTextColor = 26 PartnerConfigHelper.get(context) 27 .getColor(context, PartnerConfig.CONFIG_DESCRIPTION_LINK_TEXT_COLOR); 28 if (descriptionLinkTextColor != 0) { 29 setLinkTextColor(description, descriptionLinkTextColor); 30 } 31 32 float descriptionTextSize = 33 PartnerConfigHelper.get(context) 34 .getDimension(context, PartnerConfig.CONFIG_DESCRIPTION_TEXT_SIZE, 0); 35 if (descriptionTextSize != 0) { 36 setTextSize(description, descriptionTextSize); 37 } 38 39 String fontFamilyName = 40 PartnerConfigHelper.get(context) 41 .getString(context, PartnerConfig.CONFIG_DESCRIPTION_FONT_FAMILY); 42 Typeface font = Typeface.create(fontFamilyName, Typeface.NORMAL); 43 if (font != null) { 44 setFontFamily(description, font); 45 } 46 47 setGravity(description, PartnerStyleHelper.getLayoutGravity(context)); 48 } 49 50 @VisibleForTesting 51 static void setTextSize(TextView description, float size) { 52 if (description != null) { 53 description.setTextSize(TypedValue.COMPLEX_UNIT_PX, size); 54 } 55 } 56 57 @VisibleForTesting 58 static void setFontFamily(TextView description, Typeface fontFamily) { 59 if (description != null) { 60 description.setTypeface(fontFamily); 61 } 62 } 63 64 @VisibleForTesting 65 static void setTextColor(TextView description, int color) { 66 if (description != null) { 67 description.setTextColor(color); 68 } 69 } 70 71 @VisibleForTesting 72 static void setLinkTextColor(TextView description, int color) { 73 if (description != null) { 74 description.setLinkTextColor(color); 75 } 76 } 77 78 @VisibleForTesting 79 static void setGravity(TextView description, int gravity) { 80 if (description != null) { 81 description.setGravity(gravity); 82 } 83 } 84 } 85