diff options
author | Kjetil Ørbekk <kjetil.orbekk@gmail.com> | 2012-03-02 15:23:27 +0100 |
---|---|---|
committer | Kjetil Ørbekk <kjetil.orbekk@gmail.com> | 2012-03-02 15:23:27 +0100 |
commit | f48ad7f90ad1d494299b08f5e1866ccb63ee7b2d (patch) | |
tree | 00411d2561d7b3587a6ade03a8b018024760bfb6 /same-android/src/main/java/com | |
parent | 22c5f285c0e66e6b6439ca6237da3c7e955240c6 (diff) |
Change UI of main view.
Change from: Empty screen with menu used to pick activity.
To: ListView of available choices. User picks directly from main screen.
Diffstat (limited to 'same-android/src/main/java/com')
-rw-r--r-- | same-android/src/main/java/com/orbekk/same/MainActivity.java | 73 |
1 files changed, 43 insertions, 30 deletions
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(); } } |