From cb66aa6bcd730a134dfe46665346fcc014fe58d9 Mon Sep 17 00:00:00 2001 From: Ricky Barrette Date: Mon, 28 May 2012 00:37:17 -0400 Subject: [PATCH] Updated database to save locations as on row entry, rather than 2 closes #86 Signed-off-by: Ricky Barrette --- .../android/LocationRinger/db/RingerDatabase.java | 8 ++++++-- .../LocationRinger/services/RingerProcessingService.java | 6 ++++-- .../ui/fragments/LocationInfomationFragment.java | 8 ++++---- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/LocationRinger/src/com/TwentyCodes/android/LocationRinger/db/RingerDatabase.java b/LocationRinger/src/com/TwentyCodes/android/LocationRinger/db/RingerDatabase.java index f0a6584..b6ceae8 100644 --- a/LocationRinger/src/com/TwentyCodes/android/LocationRinger/db/RingerDatabase.java +++ b/LocationRinger/src/com/TwentyCodes/android/LocationRinger/db/RingerDatabase.java @@ -58,14 +58,18 @@ public class RingerDatabase { /* * Database keys */ - public final static String KEY_RADIUS = "radius"; + @Deprecated public final static String KEY_LOCATION_LAT = "location_lat"; + @Deprecated public final static String KEY_LOCATION_LON = "location_lon"; - public final static String KEY_RINGER_NAME = "ringer_name"; @Deprecated public final static String KEY_RINGTONE = "home_ringtone"; @Deprecated public final static String KEY_NOTIFICATION_RINGTONE = "notification_ringtone"; + + public final static String KEY_RADIUS = "radius"; + public final static String KEY_RINGER_NAME = "ringer_name"; + public final static String KEY_LOCATION = "location"; public final static String KEY_RINGTONE_IS_SILENT = "ringtone_is_silent"; public final static String KEY_NOTIFICATION_IS_SILENT = "notification_is_silent"; public final static String KEY_IS_ENABLED = "is_enabled"; diff --git a/LocationRinger/src/com/TwentyCodes/android/LocationRinger/services/RingerProcessingService.java b/LocationRinger/src/com/TwentyCodes/android/LocationRinger/services/RingerProcessingService.java index dfe6e8a..f2cf615 100644 --- a/LocationRinger/src/com/TwentyCodes/android/LocationRinger/services/RingerProcessingService.java +++ b/LocationRinger/src/com/TwentyCodes/android/LocationRinger/services/RingerProcessingService.java @@ -330,14 +330,16 @@ public class RingerProcessingService extends Service { if(RingerDatabase.parseBoolean(c.getString(1))){ ContentValues info = this.mDb.getRingerInfo(c.getString(0)); - if(info.containsKey(RingerDatabase.KEY_LOCATION_LAT) && info.containsKey(RingerDatabase.KEY_LOCATION_LON) && info.containsKey(RingerDatabase.KEY_RADIUS)) - if(GeoUtils.isIntersecting(point, new Float(mLocation.getAccuracy()) / 1000, new GeoPoint(info.getAsInteger(RingerDatabase.KEY_LOCATION_LAT), info.getAsInteger(RingerDatabase.KEY_LOCATION_LON)), new Float(info.getAsInteger(RingerDatabase.KEY_RADIUS)) / 1000, Debug.FUDGE_FACTOR)){ + if(info.containsKey(RingerDatabase.KEY_LOCATION) && info.containsKey(RingerDatabase.KEY_RADIUS)){ + final String[] pointInfo = info.getAsString(RingerDatabase.KEY_LOCATION).split(","); + if(GeoUtils.isIntersecting(point, new Float(mLocation.getAccuracy()) / 1000, new GeoPoint(Integer.parseInt(pointInfo[0]), Integer.parseInt(pointInfo[1])), new Float(info.getAsInteger(RingerDatabase.KEY_RADIUS)) / 1000, Debug.FUDGE_FACTOR)){ c.close(); getRinger(ringer, index); isDeafult = false; //break loop, we will only apply the first applicable ringer break; } + } } index++; } while (c.moveToNext()); diff --git a/LocationRinger/src/com/TwentyCodes/android/LocationRinger/ui/fragments/LocationInfomationFragment.java b/LocationRinger/src/com/TwentyCodes/android/LocationRinger/ui/fragments/LocationInfomationFragment.java index 8e16103..719aed0 100644 --- a/LocationRinger/src/com/TwentyCodes/android/LocationRinger/ui/fragments/LocationInfomationFragment.java +++ b/LocationRinger/src/com/TwentyCodes/android/LocationRinger/ui/fragments/LocationInfomationFragment.java @@ -151,8 +151,7 @@ public class LocationInfomationFragment extends Fragment implements GeoPointLoca if(this.mListener != null){ ContentValues info = new ContentValues(); - info.put(RingerDatabase.KEY_LOCATION_LAT, point.getLatitudeE6()); - info.put(RingerDatabase.KEY_LOCATION_LON, point.getLongitudeE6()); + info.put(RingerDatabase.KEY_LOCATION, point.toString()); this.mListener.onInfoContentChanged(info); } } else if(Debug.DEBUG) @@ -198,8 +197,9 @@ public class LocationInfomationFragment extends Fragment implements GeoPointLoca this.mMap.addOverlay(mRadiusOverlay); this.mRadius.setEnabled(false); - if (this.mInfo.get(RingerDatabase.KEY_LOCATION_LAT) != null && this.mInfo.get(RingerDatabase.KEY_LOCATION_LON) != null){ - this.mRadiusOverlay.setLocation(new GeoPoint(this.mInfo.getAsInteger(RingerDatabase.KEY_LOCATION_LAT), this.mInfo.getAsInteger(RingerDatabase.KEY_LOCATION_LON))); + if (this.mInfo.get(RingerDatabase.KEY_LOCATION) != null){ + final String[] point = this.mInfo.getAsString(RingerDatabase.KEY_LOCATION).split(","); + this.mRadiusOverlay.setLocation(new GeoPoint(Integer.parseInt(point[0]), Integer.parseInt(point[1]))); } if (this.mInfo.get(RingerDatabase.KEY_RADIUS) != null){