summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--same-android/res/layout/main.xml11
-rw-r--r--same-android/res/menu/main_menu.xml22
-rw-r--r--same-android/src/main/java/com/orbekk/same/MainActivity.java73
3 files changed, 48 insertions, 58 deletions
diff --git a/same-android/res/layout/main.xml b/same-android/res/layout/main.xml
index f6f0090..77e35b2 100644
--- a/same-android/res/layout/main.xml
+++ b/same-android/res/layout/main.xml
@@ -4,11 +4,10 @@
android:layout_height="fill_parent"
android:orientation="vertical" >
- <TextView
- android:id="@+id/textView1"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="See menu."
- android:textAppearance="?android:attr/textAppearanceLarge" />
+ <ListView
+ android:id="@+id/activities_menu"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content" >
+ </ListView>
</LinearLayout> \ No newline at end of file
diff --git a/same-android/res/menu/main_menu.xml b/same-android/res/menu/main_menu.xml
deleted file mode 100644
index 342ca60..0000000
--- a/same-android/res/menu/main_menu.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<menu xmlns:android="http://schemas.android.com/apk/res/android" >
-
- <item
- android:id="@+id/same_settings"
- android:title="Same settings"/>
- <item
- android:id="@+id/variable_test"
- android:title="Variable Test"/>
- <item
- android:id="@+id/state_viewer"
- android:title="State Monitor"/>
-
- <item
- android:id="@+id/graphics_demo"
- android:title="Graphics demo"/>
-
- <item
- android:id="@+id/benchmark"
- android:title="Benchmark"/>
-
-</menu> \ No newline at end of file
diff --git a/same-android/src/main/java/com/orbekk/same/MainActivity.java b/same-android/src/main/java/com/orbekk/same/MainActivity.java
index 5d76c1e..e9f7498 100644
--- a/same-android/src/main/java/com/orbekk/same/MainActivity.java
+++ b/same-android/src/main/java/com/orbekk/same/MainActivity.java
@@ -1,51 +1,64 @@
package com.orbekk.same;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.orbekk.same.android.benchmark.RepeatedSetVariableActivity;
-
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
+import android.view.View;
+import android.widget.Adapter;
+import android.widget.AdapterView;
+import android.widget.ArrayAdapter;
+import android.widget.ListView;
+
+import com.orbekk.same.android.benchmark.RepeatedSetVariableActivity;
public class MainActivity extends Activity {
Logger logger = LoggerFactory.getLogger(getClass());
- @Override public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
+ public final static Map<String, Class<? extends Activity>> activities;
+ static {
+ activities = new HashMap<String, Class<? extends Activity>>();
+ activities.put("Same settings", SameControllerActivity.class);
+ activities.put("Variable test", VariableTestActivity.class);
+ activities.put("State monitor", StateViewerActivity.class);
+ activities.put("Graphics demo", GraphicsActivity.class);
+ activities.put("Benchmark", RepeatedSetVariableActivity.class);
}
- @Override public boolean onCreateOptionsMenu(Menu menu) {
- MenuInflater inflater = getMenuInflater();
- inflater.inflate(R.menu.main_menu, menu);
- return true;
+ public final static List<String> activityList =
+ new ArrayList<String>(activities.keySet());
+
+ private AdapterView.OnItemClickListener activityListClickListener =
+ new AdapterView.OnItemClickListener() {
+ @Override
+ public void onItemClick(AdapterView<?> unused_parent, View unused_view,
+ int position, long id) {
+ String activityName = activityList.get(position);
+ Class<? extends Activity> activity = activities.get(activityName);
+ startActivity(new Intent(MainActivity.this, activity));
+ }
+ };
+
+ private void createActivityList() {
+ ListView list = (ListView)findViewById(R.id.activities_menu);
+ list.setAdapter(new ArrayAdapter<String>(
+ this, R.layout.list_text_item, activityList));
+ list.setOnItemClickListener(activityListClickListener);
}
- @Override public boolean onOptionsItemSelected(MenuItem item) {
- int id = item.getItemId();
- switch (id) {
- case R.id.same_settings:
- startActivity(new Intent(this, SameControllerActivity.class));
- break;
- case R.id.variable_test:
- startActivity(new Intent(this, VariableTestActivity.class));
- break;
- case R.id.state_viewer:
- startActivity(new Intent(this, StateViewerActivity.class));
- break;
- case R.id.graphics_demo:
- startActivity(new Intent(this, GraphicsActivity.class));
- break;
- case R.id.benchmark:
- startActivity(new Intent(this, RepeatedSetVariableActivity.class));
- default:
- logger.error("Unknown menu entry: {}", item);
- }
- return true;
+ @Override public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.main);
+ createActivityList();
}
}