fixing performance issues

git-svn-id: https://osmand.googlecode.com/svn/trunk@92 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8
This commit is contained in:
Victor Shcherb 2010-05-28 11:08:21 +00:00
parent dc7521cde5
commit 2136c74871

View file

@ -14,6 +14,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.Handler;
import android.os.Message;
import android.os.PowerManager; import android.os.PowerManager;
import android.os.PowerManager.WakeLock; import android.os.PowerManager.WakeLock;
import android.view.Menu; import android.view.Menu;
@ -52,13 +54,14 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat
private WakeLock wakeLock; private WakeLock wakeLock;
private boolean sensorRegistered = false; private boolean sensorRegistered = false;
private Handler sensorHandler = new Handler();
private final static String BACK_TO_LOCATION = "BACK_TO_LOCATION"; private final static String BACK_TO_LOCATION = "BACK_TO_LOCATION";
private final static String POINT_NAVIGATE_LAT = "POINT_NAVIGATE_LAT"; private final static String POINT_NAVIGATE_LAT = "POINT_NAVIGATE_LAT";
private final static String POINT_NAVIGATE_LON = "POINT_NAVIGATE_LON"; private final static String POINT_NAVIGATE_LON = "POINT_NAVIGATE_LON";
private boolean getBackToLocation(){ private boolean isMapLinkedToLocation(){
return getPreferences(MODE_WORLD_READABLE).getBoolean(BACK_TO_LOCATION, true); return getPreferences(MODE_WORLD_READABLE).getBoolean(BACK_TO_LOCATION, true);
} }
@ -120,7 +123,7 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat
backToLocation.setOnClickListener(new OnClickListener(){ backToLocation.setOnClickListener(new OnClickListener(){
@Override @Override
public void onClick(View v) { public void onClick(View v) {
if(!getBackToLocation()){ if(!isMapLinkedToLocation()){
getPreferences(MODE_WORLD_READABLE).edit().putBoolean(BACK_TO_LOCATION, true).commit(); getPreferences(MODE_WORLD_READABLE).edit().putBoolean(BACK_TO_LOCATION, true).commit();
backToLocation.setVisibility(View.INVISIBLE); backToLocation.setVisibility(View.INVISIBLE);
if(locationLayer.getLastKnownLocation() != null){ if(locationLayer.getLastKnownLocation() != null){
@ -181,7 +184,7 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat
locationLayer.setLastKnownLocation(location, true); locationLayer.setLastKnownLocation(location, true);
if (location != null) { if (location != null) {
if (getBackToLocation()) { if (isMapLinkedToLocation()) {
if (location.hasBearing() && OsmandSettings.isRotateMapToBearing(this)) { if (location.hasBearing() && OsmandSettings.isRotateMapToBearing(this)) {
mapView.setRotateWithLocation(-location.getBearing(), location.getLatitude(), location.getLongitude()); mapView.setRotateWithLocation(-location.getBearing(), location.getLatitude(), location.getLongitude());
} else { } else {
@ -189,10 +192,13 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat
} }
} else { } else {
mapView.prepareImage(); mapView.prepareImage();
if(backToLocation.getVisibility() != View.VISIBLE){
backToLocation.setVisibility(View.VISIBLE);
}
} }
} else { } else {
if (!getBackToLocation()) { if(backToLocation.getVisibility() != View.INVISIBLE){
backToLocation.setVisibility(View.VISIBLE); backToLocation.setVisibility(View.INVISIBLE);
} }
} }
} }
@ -259,7 +265,7 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat
if(!OsmandSettings.isRotateMapToBearing(this)){ if(!OsmandSettings.isRotateMapToBearing(this)){
mapView.setRotate(0); mapView.setRotate(0);
} }
if(mapView.getLayers().contains(poiMapLayer) != OsmandSettings.isShowingPoiOverMap(this)){ if(mapView.getLayers().contains(poiMapLayer) != OsmandSettings.isShowingPoiOverMap(this)){
if(OsmandSettings.isShowingPoiOverMap(this)){ if(OsmandSettings.isShowingPoiOverMap(this)){
mapView.addLayer(poiMapLayer); mapView.addLayer(poiMapLayer);
@ -340,7 +346,18 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat
@Override @Override
public void onSensorChanged(SensorEvent event) { public void onSensorChanged(SensorEvent event) {
locationLayer.setHeading(event.values[0], false); // using that strange technique because sensor produces a lot of events & hangs the system
locationLayer.setHeading(event.values[0], true);
if(!sensorHandler.hasMessages(1)){
Message m = Message.obtain(sensorHandler, new Runnable(){
@Override
public void run() {
mapView.prepareImage();
}
});
m.what = 1;
sensorHandler.sendMessage(m);
}
} }
} }