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