1 /* 2 * Copyright 2016, The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.managedprovisioning.common; 18 19 import android.annotation.Nullable; 20 import android.content.res.ColorStateList; 21 import android.content.res.Resources.Theme; 22 import android.os.Bundle; 23 import android.sysprop.SetupWizardProperties; 24 import android.text.Editable; 25 import android.text.TextWatcher; 26 import android.widget.TextView; 27 28 import androidx.annotation.VisibleForTesting; 29 30 import com.android.managedprovisioning.R; 31 import com.android.managedprovisioning.model.CustomizationParams; 32 import com.google.android.setupdesign.GlifLayout; 33 import com.google.android.setupdesign.util.ThemeResolver; 34 35 36 /** 37 * Base class for setting up the layout. 38 */ 39 public abstract class SetupGlifLayoutActivity extends SetupLayoutActivity { 40 41 /** 42 * Number of characters in the header needed before adding an extra line of text. 43 */ 44 private static final int CHAR_THRESHOLD_FOR_ADDITIONAL_LINE = 70; 45 SetupGlifLayoutActivity()46 public SetupGlifLayoutActivity() { 47 super(); 48 } 49 50 @Override onCreate(Bundle savedInstanceState)51 protected void onCreate(Bundle savedInstanceState) { 52 super.onCreate(savedInstanceState); 53 setDefaultTheme(); 54 } 55 56 @VisibleForTesting SetupGlifLayoutActivity(Utils utils)57 protected SetupGlifLayoutActivity(Utils utils) { 58 super(utils); 59 } 60 61 @Override onApplyThemeResource(Theme theme, int resid, boolean first)62 protected void onApplyThemeResource(Theme theme, int resid, boolean first) { 63 theme.applyStyle(R.style.SetupWizardPartnerResource, true); 64 super.onApplyThemeResource(theme, resid, first); 65 } 66 initializeLayoutParams(int layoutResourceId, @Nullable Integer headerResourceId, CustomizationParams params)67 protected void initializeLayoutParams(int layoutResourceId, @Nullable Integer headerResourceId, 68 CustomizationParams params) { 69 setContentView(layoutResourceId); 70 GlifLayout layout = findViewById(R.id.setup_wizard_layout); 71 72 // ManagedProvisioning's customization has prioritization than stencil theme currently. If 73 // there is no status bar color customized by ManagedProvisioning, it can apply status bar 74 // color from stencil theme. 75 if (!params.useSetupStatusBarColor) { 76 setStatusBarColor(params.statusBarColor); 77 } 78 layout.setPrimaryColor(ColorStateList.valueOf(params.mainColor)); 79 80 if (headerResourceId != null) { 81 layout.setHeaderText(headerResourceId); 82 layout.setHeaderColor( 83 getResources().getColorStateList(R.color.header_text_color, getTheme())); 84 } 85 86 TextView header = findViewById(R.id.suc_layout_title); 87 if (header != null) { 88 header.addTextChangedListener(new TextWatcher() { 89 @Override 90 public void beforeTextChanged(CharSequence s, int start, int count, int after) { 91 } 92 93 @Override 94 public void onTextChanged(CharSequence s, int start, int before, int count) { 95 } 96 97 @Override 98 public void afterTextChanged(Editable s) { 99 adjustHeaderMaxLines(); 100 } 101 }); 102 103 adjustHeaderMaxLines(); 104 } 105 106 layout.setIcon(LogoUtils.getOrganisationLogo(this, params.mainColor)); 107 } 108 adjustHeaderMaxLines()109 private void adjustHeaderMaxLines() { 110 TextView header = findViewById(R.id.suc_layout_title); 111 int maxLines = 3; 112 if (header.getText().length() > CHAR_THRESHOLD_FOR_ADDITIONAL_LINE) { 113 maxLines++; 114 } 115 if (header.getMaxLines() != maxLines) { 116 header.setMaxLines(maxLines); 117 } 118 } 119 setDefaultTheme()120 private void setDefaultTheme() { 121 setTheme(new ThemeResolver.Builder(ThemeResolver.getDefault()) 122 .setDefaultTheme(R.style.SudThemeGlifV3_Light) 123 .setUseDayNight(false) 124 .build() 125 .resolve(SetupWizardProperties.theme().orElse(""))); 126 } 127 128 } 129