From d55afc14d700832a675dee555b0b14385336f29d Mon Sep 17 00:00:00 2001 From: "kewl.apps.dev1" Date: Sun, 1 Sep 2019 13:22:31 +0500 Subject: [PATCH] all ok --- .../pinview/example/MainActivity.java | 16 ++++-- app/src/main/res/layout/activity_main.xml | 3 +- .../java/com/gamemalt/pinview/PinView.java | 52 ++++++++++++++++--- .../com/gamemalt/pinview/PinViewListener.java | 13 +++-- pinview/src/main/res/drawable/v_tick.xml | 9 ++++ pinview/src/main/res/layout/pin_view.xml | 11 +++- pinview/src/main/res/values/attrs.xml | 3 ++ pinview/src/main/res/values/public.xml | 3 +- 8 files changed, 90 insertions(+), 20 deletions(-) create mode 100644 pinview/src/main/res/drawable/v_tick.xml diff --git a/app/src/main/java/com/gamemalt/pinview/example/MainActivity.java b/app/src/main/java/com/gamemalt/pinview/example/MainActivity.java index 9471006..e238389 100644 --- a/app/src/main/java/com/gamemalt/pinview/example/MainActivity.java +++ b/app/src/main/java/com/gamemalt/pinview/example/MainActivity.java @@ -16,26 +16,32 @@ protected void onCreate(Bundle savedInstanceState) { setContentView(R.layout.activity_main); - PinView pinView=findViewById(R.id.pin_view); + PinView pinView = findViewById(R.id.pin_view); pinView.setListener(new PinViewListener() { @Override public void onPinButtonClick(int num) { - Log.d("yoyo",""+num); + Log.d("pinviewtest", "" + num); } @Override public void onClearButtonClick() { - Log.d("yoyo","onClearButtonClick"); + Log.d("pinviewtest", "onClearButtonClick"); } @Override public void onClearButtonLongClick() { - Log.d("yoyo","onClearButtonLongClick"); + Log.d("pinviewtest", "onClearButtonLongClick"); + + } + + @Override + public void onOkButtonClick() { + Log.d("pinviewtest", "onOkButtonClick"); } }); - + } } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 3aabadb..ed395ff 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -15,7 +15,8 @@ android:layout_gravity="center_horizontal" app:buttonTextColor="#FFEB3B" app:buttonTextSize="30" - app:isHapticFeedBack="false" + app:isHapticFeedBack="true" + app:buttonOkBackground="@drawable/v_tick" app:buttonClearBackground="@drawable/v_back" /> diff --git a/pinview/src/main/java/com/gamemalt/pinview/PinView.java b/pinview/src/main/java/com/gamemalt/pinview/PinView.java index 98e40a6..ca0ab4b 100644 --- a/pinview/src/main/java/com/gamemalt/pinview/PinView.java +++ b/pinview/src/main/java/com/gamemalt/pinview/PinView.java @@ -22,12 +22,16 @@ public class PinView extends LinearLayout { private int pinButtonBackground; - private int imageClearBackground; + private int buttonClearBackground; + private int buttonOkBackground; private int buttonTextColor; private int buttonTextSize; private ImageButton buttonClear; + private ImageButton buttonOk; + + private boolean showOkButton, showClearButton; private boolean isHapticFeedBack = false; @@ -58,11 +62,15 @@ public PinView(Context context, AttributeSet attrs, int defStyle) { private void setDefaultAttr(AttributeSet attrs) { TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.PinView); try { - imageClearBackground = typedArray.getResourceId(R.styleable.PinView_buttonClearBackground, R.drawable.v_back); + buttonClearBackground = typedArray.getResourceId(R.styleable.PinView_buttonClearBackground, R.drawable.v_back); + buttonOkBackground = typedArray.getResourceId(R.styleable.PinView_buttonOkBackground, R.drawable.v_tick); pinButtonBackground = typedArray.getResourceId(R.styleable.PinView_pinButtonBackground, android.R.color.transparent); buttonTextColor = typedArray.getColor(R.styleable.PinView_buttonTextColor, Color.WHITE); buttonTextSize = typedArray.getInt(R.styleable.PinView_buttonTextSize, 24); isHapticFeedBack = typedArray.getBoolean(R.styleable.PinView_isHapticFeedBack, false); + showOkButton = typedArray.getBoolean(R.styleable.PinView_showOkButton, true); + showClearButton = typedArray.getBoolean(R.styleable.PinView_showClearButton, true); + } finally { typedArray.recycle(); @@ -100,14 +108,21 @@ public boolean onLongClick(View v) { }); buttonClear.setOnClickListener(clickListener); + buttonOk.setOnClickListener(clickListener); + + setShowClearButton(showClearButton); + setShowOkButton(showOkButton); } private void findAllViews() { - buttonClear = findViewById(R.id.clear); - setImageClearBackground(imageClearBackground); + buttonClear = findViewById(R.id.button_clear); + buttonOk = findViewById(R.id.button_ok); + + setButtonClearBackground(buttonClearBackground); + setButtonOkBackground(buttonOkBackground); pinButtons[0] = findViewById(R.id.button_0); pinButtons[1] = findViewById(R.id.button_1); @@ -152,16 +167,20 @@ public void onClick(View v) { if (pinViewListener == null || !isEnabled) return; - if (v.getId() == R.id.clear) { + if (v.getId() == R.id.button_clear) { pinViewListener.onClearButtonClick(); + } else if (v.getId() == R.id.button_ok) { + + pinViewListener.onOkButtonClick(); } else { pinViewListener.onPinButtonClick(Integer.parseInt(((TextView) v).getText().toString().trim())); } - if (isHapticFeedBackEnabled()) { + if (isHapticFeedBackEnabled() && v.getId() != R.id.button_ok) { + //we don't vibrate on OK button vibrate(); } @@ -188,6 +207,7 @@ public void setPinButtonTextColor(int pinButtonTextColor) { // ColorStateList ColorStateList = getResources().getColorStateList(pinButtonTextColor); buttonClear.setColorFilter(pinButtonTextColor, PorterDuff.Mode.SRC_IN); + buttonOk.setColorFilter(pinButtonTextColor, PorterDuff.Mode.SRC_IN); for (TextView button : pinButtons) { button.setTextColor(pinButtonTextColor); @@ -207,11 +227,19 @@ public void setPinButtonTextSize(int pinButtonTextSize) { /* * Provide resource ID * */ - public void setImageClearBackground(int imageClearBackground) { - this.imageClearBackground = imageClearBackground; + public void setButtonClearBackground(int imageClearBackground) { + this.buttonClearBackground = imageClearBackground; buttonClear.setImageResource(imageClearBackground); } + /* + * Provide resource ID + * */ + public void setButtonOkBackground(int imageClearBackground) { + this.buttonOkBackground = imageClearBackground; + buttonOk.setImageResource(imageClearBackground); + } + public boolean isHapticFeedBackEnabled() { return isHapticFeedBack; } @@ -224,5 +252,13 @@ public void setPinViewEnabled(boolean isEnabled) { this.isEnabled = isEnabled; } + public void setShowOkButton(boolean shouldShow){ + showOkButton=shouldShow; + buttonOk.setVisibility(shouldShow ? VISIBLE : INVISIBLE); + } + public void setShowClearButton(boolean shouldShow){ + showClearButton=shouldShow; + buttonClear.setVisibility(shouldShow ? VISIBLE : INVISIBLE); + } } diff --git a/pinview/src/main/java/com/gamemalt/pinview/PinViewListener.java b/pinview/src/main/java/com/gamemalt/pinview/PinViewListener.java index a8c8219..d34cebc 100644 --- a/pinview/src/main/java/com/gamemalt/pinview/PinViewListener.java +++ b/pinview/src/main/java/com/gamemalt/pinview/PinViewListener.java @@ -1,11 +1,16 @@ package com.gamemalt.pinview; -public interface PinViewListener { +public abstract class PinViewListener { - void onPinButtonClick(int num); + public abstract void onPinButtonClick(int num); - void onClearButtonClick(); + public void onClearButtonClick() { + } - void onClearButtonLongClick(); + public void onClearButtonLongClick() { + } + + public void onOkButtonClick() { + } } diff --git a/pinview/src/main/res/drawable/v_tick.xml b/pinview/src/main/res/drawable/v_tick.xml new file mode 100644 index 0000000..3c728c5 --- /dev/null +++ b/pinview/src/main/res/drawable/v_tick.xml @@ -0,0 +1,9 @@ + + + diff --git a/pinview/src/main/res/layout/pin_view.xml b/pinview/src/main/res/layout/pin_view.xml index d1091b8..d31c51d 100644 --- a/pinview/src/main/res/layout/pin_view.xml +++ b/pinview/src/main/res/layout/pin_view.xml @@ -145,6 +145,15 @@ android:orientation="horizontal" android:weightSum="3"> + + + + diff --git a/pinview/src/main/res/values/public.xml b/pinview/src/main/res/values/public.xml index bd364cb..b630cb3 100644 --- a/pinview/src/main/res/values/public.xml +++ b/pinview/src/main/res/values/public.xml @@ -3,6 +3,7 @@ - + + \ No newline at end of file