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

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

Issue 2047903002: [Chromoting] TouchInputHandler now listens to events in DesktopView (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Resolve review comments Created 4 years, 6 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.Point; 9 import android.graphics.Point;
10 import android.graphics.PointF; 10 import android.graphics.PointF;
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 // that intentional swipes are usually detected. 205 // that intentional swipes are usually detected.
206 float density = context.getResources().getDisplayMetrics().density; 206 float density = context.getResources().getDisplayMetrics().density;
207 mSwipeThreshold = 40 * density; 207 mSwipeThreshold = 40 * density;
208 208
209 mEdgeSlopInPx = ViewConfiguration.get(context).getScaledEdgeSlop(); 209 mEdgeSlopInPx = ViewConfiguration.get(context).getScaledEdgeSlop();
210 210
211 mInputStrategy = new NullInputStrategy(); 211 mInputStrategy = new NullInputStrategy();
212 212
213 mCursorAnimationJob = new CursorAnimationJob(context); 213 mCursorAnimationJob = new CursorAnimationJob(context);
214 mScrollAnimationJob = new ScrollAnimationJob(context); 214 mScrollAnimationJob = new ScrollAnimationJob(context);
215
216 attachViewEvents(viewer);
215 } 217 }
216 218
217 @Override 219 @Override
218 public boolean onTouchEvent(MotionEvent event) {
219 // Give the underlying input strategy a chance to observe the current mo tion event before
220 // passing it to the gesture detectors. This allows the input strategy to react to the
221 // event or save the payload for use in recreating the gesture remotely.
222 mInputStrategy.onMotionEvent(event);
223
224 // Avoid short-circuit logic evaluation - ensure all gesture detectors s ee all events so
225 // that they generate correct notifications.
226 boolean handled = mScroller.onTouchEvent(event);
227 handled |= mZoomer.onTouchEvent(event);
228 handled |= mTapDetector.onTouchEvent(event);
229 mSwipePinchDetector.onTouchEvent(event);
230
231 switch (event.getActionMasked()) {
232 case MotionEvent.ACTION_DOWN:
233 mViewer.setAnimationEnabled(false);
234 mSuppressCursorMovement = false;
235 mSuppressFling = false;
236 mSwipeCompleted = false;
237 mIsDragging = false;
238 break;
239
240 case MotionEvent.ACTION_POINTER_DOWN:
241 mTotalMotionY = 0;
242 break;
243
244 default:
245 break;
246 }
247 return handled;
248 }
249
250 @Override
251 public void onClientSizeChanged(int width, int height) {
252 mPanGestureBounds = new Rect(
253 mEdgeSlopInPx, mEdgeSlopInPx, width - mEdgeSlopInPx, height - mE dgeSlopInPx);
254 mDesktopCanvas.repositionImageWithZoom(true);
255 }
256
257 @Override
258 public void onHostSizeChanged(int width, int height) {
259 moveViewport((float) width / 2, (float) height / 2);
260 mDesktopCanvas.resizeImageToFitScreen();
261 }
262
263 @Override
264 public void processAnimation() { 220 public void processAnimation() {
265 boolean active = mCursorAnimationJob.processAnimation(); 221 boolean active = mCursorAnimationJob.processAnimation();
266 active |= mScrollAnimationJob.processAnimation(); 222 active |= mScrollAnimationJob.processAnimation();
267 223
268 if (!active) { 224 if (!active) {
269 mViewer.setAnimationEnabled(false); 225 mViewer.setAnimationEnabled(false);
270 } 226 }
271 } 227 }
272 228
273 @Override 229 @Override
274 public void init(Desktop desktop, final Client client) { 230 public void init(Desktop desktop, final Client client) {
275 Preconditions.notNull(client); 231 Preconditions.notNull(client);
276 desktop.onInputModeChanged().add( 232 desktop.onInputModeChanged().add(
277 new Event.ParameterRunnable<InputModeChangedEventParameter>() { 233 new Event.ParameterRunnable<InputModeChangedEventParameter>() {
278 @Override 234 @Override
279 public void run(InputModeChangedEventParameter parameter) { 235 public void run(InputModeChangedEventParameter parameter) {
280 handleInputModeChanged(parameter, client); 236 handleInputModeChanged(parameter, client);
281 } 237 }
282 }); 238 });
283 239
284 desktop.onSoftInputMethodVisibilityChanged().add( 240 desktop.onSoftInputMethodVisibilityChanged().add(
285 new Event.ParameterRunnable<SoftInputMethodVisibilityChangedEven tParameter>() { 241 new Event.ParameterRunnable<SoftInputMethodVisibilityChangedEven tParameter>() {
286 @Override 242 @Override
287 public void run(SoftInputMethodVisibilityChangedEventParamet er parameter) { 243 public void run(SoftInputMethodVisibilityChangedEventParamet er parameter) {
288 handleSoftInputMethodVisibilityChanged(parameter); 244 handleSoftInputMethodVisibilityChanged(parameter);
289 } 245 }
290 }); 246 });
291 } 247 }
292 248
249 private void attachViewEvents(DesktopViewInterface viewer) {
250 viewer.onTouch().add(new Event.ParameterRunnable<TouchEventParameter>() {
251 @Override
252 public void run(TouchEventParameter parameter) {
253 parameter.handled = handleTouchEvent(parameter.event);
254 }
255 });
256 viewer.onClientSizeChanged().add(new Event.ParameterRunnable<SizeChanged EventParameter>() {
257 @Override
258 public void run(SizeChangedEventParameter parameter) {
259 handleClientSizeChanged(parameter.width, parameter.height);
260 }
261 });
262 viewer.onHostSizeChanged().add(new Event.ParameterRunnable<SizeChangedEv entParameter>() {
263 @Override
264 public void run(SizeChangedEventParameter parameter) {
265 handleHostSizeChanged(parameter.width, parameter.height);
266 }
267 });
268 }
269
293 private void handleInputModeChanged(InputModeChangedEventParameter parameter , 270 private void handleInputModeChanged(InputModeChangedEventParameter parameter ,
294 Client client) { 271 Client client) {
295 final Desktop.InputMode inputMode = parameter.inputMode; 272 final Desktop.InputMode inputMode = parameter.inputMode;
296 final CapabilityManager.HostCapability hostTouchCapability = 273 final CapabilityManager.HostCapability hostTouchCapability =
297 parameter.hostCapability; 274 parameter.hostCapability;
298 // We need both input mode and host input capabilities to select the inp ut 275 // We need both input mode and host input capabilities to select the inp ut
299 // strategy. 276 // strategy.
300 if (!inputMode.isSet() || !hostTouchCapability.isSet()) { 277 if (!inputMode.isSet() || !hostTouchCapability.isSet()) {
301 return; 278 return;
302 } 279 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 mRenderData.screenWidth - parameter.right, 312 mRenderData.screenWidth - parameter.right,
336 mRenderData.screenHeight - parameter.bottom); 313 mRenderData.screenHeight - parameter.bottom);
337 } else { 314 } else {
338 mDesktopCanvas.setInputMethodOffsetValues(0, 0); 315 mDesktopCanvas.setInputMethodOffsetValues(0, 0);
339 } 316 }
340 } 317 }
341 318
342 mDesktopCanvas.repositionImage(true); 319 mDesktopCanvas.repositionImage(true);
343 } 320 }
344 321
322 private boolean handleTouchEvent(MotionEvent event) {
323 // Give the underlying input strategy a chance to observe the current mo tion event before
324 // passing it to the gesture detectors. This allows the input strategy to react to the
325 // event or save the payload for use in recreating the gesture remotely.
326 mInputStrategy.onMotionEvent(event);
327
328 // Avoid short-circuit logic evaluation - ensure all gesture detectors s ee all events so
329 // that they generate correct notifications.
330 boolean handled = mScroller.onTouchEvent(event);
331 handled |= mZoomer.onTouchEvent(event);
332 handled |= mTapDetector.onTouchEvent(event);
333 mSwipePinchDetector.onTouchEvent(event);
334
335 switch (event.getActionMasked()) {
336 case MotionEvent.ACTION_DOWN:
337 mViewer.setAnimationEnabled(false);
338 mSuppressCursorMovement = false;
339 mSuppressFling = false;
340 mSwipeCompleted = false;
341 mIsDragging = false;
342 break;
343
344 case MotionEvent.ACTION_POINTER_DOWN:
345 mTotalMotionY = 0;
346 break;
347
348 default:
349 break;
350 }
351 return handled;
352 }
353
354 private void handleClientSizeChanged(int width, int height) {
355 mPanGestureBounds = new Rect(
356 mEdgeSlopInPx, mEdgeSlopInPx, width - mEdgeSlopInPx, height - mE dgeSlopInPx);
357 mDesktopCanvas.repositionImageWithZoom(true);
358 }
359
360 private void handleHostSizeChanged(int width, int height) {
361 moveViewport((float) width / 2, (float) height / 2);
362 mDesktopCanvas.resizeImageToFitScreen();
363 }
364
345 private void setInputStrategy(InputStrategyInterface inputStrategy) { 365 private void setInputStrategy(InputStrategyInterface inputStrategy) {
346 // Since the rules for flinging differ between input modes, we want to s top running the 366 // Since the rules for flinging differ between input modes, we want to s top running the
347 // current fling animation when the mode changes to prevent a wonky expe rience. 367 // current fling animation when the mode changes to prevent a wonky expe rience.
348 mCursorAnimationJob.abortAnimation(); 368 mCursorAnimationJob.abortAnimation();
349 mScrollAnimationJob.abortAnimation(); 369 mScrollAnimationJob.abortAnimation();
350 mInputStrategy = inputStrategy; 370 mInputStrategy = inputStrategy;
351 } 371 }
352 372
353 /** Moves the desired center of the viewport using the specified deltas. */ 373 /** Moves the desired center of the viewport using the specified deltas. */
354 private void moveViewportWithOffset(float deltaX, float deltaY) { 374 private void moveViewportWithOffset(float deltaX, float deltaY) {
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
628 case 2: 648 case 2:
629 return BUTTON_RIGHT; 649 return BUTTON_RIGHT;
630 case 3: 650 case 3:
631 return BUTTON_MIDDLE; 651 return BUTTON_MIDDLE;
632 default: 652 default:
633 return BUTTON_UNDEFINED; 653 return BUTTON_UNDEFINED;
634 } 654 }
635 } 655 }
636 } 656 }
637 } 657 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698