1 /* 2 * Copyright (C) 2019 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.qs; 18 19 import android.content.Context; 20 import android.content.res.ColorStateList; 21 import android.text.TextUtils; 22 import android.util.AttributeSet; 23 import android.view.View; 24 import android.widget.ImageView; 25 import android.widget.LinearLayout; 26 import android.widget.TextView; 27 28 import com.android.settingslib.Utils; 29 import com.android.settingslib.graph.SignalDrawable; 30 import com.android.systemui.DualToneHandler; 31 import com.android.systemui.R; 32 33 public class QSCarrier extends LinearLayout { 34 35 private View mMobileGroup; 36 private TextView mCarrierText; 37 private ImageView mMobileSignal; 38 private ImageView mMobileRoaming; 39 private DualToneHandler mDualToneHandler; 40 private ColorStateList mColorForegroundStateList; 41 private float mColorForegroundIntensity; 42 QSCarrier(Context context)43 public QSCarrier(Context context) { 44 super(context); 45 } 46 QSCarrier(Context context, AttributeSet attrs)47 public QSCarrier(Context context, AttributeSet attrs) { 48 super(context, attrs); 49 } 50 QSCarrier(Context context, AttributeSet attrs, int defStyleAttr)51 public QSCarrier(Context context, AttributeSet attrs, int defStyleAttr) { 52 super(context, attrs, defStyleAttr); 53 } 54 QSCarrier(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)55 public QSCarrier(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 56 super(context, attrs, defStyleAttr, defStyleRes); 57 } 58 59 @Override onFinishInflate()60 protected void onFinishInflate() { 61 super.onFinishInflate(); 62 mDualToneHandler = new DualToneHandler(getContext()); 63 mMobileGroup = findViewById(R.id.mobile_combo); 64 mMobileSignal = findViewById(R.id.mobile_signal); 65 mMobileRoaming = findViewById(R.id.mobile_roaming); 66 mCarrierText = findViewById(R.id.qs_carrier_text); 67 68 int colorForeground = Utils.getColorAttrDefaultColor(mContext, 69 android.R.attr.colorForeground); 70 mColorForegroundStateList = ColorStateList.valueOf(colorForeground); 71 mColorForegroundIntensity = QuickStatusBarHeader.getColorIntensity(colorForeground); 72 } 73 updateState(QSCarrierGroup.CellSignalState state)74 public void updateState(QSCarrierGroup.CellSignalState state) { 75 mMobileGroup.setVisibility(state.visible ? View.VISIBLE : View.GONE); 76 if (state.visible) { 77 mMobileRoaming.setVisibility(state.roaming ? View.VISIBLE : View.GONE); 78 ColorStateList colorStateList = ColorStateList.valueOf( 79 mDualToneHandler.getSingleColor(mColorForegroundIntensity)); 80 mMobileRoaming.setImageTintList(colorStateList); 81 mMobileSignal.setImageDrawable(new SignalDrawable(mContext)); 82 mMobileSignal.setImageTintList(colorStateList); 83 mMobileSignal.setImageLevel(state.mobileSignalIconId); 84 85 StringBuilder contentDescription = new StringBuilder(); 86 if (state.contentDescription != null) { 87 contentDescription.append(state.contentDescription).append(", "); 88 } 89 if (state.roaming) { 90 contentDescription 91 .append(mContext.getString(R.string.data_connection_roaming)) 92 .append(", "); 93 } 94 // TODO: show mobile data off/no internet text for 5 seconds before carrier text 95 if (hasValidTypeContentDescription(state.typeContentDescription)) { 96 contentDescription.append(state.typeContentDescription); 97 } 98 mMobileSignal.setContentDescription(contentDescription); 99 } 100 } 101 hasValidTypeContentDescription(String typeContentDescription)102 private boolean hasValidTypeContentDescription(String typeContentDescription) { 103 return TextUtils.equals(typeContentDescription, 104 mContext.getString(R.string.data_connection_no_internet)) 105 || TextUtils.equals(typeContentDescription, 106 mContext.getString(R.string.cell_data_off_content_description)) 107 || TextUtils.equals(typeContentDescription, 108 mContext.getString(R.string.not_default_data_content_description)); 109 } 110 setCarrierText(CharSequence text)111 public void setCarrierText(CharSequence text) { 112 mCarrierText.setText(text); 113 } 114 } 115