Chromium Code Reviews| 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..1a6a29fa22b68958eb4b26c0192907fdacfac559 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; |
| private boolean mHasFocusedAtLeastOnce; |
| @Nullable private PaymentRequestObserverForTest mObserverForTest; |
| @@ -59,17 +62,34 @@ 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) { |
| + // Padding at the end of mInput to preserve space for mIconsLayer. |
| + ApiCompatibilityUtils.setPaddingRelative(mInput, |
| + ApiCompatibilityUtils.getPaddingStart(mInput), mInput.getPaddingTop(), |
| + mIconsLayer.getWidth(), mInput.getPaddingBottom()); |
|
gone
2016/10/26 17:22:52
getMeasuredWidth()? I don't know if this call hap
gogerald1
2016/10/27 19:01:35
It happens after layout from the source code, 'pub
|
| + } |
| + }); |
| + |
| + 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)); |
| mActionIcon.setContentDescription(context.getResources().getString( |
| - fieldModel.getActionDescriptionForAccessibility())); |
| + fieldModel.getActionIconDescriptionForAccessibility())); |
| mActionIcon.setOnClickListener(this); |
| mActionIcon.setVisibility(VISIBLE); |
| } |
| + if (fieldModel.getValueIconGenerator() != null) { |
| + mValueIcon = (ImageView) mIconsLayer.findViewById(R.id.value_icon); |
| + mValueIcon.setVisibility(VISIBLE); |
| + } |
| + |
| // Validate the field when the user de-focuses it. |
| mInput.setOnFocusChangeListener(new OnFocusChangeListener() { |
| @Override |
| @@ -89,6 +109,7 @@ public class EditorTextField extends FrameLayout implements EditorFieldView, Vie |
| public void afterTextChanged(Editable s) { |
| fieldModel.setValue(s.toString()); |
| updateDisplayedError(false); |
| + if (mValueIcon != null) updateFieldValueIcon(false); |
| if (mObserverForTest != null) { |
| mObserverForTest.onPaymentRequestEditorTextUpdate(); |
| } |
| @@ -165,43 +186,34 @@ 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 onWindowFocusChanged(boolean hasWindowFocus) { |
| + super.onWindowFocusChanged(hasWindowFocus); |
| + |
| + if (hasWindowFocus && mValueIcon != null) updateFieldValueIcon(true); |
| + } |
| + |
| + @Override |
| public void onClick(View v) { |
| - mEditorFieldModel.getIconAction().run(); |
| + mEditorFieldModel.getActionIconAction().run(); |
| } |
| /** @return The EditorFieldModel that the TextView represents. */ |
| @@ -236,4 +248,16 @@ public class EditorTextField extends FrameLayout implements EditorFieldView, Vie |
| public void update() { |
| mInput.setText(mEditorFieldModel.getValue()); |
| } |
| + |
| + private void updateFieldValueIcon(boolean force) { |
| + int iconId = mEditorFieldModel.getValueIconGenerator().getIconResourceId(mInput.getText()); |
|
gone
2016/10/26 17:22:52
Can't getValueIconGenerator return null, in genera
gogerald1
2016/10/27 19:01:35
Done. moved if(mValueIcon == null) in this functio
|
| + if (mValueIconId == iconId && !force) return; |
| + mValueIconId = iconId; |
| + if (mValueIconId == 0) { |
| + mValueIcon.setVisibility(GONE); |
| + } else { |
| + mValueIcon.setImageResource(mValueIconId); |
| + mValueIcon.setVisibility(VISIBLE); |
| + } |
| + } |
| } |