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

Side by Side Diff: platform_tools/android/apps/viewer/src/main/java/org/skia/viewer/ViewerActivity.java

Issue 1965013007: Use swipe gesture to switch between slides on Android (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Revision Created 4 years, 7 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
« no previous file with comments | « no previous file | tools/viewer/sk_app/Window.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 package org.skia.viewer; 8 package org.skia.viewer;
9 9
10 import android.app.Activity; 10 import android.app.Activity;
11 import android.os.Bundle; 11 import android.os.Bundle;
12 import android.util.Log;
13 import android.view.GestureDetector;
14 import android.view.KeyEvent;
15 import android.view.MotionEvent;
12 import android.view.Surface; 16 import android.view.Surface;
13 import android.view.SurfaceHolder; 17 import android.view.SurfaceHolder;
14 import android.view.SurfaceView; 18 import android.view.SurfaceView;
19 import android.view.View;
15 20
16 public class ViewerActivity extends Activity implements SurfaceHolder.Callback { 21 public class ViewerActivity
22 extends Activity implements SurfaceHolder.Callback, View.OnTouchListener {
23 private static final float FLING_VELOCITY_THRESHOLD = 1000;
24
17 private SurfaceView mView; 25 private SurfaceView mView;
18 private ViewerApplication mApplication; 26 private ViewerApplication mApplication;
27 private GestureDetector mGestureDetector;
19 28
20 private native void onSurfaceCreated(long handle, Surface surface); 29 private native void onSurfaceCreated(long handle, Surface surface);
21 private native void onSurfaceChanged(long handle, Surface surface); 30 private native void onSurfaceChanged(long handle, Surface surface);
22 private native void onSurfaceDestroyed(long handle); 31 private native void onSurfaceDestroyed(long handle);
32 private native void onKeyPressed(long handle, int keycode);
33
34 private class GestureListener extends GestureDetector.SimpleOnGestureListene r {
35 @Override
36 public boolean onDown(MotionEvent e) {
37 return true;
38 }
39
40 @Override
41 public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
42 if (Math.abs(velocityX) > Math.abs(velocityY)
43 && Math.abs(velocityX) > FLING_VELOCITY_THRESHOLD) {
44 if (velocityX > 0) {
45 // Fling right
46 onKeyPressed(mApplication.getNativeHandle(), KeyEvent.KEYCOD E_SOFT_RIGHT);
47 } else {
48 // Fling left
49 onKeyPressed(mApplication.getNativeHandle(), KeyEvent.KEYCOD E_SOFT_LEFT);
50 }
51 return true;
52 }
53 return false;
54 }
55 }
23 56
24 @Override 57 @Override
25 protected void onCreate(Bundle savedInstanceState) { 58 protected void onCreate(Bundle savedInstanceState) {
26 super.onCreate(savedInstanceState); 59 super.onCreate(savedInstanceState);
27 setContentView(R.layout.activity_main); 60 setContentView(R.layout.activity_main);
28 61
29 mApplication = (ViewerApplication) getApplication(); 62 mApplication = (ViewerApplication) getApplication();
30 mView = (SurfaceView) findViewById(R.id.surfaceView); 63 mView = (SurfaceView) findViewById(R.id.surfaceView);
31 mView.getHolder().addCallback(this); 64 mView.getHolder().addCallback(this);
65
66 mGestureDetector = new GestureDetector(getApplicationContext(), new Gest ureListener());
67 mView.setOnTouchListener(this);
32 } 68 }
33 69
34 @Override 70 @Override
35 public void surfaceCreated(SurfaceHolder holder) { 71 public void surfaceCreated(SurfaceHolder holder) {
36 if (mApplication.getNativeHandle() != 0) { 72 if (mApplication.getNativeHandle() != 0) {
37 onSurfaceCreated(mApplication.getNativeHandle(), holder.getSurface() ); 73 onSurfaceCreated(mApplication.getNativeHandle(), holder.getSurface() );
38 } 74 }
39 } 75 }
40 76
41 @Override 77 @Override
42 public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { 78 public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
43 if (mApplication.getNativeHandle() != 0) { 79 if (mApplication.getNativeHandle() != 0) {
44 onSurfaceChanged(mApplication.getNativeHandle(), holder.getSurface() ); 80 onSurfaceChanged(mApplication.getNativeHandle(), holder.getSurface() );
45 } 81 }
46 } 82 }
47 83
48 @Override 84 @Override
49 public void surfaceDestroyed(SurfaceHolder holder) { 85 public void surfaceDestroyed(SurfaceHolder holder) {
50 if (mApplication.getNativeHandle() != 0) { 86 if (mApplication.getNativeHandle() != 0) {
51 onSurfaceDestroyed(mApplication.getNativeHandle()); 87 onSurfaceDestroyed(mApplication.getNativeHandle());
52 } 88 }
53 } 89 }
90
91 @Override
92 public boolean onTouch(View v, MotionEvent event) {
93 return mGestureDetector.onTouchEvent(event);
94 }
54 } 95 }
OLDNEW
« no previous file with comments | « no previous file | tools/viewer/sk_app/Window.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698