diff options
author | Adam Powell <adamp@google.com> | 2011-07-07 18:35:54 -0700 |
---|---|---|
committer | Adam Powell <adamp@google.com> | 2011-07-07 20:39:41 -0700 |
commit | 7f8f79a1ff086c04a3ad2a442b1d39a8186e3e50 (patch) | |
tree | 3dea1c5b3b5a48bf3af6828b6d1520f6fa1c43e6 /core/java/android/text/method | |
parent | eea5be5447c759fcc11e587504ae172a4665db78 (diff) | |
download | frameworks_base-7f8f79a1ff086c04a3ad2a442b1d39a8186e3e50.zip frameworks_base-7f8f79a1ff086c04a3ad2a442b1d39a8186e3e50.tar.gz frameworks_base-7f8f79a1ff086c04a3ad2a442b1d39a8186e3e50.tar.bz2 |
Add ALL CAPS style to TextView/TextAppearance
Switch out ugly hack in action menu items for the new style.
Change-Id: I68a0ed62a352b14d499e6478b82bbc12dcb5a030
Diffstat (limited to 'core/java/android/text/method')
-rw-r--r-- | core/java/android/text/method/AllCapsTransformationMethod.java | 59 | ||||
-rw-r--r-- | core/java/android/text/method/TransformationMethod2.java | 33 |
2 files changed, 92 insertions, 0 deletions
diff --git a/core/java/android/text/method/AllCapsTransformationMethod.java b/core/java/android/text/method/AllCapsTransformationMethod.java new file mode 100644 index 0000000..f9920dd --- /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 0000000..ef00ecd --- /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); +} |