• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.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 
CarrierText(Context context)36     public CarrierText(Context context) {
37         this(context, null);
38     }
39 
CarrierText(Context context, AttributeSet attrs)40     public CarrierText(Context context, AttributeSet attrs) {
41         super(context, attrs);
42         boolean useAllCaps;
43         TypedArray a = context.getTheme().obtainStyledAttributes(
44                 attrs, R.styleable.CarrierText, 0, 0);
45         try {
46             useAllCaps = a.getBoolean(R.styleable.CarrierText_allCaps, false);
47             mShowAirplaneMode = a.getBoolean(R.styleable.CarrierText_showAirplaneMode, false);
48             mShowMissingSim = a.getBoolean(R.styleable.CarrierText_showMissingSim, false);
49         } finally {
50             a.recycle();
51         }
52         setTransformationMethod(new CarrierTextTransformationMethod(mContext, useAllCaps));
53     }
54     @Override
onVisibilityChanged(View changedView, int visibility)55     protected void onVisibilityChanged(View changedView, int visibility) {
56         super.onVisibilityChanged(changedView, visibility);
57         // Only show marquee when visible
58         if (visibility == VISIBLE) {
59             setEllipsize(TextUtils.TruncateAt.MARQUEE);
60         } else {
61             setEllipsize(TextUtils.TruncateAt.END);
62         }
63     }
64 
getShowAirplaneMode()65     public boolean getShowAirplaneMode() {
66         return mShowAirplaneMode;
67     }
68 
getShowMissingSim()69     public boolean getShowMissingSim() {
70         return mShowMissingSim;
71     }
72 
73     private static class CarrierTextTransformationMethod extends SingleLineTransformationMethod {
74         private final Locale mLocale;
75         private final boolean mAllCaps;
76 
CarrierTextTransformationMethod(Context context, boolean allCaps)77         public CarrierTextTransformationMethod(Context context, boolean allCaps) {
78             mLocale = context.getResources().getConfiguration().locale;
79             mAllCaps = allCaps;
80         }
81 
82         @Override
getTransformation(CharSequence source, View view)83         public CharSequence getTransformation(CharSequence source, View view) {
84             source = super.getTransformation(source, view);
85 
86             if (mAllCaps && source != null) {
87                 source = source.toString().toUpperCase(mLocale);
88             }
89 
90             return source;
91         }
92     }
93 }
94