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.app.admin.DevicePolicyManager;
20import android.content.Intent;
21import android.os.Bundle;
22import android.os.UserHandle;
23import android.view.View;
24
25import com.android.settings.ChooseLockSettingsHelper;
26import com.android.settings.HelpUtils;
27import com.android.settings.R;
28
29/**
30 * Onboarding activity for fingerprint enrollment.
31 */
32public class FingerprintEnrollIntroduction extends FingerprintEnrollBase {
33
34    private boolean mHasPassword;
35
36    @Override
37    protected void onCreate(Bundle savedInstanceState) {
38        super.onCreate(savedInstanceState);
39        setContentView(R.layout.fingerprint_enroll_introduction);
40        setHeaderText(R.string.security_settings_fingerprint_enroll_introduction_title);
41        findViewById(R.id.cancel_button).setOnClickListener(this);
42        findViewById(R.id.learn_more_button).setOnClickListener(this);
43        final int passwordQuality = new ChooseLockSettingsHelper(this).utils()
44                .getActivePasswordQuality(UserHandle.myUserId());
45        mHasPassword = passwordQuality != DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED;
46    }
47
48    @Override
49    protected void onNextButtonClick() {
50        Intent intent;
51        if (!mHasPassword) {
52            // No fingerprints registered, launch into enrollment wizard.
53            intent = getOnboardIntent();
54        } else {
55            // Lock thingy is already set up, launch directly into find sensor step from wizard.
56            intent = getFindSensorIntent();
57        }
58        startActivityForResult(intent, 0);
59    }
60
61    protected Intent getOnboardIntent() {
62        return new Intent(this, FingerprintEnrollOnboard.class);
63    }
64
65    protected Intent getFindSensorIntent() {
66        return new Intent(this, FingerprintEnrollFindSensor.class);
67    }
68
69    @Override
70    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
71        if (resultCode == RESULT_FINISHED) {
72            setResult(RESULT_OK);
73            finish();
74        } else {
75            super.onActivityResult(requestCode, resultCode, data);
76        }
77    }
78
79    @Override
80    public void onClick(View v) {
81        if (v.getId() == R.id.cancel_button) {
82            finish();
83        }
84        if (v.getId() == R.id.learn_more_button) {
85            launchFingerprintHelp();
86        }
87        super.onClick(v);
88    }
89
90    private void launchFingerprintHelp() {
91        Intent helpIntent = HelpUtils.getHelpIntent(this,
92                getString(R.string.help_url_fingerprint), getClass().getName());
93        startActivity(helpIntent);
94    }
95}
96