From 9ef1de188e759a96c162573ac82afc66298fdf90 Mon Sep 17 00:00:00 2001 From: Andrew Shaw Date: Mon, 27 Feb 2012 15:48:57 -0800 Subject: [PATCH 1/4] Removed gps permission for task rabbit --- astrid/AndroidManifest.xml | 1 - .../taskrabbit/TaskRabbitLocationManager.java | 61 +++---------------- .../taskrabbit/TaskRabbitMapActivity.java | 60 ++++++------------ .../taskrabbit/TaskRabbitMapOverlayItem.java | 7 +-- 4 files changed, 29 insertions(+), 100 deletions(-) diff --git a/astrid/AndroidManifest.xml b/astrid/AndroidManifest.xml index 2dffbb28b..87b1dfda7 100644 --- a/astrid/AndroidManifest.xml +++ b/astrid/AndroidManifest.xml @@ -23,7 +23,6 @@ - diff --git a/astrid/plugin-src/com/todoroo/astrid/taskrabbit/TaskRabbitLocationManager.java b/astrid/plugin-src/com/todoroo/astrid/taskrabbit/TaskRabbitLocationManager.java index 7c7e3e508..19c469f11 100644 --- a/astrid/plugin-src/com/todoroo/astrid/taskrabbit/TaskRabbitLocationManager.java +++ b/astrid/plugin-src/com/todoroo/astrid/taskrabbit/TaskRabbitLocationManager.java @@ -15,7 +15,6 @@ public class TaskRabbitLocationManager { Timer timer1; LocationManager lm; LocationResult locationResult; - boolean gps_enabled=false; boolean network_enabled=false; Context context; @@ -42,13 +41,7 @@ public class TaskRabbitLocationManager { public boolean isLocationUpdatesEnabled() { boolean provider_enabled = false; try { - provider_enabled = lm.isProviderEnabled(LocationManager.GPS_PROVIDER); - } catch (Exception ex) { - // suppress - } - try { - provider_enabled = provider_enabled - || lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER); + provider_enabled = lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER); } catch (Exception ex) { // suppress } @@ -56,20 +49,11 @@ public class TaskRabbitLocationManager { } public Location getLastKnownLocation() { - boolean gps_supported=false; - boolean network_supported=false; - Location location = null; - - gps_supported = isGpsEnabled();; - network_supported = isNetworkProviderEnabled(); - if(!gps_supported && !network_supported) + if(!isNetworkProviderEnabled()) return null; - - if(gps_supported) {location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER); - } - if(location == null && network_supported) {location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER); + else { + return lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); } - return location; } public static boolean supportsCurrentLocation(Location location) { @@ -91,16 +75,11 @@ public class TaskRabbitLocationManager { public boolean getLocation(LocationResult result) { locationResult = result; - gps_enabled = isGpsEnabled(); - network_enabled = isNetworkProviderEnabled(); - if(!gps_enabled && !network_enabled) + if(!isNetworkProviderEnabled()) return false; - if(gps_enabled) - lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener); - if(network_enabled) - lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener); + lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener); timer1=new Timer(); timer1.schedule(new GetLastLocation(), 20000); return true; @@ -115,15 +94,6 @@ public class TaskRabbitLocationManager { return false; } - private boolean isGpsEnabled() { - try { - return lm.isProviderEnabled(LocationManager.GPS_PROVIDER); - } catch (Exception ex) { - // suppress - } - return false; - } - private final LocationListener locationListener = new LocationListener() { public void onLocationChanged(Location location) { timer1.cancel(); @@ -140,25 +110,8 @@ public class TaskRabbitLocationManager { public void run() { lm.removeUpdates(locationListener); - Location net_loc=null, gps_loc=null; - if(gps_enabled) - gps_loc=lm.getLastKnownLocation(LocationManager.GPS_PROVIDER); - if(network_enabled) - net_loc=lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); - - //if there are both values use the latest one - if(gps_loc!=null && net_loc!=null){ - if(gps_loc.getTime()>net_loc.getTime()) - locationResult.gotLocation(gps_loc); - else - locationResult.gotLocation(net_loc); - return; - } + Location net_loc=lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); - if(gps_loc!=null){ - locationResult.gotLocation(gps_loc); - return; - } if(net_loc!=null){ locationResult.gotLocation(net_loc); return; diff --git a/astrid/plugin-src/com/todoroo/astrid/taskrabbit/TaskRabbitMapActivity.java b/astrid/plugin-src/com/todoroo/astrid/taskrabbit/TaskRabbitMapActivity.java index b1d189855..78249b2d0 100644 --- a/astrid/plugin-src/com/todoroo/astrid/taskrabbit/TaskRabbitMapActivity.java +++ b/astrid/plugin-src/com/todoroo/astrid/taskrabbit/TaskRabbitMapActivity.java @@ -36,6 +36,7 @@ public class TaskRabbitMapActivity extends MapActivity implements LocationListen private MapView mapView; private MapController mapController; public Location currentLocation; + private LocationManager locationManager; private EditText searchText; private TaskRabbitMapOverlayItem currentOverlayItem; private String locationAddress; @@ -53,30 +54,22 @@ public class TaskRabbitMapActivity extends MapActivity implements LocationListen mapView.setBuiltInZoomControls(true); - LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); - Location lastKnownLocation = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); - locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this); - - List mapOverlays = mapView.getOverlays(); - - Drawable drawable = this.getResources().getDrawable(android.R.drawable.star_big_on); - currentOverlayItem = new TaskRabbitMapOverlayItem(drawable, this); - GeoPoint point = null; + locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); + currentLocation = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); mapController = mapView.getController(); - if(lastKnownLocation != null) { + if(currentLocation != null) { - point = locationToGeoPoint(lastKnownLocation); - OverlayItem overlayitem = createOverlayItem(point); - currentOverlayItem.addOverlay(overlayitem); - mapOverlays.add(currentOverlayItem); + updateLocationOverlay(); - locationAddress = getAddressFromLocation(lastKnownLocation); - mapController.animateTo(point); + locationAddress = getAddressFromLocation(currentLocation); mapController.setZoom(17); mapView.invalidate(); } + else { + locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this); + } searchText=(EditText)findViewById(R.id.search_text); @@ -145,23 +138,12 @@ public class TaskRabbitMapActivity extends MapActivity implements LocationListen if (addresses != null && addresses.size() > 0) { updateAddress(addresses.get(0)); - GeoPoint q = new GeoPoint( - (int) (addresses.get(0).getLatitude() * 1E6), - (int) (addresses.get(0).getLongitude() * 1E6)); - - Drawable drawable = TaskRabbitMapActivity.this.getResources().getDrawable( - android.R.drawable.star_big_on); - currentOverlayItem = new TaskRabbitMapOverlayItem(drawable, - TaskRabbitMapActivity.this); - mapController.animateTo(q); + currentLocation = new Location(""); + currentLocation.setLatitude(addresses.get(0).getLatitude()); + currentLocation.setLongitude(addresses.get(0).getLongitude()); mapController.setZoom(12); + updateLocationOverlay(); - OverlayItem overlayitem = createOverlayItem(q); - - currentOverlayItem.addOverlay(overlayitem); - List mapOverlays = mapView.getOverlays(); - mapOverlays.clear(); - mapOverlays.add(currentOverlayItem); Message successMessage = new Message(); successMessage.what = LOCATION_SEARCH_SUCCESS; @@ -223,12 +205,13 @@ public class TaskRabbitMapActivity extends MapActivity implements LocationListen if (currentLocation == null) { return; }; List mapOverlays = mapView.getOverlays(); Drawable drawable = this.getResources().getDrawable(android.R.drawable.star_big_on); - TaskRabbitMapOverlayItem myItemizedOverlay = new TaskRabbitMapOverlayItem(drawable); - GeoPoint point = new GeoPoint((int)(currentLocation.getLatitude() * 1E6), (int)(currentLocation.getLongitude() * 1E6)); - + currentOverlayItem = new TaskRabbitMapOverlayItem(drawable, this); + GeoPoint point = locationToGeoPoint(currentLocation); OverlayItem overlayitem = createOverlayItem(point); - myItemizedOverlay.addOverlay(overlayitem); - mapOverlays.add(myItemizedOverlay); + currentOverlayItem.addOverlay(overlayitem); + mapOverlays.clear(); + mapOverlays.add(currentOverlayItem); + mapController.animateTo(point); } public void didSelectItem (final OverlayItem selectedItem) { @@ -270,12 +253,9 @@ public class TaskRabbitMapActivity extends MapActivity implements LocationListen @Override public void onLocationChanged(Location location) { if (location != null) { - double lat = location.getLatitude(); - double lng = location.getLongitude(); + locationManager.removeUpdates(this); this.currentLocation = location; - GeoPoint p = new GeoPoint((int) lat * 1000000, (int) lng * 1000000); updateLocationOverlay(); - mapController.animateTo(p); } } diff --git a/astrid/plugin-src/com/todoroo/astrid/taskrabbit/TaskRabbitMapOverlayItem.java b/astrid/plugin-src/com/todoroo/astrid/taskrabbit/TaskRabbitMapOverlayItem.java index 618a0f97e..2164c8ffc 100644 --- a/astrid/plugin-src/com/todoroo/astrid/taskrabbit/TaskRabbitMapOverlayItem.java +++ b/astrid/plugin-src/com/todoroo/astrid/taskrabbit/TaskRabbitMapOverlayItem.java @@ -12,14 +12,10 @@ import com.google.android.maps.OverlayItem; public class TaskRabbitMapOverlayItem extends ItemizedOverlay { private final ArrayList mOverlays = new ArrayList(); - private TaskRabbitMapActivity mActivity; + private final TaskRabbitMapActivity mActivity; private ImageView dragImage = null; private OverlayItem selectedItem = null; - public TaskRabbitMapOverlayItem(Drawable defaultMarker) { - super(boundCenterBottom(defaultMarker)); - } - public TaskRabbitMapOverlayItem(Drawable defaultMarker, TaskRabbitMapActivity activity) { super(boundCenterBottom(defaultMarker)); mActivity = activity; @@ -60,6 +56,7 @@ public class TaskRabbitMapOverlayItem extends ItemizedOverlay { return false; } selectedItem = mOverlays.get(index); + if (mActivity != null) mActivity.didSelectItem(selectedItem); return true; From 7d45748a6c1cbf9e3540f614d130f6ec542b9ba4 Mon Sep 17 00:00:00 2001 From: Andrew Shaw Date: Mon, 27 Feb 2012 17:07:00 -0800 Subject: [PATCH 2/4] Fixing task rabbit statistics reporting with login --- .../astrid/taskrabbit/TaskRabbitActivity.java | 12 ++++++++---- .../todoroo/astrid/service/StatisticsConstants.java | 1 + 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/astrid/plugin-src/com/todoroo/astrid/taskrabbit/TaskRabbitActivity.java b/astrid/plugin-src/com/todoroo/astrid/taskrabbit/TaskRabbitActivity.java index 7ac5a4bd1..84dd4061c 100644 --- a/astrid/plugin-src/com/todoroo/astrid/taskrabbit/TaskRabbitActivity.java +++ b/astrid/plugin-src/com/todoroo/astrid/taskrabbit/TaskRabbitActivity.java @@ -119,6 +119,7 @@ public class TaskRabbitActivity extends FragmentActivity { private int currentSelectedItem = 0; private View menuNav; private ImageView menuNavDisclosure; + private boolean didReportStatistics = false; private final List controls = Collections.synchronizedList(new ArrayList()); @@ -154,6 +155,7 @@ public class TaskRabbitActivity extends FragmentActivity { public static final String TASK_RABBIT_CLIENT_ID = "fDTmGeR0uNCvoxopNyqsRWae8xOvbOBqC7jmHaxv"; //$NON-NLS-1$ public static final String TASK_RABBIT_CLIENT_APPLICATION_ID = "XBpKshU8utH5eaNmhky9N8aAId5rSLTh04Hi60Co"; //$NON-NLS-1$ public static final String TASK_RABBIT_ID = "id"; //$NON-NLS-1$ + private TaskRabbitTaskContainer taskRabbitTask; public TaskRabbitActivity() { @@ -168,7 +170,6 @@ public class TaskRabbitActivity extends FragmentActivity { loadLocation(); setContentView(R.layout.task_rabbit_enter); - StatisticsService.reportEvent(StatisticsConstants.TASK_RABBIT_VIEW); } public void showAddListPopover() { @@ -206,12 +207,15 @@ public class TaskRabbitActivity extends FragmentActivity { } } - - @Override public void onResume() { super.onResume(); StatisticsService.sessionStart(this); + + if (!didReportStatistics) { + StatisticsService.reportEvent(StatisticsConstants.TASK_RABBIT_VIEW); + didReportStatistics = true; + } populateFields(); showIntroDialog(); } @@ -688,7 +692,7 @@ public class TaskRabbitActivity extends FragmentActivity { String url = TASK_RABBIT_URL + "/api/authorize?client_id=" + TASK_RABBIT_CLIENT_ID; //$NON-NLS-1$ intent.putExtra(OAuthLoginActivity.URL_TOKEN, url); this.startActivityForResult(intent, REQUEST_CODE_TASK_RABBIT_OAUTH); - StatisticsService.reportEvent(StatisticsConstants.ACTFM_LOGIN_GL_START); + StatisticsService.reportEvent(StatisticsConstants.TASK_RABBIT_LOGIN); } catch (Exception e) { e.printStackTrace(); } diff --git a/astrid/src/com/todoroo/astrid/service/StatisticsConstants.java b/astrid/src/com/todoroo/astrid/service/StatisticsConstants.java index 688e42c05..f405426c3 100644 --- a/astrid/src/com/todoroo/astrid/service/StatisticsConstants.java +++ b/astrid/src/com/todoroo/astrid/service/StatisticsConstants.java @@ -60,6 +60,7 @@ public class StatisticsConstants { public static final String IDEAS_LINK_CLICKED = "ideas-link-clicked"; public static final String TASK_RABBIT_VIEW = "task-rabbit-view"; public static final String TASK_RABBIT_POST = "task-rabbit-post"; + public static final String TASK_RABBIT_LOGIN = "task-rabbit-login"; public static final String TASK_ONE_WEEK = "task-created-one-week"; public static final String TASK_TWO_WEEKS = "task-created-two-weeks"; From 9a8880514700c0cd1dcc7e7db5d2fcc98c35a364 Mon Sep 17 00:00:00 2001 From: Sam Bosley Date: Mon, 27 Feb 2012 17:36:27 -0800 Subject: [PATCH 3/4] Missing import --- .../com/todoroo/astrid/actfm/sync/ActFmSyncService.java | 1 + 1 file changed, 1 insertion(+) diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncService.java b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncService.java index d3b7ff8e9..179ac2cba 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncService.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncService.java @@ -52,6 +52,7 @@ import com.todoroo.astrid.dao.UpdateDao; import com.todoroo.astrid.data.Metadata; import com.todoroo.astrid.data.MetadataApiDao.MetadataCriteria; import com.todoroo.astrid.data.RemoteModel; +import com.todoroo.astrid.data.SyncFlags; import com.todoroo.astrid.data.TagData; import com.todoroo.astrid.data.Task; import com.todoroo.astrid.data.TaskApiDao; From f75571e20ab5f5bde504c30fa10a95dc5ee068b9 Mon Sep 17 00:00:00 2001 From: Sam Bosley Date: Mon, 27 Feb 2012 17:50:25 -0800 Subject: [PATCH 4/4] Fixed compilation error in unit test --- tests/src/com/todoroo/astrid/repeats/NewRepeatTests.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/src/com/todoroo/astrid/repeats/NewRepeatTests.java b/tests/src/com/todoroo/astrid/repeats/NewRepeatTests.java index 8a32d44d5..69adc6307 100644 --- a/tests/src/com/todoroo/astrid/repeats/NewRepeatTests.java +++ b/tests/src/com/todoroo/astrid/repeats/NewRepeatTests.java @@ -22,9 +22,9 @@ import com.todoroo.astrid.api.AstridApiConstants; import com.todoroo.astrid.dao.MetadataDao; import com.todoroo.astrid.dao.TaskDao; import com.todoroo.astrid.dao.TaskDao.TaskCriteria; +import com.todoroo.astrid.data.SyncFlags; import com.todoroo.astrid.data.Task; import com.todoroo.astrid.test.DatabaseTestCase; -import com.todoroo.astrid.utility.Flags; public class NewRepeatTests extends DatabaseTestCase { @@ -41,7 +41,7 @@ public class NewRepeatTests extends DatabaseTestCase { } private void saveAndTriggerRepeatListener(Task task) { - Flags.set(Flags.ACTFM_SUPPRESS_SYNC); + task.putTransitory(SyncFlags.ACTFM_SUPPRESS_SYNC, true); if(task.isSaved()) taskDao.saveExisting(task); else