1 /* 2 * Copyright 2019, 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 com.android.internal.util.Preconditions.checkNotNull; 19 20 import android.annotation.DrawableRes; 21 import android.annotation.Nullable; 22 import android.app.Activity; 23 import android.content.Intent; 24 import android.graphics.drawable.AnimatedVectorDrawable; 25 import android.view.View; 26 import android.widget.ImageView; 27 import com.android.managedprovisioning.R; 28 import com.android.managedprovisioning.common.ProvisionLogger; 29 import com.android.managedprovisioning.common.RepeatingVectorAnimation; 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.PreProvisioningController.UiParams; 34 import com.google.android.setupdesign.GlifLayout; 35 36 /** 37 * Implements functionality for the consent screen. 38 */ 39 class PrimaryConsentUiHelper implements ConsentUiHelper { 40 private final Activity mActivity; 41 private final TouchTargetEnforcer mTouchTargetEnforcer; 42 private final ConsentUiHelperCallback mCallback; 43 private final Utils mUtils; 44 private @Nullable RepeatingVectorAnimation mRepeatingVectorAnimation; 45 PrimaryConsentUiHelper(Activity activity, ConsentUiHelperCallback callback, Utils utils)46 PrimaryConsentUiHelper(Activity activity, ConsentUiHelperCallback callback, Utils utils) { 47 mActivity = activity; 48 mCallback = callback; 49 mTouchTargetEnforcer = 50 new TouchTargetEnforcer(activity.getResources().getDisplayMetrics().density); 51 mUtils = utils; 52 } 53 54 @Override onStart()55 public void onStart() { 56 if (mRepeatingVectorAnimation != null) { 57 mRepeatingVectorAnimation.start(); 58 } 59 } 60 61 @Override onStop()62 public void onStop() { 63 if (mRepeatingVectorAnimation != null) { 64 mRepeatingVectorAnimation.stop(); 65 } 66 } 67 68 @Override initiateUi(UiParams uiParams)69 public void initiateUi(UiParams uiParams) { 70 int titleResId = 0; 71 int headerResId = 0; 72 int animationResId = 0; 73 if (mUtils.isProfileOwnerAction(uiParams.provisioningAction)) { 74 titleResId = R.string.setup_profile; 75 headerResId = uiParams.isOrganizationOwnedProvisioning 76 ? R.string.work_profile_provisioning_accept_header 77 : R.string.work_profile_provisioning_accept_header_post_suw; 78 animationResId = R.drawable.consent_animation_po; 79 } else if (mUtils.isDeviceOwnerAction(uiParams.provisioningAction)) { 80 titleResId = R.string.setup_device; 81 headerResId = R.string.fully_managed_device_provisioning_accept_header; 82 animationResId = R.drawable.consent_animation_do; 83 } 84 85 final CustomizationParams customization = uiParams.customization; 86 mCallback.initializeLayoutParams( 87 R.layout.intro, 88 headerResId, 89 customization); 90 91 setupAnimation(animationResId); 92 setupAcceptAndContinueButton(uiParams.isSilentProvisioning); 93 94 // set the activity title 95 mActivity.setTitle(titleResId); 96 97 // set up terms headers 98 setupViewTermsButton(uiParams.viewTermsIntent); 99 } 100 setupAnimation(@rawableRes int animationResId)101 private void setupAnimation(@DrawableRes int animationResId) { 102 final GlifLayout layout = mActivity.findViewById(R.id.setup_wizard_layout); 103 final ImageView imageView = layout.findViewById(R.id.animation); 104 imageView.setImageResource(animationResId); 105 final AnimatedVectorDrawable animatedVectorDrawable = 106 (AnimatedVectorDrawable) imageView.getDrawable(); 107 mRepeatingVectorAnimation = new RepeatingVectorAnimation(animatedVectorDrawable); 108 mRepeatingVectorAnimation.start(); 109 } 110 setupAcceptAndContinueButton(boolean isSilentProvisioning)111 private void setupAcceptAndContinueButton(boolean isSilentProvisioning) { 112 final GlifLayout layout = mActivity.findViewById(R.id.setup_wizard_layout); 113 Utils.addAcceptAndContinueButton(layout, v -> onNextButtonClicked()); 114 if (isSilentProvisioning) { 115 onNextButtonClicked(); 116 } 117 } 118 onNextButtonClicked()119 private void onNextButtonClicked() { 120 ProvisionLogger.logi("Next button (next_button) is clicked."); 121 mCallback.nextAfterUserConsent(); 122 } 123 setupViewTermsButton(Intent showTermsIntent)124 private void setupViewTermsButton(Intent showTermsIntent) { 125 final View viewTermsButton = mActivity.findViewById(R.id.show_terms_button); 126 viewTermsButton.setOnClickListener(v -> mActivity.startActivity(showTermsIntent)); 127 mTouchTargetEnforcer.enforce(viewTermsButton, (View) viewTermsButton.getParent()); 128 } 129 } 130