Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(94)

Side by Side Diff: remoting/android/java/src/org/chromium/chromoting/TrackingInputHandler.java

Issue 600983002: [Checkstyle] Fix misc style issues in Java files. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix build Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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.Matrix; 8 import android.graphics.Matrix;
9 import android.graphics.PointF; 9 import android.graphics.PointF;
10 import android.view.GestureDetector; 10 import android.view.GestureDetector;
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 synchronized (mRenderData) { 114 synchronized (mRenderData) {
115 // Constrain cursor to the image area. 115 // Constrain cursor to the image area.
116 if (newX < 0) newX = 0; 116 if (newX < 0) newX = 0;
117 if (newY < 0) newY = 0; 117 if (newY < 0) newY = 0;
118 if (newX > mRenderData.imageWidth) newX = mRenderData.imageWidth; 118 if (newX > mRenderData.imageWidth) newX = mRenderData.imageWidth;
119 if (newY > mRenderData.imageHeight) newY = mRenderData.imageHeight; 119 if (newY > mRenderData.imageHeight) newY = mRenderData.imageHeight;
120 mCursorPosition.set(newX, newY); 120 mCursorPosition.set(newX, newY);
121 repositionImage(); 121 repositionImage();
122 } 122 }
123 123
124 mViewer.injectMouseEvent((int)newX, (int)newY, BUTTON_UNDEFINED, false); 124 mViewer.injectMouseEvent((int) newX, (int) newY, BUTTON_UNDEFINED, false );
125 } 125 }
126 126
127 /** 127 /**
128 * Repositions the image by translating it (without affecting the zoom level ) to place the 128 * Repositions the image by translating it (without affecting the zoom level ) to place the
129 * cursor close to the center of the screen. 129 * cursor close to the center of the screen.
130 */ 130 */
131 private void repositionImage() { 131 private void repositionImage() {
132 synchronized (mRenderData) { 132 synchronized (mRenderData) {
133 // Get the current cursor position in screen coordinates. 133 // Get the current cursor position in screen coordinates.
134 float[] cursorScreen = {mCursorPosition.x, mCursorPosition.y}; 134 float[] cursorScreen = {mCursorPosition.x, mCursorPosition.y};
135 mRenderData.transform.mapPoints(cursorScreen); 135 mRenderData.transform.mapPoints(cursorScreen);
136 136
137 // Translate so the cursor is displayed in the middle of the screen. 137 // Translate so the cursor is displayed in the middle of the screen.
138 mRenderData.transform.postTranslate( 138 mRenderData.transform.postTranslate(
139 (float)mRenderData.screenWidth / 2 - cursorScreen[0], 139 (float) mRenderData.screenWidth / 2 - cursorScreen[0],
140 (float)mRenderData.screenHeight / 2 - cursorScreen[1]); 140 (float) mRenderData.screenHeight / 2 - cursorScreen[1]);
141 141
142 // Now the cursor is displayed in the middle of the screen, see if t he image can be 142 // Now the cursor is displayed in the middle of the screen, see if t he image can be
143 // panned so that more of it is visible. The primary goal is to show as much of the 143 // panned so that more of it is visible. The primary goal is to show as much of the
144 // image as possible. The secondary goal is to keep the cursor in th e middle. 144 // image as possible. The secondary goal is to keep the cursor in th e middle.
145 145
146 // Get the coordinates of the desktop rectangle (top-left/bottom-rig ht corners) in 146 // Get the coordinates of the desktop rectangle (top-left/bottom-rig ht corners) in
147 // screen coordinates. Order is: left, top, right, bottom. 147 // screen coordinates. Order is: left, top, right, bottom.
148 float[] rectScreen = {0, 0, mRenderData.imageWidth, mRenderData.imag eHeight}; 148 float[] rectScreen = {0, 0, mRenderData.imageWidth, mRenderData.imag eHeight};
149 mRenderData.transform.mapPoints(rectScreen); 149 mRenderData.transform.mapPoints(rectScreen);
150 150
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 return; 193 return;
194 } 194 }
195 195
196 // Zoom out if the zoom level is too high. 196 // Zoom out if the zoom level is too high.
197 float currentZoomLevel = mRenderData.transform.mapRadius(1.0f); 197 float currentZoomLevel = mRenderData.transform.mapRadius(1.0f);
198 if (currentZoomLevel > MAX_ZOOM_FACTOR) { 198 if (currentZoomLevel > MAX_ZOOM_FACTOR) {
199 mRenderData.transform.setScale(MAX_ZOOM_FACTOR, MAX_ZOOM_FACTOR) ; 199 mRenderData.transform.setScale(MAX_ZOOM_FACTOR, MAX_ZOOM_FACTOR) ;
200 } 200 }
201 201
202 // Get image size scaled to screen coordinates. 202 // Get image size scaled to screen coordinates.
203 float[] imageSize = {(float)mRenderData.imageWidth, (float)mRenderDa ta.imageHeight}; 203 float[] imageSize = {mRenderData.imageWidth, mRenderData.imageHeight };
Lambros 2014/09/24 23:54:37 Does this still compile if you remove the (float)
204 mRenderData.transform.mapVectors(imageSize); 204 mRenderData.transform.mapVectors(imageSize);
205 205
206 if (imageSize[0] < mRenderData.screenWidth && imageSize[1] < mRender Data.screenHeight) { 206 if (imageSize[0] < mRenderData.screenWidth && imageSize[1] < mRender Data.screenHeight) {
207 // Displayed image is too small in both directions, so apply the minimum zoom 207 // Displayed image is too small in both directions, so apply the minimum zoom
208 // level needed to fit either the width or height. 208 // level needed to fit either the width or height.
209 float scale = Math.min((float)mRenderData.screenWidth / mRenderD ata.imageWidth, 209 float scale = Math.min((float) mRenderData.screenWidth / mRender Data.imageWidth,
210 (float)mRenderData.screenHeight / mRender Data.imageHeight); 210 (float) mRenderData.screenHeight / mRende rData.imageHeight);
211 mRenderData.transform.setScale(scale, scale); 211 mRenderData.transform.setScale(scale, scale);
212 } 212 }
213 213
214 repositionImage(); 214 repositionImage();
215 } 215 }
216 } 216 }
217 217
218 /** Injects a button event using the current cursor location. */ 218 /** Injects a button event using the current cursor location. */
219 private void injectButtonEvent(int button, boolean pressed) { 219 private void injectButtonEvent(int button, boolean pressed) {
220 mViewer.injectMouseEvent((int)mCursorPosition.x, (int)mCursorPosition.y, button, pressed); 220 mViewer.injectMouseEvent((int) mCursorPosition.x, (int) mCursorPosition. y, button, pressed);
221 } 221 }
222 222
223 /** Processes a (multi-finger) swipe gesture. */ 223 /** Processes a (multi-finger) swipe gesture. */
224 private boolean onSwipe() { 224 private boolean onSwipe() {
225 if (mTotalMotionY > mSwipeThreshold) { 225 if (mTotalMotionY > mSwipeThreshold) {
226 // Swipe down occurred. 226 // Swipe down occurred.
227 mViewer.showActionBar(); 227 mViewer.showActionBar();
228 } else if (mTotalMotionY < -mSwipeThreshold) { 228 } else if (mTotalMotionY < -mSwipeThreshold) {
229 // Swipe up occurred. 229 // Swipe up occurred.
230 mViewer.showKeyboard(); 230 mViewer.showKeyboard();
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 public void onScreenConfigurationChanged() { 281 public void onScreenConfigurationChanged() {
282 } 282 }
283 283
284 @Override 284 @Override
285 public void onClientSizeChanged(int width, int height) { 285 public void onClientSizeChanged(int width, int height) {
286 repositionImageWithZoom(); 286 repositionImageWithZoom();
287 } 287 }
288 288
289 @Override 289 @Override
290 public void onHostSizeChanged(int width, int height) { 290 public void onHostSizeChanged(int width, int height) {
291 moveCursor((float)width / 2, (float)height / 2); 291 moveCursor((float) width / 2, (float) height / 2);
292 repositionImageWithZoom(); 292 repositionImageWithZoom();
293 } 293 }
294 294
295 @Override 295 @Override
296 public void processAnimation() { 296 public void processAnimation() {
297 int previousX = mFlingScroller.getCurrX(); 297 int previousX = mFlingScroller.getCurrX();
298 int previousY = mFlingScroller.getCurrY(); 298 int previousY = mFlingScroller.getCurrY();
299 if (!mFlingScroller.computeScrollOffset()) { 299 if (!mFlingScroller.computeScrollOffset()) {
300 mViewer.setAnimationEnabled(false); 300 mViewer.setAnimationEnabled(false);
301 return; 301 return;
302 } 302 }
303 int deltaX = mFlingScroller.getCurrX() - previousX; 303 int deltaX = mFlingScroller.getCurrX() - previousX;
304 int deltaY = mFlingScroller.getCurrY() - previousY; 304 int deltaY = mFlingScroller.getCurrY() - previousY;
305 float[] delta = {(float)deltaX, (float)deltaY}; 305 float[] delta = {deltaX, deltaY};
Lambros 2014/09/24 23:54:37 Ditto.
306 synchronized (mRenderData) { 306 synchronized (mRenderData) {
307 Matrix canvasToImage = new Matrix(); 307 Matrix canvasToImage = new Matrix();
308 mRenderData.transform.invert(canvasToImage); 308 mRenderData.transform.invert(canvasToImage);
309 canvasToImage.mapVectors(delta); 309 canvasToImage.mapVectors(delta);
310 } 310 }
311 311
312 moveCursor(mCursorPosition.x + delta[0], mCursorPosition.y + delta[1]); 312 moveCursor(mCursorPosition.x + delta[0], mCursorPosition.y + delta[1]);
313 } 313 }
314 314
315 /** Responds to touch events filtered by the gesture detectors. */ 315 /** Responds to touch events filtered by the gesture detectors. */
316 private class GestureListener extends GestureDetector.SimpleOnGestureListene r 316 private class GestureListener extends GestureDetector.SimpleOnGestureListene r
317 implements ScaleGestureDetector.OnScaleGestureListener, 317 implements ScaleGestureDetector.OnScaleGestureListener,
318 TapGestureDetector.OnTapListener { 318 TapGestureDetector.OnTapListener {
319 /** 319 /**
320 * Called when the user drags one or more fingers across the touchscreen . 320 * Called when the user drags one or more fingers across the touchscreen .
321 */ 321 */
322 @Override 322 @Override
323 public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { 323 public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
324 int pointerCount = e2.getPointerCount(); 324 int pointerCount = e2.getPointerCount();
325 if (pointerCount == 3 && !mSwipeCompleted) { 325 if (pointerCount == 3 && !mSwipeCompleted) {
326 // Note that distance values are reversed. For example, dragging a finger in the 326 // Note that distance values are reversed. For example, dragging a finger in the
327 // direction of increasing Y coordinate (downwards) results in d istanceY being 327 // direction of increasing Y coordinate (downwards) results in d istanceY being
328 // negative. 328 // negative.
329 mTotalMotionY -= distanceY; 329 mTotalMotionY -= distanceY;
330 return onSwipe(); 330 return onSwipe();
331 } 331 }
332 332
333 if (pointerCount == 2 && mSwipePinchDetector.isSwiping()) { 333 if (pointerCount == 2 && mSwipePinchDetector.isSwiping()) {
334 mViewer.injectMouseWheelDeltaEvent(-(int)distanceX, -(int)distan ceY); 334 mViewer.injectMouseWheelDeltaEvent(-(int) distanceX, -(int) dist anceY);
335 335
336 // Prevent the cursor being moved or flung by the gesture. 336 // Prevent the cursor being moved or flung by the gesture.
337 mSuppressCursorMovement = true; 337 mSuppressCursorMovement = true;
338 return true; 338 return true;
339 } 339 }
340 340
341 if (pointerCount != 1 || mSuppressCursorMovement) { 341 if (pointerCount != 1 || mSuppressCursorMovement) {
342 return false; 342 return false;
343 } 343 }
344 344
(...skipping 21 matching lines...) Expand all
366 } 366 }
367 367
368 // The fling physics calculation is based on screen coordinates, so that it will 368 // The fling physics calculation is based on screen coordinates, so that it will
369 // behave consistently at different zoom levels (and will work nicel y at high zoom 369 // behave consistently at different zoom levels (and will work nicel y at high zoom
370 // levels, since |mFlingScroller| outputs integer coordinates). Howe ver, the desktop 370 // levels, since |mFlingScroller| outputs integer coordinates). Howe ver, the desktop
371 // will usually be panned as the cursor is moved across the desktop, which means the 371 // will usually be panned as the cursor is moved across the desktop, which means the
372 // transformation mapping from screen to desktop coordinates will ch ange. To deal with 372 // transformation mapping from screen to desktop coordinates will ch ange. To deal with
373 // this, the cursor movement is computed from relative coordinate ch anges from 373 // this, the cursor movement is computed from relative coordinate ch anges from
374 // |mFlingScroller|. This means the fling can be started at (0, 0) w ith no bounding 374 // |mFlingScroller|. This means the fling can be started at (0, 0) w ith no bounding
375 // constraints - the cursor is already constrained by the desktop si ze. 375 // constraints - the cursor is already constrained by the desktop si ze.
376 mFlingScroller.fling(0, 0, (int)velocityX, (int)velocityY, Integer.M IN_VALUE, 376 mFlingScroller.fling(0, 0, (int) velocityX, (int) velocityY, Integer .MIN_VALUE,
377 Integer.MAX_VALUE, Integer.MIN_VALUE, Integer.MAX_VALUE); 377 Integer.MAX_VALUE, Integer.MIN_VALUE, Integer.MAX_VALUE);
378 // Initialize the scroller's current offset coordinates, since they are used for 378 // Initialize the scroller's current offset coordinates, since they are used for
379 // calculating the delta values. 379 // calculating the delta values.
380 mFlingScroller.computeScrollOffset(); 380 mFlingScroller.computeScrollOffset();
381 mViewer.setAnimationEnabled(true); 381 mViewer.setAnimationEnabled(true);
382 return true; 382 return true;
383 } 383 }
384 384
385 /** Called when the user is in the process of pinch-zooming. */ 385 /** Called when the user is in the process of pinch-zooming. */
386 @Override 386 @Override
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 public void onLongPress(int pointerCount) { 455 public void onLongPress(int pointerCount) {
456 mHeldButton = mouseButtonFromPointerCount(pointerCount); 456 mHeldButton = mouseButtonFromPointerCount(pointerCount);
457 if (mHeldButton != BUTTON_UNDEFINED) { 457 if (mHeldButton != BUTTON_UNDEFINED) {
458 injectButtonEvent(mHeldButton, true); 458 injectButtonEvent(mHeldButton, true);
459 mViewer.showLongPressFeedback(); 459 mViewer.showLongPressFeedback();
460 mSuppressFling = true; 460 mSuppressFling = true;
461 } 461 }
462 } 462 }
463 } 463 }
464 } 464 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698