| /* |
| * Copyright (c) 2012-2014 The Linux Foundation. All rights reserved. |
| * Not a Contribution. |
| * Copyright (C) 2011 The Android Open Source Project |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| */ |
| |
| package com.android.systemui.statusbar; |
| |
| import android.content.Context; |
| import android.graphics.PorterDuff; |
| import android.graphics.PorterDuffColorFilter; |
| import android.os.Build; |
| import android.telephony.SubscriptionManager; |
| import android.telephony.TelephonyManager; |
| import android.util.AttributeSet; |
| import android.util.Slog; |
| import android.view.accessibility.AccessibilityEvent; |
| import android.view.View; |
| import android.view.ViewGroup; |
| import android.widget.ImageView; |
| import android.widget.LinearLayout; |
| |
| import com.android.internal.telephony.PhoneConstants; |
| import com.android.systemui.statusbar.policy.NetworkControllerImpl; |
| import com.android.systemui.statusbar.policy.MSimNetworkControllerImpl; |
| |
| import com.android.systemui.R; |
| |
| |
| // Intimately tied to the design of res/layout/msim_signal_cluster_view.xml |
| public class MSimSignalClusterView |
| extends LinearLayout |
| implements MSimNetworkControllerImpl.MSimSignalCluster { |
| |
| static final boolean DEBUG = true; |
| static final String TAG = "MSimSignalClusterView"; |
| |
| |
| MSimNetworkControllerImpl mMSimNC; |
| |
| private boolean mWifiVisible = false; |
| private int mWifiStrengthId = 0; |
| private boolean mMobileVisible = false; |
| private int[] mMobileStrengthId; |
| private int[] mMobileActivityId; |
| private int[] mMobileTypeId; |
| private int[] mNoSimIconId; |
| private boolean mIsAirplaneMode = false; |
| private int mAirplaneIconId = 0; |
| private String mWifiDescription, mMobileTypeDescription; |
| private String[] mMobileDescription; |
| |
| ViewGroup mWifiGroup; |
| ViewGroup[] mMobileGroup; |
| ImageView mWifi, mAirplane; |
| ImageView[] mNoSimSlot; |
| ImageView[] mMobile; |
| ImageView[] mMobileActivity; |
| ImageView[] mMobileType; |
| View mSpacer; |
| private int[] mMobileGroupResourceId = {R.id.mobile_combo, R.id.mobile_combo_sub2, |
| R.id.mobile_combo_sub3}; |
| private int[] mMobileResourceId = {R.id.mobile_signal, R.id.mobile_signal_sub2, |
| R.id.mobile_signal_sub3}; |
| private int[] mMobileActResourceId = {R.id.mobile_inout, R.id.mobile_inout_sub2, |
| R.id.mobile_inout_sub3}; |
| private int[] mMobileTypeResourceId = {R.id.mobile_type, R.id.mobile_type_sub2, |
| R.id.mobile_type_sub3}; |
| private int[] mNoSimSlotResourceId = {R.id.no_sim, R.id.no_sim_slot2, R.id.no_sim_slot3}; |
| private int mNumPhones = TelephonyManager.getDefault().getPhoneCount(); |
| |
| public MSimSignalClusterView(Context context) { |
| this(context, null); |
| } |
| |
| public MSimSignalClusterView(Context context, AttributeSet attrs) { |
| this(context, attrs, 0); |
| } |
| |
| public MSimSignalClusterView(Context context, AttributeSet attrs, int defStyle) { |
| super(context, attrs, defStyle); |
| mMobileStrengthId = new int[mNumPhones]; |
| mMobileDescription = new String[mNumPhones]; |
| mMobileTypeId = new int[mNumPhones]; |
| mMobileActivityId = new int[mNumPhones]; |
| mNoSimIconId = new int[mNumPhones]; |
| mMobileGroup = new ViewGroup[mNumPhones]; |
| mNoSimSlot = new ImageView[mNumPhones]; |
| mMobile = new ImageView[mNumPhones]; |
| mMobileActivity = new ImageView[mNumPhones]; |
| mMobileType = new ImageView[mNumPhones]; |
| for (int i=0; i < mNumPhones; i++) { |
| mMobileStrengthId[i] = 0; |
| mMobileTypeId[i] = 0; |
| mMobileActivityId[i] = 0; |
| mNoSimIconId[i] = 0; |
| } |
| } |
| |
| public void setNetworkController(MSimNetworkControllerImpl nc) { |
| if (DEBUG) Slog.d(TAG, "MSimNetworkController=" + nc); |
| mMSimNC = nc; |
| } |
| |
| @Override |
| protected void onAttachedToWindow() { |
| super.onAttachedToWindow(); |
| |
| mWifiGroup = (ViewGroup) findViewById(R.id.wifi_combo); |
| mWifi = (ImageView) findViewById(R.id.wifi_signal); |
| mSpacer = findViewById(R.id.spacer); |
| mAirplane = (ImageView) findViewById(R.id.airplane); |
| |
| for (int i = 0; i < mNumPhones; i++) { |
| mMobileGroup[i] = (ViewGroup) findViewById(mMobileGroupResourceId[i]); |
| mMobile[i] = (ImageView) findViewById(mMobileResourceId[i]); |
| mMobileActivity[i] = (ImageView) findViewById(mMobileActResourceId[i]); |
| mMobileType[i] = (ImageView) findViewById(mMobileTypeResourceId[i]); |
| mNoSimSlot[i] = (ImageView) findViewById(mNoSimSlotResourceId[i]); |
| } |
| for (int i = 0; i < mNumPhones; i++) { |
| apply(i); |
| } |
| } |
| |
| @Override |
| protected void onDetachedFromWindow() { |
| mWifiGroup = null; |
| mWifi = null; |
| mSpacer = null; |
| mAirplane = null; |
| for (int i = 0; i < mNumPhones; i++) { |
| mMobileGroup[i] = null; |
| mMobile[i] = null; |
| mMobileActivity[i] = null; |
| mMobileType[i] = null; |
| mNoSimSlot[i] = null; |
| } |
| super.onDetachedFromWindow(); |
| } |
| |
| @Override |
| public void setWifiIndicators(boolean visible, int strengthIcon, String contentDescription) { |
| mWifiVisible = visible; |
| mWifiStrengthId = strengthIcon; |
| mWifiDescription = contentDescription; |
| for (int i = 0; i < mNumPhones; i++) { |
| apply(i); |
| } |
| } |
| |
| @Override |
| public void setMobileDataIndicators(boolean visible, int strengthIcon, int typeIcon, |
| String contentDescription, String typeContentDescription, |
| int phoneId) { |
| mMobileVisible = visible; |
| mMobileStrengthId[phoneId] = strengthIcon; |
| mMobileTypeId[phoneId] = typeIcon; |
| mMobileDescription[phoneId] = contentDescription; |
| mMobileTypeDescription = typeContentDescription; |
| |
| apply(phoneId); |
| } |
| |
| @Override |
| public void setIsAirplaneMode(boolean is, int airplaneIconId) { |
| mIsAirplaneMode = is; |
| mAirplaneIconId = airplaneIconId; |
| for (int i = 0; i < mNumPhones; i++) { |
| apply(i); |
| } |
| } |
| |
| @Override |
| public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { |
| int defaultPhoneId = getDefaultPhoneId(); |
| // Standard group layout onPopulateAccessibilityEvent() implementations |
| // ignore content description, so populate manually |
| if (mWifiVisible && mWifiGroup != null && |
| mWifiGroup.getContentDescription() != null) |
| event.getText().add(mWifiGroup.getContentDescription()); |
| if (mMobileVisible && mMobileGroup[defaultPhoneId] != null |
| && mMobileGroup[defaultPhoneId] |
| .getContentDescription() != null) |
| event.getText().add(mMobileGroup[defaultPhoneId]. |
| getContentDescription()); |
| return super.dispatchPopulateAccessibilityEvent(event); |
| } |
| |
| @Override |
| public boolean hasOverlappingRendering() { |
| return false; |
| } |
| |
| private int getDefaultPhoneId() { |
| int phoneId; |
| phoneId = getPhoneId(SubscriptionManager.getDefaultSubId()); |
| if ( phoneId < 0 || phoneId >= mNumPhones) { |
| phoneId = 0; |
| } |
| return phoneId; |
| } |
| |
| |
| private int getPhoneId(long subId) { |
| int phoneId; |
| phoneId = SubscriptionManager.getPhoneId(subId); |
| return phoneId; |
| } |
| |
| |
| // Run after each indicator change. |
| private void apply(int phoneId) { |
| if (mWifiGroup == null) return; |
| |
| if (mWifiVisible) { |
| mWifiGroup.setVisibility(View.VISIBLE); |
| mWifi.setImageResource(mWifiStrengthId); |
| mWifiGroup.setContentDescription(mWifiDescription); |
| } else { |
| mWifiGroup.setVisibility(View.GONE); |
| } |
| |
| if (DEBUG) Slog.d(TAG, |
| String.format("wifi: %s sig=%d ", |
| (mWifiVisible ? "VISIBLE" : "GONE"), mWifiStrengthId)); |
| |
| if (mMobileVisible && !mIsAirplaneMode) { |
| mMobileGroup[phoneId].setVisibility(View.VISIBLE); |
| mMobile[phoneId].setImageResource(mMobileStrengthId[phoneId]); |
| mMobileGroup[phoneId].setContentDescription(mMobileTypeDescription + " " |
| + mMobileDescription[phoneId]); |
| mMobileActivity[phoneId].setImageResource(mMobileActivityId[phoneId]); |
| mMobileType[phoneId].setImageResource(mMobileTypeId[phoneId]); |
| mMobileType[phoneId].setVisibility( |
| !mWifiVisible ? View.VISIBLE : View.GONE); |
| mNoSimSlot[phoneId].setImageResource(mNoSimIconId[phoneId]); |
| } else { |
| mMobileGroup[phoneId].setVisibility(View.GONE); |
| } |
| |
| if (mIsAirplaneMode) { |
| mAirplane.setVisibility(View.VISIBLE); |
| mAirplane.setImageResource(mAirplaneIconId); |
| } else { |
| mAirplane.setVisibility(View.GONE); |
| } |
| |
| if (phoneId != 0) { |
| if (mMobileVisible && mWifiVisible && ((mIsAirplaneMode) || |
| (mNoSimIconId[phoneId] != 0))) { |
| mSpacer.setVisibility(View.INVISIBLE); |
| } else { |
| mSpacer.setVisibility(View.GONE); |
| } |
| } |
| |
| } |
| } |
| |