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