Index: chrome/android/java/src/org/chromium/chrome/browser/payments/ui/EditorTextField.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/payments/ui/EditorTextField.java b/chrome/android/java/src/org/chromium/chrome/browser/payments/ui/EditorTextField.java |
index a3dab17cacb105e5db0365bda40a37e82d82599b..8d4fea4a2434c517b3c140e43ad8c7922fbd2755 100644 |
--- a/chrome/android/java/src/org/chromium/chrome/browser/payments/ui/EditorTextField.java |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/payments/ui/EditorTextField.java |
@@ -34,7 +34,10 @@ public class EditorTextField extends FrameLayout implements EditorFieldView, Vie |
private EditorFieldModel mEditorFieldModel; |
private CompatibilityTextInputLayout mInputLayout; |
private AutoCompleteTextView mInput; |
+ private View mIconsLayer; |
private ImageView mActionIcon; |
+ private ImageView mValueIcon; |
+ private int mValueIconId = 0; |
please use gerrit instead
2016/10/25 17:48:18
0 is the default value for Java ints, so there's n
gogerald1
2016/10/26 15:22:16
Done.
|
private boolean mHasFocusedAtLeastOnce; |
@Nullable private PaymentRequestObserverForTest mObserverForTest; |
@@ -59,8 +62,21 @@ public class EditorTextField extends FrameLayout implements EditorFieldView, Vie |
mInput.setContentDescription(label); |
mInput.setOnEditorActionListener(actionlistener); |
- if (fieldModel.getIconAction() != null) { |
- mActionIcon = (ImageView) findViewById(R.id.action_icon); |
+ mIconsLayer = findViewById(R.id.icons_layer); |
+ mIconsLayer.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { |
+ @Override |
+ public void onLayoutChange(View v, int left, int top, int right, int bottom, |
+ int oldLeft, int oldTop, int oldRight, int oldBottom) { |
+ if (ApiCompatibilityUtils.getPaddingEnd(mInput) >= mIconsLayer.getWidth()) return; |
+ // Padding at the end of mInput to preserve space for mIconsLayer. |
+ ApiCompatibilityUtils.setPaddingRelative(mInput, |
+ ApiCompatibilityUtils.getPaddingStart(mInput), mInput.getPaddingTop(), |
+ mIconsLayer.getWidth(), mInput.getPaddingBottom()); |
+ } |
+ }); |
+ |
+ if (fieldModel.getActionIconAction() != null) { |
+ mActionIcon = (ImageView) mIconsLayer.findViewById(R.id.action_icon); |
mActionIcon.setImageDrawable( |
TintedDrawable.constructTintedDrawable(context.getResources(), |
fieldModel.getActionIconResourceId(), R.color.light_active_color)); |
@@ -70,6 +86,9 @@ public class EditorTextField extends FrameLayout implements EditorFieldView, Vie |
mActionIcon.setVisibility(VISIBLE); |
} |
+ mValueIcon = (ImageView) mIconsLayer.findViewById(R.id.value_icon); |
+ updateFieldValueIcon(); |
+ |
// Validate the field when the user de-focuses it. |
mInput.setOnFocusChangeListener(new OnFocusChangeListener() { |
@Override |
@@ -89,6 +108,7 @@ public class EditorTextField extends FrameLayout implements EditorFieldView, Vie |
public void afterTextChanged(Editable s) { |
fieldModel.setValue(s.toString()); |
updateDisplayedError(false); |
+ updateFieldValueIcon(); |
if (mObserverForTest != null) { |
mObserverForTest.onPaymentRequestEditorTextUpdate(); |
} |
@@ -165,43 +185,27 @@ public class EditorTextField extends FrameLayout implements EditorFieldView, Vie |
} |
@Override |
- public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
- if (mActionIcon != null) { |
- if (mActionIcon.getMeasuredWidth() == 0) { |
- mActionIcon.measure(widthMeasureSpec, heightMeasureSpec); |
- } |
- |
- // Padding at the end of mInput to preserve space for mActionIcon. |
- ApiCompatibilityUtils.setPaddingRelative(mInput, |
- ApiCompatibilityUtils.getPaddingStart(mInput), mInput.getPaddingTop(), |
- mActionIcon.getWidth(), mInput.getPaddingBottom()); |
- } |
- |
- super.onMeasure(widthMeasureSpec, heightMeasureSpec); |
- } |
- |
- @Override |
public void onLayout(boolean changed, int left, int top, int right, int bottom) { |
super.onLayout(changed, left, top, right, bottom); |
- if (changed && mActionIcon != null) { |
- // Align the bottom of mActionIcon to the bottom of mInput (mActionIcon overlaps |
+ if (changed) { |
+ // Align the bottom of mIconsLayer to the bottom of mInput (mIconsLayer overlaps |
// mInput). |
- // Note one: mActionIcon can not be put inside mInputLayout to display on top of |
+ // Note one: mIconsLayer can not be put inside mInputLayout to display on top of |
// mInput since mInputLayout is LinearLayout in essential. |
- // Note two: mActionIcon and mInput can not be put in ViewGroup to display over each |
+ // Note two: mIconsLayer and mInput can not be put in ViewGroup to display over each |
// other inside mInputLayout since mInputLayout must contain an instance of EditText |
// child view. |
// Note three: mInputLayout's bottom changes when displaying error. |
float offset = mInputLayout.getY() + mInput.getY() + (float) mInput.getHeight() |
- - (float) mActionIcon.getHeight() - mActionIcon.getTop(); |
- mActionIcon.setTranslationY(offset); |
+ - (float) mIconsLayer.getHeight() - mIconsLayer.getTop(); |
+ mIconsLayer.setTranslationY(offset); |
} |
} |
@Override |
public void onClick(View v) { |
- mEditorFieldModel.getIconAction().run(); |
+ mEditorFieldModel.getActionIconAction().run(); |
} |
/** @return The EditorFieldModel that the TextView represents. */ |
@@ -236,4 +240,16 @@ public class EditorTextField extends FrameLayout implements EditorFieldView, Vie |
public void update() { |
mInput.setText(mEditorFieldModel.getValue()); |
} |
+ |
+ private void updateFieldValueIcon() { |
+ int iconId = mEditorFieldModel.getValueIconResourceId(); |
+ if (mValueIconId == iconId) return; |
+ mValueIconId = iconId; |
+ if (mValueIconId == 0) { |
+ mValueIcon.setVisibility(GONE); |
+ } else { |
+ mValueIcon.setImageResource(mValueIconId); |
+ mValueIcon.setVisibility(VISIBLE); |
+ } |
+ } |
} |