Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix IME action logic on CVC field in CardMultilineWidget #790

Merged
merged 1 commit into from
Jan 30, 2019
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import android.text.TextWatcher;
import android.util.AttributeSet;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.widget.LinearLayout;

import androidx.annotation.ColorInt;
Expand Down Expand Up @@ -245,24 +246,30 @@ public void setEnabled(boolean enabled) {

void adjustViewForPostalCodeAttribute() {
// Set the label/hint to the shorter value if we have three things in a row.
@StringRes int expiryLabel = mShouldShowPostalCode
@StringRes final int expiryLabel = mShouldShowPostalCode
? R.string.expiry_label_short
: R.string.acc_label_expiry_date;
mExpiryTextInputLayout.setHint(getResources().getString(expiryLabel));

@IdRes int focusForward = mShouldShowPostalCode
@IdRes final int focusForward = mShouldShowPostalCode
? R.id.et_add_source_postal_ml
: NO_ID;
mCvcEditText.setNextFocusForwardId(focusForward);
mCvcEditText.setNextFocusDownId(focusForward);

int visibility = mShouldShowPostalCode ? View.VISIBLE : View.GONE;
mPostalInputLayout.setVisibility(visibility);
final int postalCodeVisibility = mShouldShowPostalCode ? View.VISIBLE : View.GONE;
mPostalInputLayout.setVisibility(postalCodeVisibility);

int marginPixels = mShouldShowPostalCode
// If the postal code field is not shown, the CVC field is the last one in the form and the
// action on the keyboard when the CVC field is focused should be "Done". Otherwise, show
// the "Next" action.
mCvcEditText.setImeOptions(postalCodeVisibility == View.GONE ?
EditorInfo.IME_ACTION_DONE : EditorInfo.IME_ACTION_NEXT);

final int marginPixels = mShouldShowPostalCode
? getResources().getDimensionPixelSize(R.dimen.add_card_expiry_middle_margin)
: 0;
LinearLayout.LayoutParams linearParams =
final LinearLayout.LayoutParams linearParams =
(LinearLayout.LayoutParams) mCvcTextInputLayout.getLayoutParams();
linearParams.setMargins(0, 0, marginPixels, 0);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
Expand Down