package com.andrognito.pinlockapp;

import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import com.andrognito.pinlockview.IndicatorDots;
import com.andrognito.pinlockview.PinLockListener;
import com.andrognito.pinlockview.PinLockView;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Random;
/* loaded from: classes.dex */
public class SampleActivity extends AppCompatActivity {
    public static final String TAG = "PinLockView";
    private IndicatorDots mIndicatorDots;
    private PinLockView mPinLockView;
    SharedPreferences prefs;
    public String storedPIN = "";
    private final PinLockListener mPinLockListener = new PinLockListener() { // from class: com.andrognito.pinlockapp.SampleActivity.1
        @Override // com.andrognito.pinlockview.PinLockListener
        public void onComplete(String pin) {
            Log.d(SampleActivity.TAG, "Pin complete: " + pin);
            if (SampleActivity.this.storedPIN.equalsIgnoreCase(pin)) {
                Log.d(SampleActivity.TAG, "SUCCESS");
                AlertDialog alertDialog = new AlertDialog.Builder(SampleActivity.this).create();
                alertDialog.setTitle("SUCCESS");
                alertDialog.setMessage("You entered the correct PIN! Congratulation!");
                alertDialog.setButton(-3, "OK", new DialogInterface.OnClickListener() { // from class: com.andrognito.pinlockapp.SampleActivity.1.1
                    @Override // android.content.DialogInterface.OnClickListener
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                });
                alertDialog.show();
                return;
            }
            int counter = SampleActivity.this.prefs.getInt("ch.cscn.counter", 0);
            if (counter > 4) {
                AlertDialog alertDialog2 = new AlertDialog.Builder(SampleActivity.this).create();
                alertDialog2.setTitle("WRONG PIN");
                alertDialog2.setMessage("You entered the wrong PIN more than 5 times. The app is going to close.");
                alertDialog2.setButton(-3, "OK", new DialogInterface.OnClickListener() { // from class: com.andrognito.pinlockapp.SampleActivity.1.2
                    @Override // android.content.DialogInterface.OnClickListener
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                        SampleActivity.this.finishAndRemoveTask();
                    }
                });
                alertDialog2.show();
                return;
            }
            Log.d(SampleActivity.TAG, "Wrong PIN! Correct PIN is " + SampleActivity.this.storedPIN);
            AlertDialog alertDialog3 = new AlertDialog.Builder(SampleActivity.this).create();
            alertDialog3.setTitle("WRONG PIN");
            alertDialog3.setMessage("You entered the wrong PIN. Please retry...");
            alertDialog3.setButton(-3, "OK", new DialogInterface.OnClickListener() { // from class: com.andrognito.pinlockapp.SampleActivity.1.3
                @Override // android.content.DialogInterface.OnClickListener
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });
            alertDialog3.show();
            SharedPreferences.Editor editor = SampleActivity.this.prefs.edit();
            editor.putInt("ch.cscn.counter", counter + 1);
            editor.apply();
        }

        @Override // com.andrognito.pinlockview.PinLockListener
        public void onEmpty() {
            Log.d(SampleActivity.TAG, "Pin empty");
        }

        @Override // com.andrognito.pinlockview.PinLockListener
        public void onPinChange(int pinLength, String intermediatePin) {
            Log.d(SampleActivity.TAG, "Pin changed, new length " + pinLength + " with intermediate pin " + intermediatePin);
        }
    };

    /* JADX INFO: Access modifiers changed from: protected */
    @Override // android.support.v7.app.AppCompatActivity, android.support.v4.app.FragmentActivity, android.support.v4.app.BaseFragmentActivityGingerbread, android.app.Activity
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(1);
        getWindow().setFlags(1024, 1024);
        setContentView(com.andrognito.pinlockviewappSimple.R.layout.activity_sample);
        SharedPreferences sharedPreferences = getSharedPreferences("ch.cscn.pinlockapp", 0);
        this.prefs = sharedPreferences;
        String pin = sharedPreferences.getString("ch.cscn.pin", "");
        if (pin.equalsIgnoreCase("")) {
            SharedPreferences.Editor editor = this.prefs.edit();
            editor.putString("ch.cscn.pin", getRandomNumberString());
            editor.putInt("ch.cscn.counter", 0);
            editor.apply();
        }
        int counter = this.prefs.getInt("ch.cscn.counter", 0);
        if (counter > 4) {
            AlertDialog alertDialog = new AlertDialog.Builder(this).create();
            alertDialog.setTitle("WRONG PIN");
            alertDialog.setMessage("You entered the wrong PIN more than 5 times. The app is going to close.");
            alertDialog.setButton(-3, "OK", new DialogInterface.OnClickListener() { // from class: com.andrognito.pinlockapp.SampleActivity.2
                @Override // android.content.DialogInterface.OnClickListener
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    SampleActivity.this.finishAndRemoveTask();
                }
            });
            alertDialog.show();
        }
        this.storedPIN = this.prefs.getString("ch.cscn.pin", "");
        this.mPinLockView = (PinLockView) findViewById(com.andrognito.pinlockviewappSimple.R.id.pin_lock_view);
        IndicatorDots indicatorDots = (IndicatorDots) findViewById(com.andrognito.pinlockviewappSimple.R.id.indicator_dots);
        this.mIndicatorDots = indicatorDots;
        this.mPinLockView.attachIndicatorDots(indicatorDots);
        this.mPinLockView.setPinLockListener(this.mPinLockListener);
        this.mPinLockView.setPinLength(6);
        this.mPinLockView.setTextColor(ContextCompat.getColor(this, com.andrognito.pinlockviewappSimple.R.color.white));
        this.mIndicatorDots.setIndicatorType(2);
    }

    public static String getRandomNumberString() {
        Random rnd = new Random();
        int number = rnd.nextInt(999999);
        return String.format("%06d", Integer.valueOf(number));
    }

    public static String sha256String(String source) {
        byte[] hash = null;
        try {
            MessageDigest digest = MessageDigest.getInstance("SHA-256");
            hash = digest.digest(source.getBytes());
        } catch (NoSuchAlgorithmException e) {
            Log.d(TAG, "Can't calculate SHA-256");
        }
        if (hash == null) {
            return null;
        }
        StringBuilder hashBuilder = new StringBuilder();
        for (byte b : hash) {
            String hex = Integer.toHexString(b);
            if (hex.length() == 1) {
                hashBuilder.append("0");
                hashBuilder.append(hex.charAt(hex.length() - 1));
            } else {
                hashBuilder.append(hex.substring(hex.length() - 2));
            }
        }
        String hashCode = hashBuilder.toString();
        return hashCode;
    }
}
