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