Joe Onorato | c91460d | 2010-06-01 08:18:17 -0700 | [diff] [blame] | 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 | |
Joe Onorato | fd52b18 | 2010-11-10 18:00:52 -0800 | [diff] [blame] | 17 | package com.android.systemui.statusbar.phone; |
Joe Onorato | c91460d | 2010-06-01 08:18:17 -0700 | [diff] [blame] | 18 | |
| 19 | import android.content.BroadcastReceiver; |
| 20 | import android.content.Context; |
| 21 | import android.content.Intent; |
| 22 | import android.content.IntentFilter; |
Daniel Sandler | 18ac782 | 2012-06-11 16:07:18 -0400 | [diff] [blame] | 23 | import android.text.TextUtils; |
Joe Onorato | c91460d | 2010-06-01 08:18:17 -0700 | [diff] [blame] | 24 | import android.util.AttributeSet; |
| 25 | import android.util.Slog; |
| 26 | import android.view.View; |
| 27 | import android.widget.TextView; |
| 28 | |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 29 | import com.android.internal.telephony.TelephonyIntents; |
| 30 | |
Joe Onorato | c91460d | 2010-06-01 08:18:17 -0700 | [diff] [blame] | 31 | import java.text.SimpleDateFormat; |
| 32 | import java.util.Calendar; |
| 33 | import java.util.TimeZone; |
| 34 | |
| 35 | import com.android.internal.R; |
| 36 | |
| 37 | /** |
| 38 | * This widget display an analogic clock with two hands for hours and |
| 39 | * minutes. |
| 40 | */ |
| 41 | public 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 Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 64 | filter.addAction(TelephonyIntents.SPN_STRINGS_UPDATED_ACTION); |
Joe Onorato | c91460d | 2010-06-01 08:18:17 -0700 | [diff] [blame] | 65 | 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 Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 82 | 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 Onorato | c91460d | 2010-06-01 08:18:17 -0700 | [diff] [blame] | 87 | } |
| 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 Sandler | 18ac782 | 2012-06-11 16:07:18 -0400 | [diff] [blame] | 96 | 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 Onorato | c91460d | 2010-06-01 08:18:17 -0700 | [diff] [blame] | 106 | } else { |
Daniel Sandler | 18ac782 | 2012-06-11 16:07:18 -0400 | [diff] [blame] | 107 | str = ""; |
Joe Onorato | c91460d | 2010-06-01 08:18:17 -0700 | [diff] [blame] | 108 | } |
Daniel Sandler | 18ac782 | 2012-06-11 16:07:18 -0400 | [diff] [blame] | 109 | setText(str); |
Joe Onorato | c91460d | 2010-06-01 08:18:17 -0700 | [diff] [blame] | 110 | } |
| 111 | |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 112 | |
Joe Onorato | c91460d | 2010-06-01 08:18:17 -0700 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | |