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
17package com.android.settings.fingerprint;
18
19import android.annotation.Nullable;
20import android.content.Intent;
21import android.content.res.Resources;
22import android.graphics.Color;
23import android.os.Bundle;
24import android.os.UserHandle;
25import android.text.TextUtils;
26import android.view.View;
27import android.widget.Button;
28import android.widget.TextView;
29
30import com.android.settings.R;
31import com.android.settings.SetupWizardUtils;
32import com.android.settings.core.InstrumentedActivity;
33import com.android.settings.password.ChooseLockSettingsHelper;
34import com.android.setupwizardlib.GlifLayout;
35
36/**
37 * Base activity for all fingerprint enrollment steps.
38 */
39public abstract class FingerprintEnrollBase extends InstrumentedActivity
40        implements View.OnClickListener {
41    public 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
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
62    protected void onApplyThemeResource(Resources.Theme theme, int resid, boolean first) {
63        resid = SetupWizardUtils.getTheme(getIntent());
64        super.onApplyThemeResource(theme, resid, first);
65    }
66
67    @Override
68    protected void onSaveInstanceState(Bundle outState) {
69        super.onSaveInstanceState(outState);
70        outState.putByteArray(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, mToken);
71    }
72
73    @Override
74    protected void onPostCreate(@Nullable Bundle savedInstanceState) {
75        super.onPostCreate(savedInstanceState);
76        initViews();
77    }
78
79    protected void initViews() {
80        getWindow().setStatusBarColor(Color.TRANSPARENT);
81        Button nextButton = getNextButton();
82        if (nextButton != null) {
83            nextButton.setOnClickListener(this);
84        }
85    }
86
87    protected GlifLayout getLayout() {
88        return (GlifLayout) findViewById(R.id.setup_wizard_layout);
89    }
90
91    protected void setHeaderText(int resId, boolean force) {
92        TextView layoutTitle = getLayout().getHeaderTextView();
93        CharSequence previousTitle = layoutTitle.getText();
94        CharSequence title = getText(resId);
95        if (previousTitle != title || force) {
96            if (!TextUtils.isEmpty(previousTitle)) {
97                layoutTitle.setAccessibilityLiveRegion(View.ACCESSIBILITY_LIVE_REGION_POLITE);
98            }
99            getLayout().setHeaderText(title);
100            setTitle(title);
101        }
102    }
103
104    protected void setHeaderText(int resId) {
105        setHeaderText(resId, false /* force */);
106    }
107
108    protected Button getNextButton() {
109        return (Button) findViewById(R.id.next_button);
110    }
111
112    @Override
113    public void onClick(View v) {
114        if (v == getNextButton()) {
115            onNextButtonClick();
116        }
117    }
118
119    protected void onNextButtonClick() {
120    }
121
122    protected Intent getEnrollingIntent() {
123        Intent intent = new Intent();
124        intent.setClassName("com.android.settings", FingerprintEnrollEnrolling.class.getName());
125        intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, mToken);
126        if (mUserId != UserHandle.USER_NULL) {
127            intent.putExtra(Intent.EXTRA_USER_ID, mUserId);
128        }
129        return intent;
130    }
131}
132