Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.systemui.stackdivider; |
| 18 | |
Jorim Jaggi | d47e7e1 | 2016-03-01 09:57:38 +0100 | [diff] [blame] | 19 | import static android.view.PointerIcon.STYLE_HORIZONTAL_DOUBLE_ARROW; |
| 20 | import static android.view.PointerIcon.STYLE_VERTICAL_DOUBLE_ARROW; |
| 21 | |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 22 | import android.animation.Animator; |
| 23 | import android.animation.AnimatorListenerAdapter; |
| 24 | import android.animation.ValueAnimator; |
| 25 | import android.animation.ValueAnimator.AnimatorUpdateListener; |
| 26 | import android.annotation.Nullable; |
Jorim Jaggi | 5098159 | 2015-12-29 17:54:12 +0100 | [diff] [blame] | 27 | import android.app.ActivityManager.StackId; |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 28 | import android.content.Context; |
| 29 | import android.content.res.Configuration; |
| 30 | import android.graphics.Rect; |
| 31 | import android.graphics.Region.Op; |
Filip Gruszczynski | f6d8e9e | 2015-11-12 13:39:20 -0800 | [diff] [blame] | 32 | import android.hardware.display.DisplayManager; |
Jorim Jaggi | 88afd02 | 2016-02-24 21:11:08 -0500 | [diff] [blame] | 33 | import android.os.Bundle; |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 34 | import android.util.AttributeSet; |
Filip Gruszczynski | f6d8e9e | 2015-11-12 13:39:20 -0800 | [diff] [blame] | 35 | import android.view.Display; |
| 36 | import android.view.DisplayInfo; |
Jorim Jaggi | d47e7e1 | 2016-03-01 09:57:38 +0100 | [diff] [blame] | 37 | import android.view.GestureDetector; |
Jorim Jaggi | d47e7e1 | 2016-03-01 09:57:38 +0100 | [diff] [blame] | 38 | import android.view.GestureDetector.SimpleOnGestureListener; |
Winson | d87e9a4 | 2016-04-11 12:57:31 -0700 | [diff] [blame] | 39 | import android.view.HapticFeedbackConstants; |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 40 | import android.view.MotionEvent; |
Jun Mukai | d4eaef7 | 2015-10-30 15:54:33 -0700 | [diff] [blame] | 41 | import android.view.PointerIcon; |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 42 | import android.view.VelocityTracker; |
| 43 | import android.view.View; |
| 44 | import android.view.View.OnTouchListener; |
Jorim Jaggi | d8fb3ac | 2016-01-05 15:37:42 +0100 | [diff] [blame] | 45 | import android.view.ViewConfiguration; |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 46 | import android.view.ViewTreeObserver.InternalInsetsInfo; |
| 47 | import android.view.ViewTreeObserver.OnComputeInternalInsetsListener; |
Jorim Jaggi | 81fe2d1 | 2015-12-21 14:45:18 +0100 | [diff] [blame] | 48 | import android.view.WindowInsets; |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 49 | import android.view.WindowManager; |
Jorim Jaggi | 88afd02 | 2016-02-24 21:11:08 -0500 | [diff] [blame] | 50 | import android.view.accessibility.AccessibilityNodeInfo; |
| 51 | import android.view.accessibility.AccessibilityNodeInfo.AccessibilityAction; |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 52 | import android.view.animation.Interpolator; |
| 53 | import android.view.animation.PathInterpolator; |
| 54 | import android.widget.FrameLayout; |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 55 | |
Jorim Jaggi | 29379ec | 2016-04-11 23:43:42 -0700 | [diff] [blame] | 56 | import com.android.internal.logging.MetricsLogger; |
| 57 | import com.android.internal.logging.MetricsProto.MetricsEvent; |
Jorim Jaggi | 737af72 | 2015-12-31 10:42:27 +0100 | [diff] [blame] | 58 | import com.android.internal.policy.DividerSnapAlgorithm; |
Winson | c0d7058 | 2016-01-29 10:24:39 -0800 | [diff] [blame] | 59 | import com.android.internal.policy.DividerSnapAlgorithm.SnapTarget; |
Jorim Jaggi | 737af72 | 2015-12-31 10:42:27 +0100 | [diff] [blame] | 60 | import com.android.internal.policy.DockedDividerUtils; |
Jorim Jaggi | ea4a19f | 2016-02-03 21:31:27 -0800 | [diff] [blame] | 61 | import com.android.systemui.Interpolators; |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 62 | import com.android.systemui.R; |
Jorim Jaggi | d47e7e1 | 2016-03-01 09:57:38 +0100 | [diff] [blame] | 63 | import com.android.systemui.recents.Recents; |
Jorim Jaggi | 11cc01d | 2016-01-22 19:39:23 -0800 | [diff] [blame] | 64 | import com.android.systemui.recents.events.EventBus; |
Jorim Jaggi | 899327f | 2016-02-25 20:44:18 -0500 | [diff] [blame] | 65 | import com.android.systemui.recents.events.activity.DockedTopTaskEvent; |
Jorim Jaggi | cdb06ca | 2016-01-25 19:15:12 -0800 | [diff] [blame] | 66 | import com.android.systemui.recents.events.activity.RecentsActivityStartingEvent; |
Jorim Jaggi | ea4a19f | 2016-02-03 21:31:27 -0800 | [diff] [blame] | 67 | import com.android.systemui.recents.events.activity.UndockingTaskEvent; |
Jorim Jaggi | 11cc01d | 2016-01-22 19:39:23 -0800 | [diff] [blame] | 68 | import com.android.systemui.recents.events.ui.RecentsDrawnEvent; |
Jorim Jaggi | d47e7e1 | 2016-03-01 09:57:38 +0100 | [diff] [blame] | 69 | import com.android.systemui.recents.misc.SystemServicesProxy; |
Jorim Jaggi | 2adba07 | 2016-03-03 13:43:39 +0100 | [diff] [blame] | 70 | import com.android.systemui.stackdivider.events.StartedDragingEvent; |
| 71 | import com.android.systemui.stackdivider.events.StoppedDragingEvent; |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 72 | import com.android.systemui.statusbar.FlingAnimationUtils; |
Jorim Jaggi | cdb06ca | 2016-01-25 19:15:12 -0800 | [diff] [blame] | 73 | import com.android.systemui.statusbar.phone.NavigationBarGestureHelper; |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 74 | |
| 75 | /** |
| 76 | * Docked stack divider. |
| 77 | */ |
| 78 | public class DividerView extends FrameLayout implements OnTouchListener, |
| 79 | OnComputeInternalInsetsListener { |
| 80 | |
Jorim Jaggi | 514b2cf | 2016-01-04 13:06:34 +0100 | [diff] [blame] | 81 | static final long TOUCH_ANIMATION_DURATION = 150; |
| 82 | static final long TOUCH_RELEASE_ANIMATION_DURATION = 200; |
Jorim Jaggi | 514b2cf | 2016-01-04 13:06:34 +0100 | [diff] [blame] | 83 | |
Jorim Jaggi | 29379ec | 2016-04-11 23:43:42 -0700 | [diff] [blame] | 84 | private static final int LOG_VALUE_RESIZE_50_50 = 0; |
| 85 | private static final int LOG_VALUE_RESIZE_DOCKED_SMALLER = 1; |
| 86 | private static final int LOG_VALUE_RESIZE_DOCKED_LARGER = 2; |
| 87 | |
| 88 | private static final int LOG_VALUE_UNDOCK_MAX_DOCKED = 0; |
| 89 | private static final int LOG_VALUE_UNDOCK_MAX_OTHER = 1; |
| 90 | |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 91 | |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 92 | private static final int TASK_POSITION_SAME = Integer.MAX_VALUE; |
Jorim Jaggi | 6885598 | 2016-03-25 18:46:30 -0700 | [diff] [blame] | 93 | private static final boolean SWAPPING_ENABLED = false; |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 94 | |
Jorim Jaggi | 50cd636 | 2016-01-22 17:18:29 -0800 | [diff] [blame] | 95 | /** |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 96 | * How much the background gets scaled when we are in the minimized dock state. |
| 97 | */ |
Jorim Jaggi | 2917dc4 | 2016-04-11 11:39:13 -0700 | [diff] [blame] | 98 | private static final float MINIMIZE_DOCK_SCALE = 0f; |
Jorim Jaggi | 698e763 | 2016-04-13 21:02:22 -0700 | [diff] [blame] | 99 | private static final float ADJUSTED_FOR_IME_SCALE = 0.5f; |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 100 | |
Jorim Jaggi | e435e98 | 2015-12-30 13:54:32 +0100 | [diff] [blame] | 101 | private static final PathInterpolator SLOWDOWN_INTERPOLATOR = |
| 102 | new PathInterpolator(0.5f, 1f, 0.5f, 1f); |
Jorim Jaggi | 8f8155b | 2016-01-25 19:45:42 -0800 | [diff] [blame] | 103 | private static final PathInterpolator DIM_INTERPOLATOR = |
| 104 | new PathInterpolator(.23f, .87f, .52f, -0.11f); |
Jorim Jaggi | e435e98 | 2015-12-30 13:54:32 +0100 | [diff] [blame] | 105 | |
Jorim Jaggi | 514b2cf | 2016-01-04 13:06:34 +0100 | [diff] [blame] | 106 | private DividerHandleView mHandle; |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 107 | private View mBackground; |
Jorim Jaggi | 2917dc4 | 2016-04-11 11:39:13 -0700 | [diff] [blame] | 108 | private MinimizedDockShadow mMinimizedShadow; |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 109 | private int mStartX; |
| 110 | private int mStartY; |
| 111 | private int mStartPosition; |
| 112 | private int mDockSide; |
| 113 | private final int[] mTempInt2 = new int[2]; |
Jorim Jaggi | d8fb3ac | 2016-01-05 15:37:42 +0100 | [diff] [blame] | 114 | private boolean mMoving; |
| 115 | private int mTouchSlop; |
Jorim Jaggi | e161f08 | 2016-02-05 14:26:16 -0800 | [diff] [blame] | 116 | private boolean mBackgroundLifted; |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 117 | |
| 118 | private int mDividerInsets; |
| 119 | private int mDisplayWidth; |
| 120 | private int mDisplayHeight; |
| 121 | private int mDividerWindowWidth; |
| 122 | private int mDividerSize; |
| 123 | private int mTouchElevation; |
Jorim Jaggi | e370e15 | 2016-04-15 14:13:33 -0700 | [diff] [blame^] | 124 | private int mLongPressEntraceAnimDuration; |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 125 | |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 126 | private final Rect mDockedRect = new Rect(); |
| 127 | private final Rect mDockedTaskRect = new Rect(); |
| 128 | private final Rect mOtherTaskRect = new Rect(); |
| 129 | private final Rect mOtherRect = new Rect(); |
| 130 | private final Rect mDockedInsetRect = new Rect(); |
| 131 | private final Rect mOtherInsetRect = new Rect(); |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 132 | private final Rect mLastResizeRect = new Rect(); |
Jorim Jaggi | 899327f | 2016-02-25 20:44:18 -0500 | [diff] [blame] | 133 | private final Rect mDisplayRect = new Rect(); |
Jorim Jaggi | 870ab5a | 2015-12-02 18:37:54 -0800 | [diff] [blame] | 134 | private final WindowManagerProxy mWindowManagerProxy = WindowManagerProxy.getInstance(); |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 135 | private DividerWindowManager mWindowManager; |
| 136 | private VelocityTracker mVelocityTracker; |
| 137 | private FlingAnimationUtils mFlingAnimationUtils; |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 138 | private DividerSnapAlgorithm mSnapAlgorithm; |
Jorim Jaggi | 81fe2d1 | 2015-12-21 14:45:18 +0100 | [diff] [blame] | 139 | private final Rect mStableInsets = new Rect(); |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 140 | |
Jorim Jaggi | 11cc01d | 2016-01-22 19:39:23 -0800 | [diff] [blame] | 141 | private boolean mAnimateAfterRecentsDrawn; |
Jorim Jaggi | cdb06ca | 2016-01-25 19:15:12 -0800 | [diff] [blame] | 142 | private boolean mGrowAfterRecentsDrawn; |
| 143 | private boolean mGrowRecents; |
Jorim Jaggi | 899327f | 2016-02-25 20:44:18 -0500 | [diff] [blame] | 144 | private ValueAnimator mCurrentAnimator; |
| 145 | private boolean mEntranceAnimationRunning; |
Jorim Jaggi | 47ee9ad | 2016-04-11 21:51:11 -0700 | [diff] [blame] | 146 | private boolean mExitAnimationRunning; |
| 147 | private int mExitStartPosition; |
Jorim Jaggi | d47e7e1 | 2016-03-01 09:57:38 +0100 | [diff] [blame] | 148 | private GestureDetector mGestureDetector; |
Jorim Jaggi | ef92d6f | 2016-03-25 22:07:16 -0700 | [diff] [blame] | 149 | private boolean mDockedStackMinimized; |
Jorim Jaggi | 698e763 | 2016-04-13 21:02:22 -0700 | [diff] [blame] | 150 | private boolean mAdjustedForIme; |
Jorim Jaggi | 11cc01d | 2016-01-22 19:39:23 -0800 | [diff] [blame] | 151 | |
Jorim Jaggi | 88afd02 | 2016-02-24 21:11:08 -0500 | [diff] [blame] | 152 | private final AccessibilityDelegate mHandleDelegate = new AccessibilityDelegate() { |
| 153 | @Override |
| 154 | public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfo info) { |
| 155 | super.onInitializeAccessibilityNodeInfo(host, info); |
| 156 | if (isHorizontalDivision()) { |
| 157 | info.addAction(new AccessibilityAction(R.id.action_move_up, |
| 158 | mContext.getString(R.string.accessibility_action_divider_move_up))); |
| 159 | info.addAction(new AccessibilityAction(R.id.action_move_down, |
| 160 | mContext.getString(R.string.accessibility_action_divider_move_down))); |
| 161 | } else { |
| 162 | info.addAction(new AccessibilityAction(R.id.action_move_left, |
| 163 | mContext.getString(R.string.accessibility_action_divider_move_left))); |
| 164 | info.addAction(new AccessibilityAction(R.id.action_move_right, |
| 165 | mContext.getString(R.string.accessibility_action_divider_move_right))); |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | @Override |
| 170 | public boolean performAccessibilityAction(View host, int action, Bundle args) { |
| 171 | if (action == R.id.action_move_up || action == R.id.action_move_down |
| 172 | || action == R.id.action_move_left || action == R.id.action_move_right) { |
| 173 | int position = getCurrentPosition(); |
| 174 | SnapTarget currentTarget = mSnapAlgorithm.calculateSnapTarget( |
| 175 | position, 0 /* velocity */); |
| 176 | SnapTarget nextTarget = |
| 177 | action == R.id.action_move_up || action == R.id.action_move_left |
| 178 | ? mSnapAlgorithm.getPreviousTarget(currentTarget) |
| 179 | : mSnapAlgorithm.getNextTarget(currentTarget); |
| 180 | startDragging(true /* animate */, false /* touching */); |
| 181 | stopDragging(getCurrentPosition(), nextTarget, 250, Interpolators.FAST_OUT_SLOW_IN); |
| 182 | return true; |
| 183 | } |
| 184 | return super.performAccessibilityAction(host, action, args); |
| 185 | } |
| 186 | }; |
| 187 | |
Jorim Jaggi | e661f40 | 2016-03-25 19:11:35 -0700 | [diff] [blame] | 188 | private final Runnable mResetBackgroundRunnable = new Runnable() { |
| 189 | @Override |
| 190 | public void run() { |
| 191 | resetBackground(); |
| 192 | } |
| 193 | }; |
| 194 | |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 195 | public DividerView(Context context) { |
| 196 | super(context); |
| 197 | } |
| 198 | |
| 199 | public DividerView(Context context, @Nullable AttributeSet attrs) { |
| 200 | super(context, attrs); |
| 201 | } |
| 202 | |
| 203 | public DividerView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { |
| 204 | super(context, attrs, defStyleAttr); |
| 205 | } |
| 206 | |
| 207 | public DividerView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, |
| 208 | int defStyleRes) { |
| 209 | super(context, attrs, defStyleAttr, defStyleRes); |
| 210 | } |
| 211 | |
| 212 | @Override |
| 213 | protected void onFinishInflate() { |
| 214 | super.onFinishInflate(); |
Jorim Jaggi | 514b2cf | 2016-01-04 13:06:34 +0100 | [diff] [blame] | 215 | mHandle = (DividerHandleView) findViewById(R.id.docked_divider_handle); |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 216 | mBackground = findViewById(R.id.docked_divider_background); |
Jorim Jaggi | 2917dc4 | 2016-04-11 11:39:13 -0700 | [diff] [blame] | 217 | mMinimizedShadow = (MinimizedDockShadow) findViewById(R.id.minimized_dock_shadow); |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 218 | mHandle.setOnTouchListener(this); |
| 219 | mDividerWindowWidth = getResources().getDimensionPixelSize( |
| 220 | com.android.internal.R.dimen.docked_stack_divider_thickness); |
| 221 | mDividerInsets = getResources().getDimensionPixelSize( |
| 222 | com.android.internal.R.dimen.docked_stack_divider_insets); |
| 223 | mDividerSize = mDividerWindowWidth - 2 * mDividerInsets; |
| 224 | mTouchElevation = getResources().getDimensionPixelSize( |
| 225 | R.dimen.docked_stack_divider_lift_elevation); |
Jorim Jaggi | e370e15 | 2016-04-15 14:13:33 -0700 | [diff] [blame^] | 226 | mLongPressEntraceAnimDuration = getResources().getInteger( |
| 227 | R.integer.long_press_dock_anim_duration); |
Jorim Jaggi | cdb06ca | 2016-01-25 19:15:12 -0800 | [diff] [blame] | 228 | mGrowRecents = getResources().getBoolean(R.bool.recents_grow_in_multiwindow); |
Jorim Jaggi | d8fb3ac | 2016-01-05 15:37:42 +0100 | [diff] [blame] | 229 | mTouchSlop = ViewConfiguration.get(mContext).getScaledTouchSlop(); |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 230 | mFlingAnimationUtils = new FlingAnimationUtils(getContext(), 0.3f); |
| 231 | updateDisplayInfo(); |
Jorim Jaggi | e48f428 | 2015-11-06 17:32:44 +0100 | [diff] [blame] | 232 | boolean landscape = getResources().getConfiguration().orientation |
| 233 | == Configuration.ORIENTATION_LANDSCAPE; |
Jun Mukai | d4eaef7 | 2015-10-30 15:54:33 -0700 | [diff] [blame] | 234 | mHandle.setPointerIcon(PointerIcon.getSystemIcon(getContext(), |
| 235 | landscape ? STYLE_HORIZONTAL_DOUBLE_ARROW : STYLE_VERTICAL_DOUBLE_ARROW)); |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 236 | getViewTreeObserver().addOnComputeInternalInsetsListener(this); |
Jorim Jaggi | 88afd02 | 2016-02-24 21:11:08 -0500 | [diff] [blame] | 237 | mHandle.setAccessibilityDelegate(mHandleDelegate); |
Jorim Jaggi | d47e7e1 | 2016-03-01 09:57:38 +0100 | [diff] [blame] | 238 | mGestureDetector = new GestureDetector(mContext, new SimpleOnGestureListener() { |
| 239 | @Override |
| 240 | public boolean onSingleTapUp(MotionEvent e) { |
Jorim Jaggi | 6885598 | 2016-03-25 18:46:30 -0700 | [diff] [blame] | 241 | if (SWAPPING_ENABLED) { |
| 242 | updateDockSide(); |
| 243 | SystemServicesProxy ssp = Recents.getSystemServices(); |
| 244 | if (mDockSide != WindowManager.DOCKED_INVALID |
| 245 | && !ssp.isRecentsTopMost(ssp.getTopMostTask(), null /* isTopHome */)) { |
| 246 | mWindowManagerProxy.swapTasks(); |
| 247 | return true; |
| 248 | } |
Jorim Jaggi | d47e7e1 | 2016-03-01 09:57:38 +0100 | [diff] [blame] | 249 | } |
| 250 | return false; |
| 251 | } |
| 252 | }); |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 253 | } |
| 254 | |
Jorim Jaggi | 81fe2d1 | 2015-12-21 14:45:18 +0100 | [diff] [blame] | 255 | @Override |
Jorim Jaggi | 11cc01d | 2016-01-22 19:39:23 -0800 | [diff] [blame] | 256 | protected void onAttachedToWindow() { |
| 257 | super.onAttachedToWindow(); |
| 258 | EventBus.getDefault().register(this); |
| 259 | } |
| 260 | |
| 261 | @Override |
| 262 | protected void onDetachedFromWindow() { |
| 263 | super.onDetachedFromWindow(); |
| 264 | EventBus.getDefault().unregister(this); |
| 265 | } |
| 266 | |
| 267 | @Override |
Jorim Jaggi | 81fe2d1 | 2015-12-21 14:45:18 +0100 | [diff] [blame] | 268 | public WindowInsets onApplyWindowInsets(WindowInsets insets) { |
Jorim Jaggi | 1b12ef5 | 2016-01-29 16:49:55 -0800 | [diff] [blame] | 269 | if (mStableInsets.left != insets.getStableInsetLeft() |
| 270 | || mStableInsets.top != insets.getStableInsetTop() |
| 271 | || mStableInsets.right != insets.getStableInsetRight() |
| 272 | || mStableInsets.bottom != insets.getStableInsetBottom()) { |
| 273 | mStableInsets.set(insets.getStableInsetLeft(), insets.getStableInsetTop(), |
| 274 | insets.getStableInsetRight(), insets.getStableInsetBottom()); |
| 275 | if (mSnapAlgorithm != null) { |
| 276 | mSnapAlgorithm = null; |
Jorim Jaggi | defd922 | 2016-02-03 18:28:49 -0800 | [diff] [blame] | 277 | initializeSnapAlgorithm(); |
Jorim Jaggi | 1b12ef5 | 2016-01-29 16:49:55 -0800 | [diff] [blame] | 278 | } |
| 279 | } |
Jorim Jaggi | 81fe2d1 | 2015-12-21 14:45:18 +0100 | [diff] [blame] | 280 | return super.onApplyWindowInsets(insets); |
| 281 | } |
| 282 | |
Jorim Jaggi | 8eb8a32 | 2016-04-05 18:03:56 -0700 | [diff] [blame] | 283 | @Override |
| 284 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) { |
| 285 | super.onLayout(changed, left, top, right, bottom); |
Jorim Jaggi | 2917dc4 | 2016-04-11 11:39:13 -0700 | [diff] [blame] | 286 | int minimizeLeft = 0; |
| 287 | int minimizeTop = 0; |
| 288 | if (mDockSide == WindowManager.DOCKED_TOP) { |
| 289 | minimizeTop = mBackground.getTop(); |
| 290 | } else if (mDockSide == WindowManager.DOCKED_LEFT) { |
| 291 | minimizeLeft = mBackground.getLeft(); |
| 292 | } else if (mDockSide == WindowManager.DOCKED_RIGHT) { |
| 293 | minimizeLeft = mBackground.getRight() - mMinimizedShadow.getWidth(); |
| 294 | } |
| 295 | mMinimizedShadow.layout(minimizeLeft, minimizeTop, |
| 296 | minimizeLeft + mMinimizedShadow.getMeasuredWidth(), |
| 297 | minimizeTop + mMinimizedShadow.getMeasuredHeight()); |
Jorim Jaggi | 8eb8a32 | 2016-04-05 18:03:56 -0700 | [diff] [blame] | 298 | if (changed) { |
| 299 | mWindowManagerProxy.setTouchRegion(new Rect(mHandle.getLeft(), mHandle.getTop(), |
| 300 | mHandle.getRight(), mHandle.getBottom())); |
| 301 | } |
| 302 | } |
| 303 | |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 304 | public void setWindowManager(DividerWindowManager windowManager) { |
| 305 | mWindowManager = windowManager; |
| 306 | } |
| 307 | |
Jorim Jaggi | dd98d41 | 2015-11-18 15:57:38 -0800 | [diff] [blame] | 308 | public WindowManagerProxy getWindowManagerProxy() { |
| 309 | return mWindowManagerProxy; |
| 310 | } |
| 311 | |
Jorim Jaggi | 11cc01d | 2016-01-22 19:39:23 -0800 | [diff] [blame] | 312 | public boolean startDragging(boolean animate, boolean touching) { |
Jorim Jaggi | 0c79041 | 2016-02-19 16:38:49 -0800 | [diff] [blame] | 313 | cancelFlingAnimation(); |
Jorim Jaggi | 11cc01d | 2016-01-22 19:39:23 -0800 | [diff] [blame] | 314 | if (touching) { |
| 315 | mHandle.setTouching(true, animate); |
| 316 | } |
Jorim Jaggi | dd98d41 | 2015-11-18 15:57:38 -0800 | [diff] [blame] | 317 | mDockSide = mWindowManagerProxy.getDockSide(); |
Jorim Jaggi | defd922 | 2016-02-03 18:28:49 -0800 | [diff] [blame] | 318 | initializeSnapAlgorithm(); |
Jorim Jaggi | 9511b0f | 2016-01-29 19:12:44 -0800 | [diff] [blame] | 319 | mWindowManagerProxy.setResizing(true); |
Jorim Jaggi | 9511b0f | 2016-01-29 19:12:44 -0800 | [diff] [blame] | 320 | if (touching) { |
Jorim Jaggi | e161f08 | 2016-02-05 14:26:16 -0800 | [diff] [blame] | 321 | mWindowManager.setSlippery(false); |
Jorim Jaggi | 9511b0f | 2016-01-29 19:12:44 -0800 | [diff] [blame] | 322 | liftBackground(); |
Jorim Jaggi | dd98d41 | 2015-11-18 15:57:38 -0800 | [diff] [blame] | 323 | } |
Jorim Jaggi | 2adba07 | 2016-03-03 13:43:39 +0100 | [diff] [blame] | 324 | EventBus.getDefault().send(new StartedDragingEvent()); |
Jorim Jaggi | 9511b0f | 2016-01-29 19:12:44 -0800 | [diff] [blame] | 325 | return mDockSide != WindowManager.DOCKED_INVALID; |
Jorim Jaggi | dd98d41 | 2015-11-18 15:57:38 -0800 | [diff] [blame] | 326 | } |
| 327 | |
Jorim Jaggi | 29379ec | 2016-04-11 23:43:42 -0700 | [diff] [blame] | 328 | public void stopDragging(int position, float velocity, boolean avoidDismissStart, |
| 329 | boolean logMetrics) { |
Jorim Jaggi | 514b2cf | 2016-01-04 13:06:34 +0100 | [diff] [blame] | 330 | mHandle.setTouching(false, true /* animate */); |
Jorim Jaggi | 29379ec | 2016-04-11 23:43:42 -0700 | [diff] [blame] | 331 | fling(position, velocity, avoidDismissStart, logMetrics); |
Jorim Jaggi | dd98d41 | 2015-11-18 15:57:38 -0800 | [diff] [blame] | 332 | mWindowManager.setSlippery(true); |
| 333 | releaseBackground(); |
| 334 | } |
| 335 | |
Jorim Jaggi | 11cc01d | 2016-01-22 19:39:23 -0800 | [diff] [blame] | 336 | public void stopDragging(int position, SnapTarget target, long duration, |
| 337 | Interpolator interpolator) { |
Jorim Jaggi | 545c5c2 | 2016-04-12 18:59:45 -0700 | [diff] [blame] | 338 | stopDragging(position, target, duration, 0 /* startDelay*/, 0 /* endDelay */, interpolator); |
| 339 | } |
| 340 | |
| 341 | public void stopDragging(int position, SnapTarget target, long duration, |
| 342 | Interpolator interpolator, long endDelay) { |
| 343 | stopDragging(position, target, duration, 0 /* startDelay*/, endDelay, interpolator); |
Jorim Jaggi | ea4a19f | 2016-02-03 21:31:27 -0800 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | public void stopDragging(int position, SnapTarget target, long duration, long startDelay, |
Jorim Jaggi | 545c5c2 | 2016-04-12 18:59:45 -0700 | [diff] [blame] | 347 | long endDelay, Interpolator interpolator) { |
Jorim Jaggi | 11cc01d | 2016-01-22 19:39:23 -0800 | [diff] [blame] | 348 | mHandle.setTouching(false, true /* animate */); |
Jorim Jaggi | 545c5c2 | 2016-04-12 18:59:45 -0700 | [diff] [blame] | 349 | flingTo(position, target, duration, startDelay, endDelay, interpolator); |
Jorim Jaggi | 11cc01d | 2016-01-22 19:39:23 -0800 | [diff] [blame] | 350 | mWindowManager.setSlippery(true); |
| 351 | releaseBackground(); |
| 352 | } |
| 353 | |
Jorim Jaggi | 9511b0f | 2016-01-29 19:12:44 -0800 | [diff] [blame] | 354 | private void stopDragging() { |
| 355 | mHandle.setTouching(false, true /* animate */); |
| 356 | mWindowManager.setSlippery(true); |
| 357 | releaseBackground(); |
| 358 | } |
| 359 | |
| 360 | private void updateDockSide() { |
| 361 | mDockSide = mWindowManagerProxy.getDockSide(); |
Jorim Jaggi | 2917dc4 | 2016-04-11 11:39:13 -0700 | [diff] [blame] | 362 | mMinimizedShadow.setDockSide(mDockSide); |
Jorim Jaggi | 9511b0f | 2016-01-29 19:12:44 -0800 | [diff] [blame] | 363 | } |
| 364 | |
Jorim Jaggi | defd922 | 2016-02-03 18:28:49 -0800 | [diff] [blame] | 365 | private void initializeSnapAlgorithm() { |
Jorim Jaggi | cdb06ca | 2016-01-25 19:15:12 -0800 | [diff] [blame] | 366 | if (mSnapAlgorithm == null) { |
| 367 | mSnapAlgorithm = new DividerSnapAlgorithm(getContext().getResources(), mDisplayWidth, |
| 368 | mDisplayHeight, mDividerSize, isHorizontalDivision(), mStableInsets); |
| 369 | } |
Jorim Jaggi | defd922 | 2016-02-03 18:28:49 -0800 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | public DividerSnapAlgorithm getSnapAlgorithm() { |
| 373 | initializeSnapAlgorithm(); |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 374 | return mSnapAlgorithm; |
| 375 | } |
| 376 | |
Jorim Jaggi | 11cc01d | 2016-01-22 19:39:23 -0800 | [diff] [blame] | 377 | public int getCurrentPosition() { |
| 378 | getLocationOnScreen(mTempInt2); |
| 379 | if (isHorizontalDivision()) { |
| 380 | return mTempInt2[1] + mDividerInsets; |
| 381 | } else { |
| 382 | return mTempInt2[0] + mDividerInsets; |
| 383 | } |
| 384 | } |
| 385 | |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 386 | @Override |
| 387 | public boolean onTouch(View v, MotionEvent event) { |
| 388 | convertToScreenCoordinates(event); |
Jorim Jaggi | d47e7e1 | 2016-03-01 09:57:38 +0100 | [diff] [blame] | 389 | mGestureDetector.onTouchEvent(event); |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 390 | final int action = event.getAction() & MotionEvent.ACTION_MASK; |
| 391 | switch (action) { |
| 392 | case MotionEvent.ACTION_DOWN: |
| 393 | mVelocityTracker = VelocityTracker.obtain(); |
| 394 | mVelocityTracker.addMovement(event); |
| 395 | mStartX = (int) event.getX(); |
| 396 | mStartY = (int) event.getY(); |
Jorim Jaggi | 11cc01d | 2016-01-22 19:39:23 -0800 | [diff] [blame] | 397 | boolean result = startDragging(true /* animate */, true /* touching */); |
Jorim Jaggi | 9511b0f | 2016-01-29 19:12:44 -0800 | [diff] [blame] | 398 | if (!result) { |
| 399 | |
| 400 | // Weren't able to start dragging successfully, so cancel it again. |
| 401 | stopDragging(); |
| 402 | } |
Jorim Jaggi | 11cc01d | 2016-01-22 19:39:23 -0800 | [diff] [blame] | 403 | mStartPosition = getCurrentPosition(); |
Jorim Jaggi | d8fb3ac | 2016-01-05 15:37:42 +0100 | [diff] [blame] | 404 | mMoving = false; |
Jorim Jaggi | dd98d41 | 2015-11-18 15:57:38 -0800 | [diff] [blame] | 405 | return result; |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 406 | case MotionEvent.ACTION_MOVE: |
| 407 | mVelocityTracker.addMovement(event); |
| 408 | int x = (int) event.getX(); |
| 409 | int y = (int) event.getY(); |
Jorim Jaggi | d8fb3ac | 2016-01-05 15:37:42 +0100 | [diff] [blame] | 410 | boolean exceededTouchSlop = |
| 411 | isHorizontalDivision() && Math.abs(y - mStartY) > mTouchSlop |
| 412 | || (!isHorizontalDivision() && Math.abs(x - mStartX) > mTouchSlop); |
| 413 | if (!mMoving && exceededTouchSlop) { |
| 414 | mStartX = x; |
| 415 | mStartY = y; |
| 416 | mMoving = true; |
| 417 | } |
| 418 | if (mMoving && mDockSide != WindowManager.DOCKED_INVALID) { |
Wale Ogunwale | ef676d8 | 2016-03-18 12:51:55 -0700 | [diff] [blame] | 419 | SnapTarget snapTarget = mSnapAlgorithm.calculateSnapTarget( |
| 420 | mStartPosition, 0 /* velocity */, false /* hardDismiss */); |
| 421 | resizeStack(calculatePosition(x, y), mStartPosition, snapTarget); |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 422 | } |
| 423 | break; |
| 424 | case MotionEvent.ACTION_UP: |
| 425 | case MotionEvent.ACTION_CANCEL: |
| 426 | mVelocityTracker.addMovement(event); |
| 427 | |
| 428 | x = (int) event.getRawX(); |
| 429 | y = (int) event.getRawY(); |
| 430 | |
| 431 | mVelocityTracker.computeCurrentVelocity(1000); |
Jorim Jaggi | dd98d41 | 2015-11-18 15:57:38 -0800 | [diff] [blame] | 432 | int position = calculatePosition(x, y); |
| 433 | stopDragging(position, isHorizontalDivision() ? mVelocityTracker.getYVelocity() |
Jorim Jaggi | 29379ec | 2016-04-11 23:43:42 -0700 | [diff] [blame] | 434 | : mVelocityTracker.getXVelocity(), false /* avoidDismissStart */, |
| 435 | true /* log */); |
Jorim Jaggi | d8fb3ac | 2016-01-05 15:37:42 +0100 | [diff] [blame] | 436 | mMoving = false; |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 437 | break; |
| 438 | } |
| 439 | return true; |
| 440 | } |
| 441 | |
Jorim Jaggi | 29379ec | 2016-04-11 23:43:42 -0700 | [diff] [blame] | 442 | private void logResizeEvent(SnapTarget snapTarget) { |
| 443 | if (snapTarget == mSnapAlgorithm.getDismissStartTarget()) { |
| 444 | MetricsLogger.action( |
| 445 | mContext, MetricsEvent.ACTION_WINDOW_UNDOCK_MAX, dockSideTopLeft(mDockSide) |
| 446 | ? LOG_VALUE_UNDOCK_MAX_OTHER |
| 447 | : LOG_VALUE_UNDOCK_MAX_DOCKED); |
| 448 | } else if (snapTarget == mSnapAlgorithm.getDismissEndTarget()) { |
| 449 | MetricsLogger.action( |
| 450 | mContext, MetricsEvent.ACTION_WINDOW_UNDOCK_MAX, dockSideBottomRight(mDockSide) |
| 451 | ? LOG_VALUE_UNDOCK_MAX_OTHER |
| 452 | : LOG_VALUE_UNDOCK_MAX_DOCKED); |
| 453 | } else if (snapTarget == mSnapAlgorithm.getMiddleTarget()) { |
| 454 | MetricsLogger.action(mContext, MetricsEvent.ACTION_WINDOW_DOCK_RESIZE, |
| 455 | LOG_VALUE_RESIZE_50_50); |
| 456 | } else if (snapTarget == mSnapAlgorithm.getFirstSplitTarget()) { |
| 457 | MetricsLogger.action(mContext, MetricsEvent.ACTION_WINDOW_DOCK_RESIZE, |
| 458 | dockSideTopLeft(mDockSide) |
| 459 | ? LOG_VALUE_RESIZE_DOCKED_SMALLER |
| 460 | : LOG_VALUE_RESIZE_DOCKED_LARGER); |
| 461 | } else if (snapTarget == mSnapAlgorithm.getLastSplitTarget()) { |
| 462 | MetricsLogger.action(mContext, MetricsEvent.ACTION_WINDOW_DOCK_RESIZE, |
| 463 | dockSideTopLeft(mDockSide) |
| 464 | ? LOG_VALUE_RESIZE_DOCKED_LARGER |
| 465 | : LOG_VALUE_RESIZE_DOCKED_SMALLER); |
| 466 | } |
| 467 | } |
| 468 | |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 469 | private void convertToScreenCoordinates(MotionEvent event) { |
| 470 | event.setLocation(event.getRawX(), event.getRawY()); |
| 471 | } |
| 472 | |
Jorim Jaggi | 29379ec | 2016-04-11 23:43:42 -0700 | [diff] [blame] | 473 | private void fling(int position, float velocity, boolean avoidDismissStart, |
| 474 | boolean logMetrics) { |
Jorim Jaggi | df012d5 | 2016-01-15 22:40:13 -0800 | [diff] [blame] | 475 | SnapTarget snapTarget = mSnapAlgorithm.calculateSnapTarget(position, velocity); |
| 476 | if (avoidDismissStart && snapTarget == mSnapAlgorithm.getDismissStartTarget()) { |
| 477 | snapTarget = mSnapAlgorithm.getFirstSplitTarget(); |
| 478 | } |
Jorim Jaggi | 29379ec | 2016-04-11 23:43:42 -0700 | [diff] [blame] | 479 | if (logMetrics) { |
| 480 | logResizeEvent(snapTarget); |
| 481 | } |
Jorim Jaggi | 545c5c2 | 2016-04-12 18:59:45 -0700 | [diff] [blame] | 482 | ValueAnimator anim = getFlingAnimator(position, snapTarget, 0 /* endDelay */); |
Jorim Jaggi | 11cc01d | 2016-01-22 19:39:23 -0800 | [diff] [blame] | 483 | mFlingAnimationUtils.apply(anim, position, snapTarget.position, velocity); |
| 484 | anim.start(); |
| 485 | } |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 486 | |
Jorim Jaggi | ea4a19f | 2016-02-03 21:31:27 -0800 | [diff] [blame] | 487 | private void flingTo(int position, SnapTarget target, long duration, long startDelay, |
Jorim Jaggi | 545c5c2 | 2016-04-12 18:59:45 -0700 | [diff] [blame] | 488 | long endDelay, Interpolator interpolator) { |
| 489 | ValueAnimator anim = getFlingAnimator(position, target, endDelay); |
Jorim Jaggi | 11cc01d | 2016-01-22 19:39:23 -0800 | [diff] [blame] | 490 | anim.setDuration(duration); |
Jorim Jaggi | ea4a19f | 2016-02-03 21:31:27 -0800 | [diff] [blame] | 491 | anim.setStartDelay(startDelay); |
Jorim Jaggi | 11cc01d | 2016-01-22 19:39:23 -0800 | [diff] [blame] | 492 | anim.setInterpolator(interpolator); |
| 493 | anim.start(); |
| 494 | } |
| 495 | |
Jorim Jaggi | 545c5c2 | 2016-04-12 18:59:45 -0700 | [diff] [blame] | 496 | private ValueAnimator getFlingAnimator(int position, final SnapTarget snapTarget, |
| 497 | final long endDelay) { |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 498 | ValueAnimator anim = ValueAnimator.ofInt(position, snapTarget.position); |
| 499 | anim.addUpdateListener(new AnimatorUpdateListener() { |
| 500 | @Override |
| 501 | public void onAnimationUpdate(ValueAnimator animation) { |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 502 | resizeStack((Integer) animation.getAnimatedValue(), |
| 503 | animation.getAnimatedFraction() == 1f |
| 504 | ? TASK_POSITION_SAME |
Jorim Jaggi | 11cc01d | 2016-01-22 19:39:23 -0800 | [diff] [blame] | 505 | : snapTarget.position, snapTarget); |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 506 | } |
| 507 | }); |
Jorim Jaggi | 545c5c2 | 2016-04-12 18:59:45 -0700 | [diff] [blame] | 508 | Runnable endAction = () -> { |
| 509 | commitSnapFlags(snapTarget); |
| 510 | mWindowManagerProxy.setResizing(false); |
| 511 | mDockSide = WindowManager.DOCKED_INVALID; |
| 512 | mCurrentAnimator = null; |
| 513 | mEntranceAnimationRunning = false; |
| 514 | mExitAnimationRunning = false; |
| 515 | EventBus.getDefault().send(new StoppedDragingEvent()); |
| 516 | }; |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 517 | anim.addListener(new AnimatorListenerAdapter() { |
Jorim Jaggi | 545c5c2 | 2016-04-12 18:59:45 -0700 | [diff] [blame] | 518 | |
| 519 | private boolean mCancelled; |
| 520 | |
| 521 | @Override |
| 522 | public void onAnimationCancel(Animator animation) { |
| 523 | mCancelled = true; |
| 524 | } |
| 525 | |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 526 | @Override |
| 527 | public void onAnimationEnd(Animator animation) { |
Jorim Jaggi | 545c5c2 | 2016-04-12 18:59:45 -0700 | [diff] [blame] | 528 | if (endDelay == 0 || mCancelled) { |
| 529 | endAction.run(); |
| 530 | } else { |
| 531 | postDelayed(endAction, endDelay); |
| 532 | } |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 533 | } |
| 534 | }); |
Jorim Jaggi | 0c79041 | 2016-02-19 16:38:49 -0800 | [diff] [blame] | 535 | mCurrentAnimator = anim; |
Jorim Jaggi | 11cc01d | 2016-01-22 19:39:23 -0800 | [diff] [blame] | 536 | return anim; |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 537 | } |
| 538 | |
Jorim Jaggi | 0c79041 | 2016-02-19 16:38:49 -0800 | [diff] [blame] | 539 | private void cancelFlingAnimation() { |
| 540 | if (mCurrentAnimator != null) { |
| 541 | mCurrentAnimator.cancel(); |
| 542 | } |
| 543 | } |
| 544 | |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 545 | private void commitSnapFlags(SnapTarget target) { |
| 546 | if (target.flag == SnapTarget.FLAG_NONE) { |
| 547 | return; |
| 548 | } |
| 549 | boolean dismissOrMaximize; |
| 550 | if (target.flag == SnapTarget.FLAG_DISMISS_START) { |
| 551 | dismissOrMaximize = mDockSide == WindowManager.DOCKED_LEFT |
| 552 | || mDockSide == WindowManager.DOCKED_TOP; |
| 553 | } else { |
| 554 | dismissOrMaximize = mDockSide == WindowManager.DOCKED_RIGHT |
| 555 | || mDockSide == WindowManager.DOCKED_BOTTOM; |
| 556 | } |
| 557 | if (dismissOrMaximize) { |
| 558 | mWindowManagerProxy.dismissDockedStack(); |
| 559 | } else { |
| 560 | mWindowManagerProxy.maximizeDockedStack(); |
| 561 | } |
Jorim Jaggi | 5098159 | 2015-12-29 17:54:12 +0100 | [diff] [blame] | 562 | mWindowManagerProxy.setResizeDimLayer(false, -1, 0f); |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 563 | } |
| 564 | |
| 565 | private void liftBackground() { |
Jorim Jaggi | e161f08 | 2016-02-05 14:26:16 -0800 | [diff] [blame] | 566 | if (mBackgroundLifted) { |
| 567 | return; |
| 568 | } |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 569 | if (isHorizontalDivision()) { |
Jorim Jaggi | 79b39f0 | 2015-12-17 20:04:31 -0800 | [diff] [blame] | 570 | mBackground.animate().scaleY(1.4f); |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 571 | } else { |
Jorim Jaggi | 79b39f0 | 2015-12-17 20:04:31 -0800 | [diff] [blame] | 572 | mBackground.animate().scaleX(1.4f); |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 573 | } |
| 574 | mBackground.animate() |
Jorim Jaggi | ea4a19f | 2016-02-03 21:31:27 -0800 | [diff] [blame] | 575 | .setInterpolator(Interpolators.TOUCH_RESPONSE) |
Jorim Jaggi | 514b2cf | 2016-01-04 13:06:34 +0100 | [diff] [blame] | 576 | .setDuration(TOUCH_ANIMATION_DURATION) |
| 577 | .translationZ(mTouchElevation) |
| 578 | .start(); |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 579 | |
| 580 | // Lift handle as well so it doesn't get behind the background, even though it doesn't |
| 581 | // cast shadow. |
| 582 | mHandle.animate() |
Jorim Jaggi | ea4a19f | 2016-02-03 21:31:27 -0800 | [diff] [blame] | 583 | .setInterpolator(Interpolators.TOUCH_RESPONSE) |
Jorim Jaggi | 514b2cf | 2016-01-04 13:06:34 +0100 | [diff] [blame] | 584 | .setDuration(TOUCH_ANIMATION_DURATION) |
| 585 | .translationZ(mTouchElevation) |
| 586 | .start(); |
Jorim Jaggi | e161f08 | 2016-02-05 14:26:16 -0800 | [diff] [blame] | 587 | mBackgroundLifted = true; |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 588 | } |
| 589 | |
| 590 | private void releaseBackground() { |
Jorim Jaggi | e161f08 | 2016-02-05 14:26:16 -0800 | [diff] [blame] | 591 | if (!mBackgroundLifted) { |
| 592 | return; |
| 593 | } |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 594 | mBackground.animate() |
Jorim Jaggi | ea4a19f | 2016-02-03 21:31:27 -0800 | [diff] [blame] | 595 | .setInterpolator(Interpolators.FAST_OUT_SLOW_IN) |
Jorim Jaggi | 514b2cf | 2016-01-04 13:06:34 +0100 | [diff] [blame] | 596 | .setDuration(TOUCH_RELEASE_ANIMATION_DURATION) |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 597 | .translationZ(0) |
| 598 | .scaleX(1f) |
Jorim Jaggi | 514b2cf | 2016-01-04 13:06:34 +0100 | [diff] [blame] | 599 | .scaleY(1f) |
| 600 | .start(); |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 601 | mHandle.animate() |
Jorim Jaggi | ea4a19f | 2016-02-03 21:31:27 -0800 | [diff] [blame] | 602 | .setInterpolator(Interpolators.FAST_OUT_SLOW_IN) |
Jorim Jaggi | 514b2cf | 2016-01-04 13:06:34 +0100 | [diff] [blame] | 603 | .setDuration(TOUCH_RELEASE_ANIMATION_DURATION) |
| 604 | .translationZ(0) |
| 605 | .start(); |
Jorim Jaggi | e161f08 | 2016-02-05 14:26:16 -0800 | [diff] [blame] | 606 | mBackgroundLifted = false; |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 607 | } |
| 608 | |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 609 | |
| 610 | public void setMinimizedDockStack(boolean minimized) { |
| 611 | updateDockSide(); |
| 612 | mHandle.setAlpha(minimized ? 0f : 1f); |
Jorim Jaggi | e661f40 | 2016-03-25 19:11:35 -0700 | [diff] [blame] | 613 | if (!minimized) { |
| 614 | resetBackground(); |
| 615 | } else if (mDockSide == WindowManager.DOCKED_TOP) { |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 616 | mBackground.setPivotY(0); |
Jorim Jaggi | e661f40 | 2016-03-25 19:11:35 -0700 | [diff] [blame] | 617 | mBackground.setScaleY(MINIMIZE_DOCK_SCALE); |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 618 | } else if (mDockSide == WindowManager.DOCKED_LEFT |
| 619 | || mDockSide == WindowManager.DOCKED_RIGHT) { |
| 620 | mBackground.setPivotX(mDockSide == WindowManager.DOCKED_LEFT |
| 621 | ? 0 |
| 622 | : mBackground.getWidth()); |
Jorim Jaggi | e661f40 | 2016-03-25 19:11:35 -0700 | [diff] [blame] | 623 | mBackground.setScaleX(MINIMIZE_DOCK_SCALE); |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 624 | } |
Jorim Jaggi | 2917dc4 | 2016-04-11 11:39:13 -0700 | [diff] [blame] | 625 | mMinimizedShadow.setAlpha(minimized ? 1f : 0f); |
Jorim Jaggi | ef92d6f | 2016-03-25 22:07:16 -0700 | [diff] [blame] | 626 | mDockedStackMinimized = minimized; |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 627 | } |
| 628 | |
| 629 | public void setMinimizedDockStack(boolean minimized, long animDuration) { |
| 630 | updateDockSide(); |
| 631 | mHandle.animate() |
| 632 | .setInterpolator(Interpolators.FAST_OUT_SLOW_IN) |
| 633 | .setDuration(animDuration) |
| 634 | .alpha(minimized ? 0f : 1f) |
| 635 | .start(); |
| 636 | if (mDockSide == WindowManager.DOCKED_TOP) { |
| 637 | mBackground.setPivotY(0); |
| 638 | mBackground.animate() |
| 639 | .scaleY(minimized ? MINIMIZE_DOCK_SCALE : 1f); |
| 640 | } else if (mDockSide == WindowManager.DOCKED_LEFT |
| 641 | || mDockSide == WindowManager.DOCKED_RIGHT) { |
| 642 | mBackground.setPivotX(mDockSide == WindowManager.DOCKED_LEFT |
| 643 | ? 0 |
| 644 | : mBackground.getWidth()); |
| 645 | mBackground.animate() |
| 646 | .scaleX(minimized ? MINIMIZE_DOCK_SCALE : 1f); |
| 647 | } |
Jorim Jaggi | e661f40 | 2016-03-25 19:11:35 -0700 | [diff] [blame] | 648 | if (!minimized) { |
| 649 | mBackground.animate().withEndAction(mResetBackgroundRunnable); |
| 650 | } |
Jorim Jaggi | 2917dc4 | 2016-04-11 11:39:13 -0700 | [diff] [blame] | 651 | mMinimizedShadow.animate() |
| 652 | .alpha(minimized ? 1f : 0f) |
| 653 | .setInterpolator(Interpolators.ALPHA_IN) |
| 654 | .setDuration(animDuration) |
| 655 | .start(); |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 656 | mBackground.animate() |
| 657 | .setInterpolator(Interpolators.FAST_OUT_SLOW_IN) |
| 658 | .setDuration(animDuration) |
| 659 | .start(); |
Jorim Jaggi | ef92d6f | 2016-03-25 22:07:16 -0700 | [diff] [blame] | 660 | mDockedStackMinimized = minimized; |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 661 | } |
| 662 | |
Jorim Jaggi | 698e763 | 2016-04-13 21:02:22 -0700 | [diff] [blame] | 663 | public void setAdjustedForIme(boolean adjustedForIme) { |
| 664 | updateDockSide(); |
| 665 | mHandle.setAlpha(adjustedForIme ? 0f : 1f); |
| 666 | if (!adjustedForIme) { |
| 667 | resetBackground(); |
| 668 | } else if (mDockSide == WindowManager.DOCKED_TOP) { |
| 669 | mBackground.setPivotY(0); |
| 670 | mBackground.setScaleY(MINIMIZE_DOCK_SCALE); |
| 671 | } |
| 672 | mAdjustedForIme = adjustedForIme; |
| 673 | } |
| 674 | |
| 675 | public void setAdjustedForIme(boolean adjustedForIme, long animDuration) { |
| 676 | updateDockSide(); |
| 677 | mHandle.animate() |
| 678 | .setInterpolator(Interpolators.FAST_OUT_SLOW_IN) |
| 679 | .setDuration(animDuration) |
| 680 | .alpha(adjustedForIme ? 0f : 1f) |
| 681 | .start(); |
| 682 | if (mDockSide == WindowManager.DOCKED_TOP) { |
| 683 | mBackground.setPivotY(0); |
| 684 | mBackground.animate() |
| 685 | .scaleY(adjustedForIme ? MINIMIZE_DOCK_SCALE : 1f); |
| 686 | } |
| 687 | if (!adjustedForIme) { |
| 688 | mBackground.animate().withEndAction(mResetBackgroundRunnable); |
| 689 | } |
| 690 | mBackground.animate() |
| 691 | .setInterpolator(Interpolators.FAST_OUT_SLOW_IN) |
| 692 | .setDuration(animDuration) |
| 693 | .start(); |
| 694 | mAdjustedForIme = adjustedForIme; |
| 695 | } |
| 696 | |
Jorim Jaggi | e661f40 | 2016-03-25 19:11:35 -0700 | [diff] [blame] | 697 | private void resetBackground() { |
| 698 | mBackground.setPivotX(mBackground.getWidth() / 2); |
| 699 | mBackground.setPivotY(mBackground.getHeight() / 2); |
| 700 | mBackground.setScaleX(1f); |
| 701 | mBackground.setScaleY(1f); |
Jorim Jaggi | 2917dc4 | 2016-04-11 11:39:13 -0700 | [diff] [blame] | 702 | mMinimizedShadow.setAlpha(0f); |
Jorim Jaggi | e661f40 | 2016-03-25 19:11:35 -0700 | [diff] [blame] | 703 | } |
| 704 | |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 705 | @Override |
| 706 | protected void onConfigurationChanged(Configuration newConfig) { |
| 707 | super.onConfigurationChanged(newConfig); |
| 708 | updateDisplayInfo(); |
| 709 | } |
| 710 | |
Jorim Jaggi | 2917dc4 | 2016-04-11 11:39:13 -0700 | [diff] [blame] | 711 | |
| 712 | public void notifyDockSideChanged(int newDockSide) { |
| 713 | mDockSide = newDockSide; |
| 714 | mMinimizedShadow.setDockSide(mDockSide); |
| 715 | requestLayout(); |
| 716 | } |
| 717 | |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 718 | private void updateDisplayInfo() { |
Filip Gruszczynski | f6d8e9e | 2015-11-12 13:39:20 -0800 | [diff] [blame] | 719 | final DisplayManager displayManager = |
| 720 | (DisplayManager) mContext.getSystemService(Context.DISPLAY_SERVICE); |
| 721 | Display display = displayManager.getDisplay(Display.DEFAULT_DISPLAY); |
| 722 | final DisplayInfo info = new DisplayInfo(); |
| 723 | display.getDisplayInfo(info); |
| 724 | mDisplayWidth = info.logicalWidth; |
| 725 | mDisplayHeight = info.logicalHeight; |
Jorim Jaggi | cdb06ca | 2016-01-25 19:15:12 -0800 | [diff] [blame] | 726 | mSnapAlgorithm = null; |
Jorim Jaggi | defd922 | 2016-02-03 18:28:49 -0800 | [diff] [blame] | 727 | initializeSnapAlgorithm(); |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 728 | } |
| 729 | |
| 730 | private int calculatePosition(int touchX, int touchY) { |
| 731 | return isHorizontalDivision() ? calculateYPosition(touchY) : calculateXPosition(touchX); |
| 732 | } |
| 733 | |
Jorim Jaggi | dd98d41 | 2015-11-18 15:57:38 -0800 | [diff] [blame] | 734 | public boolean isHorizontalDivision() { |
| 735 | return getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT; |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 736 | } |
| 737 | |
| 738 | private int calculateXPosition(int touchX) { |
| 739 | return mStartPosition + touchX - mStartX; |
| 740 | } |
| 741 | |
| 742 | private int calculateYPosition(int touchY) { |
| 743 | return mStartPosition + touchY - mStartY; |
| 744 | } |
| 745 | |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 746 | private void alignTopLeft(Rect containingRect, Rect rect) { |
| 747 | int width = rect.width(); |
| 748 | int height = rect.height(); |
| 749 | rect.set(containingRect.left, containingRect.top, |
| 750 | containingRect.left + width, containingRect.top + height); |
| 751 | } |
| 752 | |
| 753 | private void alignBottomRight(Rect containingRect, Rect rect) { |
| 754 | int width = rect.width(); |
| 755 | int height = rect.height(); |
| 756 | rect.set(containingRect.right - width, containingRect.bottom - height, |
| 757 | containingRect.right, containingRect.bottom); |
| 758 | } |
| 759 | |
Jorim Jaggi | 737af72 | 2015-12-31 10:42:27 +0100 | [diff] [blame] | 760 | public void calculateBoundsForPosition(int position, int dockSide, Rect outRect) { |
| 761 | DockedDividerUtils.calculateBoundsForPosition(position, dockSide, outRect, mDisplayWidth, |
| 762 | mDisplayHeight, mDividerSize); |
| 763 | } |
| 764 | |
Jorim Jaggi | e435e98 | 2015-12-30 13:54:32 +0100 | [diff] [blame] | 765 | public void resizeStack(int position, int taskPosition, SnapTarget taskSnapTarget) { |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 766 | calculateBoundsForPosition(position, mDockSide, mDockedRect); |
| 767 | |
Jorim Jaggi | e370e15 | 2016-04-15 14:13:33 -0700 | [diff] [blame^] | 768 | if (mDockedRect.equals(mLastResizeRect) && !mEntranceAnimationRunning) { |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 769 | return; |
| 770 | } |
Jorim Jaggi | c97ba49 | 2015-11-06 22:00:18 +0100 | [diff] [blame] | 771 | |
| 772 | // Make sure shadows are updated |
Jorim Jaggi | e161f08 | 2016-02-05 14:26:16 -0800 | [diff] [blame] | 773 | if (mBackground.getZ() > 0f) { |
| 774 | mBackground.invalidate(); |
| 775 | } |
Jorim Jaggi | c97ba49 | 2015-11-06 22:00:18 +0100 | [diff] [blame] | 776 | |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 777 | mLastResizeRect.set(mDockedRect); |
Jorim Jaggi | 899327f | 2016-02-25 20:44:18 -0500 | [diff] [blame] | 778 | if (mEntranceAnimationRunning && taskPosition != TASK_POSITION_SAME) { |
| 779 | if (mCurrentAnimator != null) { |
| 780 | calculateBoundsForPosition(taskPosition, mDockSide, mDockedTaskRect); |
| 781 | } else { |
| 782 | calculateBoundsForPosition(isHorizontalDivision() ? mDisplayHeight : mDisplayWidth, |
| 783 | mDockSide, mDockedTaskRect); |
| 784 | } |
| 785 | calculateBoundsForPosition(taskPosition, DockedDividerUtils.invertDockSide(mDockSide), |
| 786 | mOtherTaskRect); |
| 787 | mWindowManagerProxy.resizeDockedStack(mDockedRect, mDockedTaskRect, null, |
| 788 | mOtherTaskRect, null); |
Jorim Jaggi | 47ee9ad | 2016-04-11 21:51:11 -0700 | [diff] [blame] | 789 | } else if (mExitAnimationRunning && taskPosition != TASK_POSITION_SAME) { |
| 790 | calculateBoundsForPosition(taskPosition, |
| 791 | mDockSide, mDockedTaskRect); |
| 792 | calculateBoundsForPosition(mExitStartPosition, |
| 793 | DockedDividerUtils.invertDockSide(mDockSide), mOtherTaskRect); |
Jorim Jaggi | 545c5c2 | 2016-04-12 18:59:45 -0700 | [diff] [blame] | 794 | mOtherInsetRect.set(mOtherTaskRect); |
| 795 | applyExitAnimationParallax(mOtherTaskRect, position); |
Jorim Jaggi | 47ee9ad | 2016-04-11 21:51:11 -0700 | [diff] [blame] | 796 | mWindowManagerProxy.resizeDockedStack(mDockedRect, mDockedTaskRect, null, |
Jorim Jaggi | 545c5c2 | 2016-04-12 18:59:45 -0700 | [diff] [blame] | 797 | mOtherTaskRect, mOtherInsetRect); |
Jorim Jaggi | 899327f | 2016-02-25 20:44:18 -0500 | [diff] [blame] | 798 | } else if (taskPosition != TASK_POSITION_SAME) { |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 799 | calculateBoundsForPosition(position, DockedDividerUtils.invertDockSide(mDockSide), |
| 800 | mOtherRect); |
| 801 | int dockSideInverted = DockedDividerUtils.invertDockSide(mDockSide); |
Jorim Jaggi | e435e98 | 2015-12-30 13:54:32 +0100 | [diff] [blame] | 802 | int taskPositionDocked = |
| 803 | restrictDismissingTaskPosition(taskPosition, mDockSide, taskSnapTarget); |
| 804 | int taskPositionOther = |
| 805 | restrictDismissingTaskPosition(taskPosition, dockSideInverted, taskSnapTarget); |
| 806 | calculateBoundsForPosition(taskPositionDocked, mDockSide, mDockedTaskRect); |
| 807 | calculateBoundsForPosition(taskPositionOther, dockSideInverted, mOtherTaskRect); |
Jorim Jaggi | 899327f | 2016-02-25 20:44:18 -0500 | [diff] [blame] | 808 | mDisplayRect.set(0, 0, mDisplayWidth, mDisplayHeight); |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 809 | alignTopLeft(mDockedRect, mDockedTaskRect); |
| 810 | alignTopLeft(mOtherRect, mOtherTaskRect); |
| 811 | mDockedInsetRect.set(mDockedTaskRect); |
| 812 | mOtherInsetRect.set(mOtherTaskRect); |
Jorim Jaggi | e435e98 | 2015-12-30 13:54:32 +0100 | [diff] [blame] | 813 | if (dockSideTopLeft(mDockSide)) { |
Jorim Jaggi | 899327f | 2016-02-25 20:44:18 -0500 | [diff] [blame] | 814 | alignTopLeft(mDisplayRect, mDockedInsetRect); |
| 815 | alignBottomRight(mDisplayRect, mOtherInsetRect); |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 816 | } else { |
Jorim Jaggi | 899327f | 2016-02-25 20:44:18 -0500 | [diff] [blame] | 817 | alignBottomRight(mDisplayRect, mDockedInsetRect); |
| 818 | alignTopLeft(mDisplayRect, mOtherInsetRect); |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 819 | } |
Jorim Jaggi | e435e98 | 2015-12-30 13:54:32 +0100 | [diff] [blame] | 820 | applyDismissingParallax(mDockedTaskRect, mDockSide, taskSnapTarget, position, |
| 821 | taskPositionDocked); |
| 822 | applyDismissingParallax(mOtherTaskRect, dockSideInverted, taskSnapTarget, position, |
| 823 | taskPositionOther); |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 824 | mWindowManagerProxy.resizeDockedStack(mDockedRect, mDockedTaskRect, mDockedInsetRect, |
| 825 | mOtherTaskRect, mOtherInsetRect); |
| 826 | } else { |
| 827 | mWindowManagerProxy.resizeDockedStack(mDockedRect, null, null, null, null); |
| 828 | } |
Jorim Jaggi | 1b12ef5 | 2016-01-29 16:49:55 -0800 | [diff] [blame] | 829 | SnapTarget closestDismissTarget = mSnapAlgorithm.getClosestDismissTarget(position); |
| 830 | float dimFraction = getDimFraction(position, closestDismissTarget); |
| 831 | mWindowManagerProxy.setResizeDimLayer(dimFraction != 0f, |
| 832 | getStackIdForDismissTarget(closestDismissTarget), |
| 833 | dimFraction); |
| 834 | } |
| 835 | |
Jorim Jaggi | 545c5c2 | 2016-04-12 18:59:45 -0700 | [diff] [blame] | 836 | private void applyExitAnimationParallax(Rect taskRect, int position) { |
| 837 | if (mDockSide == WindowManager.DOCKED_TOP) { |
| 838 | taskRect.offset(0, (int) ((position - mExitStartPosition) * 0.25f)); |
| 839 | } else if (mDockSide == WindowManager.DOCKED_LEFT) { |
| 840 | taskRect.offset((int) ((position - mExitStartPosition) * 0.25f), 0); |
| 841 | } else if (mDockSide == WindowManager.DOCKED_RIGHT) { |
| 842 | taskRect.offset((int) ((mExitStartPosition - position) * 0.25f), 0); |
| 843 | } |
| 844 | } |
| 845 | |
Jorim Jaggi | 1b12ef5 | 2016-01-29 16:49:55 -0800 | [diff] [blame] | 846 | private float getDimFraction(int position, SnapTarget dismissTarget) { |
Jorim Jaggi | 899327f | 2016-02-25 20:44:18 -0500 | [diff] [blame] | 847 | if (mEntranceAnimationRunning) { |
| 848 | return 0f; |
| 849 | } |
Jorim Jaggi | 5098159 | 2015-12-29 17:54:12 +0100 | [diff] [blame] | 850 | float fraction = mSnapAlgorithm.calculateDismissingFraction(position); |
Jorim Jaggi | 8f8155b | 2016-01-25 19:45:42 -0800 | [diff] [blame] | 851 | fraction = Math.max(0, Math.min(fraction, 1f)); |
| 852 | fraction = DIM_INTERPOLATOR.getInterpolation(fraction); |
Jorim Jaggi | 1b12ef5 | 2016-01-29 16:49:55 -0800 | [diff] [blame] | 853 | if (hasInsetsAtDismissTarget(dismissTarget)) { |
| 854 | |
| 855 | // Less darkening with system insets. |
| 856 | fraction *= 0.8f; |
| 857 | } |
| 858 | return fraction; |
| 859 | } |
| 860 | |
| 861 | /** |
| 862 | * @return true if and only if there are system insets at the location of the dismiss target |
| 863 | */ |
| 864 | private boolean hasInsetsAtDismissTarget(SnapTarget dismissTarget) { |
| 865 | if (isHorizontalDivision()) { |
| 866 | if (dismissTarget == mSnapAlgorithm.getDismissStartTarget()) { |
| 867 | return mStableInsets.top != 0; |
| 868 | } else { |
| 869 | return mStableInsets.bottom != 0; |
| 870 | } |
| 871 | } else { |
| 872 | if (dismissTarget == mSnapAlgorithm.getDismissStartTarget()) { |
| 873 | return mStableInsets.left != 0; |
| 874 | } else { |
| 875 | return mStableInsets.right != 0; |
| 876 | } |
| 877 | } |
Jorim Jaggi | 5098159 | 2015-12-29 17:54:12 +0100 | [diff] [blame] | 878 | } |
| 879 | |
Jorim Jaggi | e435e98 | 2015-12-30 13:54:32 +0100 | [diff] [blame] | 880 | /** |
| 881 | * When the snap target is dismissing one side, make sure that the dismissing side doesn't get |
| 882 | * 0 size. |
| 883 | */ |
| 884 | private int restrictDismissingTaskPosition(int taskPosition, int dockSide, |
| 885 | SnapTarget snapTarget) { |
| 886 | if (snapTarget.flag == SnapTarget.FLAG_DISMISS_START && dockSideTopLeft(dockSide)) { |
| 887 | return mSnapAlgorithm.getFirstSplitTarget().position; |
| 888 | } else if (snapTarget.flag == SnapTarget.FLAG_DISMISS_END |
| 889 | && dockSideBottomRight(dockSide)) { |
| 890 | return mSnapAlgorithm.getLastSplitTarget().position; |
| 891 | } else { |
| 892 | return taskPosition; |
| 893 | } |
| 894 | } |
| 895 | |
| 896 | /** |
| 897 | * Applies a parallax to the task when dismissing. |
| 898 | */ |
| 899 | private void applyDismissingParallax(Rect taskRect, int dockSide, SnapTarget snapTarget, |
| 900 | int position, int taskPosition) { |
| 901 | float fraction = Math.min(1, Math.max(0, |
| 902 | mSnapAlgorithm.calculateDismissingFraction(position))); |
| 903 | SnapTarget dismissTarget = null; |
| 904 | SnapTarget splitTarget = null; |
Jorim Jaggi | 8dccd23 | 2016-03-25 18:10:14 -0700 | [diff] [blame] | 905 | int start = 0; |
| 906 | if (position <= mSnapAlgorithm.getLastSplitTarget().position |
Jorim Jaggi | e435e98 | 2015-12-30 13:54:32 +0100 | [diff] [blame] | 907 | && dockSideTopLeft(dockSide)) { |
| 908 | dismissTarget = mSnapAlgorithm.getDismissStartTarget(); |
| 909 | splitTarget = mSnapAlgorithm.getFirstSplitTarget(); |
Jorim Jaggi | 8dccd23 | 2016-03-25 18:10:14 -0700 | [diff] [blame] | 910 | start = taskPosition; |
| 911 | } else if (position >= mSnapAlgorithm.getLastSplitTarget().position |
Jorim Jaggi | e435e98 | 2015-12-30 13:54:32 +0100 | [diff] [blame] | 912 | && dockSideBottomRight(dockSide)) { |
| 913 | dismissTarget = mSnapAlgorithm.getDismissEndTarget(); |
| 914 | splitTarget = mSnapAlgorithm.getLastSplitTarget(); |
Jorim Jaggi | 8dccd23 | 2016-03-25 18:10:14 -0700 | [diff] [blame] | 915 | start = splitTarget.position; |
Jorim Jaggi | e435e98 | 2015-12-30 13:54:32 +0100 | [diff] [blame] | 916 | } |
| 917 | if (dismissTarget != null && fraction > 0f |
| 918 | && isDismissing(splitTarget, position, dockSide)) { |
Jorim Jaggi | 1b12ef5 | 2016-01-29 16:49:55 -0800 | [diff] [blame] | 919 | fraction = calculateParallaxDismissingFraction(fraction, dockSide); |
Jorim Jaggi | 8dccd23 | 2016-03-25 18:10:14 -0700 | [diff] [blame] | 920 | int offsetPosition = (int) (start + |
Jorim Jaggi | e435e98 | 2015-12-30 13:54:32 +0100 | [diff] [blame] | 921 | fraction * (dismissTarget.position - splitTarget.position)); |
| 922 | int width = taskRect.width(); |
| 923 | int height = taskRect.height(); |
| 924 | switch (dockSide) { |
| 925 | case WindowManager.DOCKED_LEFT: |
| 926 | taskRect.left = offsetPosition - width; |
| 927 | taskRect.right = offsetPosition; |
| 928 | break; |
| 929 | case WindowManager.DOCKED_RIGHT: |
| 930 | taskRect.left = offsetPosition + mDividerSize; |
| 931 | taskRect.right = offsetPosition + width + mDividerSize; |
| 932 | break; |
| 933 | case WindowManager.DOCKED_TOP: |
| 934 | taskRect.top = offsetPosition - height; |
| 935 | taskRect.bottom = offsetPosition; |
| 936 | break; |
| 937 | case WindowManager.DOCKED_BOTTOM: |
| 938 | taskRect.top = offsetPosition + mDividerSize; |
| 939 | taskRect.bottom = offsetPosition + height + mDividerSize; |
| 940 | break; |
| 941 | } |
| 942 | } |
| 943 | } |
| 944 | |
| 945 | /** |
| 946 | * @return for a specified {@code fraction}, this returns an adjusted value that simulates a |
| 947 | * slowing down parallax effect |
| 948 | */ |
Jorim Jaggi | 1b12ef5 | 2016-01-29 16:49:55 -0800 | [diff] [blame] | 949 | private static float calculateParallaxDismissingFraction(float fraction, int dockSide) { |
| 950 | float result = SLOWDOWN_INTERPOLATOR.getInterpolation(fraction) / 3.5f; |
| 951 | |
| 952 | // Less parallax at the top, just because. |
| 953 | if (dockSide == WindowManager.DOCKED_TOP) { |
| 954 | result /= 2f; |
| 955 | } |
| 956 | return result; |
Jorim Jaggi | e435e98 | 2015-12-30 13:54:32 +0100 | [diff] [blame] | 957 | } |
| 958 | |
| 959 | private static boolean isDismissing(SnapTarget snapTarget, int position, int dockSide) { |
| 960 | if (dockSide == WindowManager.DOCKED_TOP || dockSide == WindowManager.DOCKED_LEFT) { |
| 961 | return position < snapTarget.position; |
| 962 | } else { |
| 963 | return position > snapTarget.position; |
| 964 | } |
| 965 | } |
| 966 | |
Jorim Jaggi | 5098159 | 2015-12-29 17:54:12 +0100 | [diff] [blame] | 967 | private int getStackIdForDismissTarget(SnapTarget dismissTarget) { |
Jorim Jaggi | 8dccd23 | 2016-03-25 18:10:14 -0700 | [diff] [blame] | 968 | if ((dismissTarget.flag == SnapTarget.FLAG_DISMISS_START && dockSideTopLeft(mDockSide)) |
| 969 | || (dismissTarget.flag == SnapTarget.FLAG_DISMISS_END |
| 970 | && dockSideBottomRight(mDockSide))) { |
Jorim Jaggi | 5098159 | 2015-12-29 17:54:12 +0100 | [diff] [blame] | 971 | return StackId.DOCKED_STACK_ID; |
| 972 | } else { |
Jorim Jaggi | 8dccd23 | 2016-03-25 18:10:14 -0700 | [diff] [blame] | 973 | return StackId.HOME_STACK_ID; |
Jorim Jaggi | 5098159 | 2015-12-29 17:54:12 +0100 | [diff] [blame] | 974 | } |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 975 | } |
| 976 | |
Jorim Jaggi | e435e98 | 2015-12-30 13:54:32 +0100 | [diff] [blame] | 977 | /** |
| 978 | * @return true if and only if {@code dockSide} is top or left |
| 979 | */ |
| 980 | private static boolean dockSideTopLeft(int dockSide) { |
| 981 | return dockSide == WindowManager.DOCKED_TOP || dockSide == WindowManager.DOCKED_LEFT; |
| 982 | } |
| 983 | |
| 984 | /** |
| 985 | * @return true if and only if {@code dockSide} is bottom or right |
| 986 | */ |
| 987 | private static boolean dockSideBottomRight(int dockSide) { |
| 988 | return dockSide == WindowManager.DOCKED_BOTTOM || dockSide == WindowManager.DOCKED_RIGHT; |
| 989 | } |
| 990 | |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 991 | @Override |
| 992 | public void onComputeInternalInsets(InternalInsetsInfo inoutInfo) { |
| 993 | inoutInfo.setTouchableInsets(InternalInsetsInfo.TOUCHABLE_INSETS_REGION); |
| 994 | inoutInfo.touchableRegion.set(mHandle.getLeft(), mHandle.getTop(), mHandle.getRight(), |
| 995 | mHandle.getBottom()); |
| 996 | inoutInfo.touchableRegion.op(mBackground.getLeft(), mBackground.getTop(), |
| 997 | mBackground.getRight(), mBackground.getBottom(), Op.UNION); |
| 998 | } |
Jorim Jaggi | 11cc01d | 2016-01-22 19:39:23 -0800 | [diff] [blame] | 999 | |
Jorim Jaggi | cdb06ca | 2016-01-25 19:15:12 -0800 | [diff] [blame] | 1000 | public final void onBusEvent(RecentsActivityStartingEvent recentsActivityStartingEvent) { |
| 1001 | if (mGrowRecents && getWindowManagerProxy().getDockSide() == WindowManager.DOCKED_TOP |
| 1002 | && getCurrentPosition() == getSnapAlgorithm().getLastSplitTarget().position) { |
| 1003 | mGrowAfterRecentsDrawn = true; |
| 1004 | startDragging(false /* animate */, false /* touching */); |
| 1005 | } |
| 1006 | } |
| 1007 | |
Jorim Jaggi | 899327f | 2016-02-25 20:44:18 -0500 | [diff] [blame] | 1008 | public final void onBusEvent(DockedTopTaskEvent event) { |
| 1009 | if (event.dragMode == NavigationBarGestureHelper.DRAG_MODE_NONE) { |
Jorim Jaggi | cdb06ca | 2016-01-25 19:15:12 -0800 | [diff] [blame] | 1010 | mGrowAfterRecentsDrawn = false; |
| 1011 | mAnimateAfterRecentsDrawn = true; |
| 1012 | startDragging(false /* animate */, false /* touching */); |
| 1013 | } |
Jorim Jaggi | 899327f | 2016-02-25 20:44:18 -0500 | [diff] [blame] | 1014 | updateDockSide(); |
| 1015 | int position = DockedDividerUtils.calculatePositionForBounds(event.initialRect, |
| 1016 | mDockSide, mDividerSize); |
| 1017 | mEntranceAnimationRunning = true; |
| 1018 | resizeStack(position, mSnapAlgorithm.getMiddleTarget().position, |
| 1019 | mSnapAlgorithm.getMiddleTarget()); |
Winson | d87e9a4 | 2016-04-11 12:57:31 -0700 | [diff] [blame] | 1020 | |
| 1021 | // Vibrate after docking |
| 1022 | performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); |
Jorim Jaggi | 11cc01d | 2016-01-22 19:39:23 -0800 | [diff] [blame] | 1023 | } |
| 1024 | |
| 1025 | public final void onBusEvent(RecentsDrawnEvent drawnEvent) { |
| 1026 | if (mAnimateAfterRecentsDrawn) { |
| 1027 | mAnimateAfterRecentsDrawn = false; |
Jorim Jaggi | 9511b0f | 2016-01-29 19:12:44 -0800 | [diff] [blame] | 1028 | updateDockSide(); |
Jorim Jaggi | 545c5c2 | 2016-04-12 18:59:45 -0700 | [diff] [blame] | 1029 | |
| 1030 | // Delay switching resizing mode because this might cause jank in recents animation |
| 1031 | // that's long than this animation. |
| 1032 | stopDragging(getCurrentPosition(), mSnapAlgorithm.getMiddleTarget(), |
Jorim Jaggi | e370e15 | 2016-04-15 14:13:33 -0700 | [diff] [blame^] | 1033 | mLongPressEntraceAnimDuration, Interpolators.FAST_OUT_SLOW_IN, |
| 1034 | 200 /* endDelay */); |
Jorim Jaggi | 11cc01d | 2016-01-22 19:39:23 -0800 | [diff] [blame] | 1035 | } |
Jorim Jaggi | cdb06ca | 2016-01-25 19:15:12 -0800 | [diff] [blame] | 1036 | if (mGrowAfterRecentsDrawn) { |
| 1037 | mGrowAfterRecentsDrawn = false; |
Jorim Jaggi | 9511b0f | 2016-01-29 19:12:44 -0800 | [diff] [blame] | 1038 | updateDockSide(); |
Jorim Jaggi | cdb06ca | 2016-01-25 19:15:12 -0800 | [diff] [blame] | 1039 | stopDragging(getCurrentPosition(), mSnapAlgorithm.getMiddleTarget(), 250, |
Jorim Jaggi | 545c5c2 | 2016-04-12 18:59:45 -0700 | [diff] [blame] | 1040 | Interpolators.FAST_OUT_SLOW_IN); |
Jorim Jaggi | ea4a19f | 2016-02-03 21:31:27 -0800 | [diff] [blame] | 1041 | } |
| 1042 | } |
| 1043 | |
| 1044 | public final void onBusEvent(UndockingTaskEvent undockingTaskEvent) { |
| 1045 | int dockSide = mWindowManagerProxy.getDockSide(); |
Jorim Jaggi | ef92d6f | 2016-03-25 22:07:16 -0700 | [diff] [blame] | 1046 | if (dockSide != WindowManager.DOCKED_INVALID && !mDockedStackMinimized) { |
Jorim Jaggi | ea4a19f | 2016-02-03 21:31:27 -0800 | [diff] [blame] | 1047 | startDragging(false /* animate */, false /* touching */); |
| 1048 | SnapTarget target = dockSideTopLeft(dockSide) |
| 1049 | ? mSnapAlgorithm.getDismissEndTarget() |
| 1050 | : mSnapAlgorithm.getDismissStartTarget(); |
| 1051 | |
| 1052 | // Don't start immediately - give a little bit time to settle the drag resize change. |
Jorim Jaggi | 47ee9ad | 2016-04-11 21:51:11 -0700 | [diff] [blame] | 1053 | mExitAnimationRunning = true; |
| 1054 | mExitStartPosition = getCurrentPosition(); |
| 1055 | stopDragging(mExitStartPosition, target, 336 /* duration */, 100 /* startDelay */, |
Jorim Jaggi | 545c5c2 | 2016-04-12 18:59:45 -0700 | [diff] [blame] | 1056 | 0 /* endDelay */, Interpolators.FAST_OUT_SLOW_IN); |
Winson | d87e9a4 | 2016-04-11 12:57:31 -0700 | [diff] [blame] | 1057 | |
| 1058 | // Vibrate after undocking |
| 1059 | performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); |
Jorim Jaggi | cdb06ca | 2016-01-25 19:15:12 -0800 | [diff] [blame] | 1060 | } |
Jorim Jaggi | 11cc01d | 2016-01-22 19:39:23 -0800 | [diff] [blame] | 1061 | } |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 1062 | } |