Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 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.statusbar.phone; |
| 18 | |
| 19 | import android.app.AlarmManager; |
| 20 | import android.app.PendingIntent; |
| 21 | import android.content.Context; |
| 22 | import android.content.Intent; |
Jason Monk | dbd8817 | 2016-02-17 15:20:29 -0500 | [diff] [blame] | 23 | import android.content.res.Configuration; |
Jason Monk | 69e76cc | 2016-01-26 10:56:37 -0500 | [diff] [blame] | 24 | import android.graphics.drawable.Drawable; |
Jason Monk | 94a1bf6 | 2015-10-20 08:43:36 -0700 | [diff] [blame] | 25 | import android.graphics.drawable.RippleDrawable; |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 26 | import android.util.AttributeSet; |
| 27 | import android.view.View; |
Jason Monk | 97cb9c7 | 2016-02-17 16:41:01 -0500 | [diff] [blame] | 28 | import android.view.View.OnClickListener; |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 29 | import android.view.ViewGroup; |
| 30 | import android.widget.ImageView; |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 31 | import android.widget.TextView; |
| 32 | import android.widget.Toast; |
Jason Monk | deba7a4 | 2015-12-08 16:14:10 -0500 | [diff] [blame] | 33 | import com.android.keyguard.KeyguardStatusView; |
Jason Monk | dbd8817 | 2016-02-17 15:20:29 -0500 | [diff] [blame] | 34 | import com.android.systemui.FontSizeUtils; |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 35 | import com.android.systemui.R; |
Jason Monk | 162011e | 2016-02-19 08:11:55 -0500 | [diff] [blame] | 36 | import com.android.systemui.qs.QSAnimator; |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 37 | import com.android.systemui.qs.QSPanel; |
Jason Monk | dc35dcb | 2015-12-04 16:36:15 -0500 | [diff] [blame] | 38 | import com.android.systemui.qs.QuickQSPanel; |
Jason Monk | 97cb9c7 | 2016-02-17 16:41:01 -0500 | [diff] [blame] | 39 | import com.android.systemui.qs.TouchAnimator; |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 40 | import com.android.systemui.statusbar.policy.BatteryController; |
| 41 | import com.android.systemui.statusbar.policy.NextAlarmController; |
Jason Monk | 97cb9c7 | 2016-02-17 16:41:01 -0500 | [diff] [blame] | 42 | import com.android.systemui.statusbar.policy.NextAlarmController.NextAlarmChangeCallback; |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 43 | import com.android.systemui.statusbar.policy.UserInfoController; |
Jason Monk | 46dbfb4 | 2016-02-25 14:59:20 -0500 | [diff] [blame] | 44 | import com.android.systemui.statusbar.policy.UserInfoController.OnUserInfoChangedListener; |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 45 | import com.android.systemui.tuner.TunerService; |
| 46 | |
| 47 | public class QuickStatusBarHeader extends BaseStatusBarHeader implements |
Jason Monk | df5459d | 2016-02-29 10:47:35 -0500 | [diff] [blame] | 48 | NextAlarmChangeCallback, OnClickListener { |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 49 | |
Jason Monk | deba7a4 | 2015-12-08 16:14:10 -0500 | [diff] [blame] | 50 | private static final String TAG = "QuickStatusBarHeader"; |
Jason Monk | 97cb9c7 | 2016-02-17 16:41:01 -0500 | [diff] [blame] | 51 | |
Jason Monk | 162011e | 2016-02-19 08:11:55 -0500 | [diff] [blame] | 52 | private static final float EXPAND_INDICATOR_THRESHOLD = .93f; |
Jason Monk | 97cb9c7 | 2016-02-17 16:41:01 -0500 | [diff] [blame] | 53 | |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 54 | private ActivityStarter mActivityStarter; |
| 55 | private NextAlarmController mNextAlarmController; |
| 56 | private SettingsButton mSettingsButton; |
| 57 | private View mSettingsContainer; |
Jason Monk | dbd8817 | 2016-02-17 15:20:29 -0500 | [diff] [blame] | 58 | |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 59 | private TextView mAlarmStatus; |
Jason Monk | dbd8817 | 2016-02-17 15:20:29 -0500 | [diff] [blame] | 60 | private TextView mAlarmStatusCollapsed; |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 61 | |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 62 | private QSPanel mQsPanel; |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 63 | |
| 64 | private boolean mExpanded; |
| 65 | private boolean mAlarmShowing; |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 66 | |
Jason Monk | ec9af01 | 2015-12-10 11:10:23 -0500 | [diff] [blame] | 67 | private ViewGroup mDateTimeGroup; |
Jason Monk | dbd8817 | 2016-02-17 15:20:29 -0500 | [diff] [blame] | 68 | private ViewGroup mDateTimeAlarmGroup; |
| 69 | private TextView mEmergencyOnly; |
| 70 | |
Xiaohui Chen | 311b98e | 2016-03-30 11:55:54 -0700 | [diff] [blame] | 71 | protected ExpandableIndicator mExpandIndicator; |
Jason Monk | 97cb9c7 | 2016-02-17 16:41:01 -0500 | [diff] [blame] | 72 | |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 73 | private boolean mListening; |
| 74 | private AlarmManager.AlarmClockInfo mNextAlarm; |
| 75 | |
Jason Monk | dc35dcb | 2015-12-04 16:36:15 -0500 | [diff] [blame] | 76 | private QuickQSPanel mHeaderQsPanel; |
Jason Monk | ec9af01 | 2015-12-10 11:10:23 -0500 | [diff] [blame] | 77 | private boolean mShowEmergencyCallsOnly; |
Jason Monk | 69e76cc | 2016-01-26 10:56:37 -0500 | [diff] [blame] | 78 | private MultiUserSwitch mMultiUserSwitch; |
| 79 | private ImageView mMultiUserAvatar; |
Jason Monk | db50de8 | 2016-02-03 15:34:54 -0500 | [diff] [blame] | 80 | |
Jason Monk | dbd8817 | 2016-02-17 15:20:29 -0500 | [diff] [blame] | 81 | private float mDateTimeTranslation; |
| 82 | private float mDateTimeAlarmTranslation; |
Jason Monk | dbd8817 | 2016-02-17 15:20:29 -0500 | [diff] [blame] | 83 | private float mDateScaleFactor; |
Jason Monk | 97cb9c7 | 2016-02-17 16:41:01 -0500 | [diff] [blame] | 84 | private float mGearTranslation; |
| 85 | |
Jason Monk | 97cb9c7 | 2016-02-17 16:41:01 -0500 | [diff] [blame] | 86 | private TouchAnimator mSecondHalfAnimator; |
| 87 | private TouchAnimator mFirstHalfAnimator; |
| 88 | private TouchAnimator mDateSizeAnimator; |
| 89 | private TouchAnimator mAlarmTranslation; |
Jason Monk | 162011e | 2016-02-19 08:11:55 -0500 | [diff] [blame] | 90 | private TouchAnimator mSettingsAlpha; |
Jason Monk | 97cb9c7 | 2016-02-17 16:41:01 -0500 | [diff] [blame] | 91 | private float mExpansionAmount; |
Jason Monk | 46dbfb4 | 2016-02-25 14:59:20 -0500 | [diff] [blame] | 92 | private QSTileHost mHost; |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 93 | |
| 94 | public QuickStatusBarHeader(Context context, AttributeSet attrs) { |
| 95 | super(context, attrs); |
| 96 | } |
| 97 | |
| 98 | @Override |
| 99 | protected void onFinishInflate() { |
| 100 | super.onFinishInflate(); |
| 101 | |
Jason Monk | dbd8817 | 2016-02-17 15:20:29 -0500 | [diff] [blame] | 102 | mEmergencyOnly = (TextView) findViewById(R.id.header_emergency_calls_only); |
| 103 | |
| 104 | mDateTimeAlarmGroup = (ViewGroup) findViewById(R.id.date_time_alarm_group); |
| 105 | mDateTimeAlarmGroup.findViewById(R.id.empty_time_view).setVisibility(View.GONE); |
Jason Monk | ec9af01 | 2015-12-10 11:10:23 -0500 | [diff] [blame] | 106 | mDateTimeGroup = (ViewGroup) findViewById(R.id.date_time_group); |
Jason Monk | 97cb9c7 | 2016-02-17 16:41:01 -0500 | [diff] [blame] | 107 | mDateTimeGroup.setPivotX(0); |
| 108 | mDateTimeGroup.setPivotY(0); |
Jason Monk | dbd8817 | 2016-02-17 15:20:29 -0500 | [diff] [blame] | 109 | |
Jason Monk | 97cb9c7 | 2016-02-17 16:41:01 -0500 | [diff] [blame] | 110 | mExpandIndicator = (ExpandableIndicator) findViewById(R.id.expand_indicator); |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 111 | |
Jason Monk | dc35dcb | 2015-12-04 16:36:15 -0500 | [diff] [blame] | 112 | mHeaderQsPanel = (QuickQSPanel) findViewById(R.id.quick_qs_panel); |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 113 | |
| 114 | mSettingsButton = (SettingsButton) findViewById(R.id.settings_button); |
| 115 | mSettingsContainer = findViewById(R.id.settings_button_container); |
| 116 | mSettingsButton.setOnClickListener(this); |
| 117 | |
Jason Monk | dbd8817 | 2016-02-17 15:20:29 -0500 | [diff] [blame] | 118 | mAlarmStatusCollapsed = (TextView) findViewById(R.id.alarm_status_collapsed); |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 119 | mAlarmStatus = (TextView) findViewById(R.id.alarm_status); |
| 120 | mAlarmStatus.setOnClickListener(this); |
| 121 | |
Jason Monk | 69e76cc | 2016-01-26 10:56:37 -0500 | [diff] [blame] | 122 | mMultiUserSwitch = (MultiUserSwitch) findViewById(R.id.multi_user_switch); |
| 123 | mMultiUserAvatar = (ImageView) mMultiUserSwitch.findViewById(R.id.multi_user_avatar); |
| 124 | |
Jason Monk | 94a1bf6 | 2015-10-20 08:43:36 -0700 | [diff] [blame] | 125 | // RenderThread is doing more harm than good when touching the header (to expand quick |
| 126 | // settings), so disable it for this view |
Jason Monk | 94a1bf6 | 2015-10-20 08:43:36 -0700 | [diff] [blame] | 127 | ((RippleDrawable) mSettingsButton.getBackground()).setForceSoftware(true); |
| 128 | |
Jason Monk | dbd8817 | 2016-02-17 15:20:29 -0500 | [diff] [blame] | 129 | updateResources(); |
| 130 | } |
| 131 | |
| 132 | @Override |
| 133 | protected void onConfigurationChanged(Configuration newConfig) { |
| 134 | super.onConfigurationChanged(newConfig); |
| 135 | updateResources(); |
| 136 | } |
| 137 | |
Jason Monk | 51fb85a | 2016-03-28 14:06:04 -0400 | [diff] [blame] | 138 | @Override |
| 139 | public void onRtlPropertiesChanged(int layoutDirection) { |
| 140 | super.onRtlPropertiesChanged(layoutDirection); |
| 141 | updateResources(); |
| 142 | } |
| 143 | |
Jason Monk | dbd8817 | 2016-02-17 15:20:29 -0500 | [diff] [blame] | 144 | private void updateResources() { |
| 145 | FontSizeUtils.updateFontSize(mAlarmStatus, R.dimen.qs_date_collapsed_size); |
| 146 | FontSizeUtils.updateFontSize(mEmergencyOnly, R.dimen.qs_emergency_calls_only_text_size); |
| 147 | |
Jason Monk | 97cb9c7 | 2016-02-17 16:41:01 -0500 | [diff] [blame] | 148 | mGearTranslation = mContext.getResources().getDimension(R.dimen.qs_header_gear_translation); |
| 149 | |
Jason Monk | dbd8817 | 2016-02-17 15:20:29 -0500 | [diff] [blame] | 150 | mDateTimeTranslation = mContext.getResources().getDimension( |
| 151 | R.dimen.qs_date_anim_translation); |
| 152 | mDateTimeAlarmTranslation = mContext.getResources().getDimension( |
| 153 | R.dimen.qs_date_alarm_anim_translation); |
| 154 | float dateCollapsedSize = mContext.getResources().getDimension( |
| 155 | R.dimen.qs_date_collapsed_text_size); |
| 156 | float dateExpandedSize = mContext.getResources().getDimension( |
| 157 | R.dimen.qs_date_text_size); |
Jason Monk | 97cb9c7 | 2016-02-17 16:41:01 -0500 | [diff] [blame] | 158 | mDateScaleFactor = dateExpandedSize / dateCollapsedSize; |
Jason Monk | dbd8817 | 2016-02-17 15:20:29 -0500 | [diff] [blame] | 159 | updateDateTimePosition(); |
Jason Monk | 97cb9c7 | 2016-02-17 16:41:01 -0500 | [diff] [blame] | 160 | |
Jason Monk | 97cb9c7 | 2016-02-17 16:41:01 -0500 | [diff] [blame] | 161 | mSecondHalfAnimator = new TouchAnimator.Builder() |
Jason Monk | 97cb9c7 | 2016-02-17 16:41:01 -0500 | [diff] [blame] | 162 | .addFloat(mAlarmStatus, "alpha", 0, 1) |
| 163 | .addFloat(mEmergencyOnly, "alpha", 0, 1) |
| 164 | .setStartDelay(.5f) |
| 165 | .build(); |
| 166 | mFirstHalfAnimator = new TouchAnimator.Builder() |
| 167 | .addFloat(mAlarmStatusCollapsed, "alpha", 1, 0) |
Jason Monk | 97cb9c7 | 2016-02-17 16:41:01 -0500 | [diff] [blame] | 168 | .setEndDelay(.5f) |
| 169 | .build(); |
| 170 | mDateSizeAnimator = new TouchAnimator.Builder() |
| 171 | .addFloat(mDateTimeGroup, "scaleX", 1, mDateScaleFactor) |
| 172 | .addFloat(mDateTimeGroup, "scaleY", 1, mDateScaleFactor) |
| 173 | .setStartDelay(.36f) |
| 174 | .build(); |
Jason Monk | 162011e | 2016-02-19 08:11:55 -0500 | [diff] [blame] | 175 | mSettingsAlpha = new TouchAnimator.Builder() |
Jason Monk | 98196b0 | 2016-03-14 10:33:02 -0400 | [diff] [blame] | 176 | .addFloat(mSettingsContainer, "translationY", -mGearTranslation, 0) |
| 177 | .addFloat(mMultiUserSwitch, "translationY", -mGearTranslation, 0) |
| 178 | .addFloat(mSettingsButton, "rotation", -90, 0) |
Jason Monk | 162011e | 2016-02-19 08:11:55 -0500 | [diff] [blame] | 179 | .addFloat(mSettingsContainer, "alpha", 0, 1) |
| 180 | .addFloat(mMultiUserSwitch, "alpha", 0, 1) |
| 181 | .setStartDelay(QSAnimator.EXPANDED_TILE_DELAY) |
| 182 | .build(); |
Jason Monk | 51fb85a | 2016-03-28 14:06:04 -0400 | [diff] [blame] | 183 | |
| 184 | final boolean isRtl = isLayoutRtl(); |
| 185 | if (isRtl && mDateTimeGroup.getWidth() == 0) { |
| 186 | mDateTimeGroup.addOnLayoutChangeListener(new OnLayoutChangeListener() { |
| 187 | @Override |
| 188 | public void onLayoutChange(View v, int left, int top, int right, int bottom, |
| 189 | int oldLeft, int oldTop, int oldRight, int oldBottom) { |
| 190 | mDateTimeGroup.setPivotX(getWidth()); |
| 191 | mDateTimeGroup.removeOnLayoutChangeListener(this); |
| 192 | } |
| 193 | }); |
| 194 | } else { |
| 195 | mDateTimeGroup.setPivotX(isRtl ? mDateTimeGroup.getWidth() : 0); |
| 196 | } |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | @Override |
| 200 | public int getCollapsedHeight() { |
| 201 | return getHeight(); |
| 202 | } |
| 203 | |
| 204 | @Override |
| 205 | public int getExpandedHeight() { |
| 206 | return getHeight(); |
| 207 | } |
| 208 | |
| 209 | @Override |
| 210 | public void setExpanded(boolean expanded) { |
| 211 | mExpanded = expanded; |
Jason Monk | deba7a4 | 2015-12-08 16:14:10 -0500 | [diff] [blame] | 212 | updateEverything(); |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | @Override |
| 216 | public void onNextAlarmChanged(AlarmManager.AlarmClockInfo nextAlarm) { |
| 217 | mNextAlarm = nextAlarm; |
| 218 | if (nextAlarm != null) { |
Jason Monk | deba7a4 | 2015-12-08 16:14:10 -0500 | [diff] [blame] | 219 | mAlarmStatus.setText(KeyguardStatusView.formatNextAlarm(getContext(), nextAlarm)); |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 220 | } |
Jason Monk | 97cb9c7 | 2016-02-17 16:41:01 -0500 | [diff] [blame] | 221 | if (mAlarmShowing != (nextAlarm != null)) { |
| 222 | mAlarmShowing = nextAlarm != null; |
| 223 | updateEverything(); |
| 224 | } |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | @Override |
| 228 | public void setExpansion(float headerExpansionFraction) { |
Jason Monk | 97cb9c7 | 2016-02-17 16:41:01 -0500 | [diff] [blame] | 229 | mExpansionAmount = headerExpansionFraction; |
Jason Monk | 97cb9c7 | 2016-02-17 16:41:01 -0500 | [diff] [blame] | 230 | mSecondHalfAnimator.setPosition(headerExpansionFraction); |
| 231 | mFirstHalfAnimator.setPosition(headerExpansionFraction); |
| 232 | mDateSizeAnimator.setPosition(headerExpansionFraction); |
| 233 | mAlarmTranslation.setPosition(headerExpansionFraction); |
Jason Monk | 162011e | 2016-02-19 08:11:55 -0500 | [diff] [blame] | 234 | mSettingsAlpha.setPosition(headerExpansionFraction); |
Jason Monk | dbd8817 | 2016-02-17 15:20:29 -0500 | [diff] [blame] | 235 | |
Jason Monk | dbd8817 | 2016-02-17 15:20:29 -0500 | [diff] [blame] | 236 | updateAlarmVisibilities(); |
| 237 | |
Jason Monk | 97cb9c7 | 2016-02-17 16:41:01 -0500 | [diff] [blame] | 238 | mExpandIndicator.setExpanded(headerExpansionFraction > EXPAND_INDICATOR_THRESHOLD); |
| 239 | } |
Jason Monk | dbd8817 | 2016-02-17 15:20:29 -0500 | [diff] [blame] | 240 | |
Jason Monk | 46dbfb4 | 2016-02-25 14:59:20 -0500 | [diff] [blame] | 241 | @Override |
| 242 | protected void onDetachedFromWindow() { |
| 243 | setListening(false); |
| 244 | mHost.getUserInfoController().remListener(mUserListener); |
| 245 | mHost.getNetworkController().removeEmergencyListener(this); |
| 246 | super.onDetachedFromWindow(); |
| 247 | } |
| 248 | |
Jason Monk | dbd8817 | 2016-02-17 15:20:29 -0500 | [diff] [blame] | 249 | private void updateAlarmVisibilities() { |
Jason Monk | 97cb9c7 | 2016-02-17 16:41:01 -0500 | [diff] [blame] | 250 | mAlarmStatus.setVisibility(mAlarmShowing ? View.VISIBLE : View.INVISIBLE); |
| 251 | mAlarmStatusCollapsed.setVisibility(mAlarmShowing ? View.VISIBLE : View.INVISIBLE); |
Jason Monk | dbd8817 | 2016-02-17 15:20:29 -0500 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | private void updateDateTimePosition() { |
Jason Monk | 97cb9c7 | 2016-02-17 16:41:01 -0500 | [diff] [blame] | 255 | // This one has its own because we have to rebuild it every time the alarm state changes. |
| 256 | mAlarmTranslation = new TouchAnimator.Builder() |
| 257 | .addFloat(mDateTimeAlarmGroup, "translationY", 0, mAlarmShowing |
| 258 | ? mDateTimeAlarmTranslation : mDateTimeTranslation) |
| 259 | .build(); |
| 260 | mAlarmTranslation.setPosition(mExpansionAmount); |
Jason Monk | dbd8817 | 2016-02-17 15:20:29 -0500 | [diff] [blame] | 261 | } |
| 262 | |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 263 | public void setListening(boolean listening) { |
| 264 | if (listening == mListening) { |
| 265 | return; |
| 266 | } |
| 267 | mHeaderQsPanel.setListening(listening); |
| 268 | mListening = listening; |
| 269 | updateListeners(); |
| 270 | } |
| 271 | |
| 272 | @Override |
| 273 | public void updateEverything() { |
Jason Monk | dbd8817 | 2016-02-17 15:20:29 -0500 | [diff] [blame] | 274 | updateDateTimePosition(); |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 275 | updateVisibilities(); |
| 276 | } |
| 277 | |
| 278 | private void updateVisibilities() { |
Jason Monk | dbd8817 | 2016-02-17 15:20:29 -0500 | [diff] [blame] | 279 | updateAlarmVisibilities(); |
Jason Monk | ec9af01 | 2015-12-10 11:10:23 -0500 | [diff] [blame] | 280 | mEmergencyOnly.setVisibility(mExpanded && mShowEmergencyCallsOnly |
| 281 | ? View.VISIBLE : View.INVISIBLE); |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 282 | mSettingsContainer.findViewById(R.id.tuner_icon).setVisibility( |
| 283 | TunerService.isTunerEnabled(mContext) ? View.VISIBLE : View.INVISIBLE); |
Jason Monk | 69e76cc | 2016-01-26 10:56:37 -0500 | [diff] [blame] | 284 | mMultiUserSwitch.setVisibility(mMultiUserSwitch.hasMultipleUsers() ? View.VISIBLE |
| 285 | : View.GONE); |
| 286 | } |
| 287 | |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 288 | private void updateListeners() { |
| 289 | if (mListening) { |
| 290 | mNextAlarmController.addStateChangedCallback(this); |
| 291 | } else { |
| 292 | mNextAlarmController.removeStateChangedCallback(this); |
| 293 | } |
| 294 | } |
| 295 | |
| 296 | @Override |
| 297 | public void setActivityStarter(ActivityStarter activityStarter) { |
| 298 | mActivityStarter = activityStarter; |
| 299 | } |
| 300 | |
| 301 | @Override |
| 302 | public void setQSPanel(final QSPanel qsPanel) { |
| 303 | mQsPanel = qsPanel; |
| 304 | setupHost(qsPanel.getHost()); |
| 305 | if (mQsPanel != null) { |
Jason Monk | 69e76cc | 2016-01-26 10:56:37 -0500 | [diff] [blame] | 306 | mMultiUserSwitch.setQsPanel(qsPanel); |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 307 | } |
| 308 | } |
| 309 | |
Jason Monk | ca894a0 | 2016-01-12 15:30:22 -0500 | [diff] [blame] | 310 | public void setupHost(final QSTileHost host) { |
Jason Monk | 46dbfb4 | 2016-02-25 14:59:20 -0500 | [diff] [blame] | 311 | mHost = host; |
Jason Monk | 324ed23 | 2016-04-07 11:48:49 -0400 | [diff] [blame^] | 312 | host.setHeaderView(mExpandIndicator); |
Jason Monk | dc35dcb | 2015-12-04 16:36:15 -0500 | [diff] [blame] | 313 | mHeaderQsPanel.setQSPanelAndHeader(mQsPanel, this); |
Jason Monk | 8b9d67f | 2016-03-02 08:59:08 -0500 | [diff] [blame] | 314 | mHeaderQsPanel.setHost(host, null /* No customization in header */); |
Jason Monk | 46dbfb4 | 2016-02-25 14:59:20 -0500 | [diff] [blame] | 315 | setUserInfoController(host.getUserInfoController()); |
| 316 | setBatteryController(host.getBatteryController()); |
| 317 | setNextAlarmController(host.getNextAlarmController()); |
| 318 | |
| 319 | final boolean isAPhone = mHost.getNetworkController().hasVoiceCallingFeature(); |
| 320 | if (isAPhone) { |
| 321 | mHost.getNetworkController().addEmergencyListener(this); |
| 322 | } |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | @Override |
| 326 | public void onClick(View v) { |
| 327 | if (v == mSettingsButton) { |
| 328 | if (mSettingsButton.isTunerClick()) { |
| 329 | if (TunerService.isTunerEnabled(mContext)) { |
| 330 | TunerService.showResetRequest(mContext, new Runnable() { |
| 331 | @Override |
| 332 | public void run() { |
| 333 | // Relaunch settings so that the tuner disappears. |
| 334 | startSettingsActivity(); |
| 335 | } |
| 336 | }); |
| 337 | } else { |
| 338 | Toast.makeText(getContext(), R.string.tuner_toast, Toast.LENGTH_LONG).show(); |
| 339 | TunerService.setTunerEnabled(mContext, true); |
| 340 | } |
| 341 | } |
| 342 | startSettingsActivity(); |
| 343 | } else if (v == mAlarmStatus && mNextAlarm != null) { |
| 344 | PendingIntent showIntent = mNextAlarm.getShowIntent(); |
| 345 | if (showIntent != null && showIntent.isActivity()) { |
| 346 | mActivityStarter.startActivity(showIntent.getIntent(), true /* dismissShade */); |
| 347 | } |
| 348 | } |
| 349 | } |
| 350 | |
| 351 | private void startSettingsActivity() { |
| 352 | mActivityStarter.startActivity(new Intent(android.provider.Settings.ACTION_SETTINGS), |
| 353 | true /* dismissShade */); |
| 354 | } |
| 355 | |
| 356 | @Override |
| 357 | public void setNextAlarmController(NextAlarmController nextAlarmController) { |
| 358 | mNextAlarmController = nextAlarmController; |
| 359 | } |
| 360 | |
| 361 | @Override |
| 362 | public void setBatteryController(BatteryController batteryController) { |
| 363 | // Don't care |
| 364 | } |
| 365 | |
| 366 | @Override |
| 367 | public void setUserInfoController(UserInfoController userInfoController) { |
Jason Monk | 46dbfb4 | 2016-02-25 14:59:20 -0500 | [diff] [blame] | 368 | userInfoController.addListener(mUserListener); |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | @Override |
Jason Monk | ec9af01 | 2015-12-10 11:10:23 -0500 | [diff] [blame] | 372 | public void setEmergencyCallsOnly(boolean show) { |
| 373 | boolean changed = show != mShowEmergencyCallsOnly; |
| 374 | if (changed) { |
| 375 | mShowEmergencyCallsOnly = show; |
| 376 | if (mExpanded) { |
| 377 | updateEverything(); |
| 378 | } |
| 379 | } |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 380 | } |
Jason Monk | 46dbfb4 | 2016-02-25 14:59:20 -0500 | [diff] [blame] | 381 | |
| 382 | private final OnUserInfoChangedListener mUserListener = new OnUserInfoChangedListener() { |
| 383 | @Override |
| 384 | public void onUserInfoChanged(String name, Drawable picture) { |
| 385 | mMultiUserAvatar.setImageDrawable(picture); |
| 386 | } |
| 387 | }; |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 388 | } |