Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 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 | |
Jorim Jaggi | c7dea6e | 2014-07-26 14:36:57 +0200 | [diff] [blame] | 19 | import android.app.AlarmClockInfo; |
| 20 | import android.app.PendingIntent; |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 21 | import android.content.Context; |
Jorim Jaggi | 13c1b1f | 2014-05-11 21:55:00 +0200 | [diff] [blame] | 22 | import android.content.Intent; |
Jorim Jaggi | db3e6ed | 2014-05-12 20:18:47 +0200 | [diff] [blame] | 23 | import android.graphics.Outline; |
| 24 | import android.graphics.Rect; |
Jorim Jaggi | 3f48f46 | 2014-07-08 16:53:29 +0200 | [diff] [blame] | 25 | import android.graphics.drawable.Drawable; |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 26 | import android.util.AttributeSet; |
| 27 | import android.view.View; |
| 28 | import android.view.ViewGroup; |
Chris Craik | 7b7ca3c | 2014-07-11 13:32:19 -0700 | [diff] [blame] | 29 | import android.view.ViewOutlineProvider; |
Jorim Jaggi | f056e35 | 2014-05-11 23:09:22 +0200 | [diff] [blame] | 30 | import android.widget.ImageView; |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 31 | import android.widget.LinearLayout; |
| 32 | import android.widget.RelativeLayout; |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 33 | import android.widget.Switch; |
Adrian Roos | 59a6127 | 2014-06-06 19:07:24 +0200 | [diff] [blame] | 34 | import android.widget.TextView; |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 35 | |
Jorim Jaggi | c7dea6e | 2014-07-26 14:36:57 +0200 | [diff] [blame] | 36 | import com.android.keyguard.KeyguardStatusView; |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 37 | import com.android.systemui.R; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 38 | import com.android.systemui.qs.QSPanel; |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 39 | import com.android.systemui.qs.QSTile; |
Jorim Jaggi | 853b070 | 2014-07-05 04:31:14 +0200 | [diff] [blame] | 40 | import com.android.systemui.statusbar.policy.BatteryController; |
Adrian Roos | 723632e | 2014-07-23 21:13:21 +0200 | [diff] [blame] | 41 | import com.android.systemui.statusbar.policy.KeyguardUserSwitcher; |
Jorim Jaggi | c7dea6e | 2014-07-26 14:36:57 +0200 | [diff] [blame] | 42 | import com.android.systemui.statusbar.policy.NextAlarmController; |
Jorim Jaggi | 3d878be | 2014-05-10 03:22:32 +0200 | [diff] [blame] | 43 | import com.android.systemui.statusbar.policy.UserInfoController; |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 44 | |
| 45 | /** |
| 46 | * The view to manage the header area in the expanded status bar. |
| 47 | */ |
Jorim Jaggi | 853b070 | 2014-07-05 04:31:14 +0200 | [diff] [blame] | 48 | public class StatusBarHeaderView extends RelativeLayout implements View.OnClickListener, |
Jorim Jaggi | c7dea6e | 2014-07-26 14:36:57 +0200 | [diff] [blame] | 49 | BatteryController.BatteryStateChangeCallback, NextAlarmController.NextAlarmChangeCallback { |
Jorim Jaggi | f62f2bb | 2014-05-25 22:28:41 +0200 | [diff] [blame] | 50 | |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 51 | private boolean mExpanded; |
Jorim Jaggi | e65e310 | 2014-07-01 22:00:50 +0200 | [diff] [blame] | 52 | private boolean mListening; |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 53 | private boolean mOverscrolled; |
Jorim Jaggi | 13c1b1f | 2014-05-11 21:55:00 +0200 | [diff] [blame] | 54 | private boolean mKeyguardShowing; |
Jorim Jaggi | d4aafe9 | 2014-07-10 21:00:57 +0200 | [diff] [blame] | 55 | private boolean mCharging; |
Jorim Jaggi | 13c1b1f | 2014-05-11 21:55:00 +0200 | [diff] [blame] | 56 | |
Jorim Jaggi | 0d74eeb | 2014-05-09 22:05:24 +0200 | [diff] [blame] | 57 | private ViewGroup mSystemIconsContainer; |
Jorim Jaggi | 605f190 | 2014-06-25 05:23:42 +0200 | [diff] [blame] | 58 | private View mSystemIconsSuperContainer; |
Jorim Jaggi | c7dea6e | 2014-07-26 14:36:57 +0200 | [diff] [blame] | 59 | private View mDateGroup; |
| 60 | private View mClock; |
Jorim Jaggi | 329fa24 | 2014-07-11 21:42:00 +0200 | [diff] [blame] | 61 | private View mTime; |
| 62 | private View mAmPm; |
Jorim Jaggi | 9054d94 | 2014-05-09 22:47:28 +0200 | [diff] [blame] | 63 | private View mKeyguardCarrierText; |
Jorim Jaggi | 3d878be | 2014-05-10 03:22:32 +0200 | [diff] [blame] | 64 | private MultiUserSwitch mMultiUserSwitch; |
Jorim Jaggi | 3f48f46 | 2014-07-08 16:53:29 +0200 | [diff] [blame] | 65 | private ImageView mMultiUserAvatar; |
| 66 | private View mDateCollapsed; |
| 67 | private View mDateExpanded; |
Jorim Jaggi | 13c1b1f | 2014-05-11 21:55:00 +0200 | [diff] [blame] | 68 | private View mStatusIcons; |
| 69 | private View mSignalCluster; |
| 70 | private View mSettingsButton; |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 71 | private View mQsDetailHeader; |
John Spurlock | 486b78e | 2014-07-07 08:37:56 -0400 | [diff] [blame] | 72 | private TextView mQsDetailHeaderTitle; |
| 73 | private Switch mQsDetailHeaderSwitch; |
Adrian Roos | 59a6127 | 2014-06-06 19:07:24 +0200 | [diff] [blame] | 74 | private View mEmergencyCallsOnly; |
Jorim Jaggi | 853b070 | 2014-07-05 04:31:14 +0200 | [diff] [blame] | 75 | private TextView mBatteryLevel; |
Jorim Jaggi | c7dea6e | 2014-07-26 14:36:57 +0200 | [diff] [blame] | 76 | private TextView mAlarmStatus; |
Adrian Roos | 59a6127 | 2014-06-06 19:07:24 +0200 | [diff] [blame] | 77 | |
| 78 | private boolean mShowEmergencyCallsOnly; |
Adrian Roos | 8ddb2da | 2014-06-16 18:56:22 -0700 | [diff] [blame] | 79 | private boolean mKeyguardUserSwitcherShowing; |
Jorim Jaggi | c7dea6e | 2014-07-26 14:36:57 +0200 | [diff] [blame] | 80 | private boolean mAlarmShowing; |
| 81 | private AlarmClockInfo mNextAlarm; |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 82 | |
| 83 | private int mCollapsedHeight; |
| 84 | private int mExpandedHeight; |
Jorim Jaggi | 9054d94 | 2014-05-09 22:47:28 +0200 | [diff] [blame] | 85 | private int mKeyguardHeight; |
| 86 | |
Jorim Jaggi | e18c2cd | 2014-05-08 19:16:49 +0200 | [diff] [blame] | 87 | private int mKeyguardWidth = ViewGroup.LayoutParams.MATCH_PARENT; |
| 88 | private int mNormalWidth; |
Jorim Jaggi | 129e7ac | 2014-06-10 22:03:48 +0200 | [diff] [blame] | 89 | private int mPadding; |
| 90 | private int mMultiUserExpandedMargin; |
Jorim Jaggi | 3f48f46 | 2014-07-08 16:53:29 +0200 | [diff] [blame] | 91 | private int mMultiUserCollapsedMargin; |
| 92 | private int mMultiUserKeyguardMargin; |
Adrian Roos | 8ddb2da | 2014-06-16 18:56:22 -0700 | [diff] [blame] | 93 | private int mSystemIconsSwitcherHiddenExpandedMargin; |
Jorim Jaggi | 3f48f46 | 2014-07-08 16:53:29 +0200 | [diff] [blame] | 94 | private int mClockMarginBottomExpanded; |
Jorim Jaggi | c7dea6e | 2014-07-26 14:36:57 +0200 | [diff] [blame] | 95 | private int mClockMarginBottomCollapsed; |
Jorim Jaggi | 3f48f46 | 2014-07-08 16:53:29 +0200 | [diff] [blame] | 96 | private int mMultiUserSwitchWidthCollapsed; |
| 97 | private int mMultiUserSwitchWidthExpanded; |
Jorim Jaggi | 87d84d4 | 2014-07-28 12:14:48 +0200 | [diff] [blame^] | 98 | private int mMultiUserSwitchWidthKeyguard; |
Jorim Jaggi | d4aafe9 | 2014-07-10 21:00:57 +0200 | [diff] [blame] | 99 | private int mBatteryPaddingEnd; |
Jorim Jaggi | 87d84d4 | 2014-07-28 12:14:48 +0200 | [diff] [blame^] | 100 | private int mBatteryMarginExpanded; |
| 101 | private int mBatteryMarginKeyguard; |
Jorim Jaggi | 3f48f46 | 2014-07-08 16:53:29 +0200 | [diff] [blame] | 102 | |
| 103 | /** |
| 104 | * In collapsed QS, the clock and avatar are scaled down a bit post-layout to allow for a nice |
| 105 | * transition. These values determine that factor. |
| 106 | */ |
| 107 | private float mClockCollapsedScaleFactor; |
| 108 | private float mAvatarCollapsedScaleFactor; |
Jorim Jaggi | 87d84d4 | 2014-07-28 12:14:48 +0200 | [diff] [blame^] | 109 | private float mAvatarKeyguardScaleFactor; |
Jorim Jaggi | e18c2cd | 2014-05-08 19:16:49 +0200 | [diff] [blame] | 110 | |
Jorim Jaggi | 13c1b1f | 2014-05-11 21:55:00 +0200 | [diff] [blame] | 111 | private ActivityStarter mActivityStarter; |
Jorim Jaggi | 853b070 | 2014-07-05 04:31:14 +0200 | [diff] [blame] | 112 | private BatteryController mBatteryController; |
Jorim Jaggi | c7dea6e | 2014-07-26 14:36:57 +0200 | [diff] [blame] | 113 | private NextAlarmController mNextAlarmController; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 114 | private QSPanel mQSPanel; |
Jorim Jaggi | bc976e3 | 2014-07-25 16:42:34 +0200 | [diff] [blame] | 115 | private KeyguardUserSwitcher mKeyguardUserSwitcher; |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 116 | |
Jorim Jaggi | db3e6ed | 2014-05-12 20:18:47 +0200 | [diff] [blame] | 117 | private final Rect mClipBounds = new Rect(); |
John Spurlock | 312b792 | 2014-07-22 22:23:42 -0400 | [diff] [blame] | 118 | private final StatusIconClipper mStatusIconClipper = new StatusIconClipper(); |
Jorim Jaggi | db3e6ed | 2014-05-12 20:18:47 +0200 | [diff] [blame] | 119 | |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 120 | public StatusBarHeaderView(Context context, AttributeSet attrs) { |
| 121 | super(context, attrs); |
| 122 | } |
| 123 | |
| 124 | @Override |
| 125 | protected void onFinishInflate() { |
| 126 | super.onFinishInflate(); |
Jorim Jaggi | 605f190 | 2014-06-25 05:23:42 +0200 | [diff] [blame] | 127 | mSystemIconsSuperContainer = findViewById(R.id.system_icons_super_container); |
Jorim Jaggi | 0d74eeb | 2014-05-09 22:05:24 +0200 | [diff] [blame] | 128 | mSystemIconsContainer = (ViewGroup) findViewById(R.id.system_icons_container); |
Jorim Jaggi | 853b070 | 2014-07-05 04:31:14 +0200 | [diff] [blame] | 129 | mSystemIconsSuperContainer.setOnClickListener(this); |
Jorim Jaggi | c7dea6e | 2014-07-26 14:36:57 +0200 | [diff] [blame] | 130 | mDateGroup = findViewById(R.id.date_group); |
| 131 | mClock = findViewById(R.id.clock); |
Jorim Jaggi | 329fa24 | 2014-07-11 21:42:00 +0200 | [diff] [blame] | 132 | mTime = findViewById(R.id.time_view); |
| 133 | mAmPm = findViewById(R.id.am_pm_view); |
Jorim Jaggi | 9054d94 | 2014-05-09 22:47:28 +0200 | [diff] [blame] | 134 | mKeyguardCarrierText = findViewById(R.id.keyguard_carrier_text); |
Jorim Jaggi | 3d878be | 2014-05-10 03:22:32 +0200 | [diff] [blame] | 135 | mMultiUserSwitch = (MultiUserSwitch) findViewById(R.id.multi_user_switch); |
Jorim Jaggi | 3f48f46 | 2014-07-08 16:53:29 +0200 | [diff] [blame] | 136 | mMultiUserAvatar = (ImageView) findViewById(R.id.multi_user_avatar); |
| 137 | mDateCollapsed = findViewById(R.id.date_collapsed); |
| 138 | mDateExpanded = findViewById(R.id.date_expanded); |
Jorim Jaggi | 13c1b1f | 2014-05-11 21:55:00 +0200 | [diff] [blame] | 139 | mSettingsButton = findViewById(R.id.settings_button); |
| 140 | mSettingsButton.setOnClickListener(this); |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 141 | mQsDetailHeader = findViewById(R.id.qs_detail_header); |
| 142 | mQsDetailHeader.setAlpha(0); |
John Spurlock | 486b78e | 2014-07-07 08:37:56 -0400 | [diff] [blame] | 143 | mQsDetailHeaderTitle = (TextView) mQsDetailHeader.findViewById(android.R.id.title); |
| 144 | mQsDetailHeaderSwitch = (Switch) mQsDetailHeader.findViewById(android.R.id.toggle); |
Adrian Roos | 59a6127 | 2014-06-06 19:07:24 +0200 | [diff] [blame] | 145 | mEmergencyCallsOnly = findViewById(R.id.header_emergency_calls_only); |
Jorim Jaggi | 853b070 | 2014-07-05 04:31:14 +0200 | [diff] [blame] | 146 | mBatteryLevel = (TextView) findViewById(R.id.battery_level); |
Jorim Jaggi | c7dea6e | 2014-07-26 14:36:57 +0200 | [diff] [blame] | 147 | mAlarmStatus = (TextView) findViewById(R.id.alarm_status); |
| 148 | mAlarmStatus.setOnClickListener(this); |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 149 | loadDimens(); |
John Spurlock | e86ae85 | 2014-05-17 16:18:27 -0400 | [diff] [blame] | 150 | updateVisibilities(); |
Jorim Jaggi | 3f48f46 | 2014-07-08 16:53:29 +0200 | [diff] [blame] | 151 | updateClockScale(); |
| 152 | updateAvatarScale(); |
John Spurlock | d9792b7 | 2014-05-21 23:50:13 -0400 | [diff] [blame] | 153 | addOnLayoutChangeListener(new View.OnLayoutChangeListener() { |
| 154 | @Override |
| 155 | public void onLayoutChange(View v, int left, int top, int right, |
| 156 | int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { |
| 157 | if ((right - left) != (oldRight - oldLeft)) { |
| 158 | // width changed, update clipping |
| 159 | setClipping(getHeight()); |
| 160 | } |
Jorim Jaggi | 329fa24 | 2014-07-11 21:42:00 +0200 | [diff] [blame] | 161 | boolean rtl = getLayoutDirection() == LAYOUT_DIRECTION_RTL; |
| 162 | mTime.setPivotX(rtl ? mTime.getWidth() : 0); |
| 163 | mTime.setPivotY(mTime.getBaseline()); |
| 164 | mAmPm.setPivotX(rtl ? mAmPm.getWidth() : 0); |
| 165 | mAmPm.setPivotY(mAmPm.getBaseline()); |
| 166 | updateAmPmTranslation(); |
John Spurlock | d9792b7 | 2014-05-21 23:50:13 -0400 | [diff] [blame] | 167 | } |
| 168 | }); |
Chris Craik | 7b7ca3c | 2014-07-11 13:32:19 -0700 | [diff] [blame] | 169 | setOutlineProvider(new ViewOutlineProvider() { |
| 170 | @Override |
Chris Craik | 31ba192 | 2014-07-18 13:48:09 -0700 | [diff] [blame] | 171 | public void getOutline(View view, Outline outline) { |
Chris Craik | 7b7ca3c | 2014-07-11 13:32:19 -0700 | [diff] [blame] | 172 | outline.setRect(mClipBounds); |
Chris Craik | 7b7ca3c | 2014-07-11 13:32:19 -0700 | [diff] [blame] | 173 | } |
| 174 | }); |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | private void loadDimens() { |
Jorim Jaggi | 0d74eeb | 2014-05-09 22:05:24 +0200 | [diff] [blame] | 178 | mCollapsedHeight = getResources().getDimensionPixelSize(R.dimen.status_bar_header_height); |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 179 | mExpandedHeight = getResources().getDimensionPixelSize( |
| 180 | R.dimen.status_bar_header_height_expanded); |
Jorim Jaggi | 9054d94 | 2014-05-09 22:47:28 +0200 | [diff] [blame] | 181 | mKeyguardHeight = getResources().getDimensionPixelSize( |
| 182 | R.dimen.status_bar_header_height_keyguard); |
Jorim Jaggi | e18c2cd | 2014-05-08 19:16:49 +0200 | [diff] [blame] | 183 | mNormalWidth = getLayoutParams().width; |
Jorim Jaggi | 129e7ac | 2014-06-10 22:03:48 +0200 | [diff] [blame] | 184 | mPadding = getResources().getDimensionPixelSize(R.dimen.notification_side_padding); |
| 185 | mMultiUserExpandedMargin = |
| 186 | getResources().getDimensionPixelSize(R.dimen.multi_user_switch_expanded_margin); |
Jorim Jaggi | 3f48f46 | 2014-07-08 16:53:29 +0200 | [diff] [blame] | 187 | mMultiUserCollapsedMargin = |
| 188 | getResources().getDimensionPixelSize(R.dimen.multi_user_switch_collapsed_margin); |
| 189 | mMultiUserKeyguardMargin = |
| 190 | getResources().getDimensionPixelSize(R.dimen.multi_user_switch_keyguard_margin); |
Adrian Roos | 8ddb2da | 2014-06-16 18:56:22 -0700 | [diff] [blame] | 191 | mSystemIconsSwitcherHiddenExpandedMargin = getResources().getDimensionPixelSize( |
| 192 | R.dimen.system_icons_switcher_hidden_expanded_margin); |
Jorim Jaggi | 3f48f46 | 2014-07-08 16:53:29 +0200 | [diff] [blame] | 193 | mClockMarginBottomExpanded = |
| 194 | getResources().getDimensionPixelSize(R.dimen.clock_expanded_bottom_margin); |
Jorim Jaggi | c7dea6e | 2014-07-26 14:36:57 +0200 | [diff] [blame] | 195 | mClockMarginBottomCollapsed = |
| 196 | getResources().getDimensionPixelSize(R.dimen.clock_collapsed_bottom_margin); |
Jorim Jaggi | 3f48f46 | 2014-07-08 16:53:29 +0200 | [diff] [blame] | 197 | mMultiUserSwitchWidthCollapsed = |
| 198 | getResources().getDimensionPixelSize(R.dimen.multi_user_switch_width_collapsed); |
| 199 | mMultiUserSwitchWidthExpanded = |
| 200 | getResources().getDimensionPixelSize(R.dimen.multi_user_switch_width_expanded); |
Jorim Jaggi | 87d84d4 | 2014-07-28 12:14:48 +0200 | [diff] [blame^] | 201 | mMultiUserSwitchWidthKeyguard = |
| 202 | getResources().getDimensionPixelSize(R.dimen.multi_user_switch_width_keyguard); |
Jorim Jaggi | 3f48f46 | 2014-07-08 16:53:29 +0200 | [diff] [blame] | 203 | mAvatarCollapsedScaleFactor = |
| 204 | getResources().getDimensionPixelSize(R.dimen.multi_user_avatar_collapsed_size) |
| 205 | / (float) mMultiUserAvatar.getLayoutParams().width; |
Jorim Jaggi | 87d84d4 | 2014-07-28 12:14:48 +0200 | [diff] [blame^] | 206 | mAvatarKeyguardScaleFactor = |
| 207 | getResources().getDimensionPixelSize(R.dimen.multi_user_avatar_keyguard_size) |
| 208 | / (float) mMultiUserAvatar.getLayoutParams().width; |
Jorim Jaggi | 3f48f46 | 2014-07-08 16:53:29 +0200 | [diff] [blame] | 209 | mClockCollapsedScaleFactor = |
Jorim Jaggi | 329fa24 | 2014-07-11 21:42:00 +0200 | [diff] [blame] | 210 | (float) getResources().getDimensionPixelSize(R.dimen.qs_time_collapsed_size) |
| 211 | / (float) getResources().getDimensionPixelSize(R.dimen.qs_time_expanded_size); |
Jorim Jaggi | d4aafe9 | 2014-07-10 21:00:57 +0200 | [diff] [blame] | 212 | mBatteryPaddingEnd = |
| 213 | getResources().getDimensionPixelSize(R.dimen.battery_level_padding_end); |
Jorim Jaggi | 87d84d4 | 2014-07-28 12:14:48 +0200 | [diff] [blame^] | 214 | mBatteryMarginExpanded = |
| 215 | getResources().getDimensionPixelSize(R.dimen.header_battery_margin_expanded); |
| 216 | mBatteryMarginKeyguard = |
| 217 | getResources().getDimensionPixelSize(R.dimen.header_battery_margin_keyguard); |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 218 | } |
| 219 | |
Jorim Jaggi | 13c1b1f | 2014-05-11 21:55:00 +0200 | [diff] [blame] | 220 | public void setActivityStarter(ActivityStarter activityStarter) { |
| 221 | mActivityStarter = activityStarter; |
| 222 | } |
| 223 | |
Jorim Jaggi | 853b070 | 2014-07-05 04:31:14 +0200 | [diff] [blame] | 224 | public void setBatteryController(BatteryController batteryController) { |
| 225 | mBatteryController = batteryController; |
| 226 | } |
| 227 | |
Jorim Jaggi | c7dea6e | 2014-07-26 14:36:57 +0200 | [diff] [blame] | 228 | public void setNextAlarmController(NextAlarmController nextAlarmController) { |
| 229 | mNextAlarmController = nextAlarmController; |
| 230 | } |
| 231 | |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 232 | public int getCollapsedHeight() { |
Jorim Jaggi | 9054d94 | 2014-05-09 22:47:28 +0200 | [diff] [blame] | 233 | return mKeyguardShowing ? mKeyguardHeight : mCollapsedHeight; |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | public int getExpandedHeight() { |
| 237 | return mExpandedHeight; |
| 238 | } |
| 239 | |
Jorim Jaggi | e65e310 | 2014-07-01 22:00:50 +0200 | [diff] [blame] | 240 | public void setListening(boolean listening) { |
| 241 | if (listening == mListening) { |
| 242 | return; |
| 243 | } |
| 244 | mListening = listening; |
Jorim Jaggi | c7dea6e | 2014-07-26 14:36:57 +0200 | [diff] [blame] | 245 | updateListeners(); |
Jorim Jaggi | e65e310 | 2014-07-01 22:00:50 +0200 | [diff] [blame] | 246 | } |
| 247 | |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 248 | public void setExpanded(boolean expanded, boolean overscrolled) { |
Jorim Jaggi | 13c1b1f | 2014-05-11 21:55:00 +0200 | [diff] [blame] | 249 | boolean changed = expanded != mExpanded; |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 250 | boolean overscrollChanged = overscrolled != mOverscrolled; |
Jorim Jaggi | 9054d94 | 2014-05-09 22:47:28 +0200 | [diff] [blame] | 251 | mExpanded = expanded; |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 252 | mOverscrolled = overscrolled; |
| 253 | if (changed || overscrollChanged) { |
Jorim Jaggi | 13c1b1f | 2014-05-11 21:55:00 +0200 | [diff] [blame] | 254 | updateHeights(); |
| 255 | updateVisibilities(); |
| 256 | updateSystemIconsLayoutParams(); |
Jorim Jaggi | f62f2bb | 2014-05-25 22:28:41 +0200 | [diff] [blame] | 257 | updateZTranslation(); |
Jorim Jaggi | 5d6957e | 2014-05-26 02:15:06 +0200 | [diff] [blame] | 258 | updateClickTargets(); |
Adrian Roos | 13dee43 | 2014-06-10 19:42:47 +0200 | [diff] [blame] | 259 | updateWidth(); |
Jorim Jaggi | 129e7ac | 2014-06-10 22:03:48 +0200 | [diff] [blame] | 260 | updatePadding(); |
| 261 | updateMultiUserSwitch(); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 262 | if (mQSPanel != null) { |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 263 | mQSPanel.setExpanded(expanded && !overscrolled); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 264 | } |
Jorim Jaggi | 3f48f46 | 2014-07-08 16:53:29 +0200 | [diff] [blame] | 265 | updateClockScale(); |
| 266 | updateAvatarScale(); |
| 267 | updateClockLp(); |
Jorim Jaggi | d4aafe9 | 2014-07-10 21:00:57 +0200 | [diff] [blame] | 268 | updateBatteryLevelPaddingEnd(); |
Jorim Jaggi | 87d84d4 | 2014-07-28 12:14:48 +0200 | [diff] [blame^] | 269 | updateBatteryLevelLp(); |
John Spurlock | 312b792 | 2014-07-22 22:23:42 -0400 | [diff] [blame] | 270 | mStatusIconClipper.update(); |
Jorim Jaggi | 13c1b1f | 2014-05-11 21:55:00 +0200 | [diff] [blame] | 271 | } |
Jorim Jaggi | 9054d94 | 2014-05-09 22:47:28 +0200 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | private void updateHeights() { |
Jorim Jaggi | bc5f496 | 2014-05-12 00:00:52 +0200 | [diff] [blame] | 275 | boolean onKeyguardAndCollapsed = mKeyguardShowing && !mExpanded; |
Jorim Jaggi | 9054d94 | 2014-05-09 22:47:28 +0200 | [diff] [blame] | 276 | int height; |
| 277 | if (mExpanded) { |
| 278 | height = mExpandedHeight; |
Jorim Jaggi | bc5f496 | 2014-05-12 00:00:52 +0200 | [diff] [blame] | 279 | } else if (onKeyguardAndCollapsed) { |
Jorim Jaggi | 9054d94 | 2014-05-09 22:47:28 +0200 | [diff] [blame] | 280 | height = mKeyguardHeight; |
| 281 | } else { |
| 282 | height = mCollapsedHeight; |
| 283 | } |
| 284 | ViewGroup.LayoutParams lp = getLayoutParams(); |
| 285 | if (lp.height != height) { |
| 286 | lp.height = height; |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 287 | setLayoutParams(lp); |
Jorim Jaggi | 9054d94 | 2014-05-09 22:47:28 +0200 | [diff] [blame] | 288 | } |
Jorim Jaggi | bc5f496 | 2014-05-12 00:00:52 +0200 | [diff] [blame] | 289 | int systemIconsContainerHeight = onKeyguardAndCollapsed ? mKeyguardHeight : mCollapsedHeight; |
Jorim Jaggi | 605f190 | 2014-06-25 05:23:42 +0200 | [diff] [blame] | 290 | lp = mSystemIconsSuperContainer.getLayoutParams(); |
Jorim Jaggi | 9054d94 | 2014-05-09 22:47:28 +0200 | [diff] [blame] | 291 | if (lp.height != systemIconsContainerHeight) { |
| 292 | lp.height = systemIconsContainerHeight; |
Jorim Jaggi | 605f190 | 2014-06-25 05:23:42 +0200 | [diff] [blame] | 293 | mSystemIconsSuperContainer.setLayoutParams(lp); |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 294 | } |
Jorim Jaggi | 3d878be | 2014-05-10 03:22:32 +0200 | [diff] [blame] | 295 | lp = mMultiUserSwitch.getLayoutParams(); |
| 296 | if (lp.height != systemIconsContainerHeight) { |
| 297 | lp.height = systemIconsContainerHeight; |
| 298 | mMultiUserSwitch.setLayoutParams(lp); |
| 299 | } |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 300 | } |
| 301 | |
Jorim Jaggi | e18c2cd | 2014-05-08 19:16:49 +0200 | [diff] [blame] | 302 | private void updateWidth() { |
Adrian Roos | 13dee43 | 2014-06-10 19:42:47 +0200 | [diff] [blame] | 303 | int width = (mKeyguardShowing && !mExpanded) ? mKeyguardWidth : mNormalWidth; |
Jorim Jaggi | e18c2cd | 2014-05-08 19:16:49 +0200 | [diff] [blame] | 304 | ViewGroup.LayoutParams lp = getLayoutParams(); |
| 305 | if (width != lp.width) { |
| 306 | lp.width = width; |
| 307 | setLayoutParams(lp); |
| 308 | } |
| 309 | } |
| 310 | |
Jorim Jaggi | 740beb5 | 2014-05-11 18:53:19 +0200 | [diff] [blame] | 311 | private void updateVisibilities() { |
Jorim Jaggi | bc5f496 | 2014-05-12 00:00:52 +0200 | [diff] [blame] | 312 | boolean onKeyguardAndCollapsed = mKeyguardShowing && !mExpanded; |
Jorim Jaggi | 853b070 | 2014-07-05 04:31:14 +0200 | [diff] [blame] | 313 | if (onKeyguardAndCollapsed) { |
| 314 | setBackground(null); |
| 315 | } else { |
| 316 | setBackgroundResource(R.drawable.notification_header_bg); |
| 317 | } |
Jorim Jaggi | c7dea6e | 2014-07-26 14:36:57 +0200 | [diff] [blame] | 318 | mDateGroup.setVisibility(onKeyguardAndCollapsed ? View.INVISIBLE : View.VISIBLE); |
| 319 | mClock.setVisibility(onKeyguardAndCollapsed ? View.INVISIBLE : View.VISIBLE); |
Jorim Jaggi | bc5f496 | 2014-05-12 00:00:52 +0200 | [diff] [blame] | 320 | mKeyguardCarrierText.setVisibility(onKeyguardAndCollapsed ? View.VISIBLE : View.GONE); |
Jorim Jaggi | c7dea6e | 2014-07-26 14:36:57 +0200 | [diff] [blame] | 321 | mDateCollapsed.setVisibility(mExpanded && !mOverscrolled && mAlarmShowing |
| 322 | ? View.VISIBLE : View.GONE); |
| 323 | mDateExpanded.setVisibility(mExpanded && !mOverscrolled && mAlarmShowing |
| 324 | ? View.GONE : View.VISIBLE); |
| 325 | mAlarmStatus.setVisibility(mExpanded && !mOverscrolled && mAlarmShowing |
| 326 | ? View.VISIBLE : View.GONE); |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 327 | mSettingsButton.setVisibility(mExpanded && !mOverscrolled ? View.VISIBLE : View.GONE); |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 328 | mQsDetailHeader.setVisibility(mExpanded ? View.VISIBLE : View.GONE); |
John Spurlock | 604ae09 | 2014-07-17 18:22:45 -0400 | [diff] [blame] | 329 | if (mStatusIcons != null) { |
| 330 | mStatusIcons.setVisibility(!mExpanded || mOverscrolled ? View.VISIBLE : View.GONE); |
| 331 | } |
Jorim Jaggi | 13c1b1f | 2014-05-11 21:55:00 +0200 | [diff] [blame] | 332 | if (mSignalCluster != null) { |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 333 | mSignalCluster.setVisibility(!mExpanded || mOverscrolled ? View.VISIBLE : View.GONE); |
Jorim Jaggi | 13c1b1f | 2014-05-11 21:55:00 +0200 | [diff] [blame] | 334 | } |
Adrian Roos | 59a6127 | 2014-06-06 19:07:24 +0200 | [diff] [blame] | 335 | mEmergencyCallsOnly.setVisibility(mExpanded && !mOverscrolled && mShowEmergencyCallsOnly |
| 336 | ? VISIBLE : GONE); |
Adrian Roos | 8ddb2da | 2014-06-16 18:56:22 -0700 | [diff] [blame] | 337 | mMultiUserSwitch.setVisibility(mExpanded || !mKeyguardUserSwitcherShowing |
| 338 | ? VISIBLE : GONE); |
Jorim Jaggi | d4aafe9 | 2014-07-10 21:00:57 +0200 | [diff] [blame] | 339 | mBatteryLevel.setVisibility(mKeyguardShowing && mCharging || mExpanded && !mOverscrolled |
| 340 | ? View.VISIBLE : View.GONE); |
Jorim Jaggi | bc976e3 | 2014-07-25 16:42:34 +0200 | [diff] [blame] | 341 | if (mExpanded && !mOverscrolled && mKeyguardUserSwitcherShowing) { |
| 342 | mKeyguardUserSwitcher.hide(); |
| 343 | } |
Jorim Jaggi | 13c1b1f | 2014-05-11 21:55:00 +0200 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | private void updateSystemIconsLayoutParams() { |
Jorim Jaggi | 605f190 | 2014-06-25 05:23:42 +0200 | [diff] [blame] | 347 | RelativeLayout.LayoutParams lp = (LayoutParams) mSystemIconsSuperContainer.getLayoutParams(); |
Jorim Jaggi | d4aafe9 | 2014-07-10 21:00:57 +0200 | [diff] [blame] | 348 | lp.addRule(RelativeLayout.START_OF, mExpanded && !mOverscrolled |
Jorim Jaggi | 853b070 | 2014-07-05 04:31:14 +0200 | [diff] [blame] | 349 | ? mSettingsButton.getId() |
| 350 | : mMultiUserSwitch.getId()); |
| 351 | lp.removeRule(ALIGN_PARENT_START); |
| 352 | if (mMultiUserSwitch.getVisibility() == GONE) { |
| 353 | lp.setMarginEnd(mSystemIconsSwitcherHiddenExpandedMargin); |
Adrian Roos | 59a6127 | 2014-06-06 19:07:24 +0200 | [diff] [blame] | 354 | } else { |
Jorim Jaggi | 853b070 | 2014-07-05 04:31:14 +0200 | [diff] [blame] | 355 | lp.setMarginEnd(0); |
Adrian Roos | 59a6127 | 2014-06-06 19:07:24 +0200 | [diff] [blame] | 356 | } |
Jorim Jaggi | 605f190 | 2014-06-25 05:23:42 +0200 | [diff] [blame] | 357 | mSystemIconsSuperContainer.setLayoutParams(lp); |
Jorim Jaggi | 740beb5 | 2014-05-11 18:53:19 +0200 | [diff] [blame] | 358 | } |
| 359 | |
Jorim Jaggi | c7dea6e | 2014-07-26 14:36:57 +0200 | [diff] [blame] | 360 | private void updateListeners() { |
Jorim Jaggi | 853b070 | 2014-07-05 04:31:14 +0200 | [diff] [blame] | 361 | if (mListening) { |
| 362 | mBatteryController.addStateChangedCallback(this); |
Jorim Jaggi | c7dea6e | 2014-07-26 14:36:57 +0200 | [diff] [blame] | 363 | mNextAlarmController.addStateChangedCallback(this); |
Jorim Jaggi | 853b070 | 2014-07-05 04:31:14 +0200 | [diff] [blame] | 364 | } else { |
| 365 | mBatteryController.removeStateChangedCallback(this); |
Jorim Jaggi | c7dea6e | 2014-07-26 14:36:57 +0200 | [diff] [blame] | 366 | mNextAlarmController.removeStateChangedCallback(this); |
Jorim Jaggi | 853b070 | 2014-07-05 04:31:14 +0200 | [diff] [blame] | 367 | } |
| 368 | } |
| 369 | |
Jorim Jaggi | 3f48f46 | 2014-07-08 16:53:29 +0200 | [diff] [blame] | 370 | private void updateAvatarScale() { |
Jorim Jaggi | 87d84d4 | 2014-07-28 12:14:48 +0200 | [diff] [blame^] | 371 | if (mExpanded && !mOverscrolled) { |
Jorim Jaggi | 3f48f46 | 2014-07-08 16:53:29 +0200 | [diff] [blame] | 372 | mMultiUserSwitch.setScaleX(1f); |
| 373 | mMultiUserSwitch.setScaleY(1f); |
Jorim Jaggi | 87d84d4 | 2014-07-28 12:14:48 +0200 | [diff] [blame^] | 374 | } else if (mKeyguardShowing) { |
| 375 | mMultiUserSwitch.setScaleX(mAvatarKeyguardScaleFactor); |
| 376 | mMultiUserSwitch.setScaleY(mAvatarKeyguardScaleFactor); |
| 377 | } else { |
| 378 | mMultiUserSwitch.setScaleX(mAvatarCollapsedScaleFactor); |
| 379 | mMultiUserSwitch.setScaleY(mAvatarCollapsedScaleFactor); |
Jorim Jaggi | 3f48f46 | 2014-07-08 16:53:29 +0200 | [diff] [blame] | 380 | } |
| 381 | } |
| 382 | |
| 383 | private void updateClockScale() { |
Jorim Jaggi | 329fa24 | 2014-07-11 21:42:00 +0200 | [diff] [blame] | 384 | mAmPm.setScaleX(mClockCollapsedScaleFactor); |
| 385 | mAmPm.setScaleY(mClockCollapsedScaleFactor); |
Jorim Jaggi | 3f48f46 | 2014-07-08 16:53:29 +0200 | [diff] [blame] | 386 | if (!mExpanded || mOverscrolled) { |
Jorim Jaggi | 329fa24 | 2014-07-11 21:42:00 +0200 | [diff] [blame] | 387 | mTime.setScaleX(mClockCollapsedScaleFactor); |
| 388 | mTime.setScaleY(mClockCollapsedScaleFactor); |
Jorim Jaggi | 3f48f46 | 2014-07-08 16:53:29 +0200 | [diff] [blame] | 389 | } else { |
Jorim Jaggi | 329fa24 | 2014-07-11 21:42:00 +0200 | [diff] [blame] | 390 | mTime.setScaleX(1f); |
| 391 | mTime.setScaleY(1f); |
Jorim Jaggi | 3f48f46 | 2014-07-08 16:53:29 +0200 | [diff] [blame] | 392 | } |
Jorim Jaggi | 329fa24 | 2014-07-11 21:42:00 +0200 | [diff] [blame] | 393 | updateAmPmTranslation(); |
| 394 | } |
| 395 | |
| 396 | private void updateAmPmTranslation() { |
| 397 | boolean rtl = getLayoutDirection() == LAYOUT_DIRECTION_RTL; |
| 398 | mAmPm.setTranslationX((rtl ? 1 : -1) * mTime.getWidth() * (1 - mTime.getScaleX())); |
Jorim Jaggi | 3f48f46 | 2014-07-08 16:53:29 +0200 | [diff] [blame] | 399 | } |
| 400 | |
Jorim Jaggi | d4aafe9 | 2014-07-10 21:00:57 +0200 | [diff] [blame] | 401 | private void updateBatteryLevelPaddingEnd() { |
| 402 | mBatteryLevel.setPaddingRelative(0, 0, |
| 403 | mKeyguardShowing && !mExpanded ? 0 : mBatteryPaddingEnd, 0); |
| 404 | } |
| 405 | |
Jorim Jaggi | 853b070 | 2014-07-05 04:31:14 +0200 | [diff] [blame] | 406 | @Override |
| 407 | public void onBatteryLevelChanged(int level, boolean pluggedIn, boolean charging) { |
| 408 | mBatteryLevel.setText(getResources().getString(R.string.battery_level_template, level)); |
Jorim Jaggi | d4aafe9 | 2014-07-10 21:00:57 +0200 | [diff] [blame] | 409 | boolean changed = mCharging != charging; |
| 410 | mCharging = charging; |
| 411 | if (changed) { |
| 412 | updateVisibilities(); |
| 413 | } |
Jorim Jaggi | 853b070 | 2014-07-05 04:31:14 +0200 | [diff] [blame] | 414 | } |
| 415 | |
John Spurlock | 0ff62e0 | 2014-07-22 16:15:08 -0400 | [diff] [blame] | 416 | @Override |
| 417 | public void onPowerSaveChanged() { |
| 418 | // could not care less |
| 419 | } |
| 420 | |
Jorim Jaggi | c7dea6e | 2014-07-26 14:36:57 +0200 | [diff] [blame] | 421 | @Override |
| 422 | public void onNextAlarmChanged(AlarmClockInfo nextAlarm) { |
| 423 | mNextAlarm = nextAlarm; |
| 424 | if (nextAlarm != null) { |
| 425 | mAlarmStatus.setText(KeyguardStatusView.formatNextAlarm(getContext(), nextAlarm)); |
| 426 | } |
| 427 | mAlarmShowing = nextAlarm != null; |
| 428 | updateVisibilities(); |
| 429 | } |
| 430 | |
| 431 | |
Jorim Jaggi | 5d6957e | 2014-05-26 02:15:06 +0200 | [diff] [blame] | 432 | private void updateClickTargets() { |
Jorim Jaggi | 853b070 | 2014-07-05 04:31:14 +0200 | [diff] [blame] | 433 | setClickable(!mKeyguardShowing || mExpanded); |
Adrian Roos | 723632e | 2014-07-23 21:13:21 +0200 | [diff] [blame] | 434 | |
| 435 | boolean keyguardSwitcherAvailable = |
Jorim Jaggi | bc976e3 | 2014-07-25 16:42:34 +0200 | [diff] [blame] | 436 | mKeyguardUserSwitcher != null && mKeyguardShowing && !mExpanded; |
Adrian Roos | 723632e | 2014-07-23 21:13:21 +0200 | [diff] [blame] | 437 | mMultiUserSwitch.setClickable(mExpanded || keyguardSwitcherAvailable); |
| 438 | mMultiUserSwitch.setKeyguardMode(keyguardSwitcherAvailable); |
Jorim Jaggi | 853b070 | 2014-07-05 04:31:14 +0200 | [diff] [blame] | 439 | mSystemIconsSuperContainer.setClickable(mExpanded); |
Jorim Jaggi | c7dea6e | 2014-07-26 14:36:57 +0200 | [diff] [blame] | 440 | mAlarmStatus.setClickable(mNextAlarm != null && mNextAlarm.getShowIntent() != null); |
Jorim Jaggi | 5d6957e | 2014-05-26 02:15:06 +0200 | [diff] [blame] | 441 | } |
| 442 | |
Jorim Jaggi | f62f2bb | 2014-05-25 22:28:41 +0200 | [diff] [blame] | 443 | private void updateZTranslation() { |
| 444 | |
| 445 | // If we are on the Keyguard, we need to set our z position to zero, so we don't get |
| 446 | // shadows. |
| 447 | if (mKeyguardShowing && !mExpanded) { |
| 448 | setZ(0); |
| 449 | } else { |
| 450 | setTranslationZ(0); |
| 451 | } |
| 452 | } |
| 453 | |
Jorim Jaggi | 129e7ac | 2014-06-10 22:03:48 +0200 | [diff] [blame] | 454 | private void updatePadding() { |
| 455 | boolean padded = !mKeyguardShowing || mExpanded; |
| 456 | int padding = padded ? mPadding : 0; |
| 457 | setPaddingRelative(padding, 0, padding, 0); |
| 458 | } |
| 459 | |
Jorim Jaggi | 3f48f46 | 2014-07-08 16:53:29 +0200 | [diff] [blame] | 460 | private void updateClockLp() { |
Jorim Jaggi | c7dea6e | 2014-07-26 14:36:57 +0200 | [diff] [blame] | 461 | int marginBottom = mExpanded && !mOverscrolled |
| 462 | ? mClockMarginBottomExpanded |
| 463 | : mClockMarginBottomCollapsed; |
| 464 | LayoutParams lp = (LayoutParams) mDateGroup.getLayoutParams(); |
| 465 | if (marginBottom != lp.bottomMargin) { |
Jorim Jaggi | 3f48f46 | 2014-07-08 16:53:29 +0200 | [diff] [blame] | 466 | lp.bottomMargin = marginBottom; |
Jorim Jaggi | c7dea6e | 2014-07-26 14:36:57 +0200 | [diff] [blame] | 467 | mDateGroup.setLayoutParams(lp); |
Jorim Jaggi | 3f48f46 | 2014-07-08 16:53:29 +0200 | [diff] [blame] | 468 | } |
| 469 | } |
| 470 | |
Jorim Jaggi | 129e7ac | 2014-06-10 22:03:48 +0200 | [diff] [blame] | 471 | private void updateMultiUserSwitch() { |
Jorim Jaggi | 3f48f46 | 2014-07-08 16:53:29 +0200 | [diff] [blame] | 472 | int marginEnd; |
Jorim Jaggi | 87d84d4 | 2014-07-28 12:14:48 +0200 | [diff] [blame^] | 473 | int width; |
Jorim Jaggi | d4aafe9 | 2014-07-10 21:00:57 +0200 | [diff] [blame] | 474 | if (mExpanded && !mOverscrolled) { |
Jorim Jaggi | 3f48f46 | 2014-07-08 16:53:29 +0200 | [diff] [blame] | 475 | marginEnd = mMultiUserExpandedMargin; |
Jorim Jaggi | 87d84d4 | 2014-07-28 12:14:48 +0200 | [diff] [blame^] | 476 | width = mMultiUserSwitchWidthExpanded; |
Jorim Jaggi | 3f48f46 | 2014-07-08 16:53:29 +0200 | [diff] [blame] | 477 | } else if (mKeyguardShowing) { |
| 478 | marginEnd = mMultiUserKeyguardMargin; |
Jorim Jaggi | 87d84d4 | 2014-07-28 12:14:48 +0200 | [diff] [blame^] | 479 | width = mMultiUserSwitchWidthKeyguard; |
Jorim Jaggi | 3f48f46 | 2014-07-08 16:53:29 +0200 | [diff] [blame] | 480 | } else { |
| 481 | marginEnd = mMultiUserCollapsedMargin; |
Jorim Jaggi | 87d84d4 | 2014-07-28 12:14:48 +0200 | [diff] [blame^] | 482 | width = mMultiUserSwitchWidthCollapsed; |
Jorim Jaggi | 3f48f46 | 2014-07-08 16:53:29 +0200 | [diff] [blame] | 483 | } |
Jorim Jaggi | 129e7ac | 2014-06-10 22:03:48 +0200 | [diff] [blame] | 484 | MarginLayoutParams lp = (MarginLayoutParams) mMultiUserSwitch.getLayoutParams(); |
Jorim Jaggi | 3f48f46 | 2014-07-08 16:53:29 +0200 | [diff] [blame] | 485 | if (marginEnd != lp.getMarginEnd() || lp.width != width) { |
Jorim Jaggi | 129e7ac | 2014-06-10 22:03:48 +0200 | [diff] [blame] | 486 | lp.setMarginEnd(marginEnd); |
Jorim Jaggi | 3f48f46 | 2014-07-08 16:53:29 +0200 | [diff] [blame] | 487 | lp.width = width; |
Jorim Jaggi | 129e7ac | 2014-06-10 22:03:48 +0200 | [diff] [blame] | 488 | mMultiUserSwitch.setLayoutParams(lp); |
| 489 | } |
| 490 | } |
| 491 | |
Jorim Jaggi | 87d84d4 | 2014-07-28 12:14:48 +0200 | [diff] [blame^] | 492 | private void updateBatteryLevelLp() { |
| 493 | int marginStart = mExpanded && !mOverscrolled |
| 494 | ? mBatteryMarginExpanded |
| 495 | : mBatteryMarginKeyguard; |
| 496 | MarginLayoutParams lp = (MarginLayoutParams) mBatteryLevel.getLayoutParams(); |
| 497 | if (marginStart != lp.getMarginStart()) { |
| 498 | lp.setMarginStart(marginStart); |
| 499 | mBatteryLevel.setLayoutParams(lp); |
| 500 | } |
| 501 | } |
| 502 | |
Jorim Jaggi | 5404542 | 2014-07-03 18:30:40 +0200 | [diff] [blame] | 503 | public void setExpansion(float t) { |
| 504 | float height = mCollapsedHeight + t * (mExpandedHeight - mCollapsedHeight); |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 505 | if (height < mCollapsedHeight) { |
| 506 | height = mCollapsedHeight; |
| 507 | } |
| 508 | if (height > mExpandedHeight) { |
| 509 | height = mExpandedHeight; |
| 510 | } |
Jorim Jaggi | db3e6ed | 2014-05-12 20:18:47 +0200 | [diff] [blame] | 511 | setClipping(height); |
| 512 | } |
| 513 | |
| 514 | private void setClipping(float height) { |
| 515 | mClipBounds.set(getPaddingLeft(), 0, getWidth() - getPaddingRight(), (int) height); |
| 516 | setClipBounds(mClipBounds); |
Chris Craik | 7b7ca3c | 2014-07-11 13:32:19 -0700 | [diff] [blame] | 517 | invalidateOutline(); |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 518 | } |
| 519 | |
Jorim Jaggi | 0d74eeb | 2014-05-09 22:05:24 +0200 | [diff] [blame] | 520 | public void attachSystemIcons(LinearLayout systemIcons) { |
| 521 | mSystemIconsContainer.addView(systemIcons); |
Jorim Jaggi | 13c1b1f | 2014-05-11 21:55:00 +0200 | [diff] [blame] | 522 | mStatusIcons = systemIcons.findViewById(R.id.statusIcons); |
| 523 | mSignalCluster = systemIcons.findViewById(R.id.signal_cluster); |
John Spurlock | 312b792 | 2014-07-22 22:23:42 -0400 | [diff] [blame] | 524 | mSignalCluster.addOnLayoutChangeListener(mStatusIconClipper); |
Jorim Jaggi | 13c1b1f | 2014-05-11 21:55:00 +0200 | [diff] [blame] | 525 | } |
| 526 | |
| 527 | public void onSystemIconsDetached() { |
| 528 | if (mStatusIcons != null) { |
John Spurlock | 604ae09 | 2014-07-17 18:22:45 -0400 | [diff] [blame] | 529 | mStatusIcons.setVisibility(View.VISIBLE); |
Jorim Jaggi | 13c1b1f | 2014-05-11 21:55:00 +0200 | [diff] [blame] | 530 | } |
| 531 | if (mSignalCluster != null) { |
John Spurlock | 312b792 | 2014-07-22 22:23:42 -0400 | [diff] [blame] | 532 | mSignalCluster.removeOnLayoutChangeListener(mStatusIconClipper); |
Jorim Jaggi | 13c1b1f | 2014-05-11 21:55:00 +0200 | [diff] [blame] | 533 | mSignalCluster.setVisibility(View.VISIBLE); |
| 534 | } |
| 535 | mStatusIcons = null; |
| 536 | mSignalCluster = null; |
Jorim Jaggi | 0d74eeb | 2014-05-09 22:05:24 +0200 | [diff] [blame] | 537 | } |
| 538 | |
| 539 | public void setKeyguardShowing(boolean keyguardShowing) { |
Jorim Jaggi | 9054d94 | 2014-05-09 22:47:28 +0200 | [diff] [blame] | 540 | mKeyguardShowing = keyguardShowing; |
Jorim Jaggi | 9054d94 | 2014-05-09 22:47:28 +0200 | [diff] [blame] | 541 | updateHeights(); |
Jorim Jaggi | e18c2cd | 2014-05-08 19:16:49 +0200 | [diff] [blame] | 542 | updateWidth(); |
Jorim Jaggi | 740beb5 | 2014-05-11 18:53:19 +0200 | [diff] [blame] | 543 | updateVisibilities(); |
Jorim Jaggi | f62f2bb | 2014-05-25 22:28:41 +0200 | [diff] [blame] | 544 | updateZTranslation(); |
Jorim Jaggi | 129e7ac | 2014-06-10 22:03:48 +0200 | [diff] [blame] | 545 | updatePadding(); |
| 546 | updateMultiUserSwitch(); |
Jorim Jaggi | 853b070 | 2014-07-05 04:31:14 +0200 | [diff] [blame] | 547 | updateClickTargets(); |
Jorim Jaggi | d4aafe9 | 2014-07-10 21:00:57 +0200 | [diff] [blame] | 548 | updateBatteryLevelPaddingEnd(); |
Jorim Jaggi | 87d84d4 | 2014-07-28 12:14:48 +0200 | [diff] [blame^] | 549 | updateAvatarScale(); |
John Spurlock | 312b792 | 2014-07-22 22:23:42 -0400 | [diff] [blame] | 550 | mStatusIconClipper.update(); |
Jorim Jaggi | 0d74eeb | 2014-05-09 22:05:24 +0200 | [diff] [blame] | 551 | } |
Jorim Jaggi | 3d878be | 2014-05-10 03:22:32 +0200 | [diff] [blame] | 552 | |
| 553 | public void setUserInfoController(UserInfoController userInfoController) { |
Jorim Jaggi | 3f48f46 | 2014-07-08 16:53:29 +0200 | [diff] [blame] | 554 | userInfoController.addListener(new UserInfoController.OnUserInfoChangedListener() { |
| 555 | @Override |
| 556 | public void onUserInfoChanged(String name, Drawable picture) { |
| 557 | mMultiUserAvatar.setImageDrawable(picture); |
| 558 | } |
| 559 | }); |
Jorim Jaggi | 3d878be | 2014-05-10 03:22:32 +0200 | [diff] [blame] | 560 | } |
| 561 | |
Jorim Jaggi | 13c1b1f | 2014-05-11 21:55:00 +0200 | [diff] [blame] | 562 | @Override |
| 563 | public void onClick(View v) { |
| 564 | if (v == mSettingsButton) { |
| 565 | startSettingsActivity(); |
Jorim Jaggi | 853b070 | 2014-07-05 04:31:14 +0200 | [diff] [blame] | 566 | } else if (v == mSystemIconsSuperContainer) { |
| 567 | startBatteryActivity(); |
Jorim Jaggi | c7dea6e | 2014-07-26 14:36:57 +0200 | [diff] [blame] | 568 | } else if (v == mAlarmStatus && mNextAlarm != null) { |
| 569 | PendingIntent showIntent = mNextAlarm.getShowIntent(); |
| 570 | if (showIntent != null && showIntent.isActivity()) { |
| 571 | mActivityStarter.startActivity(showIntent.getIntent()); |
| 572 | } |
Jorim Jaggi | 13c1b1f | 2014-05-11 21:55:00 +0200 | [diff] [blame] | 573 | } |
| 574 | } |
| 575 | |
| 576 | private void startSettingsActivity() { |
| 577 | mActivityStarter.startActivity(new Intent(android.provider.Settings.ACTION_SETTINGS)); |
| 578 | } |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 579 | |
Jorim Jaggi | 853b070 | 2014-07-05 04:31:14 +0200 | [diff] [blame] | 580 | private void startBatteryActivity() { |
| 581 | mActivityStarter.startActivity(new Intent(Intent.ACTION_POWER_USAGE_SUMMARY)); |
| 582 | } |
| 583 | |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 584 | public void setQSPanel(QSPanel qsp) { |
| 585 | mQSPanel = qsp; |
John Spurlock | 3e04cc8 | 2014-05-30 12:34:03 -0400 | [diff] [blame] | 586 | if (mQSPanel != null) { |
| 587 | mQSPanel.setCallback(mQsPanelCallback); |
| 588 | } |
Adrian Roos | 1ef80fe | 2014-07-14 22:53:54 +0200 | [diff] [blame] | 589 | mMultiUserSwitch.setQsPanel(qsp); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 590 | } |
John Spurlock | 3e04cc8 | 2014-05-30 12:34:03 -0400 | [diff] [blame] | 591 | |
Adrian Roos | 723632e | 2014-07-23 21:13:21 +0200 | [diff] [blame] | 592 | public void setKeyguarUserSwitcher(KeyguardUserSwitcher keyguardUserSwitcher) { |
Jorim Jaggi | bc976e3 | 2014-07-25 16:42:34 +0200 | [diff] [blame] | 593 | mKeyguardUserSwitcher = keyguardUserSwitcher; |
Adrian Roos | 723632e | 2014-07-23 21:13:21 +0200 | [diff] [blame] | 594 | mMultiUserSwitch.setKeyguardUserSwitcher(keyguardUserSwitcher); |
| 595 | } |
| 596 | |
Selim Cinek | c0ce82d | 2014-06-10 13:21:15 +0200 | [diff] [blame] | 597 | @Override |
| 598 | public boolean shouldDelayChildPressedState() { |
| 599 | return true; |
| 600 | } |
Selim Cinek | 45f904a | 2014-06-11 11:42:53 +0200 | [diff] [blame] | 601 | |
Adrian Roos | 59a6127 | 2014-06-06 19:07:24 +0200 | [diff] [blame] | 602 | public void setShowEmergencyCallsOnly(boolean show) { |
| 603 | mShowEmergencyCallsOnly = show; |
| 604 | if (mExpanded) { |
| 605 | updateVisibilities(); |
Adrian Roos | 59a6127 | 2014-06-06 19:07:24 +0200 | [diff] [blame] | 606 | } |
| 607 | } |
| 608 | |
Adrian Roos | 8ddb2da | 2014-06-16 18:56:22 -0700 | [diff] [blame] | 609 | public void setKeyguardUserSwitcherShowing(boolean showing) { |
Adrian Roos | 8ddb2da | 2014-06-16 18:56:22 -0700 | [diff] [blame] | 610 | mKeyguardUserSwitcherShowing = showing; |
| 611 | updateVisibilities(); |
| 612 | updateSystemIconsLayoutParams(); |
| 613 | } |
Jorim Jaggi | 2580a976 | 2014-06-25 03:08:25 +0200 | [diff] [blame] | 614 | |
| 615 | @Override |
| 616 | public boolean hasOverlappingRendering() { |
| 617 | return !mKeyguardShowing || mExpanded; |
| 618 | } |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 619 | |
Jorim Jaggi | 266f677 | 2014-07-10 19:13:17 +0200 | [diff] [blame] | 620 | @Override |
| 621 | protected void dispatchSetPressed(boolean pressed) { |
| 622 | // We don't want that everything lights up when we click on the header, so block the request |
| 623 | // here. |
| 624 | } |
| 625 | |
John Spurlock | 312b792 | 2014-07-22 22:23:42 -0400 | [diff] [blame] | 626 | private final class StatusIconClipper implements OnLayoutChangeListener { |
John Spurlock | 07f6d3b | 2014-07-17 10:11:40 -0400 | [diff] [blame] | 627 | private final Rect mClipBounds = new Rect(); |
| 628 | |
| 629 | @Override |
| 630 | public void onLayoutChange(View v, int left, int top, int right, |
| 631 | int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { |
| 632 | // Hide the statusIcons in the header by clipping them. Can't touch visibility since |
| 633 | // they are mirrored to the real status bar. |
John Spurlock | 604ae09 | 2014-07-17 18:22:45 -0400 | [diff] [blame] | 634 | mClipBounds.set(left, 0, mSystemIconsContainer.getWidth(), |
| 635 | mSystemIconsContainer.getHeight()); |
John Spurlock | 312b792 | 2014-07-22 22:23:42 -0400 | [diff] [blame] | 636 | update(); |
John Spurlock | 07f6d3b | 2014-07-17 10:11:40 -0400 | [diff] [blame] | 637 | } |
John Spurlock | 312b792 | 2014-07-22 22:23:42 -0400 | [diff] [blame] | 638 | |
| 639 | public void update() { |
John Spurlock | 2eec8fe | 2014-07-24 12:16:14 -0400 | [diff] [blame] | 640 | final boolean collapsedKeyguard = mKeyguardShowing && !mExpanded; |
| 641 | final boolean expanded = mExpanded && !mOverscrolled; |
| 642 | mSystemIconsContainer.setClipBounds(collapsedKeyguard || expanded ? null : mClipBounds); |
John Spurlock | 312b792 | 2014-07-22 22:23:42 -0400 | [diff] [blame] | 643 | } |
| 644 | } |
John Spurlock | 07f6d3b | 2014-07-17 10:11:40 -0400 | [diff] [blame] | 645 | |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 646 | private final QSPanel.Callback mQsPanelCallback = new QSPanel.Callback() { |
| 647 | @Override |
| 648 | public void onToggleStateChanged(final boolean state) { |
| 649 | post(new Runnable() { |
| 650 | @Override |
| 651 | public void run() { |
| 652 | handleToggleStateChanged(state); |
| 653 | } |
| 654 | }); |
| 655 | } |
| 656 | |
| 657 | @Override |
| 658 | public void onShowingDetail(final QSTile.DetailAdapter detail) { |
| 659 | post(new Runnable() { |
| 660 | @Override |
| 661 | public void run() { |
| 662 | handleShowingDetail(detail); |
| 663 | } |
| 664 | }); |
| 665 | } |
| 666 | |
John Spurlock | 486b78e | 2014-07-07 08:37:56 -0400 | [diff] [blame] | 667 | @Override |
| 668 | public void onScanStateChanged(final boolean state) { |
| 669 | post(new Runnable() { |
| 670 | @Override |
| 671 | public void run() { |
| 672 | handleScanStateChanged(state); |
| 673 | } |
| 674 | }); |
| 675 | } |
| 676 | |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 677 | private void handleToggleStateChanged(boolean state) { |
John Spurlock | 486b78e | 2014-07-07 08:37:56 -0400 | [diff] [blame] | 678 | mQsDetailHeaderSwitch.setChecked(state); |
| 679 | } |
| 680 | |
| 681 | private void handleScanStateChanged(boolean state) { |
| 682 | // TODO - waiting on framework asset |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 683 | } |
| 684 | |
| 685 | private void handleShowingDetail(final QSTile.DetailAdapter detail) { |
| 686 | final boolean showingDetail = detail != null; |
Jorim Jaggi | c7dea6e | 2014-07-26 14:36:57 +0200 | [diff] [blame] | 687 | transition(mClock, !showingDetail); |
| 688 | transition(mDateGroup, !showingDetail); |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 689 | transition(mQsDetailHeader, showingDetail); |
| 690 | if (showingDetail) { |
John Spurlock | 486b78e | 2014-07-07 08:37:56 -0400 | [diff] [blame] | 691 | mQsDetailHeaderTitle.setText(detail.getTitle()); |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 692 | final Boolean toggleState = detail.getToggleState(); |
| 693 | if (toggleState == null) { |
John Spurlock | 486b78e | 2014-07-07 08:37:56 -0400 | [diff] [blame] | 694 | mQsDetailHeaderSwitch.setVisibility(INVISIBLE); |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 695 | mQsDetailHeader.setClickable(false); |
| 696 | } else { |
John Spurlock | 486b78e | 2014-07-07 08:37:56 -0400 | [diff] [blame] | 697 | mQsDetailHeaderSwitch.setVisibility(VISIBLE); |
| 698 | mQsDetailHeaderSwitch.setChecked(toggleState); |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 699 | mQsDetailHeader.setClickable(true); |
| 700 | mQsDetailHeader.setOnClickListener(new OnClickListener() { |
| 701 | @Override |
| 702 | public void onClick(View v) { |
John Spurlock | a7cf559 | 2014-07-15 10:55:08 -0400 | [diff] [blame] | 703 | detail.setToggleState(!mQsDetailHeaderSwitch.isChecked()); |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 704 | } |
| 705 | }); |
| 706 | } |
| 707 | } else { |
| 708 | mQsDetailHeader.setClickable(false); |
| 709 | } |
| 710 | } |
| 711 | |
| 712 | private void transition(final View v, final boolean in) { |
| 713 | if (in) { |
| 714 | v.bringToFront(); |
| 715 | } |
| 716 | v.animate().alpha(in ? 1 : 0).withLayer().start(); |
| 717 | } |
| 718 | }; |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 719 | } |