Keep drawer open in xlarge-land and add float fps
authorliyuqian <liyuqian@google.com>
Fri, 17 Jun 2016 18:04:44 +0000 (11:04 -0700)
committerCommit bot <commit-bot@chromium.org>
Fri, 17 Jun 2016 18:04:44 +0000 (11:04 -0700)
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2071333002

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

platform_tools/android/apps/viewer/src/main/java/org/skia/viewer/StateAdapter.java
platform_tools/android/apps/viewer/src/main/java/org/skia/viewer/ViewerActivity.java
platform_tools/android/apps/viewer/src/main/res/layout-xlarge-land/activity_main.xml [new file with mode: 0644]
platform_tools/android/apps/viewer/src/main/res/layout/activity_main.xml
platform_tools/android/apps/viewer/src/main/res/layout/fps_toggle.xml [new file with mode: 0644]
platform_tools/android/apps/viewer/src/main/res/values/strings.xml

index ba54079..6c080bd 100644 (file)
@@ -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);
index 0291f5e..ea61039 100644 (file)
@@ -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 (file)
index 0000000..b78112d
--- /dev/null
@@ -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>
+
index 985b67d..7041d0e 100644 (file)
@@ -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 (file)
index 0000000..4463629
--- /dev/null
@@ -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
index 582c566..5e218af 100644 (file)
@@ -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