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;
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\": []}]");
}
}
+ // 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
@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);
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;
}
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);
@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
--- /dev/null
+<?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>
+
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"
--- /dev/null
+<?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
<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