Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1104)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/payments/ui/EditorTextField.java

Issue 2434383002: [Payments] Float card scanner icon at the end of EditText instead of compound drawable (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..ff3f206c44e3911c3b600bcfb2a0f30cfa04c9bd 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
@@ -15,9 +15,10 @@ 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;
import org.chromium.base.VisibleForTesting;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.payments.ui.PaymentRequestUI.PaymentRequestObserverForTest;
@@ -27,10 +28,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 +44,24 @@ 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);
+ mActionIcon = (ImageView) findViewById(R.id.action_icon);
+ mActionIcon.setImageResource(fieldModel.getActionIconResourceId());
+ mActionIcon.setOnClickListener(this);
+ mActionIcon.setVisibility(VISIBLE);
please use gerrit instead 2016/10/20 22:52:04 mActionIcon.setContentDescription(fieldModel.getAc
gogerald1 2016/10/21 01:08:51 Done.
}
// Validate the field when the user de-focuses it.
@@ -152,6 +156,18 @@ 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.
please use gerrit instead 2016/10/20 22:52:04 Add a comment about why this is necessary. I think
gogerald1 2016/10/21 01:08:51 Done.
+ 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 +177,6 @@ public class EditorTextField extends CompatibilityTextInputLayout
return mEditorFieldModel;
}
- @Override
public AutoCompleteTextView getEditText() {
return mInput;
}
@@ -173,7 +188,7 @@ public class EditorTextField extends CompatibilityTextInputLayout
@Override
public void updateDisplayedError(boolean showError) {
- setError(showError ? mEditorFieldModel.getErrorMessage() : null);
+ mInputLayout.setError(showError ? mEditorFieldModel.getErrorMessage() : null);
}
@Override

Powered by Google App Engine
This is Rietveld 408576698