From 54ad8281e17dfa4f7e85c791205fd1d4f90e33b0 Mon Sep 17 00:00:00 2001 From: Michael McDuffee Date: Thu, 21 Sep 2017 12:54:09 -0700 Subject: [PATCH] fixing npe --- .../com/stripe/android/view/CardInputWidget.java | 16 ++++++++++++++-- .../com/stripe/android/view/StripeEditText.java | 4 ++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/stripe/src/main/java/com/stripe/android/view/CardInputWidget.java b/stripe/src/main/java/com/stripe/android/view/CardInputWidget.java index e6f278a756c..815fc061f19 100644 --- a/stripe/src/main/java/com/stripe/android/view/CardInputWidget.java +++ b/stripe/src/main/java/com/stripe/android/view/CardInputWidget.java @@ -32,8 +32,6 @@ import java.util.Locale; import static com.stripe.android.model.Card.BRAND_RESOURCE_MAP; -import static com.stripe.android.model.Card.CVC_LENGTH_AMERICAN_EXPRESS; -import static com.stripe.android.model.Card.CVC_LENGTH_COMMON; import static com.stripe.android.model.Card.CardBrand; import static com.stripe.android.view.CardInputListener.FocusField.FOCUS_CARD; import static com.stripe.android.view.CardInputListener.FocusField.FOCUS_CVC; @@ -204,6 +202,20 @@ public void setEnabled(boolean isEnabled) { mCvcNumberEditText.setEnabled(isEnabled); } + /** + * Override of {@link View#isEnabled()} that returns {@code true} only + * if all three sub-controls are enabled. + * + * @return {@code true} if the card number field, expiry field, and cvc field are enabled, + * {@code false} otherwise + */ + @Override + public boolean isEnabled() { + return mCardNumberEditText.isEnabled() && + mExpiryDateEditText.isEnabled() && + mCvcNumberEditText.isEnabled(); + } + @Override public boolean onInterceptTouchEvent(MotionEvent ev) { if (ev.getAction() != MotionEvent.ACTION_DOWN) { diff --git a/stripe/src/main/java/com/stripe/android/view/StripeEditText.java b/stripe/src/main/java/com/stripe/android/view/StripeEditText.java index eca2417202b..1b9e85c64b3 100644 --- a/stripe/src/main/java/com/stripe/android/view/StripeEditText.java +++ b/stripe/src/main/java/com/stripe/android/view/StripeEditText.java @@ -96,6 +96,10 @@ public int getDefaultErrorColorInt() { @Override public InputConnection onCreateInputConnection(EditorInfo outAttrs) { + InputConnection inputConnection = super.onCreateInputConnection(outAttrs); + if (inputConnection == null) { + return null; + } return new SoftDeleteInputConnection(super.onCreateInputConnection(outAttrs), true); }