Search in sources :

Example 1 with AppDatabase

use of com.sleepycookie.stillstanding.data.AppDatabase in project stillStanding by katsik.

the class IncidentHistory method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    setTheme(R.style.AppTheme);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_history);
    // Get a support ActionBar corresponding to this toolbar
    ActionBar ab = getSupportActionBar();
    // Enable the Up button
    ab.setDisplayHomeAsUpEnabled(true);
    AppDatabase db = AppDatabase.getInstance(this);
    final ArrayList<Incident> incidents = new ArrayList<Incident>();
    Collections.addAll(incidents, db.incidentDao().loadAllIncidents());
    IncidentAdapter adapter = new IncidentAdapter(this, incidents);
    ListView listView = (ListView) findViewById(R.id.history);
    listView.setAdapter(adapter);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            long viewId = view.getId();
            if (viewId == R.id.incident_location) {
                Incident tempIncident = incidents.get(position);
                StringBuffer url = new StringBuffer();
                url.append("http://maps.google.com?q=");
                url.append(String.format("%.7f", tempIncident.getLatitude()));
                url.append(",");
                url.append(String.format("%.7f", tempIncident.getLongitude()));
                Intent i = new Intent(Intent.ACTION_VIEW);
                i.setData(Uri.parse(url.toString()));
                startActivity(i);
            } else if (viewId == R.id.list_item) {
            }
        }
    });
}
Also used : ArrayList(java.util.ArrayList) Intent(android.content.Intent) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) ListView(android.widget.ListView) AppDatabase(com.sleepycookie.stillstanding.data.AppDatabase) AdapterView(android.widget.AdapterView) Incident(com.sleepycookie.stillstanding.data.Incident) ActionBar(android.support.v7.app.ActionBar)

Aggregations

Intent (android.content.Intent)1 ActionBar (android.support.v7.app.ActionBar)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 ListView (android.widget.ListView)1 AppDatabase (com.sleepycookie.stillstanding.data.AppDatabase)1 Incident (com.sleepycookie.stillstanding.data.Incident)1 ArrayList (java.util.ArrayList)1