/there/src/com/google/marvin/there/There.java

http://eyes-free.googlecode.com/ · Java · 85 lines · 65 code · 19 blank · 1 comment · 1 complexity · c61b0c689c827547bb902334f6bc44e6 MD5 · raw file

  1. package com.google.marvin.there;
  2. import com.google.tts.TTS;
  3. import android.app.Activity;
  4. import android.content.Intent;
  5. import android.database.Cursor;
  6. import android.os.Bundle;
  7. import android.view.Menu;
  8. import android.view.MenuItem;
  9. import android.view.View;
  10. import android.widget.AdapterView;
  11. import android.widget.ListView;
  12. import android.widget.SimpleCursorAdapter;
  13. import android.widget.TextView;
  14. import android.widget.AdapterView.OnItemClickListener;
  15. public class There extends Activity {
  16. private There self;
  17. public TTS tts;
  18. private DbManager db;
  19. private ListView placesListView;
  20. /** Called when the activity is first created. */
  21. @Override
  22. public void onCreate(Bundle savedInstanceState) {
  23. super.onCreate(savedInstanceState);
  24. self = this;
  25. db = new DbManager(this);
  26. }
  27. @Override
  28. public void onResume(){
  29. super.onResume();
  30. refreshLocationsList();
  31. }
  32. private void refreshLocationsList() {
  33. placesListView = null;
  34. placesListView = new ListView(this);
  35. String[] from = new String[] {"Name"};
  36. int[] to = new int[] {R.id.text1};
  37. Cursor c = db.getCursor();
  38. startManagingCursor(c);
  39. SimpleCursorAdapter cAdapter = new SimpleCursorAdapter(this, R.layout.place, c, from, to);
  40. placesListView.setAdapter(cAdapter);
  41. placesListView.setOnItemClickListener(new OnItemClickListener(){
  42. public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
  43. Intent intent = new Intent(self, NavigationActivity.class);
  44. intent.putExtra("DESTINATION", ((TextView)arg1).getText());
  45. startActivity(intent);
  46. }
  47. });
  48. setContentView(placesListView);
  49. }
  50. @Override
  51. public boolean onCreateOptionsMenu(Menu menu) {
  52. menu.add(0, 0, 0, "Mark current location").setIcon(
  53. android.R.drawable.ic_menu_edit);
  54. return super.onCreateOptionsMenu(menu);
  55. }
  56. @Override
  57. public boolean onOptionsItemSelected(MenuItem item) {
  58. switch (item.getItemId()) {
  59. case 0:
  60. Intent intent = new Intent(this, SetLocationForm.class);
  61. startActivity(intent);
  62. break;
  63. }
  64. return super.onOptionsItemSelected(item);
  65. }
  66. }