Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chromoting; | 5 package org.chromium.chromoting; |
| 6 | 6 |
| 7 import android.content.Context; | 7 import android.content.Context; |
| 8 import android.graphics.Bitmap; | 8 import android.graphics.Bitmap; |
| 9 import android.graphics.Canvas; | 9 import android.graphics.Canvas; |
| 10 import android.graphics.Color; | 10 import android.graphics.Color; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 56 | 56 |
| 57 /** Specifies the dimension by which the zoom level is being lower-bounded. */ | 57 /** Specifies the dimension by which the zoom level is being lower-bounded. */ |
| 58 private Constraint mConstraint; | 58 private Constraint mConstraint; |
| 59 | 59 |
| 60 /** Whether the right edge of the image was visible on-screen during the las t render. */ | 60 /** Whether the right edge of the image was visible on-screen during the las t render. */ |
| 61 private boolean mRightUsedToBeOut; | 61 private boolean mRightUsedToBeOut; |
| 62 | 62 |
| 63 /** Whether the bottom edge of the image was visible on-screen during the la st render. */ | 63 /** Whether the bottom edge of the image was visible on-screen during the la st render. */ |
| 64 private boolean mBottomUsedToBeOut; | 64 private boolean mBottomUsedToBeOut; |
| 65 | 65 |
| 66 private int mMouseButton; | |
| 67 | |
| 66 /** Whether the device has just been rotated, necessitating a canvas redraw. */ | 68 /** Whether the device has just been rotated, necessitating a canvas redraw. */ |
| 67 private boolean mJustRotated; | 69 private boolean mJustRotated; |
| 68 | 70 |
| 69 public DesktopView(Context context) { | 71 public DesktopView(Context context) { |
| 70 super(context); | 72 super(context); |
| 71 getHolder().addCallback(this); | 73 getHolder().addCallback(this); |
| 72 DesktopListener listener = new DesktopListener(); | 74 DesktopListener listener = new DesktopListener(); |
| 73 mScroller = new GestureDetector(context, listener); | 75 mScroller = new GestureDetector(context, listener); |
| 74 mZoomer = new ScaleGestureDetector(context, listener); | 76 mZoomer = new ScaleGestureDetector(context, listener); |
| 75 | 77 |
| 76 mTransform = new Matrix(); | 78 mTransform = new Matrix(); |
| 77 mScreenWidth = 0; | 79 mScreenWidth = 0; |
| 78 mScreenHeight = 0; | 80 mScreenHeight = 0; |
| 79 mConstraint = Constraint.UNDEFINED; | 81 mConstraint = Constraint.UNDEFINED; |
| 80 | 82 |
| 81 mRightUsedToBeOut = false; | 83 mRightUsedToBeOut = false; |
| 82 mBottomUsedToBeOut = false; | 84 mBottomUsedToBeOut = false; |
| 83 | 85 |
| 86 mMouseButton = 0; | |
| 87 | |
| 84 mJustRotated = false; | 88 mJustRotated = false; |
| 85 } | 89 } |
| 86 | 90 |
| 87 /** | 91 /** |
| 88 * Redraws the canvas. This should be done on a non-UI thread or it could | 92 * Redraws the canvas. This should be done on a non-UI thread or it could |
| 89 * cause the UI to lag. Specifically, it is currently invoked on the native | 93 * cause the UI to lag. Specifically, it is currently invoked on the native |
| 90 * graphics thread using a JNI. | 94 * graphics thread using a JNI. |
| 91 */ | 95 */ |
| 92 @Override | 96 @Override |
| 93 public void run() { | 97 public void run() { |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 212 Log.i("deskview", "DesktopView.surfaceCreated(...)"); | 216 Log.i("deskview", "DesktopView.surfaceCreated(...)"); |
| 213 JniInterface.provideRedrawCallback(this); | 217 JniInterface.provideRedrawCallback(this); |
| 214 } | 218 } |
| 215 | 219 |
| 216 /** Called when the canvas is finally destroyed. */ | 220 /** Called when the canvas is finally destroyed. */ |
| 217 @Override | 221 @Override |
| 218 public void surfaceDestroyed(SurfaceHolder holder) { | 222 public void surfaceDestroyed(SurfaceHolder holder) { |
| 219 Log.i("deskview", "DesktopView.surfaceDestroyed(...)"); | 223 Log.i("deskview", "DesktopView.surfaceDestroyed(...)"); |
| 220 } | 224 } |
| 221 | 225 |
| 226 /** Called when a mouse action is made. */ | |
| 227 private void handleMouseMovement(float[] coordinates, int button) { | |
| 228 // Coordinates are relative to the canvas, but we need image coordinates . | |
| 229 Matrix canvasToImage = new Matrix(); | |
| 230 mTransform.invert(canvasToImage); | |
| 231 canvasToImage.mapPoints(coordinates); | |
| 232 | |
| 233 // Coordinates are now relative to the image, so transmit them to the ho st. | |
| 234 JniInterface.mouseAction((int)coordinates[0], (int)coordinates[1], butto n); | |
| 235 } | |
| 236 | |
| 222 /** | 237 /** |
| 223 * Called whenever the user attempts to touch the canvas. Forwards such | 238 * Called whenever the user attempts to touch the canvas. Forwards such |
| 224 * events to the appropriate gesture detector until one accepts them. | 239 * events to the appropriate gesture detector until one accepts them. |
| 225 */ | 240 */ |
| 226 @Override | 241 @Override |
| 227 public boolean onTouchEvent(MotionEvent event) { | 242 public boolean onTouchEvent(MotionEvent event) { |
| 228 return mScroller.onTouchEvent(event) || mZoomer.onTouchEvent(event); | 243 boolean handled = mScroller.onTouchEvent(event) || mZoomer.onTouchEvent( event); |
| 244 | |
| 245 if (event.getPointerCount()==1) { | |
| 246 float[] coordinates = {event.getRawX(), event.getY()}; | |
| 247 | |
| 248 switch (event.getActionMasked()) { | |
| 249 case MotionEvent.ACTION_DOWN: | |
| 250 Log.i("gesture", "Down..."); | |
| 251 mMouseButton = 0; | |
| 252 break; | |
| 253 | |
| 254 case MotionEvent.ACTION_MOVE: | |
| 255 if (mMouseButton==0) { | |
| 256 Log.i("gesture", "Moving 1"); | |
| 257 mMouseButton = 1; // TODO Name me! | |
|
solb
2013/07/22 19:13:48
Sorry; I had forgotten how rough this revision was
| |
| 258 } | |
| 259 else Log.i("gesture", "Moving " + mMouseButton); | |
| 260 break; | |
| 261 | |
| 262 case MotionEvent.ACTION_UP: | |
| 263 if (mMouseButton==0) { | |
| 264 Log.i("gesture", "Releasing 1 (after press)"); | |
| 265 handleMouseMovement(coordinates, 1); // TODO Name me! | |
| 266 mMouseButton = -1; // TODO Name me! | |
| 267 } | |
| 268 else if (mMouseButton > 0) { | |
| 269 Log.i("gesture", "Releasing " + mMouseButton); | |
| 270 mMouseButton *= -1; | |
| 271 } | |
| 272 else { | |
| 273 Log.w("gesture", "Button already in released state befor e gesture ended"); | |
| 274 } | |
| 275 break; | |
| 276 | |
| 277 default: | |
| 278 return handled; | |
| 279 } | |
| 280 handleMouseMovement(coordinates, mMouseButton); | |
| 281 | |
| 282 return true; | |
| 283 } | |
| 284 | |
| 285 return handled; | |
| 229 } | 286 } |
| 230 | 287 |
| 231 /** Responds to touch events filtered by the gesture detectors. */ | 288 /** Responds to touch events filtered by the gesture detectors. */ |
| 232 private class DesktopListener extends GestureDetector.SimpleOnGestureListene r | 289 private class DesktopListener extends GestureDetector.SimpleOnGestureListene r |
| 233 implements ScaleGestureDetector.OnScaleGestureListener { | 290 implements ScaleGestureDetector.OnScaleGestureListener { |
| 234 /** | 291 /** |
| 235 * Called when the user is scrolling. We refuse to accept or process the event unless it | 292 * Called when the user is scrolling. We refuse to accept or process the event unless it |
| 236 * is being performed with 2 or more touch points, in order to reserve s ingle-point touch | 293 * is being performed with 2 or more touch points, in order to reserve s ingle-point touch |
| 237 * events for emulating mouse input. | 294 * events for emulating mouse input. |
| 238 */ | 295 */ |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 260 | 317 |
| 261 synchronized (mTransform) { | 318 synchronized (mTransform) { |
| 262 float scaleFactor = detector.getScaleFactor(); | 319 float scaleFactor = detector.getScaleFactor(); |
| 263 mTransform.postScale( | 320 mTransform.postScale( |
| 264 scaleFactor, scaleFactor, detector.getFocusX(), detector .getFocusY()); | 321 scaleFactor, scaleFactor, detector.getFocusX(), detector .getFocusY()); |
| 265 } | 322 } |
| 266 JniInterface.redrawGraphics(); | 323 JniInterface.redrawGraphics(); |
| 267 return true; | 324 return true; |
| 268 } | 325 } |
| 269 | 326 |
| 327 /** Called whenever a gesture starts. Always accepts the gesture so it i sn't ignored. */ | |
| 328 @Override | |
| 329 public boolean onDown(MotionEvent e) { | |
| 330 return true; | |
| 331 } | |
| 332 | |
| 270 /** | 333 /** |
| 271 * Called when the user starts to zoom. Always accepts the zoom so that | 334 * Called when the user starts to zoom. Always accepts the zoom so that |
| 272 * onScale() can decide whether to respond to it. | 335 * onScale() can decide whether to respond to it. |
| 273 */ | 336 */ |
| 274 @Override | 337 @Override |
| 275 public boolean onScaleBegin(ScaleGestureDetector detector) { | 338 public boolean onScaleBegin(ScaleGestureDetector detector) { |
| 276 return true; | 339 return true; |
| 277 } | 340 } |
| 278 | 341 |
| 279 /** | 342 /** |
| 280 * Called when the user is done zooming. Defers to onScale()'s judgement . | 343 * Called when the user is done zooming. Defers to onScale()'s judgement . |
| 281 */ | 344 */ |
| 282 @Override | 345 @Override |
| 283 public void onScaleEnd(ScaleGestureDetector detector) { | 346 public void onScaleEnd(ScaleGestureDetector detector) { |
| 284 onScale(detector); | 347 onScale(detector); |
| 285 } | 348 } |
| 349 | |
| 350 @Override | |
| 351 public void onLongPress(MotionEvent e) { | |
| 352 float[] coordinates = new float[] {e.getRawX(), e.getY()}; | |
| 353 | |
| 354 if (mMouseButton > 0) { | |
| 355 Log.i("gesture", "Releasing " + mMouseButton); | |
| 356 handleMouseMovement(coordinates, -mMouseButton); | |
| 357 } | |
| 358 | |
| 359 Log.i("gesture", "Pressing 3"); | |
| 360 mMouseButton = 3; // TODO Name me! | |
| 361 handleMouseMovement(coordinates, mMouseButton); | |
| 362 } | |
| 286 } | 363 } |
| 287 } | 364 } |
| OLD | NEW |