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