package com.ce.game.myapplication.view.pincode;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.widget.RelativeLayout;

import com.blablaapp.launcher.R;
import com.blablaapp.launcher.ui.screenlock.inter.LockViewInterface;
import com.blablaapp.launcher.ui.screenlock.view.KeyboardButtonView.KeyType;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by KyleCe on 2016/5/25.
 *
 * @author: KyleCe
 */
public class KeyboardView extends RelativeLayout implements View.OnClickListener {

    private Context mContext;
    private KeyboardButtonClickedListener mKeyboardButtonClickedListener;

    private List<KeyboardButtonView> mButtons;

    private LockViewInterface.Clickable mClickableController;

    private static final int TOTAL_BUTTON_NUM = 12;

    protected KeyboardView mKeyboardView;

    public KeyboardView(Context context) {
        this(context, null);
    }

    public KeyboardView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public KeyboardView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);

        this.mContext = context;
        initializeView();
    }

    private void initializeView() {
        if (!isInEditMode()) {
            LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            mKeyboardView = (KeyboardView) inflater.inflate(R.layout.password_view_keyboard, this);

            initKeyboardButtons(mKeyboardView);
        }
    }

    public void assignClickableController(LockViewInterface.Clickable clickable) {
        mClickableController = clickable;
    }

    public void hideBackButton(){
         mKeyboardView.findViewById(R.id.pin_code_button_10).setVisibility(INVISIBLE);
    }

    /**
     * Init the keyboard buttons (onClickListener)
     */
    private void initKeyboardButtons(KeyboardView view) {
        mButtons = new ArrayList<>(TOTAL_BUTTON_NUM);
        mButtons.add((KeyboardButtonView) view.findViewById(R.id.pin_code_button_0));
        mButtons.add((KeyboardButtonView) view.findViewById(R.id.pin_code_button_1));
        mButtons.add((KeyboardButtonView) view.findViewById(R.id.pin_code_button_2));
        mButtons.add((KeyboardButtonView) view.findViewById(R.id.pin_code_button_3));
        mButtons.add((KeyboardButtonView) view.findViewById(R.id.pin_code_button_4));
        mButtons.add((KeyboardButtonView) view.findViewById(R.id.pin_code_button_5));
        mButtons.add((KeyboardButtonView) view.findViewById(R.id.pin_code_button_6));
        mButtons.add((KeyboardButtonView) view.findViewById(R.id.pin_code_button_7));
        mButtons.add((KeyboardButtonView) view.findViewById(R.id.pin_code_button_8));
        mButtons.add((KeyboardButtonView) view.findViewById(R.id.pin_code_button_9));
        mButtons.add((KeyboardButtonView) view.findViewById(R.id.pin_code_button_10));
        mButtons.add((KeyboardButtonView) view.findViewById(R.id.pin_code_button_clear));

        for (View button : mButtons) button.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        if (mKeyboardButtonClickedListener == null) return;

        switch (v.getId()) {
            case R.id.pin_code_button_0:
                mKeyboardButtonClickedListener.onKeyboardClick(KeyType.K0);
                break;
            case R.id.pin_code_button_1:
                mKeyboardButtonClickedListener.onKeyboardClick(KeyType.K1);
                break;
            case R.id.pin_code_button_2:
                mKeyboardButtonClickedListener.onKeyboardClick(KeyType.K2);
                break;
            case R.id.pin_code_button_3:
                mKeyboardButtonClickedListener.onKeyboardClick(KeyType.K3);
                break;
            case R.id.pin_code_button_4:
                mKeyboardButtonClickedListener.onKeyboardClick(KeyType.K4);
                break;
            case R.id.pin_code_button_5:
                mKeyboardButtonClickedListener.onKeyboardClick(KeyType.K5);
                break;
            case R.id.pin_code_button_6:
                mKeyboardButtonClickedListener.onKeyboardClick(KeyType.K6);
                break;
            case R.id.pin_code_button_7:
                mKeyboardButtonClickedListener.onKeyboardClick(KeyType.K7);
                break;
            case R.id.pin_code_button_8:
                mKeyboardButtonClickedListener.onKeyboardClick(KeyType.K8);
                break;
            case R.id.pin_code_button_9:
                mKeyboardButtonClickedListener.onKeyboardClick(KeyType.K9);
                break;
            case R.id.pin_code_button_clear:
                mKeyboardButtonClickedListener.onKeyboardClick(KeyType.K_BACKSPACE);
                break;
            case R.id.pin_code_button_10:// back
                mKeyboardButtonClickedListener.onKeyboardClick(KeyType.K_BACK);
                break;
            default:
                break;
        }
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        if (isViewUnClickable()) return true;

        return super.dispatchTouchEvent(ev);
    }

    private boolean isViewUnClickable() {
        return mClickableController != null && !mClickableController.clickable();
    }

    public void setKeyboardButtonClickedListener(KeyboardButtonClickedListener keyboardButtonClickedListener) {
        this.mKeyboardButtonClickedListener = keyboardButtonClickedListener;
        for (KeyboardButtonView button : mButtons)
            button.setOnRippleAnimationEndListener(mKeyboardButtonClickedListener);
    }

}

@@ -257,174 +257,31 @@
 com.
-blablaapp.launcher.R;%0Aimport com.blablaapp.launcher.ui.screenlock.inter.LockViewInterface;%0Aimport com.blablaapp.launcher.ui.screenlock.view.KeyboardButtonView.KeyType
+ce.game.myapplication.R
 ;%0A%0Ai
@@ -3303,32 +3303,51 @@
 onKeyboardClick(
+KeyboardButtonView.
 KeyType.K0);%0A   
@@ -3462,32 +3462,51 @@
 onKeyboardClick(
+KeyboardButtonView.
 KeyType.K1);%0A   
@@ -3621,32 +3621,51 @@
 onKeyboardClick(
+KeyboardButtonView.
 KeyType.K2);%0A   
@@ -3780,32 +3780,51 @@
 onKeyboardClick(
+KeyboardButtonView.
 KeyType.K3);%0A   
@@ -3939,32 +3939,51 @@
 onKeyboardClick(
+KeyboardButtonView.
 KeyType.K4);%0A   
@@ -4098,32 +4098,51 @@
 onKeyboardClick(
+KeyboardButtonView.
 KeyType.K5);%0A   
@@ -4257,32 +4257,51 @@
 onKeyboardClick(
+KeyboardButtonView.
 KeyType.K6);%0A   
@@ -4416,32 +4416,51 @@
 onKeyboardClick(
+KeyboardButtonView.
 KeyType.K7);%0A   
@@ -4575,32 +4575,51 @@
 onKeyboardClick(
+KeyboardButtonView.
 KeyType.K8);%0A   
@@ -4734,32 +4734,51 @@
 onKeyboardClick(
+KeyboardButtonView.
 KeyType.K9);%0A   
@@ -4897,32 +4897,51 @@
 onKeyboardClick(
+KeyboardButtonView.
 KeyType.K_BACKSP
@@ -5081,16 +5081,35 @@
 rdClick(
+KeyboardButtonView.
 KeyType.

add pin code classes