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 import com.android.settingslib.WirelessUtils; 23 24 /** Shows the operator name */ 25 public class OperatorNameView extends TextView { 26 private boolean mDemoMode; 27 OperatorNameView(Context context)28 public OperatorNameView(Context context) { 29 this(context, null); 30 } 31 OperatorNameView(Context context, AttributeSet attrs)32 public OperatorNameView(Context context, AttributeSet attrs) { 33 this(context, attrs, 0); 34 } 35 OperatorNameView(Context context, AttributeSet attrs, int defStyle)36 public OperatorNameView(Context context, AttributeSet attrs, int defStyle) { 37 super(context, attrs, defStyle); 38 } 39 setDemoMode(boolean demoMode)40 void setDemoMode(boolean demoMode) { 41 mDemoMode = demoMode; 42 } 43 update(boolean showOperatorName, boolean hasMobile, OperatorNameViewController.SubInfo sub )44 void update(boolean showOperatorName, 45 boolean hasMobile, 46 OperatorNameViewController.SubInfo sub 47 ) { 48 setVisibility(showOperatorName ? VISIBLE : GONE); 49 50 boolean airplaneMode = WirelessUtils.isAirplaneModeOn(mContext); 51 if (!hasMobile || airplaneMode) { 52 setText(null); 53 setVisibility(GONE); 54 return; 55 } 56 57 if (!mDemoMode) { 58 updateText(sub); 59 } 60 } 61 updateText(OperatorNameViewController.SubInfo subInfo)62 void updateText(OperatorNameViewController.SubInfo subInfo) { 63 CharSequence carrierName = null; 64 CharSequence displayText = null; 65 if (subInfo != null) { 66 carrierName = subInfo.getCarrierName(); 67 } 68 if (!TextUtils.isEmpty(carrierName) && subInfo.simReady()) { 69 if (subInfo.stateInService()) { 70 displayText = carrierName; 71 } 72 } 73 setText(displayText); 74 } 75 } 76