Index: chrome/android/java/src/org/chromium/chrome/browser/widget/CompatibilityTextInputLayout.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/widget/CompatibilityTextInputLayout.java b/chrome/android/java/src/org/chromium/chrome/browser/widget/CompatibilityTextInputLayout.java |
new file mode 100644 |
index 0000000000000000000000000000000000000000..f5e3556117c89e74baa5f60a24168965266f5b1a |
--- /dev/null |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/widget/CompatibilityTextInputLayout.java |
@@ -0,0 +1,55 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+package org.chromium.chrome.browser.widget; |
+ |
+import android.content.Context; |
+import android.os.Build; |
+import android.support.design.widget.TextInputLayout; |
+import android.text.TextUtils; |
+import android.util.AttributeSet; |
+ |
+import javax.annotation.Nullable; |
+ |
+/** |
+ * Handles bugs with the Android Support library's {@link TextInputLayout} until Chrome can upgrade |
+ * to a newer version. |
Ian Wen
2016/06/30 23:12:15
Nit: shall we move the todo to the top of the file
gone
2016/06/30 23:18:58
Done.
|
+ */ |
+public class CompatibilityTextInputLayout extends TextInputLayout { |
+ |
+ /** Whether or not the background has been mutated to work around the red line bug. */ |
+ private boolean mIsBackgroundMutated; |
+ |
+ public CompatibilityTextInputLayout(Context context) { |
+ super(context); |
+ } |
+ |
+ public CompatibilityTextInputLayout(Context context, AttributeSet attrs) { |
+ super(context, attrs); |
+ } |
+ |
+ /** |
+ * Super gross, dirty, awful hack for dealing with bugs in version 23 of the support library. |
+ * |
+ * Gleaned using dirty things from comments on the Android bug and support library source: |
+ * https://code.google.com/p/android/issues/detail?id=190829 |
+ * |
+ * TODO(dfalcantara): Remove this super gross dirty hack once Chrome can roll version 24: |
+ * https://crbug.com/603635 |
+ */ |
+ @Override |
+ public void setError(@Nullable CharSequence error) { |
+ if (!mIsBackgroundMutated && getEditText() != null && getEditText().getBackground() != null |
+ && ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP))) { |
+ getEditText().setBackground( |
+ getEditText().getBackground().getConstantState().newDrawable()); |
+ getEditText().getBackground().mutate(); |
+ mIsBackgroundMutated = true; |
+ } |
+ |
+ super.setError(error); |
+ if (TextUtils.isEmpty(error)) setErrorEnabled(false); |
+ } |
+ |
+} |