From 52746d176525267a357e802174a27ab8db07f513 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Wed, 25 Nov 2015 11:10:13 +0100 Subject: [PATCH] Fix some crashes --- OsmAnd/res/values-da/strings.xml | 2 +- .../activities/search/SearchByNameAbstractActivity.java | 2 +- .../net/osmand/plus/myplaces/AvailableGPXFragment.java | 9 +++------ .../net/osmand/plus/myplaces/SelectedGPXFragment.java | 2 +- .../src/net/osmand/plus/srtmplugin/HillshadeLayer.java | 4 +++- .../osmand/plus/voice/AbstractPrologCommandPlayer.java | 9 +++++++-- 6 files changed, 16 insertions(+), 12 deletions(-) diff --git a/OsmAnd/res/values-da/strings.xml b/OsmAnd/res/values-da/strings.xml index 75d5b8361a..b2ed6cbf78 100644 --- a/OsmAnd/res/values-da/strings.xml +++ b/OsmAnd/res/values-da/strings.xml @@ -2027,7 +2027,7 @@ Vælg hvor kortfilerne skal gemmes. \'Fra\' starter direkte på kortet Kort hentet - Kort over %1$ s er hentet. Gå tilbage til kortet for at begynde at bruge det. + Kort over %1$s er hentet. Gå tilbage til kortet for at begynde at bruge det. Gå til kortet QR kode Indtast landenavn diff --git a/OsmAnd/src/net/osmand/plus/activities/search/SearchByNameAbstractActivity.java b/OsmAnd/src/net/osmand/plus/activities/search/SearchByNameAbstractActivity.java index 5d7b057c72..bf01f11644 100644 --- a/OsmAnd/src/net/osmand/plus/activities/search/SearchByNameAbstractActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/search/SearchByNameAbstractActivity.java @@ -549,7 +549,7 @@ public abstract class SearchByNameAbstractActivity extends OsmandListActivity protected void select(int mode) { LatLon searchPoint = settings.getLastSearchedPoint(); AddressInformation ai = getAddressInformation(); - if (ai != null) { + if (ai != null && searchPoint != null) { if (mode == ADD_TO_FAVORITE) { Bundle b = new Bundle(); Dialog dlg = FavoriteDialogs.createAddFavouriteDialog(getActivity(), b); diff --git a/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java b/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java index a0a4a10d9c..e2c8f34d13 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java @@ -179,10 +179,8 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment { } public static void updateCurrentTrack(View v, final Activity ctx, final OsmandApplication app) { - if (OsmandPlugin.getEnabledPlugin(OsmandMonitoringPlugin.class) == null) { - return; - } - if (v == null || ctx == null || app == null) { + final OsmandMonitoringPlugin plugin = OsmandPlugin.getEnabledPlugin(OsmandMonitoringPlugin.class); + if (v == null || ctx == null || app == null || plugin == null) { return; } final boolean isRecording = app.getSettings().SAVE_GLOBAL_TRACK_TO_GPX.get(); @@ -195,10 +193,9 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment { stop.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - final OsmandMonitoringPlugin plugin = OsmandPlugin.getEnabledPlugin(OsmandMonitoringPlugin.class); if (isRecording) { plugin.stopRecording(); - } else { + } else if(plugin != null){ if (app.getLocationProvider().checkGPSEnabled(ctx)) { plugin.startGPXMonitoring(ctx); } diff --git a/OsmAnd/src/net/osmand/plus/myplaces/SelectedGPXFragment.java b/OsmAnd/src/net/osmand/plus/myplaces/SelectedGPXFragment.java index 81c826e794..ac87ee734e 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/SelectedGPXFragment.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/SelectedGPXFragment.java @@ -335,7 +335,7 @@ public class SelectedGPXFragment extends OsmAndListFragment { public void onClick(DialogInterface dialog, int which) { SelectedGpxFile sf = app.getSelectedGpxHelper().selectGpxFile(getGpx(), vis.isChecked(), false); int clr = list.get(colorSpinner.getSelectedItemPosition()); - if(clr != 0 ) { + if(clr != 0 && sf.getModifiableGpxFile() != null) { sf.getModifiableGpxFile().setColor(clr); sf.processPoints(); } diff --git a/OsmAnd/src/net/osmand/plus/srtmplugin/HillshadeLayer.java b/OsmAnd/src/net/osmand/plus/srtmplugin/HillshadeLayer.java index c89fe440c6..f3dc143207 100644 --- a/OsmAnd/src/net/osmand/plus/srtmplugin/HillshadeLayer.java +++ b/OsmAnd/src/net/osmand/plus/srtmplugin/HillshadeLayer.java @@ -48,9 +48,11 @@ public class HillshadeLayer extends MapTileLayer { private SQLiteDatabase sqliteDb; @Override protected Void doInBackground(Void... params) { + File tilesDir = app.getAppPath(IndexConstants.TILES_INDEX_DIR); + File cacheDir = app.getCacheDir(); // fix http://stackoverflow.com/questions/26937152/workaround-for-nexus-9-sqlite-file-write-operations-on-external-dirs - sqliteDb = SQLiteDatabase.openDatabase(new File(tilesDir, HILLSHADE_CACHE).getPath() , + sqliteDb = SQLiteDatabase.openDatabase(new File(cacheDir, HILLSHADE_CACHE).getPath() , null, SQLiteDatabase.ENABLE_WRITE_AHEAD_LOGGING | SQLiteDatabase.CREATE_IF_NECESSARY ); if(sqliteDb.getVersion() == 0) { diff --git a/OsmAnd/src/net/osmand/plus/voice/AbstractPrologCommandPlayer.java b/OsmAnd/src/net/osmand/plus/voice/AbstractPrologCommandPlayer.java index 8b0965ca54..95c9c23af9 100644 --- a/OsmAnd/src/net/osmand/plus/voice/AbstractPrologCommandPlayer.java +++ b/OsmAnd/src/net/osmand/plus/voice/AbstractPrologCommandPlayer.java @@ -117,11 +117,13 @@ public abstract class AbstractPrologCommandPlayer implements CommandPlayer, Stat @Override public void stateChanged(ApplicationMode change) { - prologSystem.getTheoryManager().retract(new Struct("appMode", new Var())); - prologSystem.getTheoryManager() + if(prologSystem != null) { + prologSystem.getTheoryManager().retract(new Struct("appMode", new Var())); + prologSystem.getTheoryManager() .assertA( new Struct("appMode", new Struct(ctx.getSettings().APPLICATION_MODE.get().getStringKey() .toLowerCase())), true, "", true); + } } private void init(String voiceProvider, OsmandSettings settings, String configFile) throws CommandPlayerException { @@ -256,6 +258,9 @@ public abstract class AbstractPrologCommandPlayer implements CommandPlayer, Stat @Override public void clear() { + if(ctx != null && ctx.getSettings() != null) { + ctx.getSettings().APPLICATION_MODE.removeListener(this); + } ctx = null; prologSystem = null; }