Skip to content

Commit 1ce891b

Browse files
adampAndroid (Google) Code Review
authored andcommitted
Merge "Public API for android.widget.Spinner properties"
2 parents 92d291e + d9c7be6 commit 1ce891b

File tree

3 files changed

+207
-0
lines changed

3 files changed

+207
-0
lines changed

api/current.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27495,9 +27495,19 @@ package android.widget {
2749527495
ctor public Spinner(android.content.Context, android.util.AttributeSet);
2749627496
ctor public Spinner(android.content.Context, android.util.AttributeSet, int);
2749727497
ctor public Spinner(android.content.Context, android.util.AttributeSet, int, int);
27498+
method public int getDropDownHorizontalOffset();
27499+
method public int getDropDownVerticalOffset();
27500+
method public int getDropDownWidth();
27501+
method public int getGravity();
27502+
method public android.graphics.drawable.Drawable getPopupBackground();
2749827503
method public java.lang.CharSequence getPrompt();
2749927504
method public void onClick(android.content.DialogInterface, int);
27505+
method public void setDropDownHorizontalOffset(int);
27506+
method public void setDropDownVerticalOffset(int);
27507+
method public void setDropDownWidth(int);
2750027508
method public void setGravity(int);
27509+
method public void setPopupBackgroundDrawable(android.graphics.drawable.Drawable);
27510+
method public void setPopupBackgroundResource(int);
2750127511
method public void setPrompt(java.lang.CharSequence);
2750227512
method public void setPromptId(int);
2750327513
field public static final int MODE_DIALOG = 0; // 0x0
@@ -27534,8 +27544,10 @@ package android.widget {
2753427544
method public void setTextOff(java.lang.CharSequence);
2753527545
method public void setTextOn(java.lang.CharSequence);
2753627546
method public void setThumbDrawable(android.graphics.drawable.Drawable);
27547+
method public void setThumbResource(int);
2753727548
method public void setThumbTextPadding(int);
2753827549
method public void setTrackDrawable(android.graphics.drawable.Drawable);
27550+
method public void setTrackResource(int);
2753927551
}
2754027552

2754127553
public class TabHost extends android.widget.FrameLayout implements android.view.ViewTreeObserver.OnTouchModeChangeListener {

core/java/android/widget/Spinner.java

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import android.graphics.Rect;
2727
import android.graphics.drawable.Drawable;
2828
import android.util.AttributeSet;
29+
import android.util.Log;
2930
import android.view.Gravity;
3031
import android.view.View;
3132
import android.view.ViewGroup;
@@ -202,6 +203,130 @@ public Spinner(Context context, AttributeSet attrs, int defStyle, int mode) {
202203
}
203204
}
204205

206+
/**
207+
* Set the background drawable for the spinner's popup window of choices.
208+
* Only valid in {@link #MODE_DROPDOWN}; this method is a no-op in other modes.
209+
*
210+
* @param background Background drawable
211+
*
212+
* @attr ref android.R.styleable#Spinner_popupBackground
213+
*/
214+
public void setPopupBackgroundDrawable(Drawable background) {
215+
if (!(mPopup instanceof DropdownPopup)) {
216+
Log.e(TAG, "setPopupBackgroundDrawable: incompatible spinner mode; ignoring...");
217+
return;
218+
}
219+
((DropdownPopup) mPopup).setBackgroundDrawable(background);
220+
}
221+
222+
/**
223+
* Set the background drawable for the spinner's popup window of choices.
224+
* Only valid in {@link #MODE_DROPDOWN}; this method is a no-op in other modes.
225+
*
226+
* @param background Resource ID of a background drawable
227+
*
228+
* @attr ref android.R.styleable#Spinner_popupBackground
229+
*/
230+
public void setPopupBackgroundResource(int resId) {
231+
setPopupBackgroundDrawable(getContext().getResources().getDrawable(resId));
232+
}
233+
234+
/**
235+
* Get the background drawable for the spinner's popup window of choices.
236+
* Only valid in {@link #MODE_DROPDOWN}; other modes will return null.
237+
*
238+
* @return background Background drawable
239+
*
240+
* @attr ref android.R.styleable#Spinner_popupBackground
241+
*/
242+
public Drawable getPopupBackground() {
243+
return mPopup.getBackground();
244+
}
245+
246+
/**
247+
* Set a vertical offset in pixels for the spinner's popup window of choices.
248+
* Only valid in {@link #MODE_DROPDOWN}; this method is a no-op in other modes.
249+
*
250+
* @param pixels Vertical offset in pixels
251+
*
252+
* @attr ref android.R.styleable#Spinner_dropDownVerticalOffset
253+
*/
254+
public void setDropDownVerticalOffset(int pixels) {
255+
mPopup.setVerticalOffset(pixels);
256+
}
257+
258+
/**
259+
* Get the configured vertical offset in pixels for the spinner's popup window of choices.
260+
* Only valid in {@link #MODE_DROPDOWN}; other modes will return 0.
261+
*
262+
* @return Vertical offset in pixels
263+
*
264+
* @attr ref android.R.styleable#Spinner_dropDownVerticalOffset
265+
*/
266+
public int getDropDownVerticalOffset() {
267+
return mPopup.getVerticalOffset();
268+
}
269+
270+
/**
271+
* Set a horizontal offset in pixels for the spinner's popup window of choices.
272+
* Only valid in {@link #MODE_DROPDOWN}; this method is a no-op in other modes.
273+
*
274+
* @param pixels Horizontal offset in pixels
275+
*
276+
* @attr ref android.R.styleable#Spinner_dropDownHorizontalOffset
277+
*/
278+
public void setDropDownHorizontalOffset(int pixels) {
279+
mPopup.setHorizontalOffset(pixels);
280+
}
281+
282+
/**
283+
* Get the configured horizontal offset in pixels for the spinner's popup window of choices.
284+
* Only valid in {@link #MODE_DROPDOWN}; other modes will return 0.
285+
*
286+
* @return Horizontal offset in pixels
287+
*
288+
* @attr ref android.R.styleable#Spinner_dropDownHorizontalOffset
289+
*/
290+
public int getDropDownHorizontalOffset() {
291+
return mPopup.getHorizontalOffset();
292+
}
293+
294+
/**
295+
* Set the width of the spinner's popup window of choices in pixels. This value
296+
* may also be set to {@link android.view.ViewGroup.LayoutParams#MATCH_PARENT}
297+
* to match the width of the Spinner itself, or
298+
* {@link android.view.ViewGroup.LayoutParams#WRAP_CONTENT} to wrap to the measured size
299+
* of contained dropdown list items.
300+
*
301+
* <p>Only valid in {@link #MODE_DROPDOWN}; this method is a no-op in other modes.</p>
302+
*
303+
* @param pixels Width in pixels, WRAP_CONTENT, or MATCH_PARENT
304+
*
305+
* @attr ref android.R.styleable#Spinner_dropDownWidth
306+
*/
307+
public void setDropDownWidth(int pixels) {
308+
if (!(mPopup instanceof DropdownPopup)) {
309+
Log.e(TAG, "Cannot set dropdown width for MODE_DIALOG, ignoring");
310+
return;
311+
}
312+
mDropDownWidth = pixels;
313+
}
314+
315+
/**
316+
* Get the configured width of the spinner's popup window of choices in pixels.
317+
* The returned value may also be {@link android.view.ViewGroup.LayoutParams#MATCH_PARENT}
318+
* meaning the popup window will match the width of the Spinner itself, or
319+
* {@link android.view.ViewGroup.LayoutParams#WRAP_CONTENT} to wrap to the measured size
320+
* of contained dropdown list items.
321+
*
322+
* @return Width in pixels, WRAP_CONTENT, or MATCH_PARENT
323+
*
324+
* @attr ref android.R.styleable#Spinner_dropDownWidth
325+
*/
326+
public int getDropDownWidth() {
327+
return mDropDownWidth;
328+
}
329+
205330
@Override
206331
public void setEnabled(boolean enabled) {
207332
super.setEnabled(enabled);
@@ -231,6 +356,16 @@ public void setGravity(int gravity) {
231356
}
232357
}
233358

359+
/**
360+
* Describes how the selected item view is positioned. The default is determined by the
361+
* current theme.
362+
*
363+
* @return A {@link android.view.Gravity Gravity} value
364+
*/
365+
public int getGravity() {
366+
return mGravity;
367+
}
368+
234369
@Override
235370
public void setAdapter(SpinnerAdapter adapter) {
236371
super.setAdapter(adapter);
@@ -675,6 +810,13 @@ private interface SpinnerPopup {
675810
*/
676811
public void setPromptText(CharSequence hintText);
677812
public CharSequence getHintText();
813+
814+
public void setBackgroundDrawable(Drawable bg);
815+
public void setVerticalOffset(int px);
816+
public void setHorizontalOffset(int px);
817+
public Drawable getBackground();
818+
public int getVerticalOffset();
819+
public int getHorizontalOffset();
678820
}
679821

680822
private class DialogPopup implements SpinnerPopup, DialogInterface.OnClickListener {
@@ -719,6 +861,36 @@ public void onClick(DialogInterface dialog, int which) {
719861
}
720862
dismiss();
721863
}
864+
865+
@Override
866+
public void setBackgroundDrawable(Drawable bg) {
867+
Log.e(TAG, "Cannot set popup background for MODE_DIALOG, ignoring");
868+
}
869+
870+
@Override
871+
public void setVerticalOffset(int px) {
872+
Log.e(TAG, "Cannot set vertical offset for MODE_DIALOG, ignoring");
873+
}
874+
875+
@Override
876+
public void setHorizontalOffset(int px) {
877+
Log.e(TAG, "Cannot set horizontal offset for MODE_DIALOG, ignoring");
878+
}
879+
880+
@Override
881+
public Drawable getBackground() {
882+
return null;
883+
}
884+
885+
@Override
886+
public int getVerticalOffset() {
887+
return 0;
888+
}
889+
890+
@Override
891+
public int getHorizontalOffset() {
892+
return 0;
893+
}
722894
}
723895

724896
private class DropdownPopup extends ListPopupWindow implements SpinnerPopup {

core/java/android/widget/Switch.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,17 @@ public void setTrackDrawable(Drawable track) {
358358
requestLayout();
359359
}
360360

361+
/**
362+
* Set the drawable used for the track that the switch slides within.
363+
*
364+
* @param track Resource ID of a track drawable
365+
*
366+
* @attr ref android.R.styleable#Switch_track
367+
*/
368+
public void setTrackResource(int resId) {
369+
setTrackDrawable(getContext().getResources().getDrawable(resId));
370+
}
371+
361372
/**
362373
* Get the drawable used for the track that the switch slides within.
363374
*
@@ -382,6 +393,18 @@ public void setThumbDrawable(Drawable thumb) {
382393
requestLayout();
383394
}
384395

396+
/**
397+
* Set the drawable used for the switch "thumb" - the piece that the user
398+
* can physically touch and drag along the track.
399+
*
400+
* @param thumb Resource ID of a thumb drawable
401+
*
402+
* @attr ref android.R.styleable#Switch_thumb
403+
*/
404+
public void setThumbResource(int resId) {
405+
setThumbDrawable(getContext().getResources().getDrawable(resId));
406+
}
407+
385408
/**
386409
* Get the drawable used for the switch "thumb" - the piece that the user
387410
* can physically touch and drag along the track.

0 commit comments

Comments
 (0)