1 /* 2 * Copyright (C) 2012 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.keyguard; 18 19 import android.content.Context; 20 import android.content.res.TypedArray; 21 import android.text.TextUtils; 22 import android.text.method.SingleLineTransformationMethod; 23 import android.util.AttributeSet; 24 import android.view.View; 25 import android.view.accessibility.AccessibilityNodeInfo; 26 import android.widget.TextView; 27 28 import com.android.systemui.res.R; 29 30 import java.util.Locale; 31 32 public class CarrierText extends TextView { 33 private final boolean mShowMissingSim; 34 35 private final boolean mShowAirplaneMode; 36 37 private final String mDebugLocation; 38 CarrierText(Context context)39 public CarrierText(Context context) { 40 this(context, null); 41 } 42 CarrierText(Context context, AttributeSet attrs)43 public CarrierText(Context context, AttributeSet attrs) { 44 super(context, attrs); 45 boolean useAllCaps; 46 TypedArray a = context.getTheme().obtainStyledAttributes( 47 attrs, R.styleable.CarrierText, 0, 0); 48 try { 49 useAllCaps = a.getBoolean(R.styleable.CarrierText_allCaps, false); 50 mShowAirplaneMode = a.getBoolean(R.styleable.CarrierText_showAirplaneMode, false); 51 mShowMissingSim = a.getBoolean(R.styleable.CarrierText_showMissingSim, false); 52 mDebugLocation = a.getString(R.styleable.CarrierText_debugLocation); 53 } finally { 54 a.recycle(); 55 } 56 setTransformationMethod(new CarrierTextTransformationMethod(mContext, useAllCaps)); 57 } 58 @Override onVisibilityChanged(View changedView, int visibility)59 protected void onVisibilityChanged(View changedView, int visibility) { 60 super.onVisibilityChanged(changedView, visibility); 61 // Only show marquee when visible 62 if (visibility == VISIBLE) { 63 setEllipsize(TextUtils.TruncateAt.MARQUEE); 64 } else { 65 setEllipsize(TextUtils.TruncateAt.END); 66 } 67 } 68 69 @Override onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info)70 public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) { 71 super.onInitializeAccessibilityNodeInfo(info); 72 // Clear selected state set by CarrierTextController so "selected" not announced by 73 // accessibility but we can still marquee. 74 info.setSelected(false); 75 } 76 getShowAirplaneMode()77 public boolean getShowAirplaneMode() { 78 return mShowAirplaneMode; 79 } 80 getShowMissingSim()81 public boolean getShowMissingSim() { 82 return mShowMissingSim; 83 } 84 getDebugLocation()85 public String getDebugLocation() { 86 return mDebugLocation; 87 } 88 89 private static class CarrierTextTransformationMethod extends SingleLineTransformationMethod { 90 private final Locale mLocale; 91 private final boolean mAllCaps; 92 CarrierTextTransformationMethod(Context context, boolean allCaps)93 public CarrierTextTransformationMethod(Context context, boolean allCaps) { 94 mLocale = context.getResources().getConfiguration().locale; 95 mAllCaps = allCaps; 96 } 97 98 @Override getTransformation(CharSequence source, View view)99 public CharSequence getTransformation(CharSequence source, View view) { 100 source = super.getTransformation(source, view); 101 102 if (mAllCaps && source != null) { 103 source = source.toString().toUpperCase(mLocale); 104 } 105 106 return source; 107 } 108 } 109 } 110