Skip to content

Commit

Permalink
all ok
Browse files Browse the repository at this point in the history
  • Loading branch information
kewl.apps.dev1 committed Sep 1, 2019
1 parent 4bd6660 commit d55afc1
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 20 deletions.
16 changes: 11 additions & 5 deletions app/src/main/java/com/gamemalt/pinview/example/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");

}
});

}
}
3 changes: 2 additions & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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" />


Expand Down
52 changes: 44 additions & 8 deletions pinview/src/main/java/com/gamemalt/pinview/PinView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
}

Expand All @@ -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);
Expand All @@ -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;
}
Expand All @@ -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);
}

}
13 changes: 9 additions & 4 deletions pinview/src/main/java/com/gamemalt/pinview/PinViewListener.java
Original file line number Diff line number Diff line change
@@ -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() {
}

}
9 changes: 9 additions & 0 deletions pinview/src/main/res/drawable/v_tick.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M9,16.17L4.83,12l-1.42,1.41L9,19 21,7l-1.41,-1.41z"/>
</vector>
11 changes: 10 additions & 1 deletion pinview/src/main/res/layout/pin_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,15 @@
android:orientation="horizontal"
android:weightSum="3">

<ImageButton
android:id="@+id/button_ok"
style="@style/PinPadButton"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:src="@drawable/v_tick"
android:theme="@style/PinPadButton" />

<TextView
android:id="@+id/button_0"
Expand All @@ -157,7 +166,7 @@
android:theme="@style/PinPadButton" />

<ImageButton
android:id="@+id/clear"
android:id="@+id/button_clear"
style="@style/PinPadButton"
android:layout_width="0dp"
android:layout_height="match_parent"
Expand Down
3 changes: 3 additions & 0 deletions pinview/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
<declare-styleable name="PinView">
<attr name="pinButtonBackground" format="reference"/>
<attr name="buttonClearBackground" format="reference" />
<attr name="buttonOkBackground" format="reference" />
<attr name="buttonTextColor" format="color" />
<attr name="buttonTextSize" format="integer" />
<attr name="isHapticFeedBack" format="boolean" />
<attr name="showOkButton" format="boolean" />
<attr name="showClearButton" format="boolean" />

</declare-styleable>

Expand Down
3 changes: 2 additions & 1 deletion pinview/src/main/res/values/public.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

<public/>

<!--<public name="pin_pad_button_ripple_color" type="color"/>-->
<public name="v_back" type="drawable"/>
<public name="v_tick" type="drawable"/>

</resources>

0 comments on commit d55afc1

Please sign in to comment.