1 /* 2 * Copyright (C) 2020 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.provisioning; 18 19 import static java.util.Objects.requireNonNull; 20 21 import android.annotation.DrawableRes; 22 import android.annotation.StringRes; 23 import android.os.Bundle; 24 import android.view.ViewGroup; 25 import android.widget.ImageView; 26 import android.widget.LinearLayout; 27 import android.widget.TextView; 28 29 import com.android.internal.annotations.VisibleForTesting; 30 import com.android.managedprovisioning.R; 31 import com.android.managedprovisioning.common.AccessibilityContextMenuMaker; 32 import com.android.managedprovisioning.common.SettingsFacade; 33 import com.android.managedprovisioning.common.SetupGlifLayoutActivity; 34 import com.android.managedprovisioning.common.StylerHelper; 35 import com.android.managedprovisioning.common.ThemeHelper; 36 import com.android.managedprovisioning.common.ThemeHelper.DefaultNightModeChecker; 37 import com.android.managedprovisioning.common.ThemeHelper.DefaultSetupWizardBridge; 38 import com.android.managedprovisioning.common.Utils; 39 import com.android.managedprovisioning.model.ProvisioningParams; 40 41 import com.google.android.setupcompat.template.FooterBarMixin; 42 import com.google.android.setupcompat.template.FooterButton; 43 import com.google.android.setupdesign.GlifLayout; 44 import com.google.android.setupdesign.util.DeviceHelper; 45 46 import java.util.Objects; 47 48 /** 49 * This is the first activity the user will see during financed device provisioning. 50 */ 51 public final class FinancedDeviceLandingActivity extends SetupGlifLayoutActivity { 52 53 private final AccessibilityContextMenuMaker mContextMenuMaker; 54 private final StylerHelper mStylerHelper; 55 FinancedDeviceLandingActivity()56 public FinancedDeviceLandingActivity() { 57 this(new Utils(), /* contextMenuMaker= */null, new SettingsFacade(), 58 new ThemeHelper(new DefaultNightModeChecker(), new DefaultSetupWizardBridge()), 59 new StylerHelper()); 60 } 61 62 @VisibleForTesting FinancedDeviceLandingActivity(Utils utils, AccessibilityContextMenuMaker contextMenuMaker, SettingsFacade settingsFacade, ThemeHelper themeHelper, StylerHelper stylerHelper)63 FinancedDeviceLandingActivity(Utils utils, AccessibilityContextMenuMaker contextMenuMaker, 64 SettingsFacade settingsFacade, ThemeHelper themeHelper, StylerHelper stylerHelper) { 65 super(utils, settingsFacade, themeHelper); 66 mContextMenuMaker = contextMenuMaker != null 67 ? contextMenuMaker 68 : new AccessibilityContextMenuMaker(this); 69 mStylerHelper = requireNonNull(stylerHelper); 70 } 71 72 @Override onCreate(Bundle savedInstanceState)73 protected void onCreate(Bundle savedInstanceState) { 74 super.onCreate(savedInstanceState); 75 final ProvisioningParams params = getIntent() 76 .getParcelableExtra(ProvisioningParams.EXTRA_PROVISIONING_PARAMS); 77 initializeUi(params); 78 } 79 initializeUi(ProvisioningParams params)80 private void initializeUi(ProvisioningParams params) { 81 setContentView(R.layout.financed_device_landing_screen); 82 83 GlifLayout layout = findViewById(R.id.setup_wizard_layout); 84 CharSequence deviceName = DeviceHelper.getDeviceName(this); 85 final String headerString = getString(R.string.financed_device_screen_header, deviceName, 86 params.organizationName); 87 layout.setHeaderText(headerString); 88 layout.setIcon(getDrawable(R.drawable.ic_info_outline_24px)); 89 setupFooterBar(layout); 90 91 final ViewGroup item1 = layout.findViewById(R.id.item1); 92 final String makePaymentsSubheaderSummary = getString( 93 R.string.financed_make_payments_subheader_description, params.organizationName, 94 params.organizationName, deviceName); 95 setupItem(item1, R.string.financed_make_payments_subheader_title, 96 makePaymentsSubheaderSummary, R.drawable.ic_file_download_24px, deviceName); 97 98 final ViewGroup item2 = layout.findViewById(R.id.item2); 99 100 final String restrictDeviceSubheaderSummary = getString( 101 R.string.financed_restrict_device_subheader_description, params.organizationName, 102 deviceName); 103 setupItem(item2, R.string.financed_restrict_device_subheader_title, 104 restrictDeviceSubheaderSummary, R.drawable.ic_lock, 105 deviceName); 106 } 107 setupFooterBar(GlifLayout layout)108 private void setupFooterBar(GlifLayout layout) { 109 final FooterBarMixin footerBarMixin = layout.getMixin(FooterBarMixin.class); 110 footerBarMixin.setPrimaryButton( 111 new FooterButton.Builder(this) 112 .setText(R.string.next) 113 .setListener(view -> onNextButtonClicked()) 114 .setButtonType(FooterButton.ButtonType.NEXT) 115 .setTheme(com.google.android.setupdesign.R.style.SudGlifButton_Primary) 116 .build()); 117 } 118 setupItem(ViewGroup item, @StringRes int title, String summary, @DrawableRes int icon, CharSequence deviceName)119 private void setupItem(ViewGroup item, @StringRes int title, String summary, 120 @DrawableRes int icon, CharSequence deviceName) { 121 mStylerHelper.applyListItemStyling( 122 item, new LinearLayout.LayoutParams(item.getLayoutParams())); 123 124 final ImageView makePaymentsSubHeaderImage = item.findViewById(R.id.sud_items_icon); 125 makePaymentsSubHeaderImage.setImageDrawable(getDrawable(icon)); 126 127 final TextView makePaymentsSubHeaderTitle = item.findViewById(R.id.sud_items_title); 128 makePaymentsSubHeaderTitle.setText(getString(title, deviceName)); 129 130 final TextView makePaymentsSubHeaderDescription = item.findViewById(R.id.sud_items_summary); 131 makePaymentsSubHeaderDescription.setText(summary); 132 } 133 onNextButtonClicked()134 private void onNextButtonClicked() { 135 setResult(RESULT_OK); 136 getTransitionHelper().finishActivity(this); 137 } 138 } 139