Commit 8913484d authored by Chris Scott's avatar Chris Scott

Remove wakelock

parent f944038c
...@@ -491,7 +491,7 @@ public class BackgroundGeolocationService extends Service implements GoogleApiCl ...@@ -491,7 +491,7 @@ public class BackgroundGeolocationService extends Service implements GoogleApiCl
removeActivityUpdates(); removeActivityUpdates();
removeLocationUpdates(); removeLocationUpdates();
stopSelf(); stopSelf();
wakeLock.release(); //wakeLock.release();
} }
/** /**
......
package com.transistorsoft.cordova.bggeo.data;
import org.json.JSONObject;
import org.json.JSONException;
public interface LocationDAO {
public JSONObject[] getAllLocations();
public boolean persistLocation(JSONObject l);
public void deleteLocation(JSONObject l);
}
\ No newline at end of file
package com.transistorsoft.cordova.bggeo.data.sqlite;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
public class LocationOpenHelper extends SQLiteOpenHelper {
private static final String SQLITE_DATABASE_NAME = "cordova_background_geolocation";
private static final int DATABASE_VERSION = 1;
public static final String LOCATION_TABLE_NAME = "locations";
private static final String LOCATION_TABLE_COLUMNS = "timestamp INTEGER PRIMARY KEY, json TEXT";
private static final String LOCATION_TABLE_CREATE = "CREATE TABLE " + LOCATION_TABLE_NAME + " (" + LOCATION_TABLE_COLUMNS + ");";
LocationOpenHelper(Context context) {
super(context, SQLITE_DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(LOCATION_TABLE_CREATE);
Log.d(this.getClass().getName(), LOCATION_TABLE_CREATE);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
}
}
package com.transistorsoft.cordova.bggeo.data.sqlite;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.TimeZone;
import java.util.List;
import org.json.JSONObject;
import org.json.JSONException;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;
import com.transistorsoft.cordova.bggeo.data.LocationDAO;
public class SQLiteLocationDAO implements LocationDAO {
private static final String TAG = "SQLiteLocationDAO";
private Context context;
public SQLiteLocationDAO(Context context) {
this.context = context;
}
/*
public JSONObject[] getAllLocations() {
SQLiteDatabase db = null;
Cursor c = null;
List<JSONObject> all = new ArrayList<JSONObject>();
try {
db = new LocationOpenHelper(context).getReadableDatabase();
c = db.query(LocationOpenHelper.LOCATION_TABLE_NAME, null);
while (c.moveToNext()) {
all.add(hydrate(c));
}
} finally {
if (c != null) {
c.close();
}
if (db != null) {
db.close();
}
}
return all.toArray(new JSONObject[all.size()]);
}
public boolean persistLocation(JSONObject location) {
SQLiteDatabase db = new LocationOpenHelper(context).getWritableDatabase();
db.beginTransaction();
ContentValues values = getContentValues(location);
long rowId = db.insert(LocationOpenHelper.LOCATION_TABLE_NAME, null, values);
Log.d(TAG, "After insert, rowId = " + rowId);
db.setTransactionSuccessful();
db.endTransaction();
db.close();
if (rowId > -1) {
return true;
} else {
return false;
}
}
public void deleteLocation(JSONObject location) {
SQLiteDatabase db = new LocationOpenHelper(context).getWritableDatabase();
db.beginTransaction();
db.delete(LocationOpenHelper.LOCATION_TABLE_NAME, "timestamp = ?", location.getString("timestamp"));
db.setTransactionSuccessful();
db.endTransaction();
db.close();
}
private JSONObject hydrate(Cursor c) {
JSONObject l = new JSONObject(c);
return l;
}
private ContentValues getContentValues(JSONObject location) {
ContentValues values = new ContentValues();
values.put("latitude", location.get("latitude"));
values.put("longitude", location.get("longitude"));
values.put("timestamp", location.get("timestamp"));
values.put("accuracy", location.get("accuracy"));
values.put("altitude", location.get("altitude"));
values.put("bearing", location.get("bearing"));
values.put("speed", location.get("speed"));
return values;
}
*/
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment