From 129bdce53c6447f2993584a6710e44c35fb29a2d Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Sat, 26 Nov 2011 02:04:38 +0100 Subject: [PATCH] Small refactoring and do not clear bitmap cache often --- .../osmand/plus/activities/MapActivity.java | 13 +-- .../plus/activities/OsmandApplication.java | 95 ++++++++++--------- .../plus/render/MapRenderRepositories.java | 9 +- 3 files changed, 62 insertions(+), 55 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index da7154d379..d335e47c77 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -393,7 +393,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso return dialog; } } - if(id == OsmandApplication.PROGRESS_DIALOG){ + if (id == OsmandApplication.PROGRESS_DIALOG) { return startProgressDialog; } return null; @@ -533,6 +533,12 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso } return super.onKeyDown(keyCode, event); } + + public void setMapLocation(double lat, double lon){ + mapView.setLatLon(lat, lon); + locationChanged(lat, lon, this); + } + @Override public boolean onTrackballEvent(MotionEvent event) { 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() { return mapView; } diff --git a/OsmAnd/src/net/osmand/plus/activities/OsmandApplication.java b/OsmAnd/src/net/osmand/plus/activities/OsmandApplication.java index 769702cf2c..d8d5a3f116 100644 --- a/OsmAnd/src/net/osmand/plus/activities/OsmandApplication.java +++ b/OsmAnd/src/net/osmand/plus/activities/OsmandApplication.java @@ -291,61 +291,16 @@ public class OsmandApplication extends Application { public synchronized void startApplication() { - if(applicationInitializing){ + if (applicationInitializing) { return; } applicationInitializing = true; startDialog = new ProgressDialogImplementation(this, null, false); startDialog.setRunnable("Initializing app", new Runnable() { //$NON-NLS-1$ - @Override public void run() { - List 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(); - // 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; - } - } - } + startApplicationBackground(); } }); startDialog.run(); @@ -354,6 +309,52 @@ public class OsmandApplication extends Application { } + private void startApplicationBackground() { + List 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 warnings, final Context uiContext) { if (warnings != null && !warnings.isEmpty()) { final StringBuilder b = new StringBuilder(); diff --git a/OsmAnd/src/net/osmand/plus/render/MapRenderRepositories.java b/OsmAnd/src/net/osmand/plus/render/MapRenderRepositories.java index c65a315e5f..a460549dfc 100644 --- a/OsmAnd/src/net/osmand/plus/render/MapRenderRepositories.java +++ b/OsmAnd/src/net/osmand/plus/render/MapRenderRepositories.java @@ -172,6 +172,8 @@ public class MapRenderRepositories { public void clearAllResources() { clearCache(); + bmp = null; + bmpLocation = null; for (String f : new ArrayList(files.keySet())) { closeConnection(files.get(f), f); } @@ -607,8 +609,11 @@ public class MapRenderRepositories { public synchronized void clearCache() { cObjects = new ArrayList(); cObjectsBox = new RectF(); - prevBmp = bmp = null; - requestedBox = prevBmpLocation = bmpLocation = null; + prevBmp = null; + requestedBox = prevBmpLocation = null; + // Do not clear main bitmap to not cause a screen refresh +// bmp = null; +// bmpLocation = null; } // / Manipulating with multipolygons