ListPopupWindow.java revision 711734a2f8d7529df0ed1bce36da651fc835c144
1c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell/* 2c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * Copyright (C) 2010 The Android Open Source Project 3c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * 4c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * Licensed under the Apache License, Version 2.0 (the "License"); 5c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * you may not use this file except in compliance with the License. 6c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * You may obtain a copy of the License at 7c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * 8c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * http://www.apache.org/licenses/LICENSE-2.0 9c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * 10c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * Unless required by applicable law or agreed to in writing, software 11c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * distributed under the License is distributed on an "AS IS" BASIS, 12c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * See the License for the specific language governing permissions and 14c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * limitations under the License. 15c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell */ 16c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 17c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powellpackage android.widget; 18c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 19c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powellimport android.content.Context; 20c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powellimport android.database.DataSetObserver; 21c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powellimport android.graphics.Rect; 22c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powellimport android.graphics.drawable.Drawable; 23c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powellimport android.os.Handler; 24c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powellimport android.util.AttributeSet; 25c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powellimport android.util.Log; 26c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powellimport android.view.KeyEvent; 27c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powellimport android.view.MotionEvent; 28c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powellimport android.view.View; 29c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powellimport android.view.View.MeasureSpec; 30c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powellimport android.view.View.OnTouchListener; 31711734a2f8d7529df0ed1bce36da651fc835c144Gilles Debunneimport android.view.ViewGroup; 32711734a2f8d7529df0ed1bce36da651fc835c144Gilles Debunneimport android.view.ViewParent; 33c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 34c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell/** 35c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * A ListPopupWindow anchors itself to a host view and displays a 3665d79fbe55c017edd9419ddb71939c8916471390Adam Powell * list of choices. 37c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * 38c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * <p>ListPopupWindow contains a number of tricky behaviors surrounding 39c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * positioning, scrolling parents to fit the dropdown, interacting 40c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * sanely with the IME if present, and others. 41c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * 42c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @see android.widget.AutoCompleteTextView 43c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @see android.widget.Spinner 44c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell */ 45c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powellpublic class ListPopupWindow { 46c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell private static final String TAG = "ListPopupWindow"; 47c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell private static final boolean DEBUG = false; 48c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 49c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell /** 50c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * This value controls the length of time that the user 51c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * must leave a pointer down without scrolling to expand 52c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * the autocomplete dropdown list to cover the IME. 53c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell */ 54c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell private static final int EXPAND_LIST_TIMEOUT = 250; 55c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 56c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell private Context mContext; 57c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell private PopupWindow mPopup; 58c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell private ListAdapter mAdapter; 59c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell private DropDownListView mDropDownList; 60c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 61c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell private int mDropDownHeight = ViewGroup.LayoutParams.WRAP_CONTENT; 62c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell private int mDropDownWidth = ViewGroup.LayoutParams.WRAP_CONTENT; 63c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell private int mDropDownHorizontalOffset; 64c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell private int mDropDownVerticalOffset; 65c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 66c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell private boolean mDropDownAlwaysVisible = false; 67c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell private boolean mForceIgnoreOutsideTouch = false; 68c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 69c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell private View mPromptView; 70c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell private int mPromptPosition = POSITION_PROMPT_ABOVE; 71c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 72c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell private DataSetObserver mObserver; 73c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 74c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell private View mDropDownAnchorView; 75c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 76c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell private Drawable mDropDownListHighlight; 77c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 78c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell private AdapterView.OnItemClickListener mItemClickListener; 79c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell private AdapterView.OnItemSelectedListener mItemSelectedListener; 80c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 814267534d1c42af847ed0cefd1c88c99f66b36571Adam Powell private final ResizePopupRunnable mResizePopupRunnable = new ResizePopupRunnable(); 82c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell private final PopupTouchInterceptor mTouchInterceptor = new PopupTouchInterceptor(); 83c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell private final PopupScrollListener mScrollListener = new PopupScrollListener(); 84c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell private final ListSelectorHider mHideSelector = new ListSelectorHider(); 85c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell private Runnable mShowDropDownRunnable; 86c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 87c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell private Handler mHandler = new Handler(); 88c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 89c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell private Rect mTempRect = new Rect(); 90c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 91c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell private boolean mModal; 92c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 93c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell /** 94c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * The provided prompt view should appear above list content. 95c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * 96c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @see #setPromptPosition(int) 97c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @see #getPromptPosition() 98c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @see #setPromptView(View) 99c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell */ 100c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell public static final int POSITION_PROMPT_ABOVE = 0; 101c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 102c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell /** 103c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * The provided prompt view should appear below list content. 104c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * 105c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @see #setPromptPosition(int) 106c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @see #getPromptPosition() 107c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @see #setPromptView(View) 108c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell */ 109c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell public static final int POSITION_PROMPT_BELOW = 1; 110c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 111c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell /** 112c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * Alias for {@link ViewGroup.LayoutParams#MATCH_PARENT}. 113c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * If used to specify a popup width, the popup will match the width of the anchor view. 114c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * If used to specify a popup height, the popup will fill available space. 115c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell */ 116c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell public static final int MATCH_PARENT = ViewGroup.LayoutParams.MATCH_PARENT; 117c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 118c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell /** 119c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * Alias for {@link ViewGroup.LayoutParams#WRAP_CONTENT}. 120c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * If used to specify a popup width, the popup will use the width of its content. 121c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell */ 122c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell public static final int WRAP_CONTENT = ViewGroup.LayoutParams.WRAP_CONTENT; 123c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 124c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell /** 125c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * Mode for {@link #setInputMethodMode(int)}: the requirements for the 126c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * input method should be based on the focusability of the popup. That is 127c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * if it is focusable than it needs to work with the input method, else 128c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * it doesn't. 129c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell */ 130c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell public static final int INPUT_METHOD_FROM_FOCUSABLE = PopupWindow.INPUT_METHOD_FROM_FOCUSABLE; 131c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 132c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell /** 133c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * Mode for {@link #setInputMethodMode(int)}: this popup always needs to 134c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * work with an input method, regardless of whether it is focusable. This 135c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * means that it will always be displayed so that the user can also operate 136c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * the input method while it is shown. 137c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell */ 138c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell public static final int INPUT_METHOD_NEEDED = PopupWindow.INPUT_METHOD_NEEDED; 139c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 140c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell /** 141c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * Mode for {@link #setInputMethodMode(int)}: this popup never needs to 142c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * work with an input method, regardless of whether it is focusable. This 143c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * means that it will always be displayed to use as much space on the 144c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * screen as needed, regardless of whether this covers the input method. 145c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell */ 146c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell public static final int INPUT_METHOD_NOT_NEEDED = PopupWindow.INPUT_METHOD_NOT_NEEDED; 147c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 148c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell /** 149c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * Create a new, empty popup window capable of displaying items from a ListAdapter. 150c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * Backgrounds should be set using {@link #setBackgroundDrawable(Drawable)}. 151c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * 152c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @param context Context used for contained views. 153c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell */ 154c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell public ListPopupWindow(Context context) { 155c2238d006237ebf1296074d80fb4f4a2741ef880Daniel Lehmann this(context, null, com.android.internal.R.attr.listPopupWindowStyle, 0); 156c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 157c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 158c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell /** 159c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * Create a new, empty popup window capable of displaying items from a ListAdapter. 160c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * Backgrounds should be set using {@link #setBackgroundDrawable(Drawable)}. 161c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * 162c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @param context Context used for contained views. 163c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @param attrs Attributes from inflating parent views used to style the popup. 164c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell */ 165c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell public ListPopupWindow(Context context, AttributeSet attrs) { 1660b2d306e7000f4c0c6ad4e00d494bb401d8a9fc2Adam Powell this(context, attrs, com.android.internal.R.attr.listPopupWindowStyle, 0); 167c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 168c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 169c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell /** 170c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * Create a new, empty popup window capable of displaying items from a ListAdapter. 171c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * Backgrounds should be set using {@link #setBackgroundDrawable(Drawable)}. 172c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * 173c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @param context Context used for contained views. 174c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @param attrs Attributes from inflating parent views used to style the popup. 175c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @param defStyleAttr Default style attribute to use for popup content. 176c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell */ 177c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell public ListPopupWindow(Context context, AttributeSet attrs, int defStyleAttr) { 178c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell this(context, attrs, defStyleAttr, 0); 179c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 180c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 181c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell /** 182c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * Create a new, empty popup window capable of displaying items from a ListAdapter. 183c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * Backgrounds should be set using {@link #setBackgroundDrawable(Drawable)}. 184c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * 185c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @param context Context used for contained views. 186c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @param attrs Attributes from inflating parent views used to style the popup. 187c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @param defStyleAttr Style attribute to read for default styling of popup content. 188c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @param defStyleRes Style resource ID to use for default styling of popup content. 189c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell */ 190c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell public ListPopupWindow(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 191c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell mContext = context; 192c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell mPopup = new PopupWindow(context, attrs, defStyleAttr, defStyleRes); 1936f5e934b96c400f610b1c5ad228cc60cab5d443fAdam Powell mPopup.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED); 194c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 195c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 196c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell /** 197c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * Sets the adapter that provides the data and the views to represent the data 198c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * in this popup window. 199c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * 200c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @param adapter The adapter to use to create this window's content. 201c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell */ 202c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell public void setAdapter(ListAdapter adapter) { 203c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell if (mObserver == null) { 204c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell mObserver = new PopupDataSetObserver(); 205c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } else if (mAdapter != null) { 20699969da3772d9a0f5079672847ca4f2ad819c1bbAdam Powell mAdapter.unregisterDataSetObserver(mObserver); 207c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 208c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell mAdapter = adapter; 209c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell if (mAdapter != null) { 210c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell adapter.registerDataSetObserver(mObserver); 211c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 212c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 213c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell if (mDropDownList != null) { 214c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell mDropDownList.setAdapter(mAdapter); 215c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 216c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 217c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 218c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell /** 219c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * Set where the optional prompt view should appear. The default is 220c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * {@link #POSITION_PROMPT_ABOVE}. 221c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * 222c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @param position A position constant declaring where the prompt should be displayed. 223c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * 224c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @see #POSITION_PROMPT_ABOVE 225c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @see #POSITION_PROMPT_BELOW 226c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell */ 227c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell public void setPromptPosition(int position) { 228c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell mPromptPosition = position; 229c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 230c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 231c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell /** 232c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @return Where the optional prompt view should appear. 233c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * 234c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @see #POSITION_PROMPT_ABOVE 235c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @see #POSITION_PROMPT_BELOW 236c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell */ 237c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell public int getPromptPosition() { 238c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell return mPromptPosition; 239c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 240c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 241c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell /** 242c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * Set whether this window should be modal when shown. 243c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * 244c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * <p>If a popup window is modal, it will receive all touch and key input. 245c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * If the user touches outside the popup window's content area the popup window 246c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * will be dismissed. 247c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * 248c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @param modal {@code true} if the popup window should be modal, {@code false} otherwise. 249c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell */ 250c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell public void setModal(boolean modal) { 251c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell mModal = true; 252c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell mPopup.setFocusable(modal); 253c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 254c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 255c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell /** 256c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * Returns whether the popup window will be modal when shown. 257c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * 258c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @return {@code true} if the popup window will be modal, {@code false} otherwise. 259c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell */ 260c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell public boolean isModal() { 261c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell return mModal; 262c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 263c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 264c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell /** 265c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * Forces outside touches to be ignored. Normally if {@link #isDropDownAlwaysVisible()} is 266c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * false, we allow outside touch to dismiss the dropdown. If this is set to true, then we 267c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * ignore outside touch even when the drop down is not set to always visible. 268c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * 269c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @hide Used only by AutoCompleteTextView to handle some internal special cases. 270c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell */ 271c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell public void setForceIgnoreOutsideTouch(boolean forceIgnoreOutsideTouch) { 272c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell mForceIgnoreOutsideTouch = forceIgnoreOutsideTouch; 273c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 274c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 275c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell /** 276c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * Sets whether the drop-down should remain visible under certain conditions. 277c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * 278c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * The drop-down will occupy the entire screen below {@link #getAnchorView} regardless 279c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * of the size or content of the list. {@link #getBackground()} will fill any space 280c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * that is not used by the list. 281c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * 282c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @param dropDownAlwaysVisible Whether to keep the drop-down visible. 283c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * 284c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @hide Only used by AutoCompleteTextView under special conditions. 285c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell */ 286c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell public void setDropDownAlwaysVisible(boolean dropDownAlwaysVisible) { 287c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell mDropDownAlwaysVisible = dropDownAlwaysVisible; 288c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 289c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 290c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell /** 291c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @return Whether the drop-down is visible under special conditions. 292c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * 293c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @hide Only used by AutoCompleteTextView under special conditions. 294c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell */ 295c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell public boolean isDropDownAlwaysVisible() { 296c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell return mDropDownAlwaysVisible; 297c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 298c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 299c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell /** 300c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * Sets the operating mode for the soft input area. 301c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * 302c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @param mode The desired mode, see 303c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * {@link android.view.WindowManager.LayoutParams#softInputMode} 304c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * for the full list 305c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * 306c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @see android.view.WindowManager.LayoutParams#softInputMode 307c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @see #getSoftInputMode() 308c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell */ 309c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell public void setSoftInputMode(int mode) { 310c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell mPopup.setSoftInputMode(mode); 311c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 312c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 313c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell /** 314c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * Returns the current value in {@link #setSoftInputMode(int)}. 315c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * 316c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @see #setSoftInputMode(int) 317c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @see android.view.WindowManager.LayoutParams#softInputMode 318c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell */ 319c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell public int getSoftInputMode() { 320c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell return mPopup.getSoftInputMode(); 321c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 322c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 323c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell /** 324c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * Sets a drawable to use as the list item selector. 325c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * 326c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @param selector List selector drawable to use in the popup. 327c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell */ 328c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell public void setListSelector(Drawable selector) { 329c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell mDropDownListHighlight = selector; 330c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 331c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 332c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell /** 333c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @return The background drawable for the popup window. 334c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell */ 335c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell public Drawable getBackground() { 336c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell return mPopup.getBackground(); 337c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 338c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 339c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell /** 340c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * Sets a drawable to be the background for the popup window. 341c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * 342c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @param d A drawable to set as the background. 343c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell */ 344c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell public void setBackgroundDrawable(Drawable d) { 345c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell mPopup.setBackgroundDrawable(d); 346c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 347c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 348c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell /** 349c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * Set an animation style to use when the popup window is shown or dismissed. 350c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * 351c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @param animationStyle Animation style to use. 352c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell */ 353c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell public void setAnimationStyle(int animationStyle) { 354c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell mPopup.setAnimationStyle(animationStyle); 355c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 356c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 357c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell /** 358c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * Returns the animation style that will be used when the popup window is 359c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * shown or dismissed. 360c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * 361c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @return Animation style that will be used. 362c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell */ 363c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell public int getAnimationStyle() { 364c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell return mPopup.getAnimationStyle(); 365c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 366c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 367c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell /** 368c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * Returns the view that will be used to anchor this popup. 369c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * 370c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @return The popup's anchor view 371c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell */ 372c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell public View getAnchorView() { 373c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell return mDropDownAnchorView; 374c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 375c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 376c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell /** 377c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * Sets the popup's anchor view. This popup will always be positioned relative to 378c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * the anchor view when shown. 379c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * 380c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @param anchor The view to use as an anchor. 381c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell */ 382c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell public void setAnchorView(View anchor) { 383c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell mDropDownAnchorView = anchor; 384c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 385c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 386c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell /** 387c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @return The horizontal offset of the popup from its anchor in pixels. 388c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell */ 389c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell public int getHorizontalOffset() { 390c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell return mDropDownHorizontalOffset; 391c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 392c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 393c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell /** 394c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * Set the horizontal offset of this popup from its anchor view in pixels. 395c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * 396a984b38df5cfe6db0ba792bf2a6221f6b6072448Adam Powell * @param offset The horizontal offset of the popup from its anchor. 397c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell */ 398c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell public void setHorizontalOffset(int offset) { 399c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell mDropDownHorizontalOffset = offset; 400c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 401c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 402c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell /** 403c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @return The vertical offset of the popup from its anchor in pixels. 404c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell */ 405c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell public int getVerticalOffset() { 406c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell return mDropDownVerticalOffset; 407c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 408c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 409c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell /** 410c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * Set the vertical offset of this popup from its anchor view in pixels. 411c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * 412a984b38df5cfe6db0ba792bf2a6221f6b6072448Adam Powell * @param offset The vertical offset of the popup from its anchor. 413c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell */ 414c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell public void setVerticalOffset(int offset) { 415c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell mDropDownVerticalOffset = offset; 416c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 417c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 418c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell /** 419c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @return The width of the popup window in pixels. 420c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell */ 421c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell public int getWidth() { 422c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell return mDropDownWidth; 423c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 424c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 425c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell /** 426c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * Sets the width of the popup window in pixels. Can also be {@link #MATCH_PARENT} 427c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * or {@link #WRAP_CONTENT}. 428c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * 429c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @param width Width of the popup window. 430c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell */ 431c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell public void setWidth(int width) { 432c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell mDropDownWidth = width; 433c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 434c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 435c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell /** 4364267534d1c42af847ed0cefd1c88c99f66b36571Adam Powell * Sets the width of the popup window by the size of its content. The final width may be 4374267534d1c42af847ed0cefd1c88c99f66b36571Adam Powell * larger to accommodate styled window dressing. 4384267534d1c42af847ed0cefd1c88c99f66b36571Adam Powell * 4394267534d1c42af847ed0cefd1c88c99f66b36571Adam Powell * @param width Desired width of content in pixels. 4404267534d1c42af847ed0cefd1c88c99f66b36571Adam Powell */ 4414267534d1c42af847ed0cefd1c88c99f66b36571Adam Powell public void setContentWidth(int width) { 4424267534d1c42af847ed0cefd1c88c99f66b36571Adam Powell Drawable popupBackground = mPopup.getBackground(); 4434267534d1c42af847ed0cefd1c88c99f66b36571Adam Powell if (popupBackground != null) { 444a39b987bb761899636ae1e3669d1343499d04ebdAdam Powell popupBackground.getPadding(mTempRect); 445a39b987bb761899636ae1e3669d1343499d04ebdAdam Powell mDropDownWidth = mTempRect.left + mTempRect.right + width; 4464267534d1c42af847ed0cefd1c88c99f66b36571Adam Powell } 4474267534d1c42af847ed0cefd1c88c99f66b36571Adam Powell } 4484267534d1c42af847ed0cefd1c88c99f66b36571Adam Powell 4494267534d1c42af847ed0cefd1c88c99f66b36571Adam Powell /** 450c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @return The height of the popup window in pixels. 451c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell */ 452c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell public int getHeight() { 453c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell return mDropDownHeight; 454c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 455c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 456c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell /** 457c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * Sets the height of the popup window in pixels. Can also be {@link #MATCH_PARENT}. 458c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * 459c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @param height Height of the popup window. 460c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell */ 461c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell public void setHeight(int height) { 462c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell mDropDownHeight = height; 463c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 464c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 465c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell /** 466c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * Sets a listener to receive events when a list item is clicked. 467c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * 468c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @param clickListener Listener to register 469c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * 470c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @see ListView#setOnItemClickListener(android.widget.AdapterView.OnItemClickListener) 471c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell */ 472c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell public void setOnItemClickListener(AdapterView.OnItemClickListener clickListener) { 473c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell mItemClickListener = clickListener; 474c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 475c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 476c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell /** 477c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * Sets a listener to receive events when a list item is selected. 478c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * 479c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @param selectedListener Listener to register. 480c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * 481c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @see ListView#setOnItemSelectedListener(android.widget.AdapterView.OnItemSelectedListener) 482c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell */ 483c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell public void setOnItemSelectedListener(AdapterView.OnItemSelectedListener selectedListener) { 484c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell mItemSelectedListener = selectedListener; 485c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 486c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 487c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell /** 488c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * Set a view to act as a user prompt for this popup window. Where the prompt view will appear 489c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * is controlled by {@link #setPromptPosition(int)}. 490c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * 491c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @param prompt View to use as an informational prompt. 492c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell */ 493c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell public void setPromptView(View prompt) { 494c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell boolean showing = isShowing(); 495c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell if (showing) { 496c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell removePromptView(); 497c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 498c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell mPromptView = prompt; 499c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell if (showing) { 500c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell show(); 501c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 502c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 503c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 504c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell /** 505c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * Post a {@link #show()} call to the UI thread. 506c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell */ 507c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell public void postShow() { 508c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell mHandler.post(mShowDropDownRunnable); 509c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 510c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 511c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell /** 512c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * Show the popup list. If the list is already showing, this method 513c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * will recalculate the popup's size and position. 514c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell */ 515c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell public void show() { 516c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell int height = buildDropDown(); 517c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 518c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell int widthSpec = 0; 519c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell int heightSpec = 0; 520c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 521c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell boolean noInputMethod = isInputMethodNotNeeded(); 522c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 523c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell if (mPopup.isShowing()) { 524c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell if (mDropDownWidth == ViewGroup.LayoutParams.MATCH_PARENT) { 525c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell // The call to PopupWindow's update method below can accept -1 for any 526c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell // value you do not want to update. 527c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell widthSpec = -1; 528c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } else if (mDropDownWidth == ViewGroup.LayoutParams.WRAP_CONTENT) { 529c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell widthSpec = getAnchorView().getWidth(); 530c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } else { 531c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell widthSpec = mDropDownWidth; 532c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 533c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 534c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell if (mDropDownHeight == ViewGroup.LayoutParams.MATCH_PARENT) { 535c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell // The call to PopupWindow's update method below can accept -1 for any 536c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell // value you do not want to update. 537c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell heightSpec = noInputMethod ? height : ViewGroup.LayoutParams.MATCH_PARENT; 538c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell if (noInputMethod) { 539c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell mPopup.setWindowLayoutMode( 540c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell mDropDownWidth == ViewGroup.LayoutParams.MATCH_PARENT ? 541c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell ViewGroup.LayoutParams.MATCH_PARENT : 0, 0); 542c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } else { 543c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell mPopup.setWindowLayoutMode( 544c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell mDropDownWidth == ViewGroup.LayoutParams.MATCH_PARENT ? 545c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell ViewGroup.LayoutParams.MATCH_PARENT : 0, 546c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell ViewGroup.LayoutParams.MATCH_PARENT); 547c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 548c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } else if (mDropDownHeight == ViewGroup.LayoutParams.WRAP_CONTENT) { 549c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell heightSpec = height; 550c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } else { 551c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell heightSpec = mDropDownHeight; 552c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 553c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 554c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell mPopup.setOutsideTouchable(!mForceIgnoreOutsideTouch && !mDropDownAlwaysVisible); 555c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 556c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell mPopup.update(getAnchorView(), mDropDownHorizontalOffset, 557c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell mDropDownVerticalOffset, widthSpec, heightSpec); 558c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } else { 559c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell if (mDropDownWidth == ViewGroup.LayoutParams.MATCH_PARENT) { 560c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell widthSpec = ViewGroup.LayoutParams.MATCH_PARENT; 561c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } else { 562c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell if (mDropDownWidth == ViewGroup.LayoutParams.WRAP_CONTENT) { 563c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell mPopup.setWidth(getAnchorView().getWidth()); 564c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } else { 565c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell mPopup.setWidth(mDropDownWidth); 566c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 567c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 568c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 569c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell if (mDropDownHeight == ViewGroup.LayoutParams.MATCH_PARENT) { 570c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell heightSpec = ViewGroup.LayoutParams.MATCH_PARENT; 571c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } else { 572c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell if (mDropDownHeight == ViewGroup.LayoutParams.WRAP_CONTENT) { 573c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell mPopup.setHeight(height); 574c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } else { 575c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell mPopup.setHeight(mDropDownHeight); 576c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 577c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 578c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 579c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell mPopup.setWindowLayoutMode(widthSpec, heightSpec); 58056c2d337e02a275397fc9d0460dca90977f199acAdam Powell mPopup.setClipToScreenEnabled(true); 581c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 582c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell // use outside touchable to dismiss drop down when touching outside of it, so 583c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell // only set this if the dropdown is not always visible 584c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell mPopup.setOutsideTouchable(!mForceIgnoreOutsideTouch && !mDropDownAlwaysVisible); 585c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell mPopup.setTouchInterceptor(mTouchInterceptor); 586c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell mPopup.showAsDropDown(getAnchorView(), 587c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell mDropDownHorizontalOffset, mDropDownVerticalOffset); 588c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell mDropDownList.setSelection(ListView.INVALID_POSITION); 589c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 590c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell if (!mModal || mDropDownList.isInTouchMode()) { 591c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell clearListSelection(); 592c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 593c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell if (!mModal) { 594c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell mHandler.post(mHideSelector); 595c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 596c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 597c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 598c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 599c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell /** 600c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * Dismiss the popup window. 601c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell */ 602c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell public void dismiss() { 603c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell mPopup.dismiss(); 604c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell removePromptView(); 605c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell mPopup.setContentView(null); 606c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell mDropDownList = null; 607c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 608c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 6096c6f575423d6718c3ff322224c1520901ce881e1Adam Powell /** 6106c6f575423d6718c3ff322224c1520901ce881e1Adam Powell * Set a listener to receive a callback when the popup is dismissed. 6116c6f575423d6718c3ff322224c1520901ce881e1Adam Powell * 6126c6f575423d6718c3ff322224c1520901ce881e1Adam Powell * @param listener Listener that will be notified when the popup is dismissed. 6136c6f575423d6718c3ff322224c1520901ce881e1Adam Powell */ 6146c6f575423d6718c3ff322224c1520901ce881e1Adam Powell public void setOnDismissListener(PopupWindow.OnDismissListener listener) { 6156c6f575423d6718c3ff322224c1520901ce881e1Adam Powell mPopup.setOnDismissListener(listener); 6166c6f575423d6718c3ff322224c1520901ce881e1Adam Powell } 6176c6f575423d6718c3ff322224c1520901ce881e1Adam Powell 618c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell private void removePromptView() { 619c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell if (mPromptView != null) { 620c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell final ViewParent parent = mPromptView.getParent(); 621c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell if (parent instanceof ViewGroup) { 622c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell final ViewGroup group = (ViewGroup) parent; 623c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell group.removeView(mPromptView); 624c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 625c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 626c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 627c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 628c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell /** 629c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * Control how the popup operates with an input method: one of 630c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * {@link #INPUT_METHOD_FROM_FOCUSABLE}, {@link #INPUT_METHOD_NEEDED}, 631c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * or {@link #INPUT_METHOD_NOT_NEEDED}. 632c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * 633c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * <p>If the popup is showing, calling this method will take effect only 634c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * the next time the popup is shown or through a manual call to the {@link #show()} 635c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * method.</p> 636c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * 637c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @see #getInputMethodMode() 638c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @see #show() 639c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell */ 640c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell public void setInputMethodMode(int mode) { 641c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell mPopup.setInputMethodMode(mode); 642c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 643c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 644c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell /** 645c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * Return the current value in {@link #setInputMethodMode(int)}. 646c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * 647c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @see #setInputMethodMode(int) 648c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell */ 649c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell public int getInputMethodMode() { 650c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell return mPopup.getInputMethodMode(); 651c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 652c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 653c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell /** 654c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * Set the selected position of the list. 655c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * Only valid when {@link #isShowing()} == {@code true}. 656c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * 657c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @param position List position to set as selected. 658c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell */ 659c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell public void setSelection(int position) { 660c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell DropDownListView list = mDropDownList; 661c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell if (isShowing() && list != null) { 662c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell list.mListSelectionHidden = false; 663c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell list.setSelection(position); 664c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell if (list.getChoiceMode() != ListView.CHOICE_MODE_NONE) { 665c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell list.setItemChecked(position, true); 666c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 667c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 668c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 669c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 670c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell /** 671c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * Clear any current list selection. 672c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * Only valid when {@link #isShowing()} == {@code true}. 673c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell */ 674c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell public void clearListSelection() { 675c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell final DropDownListView list = mDropDownList; 676c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell if (list != null) { 677c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell // WARNING: Please read the comment where mListSelectionHidden is declared 678c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell list.mListSelectionHidden = true; 679c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell list.hideSelector(); 680c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell list.requestLayout(); 681c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 682c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 683c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 684c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell /** 685c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @return {@code true} if the popup is currently showing, {@code false} otherwise. 686c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell */ 687c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell public boolean isShowing() { 688c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell return mPopup.isShowing(); 689c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 690c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 691c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell /** 692c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @return {@code true} if this popup is configured to assume the user does not need 693c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * to interact with the IME while it is showing, {@code false} otherwise. 694c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell */ 695c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell public boolean isInputMethodNotNeeded() { 696c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell return mPopup.getInputMethodMode() == INPUT_METHOD_NOT_NEEDED; 697c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 698c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 699c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell /** 700c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * Perform an item click operation on the specified list adapter position. 701c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * 702c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @param position Adapter position for performing the click 703c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @return true if the click action could be performed, false if not. 704c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * (e.g. if the popup was not showing, this method would return false.) 705c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell */ 706c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell public boolean performItemClick(int position) { 707c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell if (isShowing()) { 708c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell if (mItemClickListener != null) { 709c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell final DropDownListView list = mDropDownList; 710c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell final View child = list.getChildAt(position - list.getFirstVisiblePosition()); 711cdee446075811e871fc2af295377bd99c100d16dAdam Powell final ListAdapter adapter = list.getAdapter(); 712cdee446075811e871fc2af295377bd99c100d16dAdam Powell mItemClickListener.onItemClick(list, child, position, adapter.getItemId(position)); 713c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 714c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell return true; 715c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 716c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell return false; 717c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 718c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 719c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell /** 720c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @return The currently selected item or null if the popup is not showing. 721c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell */ 722c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell public Object getSelectedItem() { 723c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell if (!isShowing()) { 724c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell return null; 725c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 726c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell return mDropDownList.getSelectedItem(); 727c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 728c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 729c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell /** 730c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @return The position of the currently selected item or {@link ListView#INVALID_POSITION} 731c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * if {@link #isShowing()} == {@code false}. 732c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * 733c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @see ListView#getSelectedItemPosition() 734c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell */ 735c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell public int getSelectedItemPosition() { 736c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell if (!isShowing()) { 737c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell return ListView.INVALID_POSITION; 738c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 739c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell return mDropDownList.getSelectedItemPosition(); 740c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 741c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 742c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell /** 743c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @return The ID of the currently selected item or {@link ListView#INVALID_ROW_ID} 744c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * if {@link #isShowing()} == {@code false}. 745c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * 746c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @see ListView#getSelectedItemId() 747c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell */ 748c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell public long getSelectedItemId() { 749c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell if (!isShowing()) { 750c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell return ListView.INVALID_ROW_ID; 751c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 752c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell return mDropDownList.getSelectedItemId(); 753c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 754c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 755c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell /** 756c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @return The View for the currently selected item or null if 757c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * {@link #isShowing()} == {@code false}. 758c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * 759c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @see ListView#getSelectedView() 760c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell */ 761c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell public View getSelectedView() { 762c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell if (!isShowing()) { 763c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell return null; 764c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 765c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell return mDropDownList.getSelectedView(); 766c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 767c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 768c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell /** 769c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @return The {@link ListView} displayed within the popup window. 770c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * Only valid when {@link #isShowing()} == {@code true}. 771c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell */ 772c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell public ListView getListView() { 773c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell return mDropDownList; 774c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 775c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 776c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell /** 7778d6d3b83fb765eefc6fd38de77f1f45d2523ab89Jeff Brown * Filter key down events. By forwarding key down events to this function, 778c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * views using non-modal ListPopupWindow can have it handle key selection of items. 779c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * 780c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @param keyCode keyCode param passed to the host view's onKeyDown 781c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @param event event param passed to the host view's onKeyDown 782c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @return true if the event was handled, false if it was ignored. 783c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * 784c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @see #setModal(boolean) 785c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell */ 786c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell public boolean onKeyDown(int keyCode, KeyEvent event) { 787c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell // when the drop down is shown, we drive it directly 788c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell if (isShowing()) { 789c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell // the key events are forwarded to the list in the drop down view 790c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell // note that ListView handles space but we don't want that to happen 791c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell // also if selection is not currently in the drop down, then don't 792c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell // let center or enter presses go there since that would cause it 793c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell // to select one of its items 794c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell if (keyCode != KeyEvent.KEYCODE_SPACE 795c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell && (mDropDownList.getSelectedItemPosition() >= 0 796c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell || (keyCode != KeyEvent.KEYCODE_ENTER 797c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell && keyCode != KeyEvent.KEYCODE_DPAD_CENTER))) { 798c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell int curIndex = mDropDownList.getSelectedItemPosition(); 799c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell boolean consumed; 800c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 801c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell final boolean below = !mPopup.isAboveAnchor(); 802c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 803c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell final ListAdapter adapter = mAdapter; 804c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 805c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell boolean allEnabled; 806c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell int firstItem = Integer.MAX_VALUE; 807c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell int lastItem = Integer.MIN_VALUE; 808c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 809c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell if (adapter != null) { 810c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell allEnabled = adapter.areAllItemsEnabled(); 811c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell firstItem = allEnabled ? 0 : 812c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell mDropDownList.lookForSelectablePosition(0, true); 813c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell lastItem = allEnabled ? adapter.getCount() - 1 : 814c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell mDropDownList.lookForSelectablePosition(adapter.getCount() - 1, false); 815c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 816c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 817c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell if ((below && keyCode == KeyEvent.KEYCODE_DPAD_UP && curIndex <= firstItem) || 818c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell (!below && keyCode == KeyEvent.KEYCODE_DPAD_DOWN && curIndex >= lastItem)) { 819c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell // When the selection is at the top, we block the key 820c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell // event to prevent focus from moving. 821c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell clearListSelection(); 822c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell mPopup.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED); 823c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell show(); 824c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell return true; 825c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } else { 826c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell // WARNING: Please read the comment where mListSelectionHidden 827c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell // is declared 828c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell mDropDownList.mListSelectionHidden = false; 829c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 830c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 831c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell consumed = mDropDownList.onKeyDown(keyCode, event); 832c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell if (DEBUG) Log.v(TAG, "Key down: code=" + keyCode + " list consumed=" + consumed); 833c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 834c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell if (consumed) { 835c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell // If it handled the key event, then the user is 836c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell // navigating in the list, so we should put it in front. 837c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell mPopup.setInputMethodMode(PopupWindow.INPUT_METHOD_NOT_NEEDED); 838c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell // Here's a little trick we need to do to make sure that 839c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell // the list view is actually showing its focus indicator, 840c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell // by ensuring it has focus and getting its window out 841c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell // of touch mode. 842c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell mDropDownList.requestFocusFromTouch(); 843c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell show(); 844c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 845c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell switch (keyCode) { 846c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell // avoid passing the focus from the text view to the 847c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell // next component 848c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell case KeyEvent.KEYCODE_ENTER: 849c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell case KeyEvent.KEYCODE_DPAD_CENTER: 850c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell case KeyEvent.KEYCODE_DPAD_DOWN: 851c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell case KeyEvent.KEYCODE_DPAD_UP: 852c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell return true; 853c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 854c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } else { 855c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell if (below && keyCode == KeyEvent.KEYCODE_DPAD_DOWN) { 856c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell // when the selection is at the bottom, we block the 857c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell // event to avoid going to the next focusable widget 858c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell if (curIndex == lastItem) { 859c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell return true; 860c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 861c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } else if (!below && keyCode == KeyEvent.KEYCODE_DPAD_UP && 862c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell curIndex == firstItem) { 863c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell return true; 864c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 865c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 866c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 867c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 868c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 869c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell return false; 870c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 871c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 872c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell /** 873c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * Filter key down events. By forwarding key up events to this function, 874c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * views using non-modal ListPopupWindow can have it handle key selection of items. 875c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * 876c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @param keyCode keyCode param passed to the host view's onKeyUp 877c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @param event event param passed to the host view's onKeyUp 878c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @return true if the event was handled, false if it was ignored. 879c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * 880c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @see #setModal(boolean) 881c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell */ 882c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell public boolean onKeyUp(int keyCode, KeyEvent event) { 883c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell if (isShowing() && mDropDownList.getSelectedItemPosition() >= 0) { 884c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell boolean consumed = mDropDownList.onKeyUp(keyCode, event); 885c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell if (consumed) { 886c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell switch (keyCode) { 887c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell // if the list accepts the key events and the key event 888c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell // was a click, the text view gets the selected item 889c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell // from the drop down as its content 890c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell case KeyEvent.KEYCODE_ENTER: 891c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell case KeyEvent.KEYCODE_DPAD_CENTER: 892c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell dismiss(); 893c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell break; 894c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 895c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 896c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell return consumed; 897c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 898c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell return false; 899c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 900c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 901c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell /** 902c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * Filter pre-IME key events. By forwarding {@link View#onKeyPreIme(int, KeyEvent)} 903c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * events to this function, views using ListPopupWindow can have it dismiss the popup 904c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * when the back key is pressed. 905c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * 906c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @param keyCode keyCode param passed to the host view's onKeyPreIme 907c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @param event event param passed to the host view's onKeyPreIme 908c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @return true if the event was handled, false if it was ignored. 909c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * 910c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @see #setModal(boolean) 911c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell */ 912c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell public boolean onKeyPreIme(int keyCode, KeyEvent event) { 913c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell if (keyCode == KeyEvent.KEYCODE_BACK && isShowing()) { 914c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell // special case for the back key, we do not even try to send it 915c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell // to the drop down list but instead, consume it immediately 916c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell final View anchorView = mDropDownAnchorView; 917c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell if (event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0) { 918b3ea92235c9ccc1ff295839a8f324dcd1c83dd6fJeff Brown KeyEvent.DispatcherState state = anchorView.getKeyDispatcherState(); 919b3ea92235c9ccc1ff295839a8f324dcd1c83dd6fJeff Brown if (state != null) { 920b3ea92235c9ccc1ff295839a8f324dcd1c83dd6fJeff Brown state.startTracking(event, this); 921b3ea92235c9ccc1ff295839a8f324dcd1c83dd6fJeff Brown } 922c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell return true; 923c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } else if (event.getAction() == KeyEvent.ACTION_UP) { 924b3ea92235c9ccc1ff295839a8f324dcd1c83dd6fJeff Brown KeyEvent.DispatcherState state = anchorView.getKeyDispatcherState(); 925b3ea92235c9ccc1ff295839a8f324dcd1c83dd6fJeff Brown if (state != null) { 926b3ea92235c9ccc1ff295839a8f324dcd1c83dd6fJeff Brown state.handleUpEvent(event); 927b3ea92235c9ccc1ff295839a8f324dcd1c83dd6fJeff Brown } 928c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell if (event.isTracking() && !event.isCanceled()) { 929c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell dismiss(); 930c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell return true; 931c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 932c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 933c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 934c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell return false; 935c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 936c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 937c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell /** 938c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * <p>Builds the popup window's content and returns the height the popup 939c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * should have. Returns -1 when the content already exists.</p> 940c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * 941c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @return the content's height or -1 if content already exists 942c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell */ 943c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell private int buildDropDown() { 944c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell ViewGroup dropDownView; 945c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell int otherHeights = 0; 946c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 947c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell if (mDropDownList == null) { 948c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell Context context = mContext; 949c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 950c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell /** 951c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * This Runnable exists for the sole purpose of checking if the view layout has got 952c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * completed and if so call showDropDown to display the drop down. This is used to show 953c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * the drop down as soon as possible after user opens up the search dialog, without 954c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * waiting for the normal UI pipeline to do it's job which is slower than this method. 955c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell */ 956c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell mShowDropDownRunnable = new Runnable() { 957c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell public void run() { 958c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell // View layout should be all done before displaying the drop down. 959c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell View view = getAnchorView(); 960c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell if (view != null && view.getWindowToken() != null) { 961c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell show(); 962c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 963c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 964c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell }; 965c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 966c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell mDropDownList = new DropDownListView(context, !mModal); 967c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell if (mDropDownListHighlight != null) { 968c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell mDropDownList.setSelector(mDropDownListHighlight); 969c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 970c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell mDropDownList.setAdapter(mAdapter); 971c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell mDropDownList.setVerticalFadingEdgeEnabled(true); 972c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell mDropDownList.setOnItemClickListener(mItemClickListener); 973c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell mDropDownList.setFocusable(true); 974c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell mDropDownList.setFocusableInTouchMode(true); 975c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell mDropDownList.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { 976c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell public void onItemSelected(AdapterView<?> parent, View view, 977c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell int position, long id) { 978c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 979c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell if (position != -1) { 980c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell DropDownListView dropDownList = mDropDownList; 981c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 982c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell if (dropDownList != null) { 983c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell dropDownList.mListSelectionHidden = false; 984c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 985c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 986c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 987c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 988c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell public void onNothingSelected(AdapterView<?> parent) { 989c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 990c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell }); 991c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell mDropDownList.setOnScrollListener(mScrollListener); 992c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 993c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell if (mItemSelectedListener != null) { 994c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell mDropDownList.setOnItemSelectedListener(mItemSelectedListener); 995c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 996c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 997c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell dropDownView = mDropDownList; 998c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 999c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell View hintView = mPromptView; 1000c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell if (hintView != null) { 1001c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell // if an hint has been specified, we accomodate more space for it and 1002c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell // add a text view in the drop down menu, at the bottom of the list 1003c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell LinearLayout hintContainer = new LinearLayout(context); 1004c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell hintContainer.setOrientation(LinearLayout.VERTICAL); 1005c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 1006c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell LinearLayout.LayoutParams hintParams = new LinearLayout.LayoutParams( 1007c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell ViewGroup.LayoutParams.MATCH_PARENT, 0, 1.0f 1008c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell ); 1009c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 1010c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell switch (mPromptPosition) { 1011c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell case POSITION_PROMPT_BELOW: 1012c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell hintContainer.addView(dropDownView, hintParams); 1013c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell hintContainer.addView(hintView); 1014c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell break; 1015c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 1016c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell case POSITION_PROMPT_ABOVE: 1017c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell hintContainer.addView(hintView); 1018c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell hintContainer.addView(dropDownView, hintParams); 1019c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell break; 1020c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 1021c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell default: 1022c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell Log.e(TAG, "Invalid hint position " + mPromptPosition); 1023c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell break; 1024c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 1025c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 1026c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell // measure the hint's height to find how much more vertical space 1027c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell // we need to add to the drop down's height 1028c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell int widthSpec = MeasureSpec.makeMeasureSpec(mDropDownWidth, MeasureSpec.AT_MOST); 1029c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell int heightSpec = MeasureSpec.UNSPECIFIED; 1030c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell hintView.measure(widthSpec, heightSpec); 1031c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 1032c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell hintParams = (LinearLayout.LayoutParams) hintView.getLayoutParams(); 1033c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell otherHeights = hintView.getMeasuredHeight() + hintParams.topMargin 1034c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell + hintParams.bottomMargin; 1035c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 1036c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell dropDownView = hintContainer; 1037c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 1038c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 1039c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell mPopup.setContentView(dropDownView); 1040c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } else { 1041c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell dropDownView = (ViewGroup) mPopup.getContentView(); 1042c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell final View view = mPromptView; 1043c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell if (view != null) { 1044c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell LinearLayout.LayoutParams hintParams = 1045c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell (LinearLayout.LayoutParams) view.getLayoutParams(); 1046c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell otherHeights = view.getMeasuredHeight() + hintParams.topMargin 1047c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell + hintParams.bottomMargin; 1048c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 1049c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 1050c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 1051c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell // Max height available on the screen for a popup. 1052c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell boolean ignoreBottomDecorations = 1053c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell mPopup.getInputMethodMode() == PopupWindow.INPUT_METHOD_NOT_NEEDED; 1054c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell final int maxHeight = mPopup.getMaxAvailableHeight( 1055c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell getAnchorView(), mDropDownVerticalOffset, ignoreBottomDecorations); 1056c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 1057c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell // getMaxAvailableHeight() subtracts the padding, so we put it back, 1058c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell // to get the available height for the whole window 1059c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell int padding = 0; 1060c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell Drawable background = mPopup.getBackground(); 1061c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell if (background != null) { 1062c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell background.getPadding(mTempRect); 1063c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell padding = mTempRect.top + mTempRect.bottom; 1064c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 1065c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 1066c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell if (mDropDownAlwaysVisible || mDropDownHeight == ViewGroup.LayoutParams.MATCH_PARENT) { 1067c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell return maxHeight + padding; 1068c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 1069c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 1070c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell final int listContent = mDropDownList.measureHeightOfChildren(MeasureSpec.UNSPECIFIED, 1071c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 0, ListView.NO_POSITION, maxHeight - otherHeights, 2); 1072c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell // add padding only if the list has items in it, that way we don't show 1073c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell // the popup if it is not needed 1074c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell if (listContent > 0) otherHeights += padding; 1075c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 1076c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell return listContent + otherHeights; 1077c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 1078c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 1079c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell /** 1080c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * <p>Wrapper class for a ListView. This wrapper can hijack the focus to 1081c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * make sure the list uses the appropriate drawables and states when 1082c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * displayed on screen within a drop down. The focus is never actually 1083c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * passed to the drop down in this mode; the list only looks focused.</p> 1084c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell */ 1085c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell private static class DropDownListView extends ListView { 1086c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell private static final String TAG = ListPopupWindow.TAG + ".DropDownListView"; 1087c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell /* 1088c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * WARNING: This is a workaround for a touch mode issue. 1089c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * 1090c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * Touch mode is propagated lazily to windows. This causes problems in 1091c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * the following scenario: 1092c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * - Type something in the AutoCompleteTextView and get some results 1093c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * - Move down with the d-pad to select an item in the list 1094c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * - Move up with the d-pad until the selection disappears 1095c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * - Type more text in the AutoCompleteTextView *using the soft keyboard* 1096c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * and get new results; you are now in touch mode 1097c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * - The selection comes back on the first item in the list, even though 1098c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * the list is supposed to be in touch mode 1099c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * 1100c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * Using the soft keyboard triggers the touch mode change but that change 1101c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * is propagated to our window only after the first list layout, therefore 1102c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * after the list attempts to resurrect the selection. 1103c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * 1104c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * The trick to work around this issue is to pretend the list is in touch 1105c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * mode when we know that the selection should not appear, that is when 1106c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * we know the user moved the selection away from the list. 1107c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * 1108c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * This boolean is set to true whenever we explicitly hide the list's 1109c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * selection and reset to false whenever we know the user moved the 1110c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * selection back to the list. 1111c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * 1112c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * When this boolean is true, isInTouchMode() returns true, otherwise it 1113c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * returns super.isInTouchMode(). 1114c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell */ 1115c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell private boolean mListSelectionHidden; 1116c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 1117c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell /** 1118c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * True if this wrapper should fake focus. 1119c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell */ 1120c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell private boolean mHijackFocus; 1121c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 1122c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell /** 1123c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * <p>Creates a new list view wrapper.</p> 1124c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * 1125c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @param context this view's context 1126c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell */ 1127c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell public DropDownListView(Context context, boolean hijackFocus) { 1128c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell super(context, null, com.android.internal.R.attr.dropDownListViewStyle); 1129c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell mHijackFocus = hijackFocus; 1130b1818e83f4a81bc4e4e30b99bb48830415be731bAmith Yamasani // TODO: Add an API to control this 1131b1818e83f4a81bc4e4e30b99bb48830415be731bAmith Yamasani setCacheColorHint(0); // Transparent, since the background drawable could be anything. 1132c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 1133c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 1134c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell /** 1135c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * <p>Avoids jarring scrolling effect by ensuring that list elements 1136c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * made of a text view fit on a single line.</p> 1137c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * 1138c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @param position the item index in the list to get a view for 1139c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @return the view for the specified item 1140c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell */ 1141c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell @Override 1142c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell View obtainView(int position, boolean[] isScrap) { 1143c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell View view = super.obtainView(position, isScrap); 1144c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 1145c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell if (view instanceof TextView) { 1146c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell ((TextView) view).setHorizontallyScrolling(true); 1147c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 1148c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 1149c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell return view; 1150c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 1151c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 1152c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell @Override 1153c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell public boolean isInTouchMode() { 1154c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell // WARNING: Please read the comment where mListSelectionHidden is declared 1155c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell return (mHijackFocus && mListSelectionHidden) || super.isInTouchMode(); 1156c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 1157c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 1158c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell /** 1159c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * <p>Returns the focus state in the drop down.</p> 1160c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * 1161c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @return true always if hijacking focus 1162c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell */ 1163c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell @Override 1164c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell public boolean hasWindowFocus() { 1165c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell return mHijackFocus || super.hasWindowFocus(); 1166c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 1167c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 1168c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell /** 1169c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * <p>Returns the focus state in the drop down.</p> 1170c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * 1171c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @return true always if hijacking focus 1172c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell */ 1173c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell @Override 1174c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell public boolean isFocused() { 1175c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell return mHijackFocus || super.isFocused(); 1176c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 1177c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 1178c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell /** 1179c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * <p>Returns the focus state in the drop down.</p> 1180c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * 1181c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell * @return true always if hijacking focus 1182c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell */ 1183c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell @Override 1184c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell public boolean hasFocus() { 1185c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell return mHijackFocus || super.hasFocus(); 1186c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 1187c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 1188c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 1189c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell private class PopupDataSetObserver extends DataSetObserver { 1190c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell @Override 1191c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell public void onChanged() { 1192c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell if (isShowing()) { 1193c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell // Resize the popup to fit new content 1194c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell show(); 1195c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 1196c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 1197c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 1198c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell @Override 1199c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell public void onInvalidated() { 1200c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell dismiss(); 1201c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 1202c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 1203c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 1204c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell private class ListSelectorHider implements Runnable { 1205c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell public void run() { 1206c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell clearListSelection(); 1207c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 1208c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 1209c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 1210c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell private class ResizePopupRunnable implements Runnable { 1211c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell public void run() { 1212c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell mPopup.setInputMethodMode(PopupWindow.INPUT_METHOD_NOT_NEEDED); 1213c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell show(); 1214c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 1215c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 1216c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 1217c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell private class PopupTouchInterceptor implements OnTouchListener { 1218c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell public boolean onTouch(View v, MotionEvent event) { 1219c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell final int action = event.getAction(); 1220c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell final int x = (int) event.getX(); 1221c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell final int y = (int) event.getY(); 1222c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 1223c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell if (action == MotionEvent.ACTION_DOWN && 1224c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell mPopup != null && mPopup.isShowing() && 1225711734a2f8d7529df0ed1bce36da651fc835c144Gilles Debunne (x >= 0 && x < mPopup.getWidth() && y >= 0 && y < mPopup.getHeight())) { 1226c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell mHandler.postDelayed(mResizePopupRunnable, EXPAND_LIST_TIMEOUT); 1227c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } else if (action == MotionEvent.ACTION_UP) { 1228c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell mHandler.removeCallbacks(mResizePopupRunnable); 1229c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 1230c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell return false; 1231c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 1232c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 1233c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 1234c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell private class PopupScrollListener implements ListView.OnScrollListener { 1235c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, 1236c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell int totalItemCount) { 1237c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 1238c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 1239c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell 1240c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell public void onScrollStateChanged(AbsListView view, int scrollState) { 1241c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell if (scrollState == SCROLL_STATE_TOUCH_SCROLL && 1242c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell !isInputMethodNotNeeded() && mPopup.getContentView() != null) { 1243c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell mHandler.removeCallbacks(mResizePopupRunnable); 1244c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell mResizePopupRunnable.run(); 1245c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 1246c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 1247c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell } 1248c3fa6304c997ccecf8ed15a4cbb7bd245128f3c3Adam Powell} 1249