Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions pinentry/src/main/java/me/philio/pinentry/PinEntryView.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ public class PinEntryView extends ViewGroup {
*/
private boolean accentRequiresFocus;

/**
* If no mask is set, all alphabet characters will be shown upercase
*/
private boolean textUpperCase;

public PinEntryView(Context context) {
this(context, null);
}
Expand Down Expand Up @@ -171,6 +176,9 @@ public PinEntryView(Context context, AttributeSet attrs, int defStyle) {
// Accent shown, default to only when focused
accentRequiresFocus = array.getBoolean(R.styleable.PinEntryView_accentRequiresFocus, true);

// All caps default false
textUpperCase = array.getBoolean(R.styleable.PinEntryView_textUpperCase, false);

// Recycle the typed array
array.recycle();

Expand Down Expand Up @@ -383,7 +391,8 @@ public void afterTextChanged(Editable s) {
for (int i = 0; i < digits; i++) {
if (s.length() > i) {
String mask = PinEntryView.this.mask == null || PinEntryView.this.mask.length() == 0 ?
String.valueOf(s.charAt(i)) : PinEntryView.this.mask;
(PinEntryView.this.textUpperCase ? String.valueOf(s.charAt(i)).toUpperCase() : String.valueOf(s.charAt(i)))
: PinEntryView.this.mask;
((TextView) getChildAt(i)).setText(mask);
} else {
((TextView) getChildAt(i)).setText("");
Expand All @@ -403,6 +412,10 @@ public void afterTextChanged(Editable s) {
addView(editText);
}

public interface OnPinEnteredListener {
void onPinEntered(String pin);
}

/**
* Save state of the view
*/
Expand Down Expand Up @@ -478,8 +491,4 @@ protected void onDraw(Canvas canvas) {

}

public interface OnPinEnteredListener {
void onPinEntered(String pin);
}

}
2 changes: 2 additions & 0 deletions pinentry/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,7 @@
</attr>
<!-- Only draw accent when View has focus -->
<attr name="accentRequiresFocus" format="boolean" />
<!-- All uppercase when no mask set -->
<attr name="textUpperCase" format="boolean" />
</declare-styleable>
</resources>