1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 * except in compliance with the License. You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software distributed under the 10 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 11 * KIND, either express or implied. See the License for the specific language governing 12 * permissions and limitations under the License. 13 */ 14 15 package com.android.systemui.statusbar; 16 17 import android.content.Context; 18 import android.text.TextUtils; 19 import android.util.AttributeSet; 20 import android.widget.TextView; 21 22 /** Shows the operator name */ 23 public class OperatorNameView extends TextView { 24 private boolean mDemoMode; 25 OperatorNameView(Context context)26 public OperatorNameView(Context context) { 27 this(context, null); 28 } 29 OperatorNameView(Context context, AttributeSet attrs)30 public OperatorNameView(Context context, AttributeSet attrs) { 31 this(context, attrs, 0); 32 } 33 OperatorNameView(Context context, AttributeSet attrs, int defStyle)34 public OperatorNameView(Context context, AttributeSet attrs, int defStyle) { 35 super(context, attrs, defStyle); 36 } 37 setDemoMode(boolean demoMode)38 void setDemoMode(boolean demoMode) { 39 mDemoMode = demoMode; 40 } 41 update( boolean showOperatorName, boolean hasMobile, boolean airplaneMode, OperatorNameViewController.SubInfo sub )42 void update( 43 boolean showOperatorName, 44 boolean hasMobile, 45 boolean airplaneMode, 46 OperatorNameViewController.SubInfo sub 47 ) { 48 setVisibility(showOperatorName ? VISIBLE : GONE); 49 50 if (!hasMobile || airplaneMode) { 51 setText(null); 52 setVisibility(GONE); 53 return; 54 } 55 56 if (!mDemoMode) { 57 updateText(sub); 58 } 59 } 60 updateText(OperatorNameViewController.SubInfo subInfo)61 void updateText(OperatorNameViewController.SubInfo subInfo) { 62 CharSequence carrierName = null; 63 CharSequence displayText = null; 64 if (subInfo != null) { 65 carrierName = subInfo.getCarrierName(); 66 } 67 if (!TextUtils.isEmpty(carrierName) && subInfo.simReady()) { 68 if (subInfo.stateInService()) { 69 displayText = carrierName; 70 } 71 } 72 setText(displayText); 73 } 74 } 75