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

Unified Diff: ui/android/java/src/org/chromium/ui/DropdownPopupWindow.java

Issue 662683005: [android] Use correct view type for dropdown. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@common-colors
Patch Set: Set adapter in tests. Created 6 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 | « chrome/android/javatests/src/org/chromium/chrome/browser/autofill/AutofillTest.java ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/android/java/src/org/chromium/ui/DropdownPopupWindow.java
diff --git a/ui/android/java/src/org/chromium/ui/DropdownPopupWindow.java b/ui/android/java/src/org/chromium/ui/DropdownPopupWindow.java
index a1b8ee6c4e04d5c9eb163dc3a55d4f978cb5fe61..26a8ef2352f4b31270e96873d957c10410818d45 100644
--- a/ui/android/java/src/org/chromium/ui/DropdownPopupWindow.java
+++ b/ui/android/java/src/org/chromium/ui/DropdownPopupWindow.java
@@ -78,7 +78,8 @@ public class DropdownPopupWindow extends ListPopupWindow {
/**
* Sets the location and the size of the anchor view that the DropdownPopupWindow will use to
- * attach itself.
+ * attach itself. Calling this method can cause a layout change, so the adapter should not be
+ * null.
* @param x X coordinate of the top left corner of the anchor view.
* @param y Y coordinate of the top left corner of the anchor view.
* @param width The width of the anchor view.
@@ -101,10 +102,14 @@ public class DropdownPopupWindow extends ListPopupWindow {
super.setAdapter(adapter);
}
+ /**
+ * Shows the popup. The adapter should be set before calling this method.
+ */
@Override
public void show() {
// An ugly hack to keep the popup from expanding on top of the keyboard.
setInputMethodMode(INPUT_METHOD_NEEDED);
+
int contentWidth = measureContentWidth();
float contentWidthInDip = contentWidth /
mContext.getResources().getDisplayMetrics().density;
@@ -154,17 +159,19 @@ public class DropdownPopupWindow extends ListPopupWindow {
}
/**
- * Measures the width of the list content.
+ * Measures the width of the list content. The adapter should not be null.
* @return The popup window width in pixels.
*/
private int measureContentWidth() {
+ assert mAdapter != null : "Set the adapter before showing the popup.";
int maxWidth = 0;
- View itemView = null;
- if (mAdapter == null) return 0;
+ View[] itemViews = new View[mAdapter.getViewTypeCount()];
final int widthMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
final int heightMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
for (int i = 0; i < mAdapter.getCount(); i++) {
- itemView = mAdapter.getView(i, itemView, null);
+ int type = mAdapter.getItemViewType(i);
+ itemViews[type] = mAdapter.getView(i, itemViews[type], null);
+ View itemView = itemViews[type];
LinearLayout.LayoutParams params =
new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
« no previous file with comments | « chrome/android/javatests/src/org/chromium/chrome/browser/autofill/AutofillTest.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698