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 298022642803544e4add2c6b38de3cc0bf423753..d38e4551d61d6c7ec57eebfa3f840e2e12304960 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 |
@@ -5,6 +5,8 @@ |
package org.chromium.chrome.browser.payments.ui; |
import android.content.Context; |
+import android.graphics.PorterDuff; |
+import android.graphics.drawable.Drawable; |
import android.text.Editable; |
import android.text.InputFilter; |
import android.text.InputType; |
@@ -15,6 +17,8 @@ import android.view.ViewGroup; |
import android.view.accessibility.AccessibilityEvent; |
import android.widget.ArrayAdapter; |
import android.widget.AutoCompleteTextView; |
+import android.widget.FrameLayout; |
+import android.widget.ImageView; |
import android.widget.TextView.OnEditorActionListener; |
import org.chromium.base.ApiCompatibilityUtils; |
@@ -27,10 +31,11 @@ import javax.annotation.Nullable; |
/** Handles validation and display of one field from the {@link EditorFieldModel}. */ |
@VisibleForTesting |
-public class EditorTextField extends CompatibilityTextInputLayout |
- implements EditorFieldView, View.OnClickListener { |
+public class EditorTextField extends FrameLayout implements EditorFieldView, View.OnClickListener { |
private EditorFieldModel mEditorFieldModel; |
+ private CompatibilityTextInputLayout mInputLayout; |
private AutoCompleteTextView mInput; |
+ private ImageView mActionIcon; |
private boolean mHasFocusedAtLeastOnce; |
@Nullable private PaymentRequestObserverForTest mObserverForTest; |
@@ -42,22 +47,31 @@ public class EditorTextField extends CompatibilityTextInputLayout |
mEditorFieldModel = fieldModel; |
mObserverForTest = observer; |
+ LayoutInflater.from(context).inflate(R.layout.payments_request_editor_textview, this, true); |
+ mInputLayout = (CompatibilityTextInputLayout) findViewById(R.id.text_input_layout); |
+ |
// Build up the label. Required fields are indicated by appending a '*'. |
CharSequence label = fieldModel.getLabel(); |
if (fieldModel.isRequired()) label = label + EditorView.REQUIRED_FIELD_INDICATOR; |
- setHint(label); |
+ mInputLayout.setHint(label); |
- // The EditText becomes a child of this class. The TextInputLayout manages how it looks. |
- LayoutInflater.from(context).inflate(R.layout.payments_request_editor_textview, this, true); |
- mInput = (AutoCompleteTextView) findViewById(R.id.text_view); |
+ mInput = (AutoCompleteTextView) mInputLayout.findViewById(R.id.text_view); |
mInput.setText(fieldModel.getValue()); |
mInput.setContentDescription(label); |
mInput.setOnEditorActionListener(actionlistener); |
if (fieldModel.getIconAction() != null) { |
- ApiCompatibilityUtils.setCompoundDrawablesRelativeWithIntrinsicBounds( |
- mInput, 0, 0, fieldModel.getActionIconResourceId(), 0); |
- mInput.setOnClickListener(this); |
+ Drawable icon = ApiCompatibilityUtils.getDrawable( |
+ context.getResources(), fieldModel.getActionIconResourceId()); |
+ icon.setColorFilter(ApiCompatibilityUtils.getColor( |
+ getContext().getResources(), R.color.light_active_color), |
+ PorterDuff.Mode.SRC_IN); |
+ mActionIcon = (ImageView) findViewById(R.id.action_icon); |
+ mActionIcon.setImageDrawable(icon); |
+ mActionIcon.setContentDescription(context.getResources().getString( |
+ fieldModel.getActionDescriptionForAccessibility())); |
+ mActionIcon.setOnClickListener(this); |
+ mActionIcon.setVisibility(VISIBLE); |
} |
// Validate the field when the user de-focuses it. |
@@ -152,6 +166,25 @@ public class EditorTextField extends CompatibilityTextInputLayout |
} |
@Override |
+ public void onWindowFocusChanged(boolean hasWindowFocus) { |
+ super.onWindowFocusChanged(hasWindowFocus); |
+ |
+ if (hasWindowFocus && mActionIcon != null) { |
+ // Align the bottom of mActionIcon to the bottom of mInput (mActionIcon overlaps |
+ // mInput). |
+ // Note one: mActionIcon 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 |
+ // 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); |
+ } |
+ } |
+ |
+ @Override |
public void onClick(View v) { |
mEditorFieldModel.getIconAction().run(); |
} |
@@ -161,7 +194,6 @@ public class EditorTextField extends CompatibilityTextInputLayout |
return mEditorFieldModel; |
} |
- @Override |
public AutoCompleteTextView getEditText() { |
return mInput; |
} |
@@ -173,7 +205,7 @@ public class EditorTextField extends CompatibilityTextInputLayout |
@Override |
public void updateDisplayedError(boolean showError) { |
- setError(showError ? mEditorFieldModel.getErrorMessage() : null); |
+ mInputLayout.setError(showError ? mEditorFieldModel.getErrorMessage() : null); |
} |
@Override |