diff options
author | Daniel Sandler <dsandler@android.com> | 2012-04-19 11:04:39 -0400 |
---|---|---|
committer | Daniel Sandler <dsandler@android.com> | 2012-04-19 14:49:49 -0400 |
commit | 4c3308de7d51b16b1450c21787b442d84ace3984 (patch) | |
tree | 65e9670ec830b374104aff9239fd2d861697198d /core/java/android/widget/Switch.java | |
parent | 9afbfb5e1339a63cff5dbe72eae02d703c9bd62f (diff) | |
download | frameworks_base-4c3308de7d51b16b1450c21787b442d84ace3984.zip frameworks_base-4c3308de7d51b16b1450c21787b442d84ace3984.tar.gz frameworks_base-4c3308de7d51b16b1450c21787b442d84ace3984.tar.bz2 |
Fix text transformations in Switches.
In particular, we now honor android:textAllCaps in the
TextAppearance specified for the switch widget itself.
(Now you no longer need to create a separate capitalized
version of your strings to get them to look like the
platform switches.)
Change-Id: Ia48222a6dddd0d0f9115e554dffb621f4d6a2b94
Diffstat (limited to 'core/java/android/widget/Switch.java')
-rw-r--r-- | core/java/android/widget/Switch.java | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/core/java/android/widget/Switch.java b/core/java/android/widget/Switch.java index 0786909..471f259 100644 --- a/core/java/android/widget/Switch.java +++ b/core/java/android/widget/Switch.java @@ -29,6 +29,8 @@ import android.text.Layout; import android.text.StaticLayout; import android.text.TextPaint; import android.text.TextUtils; +import android.text.method.AllCapsTransformationMethod; +import android.text.method.TransformationMethod2; import android.util.AttributeSet; import android.view.Gravity; import android.view.MotionEvent; @@ -91,6 +93,7 @@ public class Switch extends CompoundButton { private ColorStateList mTextColors; private Layout mOnLayout; private Layout mOffLayout; + private TransformationMethod2 mSwitchTransformationMethod; @SuppressWarnings("hiding") private final Rect mTempRect = new Rect(); @@ -207,6 +210,15 @@ public class Switch extends CompoundButton { setSwitchTypefaceByIndex(typefaceIndex, styleIndex); + boolean allCaps = appearance.getBoolean(com.android.internal.R.styleable. + TextAppearance_textAllCaps, false); + if (allCaps) { + mSwitchTransformationMethod = new AllCapsTransformationMethod(getContext()); + mSwitchTransformationMethod.setLengthChangesAllowed(true); + } else { + mSwitchTransformationMethod = null; + } + appearance.recycle(); } @@ -526,8 +538,12 @@ public class Switch extends CompoundButton { } private Layout makeLayout(CharSequence text) { - return new StaticLayout(text, mTextPaint, - (int) Math.ceil(Layout.getDesiredWidth(text, mTextPaint)), + final CharSequence transformed = (mSwitchTransformationMethod != null) + ? mSwitchTransformationMethod.getTransformation(text, this) + : text; + + return new StaticLayout(transformed, mTextPaint, + (int) Math.ceil(Layout.getDesiredWidth(transformed, mTextPaint)), Layout.Alignment.ALIGN_NORMAL, 1.f, 0, true); } |