Added ListPopupWindow. Refactored AutoCompleteTextView and Spinner
(optionally) to use it. Added associated styles. ListPopupWindow allows apps to present a popup window of options to the user that will correctly dodge the IME if needed. Change-Id: I509c6c45036856daab686a6edeb7a9de1e72eb0a
This commit is contained in:
708
api/current.xml
708
api/current.xml
@@ -16883,6 +16883,17 @@
|
||||
visibility="public"
|
||||
>
|
||||
</field>
|
||||
<field name="Widget_Spinner_DropDown"
|
||||
type="int"
|
||||
transient="false"
|
||||
volatile="false"
|
||||
value="16973970"
|
||||
static="true"
|
||||
final="true"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</field>
|
||||
<field name="Widget_TabWidget"
|
||||
type="int"
|
||||
transient="false"
|
||||
@@ -211630,6 +211641,665 @@
|
||||
</parameter>
|
||||
</method>
|
||||
</interface>
|
||||
<class name="ListPopupWindow"
|
||||
extends="java.lang.Object"
|
||||
abstract="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
<constructor name="ListPopupWindow"
|
||||
type="android.widget.ListPopupWindow"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
<parameter name="context" type="android.content.Context">
|
||||
</parameter>
|
||||
</constructor>
|
||||
<constructor name="ListPopupWindow"
|
||||
type="android.widget.ListPopupWindow"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
<parameter name="context" type="android.content.Context">
|
||||
</parameter>
|
||||
<parameter name="attrs" type="android.util.AttributeSet">
|
||||
</parameter>
|
||||
</constructor>
|
||||
<constructor name="ListPopupWindow"
|
||||
type="android.widget.ListPopupWindow"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
<parameter name="context" type="android.content.Context">
|
||||
</parameter>
|
||||
<parameter name="attrs" type="android.util.AttributeSet">
|
||||
</parameter>
|
||||
<parameter name="defStyleAttr" type="int">
|
||||
</parameter>
|
||||
</constructor>
|
||||
<constructor name="ListPopupWindow"
|
||||
type="android.widget.ListPopupWindow"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
<parameter name="context" type="android.content.Context">
|
||||
</parameter>
|
||||
<parameter name="attrs" type="android.util.AttributeSet">
|
||||
</parameter>
|
||||
<parameter name="defStyleAttr" type="int">
|
||||
</parameter>
|
||||
<parameter name="defStyleRes" type="int">
|
||||
</parameter>
|
||||
</constructor>
|
||||
<method name="clearListSelection"
|
||||
return="void"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</method>
|
||||
<method name="dismiss"
|
||||
return="void"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</method>
|
||||
<method name="getAnchorView"
|
||||
return="android.view.View"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</method>
|
||||
<method name="getAnimationStyle"
|
||||
return="int"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</method>
|
||||
<method name="getBackground"
|
||||
return="android.graphics.drawable.Drawable"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</method>
|
||||
<method name="getHeight"
|
||||
return="int"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</method>
|
||||
<method name="getHorizontalOffset"
|
||||
return="int"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</method>
|
||||
<method name="getInputMethodMode"
|
||||
return="int"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</method>
|
||||
<method name="getListView"
|
||||
return="android.widget.ListView"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</method>
|
||||
<method name="getPromptPosition"
|
||||
return="int"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</method>
|
||||
<method name="getSelectedItem"
|
||||
return="java.lang.Object"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</method>
|
||||
<method name="getSelectedItemId"
|
||||
return="long"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</method>
|
||||
<method name="getSelectedItemPosition"
|
||||
return="int"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</method>
|
||||
<method name="getSelectedView"
|
||||
return="android.view.View"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</method>
|
||||
<method name="getSoftInputMode"
|
||||
return="int"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</method>
|
||||
<method name="getVerticalOffset"
|
||||
return="int"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</method>
|
||||
<method name="getWidth"
|
||||
return="int"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</method>
|
||||
<method name="isInputMethodNotNeeded"
|
||||
return="boolean"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</method>
|
||||
<method name="isModal"
|
||||
return="boolean"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</method>
|
||||
<method name="isShowing"
|
||||
return="boolean"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</method>
|
||||
<method name="onKeyDown"
|
||||
return="boolean"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
<parameter name="keyCode" type="int">
|
||||
</parameter>
|
||||
<parameter name="event" type="android.view.KeyEvent">
|
||||
</parameter>
|
||||
</method>
|
||||
<method name="onKeyPreIme"
|
||||
return="boolean"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
<parameter name="keyCode" type="int">
|
||||
</parameter>
|
||||
<parameter name="event" type="android.view.KeyEvent">
|
||||
</parameter>
|
||||
</method>
|
||||
<method name="onKeyUp"
|
||||
return="boolean"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
<parameter name="keyCode" type="int">
|
||||
</parameter>
|
||||
<parameter name="event" type="android.view.KeyEvent">
|
||||
</parameter>
|
||||
</method>
|
||||
<method name="performItemClick"
|
||||
return="boolean"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
<parameter name="position" type="int">
|
||||
</parameter>
|
||||
</method>
|
||||
<method name="postShow"
|
||||
return="void"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</method>
|
||||
<method name="setAdapter"
|
||||
return="void"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
<parameter name="adapter" type="android.widget.ListAdapter">
|
||||
</parameter>
|
||||
</method>
|
||||
<method name="setAnchorView"
|
||||
return="void"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
<parameter name="anchor" type="android.view.View">
|
||||
</parameter>
|
||||
</method>
|
||||
<method name="setAnimationStyle"
|
||||
return="void"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
<parameter name="animationStyle" type="int">
|
||||
</parameter>
|
||||
</method>
|
||||
<method name="setBackgroundDrawable"
|
||||
return="void"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
<parameter name="d" type="android.graphics.drawable.Drawable">
|
||||
</parameter>
|
||||
</method>
|
||||
<method name="setHeight"
|
||||
return="void"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
<parameter name="height" type="int">
|
||||
</parameter>
|
||||
</method>
|
||||
<method name="setHorizontalOffset"
|
||||
return="void"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
<parameter name="offset" type="int">
|
||||
</parameter>
|
||||
</method>
|
||||
<method name="setInputMethodMode"
|
||||
return="void"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
<parameter name="mode" type="int">
|
||||
</parameter>
|
||||
</method>
|
||||
<method name="setListSelector"
|
||||
return="void"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
<parameter name="selector" type="android.graphics.drawable.Drawable">
|
||||
</parameter>
|
||||
</method>
|
||||
<method name="setModal"
|
||||
return="void"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
<parameter name="modal" type="boolean">
|
||||
</parameter>
|
||||
</method>
|
||||
<method name="setOnItemClickListener"
|
||||
return="void"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
<parameter name="clickListener" type="android.widget.AdapterView.OnItemClickListener">
|
||||
</parameter>
|
||||
</method>
|
||||
<method name="setOnItemSelectedListener"
|
||||
return="void"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
<parameter name="selectedListener" type="android.widget.AdapterView.OnItemSelectedListener">
|
||||
</parameter>
|
||||
</method>
|
||||
<method name="setPromptPosition"
|
||||
return="void"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
<parameter name="position" type="int">
|
||||
</parameter>
|
||||
</method>
|
||||
<method name="setPromptView"
|
||||
return="void"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
<parameter name="prompt" type="android.view.View">
|
||||
</parameter>
|
||||
</method>
|
||||
<method name="setSelection"
|
||||
return="void"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
<parameter name="position" type="int">
|
||||
</parameter>
|
||||
</method>
|
||||
<method name="setSoftInputMode"
|
||||
return="void"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
<parameter name="mode" type="int">
|
||||
</parameter>
|
||||
</method>
|
||||
<method name="setVerticalOffset"
|
||||
return="void"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
<parameter name="offset" type="int">
|
||||
</parameter>
|
||||
</method>
|
||||
<method name="setWidth"
|
||||
return="void"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
<parameter name="width" type="int">
|
||||
</parameter>
|
||||
</method>
|
||||
<method name="show"
|
||||
return="void"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</method>
|
||||
<field name="INPUT_METHOD_FROM_FOCUSABLE"
|
||||
type="int"
|
||||
transient="false"
|
||||
volatile="false"
|
||||
value="0"
|
||||
static="true"
|
||||
final="true"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</field>
|
||||
<field name="INPUT_METHOD_NEEDED"
|
||||
type="int"
|
||||
transient="false"
|
||||
volatile="false"
|
||||
value="1"
|
||||
static="true"
|
||||
final="true"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</field>
|
||||
<field name="INPUT_METHOD_NOT_NEEDED"
|
||||
type="int"
|
||||
transient="false"
|
||||
volatile="false"
|
||||
value="2"
|
||||
static="true"
|
||||
final="true"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</field>
|
||||
<field name="MATCH_PARENT"
|
||||
type="int"
|
||||
transient="false"
|
||||
volatile="false"
|
||||
value="-1"
|
||||
static="true"
|
||||
final="true"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</field>
|
||||
<field name="POSITION_PROMPT_ABOVE"
|
||||
type="int"
|
||||
transient="false"
|
||||
volatile="false"
|
||||
value="0"
|
||||
static="true"
|
||||
final="true"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</field>
|
||||
<field name="POSITION_PROMPT_BELOW"
|
||||
type="int"
|
||||
transient="false"
|
||||
volatile="false"
|
||||
value="1"
|
||||
static="true"
|
||||
final="true"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</field>
|
||||
<field name="WRAP_CONTENT"
|
||||
type="int"
|
||||
transient="false"
|
||||
volatile="false"
|
||||
value="-2"
|
||||
static="true"
|
||||
final="true"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</field>
|
||||
</class>
|
||||
<class name="ListView"
|
||||
extends="android.widget.AbsListView"
|
||||
abstract="false"
|
||||
@@ -212670,6 +213340,22 @@
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
<parameter name="context" type="android.content.Context">
|
||||
</parameter>
|
||||
<parameter name="attrs" type="android.util.AttributeSet">
|
||||
</parameter>
|
||||
<parameter name="defStyleAttr" type="int">
|
||||
</parameter>
|
||||
<parameter name="defStyleRes" type="int">
|
||||
</parameter>
|
||||
</constructor>
|
||||
<constructor name="PopupWindow"
|
||||
type="android.widget.PopupWindow"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</constructor>
|
||||
<constructor name="PopupWindow"
|
||||
type="android.widget.PopupWindow"
|
||||
@@ -217256,6 +217942,28 @@
|
||||
<parameter name="promptId" type="int">
|
||||
</parameter>
|
||||
</method>
|
||||
<field name="MODE_DIALOG"
|
||||
type="int"
|
||||
transient="false"
|
||||
volatile="false"
|
||||
value="0"
|
||||
static="true"
|
||||
final="true"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</field>
|
||||
<field name="MODE_DROPDOWN"
|
||||
type="int"
|
||||
transient="false"
|
||||
volatile="false"
|
||||
value="1"
|
||||
static="true"
|
||||
final="true"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</field>
|
||||
</class>
|
||||
<interface name="SpinnerAdapter"
|
||||
abstract="true"
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
1215
core/java/android/widget/ListPopupWindow.java
Normal file
1215
core/java/android/widget/ListPopupWindow.java
Normal file
File diff suppressed because it is too large
Load Diff
@@ -16,27 +16,28 @@
|
||||
|
||||
package android.widget;
|
||||
|
||||
import com.android.internal.R;
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.view.Gravity;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewTreeObserver;
|
||||
import android.view.ViewTreeObserver.OnScrollChangedListener;
|
||||
import android.view.View.OnTouchListener;
|
||||
import android.graphics.PixelFormat;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.StateListDrawable;
|
||||
import android.os.IBinder;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewTreeObserver;
|
||||
import android.view.WindowManager;
|
||||
import android.view.View.OnTouchListener;
|
||||
import android.view.ViewTreeObserver.OnScrollChangedListener;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import com.android.internal.R;
|
||||
|
||||
/**
|
||||
* <p>A popup window that can be used to display an arbitrary view. The popup
|
||||
@@ -157,12 +158,21 @@ public class PopupWindow {
|
||||
* <p>The popup does provide a background.</p>
|
||||
*/
|
||||
public PopupWindow(Context context, AttributeSet attrs, int defStyle) {
|
||||
this(context, attrs, defStyle, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Create a new, empty, non focusable popup window of dimension (0,0).</p>
|
||||
*
|
||||
* <p>The popup does not provide a background.</p>
|
||||
*/
|
||||
public PopupWindow(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
mContext = context;
|
||||
mWindowManager = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
|
||||
|
||||
TypedArray a =
|
||||
context.obtainStyledAttributes(
|
||||
attrs, com.android.internal.R.styleable.PopupWindow, defStyle, 0);
|
||||
attrs, com.android.internal.R.styleable.PopupWindow, defStyleAttr, defStyleRes);
|
||||
|
||||
mBackground = a.getDrawable(R.styleable.PopupWindow_popupBackground);
|
||||
|
||||
@@ -1315,6 +1325,7 @@ public class PopupWindow {
|
||||
}
|
||||
|
||||
private class PopupViewContainer extends FrameLayout {
|
||||
private static final String TAG = "PopupWindow.PopupViewContainer";
|
||||
|
||||
public PopupViewContainer(Context context) {
|
||||
super(context);
|
||||
|
||||
@@ -24,6 +24,7 @@ import android.content.DialogInterface.OnClickListener;
|
||||
import android.content.res.TypedArray;
|
||||
import android.database.DataSetObserver;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
@@ -37,10 +38,20 @@ import android.view.ViewGroup;
|
||||
*/
|
||||
@Widget
|
||||
public class Spinner extends AbsSpinner implements OnClickListener {
|
||||
private static final String TAG = "Spinner";
|
||||
|
||||
/**
|
||||
* Use a dialog window for selecting spinner options.
|
||||
*/
|
||||
public static final int MODE_DIALOG = 0;
|
||||
|
||||
/**
|
||||
* Use a dropdown anchored to the Spinner for selecting spinner options.
|
||||
*/
|
||||
public static final int MODE_DROPDOWN = 1;
|
||||
|
||||
private SpinnerPopup mPopup;
|
||||
|
||||
private CharSequence mPrompt;
|
||||
private AlertDialog mPopup;
|
||||
|
||||
public Spinner(Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
@@ -55,10 +66,43 @@ public class Spinner extends AbsSpinner implements OnClickListener {
|
||||
TypedArray a = context.obtainStyledAttributes(attrs,
|
||||
com.android.internal.R.styleable.Spinner, defStyle, 0);
|
||||
|
||||
mPrompt = a.getString(com.android.internal.R.styleable.Spinner_prompt);
|
||||
final int mode = a.getInt(com.android.internal.R.styleable.Spinner_spinnerMode,
|
||||
MODE_DIALOG);
|
||||
|
||||
switch (mode) {
|
||||
case MODE_DIALOG: {
|
||||
mPopup = new DialogPopup();
|
||||
break;
|
||||
}
|
||||
|
||||
case MODE_DROPDOWN: {
|
||||
final int hintResource = a.getResourceId(
|
||||
com.android.internal.R.styleable.Spinner_popupPromptView, 0);
|
||||
|
||||
DropdownPopup popup = new DropdownPopup(context, attrs, defStyle, hintResource);
|
||||
|
||||
popup.setBackgroundDrawable(a.getDrawable(
|
||||
com.android.internal.R.styleable.Spinner_popupBackground));
|
||||
popup.setVerticalOffset(a.getDimensionPixelOffset(
|
||||
com.android.internal.R.styleable.Spinner_dropDownVerticalOffset, 0));
|
||||
popup.setHorizontalOffset(a.getDimensionPixelOffset(
|
||||
com.android.internal.R.styleable.Spinner_dropDownHorizontalOffset, 0));
|
||||
|
||||
mPopup = popup;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
mPopup.setPromptText(a.getString(com.android.internal.R.styleable.Spinner_prompt));
|
||||
|
||||
a.recycle();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAdapter(SpinnerAdapter adapter) {
|
||||
super.setAdapter(adapter);
|
||||
mPopup.setAdapter(new DropDownAdapter(adapter));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBaseline() {
|
||||
@@ -246,15 +290,10 @@ public class Spinner extends AbsSpinner implements OnClickListener {
|
||||
|
||||
if (!handled) {
|
||||
handled = true;
|
||||
Context context = getContext();
|
||||
|
||||
final DropDownAdapter adapter = new DropDownAdapter(getAdapter());
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||
if (mPrompt != null) {
|
||||
builder.setTitle(mPrompt);
|
||||
if (!mPopup.isShowing()) {
|
||||
mPopup.show();
|
||||
}
|
||||
mPopup = builder.setSingleChoiceItems(adapter, getSelectedItemPosition(), this).show();
|
||||
}
|
||||
|
||||
return handled;
|
||||
@@ -271,7 +310,7 @@ public class Spinner extends AbsSpinner implements OnClickListener {
|
||||
* @param prompt the prompt to set
|
||||
*/
|
||||
public void setPrompt(CharSequence prompt) {
|
||||
mPrompt = prompt;
|
||||
mPopup.setPromptText(prompt);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -279,16 +318,42 @@ public class Spinner extends AbsSpinner implements OnClickListener {
|
||||
* @param promptId the resource ID of the prompt to display when the dialog is shown
|
||||
*/
|
||||
public void setPromptId(int promptId) {
|
||||
mPrompt = getContext().getText(promptId);
|
||||
setPrompt(getContext().getText(promptId));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The prompt to display when the dialog is shown
|
||||
*/
|
||||
public CharSequence getPrompt() {
|
||||
return mPrompt;
|
||||
return mPopup.getHintText();
|
||||
}
|
||||
|
||||
/*
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
if (mPopup.onKeyDown(keyCode, event)) {
|
||||
return true;
|
||||
}
|
||||
return super.onKeyDown(keyCode, event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKeyUp(int keyCode, KeyEvent event) {
|
||||
if (mPopup.onKeyUp(keyCode, event)) {
|
||||
return true;
|
||||
}
|
||||
return super.onKeyUp(keyCode, event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKeyPreIme(int keyCode, KeyEvent event) {
|
||||
if (mPopup.onKeyPreIme(keyCode, event)) {
|
||||
return true;
|
||||
}
|
||||
return super.onKeyPreIme(keyCode, event);
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* <p>Wrapper class for an Adapter. Transforms the embedded Adapter instance
|
||||
* into a ListAdapter.</p>
|
||||
@@ -384,4 +449,123 @@ public class Spinner extends AbsSpinner implements OnClickListener {
|
||||
return getCount() == 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements some sort of popup selection interface for selecting a spinner option.
|
||||
* Allows for different spinner modes.
|
||||
*/
|
||||
private interface SpinnerPopup {
|
||||
public void setAdapter(ListAdapter adapter);
|
||||
|
||||
/**
|
||||
* Show the popup
|
||||
*/
|
||||
public void show();
|
||||
|
||||
/**
|
||||
* Dismiss the popup
|
||||
*/
|
||||
public void dismiss();
|
||||
|
||||
/**
|
||||
* @return true if the popup is showing, false otherwise.
|
||||
*/
|
||||
public boolean isShowing();
|
||||
|
||||
/**
|
||||
* Set hint text to be displayed to the user. This should provide
|
||||
* a description of the choice being made.
|
||||
* @param hintText Hint text to set.
|
||||
*/
|
||||
public void setPromptText(CharSequence hintText);
|
||||
public CharSequence getHintText();
|
||||
}
|
||||
|
||||
private class DialogPopup implements SpinnerPopup, DialogInterface.OnClickListener {
|
||||
private AlertDialog mPopup;
|
||||
private ListAdapter mListAdapter;
|
||||
private CharSequence mPrompt;
|
||||
|
||||
public void dismiss() {
|
||||
mPopup.dismiss();
|
||||
mPopup = null;
|
||||
}
|
||||
|
||||
public boolean isShowing() {
|
||||
return mPopup != null ? mPopup.isShowing() : false;
|
||||
}
|
||||
|
||||
public void setAdapter(ListAdapter adapter) {
|
||||
mListAdapter = adapter;
|
||||
}
|
||||
|
||||
public void setPromptText(CharSequence hintText) {
|
||||
mPrompt = hintText;
|
||||
}
|
||||
|
||||
public CharSequence getHintText() {
|
||||
return mPrompt;
|
||||
}
|
||||
|
||||
public void show() {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
|
||||
if (mPrompt != null) {
|
||||
builder.setTitle(mPrompt);
|
||||
}
|
||||
mPopup = builder.setSingleChoiceItems(mListAdapter,
|
||||
getSelectedItemPosition(), this).show();
|
||||
}
|
||||
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
setSelection(which);
|
||||
dismiss();
|
||||
}
|
||||
}
|
||||
|
||||
private class DropdownPopup extends ListPopupWindow implements SpinnerPopup {
|
||||
private CharSequence mHintText;
|
||||
private TextView mHintView;
|
||||
private int mHintResource;
|
||||
|
||||
public DropdownPopup(Context context, AttributeSet attrs,
|
||||
int defStyleRes, int hintResource) {
|
||||
super(context, attrs, 0, defStyleRes);
|
||||
|
||||
mHintResource = hintResource;
|
||||
|
||||
setAnchorView(Spinner.this);
|
||||
setModal(true);
|
||||
setPromptPosition(POSITION_PROMPT_BELOW);
|
||||
setOnItemClickListener(new OnItemClickListener() {
|
||||
public void onItemClick(AdapterView parent, View v, int position, long id) {
|
||||
Spinner.this.setSelection(position);
|
||||
dismiss();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public CharSequence getHintText() {
|
||||
return mHintText;
|
||||
}
|
||||
|
||||
public void setPromptText(CharSequence hintText) {
|
||||
mHintText = hintText;
|
||||
if (mHintView != null) {
|
||||
mHintView.setText(hintText);
|
||||
}
|
||||
}
|
||||
|
||||
public void show() {
|
||||
if (mHintView == null) {
|
||||
final TextView textView = (TextView) LayoutInflater.from(getContext()).inflate(
|
||||
mHintResource, null).findViewById(com.android.internal.R.id.text1);
|
||||
textView.setText(mHintText);
|
||||
setPromptView(textView);
|
||||
mHintView = textView;
|
||||
}
|
||||
super.show();
|
||||
getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
|
||||
setSelection(Spinner.this.getSelectedItemPosition());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2207,6 +2207,30 @@
|
||||
<declare-styleable name="Spinner">
|
||||
<!-- The prompt to display when the spinner's dialog is shown. -->
|
||||
<attr name="prompt" format="reference" />
|
||||
<!-- Display mode for spinner options. -->
|
||||
<attr name="spinnerMode" format="enum">
|
||||
<!-- Spinner options will be presented to the user as a dialog window. -->
|
||||
<enum name="dialog" value="0" />
|
||||
<!-- Spinner options will be presented to the user as an inline dropdown
|
||||
anchored to the spinner widget itself. -->
|
||||
<enum name="dropdown" value="1" />
|
||||
</attr>
|
||||
<!-- List selector to use for spinnerMode="dropdown" display. -->
|
||||
<attr name="dropDownSelector" />
|
||||
<!-- Background drawable to use for the dropdown in spinnerMode="dropdown". -->
|
||||
<attr name="popupBackground" />
|
||||
<!-- Vertical offset from the spinner widget for positioning the dropdown in
|
||||
spinnerMode="dropdown". -->
|
||||
<attr name="dropDownVerticalOffset" />
|
||||
<!-- Horizontal offset from the spinner widget for positioning the dropdown
|
||||
in spinnerMode="dropdown". -->
|
||||
<attr name="dropDownHorizontalOffset" />
|
||||
<!-- Width of the dropdown in spinnerMode="dropdown". -->
|
||||
<attr name="dropDownWidth" />
|
||||
<!-- Reference to a layout to use for displaying a prompt in the dropdown for
|
||||
spinnerMode="dropdown". This layout must contain a TextView with the id
|
||||
@android:id/text1 to be populated with the prompt text. -->
|
||||
<attr name="popupPromptView" format="reference" />
|
||||
</declare-styleable>
|
||||
<declare-styleable name="DatePicker">
|
||||
<!-- The first year (inclusive), for example "1940". -->
|
||||
|
||||
@@ -1286,5 +1286,6 @@
|
||||
<public type="id" name="home" />
|
||||
|
||||
<public type="style" name="Theme.WithActionBar" />
|
||||
<public type="style" name="Widget.Spinner.DropDown" />
|
||||
|
||||
</resources>
|
||||
|
||||
@@ -451,6 +451,18 @@
|
||||
<style name="Widget.Spinner">
|
||||
<item name="android:background">@android:drawable/btn_dropdown</item>
|
||||
<item name="android:clickable">true</item>
|
||||
<item name="android:spinnerMode">dialog</item>
|
||||
|
||||
<item name="android:dropDownSelector">@android:drawable/list_selector_background</item>
|
||||
<item name="android:popupBackground">@android:drawable/spinner_dropdown_background</item>
|
||||
<item name="android:dropDownVerticalOffset">-10dip</item>
|
||||
<item name="android:dropDownHorizontalOffset">0dip</item>
|
||||
<item name="android:dropDownWidth">wrap_content</item>
|
||||
<item name="android:popupPromptView">@android:layout/simple_dropdown_hint</item>
|
||||
</style>
|
||||
|
||||
<style name="Widget.Spinner.DropDown">
|
||||
<item name="android:spinnerMode">dropdown</item>
|
||||
</style>
|
||||
|
||||
<style name="Widget.TextView.PopupMenu">
|
||||
|
||||
@@ -563,8 +563,6 @@ android.widget.AbsoluteLayout
|
||||
android.widget.AdapterView
|
||||
android.widget.ArrayAdapter
|
||||
android.widget.AutoCompleteTextView
|
||||
android.widget.AutoCompleteTextView$DropDownItemClickListener
|
||||
android.widget.AutoCompleteTextView$DropDownListView
|
||||
android.widget.BaseAdapter
|
||||
android.widget.BaseExpandableListAdapter
|
||||
android.widget.CheckBox
|
||||
@@ -582,6 +580,7 @@ android.widget.HeaderViewListAdapter
|
||||
android.widget.ImageView
|
||||
android.widget.ImageView$ScaleType
|
||||
android.widget.LinearLayout
|
||||
android.widget.ListPopupWindow
|
||||
android.widget.ListView
|
||||
android.widget.ListView$SavedState
|
||||
android.widget.MediaController
|
||||
|
||||
Reference in New Issue
Block a user