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