package com.andrognito.pinlockview;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import com.andrognito.pinlockview.PinLockAdapter;
/* loaded from: classes.dex */
public class PinLockView extends RecyclerView {
    private static final int[] DEFAULT_KEY_SET = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0};
    private static final int DEFAULT_PIN_LENGTH = 4;
    private PinLockAdapter mAdapter;
    private Drawable mButtonBackgroundDrawable;
    private int mButtonSize;
    private int[] mCustomKeySet;
    private CustomizationOptionsBundle mCustomizationOptionsBundle;
    private Drawable mDeleteButtonDrawable;
    private int mDeleteButtonPressedColor;
    private int mDeleteButtonSize;
    private int mHorizontalSpacing;
    private IndicatorDots mIndicatorDots;
    private PinLockAdapter.OnDeleteClickListener mOnDeleteClickListener;
    private PinLockAdapter.OnNumberClickListener mOnNumberClickListener;
    private String mPin;
    private int mPinLength;
    private PinLockListener mPinLockListener;
    private boolean mShowDeleteButton;
    private int mTextColor;
    private int mTextSize;
    private int mVerticalSpacing;

    public PinLockView(Context context) {
        super(context);
        this.mPin = "";
        this.mOnNumberClickListener = new PinLockAdapter.OnNumberClickListener() { // from class: com.andrognito.pinlockview.PinLockView.1
            @Override // com.andrognito.pinlockview.PinLockAdapter.OnNumberClickListener
            public void onNumberClicked(int keyValue) {
                if (PinLockView.this.mPin.length() < PinLockView.this.getPinLength()) {
                    PinLockView pinLockView = PinLockView.this;
                    pinLockView.mPin = pinLockView.mPin.concat(String.valueOf(keyValue));
                    if (PinLockView.this.isIndicatorDotsAttached()) {
                        PinLockView.this.mIndicatorDots.updateDot(PinLockView.this.mPin.length());
                    }
                    if (PinLockView.this.mPin.length() == 1) {
                        PinLockView.this.mAdapter.setPinLength(PinLockView.this.mPin.length());
                        PinLockView.this.mAdapter.notifyItemChanged(PinLockView.this.mAdapter.getItemCount() - 1);
                    }
                    if (PinLockView.this.mPinLockListener != null) {
                        if (PinLockView.this.mPin.length() == PinLockView.this.mPinLength) {
                            PinLockView.this.mPinLockListener.onComplete(PinLockView.this.mPin);
                            PinLockView.this.resetPinLockView();
                            return;
                        }
                        PinLockView.this.mPinLockListener.onPinChange(PinLockView.this.mPin.length(), PinLockView.this.mPin);
                    }
                } else if (PinLockView.this.isShowDeleteButton()) {
                    if (PinLockView.this.mPinLockListener != null) {
                        PinLockView.this.mPinLockListener.onComplete(PinLockView.this.mPin);
                        PinLockView.this.resetPinLockView();
                    }
                } else {
                    PinLockView.this.resetPinLockView();
                    PinLockView pinLockView2 = PinLockView.this;
                    pinLockView2.mPin = pinLockView2.mPin.concat(String.valueOf(keyValue));
                    if (PinLockView.this.isIndicatorDotsAttached()) {
                        PinLockView.this.mIndicatorDots.updateDot(PinLockView.this.mPin.length());
                    }
                    if (PinLockView.this.mPinLockListener != null) {
                        PinLockView.this.mPinLockListener.onPinChange(PinLockView.this.mPin.length(), PinLockView.this.mPin);
                    }
                }
            }
        };
        this.mOnDeleteClickListener = new PinLockAdapter.OnDeleteClickListener() { // from class: com.andrognito.pinlockview.PinLockView.2
            @Override // com.andrognito.pinlockview.PinLockAdapter.OnDeleteClickListener
            public void onDeleteClicked() {
                if (PinLockView.this.mPin.length() <= 0) {
                    if (PinLockView.this.mPinLockListener != null) {
                        PinLockView.this.mPinLockListener.onEmpty();
                        return;
                    }
                    return;
                }
                PinLockView pinLockView = PinLockView.this;
                pinLockView.mPin = pinLockView.mPin.substring(0, PinLockView.this.mPin.length() - 1);
                if (PinLockView.this.isIndicatorDotsAttached()) {
                    PinLockView.this.mIndicatorDots.updateDot(PinLockView.this.mPin.length());
                }
                if (PinLockView.this.mPin.length() == 0) {
                    PinLockView.this.mAdapter.setPinLength(PinLockView.this.mPin.length());
                    PinLockView.this.mAdapter.notifyItemChanged(PinLockView.this.mAdapter.getItemCount() - 1);
                }
                if (PinLockView.this.mPinLockListener != null) {
                    if (PinLockView.this.mPin.length() == 0) {
                        PinLockView.this.mPinLockListener.onEmpty();
                        PinLockView.this.clearInternalPin();
                        return;
                    }
                    PinLockView.this.mPinLockListener.onPinChange(PinLockView.this.mPin.length(), PinLockView.this.mPin);
                }
            }

            @Override // com.andrognito.pinlockview.PinLockAdapter.OnDeleteClickListener
            public void onDeleteLongClicked() {
                PinLockView.this.resetPinLockView();
                if (PinLockView.this.mPinLockListener != null) {
                    PinLockView.this.mPinLockListener.onEmpty();
                }
            }
        };
        init(null, 0);
    }

    public PinLockView(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.mPin = "";
        this.mOnNumberClickListener = new PinLockAdapter.OnNumberClickListener() { // from class: com.andrognito.pinlockview.PinLockView.1
            @Override // com.andrognito.pinlockview.PinLockAdapter.OnNumberClickListener
            public void onNumberClicked(int keyValue) {
                if (PinLockView.this.mPin.length() < PinLockView.this.getPinLength()) {
                    PinLockView pinLockView = PinLockView.this;
                    pinLockView.mPin = pinLockView.mPin.concat(String.valueOf(keyValue));
                    if (PinLockView.this.isIndicatorDotsAttached()) {
                        PinLockView.this.mIndicatorDots.updateDot(PinLockView.this.mPin.length());
                    }
                    if (PinLockView.this.mPin.length() == 1) {
                        PinLockView.this.mAdapter.setPinLength(PinLockView.this.mPin.length());
                        PinLockView.this.mAdapter.notifyItemChanged(PinLockView.this.mAdapter.getItemCount() - 1);
                    }
                    if (PinLockView.this.mPinLockListener != null) {
                        if (PinLockView.this.mPin.length() == PinLockView.this.mPinLength) {
                            PinLockView.this.mPinLockListener.onComplete(PinLockView.this.mPin);
                            PinLockView.this.resetPinLockView();
                            return;
                        }
                        PinLockView.this.mPinLockListener.onPinChange(PinLockView.this.mPin.length(), PinLockView.this.mPin);
                    }
                } else if (PinLockView.this.isShowDeleteButton()) {
                    if (PinLockView.this.mPinLockListener != null) {
                        PinLockView.this.mPinLockListener.onComplete(PinLockView.this.mPin);
                        PinLockView.this.resetPinLockView();
                    }
                } else {
                    PinLockView.this.resetPinLockView();
                    PinLockView pinLockView2 = PinLockView.this;
                    pinLockView2.mPin = pinLockView2.mPin.concat(String.valueOf(keyValue));
                    if (PinLockView.this.isIndicatorDotsAttached()) {
                        PinLockView.this.mIndicatorDots.updateDot(PinLockView.this.mPin.length());
                    }
                    if (PinLockView.this.mPinLockListener != null) {
                        PinLockView.this.mPinLockListener.onPinChange(PinLockView.this.mPin.length(), PinLockView.this.mPin);
                    }
                }
            }
        };
        this.mOnDeleteClickListener = new PinLockAdapter.OnDeleteClickListener() { // from class: com.andrognito.pinlockview.PinLockView.2
            @Override // com.andrognito.pinlockview.PinLockAdapter.OnDeleteClickListener
            public void onDeleteClicked() {
                if (PinLockView.this.mPin.length() <= 0) {
                    if (PinLockView.this.mPinLockListener != null) {
                        PinLockView.this.mPinLockListener.onEmpty();
                        return;
                    }
                    return;
                }
                PinLockView pinLockView = PinLockView.this;
                pinLockView.mPin = pinLockView.mPin.substring(0, PinLockView.this.mPin.length() - 1);
                if (PinLockView.this.isIndicatorDotsAttached()) {
                    PinLockView.this.mIndicatorDots.updateDot(PinLockView.this.mPin.length());
                }
                if (PinLockView.this.mPin.length() == 0) {
                    PinLockView.this.mAdapter.setPinLength(PinLockView.this.mPin.length());
                    PinLockView.this.mAdapter.notifyItemChanged(PinLockView.this.mAdapter.getItemCount() - 1);
                }
                if (PinLockView.this.mPinLockListener != null) {
                    if (PinLockView.this.mPin.length() == 0) {
                        PinLockView.this.mPinLockListener.onEmpty();
                        PinLockView.this.clearInternalPin();
                        return;
                    }
                    PinLockView.this.mPinLockListener.onPinChange(PinLockView.this.mPin.length(), PinLockView.this.mPin);
                }
            }

            @Override // com.andrognito.pinlockview.PinLockAdapter.OnDeleteClickListener
            public void onDeleteLongClicked() {
                PinLockView.this.resetPinLockView();
                if (PinLockView.this.mPinLockListener != null) {
                    PinLockView.this.mPinLockListener.onEmpty();
                }
            }
        };
        init(attrs, 0);
    }

    public PinLockView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        this.mPin = "";
        this.mOnNumberClickListener = new PinLockAdapter.OnNumberClickListener() { // from class: com.andrognito.pinlockview.PinLockView.1
            @Override // com.andrognito.pinlockview.PinLockAdapter.OnNumberClickListener
            public void onNumberClicked(int keyValue) {
                if (PinLockView.this.mPin.length() < PinLockView.this.getPinLength()) {
                    PinLockView pinLockView = PinLockView.this;
                    pinLockView.mPin = pinLockView.mPin.concat(String.valueOf(keyValue));
                    if (PinLockView.this.isIndicatorDotsAttached()) {
                        PinLockView.this.mIndicatorDots.updateDot(PinLockView.this.mPin.length());
                    }
                    if (PinLockView.this.mPin.length() == 1) {
                        PinLockView.this.mAdapter.setPinLength(PinLockView.this.mPin.length());
                        PinLockView.this.mAdapter.notifyItemChanged(PinLockView.this.mAdapter.getItemCount() - 1);
                    }
                    if (PinLockView.this.mPinLockListener != null) {
                        if (PinLockView.this.mPin.length() == PinLockView.this.mPinLength) {
                            PinLockView.this.mPinLockListener.onComplete(PinLockView.this.mPin);
                            PinLockView.this.resetPinLockView();
                            return;
                        }
                        PinLockView.this.mPinLockListener.onPinChange(PinLockView.this.mPin.length(), PinLockView.this.mPin);
                    }
                } else if (PinLockView.this.isShowDeleteButton()) {
                    if (PinLockView.this.mPinLockListener != null) {
                        PinLockView.this.mPinLockListener.onComplete(PinLockView.this.mPin);
                        PinLockView.this.resetPinLockView();
                    }
                } else {
                    PinLockView.this.resetPinLockView();
                    PinLockView pinLockView2 = PinLockView.this;
                    pinLockView2.mPin = pinLockView2.mPin.concat(String.valueOf(keyValue));
                    if (PinLockView.this.isIndicatorDotsAttached()) {
                        PinLockView.this.mIndicatorDots.updateDot(PinLockView.this.mPin.length());
                    }
                    if (PinLockView.this.mPinLockListener != null) {
                        PinLockView.this.mPinLockListener.onPinChange(PinLockView.this.mPin.length(), PinLockView.this.mPin);
                    }
                }
            }
        };
        this.mOnDeleteClickListener = new PinLockAdapter.OnDeleteClickListener() { // from class: com.andrognito.pinlockview.PinLockView.2
            @Override // com.andrognito.pinlockview.PinLockAdapter.OnDeleteClickListener
            public void onDeleteClicked() {
                if (PinLockView.this.mPin.length() <= 0) {
                    if (PinLockView.this.mPinLockListener != null) {
                        PinLockView.this.mPinLockListener.onEmpty();
                        return;
                    }
                    return;
                }
                PinLockView pinLockView = PinLockView.this;
                pinLockView.mPin = pinLockView.mPin.substring(0, PinLockView.this.mPin.length() - 1);
                if (PinLockView.this.isIndicatorDotsAttached()) {
                    PinLockView.this.mIndicatorDots.updateDot(PinLockView.this.mPin.length());
                }
                if (PinLockView.this.mPin.length() == 0) {
                    PinLockView.this.mAdapter.setPinLength(PinLockView.this.mPin.length());
                    PinLockView.this.mAdapter.notifyItemChanged(PinLockView.this.mAdapter.getItemCount() - 1);
                }
                if (PinLockView.this.mPinLockListener != null) {
                    if (PinLockView.this.mPin.length() == 0) {
                        PinLockView.this.mPinLockListener.onEmpty();
                        PinLockView.this.clearInternalPin();
                        return;
                    }
                    PinLockView.this.mPinLockListener.onPinChange(PinLockView.this.mPin.length(), PinLockView.this.mPin);
                }
            }

            @Override // com.andrognito.pinlockview.PinLockAdapter.OnDeleteClickListener
            public void onDeleteLongClicked() {
                PinLockView.this.resetPinLockView();
                if (PinLockView.this.mPinLockListener != null) {
                    PinLockView.this.mPinLockListener.onEmpty();
                }
            }
        };
        init(attrs, defStyle);
    }

    private void init(AttributeSet attributeSet, int defStyle) {
        TypedArray typedArray = getContext().obtainStyledAttributes(attributeSet, R.styleable.PinLockView);
        try {
            this.mPinLength = typedArray.getInt(R.styleable.PinLockView_pinLength, 4);
            this.mHorizontalSpacing = (int) typedArray.getDimension(R.styleable.PinLockView_keypadHorizontalSpacing, ResourceUtils.getDimensionInPx(getContext(), R.dimen.default_horizontal_spacing));
            this.mVerticalSpacing = (int) typedArray.getDimension(R.styleable.PinLockView_keypadVerticalSpacing, ResourceUtils.getDimensionInPx(getContext(), R.dimen.default_vertical_spacing));
            this.mTextColor = typedArray.getColor(R.styleable.PinLockView_keypadTextColor, ResourceUtils.getColor(getContext(), R.color.white));
            this.mTextSize = (int) typedArray.getDimension(R.styleable.PinLockView_keypadTextSize, ResourceUtils.getDimensionInPx(getContext(), R.dimen.default_text_size));
            this.mButtonSize = (int) typedArray.getDimension(R.styleable.PinLockView_keypadButtonSize, ResourceUtils.getDimensionInPx(getContext(), R.dimen.default_button_size));
            this.mDeleteButtonSize = (int) typedArray.getDimension(R.styleable.PinLockView_keypadDeleteButtonSize, ResourceUtils.getDimensionInPx(getContext(), R.dimen.default_delete_button_size));
            this.mButtonBackgroundDrawable = typedArray.getDrawable(R.styleable.PinLockView_keypadButtonBackgroundDrawable);
            this.mDeleteButtonDrawable = typedArray.getDrawable(R.styleable.PinLockView_keypadDeleteButtonDrawable);
            this.mShowDeleteButton = typedArray.getBoolean(R.styleable.PinLockView_keypadShowDeleteButton, true);
            this.mDeleteButtonPressedColor = typedArray.getColor(R.styleable.PinLockView_keypadDeleteButtonPressedColor, ResourceUtils.getColor(getContext(), R.color.greyish));
            typedArray.recycle();
            CustomizationOptionsBundle customizationOptionsBundle = new CustomizationOptionsBundle();
            this.mCustomizationOptionsBundle = customizationOptionsBundle;
            customizationOptionsBundle.setTextColor(this.mTextColor);
            this.mCustomizationOptionsBundle.setTextSize(this.mTextSize);
            this.mCustomizationOptionsBundle.setButtonSize(this.mButtonSize);
            this.mCustomizationOptionsBundle.setButtonBackgroundDrawable(this.mButtonBackgroundDrawable);
            this.mCustomizationOptionsBundle.setDeleteButtonDrawable(this.mDeleteButtonDrawable);
            this.mCustomizationOptionsBundle.setDeleteButtonSize(this.mDeleteButtonSize);
            this.mCustomizationOptionsBundle.setShowDeleteButton(this.mShowDeleteButton);
            this.mCustomizationOptionsBundle.setDeleteButtonPressesColor(this.mDeleteButtonPressedColor);
            initView();
        } catch (Throwable th) {
            typedArray.recycle();
            throw th;
        }
    }

    private void initView() {
        setLayoutManager(new LTRGridLayoutManager(getContext(), 3));
        PinLockAdapter pinLockAdapter = new PinLockAdapter(getContext());
        this.mAdapter = pinLockAdapter;
        pinLockAdapter.setOnItemClickListener(this.mOnNumberClickListener);
        this.mAdapter.setOnDeleteClickListener(this.mOnDeleteClickListener);
        this.mAdapter.setCustomizationOptions(this.mCustomizationOptionsBundle);
        setAdapter(this.mAdapter);
        addItemDecoration(new ItemSpaceDecoration(this.mHorizontalSpacing, this.mVerticalSpacing, 3, false));
        setOverScrollMode(2);
    }

    public void setPinLockListener(PinLockListener pinLockListener) {
        this.mPinLockListener = pinLockListener;
    }

    public int getPinLength() {
        return this.mPinLength;
    }

    public void setPinLength(int pinLength) {
        this.mPinLength = pinLength;
        if (isIndicatorDotsAttached()) {
            this.mIndicatorDots.setPinLength(pinLength);
        }
    }

    public int getTextColor() {
        return this.mTextColor;
    }

    public void setTextColor(int textColor) {
        this.mTextColor = textColor;
        this.mCustomizationOptionsBundle.setTextColor(textColor);
        this.mAdapter.notifyDataSetChanged();
    }

    public int getTextSize() {
        return this.mTextSize;
    }

    public void setTextSize(int textSize) {
        this.mTextSize = textSize;
        this.mCustomizationOptionsBundle.setTextSize(textSize);
        this.mAdapter.notifyDataSetChanged();
    }

    public int getButtonSize() {
        return this.mButtonSize;
    }

    public void setButtonSize(int buttonSize) {
        this.mButtonSize = buttonSize;
        this.mCustomizationOptionsBundle.setButtonSize(buttonSize);
        this.mAdapter.notifyDataSetChanged();
    }

    public Drawable getButtonBackgroundDrawable() {
        return this.mButtonBackgroundDrawable;
    }

    public void setButtonBackgroundDrawable(Drawable buttonBackgroundDrawable) {
        this.mButtonBackgroundDrawable = buttonBackgroundDrawable;
        this.mCustomizationOptionsBundle.setButtonBackgroundDrawable(buttonBackgroundDrawable);
        this.mAdapter.notifyDataSetChanged();
    }

    public Drawable getDeleteButtonDrawable() {
        return this.mDeleteButtonDrawable;
    }

    public void setDeleteButtonDrawable(Drawable deleteBackgroundDrawable) {
        this.mDeleteButtonDrawable = deleteBackgroundDrawable;
        this.mCustomizationOptionsBundle.setDeleteButtonDrawable(deleteBackgroundDrawable);
        this.mAdapter.notifyDataSetChanged();
    }

    public int getDeleteButtonSize() {
        return this.mDeleteButtonSize;
    }

    public void setDeleteButtonSize(int deleteButtonSize) {
        this.mDeleteButtonSize = deleteButtonSize;
        this.mCustomizationOptionsBundle.setDeleteButtonSize(deleteButtonSize);
        this.mAdapter.notifyDataSetChanged();
    }

    public boolean isShowDeleteButton() {
        return this.mShowDeleteButton;
    }

    public void setShowDeleteButton(boolean showDeleteButton) {
        this.mShowDeleteButton = showDeleteButton;
        this.mCustomizationOptionsBundle.setShowDeleteButton(showDeleteButton);
        this.mAdapter.notifyDataSetChanged();
    }

    public int getDeleteButtonPressedColor() {
        return this.mDeleteButtonPressedColor;
    }

    public void setDeleteButtonPressedColor(int deleteButtonPressedColor) {
        this.mDeleteButtonPressedColor = deleteButtonPressedColor;
        this.mCustomizationOptionsBundle.setDeleteButtonPressesColor(deleteButtonPressedColor);
        this.mAdapter.notifyDataSetChanged();
    }

    public int[] getCustomKeySet() {
        return this.mCustomKeySet;
    }

    public void setCustomKeySet(int[] customKeySet) {
        this.mCustomKeySet = customKeySet;
        PinLockAdapter pinLockAdapter = this.mAdapter;
        if (pinLockAdapter != null) {
            pinLockAdapter.setKeyValues(customKeySet);
        }
    }

    public void enableLayoutShuffling() {
        int[] shuffle = ShuffleArrayUtils.shuffle(DEFAULT_KEY_SET);
        this.mCustomKeySet = shuffle;
        PinLockAdapter pinLockAdapter = this.mAdapter;
        if (pinLockAdapter != null) {
            pinLockAdapter.setKeyValues(shuffle);
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void clearInternalPin() {
        this.mPin = "";
    }

    public void resetPinLockView() {
        clearInternalPin();
        this.mAdapter.setPinLength(this.mPin.length());
        PinLockAdapter pinLockAdapter = this.mAdapter;
        pinLockAdapter.notifyItemChanged(pinLockAdapter.getItemCount() - 1);
        IndicatorDots indicatorDots = this.mIndicatorDots;
        if (indicatorDots != null) {
            indicatorDots.updateDot(this.mPin.length());
        }
    }

    public boolean isIndicatorDotsAttached() {
        return this.mIndicatorDots != null;
    }

    public void attachIndicatorDots(IndicatorDots mIndicatorDots) {
        this.mIndicatorDots = mIndicatorDots;
    }
}
