package com.akexorcist.passapp;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import com.samsung.android.sdk.SsdkUnsupportedException;
import com.samsung.android.sdk.pass.Spass;
import com.samsung.android.sdk.pass.SpassFingerprint;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    private SpassFingerprint mSpassFingerprint;
    private Spass mSpass;

    private Button btnVerify;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        btnVerify = (Button) findViewById(R.id.btn_verify);
        btnVerify.setOnClickListener(this);

        if (setupSPass()) {
            btnVerify.setEnabled(true);
        } else {
            btnVerify.setEnabled(false);
        }
    }

    private boolean setupSPass() {
        mSpass = new Spass();
        try {
            mSpass.initialize(this);
            if (mSpass.isFeatureEnabled(Spass.DEVICE_FINGERPRINT)) {
                mSpassFingerprint = new SpassFingerprint(this);
                return true;
            }
        } catch (SsdkUnsupportedException e) {
            // Fingerprint Service is not supported in this SDK
        } catch (UnsupportedOperationException e) {
            // Fingerprint Service is not supported in this device
        }
        return false;
    }

    @Override
    public void onClick(View v) {
        if (v == btnVerify) {
            startIdentifyDialog(true);
        }
    }

    private void startIdentifyDialog(boolean backup) {
        if (mSpassFingerprint != null) {
            mSpassFingerprint.startIdentifyWithDialog(this, mIdentifyListenerDialog, backup);
        }
    }

    private SpassFingerprint.IdentifyListener mIdentifyListenerDialog = new SpassFingerprint.IdentifyListener() {
        @Override
        public void onFinished(int eventStatus) {
            Toast.makeText(MainActivity.this, getEventStatusName(eventStatus), Toast.LENGTH_SHORT).show();

            if (eventStatus == SpassFingerprint.STATUS_AUTHENTIFICATION_SUCCESS) {
                // Authentification Success
                int index = mSpassFingerprint.getIdentifiedFingerprintIndex();
                Toast.makeText(MainActivity.this, "Fingerprint Index : " + index, Toast.LENGTH_SHORT).show();
            } else if (eventStatus == SpassFingerprint.STATUS_AUTHENTIFICATION_PASSWORD_SUCCESS) {
                // Authentification Password Success
            } else if (eventStatus == SpassFingerprint.STATUS_USER_CANCELLED
                    || eventStatus == SpassFingerprint.STATUS_USER_CANCELLED_BY_TOUCH_OUTSIDE) {
                // Authentification Cancel
            } else if (eventStatus == SpassFingerprint.STATUS_TIMEOUT_FAILED) {
                // Authentification Timeout
            } else if (eventStatus == SpassFingerprint.STATUS_QUALITY_FAILED) {
                // Authentification Quality Failed
            } else {
                // Authentification Failed
            }
        }

        @Override
        public void onReady() {
            // Fingerprint sensor is ready
        }

        @Override
        public void onStarted() {
            // User touched fingerprint sensor
        }

        @Override
        public void onCompleted() {
            // Identify is completed
        }
    };

    private static String getEventStatusName(int eventStatus) {
        switch (eventStatus) {
            case SpassFingerprint.STATUS_AUTHENTIFICATION_SUCCESS:
                return "STATUS_AUTHENTIFICATION_SUCCESS";
            case SpassFingerprint.STATUS_AUTHENTIFICATION_PASSWORD_SUCCESS:
                return "STATUS_AUTHENTIFICATION_PASSWORD_SUCCESS";
            case SpassFingerprint.STATUS_TIMEOUT_FAILED:
                return "STATUS_TIMEOUT";
            case SpassFingerprint.STATUS_SENSOR_FAILED:
                return "STATUS_SENSOR_ERROR";
            case SpassFingerprint.STATUS_USER_CANCELLED:
                return "STATUS_USER_CANCELLED";
            case SpassFingerprint.STATUS_QUALITY_FAILED:
                return "STATUS_QUALITY_FAILED";
            case SpassFingerprint.STATUS_USER_CANCELLED_BY_TOUCH_OUTSIDE:
                return "STATUS_USER_CANCELLED_BY_TOUCH_OUTSIDE";
            default:
                return "STATUS_AUTHENTIFICATION_FAILED";
        }
    }
}

@@ -26,16 +26,42 @@
 ssapp;%0A%0A
+import android.os.Bundle;%0A
 import a
@@ -105,59 +105,8 @@
 ty;%0A
-import android.os.Bundle;%0Aimport android.util.Log;%0A
 impo
@@ -457,18 +457,17 @@
 erprint 
-mS
+s
 passFing
@@ -493,18 +493,17 @@
 e Spass 
-mS
+s
 pass;%0A%0A 
@@ -983,26 +983,25 @@
 ) %7B%0A        
-mS
+s
 pass = new S
@@ -1030,26 +1030,25 @@
             
-mS
+s
 pass.initial
@@ -1070,26 +1070,25 @@
         if (
-mS
+s
 pass.isFeatu
@@ -1134,34 +1134,33 @@
                 
-mS
+s
 passFingerprint 
@@ -1278,94 +1278,10 @@
 ion 
-e) %7B%0A            // Fingerprint Service is not supported in this SDK%0A        %7D catch (
+%7C 
 Unsu
@@ -1375,14 +1375,11 @@
 his 
-device
+SDK
 %0A   
@@ -1615,18 +1615,17 @@
     if (
-mS
+s
 passFing
@@ -1655,18 +1655,17 @@
         
-mS
+s
 passFing
@@ -2042,17 +2042,16 @@
 show();%0A
-%0A
         
@@ -2148,26 +2148,24 @@
  // Authenti
-fi
 cation Succe
@@ -2199,10 +2199,9 @@
 x = 
-mS
+s
 pass
@@ -2477,26 +2477,24 @@
  // Authenti
-fi
 cation Passw
@@ -2702,26 +2702,24 @@
  // Authenti
-fi
 cation Cance
@@ -2823,26 +2823,24 @@
  // Authenti
-fi
 cation Timeo
@@ -2945,26 +2945,24 @@
  // Authenti
-fi
 cation Quali
@@ -3019,18 +3019,16 @@
 Authenti
-fi
 cation F

Fix wording Fix variable name Remove unused code