Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [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 | * |
Peter Schiller | b124d56 | 2015-12-11 21:31:17 -0800 | [diff] [blame] | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 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.recents.views; |
| 18 | |
Winson | c5ef63f | 2016-01-21 14:39:23 -0800 | [diff] [blame] | 19 | import android.animation.Animator; |
| 20 | import android.animation.AnimatorListenerAdapter; |
Winson | 94a0e89 | 2016-01-08 16:06:50 -0800 | [diff] [blame] | 21 | import android.annotation.Nullable; |
Winson | c5ef63f | 2016-01-21 14:39:23 -0800 | [diff] [blame] | 22 | import android.content.ComponentName; |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 23 | import android.content.Context; |
Winson | c5ef63f | 2016-01-21 14:39:23 -0800 | [diff] [blame] | 24 | import android.content.pm.ActivityInfo; |
Winson | 94a0e89 | 2016-01-08 16:06:50 -0800 | [diff] [blame] | 25 | import android.content.res.Resources; |
Winson Chung | cd23c84 | 2014-05-29 18:30:51 -0700 | [diff] [blame] | 26 | import android.graphics.Canvas; |
Winson Chung | a0e88b5 | 2014-08-11 19:25:42 -0700 | [diff] [blame] | 27 | import android.graphics.Color; |
Winson | 94a0e89 | 2016-01-08 16:06:50 -0800 | [diff] [blame] | 28 | import android.graphics.ColorFilter; |
Winson Chung | cd23c84 | 2014-05-29 18:30:51 -0700 | [diff] [blame] | 29 | import android.graphics.Paint; |
Winson | 94a0e89 | 2016-01-08 16:06:50 -0800 | [diff] [blame] | 30 | import android.graphics.PixelFormat; |
Winson | c5ef63f | 2016-01-21 14:39:23 -0800 | [diff] [blame] | 31 | import android.graphics.PorterDuff; |
Skuhne | 8aa7d16 | 2015-03-20 13:40:53 -0700 | [diff] [blame] | 32 | import android.graphics.Rect; |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 33 | import android.graphics.drawable.Drawable; |
Winson | 18227e4 | 2016-06-08 12:57:40 -0700 | [diff] [blame] | 34 | import android.graphics.drawable.RippleDrawable; |
Peter Schiller | b124d56 | 2015-12-11 21:31:17 -0800 | [diff] [blame] | 35 | import android.os.CountDownTimer; |
Winson | c5ef63f | 2016-01-21 14:39:23 -0800 | [diff] [blame] | 36 | import android.support.v4.graphics.ColorUtils; |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 37 | import android.util.AttributeSet; |
Winson | 2170093 | 2016-03-24 17:26:23 -0700 | [diff] [blame] | 38 | import android.view.Gravity; |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 39 | import android.view.View; |
Winson | c5ef63f | 2016-01-21 14:39:23 -0800 | [diff] [blame] | 40 | import android.view.ViewAnimationUtils; |
Winson | 231bc9c | 2016-02-09 12:31:00 -0800 | [diff] [blame] | 41 | import android.view.ViewDebug; |
Winson | 2170093 | 2016-03-24 17:26:23 -0700 | [diff] [blame] | 42 | import android.view.ViewGroup; |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 43 | import android.widget.FrameLayout; |
| 44 | import android.widget.ImageView; |
Peter Schiller | b124d56 | 2015-12-11 21:31:17 -0800 | [diff] [blame] | 45 | import android.widget.ProgressBar; |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 46 | import android.widget.TextView; |
Winson | c0d7058 | 2016-01-29 10:24:39 -0800 | [diff] [blame] | 47 | |
Winson | 2536c7e | 2015-10-01 15:49:31 -0700 | [diff] [blame] | 48 | import com.android.internal.logging.MetricsLogger; |
Winson | c0d7058 | 2016-01-29 10:24:39 -0800 | [diff] [blame] | 49 | import com.android.systemui.Interpolators; |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 50 | import com.android.systemui.R; |
Winson Chung | f5e22e7 | 2014-05-02 18:35:35 -0700 | [diff] [blame] | 51 | import com.android.systemui.recents.Constants; |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 52 | import com.android.systemui.recents.Recents; |
Winson | 2536c7e | 2015-10-01 15:49:31 -0700 | [diff] [blame] | 53 | import com.android.systemui.recents.events.EventBus; |
Winson Chung | 48f2cda | 2015-12-11 13:20:12 -0500 | [diff] [blame] | 54 | import com.android.systemui.recents.events.activity.LaunchTaskEvent; |
Winson | 2536c7e | 2015-10-01 15:49:31 -0700 | [diff] [blame] | 55 | import com.android.systemui.recents.events.ui.ShowApplicationInfoEvent; |
Skuhne | 8aa7d16 | 2015-03-20 13:40:53 -0700 | [diff] [blame] | 56 | import com.android.systemui.recents.misc.SystemServicesProxy; |
Winson Chung | a0e88b5 | 2014-08-11 19:25:42 -0700 | [diff] [blame] | 57 | import com.android.systemui.recents.misc.Utilities; |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 58 | import com.android.systemui.recents.model.Task; |
| 59 | |
Winson Chung | 48f2cda | 2015-12-11 13:20:12 -0500 | [diff] [blame] | 60 | import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID; |
| 61 | import static android.app.ActivityManager.StackId.FULLSCREEN_WORKSPACE_STACK_ID; |
| 62 | import static android.app.ActivityManager.StackId.INVALID_STACK_ID; |
| 63 | |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 64 | /* The task bar view */ |
Winson | 2536c7e | 2015-10-01 15:49:31 -0700 | [diff] [blame] | 65 | public class TaskViewHeader extends FrameLayout |
| 66 | implements View.OnClickListener, View.OnLongClickListener { |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 67 | |
Winson | 12858a6 | 2016-02-24 11:06:01 -0800 | [diff] [blame] | 68 | private static final float HIGHLIGHT_LIGHTNESS_INCREMENT = 0.075f; |
Winson | c5ef63f | 2016-01-21 14:39:23 -0800 | [diff] [blame] | 69 | private static final float OVERLAY_LIGHTNESS_INCREMENT = -0.0625f; |
| 70 | private static final int OVERLAY_REVEAL_DURATION = 250; |
Peter Schiller | b124d56 | 2015-12-11 21:31:17 -0800 | [diff] [blame] | 71 | private static final long FOCUS_INDICATOR_INTERVAL_MS = 30; |
Winson | 94a0e89 | 2016-01-08 16:06:50 -0800 | [diff] [blame] | 72 | |
| 73 | /** |
| 74 | * A color drawable that draws a slight highlight at the top to help it stand out. |
| 75 | */ |
| 76 | private class HighlightColorDrawable extends Drawable { |
| 77 | |
| 78 | private Paint mHighlightPaint = new Paint(); |
| 79 | private Paint mBackgroundPaint = new Paint(); |
Winson | 8be1634 | 2016-02-09 11:53:27 -0800 | [diff] [blame] | 80 | private int mColor; |
| 81 | private float mDimAlpha; |
Winson | 94a0e89 | 2016-01-08 16:06:50 -0800 | [diff] [blame] | 82 | |
Winson | 94a0e89 | 2016-01-08 16:06:50 -0800 | [diff] [blame] | 83 | public HighlightColorDrawable() { |
| 84 | mBackgroundPaint.setColor(Color.argb(255, 0, 0, 0)); |
| 85 | mBackgroundPaint.setAntiAlias(true); |
| 86 | mHighlightPaint.setColor(Color.argb(255, 255, 255, 255)); |
| 87 | mHighlightPaint.setAntiAlias(true); |
| 88 | } |
| 89 | |
| 90 | public void setColorAndDim(int color, float dimAlpha) { |
Winson | 8be1634 | 2016-02-09 11:53:27 -0800 | [diff] [blame] | 91 | if (mColor != color || Float.compare(mDimAlpha, dimAlpha) != 0) { |
| 92 | mColor = color; |
| 93 | mDimAlpha = dimAlpha; |
| 94 | mBackgroundPaint.setColor(color); |
Winson | 94a0e89 | 2016-01-08 16:06:50 -0800 | [diff] [blame] | 95 | |
Winson | 8be1634 | 2016-02-09 11:53:27 -0800 | [diff] [blame] | 96 | ColorUtils.colorToHSL(color, mTmpHSL); |
| 97 | // TODO: Consider using the saturation of the color to adjust the lightness as well |
| 98 | mTmpHSL[2] = Math.min(1f, |
| 99 | mTmpHSL[2] + HIGHLIGHT_LIGHTNESS_INCREMENT * (1.0f - dimAlpha)); |
| 100 | mHighlightPaint.setColor(ColorUtils.HSLToColor(mTmpHSL)); |
Winson | 94a0e89 | 2016-01-08 16:06:50 -0800 | [diff] [blame] | 101 | |
Winson | 8be1634 | 2016-02-09 11:53:27 -0800 | [diff] [blame] | 102 | invalidateSelf(); |
| 103 | } |
Winson | 94a0e89 | 2016-01-08 16:06:50 -0800 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | @Override |
| 107 | public void setColorFilter(@Nullable ColorFilter colorFilter) { |
| 108 | // Do nothing |
| 109 | } |
| 110 | |
| 111 | @Override |
| 112 | public void setAlpha(int alpha) { |
| 113 | // Do nothing |
| 114 | } |
| 115 | |
| 116 | @Override |
| 117 | public void draw(Canvas canvas) { |
| 118 | // Draw the highlight at the top edge (but put the bottom edge just out of view) |
| 119 | canvas.drawRoundRect(0, 0, mTaskViewRect.width(), |
| 120 | 2 * Math.max(mHighlightHeight, mCornerRadius), |
| 121 | mCornerRadius, mCornerRadius, mHighlightPaint); |
| 122 | |
| 123 | // Draw the background with the rounded corners |
| 124 | canvas.drawRoundRect(0, mHighlightHeight, mTaskViewRect.width(), |
| 125 | getHeight() + mCornerRadius, |
| 126 | mCornerRadius, mCornerRadius, mBackgroundPaint); |
| 127 | } |
| 128 | |
| 129 | @Override |
| 130 | public int getOpacity() { |
| 131 | return PixelFormat.OPAQUE; |
| 132 | } |
Winson | 8be1634 | 2016-02-09 11:53:27 -0800 | [diff] [blame] | 133 | |
| 134 | public int getColor() { |
| 135 | return mColor; |
| 136 | } |
Winson | 94a0e89 | 2016-01-08 16:06:50 -0800 | [diff] [blame] | 137 | } |
| 138 | |
Winson | 2536c7e | 2015-10-01 15:49:31 -0700 | [diff] [blame] | 139 | Task mTask; |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 140 | |
Winson Chung | 353c0b9 | 2014-10-16 17:43:23 -0700 | [diff] [blame] | 141 | // Header views |
Winson Chung | 296278a | 2015-12-17 12:09:02 -0500 | [diff] [blame] | 142 | ImageView mIconView; |
| 143 | TextView mTitleView; |
Winson | c5ef63f | 2016-01-21 14:39:23 -0800 | [diff] [blame] | 144 | ImageView mMoveTaskButton; |
| 145 | ImageView mDismissButton; |
Winson | c5ef63f | 2016-01-21 14:39:23 -0800 | [diff] [blame] | 146 | FrameLayout mAppOverlayView; |
| 147 | ImageView mAppIconView; |
| 148 | ImageView mAppInfoView; |
| 149 | TextView mAppTitleView; |
Peter Schiller | b124d56 | 2015-12-11 21:31:17 -0800 | [diff] [blame] | 150 | ProgressBar mFocusTimerIndicator; |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 151 | |
Winson Chung | 353c0b9 | 2014-10-16 17:43:23 -0700 | [diff] [blame] | 152 | // Header drawables |
Winson | 231bc9c | 2016-02-09 12:31:00 -0800 | [diff] [blame] | 153 | @ViewDebug.ExportedProperty(category="recents") |
Winson | de0591a | 2015-12-04 17:24:35 -0800 | [diff] [blame] | 154 | Rect mTaskViewRect = new Rect(); |
Winson | 2170093 | 2016-03-24 17:26:23 -0700 | [diff] [blame] | 155 | int mHeaderBarHeight; |
| 156 | int mHeaderButtonPadding; |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 157 | int mCornerRadius; |
| 158 | int mHighlightHeight; |
Winson | 231bc9c | 2016-02-09 12:31:00 -0800 | [diff] [blame] | 159 | @ViewDebug.ExportedProperty(category="recents") |
Winson | 94a0e89 | 2016-01-08 16:06:50 -0800 | [diff] [blame] | 160 | float mDimAlpha; |
Winson Chung | 54e297a | 2014-05-09 17:15:32 -0700 | [diff] [blame] | 161 | Drawable mLightDismissDrawable; |
| 162 | Drawable mDarkDismissDrawable; |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 163 | Drawable mLightFreeformIcon; |
| 164 | Drawable mDarkFreeformIcon; |
| 165 | Drawable mLightFullscreenIcon; |
| 166 | Drawable mDarkFullscreenIcon; |
Winson | c5ef63f | 2016-01-21 14:39:23 -0800 | [diff] [blame] | 167 | Drawable mLightInfoIcon; |
| 168 | Drawable mDarkInfoIcon; |
Winson | 94a0e89 | 2016-01-08 16:06:50 -0800 | [diff] [blame] | 169 | int mTaskBarViewLightTextColor; |
| 170 | int mTaskBarViewDarkTextColor; |
Winson | 8be1634 | 2016-02-09 11:53:27 -0800 | [diff] [blame] | 171 | int mDisabledTaskBarBackgroundColor; |
Winson | c5ef63f | 2016-01-21 14:39:23 -0800 | [diff] [blame] | 172 | int mMoveTaskTargetStackId = INVALID_STACK_ID; |
Winson Chung | 54e297a | 2014-05-09 17:15:32 -0700 | [diff] [blame] | 173 | |
Winson | 94a0e89 | 2016-01-08 16:06:50 -0800 | [diff] [blame] | 174 | // Header background |
| 175 | private HighlightColorDrawable mBackground; |
Winson | c5ef63f | 2016-01-21 14:39:23 -0800 | [diff] [blame] | 176 | private HighlightColorDrawable mOverlayBackground; |
| 177 | private float[] mTmpHSL = new float[3]; |
Winson Chung | 353c0b9 | 2014-10-16 17:43:23 -0700 | [diff] [blame] | 178 | |
| 179 | // Header dim, which is only used when task view hardware layers are not used |
Winson | 94a0e89 | 2016-01-08 16:06:50 -0800 | [diff] [blame] | 180 | private Paint mDimLayerPaint = new Paint(); |
Winson Chung | cd23c84 | 2014-05-29 18:30:51 -0700 | [diff] [blame] | 181 | |
Peter Schiller | b124d56 | 2015-12-11 21:31:17 -0800 | [diff] [blame] | 182 | private CountDownTimer mFocusTimerCountDown; |
Peter Schiller | b124d56 | 2015-12-11 21:31:17 -0800 | [diff] [blame] | 183 | |
Winson Chung | ec396d6 | 2014-08-06 17:08:00 -0700 | [diff] [blame] | 184 | public TaskViewHeader(Context context) { |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 185 | this(context, null); |
| 186 | } |
| 187 | |
Winson Chung | ec396d6 | 2014-08-06 17:08:00 -0700 | [diff] [blame] | 188 | public TaskViewHeader(Context context, AttributeSet attrs) { |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 189 | this(context, attrs, 0); |
| 190 | } |
| 191 | |
Winson Chung | ec396d6 | 2014-08-06 17:08:00 -0700 | [diff] [blame] | 192 | public TaskViewHeader(Context context, AttributeSet attrs, int defStyleAttr) { |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 193 | this(context, attrs, defStyleAttr, 0); |
| 194 | } |
| 195 | |
Winson Chung | ec396d6 | 2014-08-06 17:08:00 -0700 | [diff] [blame] | 196 | public TaskViewHeader(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 197 | super(context, attrs, defStyleAttr, defStyleRes); |
Winson Chung | cd23c84 | 2014-05-29 18:30:51 -0700 | [diff] [blame] | 198 | setWillNotDraw(false); |
| 199 | |
| 200 | // Load the dismiss resources |
Winson | 94a0e89 | 2016-01-08 16:06:50 -0800 | [diff] [blame] | 201 | Resources res = context.getResources(); |
Winson Chung | 911f400 | 2015-02-13 13:49:36 -0800 | [diff] [blame] | 202 | mLightDismissDrawable = context.getDrawable(R.drawable.recents_dismiss_light); |
| 203 | mDarkDismissDrawable = context.getDrawable(R.drawable.recents_dismiss_dark); |
Jiaquan He | 90f4f52 | 2017-01-09 15:50:35 -0800 | [diff] [blame] | 204 | mCornerRadius = Recents.getConfiguration().isGridEnabled ? |
| 205 | res.getDimensionPixelSize(R.dimen.recents_grid_task_view_rounded_corners_radius) : |
| 206 | res.getDimensionPixelSize(R.dimen.recents_task_view_rounded_corners_radius); |
Winson | 94a0e89 | 2016-01-08 16:06:50 -0800 | [diff] [blame] | 207 | mHighlightHeight = res.getDimensionPixelSize(R.dimen.recents_task_view_highlight); |
| 208 | mTaskBarViewLightTextColor = context.getColor(R.color.recents_task_bar_light_text_color); |
| 209 | mTaskBarViewDarkTextColor = context.getColor(R.color.recents_task_bar_dark_text_color); |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 210 | mLightFreeformIcon = context.getDrawable(R.drawable.recents_move_task_freeform_light); |
| 211 | mDarkFreeformIcon = context.getDrawable(R.drawable.recents_move_task_freeform_dark); |
| 212 | mLightFullscreenIcon = context.getDrawable(R.drawable.recents_move_task_fullscreen_light); |
| 213 | mDarkFullscreenIcon = context.getDrawable(R.drawable.recents_move_task_fullscreen_dark); |
Winson | c5ef63f | 2016-01-21 14:39:23 -0800 | [diff] [blame] | 214 | mLightInfoIcon = context.getDrawable(R.drawable.recents_info_light); |
| 215 | mDarkInfoIcon = context.getDrawable(R.drawable.recents_info_dark); |
Winson | 8be1634 | 2016-02-09 11:53:27 -0800 | [diff] [blame] | 216 | mDisabledTaskBarBackgroundColor = |
| 217 | context.getColor(R.color.recents_task_bar_disabled_background_color); |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 218 | |
Winson | 94a0e89 | 2016-01-08 16:06:50 -0800 | [diff] [blame] | 219 | // Configure the background and dim |
| 220 | mBackground = new HighlightColorDrawable(); |
| 221 | mBackground.setColorAndDim(Color.argb(255, 0, 0, 0), 0f); |
| 222 | setBackground(mBackground); |
Winson | c5ef63f | 2016-01-21 14:39:23 -0800 | [diff] [blame] | 223 | mOverlayBackground = new HighlightColorDrawable(); |
Winson | 94a0e89 | 2016-01-08 16:06:50 -0800 | [diff] [blame] | 224 | mDimLayerPaint.setColor(Color.argb(255, 0, 0, 0)); |
| 225 | mDimLayerPaint.setAntiAlias(true); |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 226 | } |
| 227 | |
Winson | c5ef63f | 2016-01-21 14:39:23 -0800 | [diff] [blame] | 228 | /** |
| 229 | * Resets this header along with the TaskView. |
| 230 | */ |
| 231 | public void reset() { |
| 232 | hideAppOverlay(true /* immediate */); |
| 233 | } |
| 234 | |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 235 | @Override |
| 236 | protected void onFinishInflate() { |
Winson Chung | bbb3d3d | 2016-01-30 01:09:20 +0000 | [diff] [blame] | 237 | SystemServicesProxy ssp = Recents.getSystemServices(); |
| 238 | |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 239 | // Initialize the icon and description views |
Winson Chung | 296278a | 2015-12-17 12:09:02 -0500 | [diff] [blame] | 240 | mIconView = (ImageView) findViewById(R.id.icon); |
| 241 | mIconView.setOnLongClickListener(this); |
| 242 | mTitleView = (TextView) findViewById(R.id.title); |
Winson Chung | 54e297a | 2014-05-09 17:15:32 -0700 | [diff] [blame] | 243 | mDismissButton = (ImageView) findViewById(R.id.dismiss_task); |
Winson Chung | bbb3d3d | 2016-01-30 01:09:20 +0000 | [diff] [blame] | 244 | if (ssp.hasFreeformWorkspaceSupport()) { |
| 245 | mMoveTaskButton = (ImageView) findViewById(R.id.move_task); |
| 246 | } |
Winson | 2170093 | 2016-03-24 17:26:23 -0700 | [diff] [blame] | 247 | |
Winson | 619e40c | 2016-03-25 16:12:35 -0700 | [diff] [blame] | 248 | onConfigurationChanged(); |
Winson | 2170093 | 2016-03-24 17:26:23 -0700 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | /** |
| 252 | * Programmatically sets the layout params for a header bar layout. This is necessary because |
| 253 | * we can't get resources based on the current configuration, but instead need to get them |
| 254 | * based on the device configuration. |
| 255 | */ |
| 256 | private void updateLayoutParams(View icon, View title, View secondaryButton, View button) { |
| 257 | FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams( |
| 258 | ViewGroup.LayoutParams.MATCH_PARENT, mHeaderBarHeight, Gravity.TOP); |
| 259 | setLayoutParams(lp); |
| 260 | lp = new FrameLayout.LayoutParams(mHeaderBarHeight, mHeaderBarHeight, Gravity.START); |
| 261 | icon.setLayoutParams(lp); |
| 262 | lp = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, |
| 263 | ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.START | Gravity.CENTER_VERTICAL); |
Winson | a1ededd | 2016-03-25 12:23:12 -0700 | [diff] [blame] | 264 | lp.setMarginStart(mHeaderBarHeight); |
Winson | 1985237 | 2016-03-30 18:26:49 -0700 | [diff] [blame] | 265 | lp.setMarginEnd(mMoveTaskButton != null |
Winson | 2170093 | 2016-03-24 17:26:23 -0700 | [diff] [blame] | 266 | ? 2 * mHeaderBarHeight |
Winson | 1985237 | 2016-03-30 18:26:49 -0700 | [diff] [blame] | 267 | : mHeaderBarHeight); |
Winson | 2170093 | 2016-03-24 17:26:23 -0700 | [diff] [blame] | 268 | title.setLayoutParams(lp); |
| 269 | if (secondaryButton != null) { |
| 270 | lp = new FrameLayout.LayoutParams(mHeaderBarHeight, mHeaderBarHeight, Gravity.END); |
Winson | a1ededd | 2016-03-25 12:23:12 -0700 | [diff] [blame] | 271 | lp.setMarginEnd(mHeaderBarHeight); |
Winson | 2170093 | 2016-03-24 17:26:23 -0700 | [diff] [blame] | 272 | secondaryButton.setLayoutParams(lp); |
| 273 | secondaryButton.setPadding(mHeaderButtonPadding, mHeaderButtonPadding, |
| 274 | mHeaderButtonPadding, mHeaderButtonPadding); |
| 275 | } |
| 276 | lp = new FrameLayout.LayoutParams(mHeaderBarHeight, mHeaderBarHeight, Gravity.END); |
| 277 | button.setLayoutParams(lp); |
| 278 | button.setPadding(mHeaderButtonPadding, mHeaderButtonPadding, mHeaderButtonPadding, |
| 279 | mHeaderButtonPadding); |
Winson Chung | 54e297a | 2014-05-09 17:15:32 -0700 | [diff] [blame] | 280 | } |
| 281 | |
Winson | 619e40c | 2016-03-25 16:12:35 -0700 | [diff] [blame] | 282 | /** |
| 283 | * Update the header view when the configuration changes. |
| 284 | */ |
Winson | 670ea71 | 2016-04-12 17:02:26 -0700 | [diff] [blame] | 285 | public void onConfigurationChanged() { |
Winson | 619e40c | 2016-03-25 16:12:35 -0700 | [diff] [blame] | 286 | // Update the dimensions of everything in the header. We do this because we need to use |
| 287 | // resources for the display, and not the current configuration. |
| 288 | Resources res = getResources(); |
Jorim Jaggi | 25160db | 2016-04-18 16:03:36 -0700 | [diff] [blame] | 289 | int headerBarHeight = TaskStackLayoutAlgorithm.getDimensionForDevice(getContext(), |
Winson | 619e40c | 2016-03-25 16:12:35 -0700 | [diff] [blame] | 290 | R.dimen.recents_task_view_header_height, |
| 291 | R.dimen.recents_task_view_header_height, |
| 292 | R.dimen.recents_task_view_header_height, |
| 293 | R.dimen.recents_task_view_header_height_tablet_land, |
| 294 | R.dimen.recents_task_view_header_height, |
Manu Cornet | bf8e290 | 2016-12-20 08:29:33 -0800 | [diff] [blame] | 295 | R.dimen.recents_task_view_header_height_tablet_land, |
| 296 | R.dimen.recents_grid_task_view_header_height); |
Jorim Jaggi | 25160db | 2016-04-18 16:03:36 -0700 | [diff] [blame] | 297 | int headerButtonPadding = TaskStackLayoutAlgorithm.getDimensionForDevice(getContext(), |
Winson | 619e40c | 2016-03-25 16:12:35 -0700 | [diff] [blame] | 298 | R.dimen.recents_task_view_header_button_padding, |
| 299 | R.dimen.recents_task_view_header_button_padding, |
| 300 | R.dimen.recents_task_view_header_button_padding, |
| 301 | R.dimen.recents_task_view_header_button_padding_tablet_land, |
| 302 | R.dimen.recents_task_view_header_button_padding, |
Manu Cornet | bf8e290 | 2016-12-20 08:29:33 -0800 | [diff] [blame] | 303 | R.dimen.recents_task_view_header_button_padding_tablet_land, |
| 304 | R.dimen.recents_grid_task_view_header_button_padding); |
Winson | 670ea71 | 2016-04-12 17:02:26 -0700 | [diff] [blame] | 305 | if (headerBarHeight != mHeaderBarHeight || headerButtonPadding != mHeaderButtonPadding) { |
| 306 | mHeaderBarHeight = headerBarHeight; |
| 307 | mHeaderButtonPadding = headerButtonPadding; |
| 308 | updateLayoutParams(mIconView, mTitleView, mMoveTaskButton, mDismissButton); |
| 309 | if (mAppOverlayView != null) { |
| 310 | updateLayoutParams(mAppIconView, mAppTitleView, null, mAppInfoView); |
| 311 | } |
Winson | 619e40c | 2016-03-25 16:12:35 -0700 | [diff] [blame] | 312 | } |
| 313 | } |
| 314 | |
Winson Chung | bbb3d3d | 2016-01-30 01:09:20 +0000 | [diff] [blame] | 315 | @Override |
| 316 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) { |
| 317 | super.onLayout(changed, left, top, right, bottom); |
| 318 | |
| 319 | // Since we update the position of children based on the width of the parent and this view |
| 320 | // recompute these changes with the new view size |
| 321 | onTaskViewSizeChanged(mTaskViewRect.width(), mTaskViewRect.height()); |
| 322 | } |
| 323 | |
Winson | de0591a | 2015-12-04 17:24:35 -0800 | [diff] [blame] | 324 | /** |
| 325 | * Called when the task view frame changes, allowing us to move the contents of the header |
| 326 | * to match the frame changes. |
| 327 | */ |
| 328 | public void onTaskViewSizeChanged(int width, int height) { |
| 329 | mTaskViewRect.set(0, 0, width, height); |
Winson Chung | 48f2cda | 2015-12-11 13:20:12 -0500 | [diff] [blame] | 330 | |
Winson Chung | bbb3d3d | 2016-01-30 01:09:20 +0000 | [diff] [blame] | 331 | boolean showTitle = true; |
| 332 | boolean showMoveIcon = true; |
| 333 | boolean showDismissIcon = true; |
| 334 | int rightInset = width - getMeasuredWidth(); |
| 335 | |
| 336 | if (mTask != null && mTask.isFreeformTask()) { |
| 337 | // For freeform tasks, we always show the app icon, and only show the title, move-task |
| 338 | // icon, and the dismiss icon if there is room |
| 339 | int appIconWidth = mIconView.getMeasuredWidth(); |
| 340 | int titleWidth = (int) mTitleView.getPaint().measureText(mTask.title); |
| 341 | int dismissWidth = mDismissButton.getMeasuredWidth(); |
| 342 | int moveTaskWidth = mMoveTaskButton != null |
| 343 | ? mMoveTaskButton.getMeasuredWidth() |
| 344 | : 0; |
| 345 | showTitle = width >= (appIconWidth + dismissWidth + moveTaskWidth + titleWidth); |
| 346 | showMoveIcon = width >= (appIconWidth + dismissWidth + moveTaskWidth); |
| 347 | showDismissIcon = width >= (appIconWidth + dismissWidth); |
Winson | de0591a | 2015-12-04 17:24:35 -0800 | [diff] [blame] | 348 | } |
Winson Chung | bbb3d3d | 2016-01-30 01:09:20 +0000 | [diff] [blame] | 349 | |
| 350 | mTitleView.setVisibility(showTitle ? View.VISIBLE : View.INVISIBLE); |
| 351 | if (mMoveTaskButton != null) { |
| 352 | mMoveTaskButton.setVisibility(showMoveIcon ? View.VISIBLE : View.INVISIBLE); |
| 353 | mMoveTaskButton.setTranslationX(rightInset); |
Winson Chung | 48f2cda | 2015-12-11 13:20:12 -0500 | [diff] [blame] | 354 | } |
Winson Chung | bbb3d3d | 2016-01-30 01:09:20 +0000 | [diff] [blame] | 355 | mDismissButton.setVisibility(showDismissIcon ? View.VISIBLE : View.INVISIBLE); |
| 356 | mDismissButton.setTranslationX(rightInset); |
Winson | 67c7957 | 2016-04-13 14:02:18 -0700 | [diff] [blame] | 357 | |
| 358 | setLeftTopRightBottom(0, 0, width, getMeasuredHeight()); |
Winson | de0591a | 2015-12-04 17:24:35 -0800 | [diff] [blame] | 359 | } |
| 360 | |
Winson Chung | cd23c84 | 2014-05-29 18:30:51 -0700 | [diff] [blame] | 361 | @Override |
Winson | be8e696 | 2016-02-01 14:27:52 -0800 | [diff] [blame] | 362 | public void onDrawForeground(Canvas canvas) { |
| 363 | super.onDrawForeground(canvas); |
Winson | 94a0e89 | 2016-01-08 16:06:50 -0800 | [diff] [blame] | 364 | |
| 365 | // Draw the dim layer with the rounded corners |
| 366 | canvas.drawRoundRect(0, 0, mTaskViewRect.width(), getHeight() + mCornerRadius, |
| 367 | mCornerRadius, mCornerRadius, mDimLayerPaint); |
Winson Chung | cd23c84 | 2014-05-29 18:30:51 -0700 | [diff] [blame] | 368 | } |
| 369 | |
Peter Schiller | b124d56 | 2015-12-11 21:31:17 -0800 | [diff] [blame] | 370 | /** Starts the focus timer. */ |
Winson | 4b9cded | 2016-01-26 16:26:47 -0800 | [diff] [blame] | 371 | public void startFocusTimerIndicator(int duration) { |
Winson | c5ef63f | 2016-01-21 14:39:23 -0800 | [diff] [blame] | 372 | if (mFocusTimerIndicator == null) { |
| 373 | return; |
| 374 | } |
| 375 | |
Peter Schiller | b124d56 | 2015-12-11 21:31:17 -0800 | [diff] [blame] | 376 | mFocusTimerIndicator.setVisibility(View.VISIBLE); |
Winson | 4b9cded | 2016-01-26 16:26:47 -0800 | [diff] [blame] | 377 | mFocusTimerIndicator.setMax(duration); |
| 378 | mFocusTimerIndicator.setProgress(duration); |
| 379 | if (mFocusTimerCountDown != null) { |
| 380 | mFocusTimerCountDown.cancel(); |
Peter Schiller | b124d56 | 2015-12-11 21:31:17 -0800 | [diff] [blame] | 381 | } |
Winson | 4b9cded | 2016-01-26 16:26:47 -0800 | [diff] [blame] | 382 | mFocusTimerCountDown = new CountDownTimer(duration, |
| 383 | FOCUS_INDICATOR_INTERVAL_MS) { |
| 384 | public void onTick(long millisUntilFinished) { |
| 385 | mFocusTimerIndicator.setProgress((int) millisUntilFinished); |
| 386 | } |
| 387 | |
| 388 | public void onFinish() { |
| 389 | // Do nothing |
| 390 | } |
| 391 | }.start(); |
Peter Schiller | b124d56 | 2015-12-11 21:31:17 -0800 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | /** Cancels the focus timer. */ |
| 395 | public void cancelFocusTimerIndicator() { |
Winson | c5ef63f | 2016-01-21 14:39:23 -0800 | [diff] [blame] | 396 | if (mFocusTimerIndicator == null) { |
| 397 | return; |
| 398 | } |
| 399 | |
| 400 | if (mFocusTimerCountDown != null) { |
Peter Schiller | b124d56 | 2015-12-11 21:31:17 -0800 | [diff] [blame] | 401 | mFocusTimerCountDown.cancel(); |
| 402 | mFocusTimerIndicator.setProgress(0); |
| 403 | mFocusTimerIndicator.setVisibility(View.INVISIBLE); |
| 404 | } |
| 405 | } |
| 406 | |
Winson | 22574af | 2016-03-23 19:00:28 -0700 | [diff] [blame] | 407 | /** Only exposed for the workaround for b/27815919. */ |
| 408 | public ImageView getIconView() { |
| 409 | return mIconView; |
| 410 | } |
| 411 | |
Peter Schiller | b124d56 | 2015-12-11 21:31:17 -0800 | [diff] [blame] | 412 | /** Returns the secondary color for a primary color. */ |
| 413 | int getSecondaryColor(int primaryColor, boolean useLightOverlayColor) { |
| 414 | int overlayColor = useLightOverlayColor ? Color.WHITE : Color.BLACK; |
| 415 | return Utilities.getColorWithOverlay(primaryColor, overlayColor, 0.8f); |
| 416 | } |
| 417 | |
Winson Chung | 353c0b9 | 2014-10-16 17:43:23 -0700 | [diff] [blame] | 418 | /** |
| 419 | * Sets the dim alpha, only used when we are not using hardware layers. |
| 420 | * (see RecentsConfiguration.useHardwareLayers) |
| 421 | */ |
Winson | e693aaf | 2016-03-01 12:05:59 -0800 | [diff] [blame] | 422 | public void setDimAlpha(float dimAlpha) { |
| 423 | if (Float.compare(mDimAlpha, dimAlpha) != 0) { |
| 424 | mDimAlpha = dimAlpha; |
Winson | 59924fe | 2016-03-17 14:13:18 -0700 | [diff] [blame] | 425 | mTitleView.setAlpha(1f - dimAlpha); |
Winson | e693aaf | 2016-03-01 12:05:59 -0800 | [diff] [blame] | 426 | updateBackgroundColor(mBackground.getColor(), dimAlpha); |
| 427 | } |
Winson Chung | 353c0b9 | 2014-10-16 17:43:23 -0700 | [diff] [blame] | 428 | } |
| 429 | |
Winson | 94a0e89 | 2016-01-08 16:06:50 -0800 | [diff] [blame] | 430 | /** |
| 431 | * Updates the background and highlight colors for this header. |
| 432 | */ |
Winson | 8be1634 | 2016-02-09 11:53:27 -0800 | [diff] [blame] | 433 | private void updateBackgroundColor(int color, float dimAlpha) { |
Winson | 94a0e89 | 2016-01-08 16:06:50 -0800 | [diff] [blame] | 434 | if (mTask != null) { |
Winson | 8be1634 | 2016-02-09 11:53:27 -0800 | [diff] [blame] | 435 | mBackground.setColorAndDim(color, dimAlpha); |
Winson | c5ef63f | 2016-01-21 14:39:23 -0800 | [diff] [blame] | 436 | // TODO: Consider using the saturation of the color to adjust the lightness as well |
Winson | 8be1634 | 2016-02-09 11:53:27 -0800 | [diff] [blame] | 437 | ColorUtils.colorToHSL(color, mTmpHSL); |
Winson | c5ef63f | 2016-01-21 14:39:23 -0800 | [diff] [blame] | 438 | mTmpHSL[2] = Math.min(1f, mTmpHSL[2] + OVERLAY_LIGHTNESS_INCREMENT * (1.0f - dimAlpha)); |
| 439 | mOverlayBackground.setColorAndDim(ColorUtils.HSLToColor(mTmpHSL), dimAlpha); |
Winson | 94a0e89 | 2016-01-08 16:06:50 -0800 | [diff] [blame] | 440 | mDimLayerPaint.setAlpha((int) (dimAlpha * 255)); |
Winson Chung | bbb3d3d | 2016-01-30 01:09:20 +0000 | [diff] [blame] | 441 | invalidate(); |
Winson | 94a0e89 | 2016-01-08 16:06:50 -0800 | [diff] [blame] | 442 | } |
| 443 | } |
| 444 | |
Winson | d2a0306 | 2016-04-15 11:19:07 -0700 | [diff] [blame] | 445 | /** |
| 446 | * Binds the bar view to the task. |
| 447 | */ |
| 448 | public void bindToTask(Task t, boolean touchExplorationEnabled, boolean disabledInSafeMode) { |
Winson | 2536c7e | 2015-10-01 15:49:31 -0700 | [diff] [blame] | 449 | mTask = t; |
| 450 | |
Winson | 8be1634 | 2016-02-09 11:53:27 -0800 | [diff] [blame] | 451 | int primaryColor = disabledInSafeMode |
| 452 | ? mDisabledTaskBarBackgroundColor |
| 453 | : t.colorPrimary; |
Winson | e693aaf | 2016-03-01 12:05:59 -0800 | [diff] [blame] | 454 | if (mBackground.getColor() != primaryColor) { |
| 455 | updateBackgroundColor(primaryColor, mDimAlpha); |
| 456 | } |
Winson Chung | 296278a | 2015-12-17 12:09:02 -0500 | [diff] [blame] | 457 | if (!mTitleView.getText().toString().equals(t.title)) { |
| 458 | mTitleView.setText(t.title); |
Winson Chung | bdbb87d | 2014-07-09 14:29:13 -0700 | [diff] [blame] | 459 | } |
Winson | b92dd63 | 2016-04-04 11:02:11 -0700 | [diff] [blame] | 460 | mTitleView.setContentDescription(t.titleDescription); |
Winson Chung | 296278a | 2015-12-17 12:09:02 -0500 | [diff] [blame] | 461 | mTitleView.setTextColor(t.useLightOnPrimaryColor ? |
Winson | 94a0e89 | 2016-01-08 16:06:50 -0800 | [diff] [blame] | 462 | mTaskBarViewLightTextColor : mTaskBarViewDarkTextColor); |
Winson Chung | 93748a1 | 2014-07-13 17:43:31 -0700 | [diff] [blame] | 463 | mDismissButton.setImageDrawable(t.useLightOnPrimaryColor ? |
| 464 | mLightDismissDrawable : mDarkDismissDrawable); |
Winson | 5500390 | 2016-01-12 12:00:37 -0800 | [diff] [blame] | 465 | mDismissButton.setContentDescription(t.dismissDescription); |
Winson | 3e5f0af | 2016-04-26 10:22:47 -0700 | [diff] [blame] | 466 | mDismissButton.setOnClickListener(this); |
| 467 | mDismissButton.setClickable(false); |
Winson | 18227e4 | 2016-06-08 12:57:40 -0700 | [diff] [blame] | 468 | ((RippleDrawable) mDismissButton.getBackground()).setForceSoftware(true); |
Winson Chung | 48f2cda | 2015-12-11 13:20:12 -0500 | [diff] [blame] | 469 | |
| 470 | // When freeform workspaces are enabled, then update the move-task button depending on the |
| 471 | // current task |
Winson Chung | bbb3d3d | 2016-01-30 01:09:20 +0000 | [diff] [blame] | 472 | if (mMoveTaskButton != null) { |
Winson Chung | 48f2cda | 2015-12-11 13:20:12 -0500 | [diff] [blame] | 473 | if (t.isFreeformTask()) { |
| 474 | mMoveTaskTargetStackId = FULLSCREEN_WORKSPACE_STACK_ID; |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 475 | mMoveTaskButton.setImageDrawable(t.useLightOnPrimaryColor |
| 476 | ? mLightFullscreenIcon |
| 477 | : mDarkFullscreenIcon); |
Winson Chung | 48f2cda | 2015-12-11 13:20:12 -0500 | [diff] [blame] | 478 | } else { |
| 479 | mMoveTaskTargetStackId = FREEFORM_WORKSPACE_STACK_ID; |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 480 | mMoveTaskButton.setImageDrawable(t.useLightOnPrimaryColor |
| 481 | ? mLightFreeformIcon |
| 482 | : mDarkFreeformIcon); |
Winson Chung | 48f2cda | 2015-12-11 13:20:12 -0500 | [diff] [blame] | 483 | } |
Winson | 3e5f0af | 2016-04-26 10:22:47 -0700 | [diff] [blame] | 484 | mMoveTaskButton.setOnClickListener(this); |
| 485 | mMoveTaskButton.setClickable(false); |
Winson | 18227e4 | 2016-06-08 12:57:40 -0700 | [diff] [blame] | 486 | ((RippleDrawable) mMoveTaskButton.getBackground()).setForceSoftware(true); |
Winson Chung | 48f2cda | 2015-12-11 13:20:12 -0500 | [diff] [blame] | 487 | } |
Winson | 2536c7e | 2015-10-01 15:49:31 -0700 | [diff] [blame] | 488 | |
Winson | 4b9cded | 2016-01-26 16:26:47 -0800 | [diff] [blame] | 489 | if (Recents.getDebugFlags().isFastToggleRecentsEnabled()) { |
Winson | c5ef63f | 2016-01-21 14:39:23 -0800 | [diff] [blame] | 490 | if (mFocusTimerIndicator == null) { |
Winson | 9b00139 | 2016-04-08 14:54:02 -0700 | [diff] [blame] | 491 | mFocusTimerIndicator = (ProgressBar) Utilities.findViewStubById(this, |
| 492 | R.id.focus_timer_indicator_stub).inflate(); |
Winson | c5ef63f | 2016-01-21 14:39:23 -0800 | [diff] [blame] | 493 | } |
| 494 | mFocusTimerIndicator.getProgressDrawable() |
| 495 | .setColorFilter( |
| 496 | getSecondaryColor(t.colorPrimary, t.useLightOnPrimaryColor), |
| 497 | PorterDuff.Mode.SRC_IN); |
| 498 | } |
Peter Schiller | b124d56 | 2015-12-11 21:31:17 -0800 | [diff] [blame] | 499 | |
Winson | 2536c7e | 2015-10-01 15:49:31 -0700 | [diff] [blame] | 500 | // In accessibility, a single click on the focused app info button will show it |
Winson Chung | bbb3d3d | 2016-01-30 01:09:20 +0000 | [diff] [blame] | 501 | if (touchExplorationEnabled) { |
Winson | b92dd63 | 2016-04-04 11:02:11 -0700 | [diff] [blame] | 502 | mIconView.setContentDescription(t.appInfoDescription); |
Winson Chung | 296278a | 2015-12-17 12:09:02 -0500 | [diff] [blame] | 503 | mIconView.setOnClickListener(this); |
Winson | 3e5f0af | 2016-04-26 10:22:47 -0700 | [diff] [blame] | 504 | mIconView.setClickable(true); |
Winson | 2536c7e | 2015-10-01 15:49:31 -0700 | [diff] [blame] | 505 | } |
| 506 | } |
| 507 | |
Winson | d2a0306 | 2016-04-15 11:19:07 -0700 | [diff] [blame] | 508 | /** |
| 509 | * Called when the bound task's data has loaded and this view should update to reflect the |
| 510 | * changes. |
| 511 | */ |
| 512 | public void onTaskDataLoaded() { |
| 513 | if (mTask.icon != null) { |
| 514 | mIconView.setImageDrawable(mTask.icon); |
| 515 | } |
| 516 | } |
| 517 | |
Winson | 2536c7e | 2015-10-01 15:49:31 -0700 | [diff] [blame] | 518 | /** Unbinds the bar view from the task */ |
Winson Chung | bbb3d3d | 2016-01-30 01:09:20 +0000 | [diff] [blame] | 519 | void unbindFromTask(boolean touchExplorationEnabled) { |
Winson | 2536c7e | 2015-10-01 15:49:31 -0700 | [diff] [blame] | 520 | mTask = null; |
Winson Chung | 296278a | 2015-12-17 12:09:02 -0500 | [diff] [blame] | 521 | mIconView.setImageDrawable(null); |
Winson Chung | bbb3d3d | 2016-01-30 01:09:20 +0000 | [diff] [blame] | 522 | if (touchExplorationEnabled) { |
Winson | 3e5f0af | 2016-04-26 10:22:47 -0700 | [diff] [blame] | 523 | mIconView.setClickable(false); |
Winson Chung | bbb3d3d | 2016-01-30 01:09:20 +0000 | [diff] [blame] | 524 | } |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 525 | } |
| 526 | |
Winson Chung | a26fb78 | 2014-06-12 17:52:39 -0700 | [diff] [blame] | 527 | /** Animates this task bar if the user does not interact with the stack after a certain time. */ |
Winson Chung | a0e88b5 | 2014-08-11 19:25:42 -0700 | [diff] [blame] | 528 | void startNoUserInteractionAnimation() { |
Winson Chung | bbb3d3d | 2016-01-30 01:09:20 +0000 | [diff] [blame] | 529 | int duration = getResources().getInteger(R.integer.recents_task_enter_from_app_duration); |
Winson Chung | bbb3d3d | 2016-01-30 01:09:20 +0000 | [diff] [blame] | 530 | mDismissButton.setVisibility(View.VISIBLE); |
Winson | 3e5f0af | 2016-04-26 10:22:47 -0700 | [diff] [blame] | 531 | mDismissButton.setClickable(true); |
Winson Chung | bbb3d3d | 2016-01-30 01:09:20 +0000 | [diff] [blame] | 532 | if (mDismissButton.getVisibility() == VISIBLE) { |
Winson Chung | 133ad44 | 2016-01-30 01:07:34 +0000 | [diff] [blame] | 533 | mDismissButton.animate() |
| 534 | .alpha(1f) |
Winson Chung | 133ad44 | 2016-01-30 01:07:34 +0000 | [diff] [blame] | 535 | .setInterpolator(Interpolators.FAST_OUT_LINEAR_IN) |
Winson Chung | bbb3d3d | 2016-01-30 01:09:20 +0000 | [diff] [blame] | 536 | .setDuration(duration) |
Winson Chung | 133ad44 | 2016-01-30 01:07:34 +0000 | [diff] [blame] | 537 | .start(); |
Winson Chung | bbb3d3d | 2016-01-30 01:09:20 +0000 | [diff] [blame] | 538 | } else { |
| 539 | mDismissButton.setAlpha(1f); |
| 540 | } |
| 541 | if (mMoveTaskButton != null) { |
| 542 | if (mMoveTaskButton.getVisibility() == VISIBLE) { |
Winson Chung | bbb3d3d | 2016-01-30 01:09:20 +0000 | [diff] [blame] | 543 | mMoveTaskButton.setVisibility(View.VISIBLE); |
Winson | 3e5f0af | 2016-04-26 10:22:47 -0700 | [diff] [blame] | 544 | mMoveTaskButton.setClickable(true); |
Winson Chung | bbb3d3d | 2016-01-30 01:09:20 +0000 | [diff] [blame] | 545 | mMoveTaskButton.animate() |
| 546 | .alpha(1f) |
| 547 | .setInterpolator(Interpolators.FAST_OUT_LINEAR_IN) |
| 548 | .setDuration(duration) |
| 549 | .start(); |
| 550 | } else { |
| 551 | mMoveTaskButton.setAlpha(1f); |
| 552 | } |
Winson Chung | 133ad44 | 2016-01-30 01:07:34 +0000 | [diff] [blame] | 553 | } |
Winson Chung | a26fb78 | 2014-06-12 17:52:39 -0700 | [diff] [blame] | 554 | } |
| 555 | |
Peter Schiller | b124d56 | 2015-12-11 21:31:17 -0800 | [diff] [blame] | 556 | /** |
| 557 | * Mark this task view that the user does has not interacted with the stack after a certain |
| 558 | * time. |
| 559 | */ |
Winson Chung | a0e88b5 | 2014-08-11 19:25:42 -0700 | [diff] [blame] | 560 | void setNoUserInteractionState() { |
Winson Chung | bbb3d3d | 2016-01-30 01:09:20 +0000 | [diff] [blame] | 561 | mDismissButton.setVisibility(View.VISIBLE); |
| 562 | mDismissButton.animate().cancel(); |
| 563 | mDismissButton.setAlpha(1f); |
Winson | 3e5f0af | 2016-04-26 10:22:47 -0700 | [diff] [blame] | 564 | mDismissButton.setClickable(true); |
Winson Chung | bbb3d3d | 2016-01-30 01:09:20 +0000 | [diff] [blame] | 565 | if (mMoveTaskButton != null) { |
| 566 | mMoveTaskButton.setVisibility(View.VISIBLE); |
| 567 | mMoveTaskButton.animate().cancel(); |
| 568 | mMoveTaskButton.setAlpha(1f); |
Winson | 3e5f0af | 2016-04-26 10:22:47 -0700 | [diff] [blame] | 569 | mMoveTaskButton.setClickable(true); |
Winson Chung | 133ad44 | 2016-01-30 01:07:34 +0000 | [diff] [blame] | 570 | } |
Winson Chung | a26fb78 | 2014-06-12 17:52:39 -0700 | [diff] [blame] | 571 | } |
Winson Chung | a0e88b5 | 2014-08-11 19:25:42 -0700 | [diff] [blame] | 572 | |
Peter Schiller | b124d56 | 2015-12-11 21:31:17 -0800 | [diff] [blame] | 573 | /** |
| 574 | * Resets the state tracking that the user has not interacted with the stack after a certain |
| 575 | * time. |
| 576 | */ |
Winson Chung | b0a28ea | 2014-10-28 15:21:35 -0700 | [diff] [blame] | 577 | void resetNoUserInteractionState() { |
| 578 | mDismissButton.setVisibility(View.INVISIBLE); |
Winson Chung | bbb3d3d | 2016-01-30 01:09:20 +0000 | [diff] [blame] | 579 | mDismissButton.setAlpha(0f); |
Winson | 3e5f0af | 2016-04-26 10:22:47 -0700 | [diff] [blame] | 580 | mDismissButton.setClickable(false); |
Winson Chung | bbb3d3d | 2016-01-30 01:09:20 +0000 | [diff] [blame] | 581 | if (mMoveTaskButton != null) { |
| 582 | mMoveTaskButton.setVisibility(View.INVISIBLE); |
| 583 | mMoveTaskButton.setAlpha(0f); |
Winson | 3e5f0af | 2016-04-26 10:22:47 -0700 | [diff] [blame] | 584 | mMoveTaskButton.setClickable(false); |
Winson Chung | bbb3d3d | 2016-01-30 01:09:20 +0000 | [diff] [blame] | 585 | } |
Winson Chung | b0a28ea | 2014-10-28 15:21:35 -0700 | [diff] [blame] | 586 | } |
| 587 | |
Winson Chung | bf5dbf1 | 2014-09-16 00:58:25 +0200 | [diff] [blame] | 588 | @Override |
| 589 | protected int[] onCreateDrawableState(int extraSpace) { |
| 590 | |
| 591 | // Don't forward our state to the drawable - we do it manually in onTaskViewFocusChanged. |
| 592 | // This is to prevent layer trashing when the view is pressed. |
| 593 | return new int[] {}; |
| 594 | } |
| 595 | |
Jorim Jaggi | 900fb48 | 2015-06-02 15:07:33 -0700 | [diff] [blame] | 596 | @Override |
Winson | 2536c7e | 2015-10-01 15:49:31 -0700 | [diff] [blame] | 597 | public void onClick(View v) { |
Winson Chung | 296278a | 2015-12-17 12:09:02 -0500 | [diff] [blame] | 598 | if (v == mIconView) { |
Winson Chung | bbb3d3d | 2016-01-30 01:09:20 +0000 | [diff] [blame] | 599 | // In accessibility, a single click on the focused app info button will show it |
| 600 | EventBus.getDefault().send(new ShowApplicationInfoEvent(mTask)); |
Winson | 2536c7e | 2015-10-01 15:49:31 -0700 | [diff] [blame] | 601 | } else if (v == mDismissButton) { |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 602 | TaskView tv = Utilities.findParent(this, TaskView.class); |
Winson | 2536c7e | 2015-10-01 15:49:31 -0700 | [diff] [blame] | 603 | tv.dismissTask(); |
| 604 | |
| 605 | // Keep track of deletions by the dismiss button |
| 606 | MetricsLogger.histogram(getContext(), "overview_task_dismissed_source", |
| 607 | Constants.Metrics.DismissSourceHeaderButton); |
| 608 | } else if (v == mMoveTaskButton) { |
Winson Chung | 48f2cda | 2015-12-11 13:20:12 -0500 | [diff] [blame] | 609 | TaskView tv = Utilities.findParent(this, TaskView.class); |
Manu Cornet | bf8e290 | 2016-12-20 08:29:33 -0800 | [diff] [blame] | 610 | EventBus.getDefault().send(new LaunchTaskEvent(tv, mTask, null, |
Winson Chung | 48f2cda | 2015-12-11 13:20:12 -0500 | [diff] [blame] | 611 | mMoveTaskTargetStackId, false)); |
Winson | c5ef63f | 2016-01-21 14:39:23 -0800 | [diff] [blame] | 612 | } else if (v == mAppInfoView) { |
| 613 | EventBus.getDefault().send(new ShowApplicationInfoEvent(mTask)); |
| 614 | } else if (v == mAppIconView) { |
| 615 | hideAppOverlay(false /* immediate */); |
Winson | 2536c7e | 2015-10-01 15:49:31 -0700 | [diff] [blame] | 616 | } |
| 617 | } |
| 618 | |
| 619 | @Override |
| 620 | public boolean onLongClick(View v) { |
Winson Chung | 296278a | 2015-12-17 12:09:02 -0500 | [diff] [blame] | 621 | if (v == mIconView) { |
Winson | c5ef63f | 2016-01-21 14:39:23 -0800 | [diff] [blame] | 622 | showAppOverlay(); |
| 623 | return true; |
| 624 | } else if (v == mAppIconView) { |
| 625 | hideAppOverlay(false /* immediate */); |
Winson | 2536c7e | 2015-10-01 15:49:31 -0700 | [diff] [blame] | 626 | return true; |
| 627 | } |
| 628 | return false; |
| 629 | } |
Winson | c5ef63f | 2016-01-21 14:39:23 -0800 | [diff] [blame] | 630 | |
| 631 | /** |
| 632 | * Shows the application overlay. |
| 633 | */ |
| 634 | private void showAppOverlay() { |
| 635 | // Skip early if the task is invalid |
| 636 | SystemServicesProxy ssp = Recents.getSystemServices(); |
| 637 | ComponentName cn = mTask.key.getComponent(); |
| 638 | int userId = mTask.key.userId; |
| 639 | ActivityInfo activityInfo = ssp.getActivityInfo(cn, userId); |
| 640 | if (activityInfo == null) { |
| 641 | return; |
| 642 | } |
| 643 | |
| 644 | // Inflate the overlay if necessary |
| 645 | if (mAppOverlayView == null) { |
Winson | 9b00139 | 2016-04-08 14:54:02 -0700 | [diff] [blame] | 646 | mAppOverlayView = (FrameLayout) Utilities.findViewStubById(this, |
| 647 | R.id.app_overlay_stub).inflate(); |
Winson | c5ef63f | 2016-01-21 14:39:23 -0800 | [diff] [blame] | 648 | mAppOverlayView.setBackground(mOverlayBackground); |
| 649 | mAppIconView = (ImageView) mAppOverlayView.findViewById(R.id.app_icon); |
| 650 | mAppIconView.setOnClickListener(this); |
| 651 | mAppIconView.setOnLongClickListener(this); |
| 652 | mAppInfoView = (ImageView) mAppOverlayView.findViewById(R.id.app_info); |
| 653 | mAppInfoView.setOnClickListener(this); |
| 654 | mAppTitleView = (TextView) mAppOverlayView.findViewById(R.id.app_title); |
Winson | 2170093 | 2016-03-24 17:26:23 -0700 | [diff] [blame] | 655 | updateLayoutParams(mAppIconView, mAppTitleView, null, mAppInfoView); |
Winson | c5ef63f | 2016-01-21 14:39:23 -0800 | [diff] [blame] | 656 | } |
| 657 | |
| 658 | // Update the overlay contents for the current app |
| 659 | mAppTitleView.setText(ssp.getBadgedApplicationLabel(activityInfo.applicationInfo, userId)); |
Winson | 4c84a8c | 2016-01-21 18:14:12 -0800 | [diff] [blame] | 660 | mAppTitleView.setTextColor(mTask.useLightOnPrimaryColor ? |
| 661 | mTaskBarViewLightTextColor : mTaskBarViewDarkTextColor); |
| 662 | mAppIconView.setImageDrawable(ssp.getBadgedApplicationIcon(activityInfo.applicationInfo, |
| 663 | userId)); |
Winson | c5ef63f | 2016-01-21 14:39:23 -0800 | [diff] [blame] | 664 | mAppInfoView.setImageDrawable(mTask.useLightOnPrimaryColor |
| 665 | ? mLightInfoIcon |
| 666 | : mDarkInfoIcon); |
| 667 | mAppOverlayView.setVisibility(View.VISIBLE); |
| 668 | |
| 669 | int x = mIconView.getLeft() + mIconView.getWidth() / 2; |
| 670 | int y = mIconView.getTop() + mIconView.getHeight() / 2; |
| 671 | Animator revealAnim = ViewAnimationUtils.createCircularReveal(mAppOverlayView, x, y, 0, |
| 672 | getWidth()); |
| 673 | revealAnim.setDuration(OVERLAY_REVEAL_DURATION); |
Winson | c0d7058 | 2016-01-29 10:24:39 -0800 | [diff] [blame] | 674 | revealAnim.setInterpolator(Interpolators.LINEAR_OUT_SLOW_IN); |
Winson | c5ef63f | 2016-01-21 14:39:23 -0800 | [diff] [blame] | 675 | revealAnim.start(); |
| 676 | } |
| 677 | |
| 678 | /** |
| 679 | * Hide the application overlay. |
| 680 | */ |
| 681 | private void hideAppOverlay(boolean immediate) { |
| 682 | // Skip if we haven't even loaded the overlay yet |
| 683 | if (mAppOverlayView == null) { |
| 684 | return; |
| 685 | } |
| 686 | |
| 687 | if (immediate) { |
| 688 | mAppOverlayView.setVisibility(View.GONE); |
| 689 | } else { |
| 690 | int x = mIconView.getLeft() + mIconView.getWidth() / 2; |
| 691 | int y = mIconView.getTop() + mIconView.getHeight() / 2; |
| 692 | Animator revealAnim = ViewAnimationUtils.createCircularReveal(mAppOverlayView, x, y, |
| 693 | getWidth(), 0); |
| 694 | revealAnim.setDuration(OVERLAY_REVEAL_DURATION); |
Winson | c0d7058 | 2016-01-29 10:24:39 -0800 | [diff] [blame] | 695 | revealAnim.setInterpolator(Interpolators.LINEAR_OUT_SLOW_IN); |
Winson | c5ef63f | 2016-01-21 14:39:23 -0800 | [diff] [blame] | 696 | revealAnim.addListener(new AnimatorListenerAdapter() { |
| 697 | @Override |
| 698 | public void onAnimationEnd(Animator animation) { |
| 699 | mAppOverlayView.setVisibility(View.GONE); |
| 700 | } |
| 701 | }); |
| 702 | revealAnim.start(); |
| 703 | } |
| 704 | } |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 705 | } |