Commit 32ae5b89 authored by Ryan Landay's avatar Ryan Landay Committed by Commit Bot

Make UiUtils.computeMaxWidthOfListAdapterItems() use AbsListView.LayoutParams

Currently, this method uses LinearLayout.LayoutParams to measure the views in
the ListView (this code was refactored out of DropdownPopupWindow). However,
this causes a crash in certain situations on Android J and K (for example,
adding a LinearLayout as a footer view, calling this method, and then later
trying to measure a parent of the ListView) because LinearLayout.LayoutParams
can't be cast to AbsListView.LayoutParams.

This CL changes this code to use AbsListView.LayoutParams to avoid this crash.

Bug: 
Change-Id: I90b68cd812155ac87bc089f95493cdd82de77395
Reviewed-on: https://chromium-review.googlesource.com/571600Reviewed-by: default avatarTheresa <twellington@chromium.org>
Commit-Queue: Ryan Landay <rlanday@chromium.org>
Cr-Commit-Position: refs/heads/master@{#486824}
parent 1f20512d
...@@ -22,7 +22,7 @@ import android.view.ViewGroup; ...@@ -22,7 +22,7 @@ import android.view.ViewGroup;
import android.view.inputmethod.InputMethodInfo; import android.view.inputmethod.InputMethodInfo;
import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodManager;
import android.view.inputmethod.InputMethodSubtype; import android.view.inputmethod.InputMethodSubtype;
import android.widget.LinearLayout; import android.widget.AbsListView;
import android.widget.ListAdapter; import android.widget.ListAdapter;
import org.chromium.base.ApiCompatibilityUtils; import org.chromium.base.ApiCompatibilityUtils;
...@@ -429,8 +429,8 @@ public class UiUtils { ...@@ -429,8 +429,8 @@ public class UiUtils {
public static int computeMaxWidthOfListAdapterItems(ListAdapter adapter) { public static int computeMaxWidthOfListAdapterItems(ListAdapter adapter) {
final int widthMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED); final int widthMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
final int heightMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED); final int heightMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( AbsListView.LayoutParams params = new AbsListView.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); AbsListView.LayoutParams.WRAP_CONTENT, AbsListView.LayoutParams.WRAP_CONTENT);
int maxWidth = 0; int maxWidth = 0;
View[] itemViews = new View[adapter.getViewTypeCount()]; View[] itemViews = new View[adapter.getViewTypeCount()];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment