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; |
Peter Schiller | b124d56 | 2015-12-11 21:31:17 -0800 | [diff] [blame] | 34 | import android.os.CountDownTimer; |
Winson | c5ef63f | 2016-01-21 14:39:23 -0800 | [diff] [blame] | 35 | import android.support.v4.graphics.ColorUtils; |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 36 | import android.util.AttributeSet; |
Winson | 2170093 | 2016-03-24 17:26:23 -0700 | [diff] [blame] | 37 | import android.view.Gravity; |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 38 | import android.view.View; |
Winson | c5ef63f | 2016-01-21 14:39:23 -0800 | [diff] [blame] | 39 | import android.view.ViewAnimationUtils; |
Winson | 231bc9c | 2016-02-09 12:31:00 -0800 | [diff] [blame] | 40 | import android.view.ViewDebug; |
Winson | 2170093 | 2016-03-24 17:26:23 -0700 | [diff] [blame] | 41 | import android.view.ViewGroup; |
Winson | c5ef63f | 2016-01-21 14:39:23 -0800 | [diff] [blame] | 42 | import android.view.ViewStub; |
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 | 931845f | 2016-02-24 19:38:41 -0800 | [diff] [blame] | 144 | TextView mSubTitleView; |
Winson | c5ef63f | 2016-01-21 14:39:23 -0800 | [diff] [blame] | 145 | ImageView mMoveTaskButton; |
| 146 | ImageView mDismissButton; |
| 147 | ViewStub mAppOverlayViewStub; |
| 148 | FrameLayout mAppOverlayView; |
| 149 | ImageView mAppIconView; |
| 150 | ImageView mAppInfoView; |
| 151 | TextView mAppTitleView; |
| 152 | ViewStub mFocusTimerIndicatorStub; |
Peter Schiller | b124d56 | 2015-12-11 21:31:17 -0800 | [diff] [blame] | 153 | ProgressBar mFocusTimerIndicator; |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 154 | |
Winson Chung | 353c0b9 | 2014-10-16 17:43:23 -0700 | [diff] [blame] | 155 | // Header drawables |
Winson | 231bc9c | 2016-02-09 12:31:00 -0800 | [diff] [blame] | 156 | @ViewDebug.ExportedProperty(category="recents") |
Winson | de0591a | 2015-12-04 17:24:35 -0800 | [diff] [blame] | 157 | Rect mTaskViewRect = new Rect(); |
Winson | 2170093 | 2016-03-24 17:26:23 -0700 | [diff] [blame] | 158 | int mHeaderBarHeight; |
| 159 | int mHeaderButtonPadding; |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 160 | int mCornerRadius; |
| 161 | int mHighlightHeight; |
Winson | 231bc9c | 2016-02-09 12:31:00 -0800 | [diff] [blame] | 162 | @ViewDebug.ExportedProperty(category="recents") |
Winson | 94a0e89 | 2016-01-08 16:06:50 -0800 | [diff] [blame] | 163 | float mDimAlpha; |
Winson Chung | 54e297a | 2014-05-09 17:15:32 -0700 | [diff] [blame] | 164 | Drawable mLightDismissDrawable; |
| 165 | Drawable mDarkDismissDrawable; |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 166 | Drawable mLightFreeformIcon; |
| 167 | Drawable mDarkFreeformIcon; |
| 168 | Drawable mLightFullscreenIcon; |
| 169 | Drawable mDarkFullscreenIcon; |
Winson | c5ef63f | 2016-01-21 14:39:23 -0800 | [diff] [blame] | 170 | Drawable mLightInfoIcon; |
| 171 | Drawable mDarkInfoIcon; |
Winson | 94a0e89 | 2016-01-08 16:06:50 -0800 | [diff] [blame] | 172 | int mTaskBarViewLightTextColor; |
| 173 | int mTaskBarViewDarkTextColor; |
Winson | 8be1634 | 2016-02-09 11:53:27 -0800 | [diff] [blame] | 174 | int mDisabledTaskBarBackgroundColor; |
Winson | c5ef63f | 2016-01-21 14:39:23 -0800 | [diff] [blame] | 175 | int mMoveTaskTargetStackId = INVALID_STACK_ID; |
Winson Chung | 54e297a | 2014-05-09 17:15:32 -0700 | [diff] [blame] | 176 | |
Winson | 94a0e89 | 2016-01-08 16:06:50 -0800 | [diff] [blame] | 177 | // Header background |
| 178 | private HighlightColorDrawable mBackground; |
Winson | c5ef63f | 2016-01-21 14:39:23 -0800 | [diff] [blame] | 179 | private HighlightColorDrawable mOverlayBackground; |
| 180 | private float[] mTmpHSL = new float[3]; |
Winson Chung | 353c0b9 | 2014-10-16 17:43:23 -0700 | [diff] [blame] | 181 | |
| 182 | // 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] | 183 | private Paint mDimLayerPaint = new Paint(); |
Winson Chung | cd23c84 | 2014-05-29 18:30:51 -0700 | [diff] [blame] | 184 | |
Peter Schiller | b124d56 | 2015-12-11 21:31:17 -0800 | [diff] [blame] | 185 | private CountDownTimer mFocusTimerCountDown; |
Peter Schiller | b124d56 | 2015-12-11 21:31:17 -0800 | [diff] [blame] | 186 | |
Winson Chung | ec396d6 | 2014-08-06 17:08:00 -0700 | [diff] [blame] | 187 | public TaskViewHeader(Context context) { |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 188 | this(context, null); |
| 189 | } |
| 190 | |
Winson Chung | ec396d6 | 2014-08-06 17:08:00 -0700 | [diff] [blame] | 191 | public TaskViewHeader(Context context, AttributeSet attrs) { |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 192 | this(context, attrs, 0); |
| 193 | } |
| 194 | |
Winson Chung | ec396d6 | 2014-08-06 17:08:00 -0700 | [diff] [blame] | 195 | public TaskViewHeader(Context context, AttributeSet attrs, int defStyleAttr) { |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 196 | this(context, attrs, defStyleAttr, 0); |
| 197 | } |
| 198 | |
Winson Chung | ec396d6 | 2014-08-06 17:08:00 -0700 | [diff] [blame] | 199 | public TaskViewHeader(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 200 | super(context, attrs, defStyleAttr, defStyleRes); |
Winson Chung | cd23c84 | 2014-05-29 18:30:51 -0700 | [diff] [blame] | 201 | setWillNotDraw(false); |
| 202 | |
| 203 | // Load the dismiss resources |
Winson | 94a0e89 | 2016-01-08 16:06:50 -0800 | [diff] [blame] | 204 | Resources res = context.getResources(); |
Winson Chung | 911f400 | 2015-02-13 13:49:36 -0800 | [diff] [blame] | 205 | mLightDismissDrawable = context.getDrawable(R.drawable.recents_dismiss_light); |
| 206 | mDarkDismissDrawable = context.getDrawable(R.drawable.recents_dismiss_dark); |
Winson | 94a0e89 | 2016-01-08 16:06:50 -0800 | [diff] [blame] | 207 | mCornerRadius = res.getDimensionPixelSize(R.dimen.recents_task_view_rounded_corners_radius); |
| 208 | mHighlightHeight = res.getDimensionPixelSize(R.dimen.recents_task_view_highlight); |
| 209 | mTaskBarViewLightTextColor = context.getColor(R.color.recents_task_bar_light_text_color); |
| 210 | mTaskBarViewDarkTextColor = context.getColor(R.color.recents_task_bar_dark_text_color); |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 211 | mLightFreeformIcon = context.getDrawable(R.drawable.recents_move_task_freeform_light); |
| 212 | mDarkFreeformIcon = context.getDrawable(R.drawable.recents_move_task_freeform_dark); |
| 213 | mLightFullscreenIcon = context.getDrawable(R.drawable.recents_move_task_fullscreen_light); |
| 214 | mDarkFullscreenIcon = context.getDrawable(R.drawable.recents_move_task_fullscreen_dark); |
Winson | c5ef63f | 2016-01-21 14:39:23 -0800 | [diff] [blame] | 215 | mLightInfoIcon = context.getDrawable(R.drawable.recents_info_light); |
| 216 | mDarkInfoIcon = context.getDrawable(R.drawable.recents_info_dark); |
Winson | 8be1634 | 2016-02-09 11:53:27 -0800 | [diff] [blame] | 217 | mDisabledTaskBarBackgroundColor = |
| 218 | context.getColor(R.color.recents_task_bar_disabled_background_color); |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 219 | |
Winson | 94a0e89 | 2016-01-08 16:06:50 -0800 | [diff] [blame] | 220 | // Configure the background and dim |
| 221 | mBackground = new HighlightColorDrawable(); |
| 222 | mBackground.setColorAndDim(Color.argb(255, 0, 0, 0), 0f); |
| 223 | setBackground(mBackground); |
Winson | c5ef63f | 2016-01-21 14:39:23 -0800 | [diff] [blame] | 224 | mOverlayBackground = new HighlightColorDrawable(); |
Winson | 94a0e89 | 2016-01-08 16:06:50 -0800 | [diff] [blame] | 225 | mDimLayerPaint.setColor(Color.argb(255, 0, 0, 0)); |
| 226 | mDimLayerPaint.setAntiAlias(true); |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 227 | } |
| 228 | |
Winson | c5ef63f | 2016-01-21 14:39:23 -0800 | [diff] [blame] | 229 | /** |
| 230 | * Resets this header along with the TaskView. |
| 231 | */ |
| 232 | public void reset() { |
| 233 | hideAppOverlay(true /* immediate */); |
| 234 | } |
| 235 | |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 236 | @Override |
| 237 | protected void onFinishInflate() { |
Winson Chung | bbb3d3d | 2016-01-30 01:09:20 +0000 | [diff] [blame] | 238 | SystemServicesProxy ssp = Recents.getSystemServices(); |
| 239 | |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 240 | // Initialize the icon and description views |
Winson Chung | 296278a | 2015-12-17 12:09:02 -0500 | [diff] [blame] | 241 | mIconView = (ImageView) findViewById(R.id.icon); |
Winson | c5ef63f | 2016-01-21 14:39:23 -0800 | [diff] [blame] | 242 | mIconView.setClickable(false); |
Winson Chung | 296278a | 2015-12-17 12:09:02 -0500 | [diff] [blame] | 243 | mIconView.setOnLongClickListener(this); |
| 244 | mTitleView = (TextView) findViewById(R.id.title); |
Winson | 931845f | 2016-02-24 19:38:41 -0800 | [diff] [blame] | 245 | mSubTitleView = (TextView) findViewById(R.id.sub_title); |
Winson Chung | 54e297a | 2014-05-09 17:15:32 -0700 | [diff] [blame] | 246 | mDismissButton = (ImageView) findViewById(R.id.dismiss_task); |
Winson Chung | bbb3d3d | 2016-01-30 01:09:20 +0000 | [diff] [blame] | 247 | if (ssp.hasFreeformWorkspaceSupport()) { |
| 248 | mMoveTaskButton = (ImageView) findViewById(R.id.move_task); |
| 249 | } |
Winson | c5ef63f | 2016-01-21 14:39:23 -0800 | [diff] [blame] | 250 | mFocusTimerIndicatorStub = (ViewStub) findViewById(R.id.focus_timer_indicator_stub); |
| 251 | mAppOverlayViewStub = (ViewStub) findViewById(R.id.app_overlay_stub); |
Winson | 2170093 | 2016-03-24 17:26:23 -0700 | [diff] [blame] | 252 | |
Winson | 619e40c | 2016-03-25 16:12:35 -0700 | [diff] [blame] | 253 | onConfigurationChanged(); |
Winson | 2170093 | 2016-03-24 17:26:23 -0700 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | /** |
| 257 | * Programmatically sets the layout params for a header bar layout. This is necessary because |
| 258 | * we can't get resources based on the current configuration, but instead need to get them |
| 259 | * based on the device configuration. |
| 260 | */ |
| 261 | private void updateLayoutParams(View icon, View title, View secondaryButton, View button) { |
| 262 | FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams( |
| 263 | ViewGroup.LayoutParams.MATCH_PARENT, mHeaderBarHeight, Gravity.TOP); |
| 264 | setLayoutParams(lp); |
| 265 | lp = new FrameLayout.LayoutParams(mHeaderBarHeight, mHeaderBarHeight, Gravity.START); |
| 266 | icon.setLayoutParams(lp); |
| 267 | lp = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, |
| 268 | ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.START | Gravity.CENTER_VERTICAL); |
Winson | a1ededd | 2016-03-25 12:23:12 -0700 | [diff] [blame] | 269 | lp.setMarginStart(mHeaderBarHeight); |
Winson | 1985237 | 2016-03-30 18:26:49 -0700 | [diff] [blame] | 270 | lp.setMarginEnd(mMoveTaskButton != null |
Winson | 2170093 | 2016-03-24 17:26:23 -0700 | [diff] [blame] | 271 | ? 2 * mHeaderBarHeight |
Winson | 1985237 | 2016-03-30 18:26:49 -0700 | [diff] [blame] | 272 | : mHeaderBarHeight); |
Winson | 2170093 | 2016-03-24 17:26:23 -0700 | [diff] [blame] | 273 | title.setLayoutParams(lp); |
| 274 | if (secondaryButton != null) { |
| 275 | lp = new FrameLayout.LayoutParams(mHeaderBarHeight, mHeaderBarHeight, Gravity.END); |
Winson | a1ededd | 2016-03-25 12:23:12 -0700 | [diff] [blame] | 276 | lp.setMarginEnd(mHeaderBarHeight); |
Winson | 2170093 | 2016-03-24 17:26:23 -0700 | [diff] [blame] | 277 | secondaryButton.setLayoutParams(lp); |
| 278 | secondaryButton.setPadding(mHeaderButtonPadding, mHeaderButtonPadding, |
| 279 | mHeaderButtonPadding, mHeaderButtonPadding); |
| 280 | } |
| 281 | lp = new FrameLayout.LayoutParams(mHeaderBarHeight, mHeaderBarHeight, Gravity.END); |
| 282 | button.setLayoutParams(lp); |
| 283 | button.setPadding(mHeaderButtonPadding, mHeaderButtonPadding, mHeaderButtonPadding, |
| 284 | mHeaderButtonPadding); |
Winson Chung | 54e297a | 2014-05-09 17:15:32 -0700 | [diff] [blame] | 285 | } |
| 286 | |
Winson | 619e40c | 2016-03-25 16:12:35 -0700 | [diff] [blame] | 287 | /** |
| 288 | * Update the header view when the configuration changes. |
| 289 | */ |
| 290 | void onConfigurationChanged() { |
| 291 | // Update the dimensions of everything in the header. We do this because we need to use |
| 292 | // resources for the display, and not the current configuration. |
| 293 | Resources res = getResources(); |
| 294 | mHeaderBarHeight = TaskStackLayoutAlgorithm.getDimensionForDevice(res, |
| 295 | R.dimen.recents_task_view_header_height, |
| 296 | R.dimen.recents_task_view_header_height, |
| 297 | R.dimen.recents_task_view_header_height, |
| 298 | R.dimen.recents_task_view_header_height_tablet_land, |
| 299 | R.dimen.recents_task_view_header_height, |
| 300 | R.dimen.recents_task_view_header_height_tablet_land); |
| 301 | mHeaderButtonPadding = TaskStackLayoutAlgorithm.getDimensionForDevice(res, |
| 302 | R.dimen.recents_task_view_header_button_padding, |
| 303 | R.dimen.recents_task_view_header_button_padding, |
| 304 | R.dimen.recents_task_view_header_button_padding, |
| 305 | R.dimen.recents_task_view_header_button_padding_tablet_land, |
| 306 | R.dimen.recents_task_view_header_button_padding, |
| 307 | R.dimen.recents_task_view_header_button_padding_tablet_land); |
| 308 | updateLayoutParams(mIconView, findViewById(R.id.title_container), mMoveTaskButton, |
| 309 | mDismissButton); |
| 310 | if (mAppOverlayView != null) { |
| 311 | updateLayoutParams(mAppIconView, mAppTitleView, null, mAppInfoView); |
| 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 | de0591a | 2015-12-04 17:24:35 -0800 | [diff] [blame] | 357 | } |
| 358 | |
Winson Chung | cd23c84 | 2014-05-29 18:30:51 -0700 | [diff] [blame] | 359 | @Override |
Winson | be8e696 | 2016-02-01 14:27:52 -0800 | [diff] [blame] | 360 | public void onDrawForeground(Canvas canvas) { |
| 361 | super.onDrawForeground(canvas); |
Winson | 94a0e89 | 2016-01-08 16:06:50 -0800 | [diff] [blame] | 362 | |
| 363 | // Draw the dim layer with the rounded corners |
| 364 | canvas.drawRoundRect(0, 0, mTaskViewRect.width(), getHeight() + mCornerRadius, |
| 365 | mCornerRadius, mCornerRadius, mDimLayerPaint); |
Winson Chung | cd23c84 | 2014-05-29 18:30:51 -0700 | [diff] [blame] | 366 | } |
| 367 | |
Peter Schiller | b124d56 | 2015-12-11 21:31:17 -0800 | [diff] [blame] | 368 | /** Starts the focus timer. */ |
Winson | 4b9cded | 2016-01-26 16:26:47 -0800 | [diff] [blame] | 369 | public void startFocusTimerIndicator(int duration) { |
Winson | c5ef63f | 2016-01-21 14:39:23 -0800 | [diff] [blame] | 370 | if (mFocusTimerIndicator == null) { |
| 371 | return; |
| 372 | } |
| 373 | |
Peter Schiller | b124d56 | 2015-12-11 21:31:17 -0800 | [diff] [blame] | 374 | mFocusTimerIndicator.setVisibility(View.VISIBLE); |
Winson | 4b9cded | 2016-01-26 16:26:47 -0800 | [diff] [blame] | 375 | mFocusTimerIndicator.setMax(duration); |
| 376 | mFocusTimerIndicator.setProgress(duration); |
| 377 | if (mFocusTimerCountDown != null) { |
| 378 | mFocusTimerCountDown.cancel(); |
Peter Schiller | b124d56 | 2015-12-11 21:31:17 -0800 | [diff] [blame] | 379 | } |
Winson | 4b9cded | 2016-01-26 16:26:47 -0800 | [diff] [blame] | 380 | mFocusTimerCountDown = new CountDownTimer(duration, |
| 381 | FOCUS_INDICATOR_INTERVAL_MS) { |
| 382 | public void onTick(long millisUntilFinished) { |
| 383 | mFocusTimerIndicator.setProgress((int) millisUntilFinished); |
| 384 | } |
| 385 | |
| 386 | public void onFinish() { |
| 387 | // Do nothing |
| 388 | } |
| 389 | }.start(); |
Peter Schiller | b124d56 | 2015-12-11 21:31:17 -0800 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | /** Cancels the focus timer. */ |
| 393 | public void cancelFocusTimerIndicator() { |
Winson | c5ef63f | 2016-01-21 14:39:23 -0800 | [diff] [blame] | 394 | if (mFocusTimerIndicator == null) { |
| 395 | return; |
| 396 | } |
| 397 | |
| 398 | if (mFocusTimerCountDown != null) { |
Peter Schiller | b124d56 | 2015-12-11 21:31:17 -0800 | [diff] [blame] | 399 | mFocusTimerCountDown.cancel(); |
| 400 | mFocusTimerIndicator.setProgress(0); |
| 401 | mFocusTimerIndicator.setVisibility(View.INVISIBLE); |
| 402 | } |
| 403 | } |
| 404 | |
Winson | 22574af | 2016-03-23 19:00:28 -0700 | [diff] [blame] | 405 | /** Only exposed for the workaround for b/27815919. */ |
| 406 | public ImageView getIconView() { |
| 407 | return mIconView; |
| 408 | } |
| 409 | |
Peter Schiller | b124d56 | 2015-12-11 21:31:17 -0800 | [diff] [blame] | 410 | /** Returns the secondary color for a primary color. */ |
| 411 | int getSecondaryColor(int primaryColor, boolean useLightOverlayColor) { |
| 412 | int overlayColor = useLightOverlayColor ? Color.WHITE : Color.BLACK; |
| 413 | return Utilities.getColorWithOverlay(primaryColor, overlayColor, 0.8f); |
| 414 | } |
| 415 | |
Winson Chung | 353c0b9 | 2014-10-16 17:43:23 -0700 | [diff] [blame] | 416 | /** |
| 417 | * Sets the dim alpha, only used when we are not using hardware layers. |
| 418 | * (see RecentsConfiguration.useHardwareLayers) |
| 419 | */ |
Winson | e693aaf | 2016-03-01 12:05:59 -0800 | [diff] [blame] | 420 | public void setDimAlpha(float dimAlpha) { |
| 421 | if (Float.compare(mDimAlpha, dimAlpha) != 0) { |
| 422 | mDimAlpha = dimAlpha; |
Winson | 59924fe | 2016-03-17 14:13:18 -0700 | [diff] [blame] | 423 | mTitleView.setAlpha(1f - dimAlpha); |
Winson | e693aaf | 2016-03-01 12:05:59 -0800 | [diff] [blame] | 424 | updateBackgroundColor(mBackground.getColor(), dimAlpha); |
| 425 | } |
Winson Chung | 353c0b9 | 2014-10-16 17:43:23 -0700 | [diff] [blame] | 426 | } |
| 427 | |
Winson | 94a0e89 | 2016-01-08 16:06:50 -0800 | [diff] [blame] | 428 | /** |
| 429 | * Updates the background and highlight colors for this header. |
| 430 | */ |
Winson | 8be1634 | 2016-02-09 11:53:27 -0800 | [diff] [blame] | 431 | private void updateBackgroundColor(int color, float dimAlpha) { |
Winson | 94a0e89 | 2016-01-08 16:06:50 -0800 | [diff] [blame] | 432 | if (mTask != null) { |
Winson | 8be1634 | 2016-02-09 11:53:27 -0800 | [diff] [blame] | 433 | mBackground.setColorAndDim(color, dimAlpha); |
Winson | c5ef63f | 2016-01-21 14:39:23 -0800 | [diff] [blame] | 434 | // 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] | 435 | ColorUtils.colorToHSL(color, mTmpHSL); |
Winson | c5ef63f | 2016-01-21 14:39:23 -0800 | [diff] [blame] | 436 | mTmpHSL[2] = Math.min(1f, mTmpHSL[2] + OVERLAY_LIGHTNESS_INCREMENT * (1.0f - dimAlpha)); |
| 437 | mOverlayBackground.setColorAndDim(ColorUtils.HSLToColor(mTmpHSL), dimAlpha); |
Winson | 94a0e89 | 2016-01-08 16:06:50 -0800 | [diff] [blame] | 438 | mDimLayerPaint.setAlpha((int) (dimAlpha * 255)); |
Winson Chung | bbb3d3d | 2016-01-30 01:09:20 +0000 | [diff] [blame] | 439 | invalidate(); |
Winson | 94a0e89 | 2016-01-08 16:06:50 -0800 | [diff] [blame] | 440 | } |
| 441 | } |
| 442 | |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 443 | /** Binds the bar view to the task */ |
Winson | 8be1634 | 2016-02-09 11:53:27 -0800 | [diff] [blame] | 444 | public void rebindToTask(Task t, boolean touchExplorationEnabled, boolean disabledInSafeMode) { |
Winson | 931845f | 2016-02-24 19:38:41 -0800 | [diff] [blame] | 445 | SystemServicesProxy ssp = Recents.getSystemServices(); |
Winson | 2536c7e | 2015-10-01 15:49:31 -0700 | [diff] [blame] | 446 | mTask = t; |
| 447 | |
Winson Chung | 11e41ba | 2014-04-21 12:39:20 -0700 | [diff] [blame] | 448 | // If an activity icon is defined, then we use that as the primary icon to show in the bar, |
| 449 | // otherwise, we fall back to the application icon |
Winson | 8be1634 | 2016-02-09 11:53:27 -0800 | [diff] [blame] | 450 | int primaryColor = disabledInSafeMode |
| 451 | ? mDisabledTaskBarBackgroundColor |
| 452 | : t.colorPrimary; |
Winson | e693aaf | 2016-03-01 12:05:59 -0800 | [diff] [blame] | 453 | if (mBackground.getColor() != primaryColor) { |
| 454 | updateBackgroundColor(primaryColor, mDimAlpha); |
| 455 | } |
Winson Chung | 296278a | 2015-12-17 12:09:02 -0500 | [diff] [blame] | 456 | if (t.icon != null) { |
| 457 | mIconView.setImageDrawable(t.icon); |
Winson Chung | 11e41ba | 2014-04-21 12:39:20 -0700 | [diff] [blame] | 458 | } |
Winson Chung | 296278a | 2015-12-17 12:09:02 -0500 | [diff] [blame] | 459 | if (!mTitleView.getText().toString().equals(t.title)) { |
| 460 | mTitleView.setText(t.title); |
Winson Chung | bdbb87d | 2014-07-09 14:29:13 -0700 | [diff] [blame] | 461 | } |
Winson Chung | 296278a | 2015-12-17 12:09:02 -0500 | [diff] [blame] | 462 | mTitleView.setContentDescription(t.contentDescription); |
Winson Chung | 296278a | 2015-12-17 12:09:02 -0500 | [diff] [blame] | 463 | mTitleView.setTextColor(t.useLightOnPrimaryColor ? |
Winson | 94a0e89 | 2016-01-08 16:06:50 -0800 | [diff] [blame] | 464 | mTaskBarViewLightTextColor : mTaskBarViewDarkTextColor); |
Winson | 931845f | 2016-02-24 19:38:41 -0800 | [diff] [blame] | 465 | if (!t.isDockable && ssp.hasDockedTask()) { |
| 466 | mSubTitleView.setVisibility(View.VISIBLE); |
| 467 | mSubTitleView.setTextColor(t.useLightOnPrimaryColor ? |
| 468 | mTaskBarViewLightTextColor : mTaskBarViewDarkTextColor); |
| 469 | } else { |
| 470 | mSubTitleView.setVisibility(View.GONE); |
| 471 | } |
Winson Chung | 93748a1 | 2014-07-13 17:43:31 -0700 | [diff] [blame] | 472 | mDismissButton.setImageDrawable(t.useLightOnPrimaryColor ? |
| 473 | mLightDismissDrawable : mDarkDismissDrawable); |
Winson | 5500390 | 2016-01-12 12:00:37 -0800 | [diff] [blame] | 474 | mDismissButton.setContentDescription(t.dismissDescription); |
Winson Chung | 48f2cda | 2015-12-11 13:20:12 -0500 | [diff] [blame] | 475 | |
| 476 | // When freeform workspaces are enabled, then update the move-task button depending on the |
| 477 | // current task |
Winson Chung | bbb3d3d | 2016-01-30 01:09:20 +0000 | [diff] [blame] | 478 | if (mMoveTaskButton != null) { |
Winson Chung | 48f2cda | 2015-12-11 13:20:12 -0500 | [diff] [blame] | 479 | if (t.isFreeformTask()) { |
| 480 | mMoveTaskTargetStackId = FULLSCREEN_WORKSPACE_STACK_ID; |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 481 | mMoveTaskButton.setImageDrawable(t.useLightOnPrimaryColor |
| 482 | ? mLightFullscreenIcon |
| 483 | : mDarkFullscreenIcon); |
Winson Chung | 48f2cda | 2015-12-11 13:20:12 -0500 | [diff] [blame] | 484 | } else { |
| 485 | mMoveTaskTargetStackId = FREEFORM_WORKSPACE_STACK_ID; |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 486 | mMoveTaskButton.setImageDrawable(t.useLightOnPrimaryColor |
| 487 | ? mLightFreeformIcon |
| 488 | : mDarkFreeformIcon); |
Winson Chung | 48f2cda | 2015-12-11 13:20:12 -0500 | [diff] [blame] | 489 | } |
Winson Chung | 48f2cda | 2015-12-11 13:20:12 -0500 | [diff] [blame] | 490 | } |
Winson | 2536c7e | 2015-10-01 15:49:31 -0700 | [diff] [blame] | 491 | |
Winson | 4b9cded | 2016-01-26 16:26:47 -0800 | [diff] [blame] | 492 | if (Recents.getDebugFlags().isFastToggleRecentsEnabled()) { |
Winson | c5ef63f | 2016-01-21 14:39:23 -0800 | [diff] [blame] | 493 | if (mFocusTimerIndicator == null) { |
| 494 | mFocusTimerIndicator = (ProgressBar) mFocusTimerIndicatorStub.inflate(); |
| 495 | } |
| 496 | mFocusTimerIndicator.getProgressDrawable() |
| 497 | .setColorFilter( |
| 498 | getSecondaryColor(t.colorPrimary, t.useLightOnPrimaryColor), |
| 499 | PorterDuff.Mode.SRC_IN); |
| 500 | } |
Peter Schiller | b124d56 | 2015-12-11 21:31:17 -0800 | [diff] [blame] | 501 | |
Winson | 2536c7e | 2015-10-01 15:49:31 -0700 | [diff] [blame] | 502 | // 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] | 503 | if (touchExplorationEnabled) { |
Winson Chung | 296278a | 2015-12-17 12:09:02 -0500 | [diff] [blame] | 504 | mIconView.setOnClickListener(this); |
Winson | 2536c7e | 2015-10-01 15:49:31 -0700 | [diff] [blame] | 505 | } |
| 506 | } |
| 507 | |
| 508 | /** Unbinds the bar view from the task */ |
Winson Chung | bbb3d3d | 2016-01-30 01:09:20 +0000 | [diff] [blame] | 509 | void unbindFromTask(boolean touchExplorationEnabled) { |
Winson | 2536c7e | 2015-10-01 15:49:31 -0700 | [diff] [blame] | 510 | mTask = null; |
Winson Chung | 296278a | 2015-12-17 12:09:02 -0500 | [diff] [blame] | 511 | mIconView.setImageDrawable(null); |
Winson Chung | bbb3d3d | 2016-01-30 01:09:20 +0000 | [diff] [blame] | 512 | if (touchExplorationEnabled) { |
| 513 | mIconView.setOnClickListener(null); |
| 514 | } |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 515 | } |
| 516 | |
Winson Chung | a26fb78 | 2014-06-12 17:52:39 -0700 | [diff] [blame] | 517 | /** 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] | 518 | void startNoUserInteractionAnimation() { |
Winson Chung | bbb3d3d | 2016-01-30 01:09:20 +0000 | [diff] [blame] | 519 | int duration = getResources().getInteger(R.integer.recents_task_enter_from_app_duration); |
| 520 | mDismissButton.setOnClickListener(this); |
| 521 | mDismissButton.setVisibility(View.VISIBLE); |
| 522 | if (mDismissButton.getVisibility() == VISIBLE) { |
Winson Chung | 133ad44 | 2016-01-30 01:07:34 +0000 | [diff] [blame] | 523 | mDismissButton.animate() |
| 524 | .alpha(1f) |
Winson Chung | 133ad44 | 2016-01-30 01:07:34 +0000 | [diff] [blame] | 525 | .setInterpolator(Interpolators.FAST_OUT_LINEAR_IN) |
Winson Chung | bbb3d3d | 2016-01-30 01:09:20 +0000 | [diff] [blame] | 526 | .setDuration(duration) |
Winson Chung | 133ad44 | 2016-01-30 01:07:34 +0000 | [diff] [blame] | 527 | .start(); |
Winson Chung | bbb3d3d | 2016-01-30 01:09:20 +0000 | [diff] [blame] | 528 | } else { |
| 529 | mDismissButton.setAlpha(1f); |
| 530 | } |
| 531 | if (mMoveTaskButton != null) { |
| 532 | if (mMoveTaskButton.getVisibility() == VISIBLE) { |
| 533 | mMoveTaskButton.setOnClickListener(this); |
| 534 | mMoveTaskButton.setVisibility(View.VISIBLE); |
| 535 | mMoveTaskButton.animate() |
| 536 | .alpha(1f) |
| 537 | .setInterpolator(Interpolators.FAST_OUT_LINEAR_IN) |
| 538 | .setDuration(duration) |
| 539 | .start(); |
| 540 | } else { |
| 541 | mMoveTaskButton.setAlpha(1f); |
| 542 | } |
Winson Chung | 133ad44 | 2016-01-30 01:07:34 +0000 | [diff] [blame] | 543 | } |
Winson Chung | a26fb78 | 2014-06-12 17:52:39 -0700 | [diff] [blame] | 544 | } |
| 545 | |
Peter Schiller | b124d56 | 2015-12-11 21:31:17 -0800 | [diff] [blame] | 546 | /** |
| 547 | * Mark this task view that the user does has not interacted with the stack after a certain |
| 548 | * time. |
| 549 | */ |
Winson Chung | a0e88b5 | 2014-08-11 19:25:42 -0700 | [diff] [blame] | 550 | void setNoUserInteractionState() { |
Winson Chung | bbb3d3d | 2016-01-30 01:09:20 +0000 | [diff] [blame] | 551 | mDismissButton.setVisibility(View.VISIBLE); |
| 552 | mDismissButton.animate().cancel(); |
| 553 | mDismissButton.setAlpha(1f); |
| 554 | mDismissButton.setOnClickListener(this); |
| 555 | if (mMoveTaskButton != null) { |
| 556 | mMoveTaskButton.setVisibility(View.VISIBLE); |
| 557 | mMoveTaskButton.animate().cancel(); |
| 558 | mMoveTaskButton.setAlpha(1f); |
| 559 | mMoveTaskButton.setOnClickListener(this); |
Winson Chung | 133ad44 | 2016-01-30 01:07:34 +0000 | [diff] [blame] | 560 | } |
Winson Chung | a26fb78 | 2014-06-12 17:52:39 -0700 | [diff] [blame] | 561 | } |
Winson Chung | a0e88b5 | 2014-08-11 19:25:42 -0700 | [diff] [blame] | 562 | |
Peter Schiller | b124d56 | 2015-12-11 21:31:17 -0800 | [diff] [blame] | 563 | /** |
| 564 | * Resets the state tracking that the user has not interacted with the stack after a certain |
| 565 | * time. |
| 566 | */ |
Winson Chung | b0a28ea | 2014-10-28 15:21:35 -0700 | [diff] [blame] | 567 | void resetNoUserInteractionState() { |
| 568 | mDismissButton.setVisibility(View.INVISIBLE); |
Winson Chung | bbb3d3d | 2016-01-30 01:09:20 +0000 | [diff] [blame] | 569 | mDismissButton.setAlpha(0f); |
| 570 | mDismissButton.setOnClickListener(null); |
| 571 | if (mMoveTaskButton != null) { |
| 572 | mMoveTaskButton.setVisibility(View.INVISIBLE); |
| 573 | mMoveTaskButton.setAlpha(0f); |
| 574 | mMoveTaskButton.setOnClickListener(null); |
| 575 | } |
Winson Chung | b0a28ea | 2014-10-28 15:21:35 -0700 | [diff] [blame] | 576 | } |
| 577 | |
Winson Chung | bf5dbf1 | 2014-09-16 00:58:25 +0200 | [diff] [blame] | 578 | @Override |
| 579 | protected int[] onCreateDrawableState(int extraSpace) { |
| 580 | |
| 581 | // Don't forward our state to the drawable - we do it manually in onTaskViewFocusChanged. |
| 582 | // This is to prevent layer trashing when the view is pressed. |
| 583 | return new int[] {}; |
| 584 | } |
| 585 | |
Jorim Jaggi | 900fb48 | 2015-06-02 15:07:33 -0700 | [diff] [blame] | 586 | @Override |
Winson | 2536c7e | 2015-10-01 15:49:31 -0700 | [diff] [blame] | 587 | public void onClick(View v) { |
Winson Chung | 296278a | 2015-12-17 12:09:02 -0500 | [diff] [blame] | 588 | if (v == mIconView) { |
Winson Chung | bbb3d3d | 2016-01-30 01:09:20 +0000 | [diff] [blame] | 589 | // In accessibility, a single click on the focused app info button will show it |
| 590 | EventBus.getDefault().send(new ShowApplicationInfoEvent(mTask)); |
Winson | 2536c7e | 2015-10-01 15:49:31 -0700 | [diff] [blame] | 591 | } else if (v == mDismissButton) { |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 592 | TaskView tv = Utilities.findParent(this, TaskView.class); |
Winson | 2536c7e | 2015-10-01 15:49:31 -0700 | [diff] [blame] | 593 | tv.dismissTask(); |
| 594 | |
| 595 | // Keep track of deletions by the dismiss button |
| 596 | MetricsLogger.histogram(getContext(), "overview_task_dismissed_source", |
| 597 | Constants.Metrics.DismissSourceHeaderButton); |
| 598 | } else if (v == mMoveTaskButton) { |
Winson Chung | 48f2cda | 2015-12-11 13:20:12 -0500 | [diff] [blame] | 599 | TaskView tv = Utilities.findParent(this, TaskView.class); |
| 600 | Rect bounds = mMoveTaskTargetStackId == FREEFORM_WORKSPACE_STACK_ID |
| 601 | ? new Rect(mTaskViewRect) |
| 602 | : new Rect(); |
| 603 | EventBus.getDefault().send(new LaunchTaskEvent(tv, mTask, bounds, |
| 604 | mMoveTaskTargetStackId, false)); |
Winson | c5ef63f | 2016-01-21 14:39:23 -0800 | [diff] [blame] | 605 | } else if (v == mAppInfoView) { |
| 606 | EventBus.getDefault().send(new ShowApplicationInfoEvent(mTask)); |
| 607 | } else if (v == mAppIconView) { |
| 608 | hideAppOverlay(false /* immediate */); |
Winson | 2536c7e | 2015-10-01 15:49:31 -0700 | [diff] [blame] | 609 | } |
| 610 | } |
| 611 | |
| 612 | @Override |
| 613 | public boolean onLongClick(View v) { |
Winson Chung | 296278a | 2015-12-17 12:09:02 -0500 | [diff] [blame] | 614 | if (v == mIconView) { |
Winson | c5ef63f | 2016-01-21 14:39:23 -0800 | [diff] [blame] | 615 | showAppOverlay(); |
| 616 | return true; |
| 617 | } else if (v == mAppIconView) { |
| 618 | hideAppOverlay(false /* immediate */); |
Winson | 2536c7e | 2015-10-01 15:49:31 -0700 | [diff] [blame] | 619 | return true; |
| 620 | } |
| 621 | return false; |
| 622 | } |
Winson | c5ef63f | 2016-01-21 14:39:23 -0800 | [diff] [blame] | 623 | |
| 624 | /** |
| 625 | * Shows the application overlay. |
| 626 | */ |
| 627 | private void showAppOverlay() { |
| 628 | // Skip early if the task is invalid |
| 629 | SystemServicesProxy ssp = Recents.getSystemServices(); |
| 630 | ComponentName cn = mTask.key.getComponent(); |
| 631 | int userId = mTask.key.userId; |
| 632 | ActivityInfo activityInfo = ssp.getActivityInfo(cn, userId); |
| 633 | if (activityInfo == null) { |
| 634 | return; |
| 635 | } |
| 636 | |
| 637 | // Inflate the overlay if necessary |
| 638 | if (mAppOverlayView == null) { |
| 639 | mAppOverlayView = (FrameLayout) mAppOverlayViewStub.inflate(); |
| 640 | mAppOverlayView.setBackground(mOverlayBackground); |
| 641 | mAppIconView = (ImageView) mAppOverlayView.findViewById(R.id.app_icon); |
| 642 | mAppIconView.setOnClickListener(this); |
| 643 | mAppIconView.setOnLongClickListener(this); |
| 644 | mAppInfoView = (ImageView) mAppOverlayView.findViewById(R.id.app_info); |
| 645 | mAppInfoView.setOnClickListener(this); |
| 646 | mAppTitleView = (TextView) mAppOverlayView.findViewById(R.id.app_title); |
Winson | 2170093 | 2016-03-24 17:26:23 -0700 | [diff] [blame] | 647 | updateLayoutParams(mAppIconView, mAppTitleView, null, mAppInfoView); |
Winson | c5ef63f | 2016-01-21 14:39:23 -0800 | [diff] [blame] | 648 | } |
| 649 | |
| 650 | // Update the overlay contents for the current app |
| 651 | mAppTitleView.setText(ssp.getBadgedApplicationLabel(activityInfo.applicationInfo, userId)); |
Winson | 4c84a8c | 2016-01-21 18:14:12 -0800 | [diff] [blame] | 652 | mAppTitleView.setTextColor(mTask.useLightOnPrimaryColor ? |
| 653 | mTaskBarViewLightTextColor : mTaskBarViewDarkTextColor); |
| 654 | mAppIconView.setImageDrawable(ssp.getBadgedApplicationIcon(activityInfo.applicationInfo, |
| 655 | userId)); |
Winson | c5ef63f | 2016-01-21 14:39:23 -0800 | [diff] [blame] | 656 | mAppInfoView.setImageDrawable(mTask.useLightOnPrimaryColor |
| 657 | ? mLightInfoIcon |
| 658 | : mDarkInfoIcon); |
| 659 | mAppOverlayView.setVisibility(View.VISIBLE); |
| 660 | |
| 661 | int x = mIconView.getLeft() + mIconView.getWidth() / 2; |
| 662 | int y = mIconView.getTop() + mIconView.getHeight() / 2; |
| 663 | Animator revealAnim = ViewAnimationUtils.createCircularReveal(mAppOverlayView, x, y, 0, |
| 664 | getWidth()); |
| 665 | revealAnim.setDuration(OVERLAY_REVEAL_DURATION); |
Winson | c0d7058 | 2016-01-29 10:24:39 -0800 | [diff] [blame] | 666 | revealAnim.setInterpolator(Interpolators.LINEAR_OUT_SLOW_IN); |
Winson | c5ef63f | 2016-01-21 14:39:23 -0800 | [diff] [blame] | 667 | revealAnim.start(); |
| 668 | } |
| 669 | |
| 670 | /** |
| 671 | * Hide the application overlay. |
| 672 | */ |
| 673 | private void hideAppOverlay(boolean immediate) { |
| 674 | // Skip if we haven't even loaded the overlay yet |
| 675 | if (mAppOverlayView == null) { |
| 676 | return; |
| 677 | } |
| 678 | |
| 679 | if (immediate) { |
| 680 | mAppOverlayView.setVisibility(View.GONE); |
| 681 | } else { |
| 682 | int x = mIconView.getLeft() + mIconView.getWidth() / 2; |
| 683 | int y = mIconView.getTop() + mIconView.getHeight() / 2; |
| 684 | Animator revealAnim = ViewAnimationUtils.createCircularReveal(mAppOverlayView, x, y, |
| 685 | getWidth(), 0); |
| 686 | revealAnim.setDuration(OVERLAY_REVEAL_DURATION); |
Winson | c0d7058 | 2016-01-29 10:24:39 -0800 | [diff] [blame] | 687 | revealAnim.setInterpolator(Interpolators.LINEAR_OUT_SLOW_IN); |
Winson | c5ef63f | 2016-01-21 14:39:23 -0800 | [diff] [blame] | 688 | revealAnim.addListener(new AnimatorListenerAdapter() { |
| 689 | @Override |
| 690 | public void onAnimationEnd(Animator animation) { |
| 691 | mAppOverlayView.setVisibility(View.GONE); |
| 692 | } |
| 693 | }); |
| 694 | revealAnim.start(); |
| 695 | } |
| 696 | } |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 697 | } |