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

Unified Diff: content/public/android/java/src/org/chromium/content/browser/input/SelectPopupAdapter.java

Issue 2381063003: Avoid creating new CheckedTextViews in AlertDialog for <select> (Closed)
Patch Set: use tag instead of stack 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/public/android/java/src/org/chromium/content/browser/input/SelectPopupAdapter.java
diff --git a/content/public/android/java/src/org/chromium/content/browser/input/SelectPopupAdapter.java b/content/public/android/java/src/org/chromium/content/browser/input/SelectPopupAdapter.java
index ca8e5f0e52181de3433c592e777297a3d4cbfffa..b69910bc490ae07a3065510982753869b789bf0d 100644
--- a/content/public/android/java/src/org/chromium/content/browser/input/SelectPopupAdapter.java
+++ b/content/public/android/java/src/org/chromium/content/browser/input/SelectPopupAdapter.java
@@ -5,6 +5,7 @@
package org.chromium.content.browser.input;
import android.content.Context;
+import android.graphics.drawable.Drawable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
@@ -49,27 +50,36 @@ public class SelectPopupAdapter extends ArrayAdapter<SelectPopupItem> {
public View getView(int position, View convertView, ViewGroup parent) {
if (position < 0 || position >= getCount()) return null;
- // Always pass in null so that we will get a new CheckedTextView. Otherwise, an item
- // which was previously used as an <optgroup> element (i.e. has no check), could get
- // used as an <option> element, which needs a checkbox/radio, but it would not have
- // one.
- convertView = super.getView(position, null, parent);
+ convertView = super.getView(position, convertView, parent);
((TextView) convertView).setText(mItems.get(position).getLabel());
- if (mItems.get(position).getType() != PopupItemType.ENABLED) {
+ // Currently select_dialog_(single|multi)choice uses CheckedTextViews.
+ // If that changes, the class cast will no longer be valid.
+ // The WebView build cannot rely on this being the case, so
+ // we must check.
+ if (convertView instanceof CheckedTextView) {
+ // <optgroup> elements do not have check marks. If an item previously used as an
+ // <optgroup> gets reused for a non-<optgroup> element, we need to get the check mark
+ // back. Inflating a new View from XML can be slow, for both the inflation part and GC
+ // afterwards. Even creating a new Drawable can be tricky, considering getting the
+ // check/radio type and theme right.
+ // Saving the previously removed Drawables and reuse them when needed is faster,
+ // and the memory implication should be fine.
+ CheckedTextView view = (CheckedTextView) convertView;
if (mItems.get(position).getType() == PopupItemType.GROUP) {
- // Currently select_dialog_multichoice uses CheckedTextViews.
- // If that changes, the class cast will no longer be valid.
- // The WebView build cannot rely on this being the case, so
- // we must check.
- if (convertView instanceof CheckedTextView) {
- ((CheckedTextView) convertView).setCheckMarkDrawable(null);
+ if (view.getCheckMarkDrawable() != null) {
+ view.setTag(view.getCheckMarkDrawable());
+ view.setCheckMarkDrawable(null);
}
} else {
- // Draw the disabled element in a disabled state.
- convertView.setEnabled(false);
+ if (view.getCheckMarkDrawable() == null) {
+ view.setCheckMarkDrawable((Drawable) view.getTag());
+ }
}
}
+ // Draw the disabled element in a disabled state.
+ convertView.setEnabled(mItems.get(position).getType() != PopupItemType.DISABLED);
+
return convertView;
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698