| 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.app.ActionBar; | 7 import android.app.ActionBar; |
| 8 import android.app.Activity; | 8 import android.app.Activity; |
| 9 import android.graphics.Bitmap; | 9 import android.graphics.Bitmap; |
| 10 import android.graphics.Canvas; | 10 import android.graphics.Canvas; |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 */ | 259 */ |
| 260 @Override | 260 @Override |
| 261 public void surfaceDestroyed(SurfaceHolder holder) { | 261 public void surfaceDestroyed(SurfaceHolder holder) { |
| 262 Log.i("deskview", "DesktopView.surfaceDestroyed(...)"); | 262 Log.i("deskview", "DesktopView.surfaceDestroyed(...)"); |
| 263 | 263 |
| 264 // Stop this canvas from being redrawn. | 264 // Stop this canvas from being redrawn. |
| 265 JniInterface.provideRedrawCallback(null); | 265 JniInterface.provideRedrawCallback(null); |
| 266 } | 266 } |
| 267 | 267 |
| 268 /** Called when a mouse action is made. */ | 268 /** Called when a mouse action is made. */ |
| 269 private void handleMouseMovement(float[] coordinates, int button, boolean pr
essed) { | 269 private void handleMouseMovement(float x, float y, int button, boolean press
ed) { |
| 270 float[] coordinates = {x, y}; |
| 271 |
| 270 // Coordinates are relative to the canvas, but we need image coordinates
. | 272 // Coordinates are relative to the canvas, but we need image coordinates
. |
| 271 Matrix canvasToImage = new Matrix(); | 273 Matrix canvasToImage = new Matrix(); |
| 272 mTransform.invert(canvasToImage); | 274 mTransform.invert(canvasToImage); |
| 273 canvasToImage.mapPoints(coordinates); | 275 canvasToImage.mapPoints(coordinates); |
| 274 | 276 |
| 275 // Coordinates are now relative to the image, so transmit them to the ho
st. | 277 // Coordinates are now relative to the image, so transmit them to the ho
st. |
| 276 JniInterface.mouseAction((int)coordinates[0], (int)coordinates[1], butto
n, pressed); | 278 JniInterface.mouseAction((int)coordinates[0], (int)coordinates[1], butto
n, pressed); |
| 277 } | 279 } |
| 278 | 280 |
| 279 /** | 281 /** |
| 280 * Called whenever the user attempts to touch the canvas. Forwards such | 282 * Called whenever the user attempts to touch the canvas. Forwards such |
| 281 * events to the appropriate gesture detector until one accepts them. | 283 * events to the appropriate gesture detector until one accepts them. |
| 282 */ | 284 */ |
| 283 @Override | 285 @Override |
| 284 public boolean onTouchEvent(MotionEvent event) { | 286 public boolean onTouchEvent(MotionEvent event) { |
| 285 if (event.getPointerCount() == 3) { | 287 if (event.getPointerCount() == 3) { |
| 286 mActionBar.show(); | 288 mActionBar.show(); |
| 287 } | 289 } |
| 288 | 290 |
| 289 boolean handled = mScroller.onTouchEvent(event) || mZoomer.onTouchEvent(
event); | 291 boolean handled = mScroller.onTouchEvent(event) || mZoomer.onTouchEvent(
event); |
| 290 | 292 |
| 291 if (event.getPointerCount() == 1) { | 293 if (event.getPointerCount() == 1) { |
| 292 float[] coordinates = {event.getRawX(), event.getY()}; | 294 float x = event.getRawX(); |
| 295 float y = event.getY(); |
| 293 | 296 |
| 294 switch (event.getActionMasked()) { | 297 switch (event.getActionMasked()) { |
| 295 case MotionEvent.ACTION_DOWN: | 298 case MotionEvent.ACTION_DOWN: |
| 296 Log.i("mouse", "Found a finger"); | 299 Log.i("mouse", "Found a finger"); |
| 297 mMouseButton = BUTTON_UNDEFINED; | 300 mMouseButton = BUTTON_UNDEFINED; |
| 298 mMousePressed = false; | 301 mMousePressed = false; |
| 299 break; | 302 break; |
| 300 | 303 |
| 301 case MotionEvent.ACTION_MOVE: | 304 case MotionEvent.ACTION_MOVE: |
| 302 Log.i("mouse", "Finger is dragging"); | 305 Log.i("mouse", "Finger is dragging"); |
| 303 if (mMouseButton == BUTTON_UNDEFINED) { | 306 if (mMouseButton == BUTTON_UNDEFINED) { |
| 304 Log.i("mouse", "\tStarting left click"); | 307 Log.i("mouse", "\tStarting left click"); |
| 305 mMouseButton = BUTTON_LEFT; | 308 mMouseButton = BUTTON_LEFT; |
| 306 mMousePressed = true; | 309 mMousePressed = true; |
| 307 } | 310 } |
| 308 break; | 311 break; |
| 309 | 312 |
| 310 case MotionEvent.ACTION_UP: | 313 case MotionEvent.ACTION_UP: |
| 311 Log.i("mouse", "Lost the finger"); | 314 Log.i("mouse", "Lost the finger"); |
| 312 if (mMouseButton == BUTTON_UNDEFINED) { | 315 if (mMouseButton == BUTTON_UNDEFINED) { |
| 313 // The user pressed and released without moving: do left
click and release. | 316 // The user pressed and released without moving: do left
click and release. |
| 314 Log.i("mouse", "\tStarting and finishing left click"); | 317 Log.i("mouse", "\tStarting and finishing left click"); |
| 315 handleMouseMovement(new float[] {coordinates[0], coordin
ates[1]}, | 318 handleMouseMovement(x, y, BUTTON_LEFT, true); |
| 316 BUTTON_LEFT, true); | |
| 317 mMouseButton = BUTTON_LEFT; | 319 mMouseButton = BUTTON_LEFT; |
| 318 mMousePressed = false; | 320 mMousePressed = false; |
| 319 } | 321 } |
| 320 else if (mMousePressed) { | 322 else if (mMousePressed) { |
| 321 Log.i("mouse", "\tReleasing the currently-pressed button
"); | 323 Log.i("mouse", "\tReleasing the currently-pressed button
"); |
| 322 mMousePressed = false; | 324 mMousePressed = false; |
| 323 } | 325 } |
| 324 else { | 326 else { |
| 325 Log.w("mouse", "Button already in released state before
gesture ended"); | 327 Log.w("mouse", "Button already in released state before
gesture ended"); |
| 326 } | 328 } |
| 327 break; | 329 break; |
| 328 | 330 |
| 329 default: | 331 default: |
| 330 return handled; | 332 return handled; |
| 331 } | 333 } |
| 332 handleMouseMovement(coordinates, mMouseButton, mMousePressed); | 334 handleMouseMovement(x, y, mMouseButton, mMousePressed); |
| 333 | 335 |
| 334 return true; | 336 return true; |
| 335 } | 337 } |
| 336 | 338 |
| 337 return handled; | 339 return handled; |
| 338 } | 340 } |
| 339 | 341 |
| 340 /** Responds to touch events filtered by the gesture detectors. */ | 342 /** Responds to touch events filtered by the gesture detectors. */ |
| 341 private class DesktopListener extends GestureDetector.SimpleOnGestureListene
r | 343 private class DesktopListener extends GestureDetector.SimpleOnGestureListene
r |
| 342 implements ScaleGestureDetector.OnScaleGestureListener { | 344 implements ScaleGestureDetector.OnScaleGestureListener { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 onScale(detector); | 399 onScale(detector); |
| 398 } | 400 } |
| 399 | 401 |
| 400 /** Called when the user holds down on the screen. Starts a right-click.
*/ | 402 /** Called when the user holds down on the screen. Starts a right-click.
*/ |
| 401 @Override | 403 @Override |
| 402 public void onLongPress(MotionEvent e) { | 404 public void onLongPress(MotionEvent e) { |
| 403 if (e.getPointerCount() > 1) { | 405 if (e.getPointerCount() > 1) { |
| 404 return; | 406 return; |
| 405 } | 407 } |
| 406 | 408 |
| 407 float[] coordinates = new float[] {e.getRawX(), e.getY()}; | 409 float x = e.getRawX(); |
| 410 float y = e.getY(); |
| 408 | 411 |
| 409 Log.i("mouse", "Finger held down"); | 412 Log.i("mouse", "Finger held down"); |
| 410 if (mMousePressed) { | 413 if (mMousePressed) { |
| 411 Log.i("mouse", "\tReleasing the currently-pressed button"); | 414 Log.i("mouse", "\tReleasing the currently-pressed button"); |
| 412 handleMouseMovement(coordinates, mMouseButton, false); | 415 handleMouseMovement(x, y, mMouseButton, false); |
| 413 } | 416 } |
| 414 | 417 |
| 415 Log.i("mouse", "\tStarting right click"); | 418 Log.i("mouse", "\tStarting right click"); |
| 416 mMouseButton = BUTTON_RIGHT; | 419 mMouseButton = BUTTON_RIGHT; |
| 417 mMousePressed = true; | 420 mMousePressed = true; |
| 418 handleMouseMovement(coordinates, mMouseButton, mMousePressed); | 421 handleMouseMovement(x, y, mMouseButton, mMousePressed); |
| 419 } | 422 } |
| 420 } | 423 } |
| 421 } | 424 } |
| OLD | NEW |