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.content.Intent;
     20 import android.hardware.fingerprint.FingerprintManager;
     21 import android.os.Bundle;
     22 import android.view.View;
     23 import android.widget.Button;
     24 
     25 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
     26 import com.android.settings.R;
     27 import com.android.settings.Utils;
     28 
     29 /**
     30  * Activity which concludes fingerprint enrollment.
     31  */
     32 public class FingerprintEnrollFinish extends FingerprintEnrollBase {
     33 
     34     private static final int REQUEST_ADD_ANOTHER = 1;
     35 
     36     @Override
     37     protected void onCreate(Bundle savedInstanceState) {
     38         super.onCreate(savedInstanceState);
     39         setContentView(R.layout.fingerprint_enroll_finish);
     40         setHeaderText(R.string.security_settings_fingerprint_enroll_finish_title);
     41     }
     42 
     43     @Override
     44     protected void onResume() {
     45         super.onResume();
     46 
     47         Button addButton = (Button) findViewById(R.id.add_another_button);
     48 
     49         final FingerprintManager fpm = Utils.getFingerprintManagerOrNull(this);
     50         boolean hideAddAnother = false;
     51         if (fpm != null) {
     52             int enrolled = fpm.getEnrolledFingerprints(mUserId).size();
     53             int max = getResources().getInteger(
     54                     com.android.internal.R.integer.config_fingerprintMaxTemplatesPerUser);
     55             hideAddAnother = enrolled >= max;
     56         }
     57         if (hideAddAnother) {
     58             // Don't show "Add" button if too many fingerprints already added
     59             addButton.setVisibility(View.INVISIBLE);
     60         } else {
     61             addButton.setOnClickListener(this);
     62         }
     63     }
     64 
     65     @Override
     66     protected void onNextButtonClick() {
     67         setResult(RESULT_FINISHED);
     68         finish();
     69     }
     70 
     71     @Override
     72     public void onClick(View v) {
     73         if (v.getId() == R.id.add_another_button) {
     74             startActivityForResult(getEnrollingIntent(), REQUEST_ADD_ANOTHER);
     75         }
     76         super.onClick(v);
     77     }
     78 
     79     @Override
     80     protected void onActivityResult(int requestCode, int resultCode, Intent data) {
     81         if (requestCode == REQUEST_ADD_ANOTHER && resultCode != RESULT_CANCELED) {
     82             setResult(resultCode, data);
     83             finish();
     84         } else {
     85             super.onActivityResult(requestCode, resultCode, data);
     86         }
     87     }
     88 
     89     @Override
     90     public int getMetricsCategory() {
     91         return MetricsEvent.FINGERPRINT_ENROLL_FINISH;
     92     }
     93 }
     94