Loading api/current.txt +78 −59 File changed.Preview size limit exceeded, changes collapsed. Show changes core/java/android/widget/Switch.java +26 −22 Original line number Diff line number Diff line Loading @@ -41,9 +41,15 @@ import com.android.internal.R; /** * A Switch is a two-state toggle switch widget that can select between two * options. The user may drag the "thumb" back and forth to choose the selected option, * or simply tap to toggle as if it were a checkbox. * or simply tap to toggle as if it were a checkbox. The {@link #setText(CharSequence) text} * property controls the text displayed in the label for the switch, whereas the * {@link #setTextOff(CharSequence) off} and {@link #setTextOn(CharSequence) on} text * controls the text on the thumb. Similarly, the * {@link #setTextAppearance(android.content.Context, int) textAppearance} and the related * setTypeface() methods control the typeface and style of label text, whereas the * {@link #setSwitchTextAppearance(android.content.Context, int) switchTextAppearance} and * the related seSwitchTypeface() methods control that of the thumb. * * @hide */ public class Switch extends CompoundButton { private static final int TOUCH_MODE_IDLE = 0; Loading Loading @@ -132,8 +138,8 @@ public class Switch extends CompoundButton { TypedArray a = context.obtainStyledAttributes(attrs, com.android.internal.R.styleable.Switch, defStyle, 0); mThumbDrawable = a.getDrawable(com.android.internal.R.styleable.Switch_switchThumb); mTrackDrawable = a.getDrawable(com.android.internal.R.styleable.Switch_switchTrack); mThumbDrawable = a.getDrawable(com.android.internal.R.styleable.Switch_thumb); mTrackDrawable = a.getDrawable(com.android.internal.R.styleable.Switch_track); mTextOn = a.getText(com.android.internal.R.styleable.Switch_textOn); mTextOff = a.getText(com.android.internal.R.styleable.Switch_textOff); mThumbTextPadding = a.getDimensionPixelSize( Loading @@ -146,7 +152,7 @@ public class Switch extends CompoundButton { int appearance = a.getResourceId( com.android.internal.R.styleable.Switch_switchTextAppearance, 0); if (appearance != 0) { setSwitchTextAppearance(appearance); setSwitchTextAppearance(context, appearance); } a.recycle(); Loading @@ -162,9 +168,9 @@ public class Switch extends CompoundButton { * Sets the switch text color, size, style, hint color, and highlight color * from the specified TextAppearance resource. */ public void setSwitchTextAppearance(int resid) { public void setSwitchTextAppearance(Context context, int resid) { TypedArray appearance = getContext().obtainStyledAttributes(resid, context.obtainStyledAttributes(resid, com.android.internal.R.styleable.TextAppearance); ColorStateList colors; Loading @@ -174,6 +180,9 @@ public class Switch extends CompoundButton { TextAppearance_textColor); if (colors != null) { mTextColors = colors; } else { // If no color set in TextAppearance, default to the view's textColor mTextColors = getTextColors(); } ts = appearance.getDimensionPixelSize(com.android.internal.R.styleable. Loading Loading @@ -244,7 +253,7 @@ public class Switch extends CompoundButton { } /** * Sets the typeface and style in which the text should be displayed on the switch. * Sets the typeface in which the text should be displayed on the switch. * Note that not all Typeface families actually have bold and italic * variants, so you may need to use * {@link #setSwitchTypeface(Typeface, int)} to get the appearance Loading @@ -263,18 +272,14 @@ public class Switch extends CompoundButton { } /** * Returns the text for when the button is in the checked state. * * @return The text. * Returns the text displayed when the button is in the checked state. */ public CharSequence getTextOn() { return mTextOn; } /** * Sets the text for when the button is in the checked state. * * @param textOn The text. * Sets the text displayed when the button is in the checked state. */ public void setTextOn(CharSequence textOn) { mTextOn = textOn; Loading @@ -282,18 +287,14 @@ public class Switch extends CompoundButton { } /** * Returns the text for when the button is not in the checked state. * * @return The text. * Returns the text displayed when the button is not in the checked state. */ public CharSequence getTextOff() { return mTextOff; } /** * Sets the text for when the button is not in the checked state. * * @param textOff The text. * Sets the text displayed when the button is not in the checked state. */ public void setTextOff(CharSequence textOff) { mTextOff = textOff; Loading Loading @@ -582,8 +583,11 @@ public class Switch extends CompoundButton { mThumbDrawable.setBounds(thumbLeft, switchTop, thumbRight, switchBottom); mThumbDrawable.draw(canvas); // mTextColors should not be null, but just in case if (mTextColors != null) { mTextPaint.setColor(mTextColors.getColorForState(getDrawableState(), mTextColors.getDefaultColor())); } mTextPaint.drawableState = getDrawableState(); Layout switchText = getTargetCheckedState() ? mOnLayout : mOffLayout; Loading core/res/res/values/attrs.xml +2 −2 Original line number Diff line number Diff line Loading @@ -5318,9 +5318,9 @@ <declare-styleable name="Switch"> <!-- Drawable to use as the "thumb" that switches back and forth. --> <attr name="switchThumb" format="reference" /> <attr name="thumb" /> <!-- Drawable to use as the "track" that the switch thumb slides within. --> <attr name="switchTrack" format="reference" /> <attr name="track" format="reference" /> <!-- Text to use when the switch is in the checked/"on" state. --> <attr name="textOn" /> <!-- Text to use when the switch is in the unchecked/"off" state. --> Loading core/res/res/values/public.xml +5 −0 Original line number Diff line number Diff line Loading @@ -1713,6 +1713,11 @@ <public type="attr" name="switchTextOn" /> <public type="attr" name="switchTextOff" /> <public type="attr" name="switchPreferenceStyle" /> <public type="attr" name="switchTextAppearance" /> <public type="attr" name="track" /> <public type="attr" name="switchMinWidth" /> <public type="attr" name="switchPadding" /> <public type="attr" name="thumbTextPadding" /> <public type="attr" name="textSuggestionsWindowStyle" /> <public type="attr" name="textEditSuggestionItemLayout" /> Loading core/res/res/values/styles.xml +18 −2 Original line number Diff line number Diff line Loading @@ -725,6 +725,11 @@ please see styles_device_defaults.xml. <item name="android:quickContactWindowSize">modeLarge</item> </style> <style name="Widget.CompoundButton.Switch"> <item name="android:textOn">@android:string/capital_on</item> <item name="android:textOff">@android:string/capital_off</item> </style> <!-- Text Appearances --> <eat-comment /> Loading Loading @@ -1919,8 +1924,8 @@ please see styles_device_defaults.xml. </style> <style name="Widget.Holo.CompoundButton.Switch"> <item name="android:switchTrack">@android:drawable/switch_track_holo_dark</item> <item name="android:switchThumb">@android:drawable/switch_inner_holo_dark</item> <item name="android:track">@android:drawable/switch_track_holo_dark</item> <item name="android:thumb">@android:drawable/switch_inner_holo_dark</item> <item name="android:switchTextAppearance">@android:style/TextAppearance.Holo.Widget.Switch</item> <item name="android:textOn">@android:string/capital_on</item> <item name="android:textOff">@android:string/capital_off</item> Loading Loading @@ -2293,6 +2298,17 @@ please see styles_device_defaults.xml. <item name="android:itemPadding">8dip</item> </style> <style name="Widget.Holo.Light.CompoundButton.Switch" parent="Widget.CompoundButton.Switch"> <item name="android:track">@android:drawable/switch_track_holo_light</item> <item name="android:thumb">@android:drawable/switch_inner_holo_light</item> <item name="android:switchTextAppearance">@android:style/TextAppearance.Holo.Widget.Switch</item> <item name="android:textOn">@android:string/capital_on</item> <item name="android:textOff">@android:string/capital_off</item> <item name="android:thumbTextPadding">12dip</item> <item name="android:switchMinWidth">96dip</item> <item name="android:switchPadding">16dip</item> </style> <!-- Animation Styles --> <style name="Animation.Holo" parent="Animation"> Loading Loading
core/java/android/widget/Switch.java +26 −22 Original line number Diff line number Diff line Loading @@ -41,9 +41,15 @@ import com.android.internal.R; /** * A Switch is a two-state toggle switch widget that can select between two * options. The user may drag the "thumb" back and forth to choose the selected option, * or simply tap to toggle as if it were a checkbox. * or simply tap to toggle as if it were a checkbox. The {@link #setText(CharSequence) text} * property controls the text displayed in the label for the switch, whereas the * {@link #setTextOff(CharSequence) off} and {@link #setTextOn(CharSequence) on} text * controls the text on the thumb. Similarly, the * {@link #setTextAppearance(android.content.Context, int) textAppearance} and the related * setTypeface() methods control the typeface and style of label text, whereas the * {@link #setSwitchTextAppearance(android.content.Context, int) switchTextAppearance} and * the related seSwitchTypeface() methods control that of the thumb. * * @hide */ public class Switch extends CompoundButton { private static final int TOUCH_MODE_IDLE = 0; Loading Loading @@ -132,8 +138,8 @@ public class Switch extends CompoundButton { TypedArray a = context.obtainStyledAttributes(attrs, com.android.internal.R.styleable.Switch, defStyle, 0); mThumbDrawable = a.getDrawable(com.android.internal.R.styleable.Switch_switchThumb); mTrackDrawable = a.getDrawable(com.android.internal.R.styleable.Switch_switchTrack); mThumbDrawable = a.getDrawable(com.android.internal.R.styleable.Switch_thumb); mTrackDrawable = a.getDrawable(com.android.internal.R.styleable.Switch_track); mTextOn = a.getText(com.android.internal.R.styleable.Switch_textOn); mTextOff = a.getText(com.android.internal.R.styleable.Switch_textOff); mThumbTextPadding = a.getDimensionPixelSize( Loading @@ -146,7 +152,7 @@ public class Switch extends CompoundButton { int appearance = a.getResourceId( com.android.internal.R.styleable.Switch_switchTextAppearance, 0); if (appearance != 0) { setSwitchTextAppearance(appearance); setSwitchTextAppearance(context, appearance); } a.recycle(); Loading @@ -162,9 +168,9 @@ public class Switch extends CompoundButton { * Sets the switch text color, size, style, hint color, and highlight color * from the specified TextAppearance resource. */ public void setSwitchTextAppearance(int resid) { public void setSwitchTextAppearance(Context context, int resid) { TypedArray appearance = getContext().obtainStyledAttributes(resid, context.obtainStyledAttributes(resid, com.android.internal.R.styleable.TextAppearance); ColorStateList colors; Loading @@ -174,6 +180,9 @@ public class Switch extends CompoundButton { TextAppearance_textColor); if (colors != null) { mTextColors = colors; } else { // If no color set in TextAppearance, default to the view's textColor mTextColors = getTextColors(); } ts = appearance.getDimensionPixelSize(com.android.internal.R.styleable. Loading Loading @@ -244,7 +253,7 @@ public class Switch extends CompoundButton { } /** * Sets the typeface and style in which the text should be displayed on the switch. * Sets the typeface in which the text should be displayed on the switch. * Note that not all Typeface families actually have bold and italic * variants, so you may need to use * {@link #setSwitchTypeface(Typeface, int)} to get the appearance Loading @@ -263,18 +272,14 @@ public class Switch extends CompoundButton { } /** * Returns the text for when the button is in the checked state. * * @return The text. * Returns the text displayed when the button is in the checked state. */ public CharSequence getTextOn() { return mTextOn; } /** * Sets the text for when the button is in the checked state. * * @param textOn The text. * Sets the text displayed when the button is in the checked state. */ public void setTextOn(CharSequence textOn) { mTextOn = textOn; Loading @@ -282,18 +287,14 @@ public class Switch extends CompoundButton { } /** * Returns the text for when the button is not in the checked state. * * @return The text. * Returns the text displayed when the button is not in the checked state. */ public CharSequence getTextOff() { return mTextOff; } /** * Sets the text for when the button is not in the checked state. * * @param textOff The text. * Sets the text displayed when the button is not in the checked state. */ public void setTextOff(CharSequence textOff) { mTextOff = textOff; Loading Loading @@ -582,8 +583,11 @@ public class Switch extends CompoundButton { mThumbDrawable.setBounds(thumbLeft, switchTop, thumbRight, switchBottom); mThumbDrawable.draw(canvas); // mTextColors should not be null, but just in case if (mTextColors != null) { mTextPaint.setColor(mTextColors.getColorForState(getDrawableState(), mTextColors.getDefaultColor())); } mTextPaint.drawableState = getDrawableState(); Layout switchText = getTargetCheckedState() ? mOnLayout : mOffLayout; Loading
core/res/res/values/attrs.xml +2 −2 Original line number Diff line number Diff line Loading @@ -5318,9 +5318,9 @@ <declare-styleable name="Switch"> <!-- Drawable to use as the "thumb" that switches back and forth. --> <attr name="switchThumb" format="reference" /> <attr name="thumb" /> <!-- Drawable to use as the "track" that the switch thumb slides within. --> <attr name="switchTrack" format="reference" /> <attr name="track" format="reference" /> <!-- Text to use when the switch is in the checked/"on" state. --> <attr name="textOn" /> <!-- Text to use when the switch is in the unchecked/"off" state. --> Loading
core/res/res/values/public.xml +5 −0 Original line number Diff line number Diff line Loading @@ -1713,6 +1713,11 @@ <public type="attr" name="switchTextOn" /> <public type="attr" name="switchTextOff" /> <public type="attr" name="switchPreferenceStyle" /> <public type="attr" name="switchTextAppearance" /> <public type="attr" name="track" /> <public type="attr" name="switchMinWidth" /> <public type="attr" name="switchPadding" /> <public type="attr" name="thumbTextPadding" /> <public type="attr" name="textSuggestionsWindowStyle" /> <public type="attr" name="textEditSuggestionItemLayout" /> Loading
core/res/res/values/styles.xml +18 −2 Original line number Diff line number Diff line Loading @@ -725,6 +725,11 @@ please see styles_device_defaults.xml. <item name="android:quickContactWindowSize">modeLarge</item> </style> <style name="Widget.CompoundButton.Switch"> <item name="android:textOn">@android:string/capital_on</item> <item name="android:textOff">@android:string/capital_off</item> </style> <!-- Text Appearances --> <eat-comment /> Loading Loading @@ -1919,8 +1924,8 @@ please see styles_device_defaults.xml. </style> <style name="Widget.Holo.CompoundButton.Switch"> <item name="android:switchTrack">@android:drawable/switch_track_holo_dark</item> <item name="android:switchThumb">@android:drawable/switch_inner_holo_dark</item> <item name="android:track">@android:drawable/switch_track_holo_dark</item> <item name="android:thumb">@android:drawable/switch_inner_holo_dark</item> <item name="android:switchTextAppearance">@android:style/TextAppearance.Holo.Widget.Switch</item> <item name="android:textOn">@android:string/capital_on</item> <item name="android:textOff">@android:string/capital_off</item> Loading Loading @@ -2293,6 +2298,17 @@ please see styles_device_defaults.xml. <item name="android:itemPadding">8dip</item> </style> <style name="Widget.Holo.Light.CompoundButton.Switch" parent="Widget.CompoundButton.Switch"> <item name="android:track">@android:drawable/switch_track_holo_light</item> <item name="android:thumb">@android:drawable/switch_inner_holo_light</item> <item name="android:switchTextAppearance">@android:style/TextAppearance.Holo.Widget.Switch</item> <item name="android:textOn">@android:string/capital_on</item> <item name="android:textOff">@android:string/capital_off</item> <item name="android:thumbTextPadding">12dip</item> <item name="android:switchMinWidth">96dip</item> <item name="android:switchPadding">16dip</item> </style> <!-- Animation Styles --> <style name="Animation.Holo" parent="Animation"> Loading