Small refactoring and do not clear bitmap cache often

This commit is contained in:
Victor Shcherb 2011-11-26 02:04:38 +01:00
parent d79ffb1580
commit 129bdce53c
3 changed files with 62 additions and 55 deletions

View file

@ -393,7 +393,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
return dialog; return dialog;
} }
} }
if(id == OsmandApplication.PROGRESS_DIALOG){ if (id == OsmandApplication.PROGRESS_DIALOG) {
return startProgressDialog; return startProgressDialog;
} }
return null; return null;
@ -533,6 +533,12 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
} }
return super.onKeyDown(keyCode, event); return super.onKeyDown(keyCode, event);
} }
public void setMapLocation(double lat, double lon){
mapView.setLatLon(lat, lon);
locationChanged(lat, lon, this);
}
@Override @Override
public boolean onTrackballEvent(MotionEvent event) { public boolean onTrackballEvent(MotionEvent event) {
if(event.getAction() == MotionEvent.ACTION_MOVE && settings.USE_TRACKBALL_FOR_MOVEMENTS.get()){ if(event.getAction() == MotionEvent.ACTION_MOVE && settings.USE_TRACKBALL_FOR_MOVEMENTS.get()){
@ -965,11 +971,6 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
} }
} }
public void setMapLocation(double lat, double lon){
mapView.setLatLon(lat, lon);
locationChanged(lat, lon, this);
}
public OsmandMapTileView getMapView() { public OsmandMapTileView getMapView() {
return mapView; return mapView;
} }

View file

@ -291,61 +291,16 @@ public class OsmandApplication extends Application {
public synchronized void startApplication() { public synchronized void startApplication() {
if(applicationInitializing){ if (applicationInitializing) {
return; return;
} }
applicationInitializing = true; applicationInitializing = true;
startDialog = new ProgressDialogImplementation(this, null, false); startDialog = new ProgressDialogImplementation(this, null, false);
startDialog.setRunnable("Initializing app", new Runnable() { //$NON-NLS-1$ startDialog.setRunnable("Initializing app", new Runnable() { //$NON-NLS-1$
@Override @Override
public void run() { public void run() {
List<String> warnings = null; startApplicationBackground();
try {
if (osmandSettings.NATIVE_RENDERING.get()) {
startDialog.startTask(getString(R.string.init_native_library), -1);
RenderingRulesStorage storage = rendererRegistry.getCurrentSelectedRenderer();
boolean initialized = NativeOsmandLibrary.getLibrary(storage) != null;
if (!initialized) {
LOG.info("Native library could not loaded!");
}
}
warnings = manager.reloadIndexes(startDialog);
player = null;
SavingTrackHelper helper = new SavingTrackHelper(OsmandApplication.this);
if (helper.hasDataToSave()) {
startDialog.startTask(getString(R.string.saving_gpx_tracks), -1);
warnings.addAll(helper.saveDataToGpx());
}
helper.close();
// NativeOsmandLibrary.loadLibrary();
} finally {
synchronized (OsmandApplication.this) {
final ProgressDialog toDismiss;
if (startDialog != null) {
toDismiss = startDialog.getDialog();
} else {
toDismiss = null;
}
startDialog = null;
if (toDismiss != null) {
uiHandler.post(new Runnable() {
@Override
public void run() {
if (toDismiss.getOwnerActivity() != null) {
toDismiss.getOwnerActivity().dismissDialog(PROGRESS_DIALOG);
}
}
});
showWarnings(warnings, toDismiss.getContext());
} else {
startingWarnings = warnings;
}
}
}
} }
}); });
startDialog.run(); startDialog.run();
@ -354,6 +309,52 @@ public class OsmandApplication extends Application {
} }
private void startApplicationBackground() {
List<String> warnings = null;
try {
if (osmandSettings.NATIVE_RENDERING.get()) {
startDialog.startTask(getString(R.string.init_native_library), -1);
RenderingRulesStorage storage = rendererRegistry.getCurrentSelectedRenderer();
boolean initialized = NativeOsmandLibrary.getLibrary(storage) != null;
if (!initialized) {
LOG.info("Native library could not loaded!");
}
}
warnings = manager.reloadIndexes(startDialog);
player = null;
SavingTrackHelper helper = new SavingTrackHelper(OsmandApplication.this);
if (helper.hasDataToSave()) {
startDialog.startTask(getString(R.string.saving_gpx_tracks), -1);
warnings.addAll(helper.saveDataToGpx());
}
helper.close();
} finally {
synchronized (OsmandApplication.this) {
final ProgressDialog toDismiss;
if (startDialog != null) {
toDismiss = startDialog.getDialog();
} else {
toDismiss = null;
}
startDialog = null;
if (toDismiss != null) {
uiHandler.post(new Runnable() {
@Override
public void run() {
if (toDismiss.getOwnerActivity() != null) {
toDismiss.getOwnerActivity().dismissDialog(PROGRESS_DIALOG);
}
}
});
showWarnings(warnings, toDismiss.getContext());
} else {
startingWarnings = warnings;
}
}
}
}
protected void showWarnings(List<String> warnings, final Context uiContext) { protected void showWarnings(List<String> warnings, final Context uiContext) {
if (warnings != null && !warnings.isEmpty()) { if (warnings != null && !warnings.isEmpty()) {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();

View file

@ -172,6 +172,8 @@ public class MapRenderRepositories {
public void clearAllResources() { public void clearAllResources() {
clearCache(); clearCache();
bmp = null;
bmpLocation = null;
for (String f : new ArrayList<String>(files.keySet())) { for (String f : new ArrayList<String>(files.keySet())) {
closeConnection(files.get(f), f); closeConnection(files.get(f), f);
} }
@ -607,8 +609,11 @@ public class MapRenderRepositories {
public synchronized void clearCache() { public synchronized void clearCache() {
cObjects = new ArrayList<BinaryMapDataObject>(); cObjects = new ArrayList<BinaryMapDataObject>();
cObjectsBox = new RectF(); cObjectsBox = new RectF();
prevBmp = bmp = null; prevBmp = null;
requestedBox = prevBmpLocation = bmpLocation = null; requestedBox = prevBmpLocation = null;
// Do not clear main bitmap to not cause a screen refresh
// bmp = null;
// bmpLocation = null;
} }
// / Manipulating with multipolygons // / Manipulating with multipolygons