introduce wake lock

git-svn-id: https://osmand.googlecode.com/svn/trunk@47 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8
This commit is contained in:
Victor Shcherb 2010-05-07 13:42:33 +00:00
parent ecdc1dc825
commit 6d7a01ed9d
2 changed files with 14 additions and 1 deletions

View file

@ -28,4 +28,5 @@
<uses-permission android:name="android.permission.INTERNET"></uses-permission> <uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
<uses-permission android:name="android.permission.WAKE_LOCK"></uses-permission>
</manifest> </manifest>

View file

@ -11,6 +11,8 @@ import android.location.LocationListener;
import android.location.LocationManager; import android.location.LocationManager;
import android.location.LocationProvider; import android.location.LocationProvider;
import android.os.Bundle; import android.os.Bundle;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
import android.view.Menu; import android.view.Menu;
import android.view.MenuInflater; import android.view.MenuInflater;
import android.view.MenuItem; import android.view.MenuItem;
@ -47,6 +49,7 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat
private PointLocationLayer locationLayer; private PointLocationLayer locationLayer;
private POIMapLayer poiMapLayer; private POIMapLayer poiMapLayer;
private WakeLock wakeLock;
protected void onRestoreInstanceState(Bundle savedInstanceState) { protected void onRestoreInstanceState(Bundle savedInstanceState) {
@ -178,7 +181,10 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat
edit.putFloat(KEY_LAST_LON, (float) mapView.getLongitude()); edit.putFloat(KEY_LAST_LON, (float) mapView.getLongitude());
edit.putInt(KEY_LAST_ZOOM, mapView.getZoom()); edit.putInt(KEY_LAST_ZOOM, mapView.getZoom());
edit.commit(); edit.commit();
if (wakeLock != null) {
wakeLock.release();
wakeLock = null;
}
} }
@Override @Override
@ -196,6 +202,12 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat
} }
LocationManager service = (LocationManager) getSystemService(LOCATION_SERVICE); LocationManager service = (LocationManager) getSystemService(LOCATION_SERVICE);
service.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2000, 0, this); service.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2000, 0, this);
if (wakeLock == null) {
PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
wakeLock = powerManager.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "com.osmand.map");
wakeLock.acquire();
}
} }