From ca75574f578bede91b960731401c842b9d88b787 Mon Sep 17 00:00:00 2001 From: Denis Date: Mon, 11 Aug 2014 19:03:19 +0300 Subject: [PATCH] Updated osmandSettings structure --- .../osmand/plus/OsmAndAppCustomization.java | 8 +++---- .../net/osmand/plus/OsmandApplication.java | 23 ++++++++++++------- .../plus/activities/MainMenuActivity.java | 1 - .../plus/sherpafy/SherpafyCustomization.java | 18 +++++++-------- .../plus/sherpafy/TourViewActivity.java | 6 ++--- 5 files changed, 31 insertions(+), 25 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/OsmAndAppCustomization.java b/OsmAnd/src/net/osmand/plus/OsmAndAppCustomization.java index dab38169c4..475951f43d 100644 --- a/OsmAnd/src/net/osmand/plus/OsmAndAppCustomization.java +++ b/OsmAnd/src/net/osmand/plus/OsmAndAppCustomization.java @@ -16,6 +16,7 @@ import net.osmand.plus.activities.PluginsActivity; import net.osmand.plus.activities.SettingsActivity; import net.osmand.plus.activities.search.SearchActivity; import net.osmand.plus.api.SettingsAPI; +import net.osmand.plus.api.SettingsAPIImpl; import net.osmand.plus.download.DownloadActivityType; import net.osmand.plus.views.OsmandMapTileView; import android.app.Activity; @@ -24,15 +25,14 @@ import android.view.Window; public class OsmAndAppCustomization { protected OsmandApplication app; + protected OsmandSettings osmandSettings; public void setup(OsmandApplication app) { this.app = app; - } - - public OsmandSettings createSettings(SettingsAPI api) { - return new OsmandSettings(app, api); + this.osmandSettings = new OsmandSettings(app, new net.osmand.plus.api.SettingsAPIImpl(app)); } + public OsmandSettings getOsmandSettings(){ return osmandSettings;} // Main menu public boolean checkExceptionsOnStart() { return true; diff --git a/OsmAnd/src/net/osmand/plus/OsmandApplication.java b/OsmAnd/src/net/osmand/plus/OsmandApplication.java index 9f3f1591b1..a2d15f18e8 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandApplication.java +++ b/OsmAnd/src/net/osmand/plus/OsmandApplication.java @@ -24,12 +24,14 @@ import net.osmand.plus.activities.SavingTrackHelper; import net.osmand.plus.activities.SettingsActivity; import net.osmand.plus.api.SQLiteAPI; import net.osmand.plus.api.SQLiteAPIImpl; +import net.osmand.plus.api.SettingsAPIImpl; import net.osmand.plus.helpers.WaypointHelper; import net.osmand.plus.monitoring.LiveMonitoringHelper; import net.osmand.plus.render.NativeOsmandLibrary; import net.osmand.plus.render.RendererRegistry; import net.osmand.plus.resources.ResourceManager; import net.osmand.plus.routing.RoutingHelper; +import net.osmand.plus.sherpafy.SherpafyCustomization; import net.osmand.plus.voice.CommandPlayer; import net.osmand.plus.voice.CommandPlayerException; import net.osmand.plus.voice.CommandPlayerFactory; @@ -126,9 +128,6 @@ public class OsmandApplication extends Application { } super.onCreate(); new Toast(this); // activate in UI thread to avoid further exceptions - appCustomization = new OsmAndAppCustomization(); - appCustomization.setup(this); - sqliteAPI = new SQLiteAPIImpl(this); try { bRouterServiceConnection = BRouterServiceConnection.connect(this); @@ -136,13 +135,21 @@ public class OsmandApplication extends Application { e.printStackTrace(); } - // settings used everywhere so they need to be created first - osmandSettings = appCustomization.createSettings(new net.osmand.plus.api.SettingsAPIImpl(this)); + if(Version.isSherpafy(this)) { + appCustomization = new SherpafyCustomization(); + } else { + appCustomization = new OsmAndAppCustomization(); + } + + appCustomization.setup(this); + + osmandSettings = appCustomization.getOsmandSettings(); // always update application mode to default if(!osmandSettings.FOLLOW_THE_ROUTE.get()){ osmandSettings.APPLICATION_MODE.set(osmandSettings.DEFAULT_APPLICATION_MODE.get()); } - + + applyTheme(this); routingHelper = new RoutingHelper(this, player); @@ -173,8 +180,8 @@ public class OsmandApplication extends Application { if (LOG.isDebugEnabled()) { LOG.debug("Time to init plugins " + (System.currentTimeMillis() - timeToStart) + " ms. Should be less < 800 ms"); } - - + + } @Override diff --git a/OsmAnd/src/net/osmand/plus/activities/MainMenuActivity.java b/OsmAnd/src/net/osmand/plus/activities/MainMenuActivity.java index b0b86db209..22076ca8f7 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MainMenuActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MainMenuActivity.java @@ -197,7 +197,6 @@ public class MainMenuActivity extends Activity { super.onCreate(savedInstanceState); if(Version.isSherpafy(getMyApplication())) { final Intent mapIntent = new Intent(this, TourViewActivity.class); - getMyApplication().setAppCustomization(new SherpafyCustomization()); startActivity(mapIntent); finish(); return; diff --git a/OsmAnd/src/net/osmand/plus/sherpafy/SherpafyCustomization.java b/OsmAnd/src/net/osmand/plus/sherpafy/SherpafyCustomization.java index 9e303d226d..8d87a41326 100644 --- a/OsmAnd/src/net/osmand/plus/sherpafy/SherpafyCustomization.java +++ b/OsmAnd/src/net/osmand/plus/sherpafy/SherpafyCustomization.java @@ -11,18 +11,17 @@ import java.util.TreeSet; import net.osmand.IProgress; import net.osmand.data.FavouritePoint; -import net.osmand.data.LocationPoint; import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.GPXUtilities; import net.osmand.plus.OsmAndAppCustomization; import net.osmand.plus.OsmandApplication; -import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings.CommonPreference; import net.osmand.plus.R; import net.osmand.plus.activities.DownloadIndexActivity; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivityLayers; import net.osmand.plus.api.FileSettingsAPIImpl; +import net.osmand.plus.api.SettingsAPI; import net.osmand.plus.download.DownloadActivityType; import net.osmand.plus.sherpafy.TourInformation.StageFavorite; import net.osmand.plus.sherpafy.TourInformation.StageInformation; @@ -38,7 +37,7 @@ public class SherpafyCustomization extends OsmAndAppCustomization { private static final String SELECTED_TOUR = "selected_tour"; private static final String ACCESS_CODE = "access_code"; private static final String SELECTED_STAGE = "selected_stage"; - private OsmandSettings originalSettings; + private CommonPreference selectedTourPref; private CommonPreference selectedStagePref; private List tourPresent = new ArrayList(); @@ -47,16 +46,17 @@ public class SherpafyCustomization extends OsmAndAppCustomization { private File toursFolder; private CommonPreference accessCodePref; private List cachedFavorites = new ArrayList(); + private SettingsAPI originalApi; @Override public void setup(OsmandApplication app) { super.setup(app); - originalSettings = createSettings(app.getSettings().getSettingsAPI()); - selectedTourPref = originalSettings.registerStringPreference(SELECTED_TOUR, null).makeGlobal(); - accessCodePref = originalSettings.registerStringPreference(ACCESS_CODE, "").makeGlobal(); - toursFolder = new File(originalSettings.getExternalStorageDirectory(), "osmand/tours"); + originalApi = osmandSettings.getSettingsAPI(); + selectedTourPref = osmandSettings.registerStringPreference(SELECTED_TOUR, null).makeGlobal(); + accessCodePref = osmandSettings.registerStringPreference(ACCESS_CODE, "").makeGlobal(); + toursFolder = new File(osmandSettings.getExternalStorageDirectory(), "osmand/tours"); } - + public boolean setAccessCode(String acCode) { acCode = acCode.toUpperCase(); if(validate(acCode)) { @@ -162,7 +162,7 @@ public class SherpafyCustomization extends OsmAndAppCustomization { } } if (selectedName == null) { - app.getSettings().setSettingsAPI(originalSettings.getSettingsAPI()); + app.getSettings().setSettingsAPI(originalApi); } } } diff --git a/OsmAnd/src/net/osmand/plus/sherpafy/TourViewActivity.java b/OsmAnd/src/net/osmand/plus/sherpafy/TourViewActivity.java index 15be819c32..c2dcbd208d 100644 --- a/OsmAnd/src/net/osmand/plus/sherpafy/TourViewActivity.java +++ b/OsmAnd/src/net/osmand/plus/sherpafy/TourViewActivity.java @@ -67,9 +67,9 @@ public class TourViewActivity extends SherlockFragmentActivity { @Override protected void onCreate(Bundle savedInstanceState) { - if (!(getMyApplication().getAppCustomization() instanceof SherpafyCustomization)) { - getMyApplication().setAppCustomization(new SherpafyCustomization()); - } +// if (!(getMyApplication().getAppCustomization() instanceof SherpafyCustomization)) { +// getMyApplication().setAppCustomization(new SherpafyCustomization()); +// } customization = (SherpafyCustomization) getMyApplication().getAppCustomization(); setTheme(R.style.OsmandLightTheme); ((OsmandApplication) getApplication()).setLanguage(this);