Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 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.server.wm; |
| 18 | |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 19 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_DRAG; |
| 20 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION; |
| 21 | import static com.android.server.wm.WindowManagerDebugConfig.SHOW_LIGHT_TRANSACTIONS; |
| 22 | import static com.android.server.wm.WindowManagerDebugConfig.SHOW_TRANSACTIONS; |
| 23 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 24 | |
| 25 | import android.content.ClipData; |
| 26 | import android.content.ClipDescription; |
Vladislav Kaznacheev | da2f194 | 2016-02-11 18:58:41 -0800 | [diff] [blame] | 27 | import android.content.Context; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 28 | import android.graphics.Matrix; |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 29 | import android.graphics.Point; |
Vladislav Kaznacheev | ba76112 | 2016-01-22 12:09:45 -0800 | [diff] [blame] | 30 | import android.hardware.input.InputManager; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 31 | import android.os.IBinder; |
| 32 | import android.os.Message; |
| 33 | import android.os.Process; |
| 34 | import android.os.RemoteException; |
Vladislav Kaznacheev | da2f194 | 2016-02-11 18:58:41 -0800 | [diff] [blame] | 35 | import android.os.ServiceManager; |
| 36 | import android.os.UserHandle; |
| 37 | import android.os.UserManager; |
| 38 | import android.os.IUserManager; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 39 | import android.util.Slog; |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 40 | import android.view.Display; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 41 | import android.view.DragEvent; |
| 42 | import android.view.InputChannel; |
Vladislav Kaznacheev | ba76112 | 2016-01-22 12:09:45 -0800 | [diff] [blame] | 43 | import android.view.InputDevice; |
| 44 | import android.view.PointerIcon; |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 45 | import android.view.SurfaceControl; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 46 | import android.view.View; |
| 47 | import android.view.WindowManager; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 48 | import android.view.animation.AlphaAnimation; |
| 49 | import android.view.animation.Animation; |
| 50 | import android.view.animation.AnimationSet; |
| 51 | import android.view.animation.DecelerateInterpolator; |
| 52 | import android.view.animation.Interpolator; |
| 53 | import android.view.animation.ScaleAnimation; |
| 54 | import android.view.animation.Transformation; |
| 55 | import android.view.animation.TranslateAnimation; |
| 56 | |
| 57 | import com.android.server.input.InputApplicationHandle; |
| 58 | import com.android.server.input.InputWindowHandle; |
| 59 | import com.android.server.wm.WindowManagerService.DragInputEventReceiver; |
| 60 | import com.android.server.wm.WindowManagerService.H; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 61 | |
Vladislav Kaznacheev | 9149d2b | 2015-12-15 12:16:28 -0800 | [diff] [blame] | 62 | import com.android.internal.view.IDropPermissions; |
| 63 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 64 | import java.util.ArrayList; |
| 65 | |
| 66 | /** |
| 67 | * Drag/drop state |
| 68 | */ |
| 69 | class DragState { |
Vladislav Kaznacheev | 8b6f38c | 2015-11-19 16:00:28 -0800 | [diff] [blame] | 70 | private static final long ANIMATION_DURATION_MS = 500; |
| 71 | |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 72 | private static final int DRAG_FLAGS_URI_ACCESS = View.DRAG_FLAG_GLOBAL_URI_READ | |
| 73 | View.DRAG_FLAG_GLOBAL_URI_WRITE; |
| 74 | |
| 75 | private static final int DRAG_FLAGS_URI_PERMISSIONS = DRAG_FLAGS_URI_ACCESS | |
| 76 | View.DRAG_FLAG_GLOBAL_PERSISTABLE_URI_PERMISSION | |
| 77 | View.DRAG_FLAG_GLOBAL_PREFIX_URI_PERMISSION; |
| 78 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 79 | final WindowManagerService mService; |
| 80 | IBinder mToken; |
Mathias Agopian | 29479eb | 2013-02-14 14:36:04 -0800 | [diff] [blame] | 81 | SurfaceControl mSurfaceControl; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 82 | int mFlags; |
| 83 | IBinder mLocalWin; |
Vladislav Kaznacheev | c748241 | 2015-11-05 14:03:07 -0800 | [diff] [blame] | 84 | int mPid; |
Vladislav Kaznacheev | ede5f54 | 2015-07-15 18:04:04 -0700 | [diff] [blame] | 85 | int mUid; |
Vladislav Kaznacheev | da2f194 | 2016-02-11 18:58:41 -0800 | [diff] [blame] | 86 | int mSourceUserId; |
| 87 | boolean mCrossProfileCopyAllowed; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 88 | ClipData mData; |
| 89 | ClipDescription mDataDescription; |
Vladislav Kaznacheev | ba76112 | 2016-01-22 12:09:45 -0800 | [diff] [blame] | 90 | int mTouchSource; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 91 | boolean mDragResult; |
Vladislav Kaznacheev | 8b6f38c | 2015-11-19 16:00:28 -0800 | [diff] [blame] | 92 | float mOriginalAlpha; |
| 93 | float mOriginalX, mOriginalY; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 94 | float mCurrentX, mCurrentY; |
| 95 | float mThumbOffsetX, mThumbOffsetY; |
| 96 | InputChannel mServerChannel, mClientChannel; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 97 | DragInputEventReceiver mInputEventReceiver; |
Jeff Brown | ea42655 | 2011-07-18 16:53:48 -0700 | [diff] [blame] | 98 | InputApplicationHandle mDragApplicationHandle; |
| 99 | InputWindowHandle mDragWindowHandle; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 100 | WindowState mTargetWindow; |
| 101 | ArrayList<WindowState> mNotifiedWindows; |
| 102 | boolean mDragInProgress; |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 103 | DisplayContent mDisplayContent; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 104 | |
Vladislav Kaznacheev | 8b6f38c | 2015-11-19 16:00:28 -0800 | [diff] [blame] | 105 | private Animation mAnimation; |
| 106 | final Transformation mTransformation = new Transformation(); |
| 107 | private final Interpolator mCubicEaseOutInterpolator = new DecelerateInterpolator(1.5f); |
| 108 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 109 | DragState(WindowManagerService service, IBinder token, SurfaceControl surface, |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 110 | int flags, IBinder localWin) { |
| 111 | mService = service; |
| 112 | mToken = token; |
Mathias Agopian | 29479eb | 2013-02-14 14:36:04 -0800 | [diff] [blame] | 113 | mSurfaceControl = surface; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 114 | mFlags = flags; |
| 115 | mLocalWin = localWin; |
| 116 | mNotifiedWindows = new ArrayList<WindowState>(); |
| 117 | } |
| 118 | |
| 119 | void reset() { |
Mathias Agopian | 29479eb | 2013-02-14 14:36:04 -0800 | [diff] [blame] | 120 | if (mSurfaceControl != null) { |
| 121 | mSurfaceControl.destroy(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 122 | } |
Mathias Agopian | 29479eb | 2013-02-14 14:36:04 -0800 | [diff] [blame] | 123 | mSurfaceControl = null; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 124 | mFlags = 0; |
| 125 | mLocalWin = null; |
| 126 | mToken = null; |
| 127 | mData = null; |
| 128 | mThumbOffsetX = mThumbOffsetY = 0; |
| 129 | mNotifiedWindows = null; |
| 130 | } |
| 131 | |
Craig Mautner | 3486b96 | 2012-08-27 11:31:24 -0700 | [diff] [blame] | 132 | /** |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 133 | * @param display The Display that the window being dragged is on. |
Craig Mautner | 3486b96 | 2012-08-27 11:31:24 -0700 | [diff] [blame] | 134 | */ |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 135 | void register(Display display) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 136 | if (DEBUG_DRAG) Slog.d(TAG_WM, "registering drag input channel"); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 137 | if (mClientChannel != null) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 138 | Slog.e(TAG_WM, "Duplicate register of drag input channel"); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 139 | } else { |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 140 | mDisplayContent = mService.getDisplayContentLocked(display.getDisplayId()); |
| 141 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 142 | InputChannel[] channels = InputChannel.openInputChannelPair("drag"); |
| 143 | mServerChannel = channels[0]; |
| 144 | mClientChannel = channels[1]; |
| 145 | mService.mInputManager.registerInputChannel(mServerChannel, null); |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 146 | mInputEventReceiver = mService.new DragInputEventReceiver(mClientChannel, |
| 147 | mService.mH.getLooper()); |
Jeff Brown | ea42655 | 2011-07-18 16:53:48 -0700 | [diff] [blame] | 148 | |
| 149 | mDragApplicationHandle = new InputApplicationHandle(null); |
| 150 | mDragApplicationHandle.name = "drag"; |
| 151 | mDragApplicationHandle.dispatchingTimeoutNanos = |
| 152 | WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; |
| 153 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 154 | mDragWindowHandle = new InputWindowHandle(mDragApplicationHandle, null, |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 155 | display.getDisplayId()); |
Jeff Brown | ea42655 | 2011-07-18 16:53:48 -0700 | [diff] [blame] | 156 | mDragWindowHandle.name = "drag"; |
| 157 | mDragWindowHandle.inputChannel = mServerChannel; |
| 158 | mDragWindowHandle.layer = getDragLayerLw(); |
| 159 | mDragWindowHandle.layoutParamsFlags = 0; |
| 160 | mDragWindowHandle.layoutParamsType = WindowManager.LayoutParams.TYPE_DRAG; |
| 161 | mDragWindowHandle.dispatchingTimeoutNanos = |
| 162 | WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; |
| 163 | mDragWindowHandle.visible = true; |
| 164 | mDragWindowHandle.canReceiveKeys = false; |
| 165 | mDragWindowHandle.hasFocus = true; |
| 166 | mDragWindowHandle.hasWallpaper = false; |
| 167 | mDragWindowHandle.paused = false; |
| 168 | mDragWindowHandle.ownerPid = Process.myPid(); |
| 169 | mDragWindowHandle.ownerUid = Process.myUid(); |
| 170 | mDragWindowHandle.inputFeatures = 0; |
| 171 | mDragWindowHandle.scaleFactor = 1.0f; |
| 172 | |
| 173 | // The drag window cannot receive new touches. |
| 174 | mDragWindowHandle.touchableRegion.setEmpty(); |
| 175 | |
| 176 | // The drag window covers the entire display |
| 177 | mDragWindowHandle.frameLeft = 0; |
| 178 | mDragWindowHandle.frameTop = 0; |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 179 | Point p = new Point(); |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 180 | display.getRealSize(p); |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 181 | mDragWindowHandle.frameRight = p.x; |
| 182 | mDragWindowHandle.frameBottom = p.y; |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 183 | |
| 184 | // Pause rotations before a drag. |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 185 | if (DEBUG_ORIENTATION) { |
| 186 | Slog.d(TAG_WM, "Pausing rotation during drag"); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 187 | } |
| 188 | mService.pauseRotationLocked(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 189 | } |
| 190 | } |
| 191 | |
| 192 | void unregister() { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 193 | if (DEBUG_DRAG) Slog.d(TAG_WM, "unregistering drag input channel"); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 194 | if (mClientChannel == null) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 195 | Slog.e(TAG_WM, "Unregister of nonexistent drag input channel"); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 196 | } else { |
| 197 | mService.mInputManager.unregisterInputChannel(mServerChannel); |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 198 | mInputEventReceiver.dispose(); |
| 199 | mInputEventReceiver = null; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 200 | mClientChannel.dispose(); |
| 201 | mServerChannel.dispose(); |
| 202 | mClientChannel = null; |
| 203 | mServerChannel = null; |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 204 | |
| 205 | mDragWindowHandle = null; |
| 206 | mDragApplicationHandle = null; |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 207 | |
| 208 | // Resume rotations after a drag. |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 209 | if (DEBUG_ORIENTATION) { |
| 210 | Slog.d(TAG_WM, "Resuming rotation after drag"); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 211 | } |
| 212 | mService.resumeRotationLocked(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 213 | } |
| 214 | } |
| 215 | |
| 216 | int getDragLayerLw() { |
| 217 | return mService.mPolicy.windowTypeToLayerLw(WindowManager.LayoutParams.TYPE_DRAG) |
| 218 | * WindowManagerService.TYPE_LAYER_MULTIPLIER |
| 219 | + WindowManagerService.TYPE_LAYER_OFFSET; |
| 220 | } |
| 221 | |
| 222 | /* call out to each visible window/session informing it about the drag |
| 223 | */ |
| 224 | void broadcastDragStartedLw(final float touchX, final float touchY) { |
Vladislav Kaznacheev | 8b6f38c | 2015-11-19 16:00:28 -0800 | [diff] [blame] | 225 | mOriginalX = mCurrentX = touchX; |
| 226 | mOriginalY = mCurrentY = touchY; |
| 227 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 228 | // Cache a base-class instance of the clip metadata so that parceling |
| 229 | // works correctly in calling out to the apps. |
| 230 | mDataDescription = (mData != null) ? mData.getDescription() : null; |
| 231 | mNotifiedWindows.clear(); |
| 232 | mDragInProgress = true; |
| 233 | |
Vladislav Kaznacheev | da2f194 | 2016-02-11 18:58:41 -0800 | [diff] [blame] | 234 | mSourceUserId = UserHandle.getUserId(mUid); |
| 235 | |
| 236 | final IUserManager userManager = |
| 237 | (IUserManager) ServiceManager.getService(Context.USER_SERVICE); |
| 238 | try { |
| 239 | mCrossProfileCopyAllowed = !userManager.getUserRestrictions(mSourceUserId).getBoolean( |
| 240 | UserManager.DISALLOW_CROSS_PROFILE_COPY_PASTE); |
| 241 | } catch (RemoteException e) { |
| 242 | Slog.e(TAG_WM, "Remote Exception calling UserManager: " + e); |
| 243 | mCrossProfileCopyAllowed = false; |
| 244 | } |
| 245 | |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 246 | if (DEBUG_DRAG) { |
| 247 | Slog.d(TAG_WM, "broadcasting DRAG_STARTED at (" + touchX + ", " + touchY + ")"); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 248 | } |
| 249 | |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 250 | final WindowList windows = mDisplayContent.getWindowList(); |
| 251 | final int N = windows.size(); |
| 252 | for (int i = 0; i < N; i++) { |
| 253 | sendDragStartedLw(windows.get(i), touchX, touchY, mDataDescription); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 254 | } |
| 255 | } |
| 256 | |
Vladislav Kaznacheev | da2f194 | 2016-02-11 18:58:41 -0800 | [diff] [blame] | 257 | /* helper - send a ACTION_DRAG_STARTED event, if the |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 258 | * designated window is potentially a drop recipient. There are race situations |
| 259 | * around DRAG_ENDED broadcast, so we make sure that once we've declared that |
| 260 | * the drag has ended, we never send out another DRAG_STARTED for this drag action. |
| 261 | * |
| 262 | * This method clones the 'event' parameter if it's being delivered to the same |
| 263 | * process, so it's safe for the caller to call recycle() on the event afterwards. |
| 264 | */ |
| 265 | private void sendDragStartedLw(WindowState newWin, float touchX, float touchY, |
| 266 | ClipDescription desc) { |
Vladislav Kaznacheev | da2f194 | 2016-02-11 18:58:41 -0800 | [diff] [blame] | 267 | if (mDragInProgress && isValidDropTarget(newWin)) { |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 268 | DragEvent event = obtainDragEvent(newWin, DragEvent.ACTION_DRAG_STARTED, |
Vladislav Kaznacheev | ede5f54 | 2015-07-15 18:04:04 -0700 | [diff] [blame] | 269 | touchX, touchY, null, desc, null, null, false); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 270 | try { |
| 271 | newWin.mClient.dispatchDragEvent(event); |
| 272 | // track each window that we've notified that the drag is starting |
| 273 | mNotifiedWindows.add(newWin); |
| 274 | } catch (RemoteException e) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 275 | Slog.w(TAG_WM, "Unable to drag-start window " + newWin); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 276 | } finally { |
| 277 | // if the callee was local, the dispatch has already recycled the event |
| 278 | if (Process.myPid() != newWin.mSession.mPid) { |
| 279 | event.recycle(); |
| 280 | } |
| 281 | } |
| 282 | } |
| 283 | } |
| 284 | |
Vladislav Kaznacheev | da2f194 | 2016-02-11 18:58:41 -0800 | [diff] [blame] | 285 | private boolean isValidDropTarget(WindowState targetWin) { |
| 286 | if (targetWin == null) { |
| 287 | return false; |
| 288 | } |
| 289 | if (!targetWin.isPotentialDragTarget()) { |
| 290 | return false; |
| 291 | } |
| 292 | if ((mFlags & View.DRAG_FLAG_GLOBAL) == 0) { |
| 293 | // Drag is limited to the current window. |
| 294 | if (mLocalWin != targetWin.mClient.asBinder()) { |
| 295 | return false; |
| 296 | } |
| 297 | } |
| 298 | |
| 299 | return mCrossProfileCopyAllowed || |
| 300 | mSourceUserId == UserHandle.getUserId(targetWin.getOwningUid()); |
| 301 | } |
| 302 | |
| 303 | /* helper - send a ACTION_DRAG_STARTED event only if the window has not |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 304 | * previously been notified, i.e. it became visible after the drag operation |
| 305 | * was begun. This is a rare case. |
| 306 | */ |
| 307 | void sendDragStartedIfNeededLw(WindowState newWin) { |
| 308 | if (mDragInProgress) { |
| 309 | // If we have sent the drag-started, we needn't do so again |
Vladislav Kaznacheev | da2f194 | 2016-02-11 18:58:41 -0800 | [diff] [blame] | 310 | if (isWindowNotified(newWin)) { |
| 311 | return; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 312 | } |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 313 | if (DEBUG_DRAG) { |
| 314 | Slog.d(TAG_WM, "need to send DRAG_STARTED to new window " + newWin); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 315 | } |
| 316 | sendDragStartedLw(newWin, mCurrentX, mCurrentY, mDataDescription); |
| 317 | } |
| 318 | } |
| 319 | |
Vladislav Kaznacheev | da2f194 | 2016-02-11 18:58:41 -0800 | [diff] [blame] | 320 | private boolean isWindowNotified(WindowState newWin) { |
| 321 | for (WindowState ws : mNotifiedWindows) { |
| 322 | if (ws == newWin) { |
| 323 | return true; |
| 324 | } |
| 325 | } |
| 326 | return false; |
| 327 | } |
| 328 | |
Vladislav Kaznacheev | a56b2b9 | 2015-11-20 18:30:21 -0800 | [diff] [blame] | 329 | private void broadcastDragEndedLw() { |
Vladislav Kaznacheev | 68dd2e8 | 2015-10-22 17:06:40 -0700 | [diff] [blame] | 330 | final int myPid = Process.myPid(); |
| 331 | |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 332 | if (DEBUG_DRAG) { |
| 333 | Slog.d(TAG_WM, "broadcasting DRAG_ENDED"); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 334 | } |
Vladislav Kaznacheev | 68dd2e8 | 2015-10-22 17:06:40 -0700 | [diff] [blame] | 335 | for (WindowState ws : mNotifiedWindows) { |
Vladislav Kaznacheev | c748241 | 2015-11-05 14:03:07 -0800 | [diff] [blame] | 336 | float x = 0; |
| 337 | float y = 0; |
| 338 | if (!mDragResult && (ws.mSession.mPid == mPid)) { |
| 339 | // Report unconsumed drop location back to the app that started the drag. |
| 340 | x = mCurrentX; |
| 341 | y = mCurrentY; |
| 342 | } |
Vladislav Kaznacheev | 68dd2e8 | 2015-10-22 17:06:40 -0700 | [diff] [blame] | 343 | DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_ENDED, |
Vladislav Kaznacheev | c748241 | 2015-11-05 14:03:07 -0800 | [diff] [blame] | 344 | x, y, null, null, null, null, mDragResult); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 345 | try { |
| 346 | ws.mClient.dispatchDragEvent(evt); |
| 347 | } catch (RemoteException e) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 348 | Slog.w(TAG_WM, "Unable to drag-end window " + ws); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 349 | } |
Vladislav Kaznacheev | 68dd2e8 | 2015-10-22 17:06:40 -0700 | [diff] [blame] | 350 | // if the current window is in the same process, |
| 351 | // the dispatch has already recycled the event |
| 352 | if (myPid != ws.mSession.mPid) { |
| 353 | evt.recycle(); |
| 354 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 355 | } |
| 356 | mNotifiedWindows.clear(); |
| 357 | mDragInProgress = false; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | void endDragLw() { |
Vladislav Kaznacheev | a56b2b9 | 2015-11-20 18:30:21 -0800 | [diff] [blame] | 361 | if (mAnimation != null) { |
| 362 | return; |
| 363 | } |
Vladislav Kaznacheev | 8b6f38c | 2015-11-19 16:00:28 -0800 | [diff] [blame] | 364 | if (!mDragResult) { |
| 365 | mAnimation = createReturnAnimationLocked(); |
| 366 | mService.scheduleAnimationLocked(); |
| 367 | return; // Will call cleanUpDragLw when the animation is done. |
| 368 | } |
| 369 | cleanUpDragLw(); |
| 370 | } |
| 371 | |
Vladislav Kaznacheev | ce2aef9 | 2015-11-20 18:49:59 -0800 | [diff] [blame] | 372 | void cancelDragLw() { |
| 373 | if (mAnimation != null) { |
| 374 | return; |
| 375 | } |
| 376 | mAnimation = createCancelAnimationLocked(); |
| 377 | mService.scheduleAnimationLocked(); |
| 378 | } |
Vladislav Kaznacheev | 8b6f38c | 2015-11-19 16:00:28 -0800 | [diff] [blame] | 379 | |
Vladislav Kaznacheev | a56b2b9 | 2015-11-20 18:30:21 -0800 | [diff] [blame] | 380 | private void cleanUpDragLw() { |
Vladislav Kaznacheev | 8b6f38c | 2015-11-19 16:00:28 -0800 | [diff] [blame] | 381 | broadcastDragEndedLw(); |
Vladislav Kaznacheev | 989b58a | 2016-02-10 12:19:33 -0800 | [diff] [blame] | 382 | if (isFromSource(InputDevice.SOURCE_MOUSE)) { |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 383 | mService.restorePointerIconLocked(mDisplayContent, mCurrentX, mCurrentY); |
Vladislav Kaznacheev | 989b58a | 2016-02-10 12:19:33 -0800 | [diff] [blame] | 384 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 385 | |
| 386 | // stop intercepting input |
Vladislav Kaznacheev | 8b6f38c | 2015-11-19 16:00:28 -0800 | [diff] [blame] | 387 | unregister(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 388 | |
| 389 | // free our resources and drop all the object references |
Vladislav Kaznacheev | 8b6f38c | 2015-11-19 16:00:28 -0800 | [diff] [blame] | 390 | reset(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 391 | mService.mDragState = null; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 392 | |
| 393 | mService.mInputMonitor.updateInputWindowsLw(true /*force*/); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | void notifyMoveLw(float x, float y) { |
Vladislav Kaznacheev | a56b2b9 | 2015-11-20 18:30:21 -0800 | [diff] [blame] | 397 | if (mAnimation != null) { |
| 398 | return; |
| 399 | } |
Vladislav Kaznacheev | 8b6f38c | 2015-11-19 16:00:28 -0800 | [diff] [blame] | 400 | mCurrentX = x; |
| 401 | mCurrentY = y; |
| 402 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 403 | // Move the surface to the given touch |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 404 | if (SHOW_LIGHT_TRANSACTIONS) Slog.i( |
| 405 | TAG_WM, ">>> OPEN TRANSACTION notifyMoveLw"); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 406 | SurfaceControl.openTransaction(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 407 | try { |
Mathias Agopian | 29479eb | 2013-02-14 14:36:04 -0800 | [diff] [blame] | 408 | mSurfaceControl.setPosition(x - mThumbOffsetX, y - mThumbOffsetY); |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 409 | if (SHOW_TRANSACTIONS) Slog.i(TAG_WM, " DRAG " |
Mathias Agopian | 29479eb | 2013-02-14 14:36:04 -0800 | [diff] [blame] | 410 | + mSurfaceControl + ": pos=(" + |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 411 | (int)(x - mThumbOffsetX) + "," + (int)(y - mThumbOffsetY) + ")"); |
| 412 | } finally { |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 413 | SurfaceControl.closeTransaction(); |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 414 | if (SHOW_LIGHT_TRANSACTIONS) Slog.i( |
| 415 | TAG_WM, "<<< CLOSE TRANSACTION notifyMoveLw"); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 416 | } |
Vladislav Kaznacheev | d0ed893 | 2016-01-15 15:37:05 -0800 | [diff] [blame] | 417 | notifyLocationLw(x, y); |
| 418 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 419 | |
Vladislav Kaznacheev | d0ed893 | 2016-01-15 15:37:05 -0800 | [diff] [blame] | 420 | void notifyLocationLw(float x, float y) { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 421 | // Tell the affected window |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 422 | WindowState touchedWin = mDisplayContent.getTouchableWinAtPointLocked(x, y); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 423 | if (touchedWin == null) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 424 | if (DEBUG_DRAG) Slog.d(TAG_WM, "No touched win at x=" + x + " y=" + y); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 425 | return; |
| 426 | } |
Vladislav Kaznacheev | da2f194 | 2016-02-11 18:58:41 -0800 | [diff] [blame] | 427 | |
| 428 | if (!isWindowNotified(touchedWin)) { |
| 429 | // The drag point is over a window which was not notified about a drag start. |
| 430 | // Pretend it's over empty space. |
| 431 | touchedWin = null; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 432 | } |
Vladislav Kaznacheev | da2f194 | 2016-02-11 18:58:41 -0800 | [diff] [blame] | 433 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 434 | try { |
Vladislav Kaznacheev | d0ed893 | 2016-01-15 15:37:05 -0800 | [diff] [blame] | 435 | final int myPid = Process.myPid(); |
| 436 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 437 | // have we dragged over a new window? |
| 438 | if ((touchedWin != mTargetWindow) && (mTargetWindow != null)) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 439 | if (DEBUG_DRAG) { |
| 440 | Slog.d(TAG_WM, "sending DRAG_EXITED to " + mTargetWindow); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 441 | } |
| 442 | // force DRAG_EXITED_EVENT if appropriate |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 443 | DragEvent evt = obtainDragEvent(mTargetWindow, DragEvent.ACTION_DRAG_EXITED, |
Vladislav Kaznacheev | cc010b2 | 2016-01-21 16:24:40 -0800 | [diff] [blame] | 444 | 0, 0, null, null, null, null, false); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 445 | mTargetWindow.mClient.dispatchDragEvent(evt); |
| 446 | if (myPid != mTargetWindow.mSession.mPid) { |
| 447 | evt.recycle(); |
| 448 | } |
| 449 | } |
| 450 | if (touchedWin != null) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 451 | if (false && DEBUG_DRAG) { |
| 452 | Slog.d(TAG_WM, "sending DRAG_LOCATION to " + touchedWin); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 453 | } |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 454 | DragEvent evt = obtainDragEvent(touchedWin, DragEvent.ACTION_DRAG_LOCATION, |
Vladislav Kaznacheev | ede5f54 | 2015-07-15 18:04:04 -0700 | [diff] [blame] | 455 | x, y, null, null, null, null, false); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 456 | touchedWin.mClient.dispatchDragEvent(evt); |
| 457 | if (myPid != touchedWin.mSession.mPid) { |
| 458 | evt.recycle(); |
| 459 | } |
| 460 | } |
| 461 | } catch (RemoteException e) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 462 | Slog.w(TAG_WM, "can't send drag notification to windows"); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 463 | } |
| 464 | mTargetWindow = touchedWin; |
| 465 | } |
| 466 | |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 467 | // Find the drop target and tell it about the data. Returns 'true' if we can immediately |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 468 | // dispatch the global drag-ended message, 'false' if we need to wait for a |
| 469 | // result from the recipient. |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 470 | boolean notifyDropLw(float x, float y) { |
Vladislav Kaznacheev | a56b2b9 | 2015-11-20 18:30:21 -0800 | [diff] [blame] | 471 | if (mAnimation != null) { |
| 472 | return false; |
| 473 | } |
Vladislav Kaznacheev | 8b6f38c | 2015-11-19 16:00:28 -0800 | [diff] [blame] | 474 | mCurrentX = x; |
| 475 | mCurrentY = y; |
| 476 | |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 477 | WindowState touchedWin = mDisplayContent.getTouchableWinAtPointLocked(x, y); |
| 478 | |
Vladislav Kaznacheev | da2f194 | 2016-02-11 18:58:41 -0800 | [diff] [blame] | 479 | if (!isWindowNotified(touchedWin)) { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 480 | // "drop" outside a valid window -- no recipient to apply a |
| 481 | // timeout to, and we can send the drag-ended message immediately. |
| 482 | mDragResult = false; |
| 483 | return true; |
| 484 | } |
| 485 | |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 486 | if (DEBUG_DRAG) { |
| 487 | Slog.d(TAG_WM, "sending DROP to " + touchedWin); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 488 | } |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 489 | |
| 490 | final int targetUserId = UserHandle.getUserId(touchedWin.getOwningUid()); |
| 491 | |
| 492 | DropPermissionsHandler dropPermissions = null; |
| 493 | if ((mFlags & View.DRAG_FLAG_GLOBAL) != 0 && |
| 494 | (mFlags & DRAG_FLAGS_URI_ACCESS) != 0) { |
| 495 | dropPermissions = new DropPermissionsHandler( |
| 496 | mData, |
| 497 | mUid, |
| 498 | touchedWin.getOwningPackage(), |
| 499 | mFlags & DRAG_FLAGS_URI_PERMISSIONS, |
| 500 | mSourceUserId, |
| 501 | targetUserId); |
| 502 | } |
| 503 | if (mSourceUserId != targetUserId){ |
Vladislav Kaznacheev | da2f194 | 2016-02-11 18:58:41 -0800 | [diff] [blame] | 504 | mData.fixUris(mSourceUserId); |
| 505 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 506 | final int myPid = Process.myPid(); |
| 507 | final IBinder token = touchedWin.mClient.asBinder(); |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 508 | DragEvent evt = obtainDragEvent(touchedWin, DragEvent.ACTION_DROP, x, y, |
Vladislav Kaznacheev | 9149d2b | 2015-12-15 12:16:28 -0800 | [diff] [blame] | 509 | null, null, mData, dropPermissions, false); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 510 | try { |
| 511 | touchedWin.mClient.dispatchDragEvent(evt); |
| 512 | |
| 513 | // 5 second timeout for this window to respond to the drop |
| 514 | mService.mH.removeMessages(H.DRAG_END_TIMEOUT, token); |
| 515 | Message msg = mService.mH.obtainMessage(H.DRAG_END_TIMEOUT, token); |
| 516 | mService.mH.sendMessageDelayed(msg, 5000); |
| 517 | } catch (RemoteException e) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 518 | Slog.w(TAG_WM, "can't send drop notification to win " + touchedWin); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 519 | return true; |
| 520 | } finally { |
| 521 | if (myPid != touchedWin.mSession.mPid) { |
| 522 | evt.recycle(); |
| 523 | } |
| 524 | } |
| 525 | mToken = token; |
| 526 | return false; |
| 527 | } |
| 528 | |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 529 | private static DragEvent obtainDragEvent(WindowState win, int action, |
| 530 | float x, float y, Object localState, |
Vladislav Kaznacheev | ede5f54 | 2015-07-15 18:04:04 -0700 | [diff] [blame] | 531 | ClipDescription description, ClipData data, |
Vladislav Kaznacheev | 9149d2b | 2015-12-15 12:16:28 -0800 | [diff] [blame] | 532 | IDropPermissions dropPermissions, |
Vladislav Kaznacheev | ede5f54 | 2015-07-15 18:04:04 -0700 | [diff] [blame] | 533 | boolean result) { |
Vladislav Kaznacheev | 989b58a | 2016-02-10 12:19:33 -0800 | [diff] [blame] | 534 | final float winX = win.translateToWindowX(x); |
| 535 | final float winY = win.translateToWindowY(y); |
Vladislav Kaznacheev | ede5f54 | 2015-07-15 18:04:04 -0700 | [diff] [blame] | 536 | return DragEvent.obtain(action, winX, winY, localState, description, data, |
Vladislav Kaznacheev | 9149d2b | 2015-12-15 12:16:28 -0800 | [diff] [blame] | 537 | dropPermissions, result); |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 538 | } |
Vladislav Kaznacheev | 8b6f38c | 2015-11-19 16:00:28 -0800 | [diff] [blame] | 539 | |
| 540 | boolean stepAnimationLocked(long currentTimeMs) { |
| 541 | if (mAnimation == null) { |
| 542 | return false; |
| 543 | } |
| 544 | |
| 545 | mTransformation.clear(); |
| 546 | if (!mAnimation.getTransformation(currentTimeMs, mTransformation)) { |
| 547 | cleanUpDragLw(); |
| 548 | return false; |
| 549 | } |
| 550 | |
Vladislav Kaznacheev | ce2aef9 | 2015-11-20 18:49:59 -0800 | [diff] [blame] | 551 | mTransformation.getMatrix().postTranslate( |
| 552 | mCurrentX - mThumbOffsetX, mCurrentY - mThumbOffsetY); |
Vladislav Kaznacheev | 8b6f38c | 2015-11-19 16:00:28 -0800 | [diff] [blame] | 553 | final float tmpFloats[] = mService.mTmpFloats; |
| 554 | mTransformation.getMatrix().getValues(tmpFloats); |
Vladislav Kaznacheev | ce2aef9 | 2015-11-20 18:49:59 -0800 | [diff] [blame] | 555 | mSurfaceControl.setPosition(tmpFloats[Matrix.MTRANS_X], tmpFloats[Matrix.MTRANS_Y]); |
Vladislav Kaznacheev | 8b6f38c | 2015-11-19 16:00:28 -0800 | [diff] [blame] | 556 | mSurfaceControl.setAlpha(mTransformation.getAlpha()); |
| 557 | mSurfaceControl.setMatrix(tmpFloats[Matrix.MSCALE_X], tmpFloats[Matrix.MSKEW_Y], |
| 558 | tmpFloats[Matrix.MSKEW_X], tmpFloats[Matrix.MSCALE_Y]); |
| 559 | return true; |
| 560 | } |
| 561 | |
| 562 | private Animation createReturnAnimationLocked() { |
| 563 | final AnimationSet set = new AnimationSet(false); |
| 564 | set.addAnimation(new TranslateAnimation( |
Vladislav Kaznacheev | ce2aef9 | 2015-11-20 18:49:59 -0800 | [diff] [blame] | 565 | 0, mOriginalX - mCurrentX, 0, mOriginalY - mCurrentY)); |
Vladislav Kaznacheev | 8b6f38c | 2015-11-19 16:00:28 -0800 | [diff] [blame] | 566 | set.addAnimation(new AlphaAnimation(mOriginalAlpha, mOriginalAlpha / 2)); |
| 567 | set.setDuration(ANIMATION_DURATION_MS); |
| 568 | set.setInterpolator(mCubicEaseOutInterpolator); |
| 569 | set.initialize(0, 0, 0, 0); |
| 570 | set.start(); // Will start on the first call to getTransformation. |
| 571 | return set; |
| 572 | } |
Vladislav Kaznacheev | ce2aef9 | 2015-11-20 18:49:59 -0800 | [diff] [blame] | 573 | |
| 574 | private Animation createCancelAnimationLocked() { |
| 575 | final AnimationSet set = new AnimationSet(false); |
| 576 | set.addAnimation(new ScaleAnimation(1, 0, 1, 0, mThumbOffsetX, mThumbOffsetY)); |
| 577 | set.addAnimation(new AlphaAnimation(mOriginalAlpha, 0)); |
| 578 | set.setDuration(ANIMATION_DURATION_MS); |
| 579 | set.setInterpolator(mCubicEaseOutInterpolator); |
| 580 | set.initialize(0, 0, 0, 0); |
| 581 | set.start(); // Will start on the first call to getTransformation. |
| 582 | return set; |
| 583 | } |
Vladislav Kaznacheev | ba76112 | 2016-01-22 12:09:45 -0800 | [diff] [blame] | 584 | |
| 585 | private boolean isFromSource(int source) { |
| 586 | return (mTouchSource & source) == source; |
| 587 | } |
| 588 | |
| 589 | void overridePointerIconLw(int touchSource) { |
| 590 | mTouchSource = touchSource; |
| 591 | if (isFromSource(InputDevice.SOURCE_MOUSE)) { |
| 592 | InputManager.getInstance().setPointerIconShape(PointerIcon.STYLE_GRAB); |
| 593 | } |
| 594 | } |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 595 | } |