1 /* 2 * Copyright (C) 2006 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.systemui.statusbar.phone; 18 19 import android.content.BroadcastReceiver; 20 import android.content.Context; 21 import android.content.Intent; 22 import android.content.IntentFilter; 23 import android.provider.Telephony; 24 import android.text.TextUtils; 25 import android.util.AttributeSet; 26 import android.util.Slog; 27 import android.view.View; 28 import android.widget.TextView; 29 30 import java.text.SimpleDateFormat; 31 import java.util.Calendar; 32 import java.util.TimeZone; 33 34 import com.android.internal.R; 35 36 /** 37 * This widget display an analogic clock with two hands for hours and 38 * minutes. 39 */ 40 public class CarrierLabel extends TextView { 41 private boolean mAttached; 42 43 public CarrierLabel(Context context) { 44 this(context, null); 45 } 46 47 public CarrierLabel(Context context, AttributeSet attrs) { 48 this(context, attrs, 0); 49 } 50 51 public CarrierLabel(Context context, AttributeSet attrs, int defStyle) { 52 super(context, attrs, defStyle); 53 updateNetworkName(false, null, false, null); 54 } 55 56 @Override 57 protected void onAttachedToWindow() { 58 super.onAttachedToWindow(); 59 60 if (!mAttached) { 61 mAttached = true; 62 IntentFilter filter = new IntentFilter(); 63 filter.addAction(Telephony.Intents.SPN_STRINGS_UPDATED_ACTION); 64 getContext().registerReceiver(mIntentReceiver, filter, null, getHandler()); 65 } 66 } 67 68 @Override 69 protected void onDetachedFromWindow() { 70 super.onDetachedFromWindow(); 71 if (mAttached) { 72 getContext().unregisterReceiver(mIntentReceiver); 73 mAttached = false; 74 } 75 } 76 77 private final BroadcastReceiver mIntentReceiver = new BroadcastReceiver() { 78 @Override 79 public void onReceive(Context context, Intent intent) { 80 String action = intent.getAction(); 81 if (Telephony.Intents.SPN_STRINGS_UPDATED_ACTION.equals(action)) { 82 updateNetworkName(intent.getBooleanExtra(Telephony.Intents.EXTRA_SHOW_SPN, false), 83 intent.getStringExtra(Telephony.Intents.EXTRA_SPN), 84 intent.getBooleanExtra(Telephony.Intents.EXTRA_SHOW_PLMN, false), 85 intent.getStringExtra(Telephony.Intents.EXTRA_PLMN)); 86 } 87 } 88 }; 89 90 void updateNetworkName(boolean showSpn, String spn, boolean showPlmn, String plmn) { 91 if (false) { 92 Slog.d("CarrierLabel", "updateNetworkName showSpn=" + showSpn + " spn=" + spn 93 + " showPlmn=" + showPlmn + " plmn=" + plmn); 94 } 95 final String str; 96 // match logic in KeyguardStatusViewManager 97 final boolean plmnValid = showPlmn && !TextUtils.isEmpty(plmn); 98 final boolean spnValid = showSpn && !TextUtils.isEmpty(spn); 99 if (plmnValid && spnValid) { 100 str = plmn + "|" + spn; 101 } else if (plmnValid) { 102 str = plmn; 103 } else if (spnValid) { 104 str = spn; 105 } else { 106 str = ""; 107 } 108 setText(str); 109 } 110 111 112 } 113 114 115