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.widget.TextView; 26 27 import com.android.systemui.res.R; 28 29 import java.util.Locale; 30 31 public class CarrierText extends TextView { 32 private final boolean mShowMissingSim; 33 34 private final boolean mShowAirplaneMode; 35 36 private final String mDebugLocation; 37 CarrierText(Context context)38 public CarrierText(Context context) { 39 this(context, null); 40 } 41 CarrierText(Context context, AttributeSet attrs)42 public CarrierText(Context context, AttributeSet attrs) { 43 super(context, attrs); 44 boolean useAllCaps; 45 TypedArray a = context.getTheme().obtainStyledAttributes( 46 attrs, R.styleable.CarrierText, 0, 0); 47 try { 48 useAllCaps = a.getBoolean(R.styleable.CarrierText_allCaps, false); 49 mShowAirplaneMode = a.getBoolean(R.styleable.CarrierText_showAirplaneMode, false); 50 mShowMissingSim = a.getBoolean(R.styleable.CarrierText_showMissingSim, false); 51 mDebugLocation = a.getString(R.styleable.CarrierText_debugLocation); 52 } finally { 53 a.recycle(); 54 } 55 setTransformationMethod(new CarrierTextTransformationMethod(mContext, useAllCaps)); 56 } 57 @Override onVisibilityChanged(View changedView, int visibility)58 protected void onVisibilityChanged(View changedView, int visibility) { 59 super.onVisibilityChanged(changedView, visibility); 60 // Only show marquee when visible 61 if (visibility == VISIBLE) { 62 setEllipsize(TextUtils.TruncateAt.MARQUEE); 63 } else { 64 setEllipsize(TextUtils.TruncateAt.END); 65 } 66 } 67 getShowAirplaneMode()68 public boolean getShowAirplaneMode() { 69 return mShowAirplaneMode; 70 } 71 getShowMissingSim()72 public boolean getShowMissingSim() { 73 return mShowMissingSim; 74 } 75 getDebugLocation()76 public String getDebugLocation() { 77 return mDebugLocation; 78 } 79 80 private static class CarrierTextTransformationMethod extends SingleLineTransformationMethod { 81 private final Locale mLocale; 82 private final boolean mAllCaps; 83 CarrierTextTransformationMethod(Context context, boolean allCaps)84 public CarrierTextTransformationMethod(Context context, boolean allCaps) { 85 mLocale = context.getResources().getConfiguration().locale; 86 mAllCaps = allCaps; 87 } 88 89 @Override getTransformation(CharSequence source, View view)90 public CharSequence getTransformation(CharSequence source, View view) { 91 source = super.getTransformation(source, view); 92 93 if (mAllCaps && source != null) { 94 source = source.toString().toUpperCase(mLocale); 95 } 96 97 return source; 98 } 99 } 100 } 101