17f8f79a1ff086c04a3ad2a442b1d39a8186e3e50Adam Powell/* 27f8f79a1ff086c04a3ad2a442b1d39a8186e3e50Adam Powell * Copyright (C) 2011 The Android Open Source Project 37f8f79a1ff086c04a3ad2a442b1d39a8186e3e50Adam Powell * 47f8f79a1ff086c04a3ad2a442b1d39a8186e3e50Adam Powell * Licensed under the Apache License, Version 2.0 (the "License"); 57f8f79a1ff086c04a3ad2a442b1d39a8186e3e50Adam Powell * you may not use this file except in compliance with the License. 67f8f79a1ff086c04a3ad2a442b1d39a8186e3e50Adam Powell * You may obtain a copy of the License at 77f8f79a1ff086c04a3ad2a442b1d39a8186e3e50Adam Powell * 87f8f79a1ff086c04a3ad2a442b1d39a8186e3e50Adam Powell * http://www.apache.org/licenses/LICENSE-2.0 97f8f79a1ff086c04a3ad2a442b1d39a8186e3e50Adam Powell * 107f8f79a1ff086c04a3ad2a442b1d39a8186e3e50Adam Powell * Unless required by applicable law or agreed to in writing, software 117f8f79a1ff086c04a3ad2a442b1d39a8186e3e50Adam Powell * distributed under the License is distributed on an "AS IS" BASIS, 127f8f79a1ff086c04a3ad2a442b1d39a8186e3e50Adam Powell * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 137f8f79a1ff086c04a3ad2a442b1d39a8186e3e50Adam Powell * See the License for the specific language governing permissions and 147f8f79a1ff086c04a3ad2a442b1d39a8186e3e50Adam Powell * limitations under the License. 157f8f79a1ff086c04a3ad2a442b1d39a8186e3e50Adam Powell */ 167f8f79a1ff086c04a3ad2a442b1d39a8186e3e50Adam Powellpackage android.text.method; 177f8f79a1ff086c04a3ad2a442b1d39a8186e3e50Adam Powell 187f8f79a1ff086c04a3ad2a442b1d39a8186e3e50Adam Powellimport android.content.Context; 197f8f79a1ff086c04a3ad2a442b1d39a8186e3e50Adam Powellimport android.graphics.Rect; 207f8f79a1ff086c04a3ad2a442b1d39a8186e3e50Adam Powellimport android.util.Log; 217f8f79a1ff086c04a3ad2a442b1d39a8186e3e50Adam Powellimport android.view.View; 227f8f79a1ff086c04a3ad2a442b1d39a8186e3e50Adam Powell 237f8f79a1ff086c04a3ad2a442b1d39a8186e3e50Adam Powellimport java.util.Locale; 247f8f79a1ff086c04a3ad2a442b1d39a8186e3e50Adam Powell 257f8f79a1ff086c04a3ad2a442b1d39a8186e3e50Adam Powell/** 267f8f79a1ff086c04a3ad2a442b1d39a8186e3e50Adam Powell * Transforms source text into an ALL CAPS string, locale-aware. 277f8f79a1ff086c04a3ad2a442b1d39a8186e3e50Adam Powell * 287f8f79a1ff086c04a3ad2a442b1d39a8186e3e50Adam Powell * @hide 297f8f79a1ff086c04a3ad2a442b1d39a8186e3e50Adam Powell */ 307f8f79a1ff086c04a3ad2a442b1d39a8186e3e50Adam Powellpublic class AllCapsTransformationMethod implements TransformationMethod2 { 317f8f79a1ff086c04a3ad2a442b1d39a8186e3e50Adam Powell private static final String TAG = "AllCapsTransformationMethod"; 327f8f79a1ff086c04a3ad2a442b1d39a8186e3e50Adam Powell 337f8f79a1ff086c04a3ad2a442b1d39a8186e3e50Adam Powell private boolean mEnabled; 347f8f79a1ff086c04a3ad2a442b1d39a8186e3e50Adam Powell private Locale mLocale; 357f8f79a1ff086c04a3ad2a442b1d39a8186e3e50Adam Powell 367f8f79a1ff086c04a3ad2a442b1d39a8186e3e50Adam Powell public AllCapsTransformationMethod(Context context) { 377f8f79a1ff086c04a3ad2a442b1d39a8186e3e50Adam Powell mLocale = context.getResources().getConfiguration().locale; 387f8f79a1ff086c04a3ad2a442b1d39a8186e3e50Adam Powell } 397f8f79a1ff086c04a3ad2a442b1d39a8186e3e50Adam Powell 407f8f79a1ff086c04a3ad2a442b1d39a8186e3e50Adam Powell @Override 417f8f79a1ff086c04a3ad2a442b1d39a8186e3e50Adam Powell public CharSequence getTransformation(CharSequence source, View view) { 427f8f79a1ff086c04a3ad2a442b1d39a8186e3e50Adam Powell if (mEnabled) { 437f8f79a1ff086c04a3ad2a442b1d39a8186e3e50Adam Powell return source != null ? source.toString().toUpperCase(mLocale) : null; 447f8f79a1ff086c04a3ad2a442b1d39a8186e3e50Adam Powell } 457f8f79a1ff086c04a3ad2a442b1d39a8186e3e50Adam Powell Log.w(TAG, "Caller did not enable length changes; not transforming text"); 467f8f79a1ff086c04a3ad2a442b1d39a8186e3e50Adam Powell return source; 477f8f79a1ff086c04a3ad2a442b1d39a8186e3e50Adam Powell } 487f8f79a1ff086c04a3ad2a442b1d39a8186e3e50Adam Powell 497f8f79a1ff086c04a3ad2a442b1d39a8186e3e50Adam Powell @Override 507f8f79a1ff086c04a3ad2a442b1d39a8186e3e50Adam Powell public void onFocusChanged(View view, CharSequence sourceText, boolean focused, int direction, 517f8f79a1ff086c04a3ad2a442b1d39a8186e3e50Adam Powell Rect previouslyFocusedRect) { 527f8f79a1ff086c04a3ad2a442b1d39a8186e3e50Adam Powell } 537f8f79a1ff086c04a3ad2a442b1d39a8186e3e50Adam Powell 547f8f79a1ff086c04a3ad2a442b1d39a8186e3e50Adam Powell @Override 557f8f79a1ff086c04a3ad2a442b1d39a8186e3e50Adam Powell public void setLengthChangesAllowed(boolean allowLengthChanges) { 567f8f79a1ff086c04a3ad2a442b1d39a8186e3e50Adam Powell mEnabled = allowLengthChanges; 577f8f79a1ff086c04a3ad2a442b1d39a8186e3e50Adam Powell } 587f8f79a1ff086c04a3ad2a442b1d39a8186e3e50Adam Powell 597f8f79a1ff086c04a3ad2a442b1d39a8186e3e50Adam Powell} 60