Use title buttons to switch slides
authorliyuqian <liyuqian@google.com>
Fri, 13 May 2016 13:45:21 +0000 (06:45 -0700)
committerCommit bot <commit-bot@chromium.org>
Fri, 13 May 2016 13:45:21 +0000 (06:45 -0700)
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1975723004

Review-Url: https://codereview.chromium.org/1975723004

platform_tools/android/apps/viewer/src/main/java/org/skia/viewer/ViewerActivity.java
platform_tools/android/apps/viewer/src/main/res/menu/title.xml [new file with mode: 0644]

index e115de6..e3260c2 100644 (file)
@@ -12,6 +12,9 @@ import android.os.Bundle;
 import android.util.Log;
 import android.view.GestureDetector;
 import android.view.KeyEvent;
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.MenuItem;
 import android.view.MotionEvent;
 import android.view.Surface;
 import android.view.SurfaceHolder;
@@ -24,33 +27,30 @@ public class ViewerActivity
 
     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 onCreateOptionsMenu(Menu menu) {
+        MenuInflater inflater = getMenuInflater();
+        inflater.inflate(R.menu.title, menu);
+        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
-                    onKeyPressed(mApplication.getNativeHandle(), KeyEvent.KEYCODE_SOFT_RIGHT);
-                } else {
-                    // Fling left
-                    onKeyPressed(mApplication.getNativeHandle(), KeyEvent.KEYCODE_SOFT_LEFT);
-                }
+    @Override
+    public boolean onOptionsItemSelected(MenuItem item) {
+        switch (item.getItemId()) {
+            case R.id.action_left:
+                onKeyPressed(mApplication.getNativeHandle(), KeyEvent.KEYCODE_SOFT_LEFT);
+                return true;
+            case R.id.action_right:
+                onKeyPressed(mApplication.getNativeHandle(), KeyEvent.KEYCODE_SOFT_RIGHT);
                 return true;
-            }
-            return false;
+            default:
+                return super.onOptionsItemSelected(item);
         }
     }
 
@@ -63,7 +63,6 @@ public class ViewerActivity
         mView = (SurfaceView) findViewById(R.id.surfaceView);
         mView.getHolder().addCallback(this);
 
-        mGestureDetector = new GestureDetector(getApplicationContext(), new GestureListener());
         mView.setOnTouchListener(this);
     }
 
@@ -90,6 +89,6 @@ public class ViewerActivity
 
     @Override
     public boolean onTouch(View v, MotionEvent event) {
-        return mGestureDetector.onTouchEvent(event);
+        return false; // TODO pass the touch event to native code
     }
 }
diff --git a/platform_tools/android/apps/viewer/src/main/res/menu/title.xml b/platform_tools/android/apps/viewer/src/main/res/menu/title.xml
new file mode 100644 (file)
index 0000000..57d04ef
--- /dev/null
@@ -0,0 +1,12 @@
+<menu xmlns:android="http://schemas.android.com/apk/res/android" >
+
+    <item
+        android:id="@+id/action_left"
+        android:icon="@android:drawable/ic_media_previous"
+        android:showAsAction="always"/>
+
+    <item android:id="@+id/action_right"
+        android:icon="@android:drawable/ic_media_next"
+        android:showAsAction="always"/>
+
+</menu>