blob: 3ff30c527f39f56be8951fe5eac4453513d46b36 [file] [log] [blame]
Fabian Kozynskia48d2d02019-02-27 11:36:02 -05001/*
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
17package com.android.systemui.qs;
18
19import android.content.Context;
20import android.content.res.ColorStateList;
21import android.text.TextUtils;
22import android.util.AttributeSet;
23import android.view.View;
24import android.widget.ImageView;
25import android.widget.LinearLayout;
26import android.widget.TextView;
27
28import com.android.settingslib.Utils;
29import com.android.settingslib.graph.SignalDrawable;
30import com.android.systemui.R;
31
32public class QSCarrier extends LinearLayout {
33
34 private View mMobileGroup;
Fabian Kozynski4e76d1f2019-02-25 16:30:04 -050035 private QSCarrierText mCarrierText;
Fabian Kozynskia48d2d02019-02-27 11:36:02 -050036 private ImageView mMobileSignal;
37 private ImageView mMobileRoaming;
38 private ColorStateList mColorForegroundStateList;
39 private float mColorForegroundIntensity;
40
41 public QSCarrier(Context context) {
42 super(context);
43 }
44
45 public QSCarrier(Context context, AttributeSet attrs) {
46 super(context, attrs);
47 }
48
49 public QSCarrier(Context context, AttributeSet attrs, int defStyleAttr) {
50 super(context, attrs, defStyleAttr);
51 }
52
53 public QSCarrier(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
54 super(context, attrs, defStyleAttr, defStyleRes);
55 }
56
57 @Override
58 protected void onFinishInflate() {
59 super.onFinishInflate();
60 mMobileGroup = findViewById(R.id.mobile_combo);
61 mMobileSignal = findViewById(R.id.mobile_signal);
62 mMobileRoaming = findViewById(R.id.mobile_roaming);
63 mCarrierText = findViewById(R.id.qs_carrier_text);
64
65 int colorForeground = Utils.getColorAttrDefaultColor(mContext,
66 android.R.attr.colorForeground);
67 mColorForegroundStateList = ColorStateList.valueOf(colorForeground);
68 mColorForegroundIntensity = QuickStatusBarHeader.getColorIntensity(colorForeground);
69
70 }
71
72 public void updateState(QSCarrierGroup.CellSignalState state) {
73 mMobileGroup.setVisibility(state.visible ? View.VISIBLE : View.GONE);
74 if (state.visible) {
75 mMobileRoaming.setVisibility(state.roaming ? View.VISIBLE : View.GONE);
76 mMobileRoaming.setImageTintList(mColorForegroundStateList);
77 SignalDrawable d = new SignalDrawable(mContext);
78 d.setDarkIntensity(mColorForegroundIntensity);
79 mMobileSignal.setImageDrawable(d);
80 mMobileSignal.setImageLevel(state.mobileSignalIconId);
81
82 StringBuilder contentDescription = new StringBuilder();
83 if (state.contentDescription != null) {
84 contentDescription.append(state.contentDescription).append(", ");
85 }
86 if (state.roaming) {
87 contentDescription
88 .append(mContext.getString(R.string.data_connection_roaming))
89 .append(", ");
90 }
91 // TODO: show mobile data off/no internet text for 5 seconds before carrier text
92 if (TextUtils.equals(state.typeContentDescription,
93 mContext.getString(R.string.data_connection_no_internet))
94 || TextUtils.equals(state.typeContentDescription,
95 mContext.getString(R.string.cell_data_off_content_description))) {
96 contentDescription.append(state.typeContentDescription);
97 }
98 mMobileSignal.setContentDescription(contentDescription);
99 }
100 }
101
102 public void setCarrierText(CharSequence text) {
103 mCarrierText.setText(text);
104 }
105
106 /**
107 * TextView that changes its ellipsize value with its visibility.
108 */
109 public static class QSCarrierText extends TextView {
Fabian Kozynski4e76d1f2019-02-25 16:30:04 -0500110
Fabian Kozynskia48d2d02019-02-27 11:36:02 -0500111 public QSCarrierText(Context context) {
112 super(context);
113 }
114
115 public QSCarrierText(Context context, AttributeSet attrs) {
116 super(context, attrs);
117 }
118
119 public QSCarrierText(Context context, AttributeSet attrs, int defStyleAttr) {
120 super(context, attrs, defStyleAttr);
121 }
122
123 public QSCarrierText(Context context, AttributeSet attrs, int defStyleAttr,
124 int defStyleRes) {
125 super(context, attrs, defStyleAttr, defStyleRes);
126 }
127
128 @Override
129 protected void onVisibilityChanged(View changedView, int visibility) {
130 super.onVisibilityChanged(changedView, visibility);
131 // Only show marquee when visible
132 if (visibility == VISIBLE) {
133 setEllipsize(TextUtils.TruncateAt.MARQUEE);
134 setSelected(true);
135 } else {
136 setEllipsize(TextUtils.TruncateAt.END);
137 setSelected(false);
138 }
139 }
140 }
141}