Merge "Fix bug 2957414 - Add Spinner constructor for selecting dialog/dropdown mode"
diff --git a/api/current.xml b/api/current.xml
index 47310e7..81997fc 100644
--- a/api/current.xml
+++ b/api/current.xml
@@ -232363,6 +232363,18 @@
>
<parameter name="context" type="android.content.Context">
</parameter>
+<parameter name="mode" type="int">
+</parameter>
+</constructor>
+<constructor name="Spinner"
+ type="android.widget.Spinner"
+ 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>
@@ -232380,6 +232392,22 @@
<parameter name="defStyle" type="int">
</parameter>
</constructor>
+<constructor name="Spinner"
+ type="android.widget.Spinner"
+ 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="defStyle" type="int">
+</parameter>
+<parameter name="mode" type="int">
+</parameter>
+</constructor>
<method name="getPrompt"
return="java.lang.CharSequence"
abstract="false"
diff --git a/core/java/android/widget/Spinner.java b/core/java/android/widget/Spinner.java
index 58c2613..c0cbb19 100644
--- a/core/java/android/widget/Spinner.java
+++ b/core/java/android/widget/Spinner.java
@@ -53,25 +53,93 @@
*/
public static final int MODE_DROPDOWN = 1;
+ /**
+ * Use the theme-supplied value to select the dropdown mode.
+ */
+ private static final int MODE_THEME = -1;
+
private SpinnerPopup mPopup;
private DropDownAdapter mTempAdapter;
-
+
+ /**
+ * Construct a new spinner with the given context's theme.
+ *
+ * @param context The Context the view is running in, through which it can
+ * access the current theme, resources, etc.
+ */
public Spinner(Context context) {
this(context, null);
}
+ /**
+ * Construct a new spinner with the given context's theme and the supplied
+ * mode of displaying choices. <code>mode</code> may be one of
+ * {@link #MODE_DIALOG} or {@link #MODE_DROPDOWN}.
+ *
+ * @param context The Context the view is running in, through which it can
+ * access the current theme, resources, etc.
+ * @param mode Constant describing how the user will select choices from the spinner.
+ *
+ * @see #MODE_DIALOG
+ * @see #MODE_DROPDOWN
+ */
+ public Spinner(Context context, int mode) {
+ this(context, null, com.android.internal.R.attr.spinnerStyle, mode);
+ }
+
+ /**
+ * Construct a new spinner with the given context's theme and the supplied attribute set.
+ *
+ * @param context The Context the view is running in, through which it can
+ * access the current theme, resources, etc.
+ * @param attrs The attributes of the XML tag that is inflating the view.
+ */
public Spinner(Context context, AttributeSet attrs) {
this(context, attrs, com.android.internal.R.attr.spinnerStyle);
}
+ /**
+ * Construct a new spinner with the given context's theme, the supplied attribute set,
+ * and default style.
+ *
+ * @param context The Context the view is running in, through which it can
+ * access the current theme, resources, etc.
+ * @param attrs The attributes of the XML tag that is inflating the view.
+ * @param defStyle The default style to apply to this view. If 0, no style
+ * will be applied (beyond what is included in the theme). This may
+ * either be an attribute resource, whose value will be retrieved
+ * from the current theme, or an explicit style resource.
+ */
public Spinner(Context context, AttributeSet attrs, int defStyle) {
+ this(context, attrs, defStyle, MODE_THEME);
+ }
+
+ /**
+ * Construct a new spinner with the given context's theme, the supplied attribute set,
+ * and default style. <code>mode</code> may be one of {@link #MODE_DIALOG} or
+ * {@link #MODE_DROPDOWN} and determines how the user will select choices from the spinner.
+ *
+ * @param context The Context the view is running in, through which it can
+ * access the current theme, resources, etc.
+ * @param attrs The attributes of the XML tag that is inflating the view.
+ * @param defStyle The default style to apply to this view. If 0, no style
+ * will be applied (beyond what is included in the theme). This may
+ * either be an attribute resource, whose value will be retrieved
+ * from the current theme, or an explicit style resource.
+ * @param mode Constant describing how the user will select choices from the spinner.
+ *
+ * @see #MODE_DIALOG
+ * @see #MODE_DROPDOWN
+ */
+ public Spinner(Context context, AttributeSet attrs, int defStyle, int mode) {
super(context, attrs, defStyle);
TypedArray a = context.obtainStyledAttributes(attrs,
com.android.internal.R.styleable.Spinner, defStyle, 0);
-
- final int mode = a.getInt(com.android.internal.R.styleable.Spinner_spinnerMode,
- MODE_DIALOG);
+
+ if (mode == MODE_THEME) {
+ mode = a.getInt(com.android.internal.R.styleable.Spinner_spinnerMode, MODE_DIALOG);
+ }
switch (mode) {
case MODE_DIALOG: {