blob: 66494e4594825ff45a7fd793bf19a11b5631a9e0 [file] [log] [blame]
Joe Onoratoc91460d2010-06-01 08:18:17 -07001/*
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
Joe Onoratofd52b182010-11-10 18:00:52 -080017package com.android.systemui.statusbar.phone;
Joe Onoratoc91460d2010-06-01 08:18:17 -070018
19import android.content.BroadcastReceiver;
20import android.content.Context;
21import android.content.Intent;
22import android.content.IntentFilter;
Daniel Sandler18ac7822012-06-11 16:07:18 -040023import android.text.TextUtils;
Joe Onoratoc91460d2010-06-01 08:18:17 -070024import android.util.AttributeSet;
25import android.util.Slog;
26import android.view.View;
27import android.widget.TextView;
28
Wink Savillea639b312012-07-10 12:37:54 -070029import com.android.internal.telephony.TelephonyIntents;
30
Joe Onoratoc91460d2010-06-01 08:18:17 -070031import java.text.SimpleDateFormat;
32import java.util.Calendar;
33import java.util.TimeZone;
34
35import com.android.internal.R;
36
37/**
38 * This widget display an analogic clock with two hands for hours and
39 * minutes.
40 */
41public class CarrierLabel extends TextView {
42 private boolean mAttached;
43
44 public CarrierLabel(Context context) {
45 this(context, null);
46 }
47
48 public CarrierLabel(Context context, AttributeSet attrs) {
49 this(context, attrs, 0);
50 }
51
52 public CarrierLabel(Context context, AttributeSet attrs, int defStyle) {
53 super(context, attrs, defStyle);
54 updateNetworkName(false, null, false, null);
55 }
56
57 @Override
58 protected void onAttachedToWindow() {
59 super.onAttachedToWindow();
60
61 if (!mAttached) {
62 mAttached = true;
63 IntentFilter filter = new IntentFilter();
Wink Savillea639b312012-07-10 12:37:54 -070064 filter.addAction(TelephonyIntents.SPN_STRINGS_UPDATED_ACTION);
Joe Onoratoc91460d2010-06-01 08:18:17 -070065 getContext().registerReceiver(mIntentReceiver, filter, null, getHandler());
66 }
67 }
68
69 @Override
70 protected void onDetachedFromWindow() {
71 super.onDetachedFromWindow();
72 if (mAttached) {
73 getContext().unregisterReceiver(mIntentReceiver);
74 mAttached = false;
75 }
76 }
77
78 private final BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
79 @Override
80 public void onReceive(Context context, Intent intent) {
81 String action = intent.getAction();
Wink Savillea639b312012-07-10 12:37:54 -070082 if (TelephonyIntents.SPN_STRINGS_UPDATED_ACTION.equals(action)) {
83 updateNetworkName(intent.getBooleanExtra(TelephonyIntents.EXTRA_SHOW_SPN, false),
84 intent.getStringExtra(TelephonyIntents.EXTRA_SPN),
85 intent.getBooleanExtra(TelephonyIntents.EXTRA_SHOW_PLMN, false),
86 intent.getStringExtra(TelephonyIntents.EXTRA_PLMN));
Joe Onoratoc91460d2010-06-01 08:18:17 -070087 }
88 }
89 };
90
91 void updateNetworkName(boolean showSpn, String spn, boolean showPlmn, String plmn) {
92 if (false) {
93 Slog.d("CarrierLabel", "updateNetworkName showSpn=" + showSpn + " spn=" + spn
94 + " showPlmn=" + showPlmn + " plmn=" + plmn);
95 }
Daniel Sandler18ac7822012-06-11 16:07:18 -040096 final String str;
97 // match logic in KeyguardStatusViewManager
98 final boolean plmnValid = showPlmn && !TextUtils.isEmpty(plmn);
99 final boolean spnValid = showSpn && !TextUtils.isEmpty(spn);
100 if (plmnValid && spnValid) {
101 str = plmn + "|" + spn;
102 } else if (plmnValid) {
103 str = plmn;
104 } else if (spnValid) {
105 str = spn;
Joe Onoratoc91460d2010-06-01 08:18:17 -0700106 } else {
Daniel Sandler18ac7822012-06-11 16:07:18 -0400107 str = "";
Joe Onoratoc91460d2010-06-01 08:18:17 -0700108 }
Daniel Sandler18ac7822012-06-11 16:07:18 -0400109 setText(str);
Joe Onoratoc91460d2010-06-01 08:18:17 -0700110 }
111
Wink Savillea639b312012-07-10 12:37:54 -0700112
Joe Onoratoc91460d2010-06-01 08:18:17 -0700113}
114
115