• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
25 import androidx.annotation.VisibleForTesting;
26 
27 import com.android.managedprovisioning.R;
28 import com.android.managedprovisioning.model.CustomizationParams;
29 import com.google.android.setupdesign.GlifLayout;
30 import com.google.android.setupdesign.util.ThemeResolver;
31 
32 
33 /**
34  * Base class for setting up the layout.
35  */
36 public abstract class SetupGlifLayoutActivity extends SetupLayoutActivity {
SetupGlifLayoutActivity()37     public SetupGlifLayoutActivity() {
38         super();
39     }
40 
41     @Override
onCreate(Bundle savedInstanceState)42     protected void onCreate(Bundle savedInstanceState) {
43         super.onCreate(savedInstanceState);
44         setDefaultTheme();
45     }
46 
47     @VisibleForTesting
SetupGlifLayoutActivity(Utils utils)48     protected SetupGlifLayoutActivity(Utils utils) {
49         super(utils);
50     }
51 
52     @Override
onApplyThemeResource(Theme theme, int resid, boolean first)53     protected void onApplyThemeResource(Theme theme, int resid, boolean first) {
54         theme.applyStyle(R.style.SetupWizardPartnerResource, true);
55         super.onApplyThemeResource(theme, resid, first);
56     }
57 
initializeLayoutParams(int layoutResourceId, @Nullable Integer headerResourceId, CustomizationParams params)58     protected void initializeLayoutParams(int layoutResourceId, @Nullable Integer headerResourceId,
59             CustomizationParams params) {
60         setContentView(layoutResourceId);
61         GlifLayout layout = findViewById(R.id.setup_wizard_layout);
62 
63         // ManagedProvisioning's customization has prioritization than stencil theme currently. If
64         // there is no status bar color customized by ManagedProvisioning, it can apply status bar
65         // color from stencil theme.
66         if (!params.useSetupStatusBarColor) {
67             setStatusBarColor(params.statusBarColor);
68         }
69         layout.setPrimaryColor(ColorStateList.valueOf(params.mainColor));
70 
71         if (headerResourceId != null) {
72             layout.setHeaderText(headerResourceId);
73             layout.setHeaderColor(
74                     getResources().getColorStateList(R.color.header_text_color, getTheme()));
75         }
76 
77         layout.setIcon(LogoUtils.getOrganisationLogo(this, params.mainColor));
78     }
79 
setDefaultTheme()80     private void setDefaultTheme() {
81         setTheme(new ThemeResolver.Builder(ThemeResolver.getDefault())
82             .setDefaultTheme(R.style.SudThemeGlifV3_Light)
83             .setUseDayNight(false)
84             .build()
85             .resolve(SetupWizardProperties.theme().orElse("")));
86     }
87 
88 }
89