1 /*
2  * Copyright (C) 2015 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.fingerprint;
18 
19 import android.annotation.Nullable;
20 import android.content.Intent;
21 import android.graphics.Color;
22 import android.os.Bundle;
23 import android.os.UserHandle;
24 import android.text.TextUtils;
25 import android.view.View;
26 import android.view.WindowManager;
27 import android.widget.Button;
28 import android.widget.TextView;
29 
30 import com.android.settings.ChooseLockSettingsHelper;
31 import com.android.settings.InstrumentedActivity;
32 import com.android.settings.R;
33 import com.android.setupwizardlib.SetupWizardLayout;
34 import com.android.setupwizardlib.view.NavigationBar;
35 
36 /**
37  * Base activity for all fingerprint enrollment steps.
38  */
39 public abstract class FingerprintEnrollBase extends InstrumentedActivity
40         implements View.OnClickListener {
41     static final int RESULT_FINISHED = FingerprintSettings.RESULT_FINISHED;
42     static final int RESULT_SKIP = FingerprintSettings.RESULT_SKIP;
43     static final int RESULT_TIMEOUT = FingerprintSettings.RESULT_TIMEOUT;
44 
45     protected byte[] mToken;
46     protected int mUserId;
47 
48     @Override
onCreate(Bundle savedInstanceState)49     protected void onCreate(Bundle savedInstanceState) {
50         super.onCreate(savedInstanceState);
51         setTheme(R.style.Theme_FingerprintEnroll);
52         mToken = getIntent().getByteArrayExtra(
53                 ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN);
54         if (savedInstanceState != null && mToken == null) {
55             mToken = savedInstanceState.getByteArray(
56                     ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN);
57         }
58         mUserId = getIntent().getIntExtra(Intent.EXTRA_USER_ID, UserHandle.myUserId());
59     }
60 
61     @Override
onSaveInstanceState(Bundle outState)62     protected void onSaveInstanceState(Bundle outState) {
63         super.onSaveInstanceState(outState);
64         outState.putByteArray(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, mToken);
65     }
66 
67     @Override
onPostCreate(@ullable Bundle savedInstanceState)68     protected void onPostCreate(@Nullable Bundle savedInstanceState) {
69         super.onPostCreate(savedInstanceState);
70         initViews();
71     }
72 
initViews()73     protected void initViews() {
74         getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS |
75                 WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN |
76                 WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR);
77 
78         getWindow().getDecorView().setSystemUiVisibility(
79                 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
80 
81         getWindow().setStatusBarColor(Color.TRANSPARENT);
82         getNavigationBar().setVisibility(View.GONE);
83         Button nextButton = getNextButton();
84         if (nextButton != null) {
85             nextButton.setOnClickListener(this);
86         }
87     }
88 
getNavigationBar()89     protected NavigationBar getNavigationBar() {
90         return (NavigationBar) findViewById(R.id.suw_layout_navigation_bar);
91     }
92 
getSetupWizardLayout()93     protected SetupWizardLayout getSetupWizardLayout() {
94         return (SetupWizardLayout) findViewById(R.id.setup_wizard_layout);
95     }
96 
setHeaderText(int resId, boolean force)97     protected void setHeaderText(int resId, boolean force) {
98         TextView layoutTitle = getSetupWizardLayout().getHeaderTextView();
99         CharSequence previousTitle = layoutTitle.getText();
100         CharSequence title = getText(resId);
101         if (previousTitle != title || force) {
102             if (!TextUtils.isEmpty(previousTitle)) {
103                 layoutTitle.setAccessibilityLiveRegion(View.ACCESSIBILITY_LIVE_REGION_POLITE);
104             }
105             getSetupWizardLayout().setHeaderText(title);
106             setTitle(title);
107         }
108     }
109 
setHeaderText(int resId)110     protected void setHeaderText(int resId) {
111         setHeaderText(resId, false /* force */);
112     }
113 
getNextButton()114     protected Button getNextButton() {
115         return (Button) findViewById(R.id.next_button);
116     }
117 
118     @Override
onClick(View v)119     public void onClick(View v) {
120         if (v == getNextButton()) {
121             onNextButtonClick();
122         }
123     }
124 
onNextButtonClick()125     protected void onNextButtonClick() {
126     }
127 
getEnrollingIntent()128     protected Intent getEnrollingIntent() {
129         Intent intent = new Intent();
130         intent.setClassName("com.android.settings", FingerprintEnrollEnrolling.class.getName());
131         intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, mToken);
132         if (mUserId != UserHandle.USER_NULL) {
133             intent.putExtra(Intent.EXTRA_USER_ID, mUserId);
134         }
135         return intent;
136     }
137 }
138