aboutsummaryrefslogtreecommitdiffhomepage
path: root/platform_tools/android/apps
diff options
context:
space:
mode:
authorGravatar liyuqian <liyuqian@google.com>2016-06-17 11:04:44 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-06-17 11:04:44 -0700
commitea1fb74389e9470a3de988fd7fa478cff5ae8c07 (patch)
treeca914757b1a1205a176b193e4a37dd602ecac4fc /platform_tools/android/apps
parent063ece71848fadc963cbac5c978cd48262138131 (diff)
Keep drawer open in xlarge-land and add float fps
Diffstat (limited to 'platform_tools/android/apps')
-rw-r--r--platform_tools/android/apps/viewer/src/main/java/org/skia/viewer/StateAdapter.java59
-rw-r--r--platform_tools/android/apps/viewer/src/main/java/org/skia/viewer/ViewerActivity.java22
-rw-r--r--platform_tools/android/apps/viewer/src/main/res/layout-xlarge-land/activity_main.xml54
-rw-r--r--platform_tools/android/apps/viewer/src/main/res/layout/activity_main.xml39
-rw-r--r--platform_tools/android/apps/viewer/src/main/res/layout/fps_toggle.xml23
-rw-r--r--platform_tools/android/apps/viewer/src/main/res/values/strings.xml1
6 files changed, 165 insertions, 33 deletions
diff --git a/platform_tools/android/apps/viewer/src/main/java/org/skia/viewer/StateAdapter.java b/platform_tools/android/apps/viewer/src/main/java/org/skia/viewer/StateAdapter.java
index ba5407984b..6c080bd214 100644
--- a/platform_tools/android/apps/viewer/src/main/java/org/skia/viewer/StateAdapter.java
+++ b/platform_tools/android/apps/viewer/src/main/java/org/skia/viewer/StateAdapter.java
@@ -8,9 +8,11 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
+import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.Spinner;
+import android.widget.Switch;
import android.widget.TextView;
import org.json.JSONArray;
@@ -30,18 +32,21 @@ import java.util.ArrayList;
Within that LinearLayout, we maintain views ourselves so we can efficiently update its children.
*/
public class StateAdapter extends BaseAdapter implements AdapterView.OnItemSelectedListener {
- static final String NAME = "name";
- static final String VALUE = "value";
- static final String OPTIONS = "options";
+ private static final String NAME = "name";
+ private static final String VALUE = "value";
+ private static final String OPTIONS = "options";
private static final String BACKEND_STATE_NAME = "Backend";
+ private static final String FPS_STATE_NAME = "FPS";
private static final int FILTER_LENGTH = 20;
- ViewerActivity mViewerActivity;
- LinearLayout mLayout;
- JSONArray mStateJson;
+ private ViewerActivity mViewerActivity;
+ private LinearLayout mLayout;
+ private JSONArray mStateJson;
+ private TextView mFPSFloatText;
public StateAdapter(ViewerActivity viewerActivity) {
mViewerActivity = viewerActivity;
+ mFPSFloatText = (TextView) viewerActivity.findViewById(R.id.fpsFloatText);
try {
mStateJson = new JSONArray("[{\"name\": \"Please\", " +
"\"value\": \"Initialize\", \"options\": []}]");
@@ -63,9 +68,11 @@ public class StateAdapter extends BaseAdapter implements AdapterView.OnItemSelec
}
}
+ // The first list item is the mLayout that contains a list of state items
+ // The second list item is the toggle for float FPS
@Override
public int getCount() {
- return 1;
+ return 2;
}
@Override
@@ -80,21 +87,47 @@ public class StateAdapter extends BaseAdapter implements AdapterView.OnItemSelec
@Override
public View getView(int position, View convertView, ViewGroup parent) {
- if (mLayout == null) {
- mLayout = new LinearLayout(mViewerActivity);
- mLayout.setOrientation(LinearLayout.VERTICAL);
- updateDrawer();
+ switch (position) {
+ case 0: {
+ if (mLayout == null) {
+ mLayout = new LinearLayout(mViewerActivity);
+ mLayout.setOrientation(LinearLayout.VERTICAL);
+ updateDrawer();
+ }
+ return mLayout;
+ }
+ case 1: {
+ View view = LayoutInflater.from(mViewerActivity).inflate(R.layout.fps_toggle, null);
+ Switch theSwitch = (Switch) view.findViewById(R.id.theSwitch);
+ theSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener(){
+ @Override
+ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
+ mFPSFloatText.setVisibility(isChecked ? View.VISIBLE : View.INVISIBLE);
+ }
+ });
+ return view;
+ }
+ default: {
+ return null;
+ }
}
- return mLayout;
}
private View inflateItemView(JSONObject item) throws JSONException {
- LinearLayout itemView = (LinearLayout) LayoutInflater.from(mViewerActivity).inflate(R.layout.state_item, null);
+ LinearLayout itemView = (LinearLayout)
+ LayoutInflater.from(mViewerActivity).inflate(R.layout.state_item, null);
TextView nameText = (TextView) itemView.findViewById(R.id.nameText);
TextView valueText = (TextView) itemView.findViewById(R.id.valueText);
Spinner optionSpinner = (Spinner) itemView.findViewById(R.id.optionSpinner);
nameText.setText(item.getString(NAME));
String value = item.getString(VALUE);
+
+ if (nameText.getText().equals(FPS_STATE_NAME) && mFPSFloatText != null) {
+ mFPSFloatText.setText(value);
+ // Don't show FPS in the drawer. We'll show it in the float text.
+ itemView.setVisibility(View.GONE);
+ }
+
JSONArray options = item.getJSONArray(OPTIONS);
if (options.length() == 0) {
valueText.setText(value);
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 0291f5e291..ea610397b9 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
@@ -52,7 +52,7 @@ public class ViewerActivity
public boolean onOptionsItemSelected(MenuItem item) {
// Pass the event to ActionBarDrawerToggle, if it returns
// true, then it has handled the app icon touch event
- if (mDrawerToggle.onOptionsItemSelected(item)) {
+ if (mDrawerToggle != null && mDrawerToggle.onOptionsItemSelected(item)) {
return true;
}
@@ -78,11 +78,13 @@ public class ViewerActivity
surfaceView.setOnTouchListener(this);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);
- mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
- R.string.drawer_open, R.string.drawer_close);
- mDrawerLayout.addDrawerListener(mDrawerToggle);
- getActionBar().setDisplayHomeAsUpEnabled(true);
- getActionBar().setHomeButtonEnabled(true);
+ if (mDrawerLayout != null) { // xlarge-land has no drawer layout (drawer is always open)
+ mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
+ R.string.drawer_open, R.string.drawer_close);
+ mDrawerLayout.addDrawerListener(mDrawerToggle);
+ getActionBar().setDisplayHomeAsUpEnabled(true);
+ getActionBar().setHomeButtonEnabled(true);
+ }
mDrawerList = (ListView) findViewById(R.id.leftDrawer);
mStateAdapter = new StateAdapter(this);
@@ -95,13 +97,17 @@ public class ViewerActivity
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
- mDrawerToggle.syncState();
+ if (mDrawerToggle != null) {
+ mDrawerToggle.syncState();
+ }
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
- mDrawerToggle.onConfigurationChanged(newConfig);
+ if (mDrawerToggle != null) {
+ mDrawerToggle.onConfigurationChanged(newConfig);
+ }
}
@Override
diff --git a/platform_tools/android/apps/viewer/src/main/res/layout-xlarge-land/activity_main.xml b/platform_tools/android/apps/viewer/src/main/res/layout-xlarge-land/activity_main.xml
new file mode 100644
index 0000000000..b78112dc52
--- /dev/null
+++ b/platform_tools/android/apps/viewer/src/main/res/layout-xlarge-land/activity_main.xml
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<LinearLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="horizontal"
+ android:layout_width="match_parent"
+ android:background="@android:color/darker_gray"
+ android:layout_height="match_parent">
+
+ <!-- The navigation drawer that's always open -->
+ <ListView android:id="@+id/leftDrawer"
+ android:layout_width="240dp"
+ android:layout_height="match_parent"
+ android:layout_gravity="start"
+ android:choiceMode="singleChoice"
+ android:divider="@android:color/transparent"
+ android:dividerHeight="0dp"
+ android:layout_marginRight="5dp"
+ android:background="@android:color/background_light"/>
+
+ <!-- The main content view -->
+ <RelativeLayout
+ android:layout_width="match_parent"
+ android:layout_height="match_parent">
+
+ <!-- We use mainLayout for recreating SurfaceView -->
+ <LinearLayout
+ android:id="@+id/mainLayout"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent">
+ <SurfaceView
+ android:id="@+id/surfaceView"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:layout_centerVertical="true"
+ android:layout_centerHorizontal="true" />
+ </LinearLayout>
+
+ <TextView
+ android:visibility="invisible"
+ android:layout_width="100dp"
+ android:layout_height="wrap_content"
+ android:layout_margin="10dp"
+ android:padding="10dp"
+ android:background="@android:color/holo_blue_dark"
+ android:textColor="@android:color/white"
+ android:text=" 100.000ms"
+ android:id="@+id/fpsFloatText"
+ android:layout_alignParentBottom="true"
+ android:layout_alignParentEnd="true" />
+ </RelativeLayout>
+
+</LinearLayout>
+
diff --git a/platform_tools/android/apps/viewer/src/main/res/layout/activity_main.xml b/platform_tools/android/apps/viewer/src/main/res/layout/activity_main.xml
index 985b67d085..7041d0e8ed 100644
--- a/platform_tools/android/apps/viewer/src/main/res/layout/activity_main.xml
+++ b/platform_tools/android/apps/viewer/src/main/res/layout/activity_main.xml
@@ -6,22 +6,37 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- The main content view -->
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:id="@+id/mainLayout"
- android:orientation="vertical"
+ <RelativeLayout
android:layout_width="match_parent"
- android:layout_height="match_parent"
- tools:context=".ViewerActivity">
+ android:layout_height="match_parent">
- <SurfaceView
- android:id="@+id/surfaceView"
+ <!-- We use mainLayout for recreating SurfaceView -->
+ <LinearLayout
+ android:id="@+id/mainLayout"
android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_centerVertical="true"
- android:layout_centerHorizontal="true" />
+ android:layout_height="match_parent">
+ <SurfaceView
+ android:id="@+id/surfaceView"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:layout_centerVertical="true"
+ android:layout_centerHorizontal="true" />
+ </LinearLayout>
+
+ <TextView
+ android:layout_width="100dp"
+ android:layout_height="wrap_content"
+ android:layout_margin="10dp"
+ android:padding="10dp"
+ android:background="@android:color/holo_blue_dark"
+ android:textColor="@android:color/white"
+ android:text=" 100.000ms"
+ android:id="@+id/fpsFloatText"
+ android:visibility="invisible"
+ android:layout_alignParentBottom="true"
+ android:layout_alignParentEnd="true" />
- </LinearLayout>
+ </RelativeLayout>
<!-- The navigation drawer -->
<ListView android:id="@+id/leftDrawer"
diff --git a/platform_tools/android/apps/viewer/src/main/res/layout/fps_toggle.xml b/platform_tools/android/apps/viewer/src/main/res/layout/fps_toggle.xml
new file mode 100644
index 0000000000..4463629ab7
--- /dev/null
+++ b/platform_tools/android/apps/viewer/src/main/res/layout/fps_toggle.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content">
+
+ <TextView
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="10dp"
+ android:layout_marginLeft="10dp"
+ android:layout_marginBottom="0dp"
+ android:textAppearance="?android:attr/textAppearanceLarge"
+ android:text="@string/float_fps" />
+
+ <Switch
+ android:id="@+id/theSwitch"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginBottom="10dp"
+ android:layout_marginLeft="10dp"
+ android:layout_marginTop="0dp" />
+</LinearLayout> \ No newline at end of file
diff --git a/platform_tools/android/apps/viewer/src/main/res/values/strings.xml b/platform_tools/android/apps/viewer/src/main/res/values/strings.xml
index 582c566679..5e218af9e3 100644
--- a/platform_tools/android/apps/viewer/src/main/res/values/strings.xml
+++ b/platform_tools/android/apps/viewer/src/main/res/values/strings.xml
@@ -2,4 +2,5 @@
<resources>
<string name="drawer_open">Open navigation drawer</string>
<string name="drawer_close">Close navigation drawer</string>
+ <string name="float_fps">Render time</string>
</resources> \ No newline at end of file