Removed gps permission for task rabbit

pull/14/head
Andrew Shaw 14 years ago
parent 4744320760
commit 9ef1de188e

@ -23,7 +23,6 @@
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- for analytics --> <!-- for analytics -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!-- for google tasks --> <!-- for google tasks -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" /> <uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" /> <uses-permission android:name="android.permission.USE_CREDENTIALS" />

@ -15,7 +15,6 @@ public class TaskRabbitLocationManager {
Timer timer1; Timer timer1;
LocationManager lm; LocationManager lm;
LocationResult locationResult; LocationResult locationResult;
boolean gps_enabled=false;
boolean network_enabled=false; boolean network_enabled=false;
Context context; Context context;
@ -42,13 +41,7 @@ public class TaskRabbitLocationManager {
public boolean isLocationUpdatesEnabled() { public boolean isLocationUpdatesEnabled() {
boolean provider_enabled = false; boolean provider_enabled = false;
try { try {
provider_enabled = lm.isProviderEnabled(LocationManager.GPS_PROVIDER); provider_enabled = lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
} catch (Exception ex) {
// suppress
}
try {
provider_enabled = provider_enabled
|| lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
} catch (Exception ex) { } catch (Exception ex) {
// suppress // suppress
} }
@ -56,20 +49,11 @@ public class TaskRabbitLocationManager {
} }
public Location getLastKnownLocation() public Location getLastKnownLocation()
{ {
boolean gps_supported=false; if(!isNetworkProviderEnabled())
boolean network_supported=false;
Location location = null;
gps_supported = isGpsEnabled();;
network_supported = isNetworkProviderEnabled();
if(!gps_supported && !network_supported)
return null; return null;
else {
if(gps_supported) {location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER); return lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
}
if(location == null && network_supported) {location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
} }
return location;
} }
public static boolean supportsCurrentLocation(Location location) { public static boolean supportsCurrentLocation(Location location) {
@ -91,16 +75,11 @@ public class TaskRabbitLocationManager {
public boolean getLocation(LocationResult result) public boolean getLocation(LocationResult result)
{ {
locationResult = result; locationResult = result;
gps_enabled = isGpsEnabled();
network_enabled = isNetworkProviderEnabled();
if(!gps_enabled && !network_enabled) if(!isNetworkProviderEnabled())
return false; return false;
if(gps_enabled) lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
if(network_enabled)
lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
timer1=new Timer(); timer1=new Timer();
timer1.schedule(new GetLastLocation(), 20000); timer1.schedule(new GetLastLocation(), 20000);
return true; return true;
@ -115,15 +94,6 @@ public class TaskRabbitLocationManager {
return false; return false;
} }
private boolean isGpsEnabled() {
try {
return lm.isProviderEnabled(LocationManager.GPS_PROVIDER);
} catch (Exception ex) {
// suppress
}
return false;
}
private final LocationListener locationListener = new LocationListener() { private final LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) { public void onLocationChanged(Location location) {
timer1.cancel(); timer1.cancel();
@ -140,25 +110,8 @@ public class TaskRabbitLocationManager {
public void run() { public void run() {
lm.removeUpdates(locationListener); lm.removeUpdates(locationListener);
Location net_loc=null, gps_loc=null; Location net_loc=lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
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;
}
if(gps_loc!=null){
locationResult.gotLocation(gps_loc);
return;
}
if(net_loc!=null){ if(net_loc!=null){
locationResult.gotLocation(net_loc); locationResult.gotLocation(net_loc);
return; return;

@ -36,6 +36,7 @@ public class TaskRabbitMapActivity extends MapActivity implements LocationListen
private MapView mapView; private MapView mapView;
private MapController mapController; private MapController mapController;
public Location currentLocation; public Location currentLocation;
private LocationManager locationManager;
private EditText searchText; private EditText searchText;
private TaskRabbitMapOverlayItem currentOverlayItem; private TaskRabbitMapOverlayItem currentOverlayItem;
private String locationAddress; private String locationAddress;
@ -53,30 +54,22 @@ public class TaskRabbitMapActivity extends MapActivity implements LocationListen
mapView.setBuiltInZoomControls(true); mapView.setBuiltInZoomControls(true);
LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
Location lastKnownLocation = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); currentLocation = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
List<Overlay> mapOverlays = mapView.getOverlays();
Drawable drawable = this.getResources().getDrawable(android.R.drawable.star_big_on);
currentOverlayItem = new TaskRabbitMapOverlayItem(drawable, this);
GeoPoint point = null;
mapController = mapView.getController(); mapController = mapView.getController();
if(lastKnownLocation != null) { if(currentLocation != null) {
point = locationToGeoPoint(lastKnownLocation); updateLocationOverlay();
OverlayItem overlayitem = createOverlayItem(point);
currentOverlayItem.addOverlay(overlayitem);
mapOverlays.add(currentOverlayItem);
locationAddress = getAddressFromLocation(lastKnownLocation); locationAddress = getAddressFromLocation(currentLocation);
mapController.animateTo(point);
mapController.setZoom(17); mapController.setZoom(17);
mapView.invalidate(); mapView.invalidate();
} }
else {
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this);
}
searchText=(EditText)findViewById(R.id.search_text); searchText=(EditText)findViewById(R.id.search_text);
@ -145,23 +138,12 @@ public class TaskRabbitMapActivity extends MapActivity implements LocationListen
if (addresses != null && addresses.size() > 0) { if (addresses != null && addresses.size() > 0) {
updateAddress(addresses.get(0)); updateAddress(addresses.get(0));
GeoPoint q = new GeoPoint( currentLocation = new Location("");
(int) (addresses.get(0).getLatitude() * 1E6), currentLocation.setLatitude(addresses.get(0).getLatitude());
(int) (addresses.get(0).getLongitude() * 1E6)); currentLocation.setLongitude(addresses.get(0).getLongitude());
Drawable drawable = TaskRabbitMapActivity.this.getResources().getDrawable(
android.R.drawable.star_big_on);
currentOverlayItem = new TaskRabbitMapOverlayItem(drawable,
TaskRabbitMapActivity.this);
mapController.animateTo(q);
mapController.setZoom(12); mapController.setZoom(12);
updateLocationOverlay();
OverlayItem overlayitem = createOverlayItem(q);
currentOverlayItem.addOverlay(overlayitem);
List<Overlay> mapOverlays = mapView.getOverlays();
mapOverlays.clear();
mapOverlays.add(currentOverlayItem);
Message successMessage = new Message(); Message successMessage = new Message();
successMessage.what = LOCATION_SEARCH_SUCCESS; successMessage.what = LOCATION_SEARCH_SUCCESS;
@ -223,12 +205,13 @@ public class TaskRabbitMapActivity extends MapActivity implements LocationListen
if (currentLocation == null) { return; }; if (currentLocation == null) { return; };
List<Overlay> mapOverlays = mapView.getOverlays(); List<Overlay> mapOverlays = mapView.getOverlays();
Drawable drawable = this.getResources().getDrawable(android.R.drawable.star_big_on); Drawable drawable = this.getResources().getDrawable(android.R.drawable.star_big_on);
TaskRabbitMapOverlayItem myItemizedOverlay = new TaskRabbitMapOverlayItem(drawable); currentOverlayItem = new TaskRabbitMapOverlayItem(drawable, this);
GeoPoint point = new GeoPoint((int)(currentLocation.getLatitude() * 1E6), (int)(currentLocation.getLongitude() * 1E6)); GeoPoint point = locationToGeoPoint(currentLocation);
OverlayItem overlayitem = createOverlayItem(point); OverlayItem overlayitem = createOverlayItem(point);
myItemizedOverlay.addOverlay(overlayitem); currentOverlayItem.addOverlay(overlayitem);
mapOverlays.add(myItemizedOverlay); mapOverlays.clear();
mapOverlays.add(currentOverlayItem);
mapController.animateTo(point);
} }
public void didSelectItem (final OverlayItem selectedItem) { public void didSelectItem (final OverlayItem selectedItem) {
@ -270,12 +253,9 @@ public class TaskRabbitMapActivity extends MapActivity implements LocationListen
@Override @Override
public void onLocationChanged(Location location) { public void onLocationChanged(Location location) {
if (location != null) { if (location != null) {
double lat = location.getLatitude(); locationManager.removeUpdates(this);
double lng = location.getLongitude();
this.currentLocation = location; this.currentLocation = location;
GeoPoint p = new GeoPoint((int) lat * 1000000, (int) lng * 1000000);
updateLocationOverlay(); updateLocationOverlay();
mapController.animateTo(p);
} }
} }

@ -12,14 +12,10 @@ import com.google.android.maps.OverlayItem;
public class TaskRabbitMapOverlayItem extends ItemizedOverlay<OverlayItem> { public class TaskRabbitMapOverlayItem extends ItemizedOverlay<OverlayItem> {
private final ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>(); private final ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
private TaskRabbitMapActivity mActivity; private final TaskRabbitMapActivity mActivity;
private ImageView dragImage = null; private ImageView dragImage = null;
private OverlayItem selectedItem = null; private OverlayItem selectedItem = null;
public TaskRabbitMapOverlayItem(Drawable defaultMarker) {
super(boundCenterBottom(defaultMarker));
}
public TaskRabbitMapOverlayItem(Drawable defaultMarker, TaskRabbitMapActivity activity) { public TaskRabbitMapOverlayItem(Drawable defaultMarker, TaskRabbitMapActivity activity) {
super(boundCenterBottom(defaultMarker)); super(boundCenterBottom(defaultMarker));
mActivity = activity; mActivity = activity;
@ -60,6 +56,7 @@ public class TaskRabbitMapOverlayItem extends ItemizedOverlay<OverlayItem> {
return false; return false;
} }
selectedItem = mOverlays.get(index); selectedItem = mOverlays.get(index);
if (mActivity != null)
mActivity.didSelectItem(selectedItem); mActivity.didSelectItem(selectedItem);
return true; return true;

Loading…
Cancel
Save