Chromium Code Reviews| Index: platform_tools/android/apps/viewer/src/main/java/org/skia/viewer/ViewerActivity.java |
| diff --git a/platform_tools/android/apps/viewer/src/main/java/org/skia/viewer/ViewerActivity.java b/platform_tools/android/apps/viewer/src/main/java/org/skia/viewer/ViewerActivity.java |
| index 48cec39f483d658970297cc17813b460b75dc53b..e59b4150c21c380a6eda11af149ba7488163fc72 100644 |
| --- a/platform_tools/android/apps/viewer/src/main/java/org/skia/viewer/ViewerActivity.java |
| +++ b/platform_tools/android/apps/viewer/src/main/java/org/skia/viewer/ViewerActivity.java |
| @@ -9,17 +9,52 @@ package org.skia.viewer; |
| import android.app.Activity; |
| import android.os.Bundle; |
| +import android.util.Log; |
| +import android.view.GestureDetector; |
| +import android.view.KeyEvent; |
| +import android.view.MotionEvent; |
| import android.view.Surface; |
| import android.view.SurfaceHolder; |
| import android.view.SurfaceView; |
| +import android.view.View; |
| + |
| +public class ViewerActivity |
| + extends Activity implements SurfaceHolder.Callback, View.OnTouchListener { |
|
djsollen
2016/05/11 19:05:25
this line should be indented by 8 spaces since it
liyuqian
2016/05/11 19:11:24
Done.
|
| + private static final float FLING_VELOCITY_THRESHOLD = 1000; |
| -public class ViewerActivity extends Activity implements SurfaceHolder.Callback { |
| private SurfaceView mView; |
| private ViewerApplication mApplication; |
| + private GestureDetector mGestureDetector; |
| private native void onSurfaceCreated(long handle, Surface surface); |
| private native void onSurfaceChanged(long handle, Surface surface); |
| private native void onSurfaceDestroyed(long handle); |
| + private native void onKeyPressed(long handle, int keycode); |
| + |
| + private class GestureListener extends GestureDetector.SimpleOnGestureListener { |
| + @Override |
| + public boolean onDown(MotionEvent e) { |
| + return true; |
| + } |
| + |
| + @Override |
| + public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { |
| + if (Math.abs(velocityX) > Math.abs(velocityY) |
| + && Math.abs(velocityX) > FLING_VELOCITY_THRESHOLD) { |
| + if (velocityX > 0) { |
| + // Fling right |
| + Log.d("test", "fling right, velocity = " + velocityX); |
|
djsollen
2016/05/11 19:05:25
remove the logging
liyuqian
2016/05/11 19:11:24
Done.
|
| + onKeyPressed(mApplication.getNativeHandle(), KeyEvent.KEYCODE_SOFT_RIGHT); |
| + } else { |
| + // Fling left |
| + Log.d("test", "fling left, velocity = " + velocityX); |
| + onKeyPressed(mApplication.getNativeHandle(), KeyEvent.KEYCODE_SOFT_LEFT); |
| + } |
| + return true; |
| + } |
| + return false; |
| + } |
| + } |
| @Override |
| protected void onCreate(Bundle savedInstanceState) { |
| @@ -29,6 +64,9 @@ public class ViewerActivity extends Activity implements SurfaceHolder.Callback { |
| mApplication = (ViewerApplication) getApplication(); |
| mView = (SurfaceView) findViewById(R.id.surfaceView); |
| mView.getHolder().addCallback(this); |
| + |
| + mGestureDetector = new GestureDetector(getApplicationContext(), new GestureListener()); |
| + mView.setOnTouchListener(this); |
| } |
| @Override |
| @@ -51,4 +89,9 @@ public class ViewerActivity extends Activity implements SurfaceHolder.Callback { |
| onSurfaceDestroyed(mApplication.getNativeHandle()); |
| } |
| } |
| + |
| + @Override |
| + public boolean onTouch(View v, MotionEvent event) { |
| + return mGestureDetector.onTouchEvent(event); |
| + } |
| } |