OSDN Git Service

Re-enable continue button for accessibility flow
[android-x86/packages-apps-Settings.git] / src / com / android / settings / biometrics / face / FaceEnrollEducation.java
1 /*
2  * Copyright (C) 2018 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.settings.biometrics.face;
18
19 import static android.provider.Settings.Secure.FACE_UNLOCK_EDUCATION_INFO_DISPLAYED;
20 import static android.security.KeyStore.getApplicationContext;
21
22 import android.app.settings.SettingsEnums;
23 import android.content.ComponentName;
24 import android.content.Context;
25 import android.content.Intent;
26 import android.hardware.face.FaceManager;
27 import android.os.Bundle;
28 import android.os.Handler;
29 import android.os.UserHandle;
30 import android.provider.Settings;
31 import android.text.TextUtils;
32 import android.view.View;
33 import android.widget.Button;
34 import android.widget.CompoundButton;
35
36 import com.android.settings.R;
37 import com.android.settings.Utils;
38 import com.android.settings.biometrics.BiometricEnrollBase;
39 import com.android.settings.password.ChooseLockSettingsHelper;
40
41 import com.google.android.setupcompat.template.FooterBarMixin;
42 import com.google.android.setupcompat.template.FooterButton;
43 import com.google.android.setupcompat.util.WizardManagerHelper;
44 import com.google.android.setupdesign.view.IllustrationVideoView;
45
46 public class FaceEnrollEducation extends BiometricEnrollBase {
47
48     private static final String TAG = "FaceEducation";
49     private static final int ON = 1;
50     private static final int OFF = 0;
51     // 10 seconds.
52     private static final long FACE_ENROLL_EDUCATION_DELAY = 16000;
53
54     private FaceManager mFaceManager;
55     private FaceEnrollAccessibilityToggle mSwitchDiversity;
56
57     private IllustrationVideoView mIllustrationNormal;
58     private View mIllustrationAccessibility;
59     private Handler mHandler;
60
61     private CompoundButton.OnCheckedChangeListener mSwitchDiversityListener =
62             new CompoundButton.OnCheckedChangeListener() {
63                 @Override
64                 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
65                     if (isChecked) {
66                         mIllustrationNormal.stop();
67                         mIllustrationNormal.setVisibility(View.INVISIBLE);
68                         mIllustrationAccessibility.setVisibility(View.VISIBLE);
69                     } else {
70                         mIllustrationNormal.setVisibility(View.VISIBLE);
71                         mIllustrationNormal.start();
72                         mIllustrationAccessibility.setVisibility(View.INVISIBLE);
73                     }
74                 }
75             };
76
77     @Override
78     protected void onCreate(Bundle savedInstanceState) {
79         super.onCreate(savedInstanceState);
80         setContentView(R.layout.face_enroll_education);
81         getLayout().setHeaderText(R.string.security_settings_face_enroll_education_title);
82         setTitle(R.string.security_settings_face_enroll_education_title);
83         mHandler = new Handler();
84
85         mFaceManager = Utils.getFaceManagerOrNull(this);
86
87         mIllustrationNormal = findViewById(R.id.illustration_normal);
88         mIllustrationAccessibility = findViewById(R.id.illustration_accessibility);
89
90         mFooterBarMixin = getLayout().getMixin(FooterBarMixin.class);
91         mFooterBarMixin.setSecondaryButton(
92                 new FooterButton.Builder(this)
93                         .setText(R.string.security_settings_face_enroll_enrolling_skip)
94                         .setListener(this::onSkipButtonClick)
95                         .setButtonType(FooterButton.ButtonType.SKIP)
96                         .setTheme(R.style.SudGlifButton_Secondary)
97                         .build()
98         );
99
100         final FooterButton footerButton = new FooterButton.Builder(this)
101                 .setText(R.string.wizard_next)
102                 .setListener(this::onNextButtonClick)
103                 .setButtonType(FooterButton.ButtonType.NEXT)
104                 .setTheme(R.style.SudGlifButton_Primary)
105                 .build();
106
107         mFooterBarMixin.setPrimaryButton(footerButton);
108         final Context context = getApplicationContext();
109         final boolean didDisplayEdu = Settings.Secure.getIntForUser(context.getContentResolver(),
110                 FACE_UNLOCK_EDUCATION_INFO_DISPLAYED, OFF, mUserId) == ON;
111         if (!didDisplayEdu) {
112             Settings.Secure.putIntForUser(context.getContentResolver(),
113                     FACE_UNLOCK_EDUCATION_INFO_DISPLAYED, ON, mUserId);
114             footerButton.setEnabled(false);
115             mHandler.postDelayed(() -> {
116                 footerButton.setEnabled(true);
117             }, FACE_ENROLL_EDUCATION_DELAY);
118         }
119
120         final Button accessibilityButton = findViewById(R.id.accessibility_button);
121         accessibilityButton.setOnClickListener(view -> {
122             footerButton.setEnabled(true);
123             mSwitchDiversity.setChecked(true);
124             accessibilityButton.setVisibility(View.GONE);
125             mSwitchDiversity.setVisibility(View.VISIBLE);
126         });
127
128         mSwitchDiversity = findViewById(R.id.toggle_diversity);
129         mSwitchDiversity.setListener(mSwitchDiversityListener);
130     }
131
132     @Override
133     protected void onResume() {
134         super.onResume();
135         mSwitchDiversityListener.onCheckedChanged(mSwitchDiversity.getSwitch(),
136                 mSwitchDiversity.isChecked());
137     }
138
139     @Override
140     protected void onNextButtonClick(View view) {
141         final Intent intent = new Intent();
142         if (mToken != null) {
143             intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, mToken);
144         }
145         if (mUserId != UserHandle.USER_NULL) {
146             intent.putExtra(Intent.EXTRA_USER_ID, mUserId);
147         }
148         final String flattenedString = getString(R.string.config_face_enroll);
149         if (!TextUtils.isEmpty(flattenedString)) {
150             ComponentName componentName = ComponentName.unflattenFromString(flattenedString);
151             intent.setComponent(componentName);
152         } else {
153             intent.setClass(this, FaceEnrollEnrolling.class);
154         }
155         intent.putExtra(EXTRA_KEY_REQUIRE_DIVERSITY, !mSwitchDiversity.isChecked());
156         WizardManagerHelper.copyWizardManagerExtras(getIntent(), intent);
157         startActivityForResult(intent, BIOMETRIC_FIND_SENSOR_REQUEST);
158     }
159
160     protected void onSkipButtonClick(View view) {
161         setResult(RESULT_SKIP);
162         finish();
163     }
164
165     @Override
166     protected void onActivityResult(int requestCode, int resultCode, Intent data) {
167         if (requestCode == BIOMETRIC_FIND_SENSOR_REQUEST) {
168             setResult(resultCode);
169             finish();
170         }
171     }
172
173     @Override
174     public int getMetricsCategory() {
175         return SettingsEnums.FACE_ENROLL_INTRO;
176     }
177 }