Removed gps permission for task rabbit

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

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

@ -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;

@ -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<Overlay> 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<Overlay> 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<Overlay> 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);
}
}

@ -12,14 +12,10 @@ import com.google.android.maps.OverlayItem;
public class TaskRabbitMapOverlayItem extends ItemizedOverlay<OverlayItem> {
private final ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
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<OverlayItem> {
return false;
}
selectedItem = mOverlays.get(index);
if (mActivity != null)
mActivity.didSelectItem(selectedItem);
return true;

Loading…
Cancel
Save