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