diff options
| -rw-r--r-- | api/current.txt | 2 | ||||
| -rw-r--r-- | core/java/android/text/method/AllCapsTransformationMethod.java | 59 | ||||
| -rw-r--r-- | core/java/android/text/method/TransformationMethod2.java | 33 | ||||
| -rw-r--r-- | core/java/android/widget/TextView.java | 67 | ||||
| -rw-r--r-- | core/java/com/android/internal/view/menu/ActionMenuItemView.java | 7 | ||||
| -rw-r--r-- | core/java/com/android/internal/widget/ScrollingTabContainerView.java | 1 | ||||
| -rwxr-xr-x | core/res/res/values/attrs.xml | 4 | ||||
| -rw-r--r-- | core/res/res/values/public.xml | 2 | ||||
| -rw-r--r-- | core/res/res/values/styles.xml | 2 |
9 files changed, 161 insertions, 16 deletions
diff --git a/api/current.txt b/api/current.txt index 91c561c5b2fb..b240e1408094 100644 --- a/api/current.txt +++ b/api/current.txt @@ -941,6 +941,7 @@ package android { field public static final int tension = 16843370; // 0x101026a field public static final int testOnly = 16843378; // 0x1010272 field public static final int text = 16843087; // 0x101014f + field public static final int textAllCaps = 16843680; // 0x10103a0 field public static final int textAppearance = 16842804; // 0x1010034 field public static final int textAppearanceButton = 16843271; // 0x1010207 field public static final int textAppearanceInverse = 16842805; // 0x1010035 @@ -26162,6 +26163,7 @@ package android.widget { method public boolean onTextContextMenuItem(int); method public void removeTextChangedListener(android.text.TextWatcher); method protected void resetLayoutDirectionResolution(); + method public void setAllCaps(boolean); method public final void setAutoLinkMask(int); method public void setCompoundDrawablePadding(int); method public void setCompoundDrawables(android.graphics.drawable.Drawable, android.graphics.drawable.Drawable, android.graphics.drawable.Drawable, android.graphics.drawable.Drawable); diff --git a/core/java/android/text/method/AllCapsTransformationMethod.java b/core/java/android/text/method/AllCapsTransformationMethod.java new file mode 100644 index 000000000000..f9920dd2e275 --- /dev/null +++ b/core/java/android/text/method/AllCapsTransformationMethod.java @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package android.text.method; + +import android.content.Context; +import android.graphics.Rect; +import android.util.Log; +import android.view.View; + +import java.util.Locale; + +/** + * Transforms source text into an ALL CAPS string, locale-aware. + * + * @hide + */ +public class AllCapsTransformationMethod implements TransformationMethod2 { + private static final String TAG = "AllCapsTransformationMethod"; + + private boolean mEnabled; + private Locale mLocale; + + public AllCapsTransformationMethod(Context context) { + mLocale = context.getResources().getConfiguration().locale; + } + + @Override + public CharSequence getTransformation(CharSequence source, View view) { + if (mEnabled) { + return source != null ? source.toString().toUpperCase(mLocale) : null; + } + Log.w(TAG, "Caller did not enable length changes; not transforming text"); + return source; + } + + @Override + public void onFocusChanged(View view, CharSequence sourceText, boolean focused, int direction, + Rect previouslyFocusedRect) { + } + + @Override + public void setLengthChangesAllowed(boolean allowLengthChanges) { + mEnabled = allowLengthChanges; + } + +} diff --git a/core/java/android/text/method/TransformationMethod2.java b/core/java/android/text/method/TransformationMethod2.java new file mode 100644 index 000000000000..ef00ecdb8179 --- /dev/null +++ b/core/java/android/text/method/TransformationMethod2.java @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package android.text.method; + +/** + * TransformationMethod2 extends the TransformationMethod interface + * and adds the ability to relax restrictions of TransformationMethod. + * + * @hide + */ +public interface TransformationMethod2 extends TransformationMethod { + /** + * Relax the contract of TransformationMethod to allow length changes, + * or revert to the length-restricted behavior. + * + * @param allowLengthChanges true to allow the transformation to change the length + * of the input string. + */ + public void setLengthChangesAllowed(boolean allowLengthChanges); +} diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java index 772e8e9e67d4..1e63e2677d6c 100644 --- a/core/java/android/widget/TextView.java +++ b/core/java/android/widget/TextView.java @@ -16,6 +16,11 @@ package android.widget; +import com.android.internal.util.FastMath; +import com.android.internal.widget.EditableInputConnection; + +import org.xmlpull.v1.XmlPullParserException; + import android.R; import android.content.ClipData; import android.content.ClipData.Item; @@ -62,6 +67,7 @@ import android.text.StaticLayout; import android.text.TextPaint; import android.text.TextUtils; import android.text.TextWatcher; +import android.text.method.AllCapsTransformationMethod; import android.text.method.ArrowKeyMovementMethod; import android.text.method.DateKeyListener; import android.text.method.DateTimeKeyListener; @@ -76,6 +82,7 @@ import android.text.method.SingleLineTransformationMethod; import android.text.method.TextKeyListener; import android.text.method.TimeKeyListener; import android.text.method.TransformationMethod; +import android.text.method.TransformationMethod2; import android.text.method.WordIterator; import android.text.style.ClickableSpan; import android.text.style.ParagraphStyle; @@ -125,11 +132,6 @@ import android.view.inputmethod.InputConnection; import android.view.inputmethod.InputMethodManager; import android.widget.RemoteViews.RemoteView; -import com.android.internal.util.FastMath; -import com.android.internal.widget.EditableInputConnection; - -import org.xmlpull.v1.XmlPullParserException; - import java.io.IOException; import java.lang.ref.WeakReference; import java.text.BreakIterator; @@ -424,6 +426,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener int textSize = 15; int typefaceIndex = -1; int styleIndex = -1; + boolean allCaps = false; /* * Look the appearance up without checking first if it exists because @@ -471,6 +474,10 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener case com.android.internal.R.styleable.TextAppearance_textStyle: styleIndex = appearance.getInt(attr, -1); break; + + case com.android.internal.R.styleable.TextAppearance_textAllCaps: + allCaps = appearance.getBoolean(attr, false); + break; } } @@ -822,6 +829,10 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener case com.android.internal.R.styleable.TextView_suggestionsEnabled: mSuggestionsEnabled = a.getBoolean(attr, true); break; + + case com.android.internal.R.styleable.TextView_textAllCaps: + allCaps = a.getBoolean(attr, false); + break; } } a.recycle(); @@ -1004,6 +1015,10 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } setRawTextSize(textSize); + if (allCaps) { + setTransformationMethod(new AllCapsTransformationMethod(getContext())); + } + if (password || passwordInputType || webPasswordInputType || numberPasswordInputType) { setTransformationMethod(PasswordTransformationMethod.getInstance()); typefaceIndex = MONOSPACE; @@ -1331,6 +1346,14 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener mTransformation = method; + if (method instanceof TransformationMethod2) { + TransformationMethod2 method2 = (TransformationMethod2) method; + mAllowTransformationLengthChange = !mTextIsSelectable && !(mText instanceof Editable); + method2.setLengthChangesAllowed(mAllowTransformationLengthChange); + } else { + mAllowTransformationLengthChange = false; + } + setText(mText); } @@ -1775,6 +1798,11 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener setTypefaceByIndex(typefaceIndex, styleIndex); + if (appearance.getBoolean(com.android.internal.R.styleable.TextAppearance_textAllCaps, + false)) { + setTransformationMethod(new AllCapsTransformationMethod(getContext())); + } + appearance.recycle(); } @@ -2823,14 +2851,15 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener mBufferType = type; mText = text; - if (mTransformation == null) + if (mTransformation == null) { mTransformed = text; - else + } else { mTransformed = mTransformation.getTransformation(text, this); + } final int textLength = text.length(); - if (text instanceof Spannable) { + if (text instanceof Spannable && !mAllowTransformationLengthChange) { Spannable sp = (Spannable) text; // Remove any ChangeWatchers that might have come @@ -2852,7 +2881,6 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener if (mTransformation != null) { sp.setSpan(mTransformation, 0, textLength, Spanned.SPAN_INCLUSIVE_INCLUSIVE); - } if (mMovement != null) { @@ -6570,6 +6598,26 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } /** + * Sets the properties of this field to transform input to ALL CAPS + * display. This may use a "small caps" formatting if available. + * This setting will be ignored if this field is editable or selectable. + * + * This call replaces the current transformation method. Disabling this + * will not necessarily restore the previous behavior from before this + * was enabled. + * + * @see #setTransformationMethod(TransformationMethod) + * @attr ref android.R.styleable#TextView_textAllCaps + */ + public void setAllCaps(boolean allCaps) { + if (allCaps) { + setTransformationMethod(new AllCapsTransformationMethod(getContext())); + } else { + setTransformationMethod(null); + } + } + + /** * If true, sets the properties of this field (number of lines, horizontally scrolling, * transformation method) to be for a single-line input; if false, restores these to the default * conditions. @@ -10254,6 +10302,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener private MovementMethod mMovement; private TransformationMethod mTransformation; + private boolean mAllowTransformationLengthChange; private ChangeWatcher mChangeWatcher; private ArrayList<TextWatcher> mListeners = null; diff --git a/core/java/com/android/internal/view/menu/ActionMenuItemView.java b/core/java/com/android/internal/view/menu/ActionMenuItemView.java index 3b497e46f3c5..09bebae4ca1d 100644 --- a/core/java/com/android/internal/view/menu/ActionMenuItemView.java +++ b/core/java/com/android/internal/view/menu/ActionMenuItemView.java @@ -154,12 +154,7 @@ public class ActionMenuItemView extends LinearLayout // populate accessibility description with title setContentDescription(title); - if (mShowTextAllCaps && title != null) { - mTextButton.setText(title.toString().toUpperCase( - getContext().getResources().getConfiguration().locale)); - } else { - mTextButton.setText(mTitle); - } + mTextButton.setText(mTitle); updateTextButtonVisibility(); } diff --git a/core/java/com/android/internal/widget/ScrollingTabContainerView.java b/core/java/com/android/internal/widget/ScrollingTabContainerView.java index 2f7adf0c0b46..40e5e8a1fc10 100644 --- a/core/java/com/android/internal/widget/ScrollingTabContainerView.java +++ b/core/java/com/android/internal/widget/ScrollingTabContainerView.java @@ -260,7 +260,6 @@ public class ScrollingTabContainerView extends HorizontalScrollView { if (mTextView == null) { TextView textView = new TextView(getContext(), null, com.android.internal.R.attr.actionBarTabTextStyle); - textView.setSingleLine(); textView.setEllipsize(TruncateAt.END); LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml index 2cc81710fd5d..39de054916ca 100755 --- a/core/res/res/values/attrs.xml +++ b/core/res/res/values/attrs.xml @@ -2810,6 +2810,8 @@ <attr name="textColorHint" /> <!-- Color of the links. --> <attr name="textColorLink" /> + <!-- Present the text in ALL CAPS. This may use a small-caps form when available. --> + <attr name="textAllCaps" format="boolean" /> </declare-styleable> <declare-styleable name="TextSwitcher"> </declare-styleable> @@ -3074,6 +3076,8 @@ <attr name="textIsSelectable" /> <!-- Suggestions will be displayed when the user double taps on editable text. --> <attr name="suggestionsEnabled" /> + <!-- Present the text in ALL CAPS. This may use a small-caps form when available. --> + <attr name="textAllCaps" /> </declare-styleable> <!-- An <code>input-extras</code> is a container for extra data to supply to an input method. Contains diff --git a/core/res/res/values/public.xml b/core/res/res/values/public.xml index 2de9cd3d4aae..3c23add10dff 100644 --- a/core/res/res/values/public.xml +++ b/core/res/res/values/public.xml @@ -1779,6 +1779,8 @@ <public type="attr" name="backgroundStacked" /> <public type="attr" name="backgroundSplit" /> + <public type="attr" name="textAllCaps" /> + <public type="style" name="TextAppearance.SuggestionHighlight" /> <public type="style" name="Theme.Holo.SplitActionBarWhenNarrow" /> <public type="style" name="Theme.Holo.Light.SplitActionBarWhenNarrow" /> diff --git a/core/res/res/values/styles.xml b/core/res/res/values/styles.xml index 11016f4a5dee..8a8f81a5bf19 100644 --- a/core/res/res/values/styles.xml +++ b/core/res/res/values/styles.xml @@ -1319,6 +1319,7 @@ <item name="android:textSize">12sp</item> <item name="android:textStyle">bold</item> <item name="android:textColor">?android:attr/actionMenuTextColor</item> + <item name="android:textAllCaps">true</item> </style> <style name="TextAppearance.Holo.Widget.ActionMode"> @@ -1857,6 +1858,7 @@ <item name="android:textColor">?android:attr/textColorPrimary</item> <item name="android:textSize">12sp</item> <item name="android:textStyle">bold</item> + <item name="android:textAllCaps">true</item> </style> <style name="Widget.Holo.ActionMode" parent="Widget.ActionMode"> |