| 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; |
| 11 import android.graphics.Color; | 11 import android.graphics.Color; |
| 12 import android.graphics.Matrix; | 12 import android.graphics.Matrix; |
| 13 import android.graphics.Paint; | 13 import android.graphics.Paint; |
| 14 import android.graphics.Point; |
| 14 import android.os.Bundle; | 15 import android.os.Bundle; |
| 15 import android.os.Looper; | 16 import android.os.Looper; |
| 16 import android.text.InputType; | 17 import android.text.InputType; |
| 17 import android.util.Log; | 18 import android.util.Log; |
| 18 import android.view.GestureDetector; | 19 import android.view.GestureDetector; |
| 19 import android.view.MotionEvent; | 20 import android.view.MotionEvent; |
| 20 import android.view.ScaleGestureDetector; | 21 import android.view.ScaleGestureDetector; |
| 21 import android.view.SurfaceHolder; | 22 import android.view.SurfaceHolder; |
| 22 import android.view.SurfaceView; | 23 import android.view.SurfaceView; |
| 23 import android.view.inputmethod.EditorInfo; | 24 import android.view.inputmethod.EditorInfo; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 | 61 |
| 61 private GestureDetector mScroller; | 62 private GestureDetector mScroller; |
| 62 private ScaleGestureDetector mZoomer; | 63 private ScaleGestureDetector mZoomer; |
| 63 | 64 |
| 64 /** Stores pan and zoom configuration and converts image coordinates to scre
en coordinates. */ | 65 /** Stores pan and zoom configuration and converts image coordinates to scre
en coordinates. */ |
| 65 private Matrix mTransform; | 66 private Matrix mTransform; |
| 66 | 67 |
| 67 private int mScreenWidth; | 68 private int mScreenWidth; |
| 68 private int mScreenHeight; | 69 private int mScreenHeight; |
| 69 | 70 |
| 71 /** |
| 72 * Specifies the position, in image coordinates, at which the cursor image w
ill be drawn. |
| 73 * This will normally be at the location of the most recently injected motio
n event. |
| 74 */ |
| 75 private Point mCursorPosition; |
| 76 |
| 70 /** Specifies the dimension by which the zoom level is being lower-bounded.
*/ | 77 /** Specifies the dimension by which the zoom level is being lower-bounded.
*/ |
| 71 private Constraint mConstraint; | 78 private Constraint mConstraint; |
| 72 | 79 |
| 73 /** Whether the dimension of constraint should be reckecked on the next aspe
ct ratio change. */ | 80 /** Whether the dimension of constraint should be reckecked on the next aspe
ct ratio change. */ |
| 74 private boolean mRecheckConstraint; | 81 private boolean mRecheckConstraint; |
| 75 | 82 |
| 76 /** Whether the right edge of the image was visible on-screen during the las
t render. */ | 83 /** Whether the right edge of the image was visible on-screen during the las
t render. */ |
| 77 private boolean mRightUsedToBeOut; | 84 private boolean mRightUsedToBeOut; |
| 78 | 85 |
| 79 /** Whether the bottom edge of the image was visible on-screen during the la
st render. */ | 86 /** Whether the bottom edge of the image was visible on-screen during the la
st render. */ |
| (...skipping 11 matching lines...) Expand all Loading... |
| 91 mActionBar = context.getActionBar(); | 98 mActionBar = context.getActionBar(); |
| 92 | 99 |
| 93 getHolder().addCallback(this); | 100 getHolder().addCallback(this); |
| 94 DesktopListener listener = new DesktopListener(); | 101 DesktopListener listener = new DesktopListener(); |
| 95 mScroller = new GestureDetector(context, listener, null, false); | 102 mScroller = new GestureDetector(context, listener, null, false); |
| 96 mZoomer = new ScaleGestureDetector(context, listener); | 103 mZoomer = new ScaleGestureDetector(context, listener); |
| 97 | 104 |
| 98 mTransform = new Matrix(); | 105 mTransform = new Matrix(); |
| 99 mScreenWidth = 0; | 106 mScreenWidth = 0; |
| 100 mScreenHeight = 0; | 107 mScreenHeight = 0; |
| 108 mCursorPosition = new Point(); |
| 101 | 109 |
| 102 mConstraint = Constraint.UNDEFINED; | 110 mConstraint = Constraint.UNDEFINED; |
| 103 mRecheckConstraint = false; | 111 mRecheckConstraint = false; |
| 104 | 112 |
| 105 mRightUsedToBeOut = false; | 113 mRightUsedToBeOut = false; |
| 106 mBottomUsedToBeOut = false; | 114 mBottomUsedToBeOut = false; |
| 107 | 115 |
| 108 mMouseButton = BUTTON_UNDEFINED; | 116 mMouseButton = BUTTON_UNDEFINED; |
| 109 mMousePressed = false; | 117 mMousePressed = false; |
| 110 } | 118 } |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 } | 217 } |
| 210 | 218 |
| 211 mTransform.setValues(values); | 219 mTransform.setValues(values); |
| 212 } | 220 } |
| 213 | 221 |
| 214 canvas.setMatrix(mTransform); | 222 canvas.setMatrix(mTransform); |
| 215 } | 223 } |
| 216 | 224 |
| 217 canvas.drawColor(Color.BLACK); | 225 canvas.drawColor(Color.BLACK); |
| 218 canvas.drawBitmap(image, 0, 0, new Paint()); | 226 canvas.drawBitmap(image, 0, 0, new Paint()); |
| 227 Bitmap cursorBitmap = JniInterface.getCursorBitmap(); |
| 228 if (cursorBitmap != null) { |
| 229 Point hotspot = JniInterface.getCursorHotspot(); |
| 230 int bitmapX, bitmapY; |
| 231 synchronized (mCursorPosition) { |
| 232 bitmapX = mCursorPosition.x - hotspot.x; |
| 233 bitmapY = mCursorPosition.y - hotspot.y; |
| 234 } |
| 235 canvas.drawBitmap(cursorBitmap, bitmapX, bitmapY, new Paint()); |
| 236 } |
| 219 getHolder().unlockCanvasAndPost(canvas); | 237 getHolder().unlockCanvasAndPost(canvas); |
| 220 } | 238 } |
| 221 | 239 |
| 222 /** | 240 /** |
| 223 * Causes the next canvas redraw to perform a check for which screen dimensi
on more tightly | 241 * Causes the next canvas redraw to perform a check for which screen dimensi
on more tightly |
| 224 * constrains the view of the image. This should be called between the time
that a screen size | 242 * constrains the view of the image. This should be called between the time
that a screen size |
| 225 * change is requested and the time it actually occurs. If it is not called
in such a case, the | 243 * change is requested and the time it actually occurs. If it is not called
in such a case, the |
| 226 * screen will not be rearranged as aggressively (which is desirable when th
e software keyboard | 244 * screen will not be rearranged as aggressively (which is desirable when th
e software keyboard |
| 227 * appears in order to allow it to cover the image without forcing a resize)
. | 245 * appears in order to allow it to cover the image without forcing a resize)
. |
| 228 */ | 246 */ |
| (...skipping 13 matching lines...) Expand all Loading... |
| 242 synchronized (mTransform) { | 260 synchronized (mTransform) { |
| 243 mScreenWidth = width; | 261 mScreenWidth = width; |
| 244 mScreenHeight = height; | 262 mScreenHeight = height; |
| 245 | 263 |
| 246 if (mRecheckConstraint) { | 264 if (mRecheckConstraint) { |
| 247 mConstraint = Constraint.UNDEFINED; | 265 mConstraint = Constraint.UNDEFINED; |
| 248 mRecheckConstraint = false; | 266 mRecheckConstraint = false; |
| 249 } | 267 } |
| 250 } | 268 } |
| 251 | 269 |
| 270 synchronized (mCursorPosition) { |
| 271 mCursorPosition.x = width / 2; |
| 272 mCursorPosition.y = height / 2; |
| 273 } |
| 274 |
| 252 if (!JniInterface.redrawGraphics()) { | 275 if (!JniInterface.redrawGraphics()) { |
| 253 JniInterface.provideRedrawCallback(this); | 276 JniInterface.provideRedrawCallback(this); |
| 254 } | 277 } |
| 255 } | 278 } |
| 256 | 279 |
| 257 /** Called when the canvas is first created. */ | 280 /** Called when the canvas is first created. */ |
| 258 @Override | 281 @Override |
| 259 public void surfaceCreated(SurfaceHolder holder) { | 282 public void surfaceCreated(SurfaceHolder holder) { |
| 260 Log.i("deskview", "DesktopView.surfaceCreated(...)"); | 283 Log.i("deskview", "DesktopView.surfaceCreated(...)"); |
| 261 } | 284 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 289 | 312 |
| 290 return null; | 313 return null; |
| 291 } | 314 } |
| 292 | 315 |
| 293 /** Called when a mouse action is made. */ | 316 /** Called when a mouse action is made. */ |
| 294 private void handleMouseMovement(float x, float y, int button, boolean press
ed) { | 317 private void handleMouseMovement(float x, float y, int button, boolean press
ed) { |
| 295 float[] coordinates = {x, y}; | 318 float[] coordinates = {x, y}; |
| 296 | 319 |
| 297 // Coordinates are relative to the canvas, but we need image coordinates
. | 320 // Coordinates are relative to the canvas, but we need image coordinates
. |
| 298 Matrix canvasToImage = new Matrix(); | 321 Matrix canvasToImage = new Matrix(); |
| 299 mTransform.invert(canvasToImage); | 322 synchronized (mTransform) { |
| 323 mTransform.invert(canvasToImage); |
| 324 } |
| 300 canvasToImage.mapPoints(coordinates); | 325 canvasToImage.mapPoints(coordinates); |
| 301 | 326 |
| 327 int imageX = (int)coordinates[0]; |
| 328 int imageY = (int)coordinates[1]; |
| 329 |
| 330 synchronized (mCursorPosition) { |
| 331 mCursorPosition.x = imageX; |
| 332 mCursorPosition.y = imageY; |
| 333 } |
| 334 |
| 302 // Coordinates are now relative to the image, so transmit them to the ho
st. | 335 // Coordinates are now relative to the image, so transmit them to the ho
st. |
| 303 JniInterface.mouseAction((int)coordinates[0], (int)coordinates[1], butto
n, pressed); | 336 JniInterface.mouseAction(imageX, imageY, button, pressed); |
| 337 |
| 338 // TODO(lambroslambrou): Optimize this to repaint only the areas covered
by the old and new |
| 339 // cursor positions. |
| 340 JniInterface.redrawGraphics(); |
| 304 } | 341 } |
| 305 | 342 |
| 306 /** | 343 /** |
| 307 * Called whenever the user attempts to touch the canvas. Forwards such | 344 * Called whenever the user attempts to touch the canvas. Forwards such |
| 308 * events to the appropriate gesture detector until one accepts them. | 345 * events to the appropriate gesture detector until one accepts them. |
| 309 */ | 346 */ |
| 310 @Override | 347 @Override |
| 311 public boolean onTouchEvent(MotionEvent event) { | 348 public boolean onTouchEvent(MotionEvent event) { |
| 312 if (event.getPointerCount() == 3) { | 349 if (event.getPointerCount() == 3) { |
| 313 mActionBar.show(); | 350 mActionBar.show(); |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 handleMouseMovement(x, y, mMouseButton, false); | 477 handleMouseMovement(x, y, mMouseButton, false); |
| 441 } | 478 } |
| 442 | 479 |
| 443 Log.i("mouse", "\tStarting right click"); | 480 Log.i("mouse", "\tStarting right click"); |
| 444 mMouseButton = BUTTON_RIGHT; | 481 mMouseButton = BUTTON_RIGHT; |
| 445 mMousePressed = true; | 482 mMousePressed = true; |
| 446 handleMouseMovement(x, y, mMouseButton, mMousePressed); | 483 handleMouseMovement(x, y, mMouseButton, mMousePressed); |
| 447 } | 484 } |
| 448 } | 485 } |
| 449 } | 486 } |
| OLD | NEW |