1 /* 2 * Copyright (C) 2021 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 package com.android.managedprovisioning.preprovisioning.consent; 17 18 import static java.util.Objects.requireNonNull; 19 20 import android.annotation.DrawableRes; 21 import android.app.Activity; 22 import android.view.View; 23 import android.widget.TextView; 24 25 import androidx.annotation.RawRes; 26 27 import com.android.managedprovisioning.R; 28 import com.android.managedprovisioning.common.ProvisionLogger; 29 import com.android.managedprovisioning.common.ThemeHelper; 30 import com.android.managedprovisioning.common.TouchTargetEnforcer; 31 import com.android.managedprovisioning.common.Utils; 32 import com.android.managedprovisioning.model.CustomizationParams; 33 import com.android.managedprovisioning.preprovisioning.PreProvisioningActivityBridgeCallbacks; 34 import com.android.managedprovisioning.preprovisioning.PreProvisioningActivityController.UiParams; 35 36 import com.airbnb.lottie.LottieAnimationView; 37 import com.google.android.setupdesign.GlifLayout; 38 39 40 /** 41 * Implements functionality for the consent screen. 42 */ 43 class ConsentUiHelperImpl implements ConsentUiHelper { 44 private final Activity mActivity; 45 private final TouchTargetEnforcer mTouchTargetEnforcer; 46 private final ConsentUiHelperCallback mCallback; 47 private final Utils mUtils; 48 private final PreProvisioningActivityBridgeCallbacks mBridgeCallbacks; 49 private final ThemeHelper mThemeHelper; 50 ConsentUiHelperImpl(Activity activity, ConsentUiHelperCallback callback, Utils utils, PreProvisioningActivityBridgeCallbacks bridgeCallbacks, ThemeHelper themeHelper)51 ConsentUiHelperImpl(Activity activity, ConsentUiHelperCallback callback, Utils utils, 52 PreProvisioningActivityBridgeCallbacks bridgeCallbacks, 53 ThemeHelper themeHelper) { 54 mActivity = requireNonNull(activity); 55 mCallback = requireNonNull(callback); 56 mTouchTargetEnforcer = 57 new TouchTargetEnforcer(activity.getResources().getDisplayMetrics().density); 58 mUtils = requireNonNull(utils); 59 mBridgeCallbacks = requireNonNull(bridgeCallbacks); 60 mThemeHelper = requireNonNull(themeHelper); 61 } 62 63 @Override initiateUi(UiParams uiParams)64 public void initiateUi(UiParams uiParams) { 65 int titleResId = 0; 66 int headerResId = 0; 67 int animationResId = 0; 68 if (mUtils.isProfileOwnerAction(uiParams.provisioningAction)) { 69 titleResId = R.string.setup_profile; 70 headerResId = R.string.work_profile_provisioning_accept_header_post_suw; 71 animationResId = R.raw.consent_animation_po; 72 } else if (mUtils.isDeviceOwnerAction(uiParams.provisioningAction)) { 73 titleResId = R.string.setup_device; 74 headerResId = R.string.fully_managed_device_provisioning_accept_header; 75 animationResId = R.raw.consent_animation_do; 76 } 77 78 final CustomizationParams customization = uiParams.customization; 79 mCallback.onInitiateUi( 80 R.layout.intro, 81 headerResId, 82 customization); 83 84 setupAnimation(animationResId); 85 setupAcceptAndContinueButton(); 86 87 // set the activity title 88 mActivity.setTitle(titleResId); 89 90 // set up terms headers 91 setupViewTermsButton(); 92 } 93 94 @Override onStart()95 public void onStart() {} 96 97 @Override onStop()98 public void onStop() {} 99 setupAnimation(@awRes int animationResId)100 private void setupAnimation(@RawRes int animationResId) { 101 final GlifLayout layout = mActivity.findViewById(R.id.setup_wizard_layout); 102 LottieAnimationView lottieAnimationView = layout.findViewById(R.id.animation); 103 lottieAnimationView.setAnimation(animationResId); 104 mThemeHelper.setupAnimationDynamicColors( 105 mActivity, lottieAnimationView, mActivity.getIntent()); 106 } 107 setupAcceptAndContinueButton()108 private void setupAcceptAndContinueButton() { 109 final GlifLayout layout = mActivity.findViewById(R.id.setup_wizard_layout); 110 Utils.addAcceptAndContinueButton(layout, v -> onNextButtonClicked()); 111 } 112 onNextButtonClicked()113 private void onNextButtonClicked() { 114 ProvisionLogger.logi("Next button (next_button) is clicked."); 115 mBridgeCallbacks.onTermsAccepted(); 116 } 117 setupViewTermsButton()118 private void setupViewTermsButton() { 119 final GlifLayout layout = mActivity.findViewById(R.id.setup_wizard_layout); 120 layout.setDescriptionText(R.string.view_terms); 121 TextView subtitle = layout.findViewById(R.id.sud_layout_subtitle); 122 subtitle.setTextColor(mUtils.getAccentColor(mActivity)); 123 subtitle.setOnClickListener(v -> mBridgeCallbacks.onTermsButtonClicked()); 124 mTouchTargetEnforcer.enforce(subtitle, (View) subtitle.getParent()); 125 } 126 } 127