Skip to content
This repository has been archived by the owner on Jan 12, 2019. It is now read-only.

Commit

Permalink
add numeric-only postal code extra
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff Brateman committed Jan 8, 2016
1 parent 7863a84 commit 05d5b27
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public void onScanPress(View v) {
scanIntent.putExtra(CardIOActivity.EXTRA_REQUIRE_EXPIRY, true); // default: false
scanIntent.putExtra(CardIOActivity.EXTRA_REQUIRE_CVV, false); // default: false
scanIntent.putExtra(CardIOActivity.EXTRA_REQUIRE_POSTAL_CODE, false); // default: false
scanIntent.putExtra(CardIOActivity.EXTRA_RESTRICT_POSTAL_CODE_TO_NUMERIC_ONLY, false); // default: false
scanIntent.putExtra(CardIOActivity.EXTRA_REQUIRE_CARDHOLDER_NAME, false); // default: false

// hides the manual entry button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public class CardIOSimpleExampleActivity extends Activity {
private CheckBox mScanExpiryToggle;
private CheckBox mCvvToggle;
private CheckBox mPostalCodeToggle;
private CheckBox mPostalCodeNumericOnlyToggle;
private CheckBox mCardholderNameToggle;
private CheckBox mSuppressManualToggle;
private CheckBox mSuppressConfirmationToggle;
Expand Down Expand Up @@ -97,6 +98,7 @@ public void onCreate(Bundle b) {
mScanExpiryToggle = (CheckBox) findViewById(R.id.scanExpiry);
mCvvToggle = (CheckBox) findViewById(R.id.gatherCvv);
mPostalCodeToggle = (CheckBox) findViewById(R.id.gatherPostalCode);
mPostalCodeNumericOnlyToggle = (CheckBox) findViewById(R.id.postalCodeNumericOnly);
mCardholderNameToggle = (CheckBox) findViewById(R.id.gatherCardholderName);
mSuppressManualToggle = (CheckBox) findViewById(R.id.suppressManual);
mSuppressConfirmationToggle = (CheckBox) findViewById(R.id.suppressConfirmation);
Expand Down Expand Up @@ -192,6 +194,8 @@ public void onItemSelected(AdapterView<?> parent, View content, int pos, long id
intent.putExtra(CardIOActivity.EXTRA_REQUIRE_CVV, mCvvToggle.isChecked());
intent.putExtra(CardIOActivity.EXTRA_REQUIRE_POSTAL_CODE,
mPostalCodeToggle.isChecked());
intent.putExtra(CardIOActivity.EXTRA_RESTRICT_POSTAL_CODE_TO_NUMERIC_ONLY,
mPostalCodeNumericOnlyToggle.isChecked());
intent.putExtra(CardIOActivity.EXTRA_REQUIRE_CARDHOLDER_NAME,
mCardholderNameToggle.isChecked());

Expand Down Expand Up @@ -225,6 +229,8 @@ public void onScanPressed(@SuppressWarnings("unused") View pressed) {
intent.putExtra(CardIOActivity.EXTRA_SCAN_EXPIRY, mScanExpiryToggle.isChecked());
intent.putExtra(CardIOActivity.EXTRA_REQUIRE_CVV, mCvvToggle.isChecked());
intent.putExtra(CardIOActivity.EXTRA_REQUIRE_POSTAL_CODE, mPostalCodeToggle.isChecked());
intent.putExtra(CardIOActivity.EXTRA_RESTRICT_POSTAL_CODE_TO_NUMERIC_ONLY,
mPostalCodeNumericOnlyToggle.isChecked());
intent.putExtra(CardIOActivity.EXTRA_REQUIRE_CARDHOLDER_NAME, mCardholderNameToggle.isChecked());
intent.putExtra(CardIOActivity.EXTRA_SUPPRESS_MANUAL_ENTRY,
mSuppressManualToggle.isChecked());
Expand Down
7 changes: 7 additions & 0 deletions card.io/src/androidTest/res/layout/demo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@
android:layout_height="wrap_content"
android:text="Cardholder Name"/>


<CheckBox
android:id="@+id/postalCodeNumericOnly"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Restrict Postal Code to Numeric Only"/>

<CheckBox
android:id="@+id/scanExpiry"
android:layout_width="match_parent"
Expand Down
7 changes: 7 additions & 0 deletions card.io/src/main/java/io/card/payment/CardIOActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ public final class CardIOActivity extends Activity {
*/
public static final String EXTRA_REQUIRE_POSTAL_CODE = "io.card.payment.requirePostalCode";

/**
* Boolean extra. Optional. Defaults to <code>false</code>. If set, the postal code will only collect numeric
* input. Set this if you know the <a href="https://en.wikipedia.org/wiki/Postal_code">expected country's
* postal code</a> has only numeric postal codes.
*/
public static final String EXTRA_RESTRICT_POSTAL_CODE_TO_NUMERIC_ONLY = "io.card.payment.restrictPostalCodeToNumericOnly";

/**
* Boolean extra. Optional. Defaults to <code>false</code>. If set, the user will be prompted
* for the cardholder name.
Expand Down
10 changes: 9 additions & 1 deletion card.io/src/main/java/io/card/payment/DataEntryActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -314,13 +314,21 @@ protected void onCreate(Bundle savedInstanceState) {
postalCodeLayout
.addView(zipLabel, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

boolean postalCodeNumericOnly =
getIntent().getBooleanExtra(CardIOActivity.EXTRA_RESTRICT_POSTAL_CODE_TO_NUMERIC_ONLY, false);

postalCodeEdit = new EditText(this);
postalCodeEdit.setId(editTextIdCounter++);
postalCodeEdit.setMaxLines(1);
postalCodeEdit.setImeOptions(EditorInfo.IME_ACTION_DONE);
postalCodeEdit.setTextAppearance(getApplicationContext(),
android.R.attr.textAppearanceLarge);
postalCodeEdit.setInputType(InputType.TYPE_CLASS_TEXT);
if (postalCodeNumericOnly) {
// class is phone to be consistent with other numeric fields. Perhaps this could be improved.
postalCodeEdit.setInputType(InputType.TYPE_CLASS_PHONE);
} else {
postalCodeEdit.setInputType(InputType.TYPE_CLASS_TEXT);
}
if(! useApplicationTheme ) {
postalCodeEdit.setHintTextColor(Appearance.TEXT_COLOR_EDIT_TEXT_HINT);
}
Expand Down

0 comments on commit 05d5b27

Please sign in to comment.