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

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

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

Powered by Google App Engine
This is Rietveld 408576698