Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 3 commits
  • 4 files changed
  • 0 comments
  • 1 contributor
2  AndroidManifest.xml
@@ -29,7 +29,7 @@
29 29 <activity
30 30 android:label="@string/app_name"
31 31 android:name=".ITNLocationListView"
32   - android:theme="@android:style/Theme.Light.NoTitleBar" />
  32 + android:theme="@android:style/Theme.Light" />
33 33
34 34 </application>
35 35
4 res/layout/googlemaps.xml
@@ -5,4 +5,6 @@
5 5 android:layout_width="fill_parent"
6 6 android:layout_height="fill_parent"
7 7 android:clickable="true"
8   - android:apiKey="0H9O8FHhvk4rTjRQlyuxxOmiuzkKOAK-uyHfOQw" />
  8 + android:apiKey="0H9O8FHhvk4rTjRQlyuxxOmiuzkKOAK-uyHfOQw" />
  9 +
  10 + <!-- Remember to replace Debug key with App key. -->
36 src/hfoster/android/inthenear/db/ITNDatabaseHelper.java
... ... @@ -0,0 +1,36 @@
  1 +package hfoster.android.inthenear.db;
  2 +
  3 +import android.content.Context;
  4 +import android.database.sqlite.SQLiteDatabase;
  5 +import android.database.sqlite.SQLiteOpenHelper;
  6 +import android.util.Log;
  7 +
  8 +public class ITNDatabaseHelper extends SQLiteOpenHelper {
  9 +
  10 + private static final String DATABASE_NAME = "inthenear_applicationdata";
  11 + private static final int DATABASE_VERSION = 1;
  12 + // DB creation SQL statement -- creates two tables; location and point_of_interest
  13 + private static final String DATABASE_CREATE = "create table location (id integer primary key autoincrement, label text not null, longitude numeric not null, latitude numeric not null);"
  14 + + "create table point_of_interest (id integer primary key autoincrement, label text not null, longitude numeric not null, latitude numeric not null, loc_id integer not null);";
  15 +
  16 + public ITNDatabaseHelper(Context context) {
  17 + super(context, DATABASE_NAME, null, DATABASE_VERSION);
  18 + }
  19 +
  20 + // Called during DB creation
  21 + @Override
  22 + public void onCreate(SQLiteDatabase database) {
  23 + database.execSQL(DATABASE_CREATE);
  24 + }
  25 +
  26 + // Called during DB upgrade - i.e. when DATABASE_VERSION is incremented
  27 + @Override
  28 + public void onUpgrade(SQLiteDatabase database, int oldVersion, int newVersion) {
  29 + Log.w(ITNDatabaseHelper.class.getName(), "Upgrade database from version " + oldVersion + " to "
  30 + + newVersion + ", which will destroy all old data.");
  31 + database.execSQL("DROP TABLE IF EXISTS location");
  32 + database.execSQL("DROP TABLE IF EXISTS point_of_interest");
  33 + onCreate(database);
  34 + }
  35 +
  36 +}
