Skip to content

Commit

Permalink
pinView also returns password
Browse files Browse the repository at this point in the history
  • Loading branch information
kewl.apps.dev1 committed Nov 23, 2019
1 parent ac16acc commit 83a49e4
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 10 deletions.
49 changes: 42 additions & 7 deletions pinview/src/main/java/com/gamemalt/pinview/PinView.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public class PinView extends LinearLayout {
boolean isEnabled = true;
private OnConfigurationChangedListener onConfigurationChangedListener;

private String passWord = "";


public PinView(Context context) {
super(context);
Expand Down Expand Up @@ -110,15 +112,19 @@ private void initView() {
@Override
public boolean onLongClick(View v) {

if (pinViewListener == null || !isEnabled)
return true;

pinViewListener.onClearButtonLongClick();
if (!isEnabled)
return true;

resetPassword();
if (isHapticFeedBackEnabled()) {
vibrate();
}

if (pinViewListener != null)
pinViewListener.onClearButtonLongClick();


return true;

}
Expand Down Expand Up @@ -180,18 +186,28 @@ public void shufflePinPad(boolean shouldShuffle) {
@Override
public void onClick(View v) {

if (pinViewListener == null || !isEnabled)
if (!isEnabled)
return;

if (v.getId() == R.id.button_clear) {

pinViewListener.onClearButtonClick();
passWord = removeLast(passWord);

if (pinViewListener != null)
pinViewListener.onClearButtonClick(passWord);

} else if (v.getId() == R.id.button_ok) {

pinViewListener.onOkButtonClick();
if (pinViewListener != null)
pinViewListener.onOkButtonClick(passWord);
} else {
pinViewListener.onPinButtonClick(Integer.parseInt(((TextView) v).getText().toString().trim()));

int num = Integer.parseInt(((TextView) v).getText().toString().trim());

passWord += String.valueOf(num);

if (pinViewListener != null)
pinViewListener.onPinButtonClick(num, passWord);

}

Expand Down Expand Up @@ -327,4 +343,23 @@ public void setOnConfigurationChangedListener(OnConfigurationChangedListener onC
public interface OnConfigurationChangedListener {
void onConfigurationChanged(Configuration newConfig);
}

public void resetPassword() {
passWord = "";
}

public String getPassword() {
return passWord;
}


/*
* Removes the last character of the string and return the new string
* */
public static String removeLast(String str) {
if (str != null && str.length() > 0) {
str = str.substring(0, str.length() - 1);
}
return str;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

public abstract class PinViewListener {

public abstract void onPinButtonClick(int num);
public abstract void onPinButtonClick(int num,String currentPassword);

public void onClearButtonClick() {
public void onClearButtonClick(String currentPassword) {
}

public void onClearButtonLongClick() {
}

public void onOkButtonClick() {
public void onOkButtonClick(String currentPassword) {
}

}

0 comments on commit 83a49e4

Please sign in to comment.