Android Open Source - android-accelerometer-gps Days Activity






From Project

Back to project page android-accelerometer-gps.

License

The source code is released under:

MIT License

If you think the Android project android-accelerometer-gps listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.szlosek.whenmoving;
/*from www .  ja  v a  2 s  .  co m*/

import android.app.ListActivity;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.os.Bundle;
import android.view.View;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.util.Log;


public class DaysActivity extends ListActivity {

  SQLiteOpenHelper dbHelper;
  SQLiteDatabase db;

  @Override
  protected void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);

    // We'll define a custom screen layout here (the one shown above), but
    // typically, you could just use the standard ListActivity layout.
    //setContentView(R.layout.days_list_item);
    
    SQLiteOpenHelper dbHelper = new DatabaseHelper(this);
    SQLiteDatabase db = dbHelper.getReadableDatabase();
    // Get each day
    Cursor c = db.rawQuery("select day as _id, count(milliseconds) as points from locations group by day order by day desc", null);
    startManagingCursor(c);

    // Now create a new list adapter bound to the cursor.
    // SimpleListAdapter is designed for binding to a Cursor.
    ListAdapter adapter = new SimpleCursorAdapter(
      this,
      R.layout.days_list_item,
      c,
      // Array of cursor columns to bind to.
      new String[] {
        "_id",
        "points"
      },
      // corresponding fields in template
      new int[] {R.id.text1, R.id.text2}
    );
    setListAdapter(adapter);
  }

  @Override
  protected void onListItemClick (ListView l, View v, int position, long id) {
    Cursor c;
    Intent intent = new Intent();
    intent.putExtra("id", id);
    setResult(ListActivity.RESULT_OK, intent);
    finish();
  }
  
  @Override
  protected void onDestroy() {
    super.onDestroy();
    if (db != null) db.close();
  }
}




Java Source Code List

com.szlosek.whenmoving.CalibrationActivity.java
com.szlosek.whenmoving.CircularBuffer.java
com.szlosek.whenmoving.DatabaseHelper.java
com.szlosek.whenmoving.DaysActivity.java
com.szlosek.whenmoving.MainActivity.java
com.szlosek.whenmoving.MainApplication.java
com.szlosek.whenmoving.MainReceiver.java
com.szlosek.whenmoving.MainService.java
com.szlosek.whenmoving.SettingsActivity.java
com.szlosek.whenmoving.TimeoutReceiver.java