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

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

Issue 2004633002: Add drawer with state information (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Merge 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 /* 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.content.res.Configuration;
11 import android.os.Bundle; 12 import android.os.Bundle;
12 import android.util.Log; 13 import android.support.v4.widget.DrawerLayout;
13 import android.view.GestureDetector; 14 import android.support.v7.app.ActionBarDrawerToggle;
14 import android.view.KeyEvent; 15 import android.view.KeyEvent;
15 import android.view.Menu; 16 import android.view.Menu;
16 import android.view.MenuInflater; 17 import android.view.MenuInflater;
17 import android.view.MenuItem; 18 import android.view.MenuItem;
18 import android.view.MotionEvent; 19 import android.view.MotionEvent;
19 import android.view.Surface; 20 import android.view.Surface;
20 import android.view.SurfaceHolder; 21 import android.view.SurfaceHolder;
21 import android.view.SurfaceView; 22 import android.view.SurfaceView;
22 import android.view.View; 23 import android.view.View;
24 import android.widget.ListView;
23 25
24 public class ViewerActivity 26 public class ViewerActivity
25 extends Activity implements SurfaceHolder.Callback, View.OnTouchListener { 27 extends Activity implements SurfaceHolder.Callback, View.OnTouchListener {
26 private static final float FLING_VELOCITY_THRESHOLD = 1000; 28 private static final float FLING_VELOCITY_THRESHOLD = 1000;
27 29
30 private DrawerLayout mDrawerLayout;
31 private ActionBarDrawerToggle mDrawerToggle;
32 private ListView mDrawerList;
33 private StateAdapter mStateAdapter;
34
28 private SurfaceView mView; 35 private SurfaceView mView;
29 private ViewerApplication mApplication; 36 private ViewerApplication mApplication;
30 37
31 private native void onSurfaceCreated(long handle, Surface surface); 38 private native void onSurfaceCreated(long handle, Surface surface);
32 private native void onSurfaceChanged(long handle, Surface surface); 39 private native void onSurfaceChanged(long handle, Surface surface);
33 private native void onSurfaceDestroyed(long handle); 40 private native void onSurfaceDestroyed(long handle);
34 private native void onKeyPressed(long handle, int keycode); 41 private native void onKeyPressed(long handle, int keycode);
35 private native void onTouched(long handle, int owner, int state, float x, fl oat y); 42 private native void onTouched(long handle, int owner, int state, float x, fl oat y);
43 private native void onUIStateChanged(long handle, String stateName, String s tateValue);
36 44
37 @Override 45 @Override
38 public boolean onCreateOptionsMenu(Menu menu) { 46 public boolean onCreateOptionsMenu(Menu menu) {
39 MenuInflater inflater = getMenuInflater(); 47 MenuInflater inflater = getMenuInflater();
40 inflater.inflate(R.menu.title, menu); 48 inflater.inflate(R.menu.title, menu);
41 return true; 49 return true;
42 } 50 }
43 51
44 @Override 52 @Override
45 public boolean onOptionsItemSelected(MenuItem item) { 53 public boolean onOptionsItemSelected(MenuItem item) {
54 // Pass the event to ActionBarDrawerToggle, if it returns
55 // true, then it has handled the app icon touch event
56 if (mDrawerToggle.onOptionsItemSelected(item)) {
57 return true;
58 }
59
46 switch (item.getItemId()) { 60 switch (item.getItemId()) {
47 case R.id.action_left: 61 case R.id.action_left:
48 onKeyPressed(mApplication.getNativeHandle(), KeyEvent.KEYCODE_SO FT_LEFT); 62 onKeyPressed(mApplication.getNativeHandle(), KeyEvent.KEYCODE_SO FT_LEFT);
49 return true; 63 return true;
50 case R.id.action_right: 64 case R.id.action_right:
51 onKeyPressed(mApplication.getNativeHandle(), KeyEvent.KEYCODE_SO FT_RIGHT); 65 onKeyPressed(mApplication.getNativeHandle(), KeyEvent.KEYCODE_SO FT_RIGHT);
52 return true; 66 return true;
53 default: 67 default:
54 return super.onOptionsItemSelected(item); 68 return super.onOptionsItemSelected(item);
55 } 69 }
56 } 70 }
57 71
58 @Override 72 @Override
59 protected void onCreate(Bundle savedInstanceState) { 73 protected void onCreate(Bundle savedInstanceState) {
60 super.onCreate(savedInstanceState); 74 super.onCreate(savedInstanceState);
61 setContentView(R.layout.activity_main); 75 setContentView(R.layout.activity_main);
62 76
63 mApplication = (ViewerApplication) getApplication();
64 mApplication.setViewerActivity(this);
65 mView = (SurfaceView) findViewById(R.id.surfaceView); 77 mView = (SurfaceView) findViewById(R.id.surfaceView);
66 mView.getHolder().addCallback(this); 78 mView.getHolder().addCallback(this);
67 79
68 mView.setOnTouchListener(this); 80 mView.setOnTouchListener(this);
81
82 mDrawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);
83 mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
84 R.string.drawer_open, R.string.drawer_close);
85 mDrawerLayout.addDrawerListener(mDrawerToggle);
86 getActionBar().setDisplayHomeAsUpEnabled(true);
87 getActionBar().setHomeButtonEnabled(true);
88
89 mDrawerList = (ListView) findViewById(R.id.leftDrawer);
90 mStateAdapter = new StateAdapter(this);
91 mDrawerList.setAdapter(mStateAdapter);
92
93 mApplication = (ViewerApplication) getApplication();
94 mApplication.setViewerActivity(this);
69 } 95 }
70 96
71 @Override 97 @Override
98 protected void onPostCreate(Bundle savedInstanceState) {
99 super.onPostCreate(savedInstanceState);
100 mDrawerToggle.syncState();
101 }
102
103 @Override
104 public void onConfigurationChanged(Configuration newConfig) {
105 super.onConfigurationChanged(newConfig);
106 mDrawerToggle.onConfigurationChanged(newConfig);
107 }
108
109 @Override
72 protected void onDestroy() { 110 protected void onDestroy() {
73 mApplication.setViewerActivity(null); 111 mApplication.setViewerActivity(null);
74 super.onDestroy(); 112 super.onDestroy();
75 } 113 }
76 114
77 @Override 115 @Override
78 public void surfaceCreated(SurfaceHolder holder) { 116 public void surfaceCreated(SurfaceHolder holder) {
79 if (mApplication.getNativeHandle() != 0) { 117 if (mApplication.getNativeHandle() != 0) {
80 onSurfaceCreated(mApplication.getNativeHandle(), holder.getSurface() ); 118 onSurfaceCreated(mApplication.getNativeHandle(), holder.getSurface() );
81 } 119 }
(...skipping 18 matching lines...) Expand all
100 int count = event.getPointerCount(); 138 int count = event.getPointerCount();
101 for (int i = 0; i < count; i++) { 139 for (int i = 0; i < count; i++) {
102 final float x = event.getX(i); 140 final float x = event.getX(i);
103 final float y = event.getY(i); 141 final float y = event.getY(i);
104 final int owner = event.getPointerId(i); 142 final int owner = event.getPointerId(i);
105 int action = event.getAction() & MotionEvent.ACTION_MASK; 143 int action = event.getAction() & MotionEvent.ACTION_MASK;
106 onTouched(mApplication.getNativeHandle(), owner, action, x, y); 144 onTouched(mApplication.getNativeHandle(), owner, action, x, y);
107 } 145 }
108 return true; 146 return true;
109 } 147 }
148
149 public void setState(String stateJson) {
150 mStateAdapter.setState(stateJson);
151 }
152
153 public void onStateChanged(String stateName, String stateValue) {
154 onUIStateChanged(mApplication.getNativeHandle(), stateName, stateValue);
155 }
110 } 156 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698