121 src/hfoster/android/inthenear/db/ITNDbAdapter.java
... ... @@ -0,0 +1,121 @@
  1 +package hfoster.android.inthenear.db;
  2 +
  3 +import android.content.ContentValues;
  4 +import android.content.Context;
  5 +import android.database.Cursor;
  6 +import android.database.SQLException;
  7 +import android.database.sqlite.SQLiteDatabase;
  8 +
  9 +public class ITNDbAdapter {
  10 +
  11 + // Database fields
  12 + public static final String KEY_ID = "id";
  13 + public static final String KEY_LABEL = "label";
  14 + public static final String KEY_LONGITUDE = "longitude";
  15 + public static final String KEY_LATITUDE = "latitude";
  16 + public static final String KEY_LOC_ID = "loc_id";
  17 + private static final String T1_DATABASE_TABLE = "location";
  18 + private static final String T2_DATABASE_TABLE = "point_of_interest";
  19 + private Context context;
  20 + private SQLiteDatabase database;
  21 + private ITNDatabaseHelper dbHelper;
  22 +
  23 + public ITNDbAdapter(Context context) {
  24 + this.context = context;
  25 + }
  26 +
  27 + public ITNDbAdapter open() throws SQLException {
  28 + dbHelper = new ITNDatabaseHelper(context);
  29 + database = dbHelper.getWritableDatabase();
  30 + return this;
  31 + }
  32 +
  33 + public void close() {
  34 + dbHelper.close();
  35 + }
  36 +
  37 + /*
  38 + * Create new row. If successful, return the new row ID. Otherwise return -1.
  39 + */
  40 + public long createRow(String label, double longitude, double latitude, String table) {
  41 + ContentValues initialValues = createContentValues(label, longitude, latitude);
  42 + return database.insert(table, null, initialValues);
  43 + }
  44 +
  45 + public long createRow(String label, double longitude, double latitude, int locId, String table) {
  46 + ContentValues initialValues = createContentValues(label, longitude, latitude, locId);
  47 + return database.insert(table, null, initialValues);
  48 + }
  49 +
  50 + /*
  51 + * Update a row.
  52 + */
  53 + public boolean updateRow(long rowId, String label, double longitude, double latitude, String table) {
  54 + ContentValues updateValues = createContentValues(label, longitude, latitude);
  55 + return database.update(table, updateValues, KEY_ID + "=" + rowId, null) > 0;
  56 + }
  57 +
  58 + /*
  59 + * Delete a row.
  60 + */
  61 + public boolean deleteRow(long rowId, String table) {
  62 + return database.delete(table, KEY_ID + "=" + rowId, null) > 0;
  63 + }
  64 +
  65 + /*
  66 + * Return Cursor over all Locations.
  67 + */
  68 + public Cursor fetchAllLocations() {
  69 + return database.query(T1_DATABASE_TABLE, new String[] { KEY_ID, KEY_LABEL, KEY_LONGITUDE, KEY_LATITUDE },
  70 + null, null, null, null, null);
  71 + }
  72 +
  73 + /*
  74 + * Return Cursor over all points of interest.
  75 + */
  76 + public Cursor fetchAllPointOfInterest() {
  77 + return database.query(T2_DATABASE_TABLE, new String[] { KEY_ID, KEY_LABEL, KEY_LONGITUDE, KEY_LATITUDE, KEY_LOC_ID },
  78 + null, null, null, null, null);
  79 + }
  80 +
  81 + /*
  82 + * Return Cursor positioned at defined Location.
  83 + */
  84 + public Cursor fetchLocation(long rowId) throws SQLException {
  85 + Cursor cursor = database.query(true, T1_DATABASE_TABLE, new String[] { KEY_ID, KEY_LABEL, KEY_LONGITUDE, KEY_LATITUDE },
  86 + KEY_ID + "=" + rowId, null, null, null, null, null);
  87 + if (cursor != null) {
  88 + cursor.moveToFirst();
  89 + }
  90 + return cursor;
  91 + }
  92 +
  93 + /*
  94 + * Return Cursor positioned at defined point of interest.
  95 + */
  96 + public Cursor fetchPointOfInterest(long rowId) throws SQLException {
  97 + Cursor cursor = database.query(true, T2_DATABASE_TABLE, new String[] { KEY_ID, KEY_LABEL, KEY_LONGITUDE, KEY_LATITUDE, KEY_LOC_ID },
  98 + KEY_ID + "=" + rowId, null, null, null, null, null);
  99 + if (cursor != null) {
  100 + cursor.moveToFirst();
  101 + }
  102 + return cursor;
  103 + }
  104 +
  105 + private ContentValues createContentValues(String label, double longitude, double latitude) {
  106 + ContentValues values = new ContentValues();
  107 + values.put(KEY_LABEL, label);
  108 + values.put(KEY_LONGITUDE, longitude);
  109 + values.put(KEY_LATITUDE, latitude);
  110 + return values;
  111 + }
  112 +
  113 + private ContentValues createContentValues(String label, double longitude, double latitude, int locId) {
  114 + ContentValues values = new ContentValues();
  115 + values.put(KEY_LABEL, label);
  116 + values.put(KEY_LONGITUDE, longitude);
  117 + values.put(KEY_LATITUDE, latitude);
  118 + values.put(KEY_LOC_ID, locId);
  119 + return values;
  120 + }
  121 +}

No commit comments for this range

Something went wrong with that request. Please try again.