From f2755361311c92355f6a18e2d79b393403929bec Mon Sep 17 00:00:00 2001 From: max-klaus Date: Tue, 26 Nov 2019 16:36:25 +0300 Subject: [PATCH 01/11] Fix dashboard/settings srtm plugin get --- .../plus/activities/PluginActivity.java | 13 +++++++++- .../plus/dashboard/DashPluginsFragment.java | 24 +++++++++++++++++-- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/activities/PluginActivity.java b/OsmAnd/src/net/osmand/plus/activities/PluginActivity.java index e12f0266f1..4f64d740d8 100644 --- a/OsmAnd/src/net/osmand/plus/activities/PluginActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/PluginActivity.java @@ -8,6 +8,7 @@ import android.net.Uri; import android.os.Build; import android.os.Bundle; import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentManager; import android.util.Log; import android.view.MenuItem; import android.view.View; @@ -18,7 +19,9 @@ import android.widget.TextView; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.R; +import net.osmand.plus.chooseplan.ChoosePlanDialogFragment; import net.osmand.plus.download.DownloadIndexesThread; +import net.osmand.plus.srtmplugin.SRTMPlugin; public class PluginActivity extends OsmandActionBarActivity implements DownloadIndexesThread.DownloadEvents { private static final String TAG = "PluginActivity"; @@ -94,11 +97,19 @@ public class PluginActivity extends OsmandActionBarActivity implements Download } }); Button getButton = (Button)findViewById(R.id.plugin_get); + getButton.setText(plugin.isPaid() ? R.string.get_plugin : R.string.shared_string_install); getButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { try { - startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(plugin.getInstallURL()))); + if (plugin instanceof SRTMPlugin) { + FragmentManager fragmentManager = getSupportFragmentManager(); + if (fragmentManager != null) { + ChoosePlanDialogFragment.showHillshadeSrtmPluginInstance(fragmentManager); + } + } else { + startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(plugin.getInstallURL()))); + } } catch (Exception e) { //ignored } diff --git a/OsmAnd/src/net/osmand/plus/dashboard/DashPluginsFragment.java b/OsmAnd/src/net/osmand/plus/dashboard/DashPluginsFragment.java index 0bb0a03741..f50cc1af1a 100644 --- a/OsmAnd/src/net/osmand/plus/dashboard/DashPluginsFragment.java +++ b/OsmAnd/src/net/osmand/plus/dashboard/DashPluginsFragment.java @@ -5,6 +5,7 @@ import android.content.res.TypedArray; import android.net.Uri; import android.os.Bundle; import android.support.annotation.Nullable; +import android.support.v4.app.FragmentManager; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -17,8 +18,12 @@ import android.widget.TextView; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.R; import net.osmand.plus.activities.PluginActivity; +import net.osmand.plus.chooseplan.ChoosePlanDialogFragment; import net.osmand.plus.dashboard.tools.DashFragmentData; import net.osmand.plus.development.OsmandDevelopmentPlugin; +import net.osmand.plus.openseamapsplugin.NauticalMapsPlugin; +import net.osmand.plus.skimapsplugin.SkiMapsPlugin; +import net.osmand.plus.srtmplugin.SRTMPlugin; import java.util.ArrayList; import java.util.Collections; @@ -45,7 +50,14 @@ public class DashPluginsFragment extends DashBaseFragment { return new View.OnClickListener() { @Override public void onClick(View view) { - startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(plugin.getInstallURL()))); + if (plugin instanceof SRTMPlugin) { + FragmentManager fragmentManager = getFragmentManager(); + if (fragmentManager != null) { + ChoosePlanDialogFragment.showHillshadeSrtmPluginInstance(fragmentManager); + } + } else { + startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(plugin.getInstallURL()))); + } closeDashboard(); } }; @@ -82,10 +94,17 @@ public class DashPluginsFragment extends DashBaseFragment { private void initPlugins() { List notActivePlugins = OsmandPlugin.getNotEnabledVisiblePlugins(); + notActivePlugins.remove(OsmandPlugin.getPlugin(SkiMapsPlugin.class)); + notActivePlugins.remove(OsmandPlugin.getPlugin(NauticalMapsPlugin.class)); Collections.shuffle(notActivePlugins); + + List enabledPlugins = OsmandPlugin.getEnabledVisiblePlugins(); + enabledPlugins.remove(OsmandPlugin.getPlugin(SkiMapsPlugin.class)); + enabledPlugins.remove(OsmandPlugin.getPlugin(NauticalMapsPlugin.class)); + plugins = new ArrayList(); Iterator nit = notActivePlugins.iterator(); - Iterator it = OsmandPlugin.getEnabledVisiblePlugins().iterator(); + Iterator it = enabledPlugins.iterator(); addPluginsToLimit(nit, 1); addPluginsToLimit(it, 5); addPluginsToLimit(nit, 5); @@ -152,6 +171,7 @@ public class DashPluginsFragment extends DashBaseFragment { CompoundButton enableDisableButton = (CompoundButton) view.findViewById(R.id.plugin_enable_disable); Button getButton = (Button) view.findViewById(R.id.get_plugin); + getButton.setText(plugin.isPaid() ? R.string.get_plugin : R.string.shared_string_install); getButton.setOnClickListener(getListener(plugin)); enableDisableButton.setOnCheckedChangeListener(null); updatePluginState(view, plugin); From d0bdc0ad21c92cc98c144518f59bef528a45b264 Mon Sep 17 00:00:00 2001 From: Chumva Date: Tue, 26 Nov 2019 15:39:19 +0200 Subject: [PATCH 02/11] Combine speak routing alarms and voice mute --- OsmAnd/res/xml/navigation_settings_new.xml | 3 +- OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java | 2 -- .../src/net/osmand/plus/OsmandSettings.java | 3 +- .../plus/helpers/ExternalApiHelper.java | 2 -- .../quickaction/actions/NavVoiceAction.java | 10 ++----- .../MapRouteInfoMenu.java | 5 ++-- .../RouteOptionsBottomSheet.java | 14 ++++----- .../RoutingOptionsHelper.java | 6 ++-- .../net/osmand/plus/routing/VoiceRouter.java | 30 +++++++++++-------- .../plus/settings/NavigationFragment.java | 23 ++++++++++++-- .../plus/settings/VoiceAnnouncesFragment.java | 19 ++++++++---- 11 files changed, 70 insertions(+), 47 deletions(-) diff --git a/OsmAnd/res/xml/navigation_settings_new.xml b/OsmAnd/res/xml/navigation_settings_new.xml index 49125d8f49..dd1c6b0294 100644 --- a/OsmAnd/res/xml/navigation_settings_new.xml +++ b/OsmAnd/res/xml/navigation_settings_new.xml @@ -22,8 +22,9 @@ tools:icon="@drawable/ic_action_alert" /> SHOW_NEARBY_FAVORITES = new BooleanPreference("show_nearby_favorites", false).makeProfile().cache(); public final OsmandPreference SHOW_NEARBY_POI = new BooleanPreference("show_nearby_poi", false).makeProfile().cache(); - public final OsmandPreference SPEAK_ROUTING_ALARMS = new BooleanPreference("speak_routing_alarms", true).makeProfile().cache(); public final OsmandPreference SPEAK_STREET_NAMES = new BooleanPreference("speak_street_names", true).makeProfile().cache(); public final CommonPreference SPEAK_TRAFFIC_WARNINGS = new BooleanPreference("speak_traffic_warnings", true).makeProfile().cache(); { @@ -3130,7 +3129,7 @@ public class OsmandSettings { public final OsmandPreference USE_OSM_LIVE_FOR_PUBLIC_TRANSPORT = new BooleanPreference("enable_osmc_public_transport", false).makeGlobal(); - public final OsmandPreference VOICE_MUTE = new BooleanPreference("voice_mute", false).makeGlobal(); + public final OsmandPreference VOICE_MUTE = new BooleanPreference("voice_mute", false).makeProfile().cache(); // for background service public final OsmandPreference MAP_ACTIVITY_ENABLED = new BooleanPreference("map_activity_enabled", false).makeGlobal(); diff --git a/OsmAnd/src/net/osmand/plus/helpers/ExternalApiHelper.java b/OsmAnd/src/net/osmand/plus/helpers/ExternalApiHelper.java index e61dc78cd9..64ed3acfcb 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/ExternalApiHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/ExternalApiHelper.java @@ -403,11 +403,9 @@ public class ExternalApiHelper { resultCode = Activity.RESULT_OK; } } else if (API_CMD_MUTE_NAVIGATION.equals(cmd)) { - mapActivity.getMyApplication().getSettings().VOICE_MUTE.set(true); mapActivity.getRoutingHelper().getVoiceRouter().setMute(true); resultCode = Activity.RESULT_OK; } else if (API_CMD_UNMUTE_NAVIGATION.equals(cmd)) { - mapActivity.getMyApplication().getSettings().VOICE_MUTE.set(false); mapActivity.getRoutingHelper().getVoiceRouter().setMute(false); resultCode = Activity.RESULT_OK; } else if (API_CMD_RECORD_AUDIO.equals(cmd) diff --git a/OsmAnd/src/net/osmand/plus/quickaction/actions/NavVoiceAction.java b/OsmAnd/src/net/osmand/plus/quickaction/actions/NavVoiceAction.java index 7da8366bff..1e4eb81502 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/actions/NavVoiceAction.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/actions/NavVoiceAction.java @@ -23,16 +23,12 @@ public class NavVoiceAction extends QuickAction { @Override public void execute(MapActivity activity) { - - boolean voice = activity.getMyApplication().getSettings().VOICE_MUTE.get(); - - activity.getMyApplication().getSettings().VOICE_MUTE.set(!voice); - activity.getRoutingHelper().getVoiceRouter().setMute(!voice); + boolean mute = activity.getMyApplication().getSettings().VOICE_MUTE.get(); + activity.getMyApplication().getSettings().VOICE_MUTE.set(!mute); } @Override public void drawUI(ViewGroup parent, MapActivity activity) { - View view = LayoutInflater.from(parent.getContext()) .inflate(R.layout.quick_action_with_text, parent, false); @@ -44,7 +40,6 @@ public class NavVoiceAction extends QuickAction { @Override public String getActionText(OsmandApplication application) { - return application.getSettings().VOICE_MUTE.get() ? application.getString(R.string.quick_action_navigation_voice_off) : application.getString(R.string.quick_action_navigation_voice_on); @@ -52,7 +47,6 @@ public class NavVoiceAction extends QuickAction { @Override public boolean isActionWithSlash(OsmandApplication application) { - return !application.getSettings().VOICE_MUTE.get(); } } diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java index 9e2113d18a..ee2994d7d4 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java @@ -1054,10 +1054,11 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener } private void createMuteSoundRoutingParameterButton(MapActivity mapActivity, final MuteSoundRoutingParameter parameter, final RouteMenuAppModes mode, LinearLayout optionsContainer) { + final ApplicationMode appMode = mapActivity.getRoutingHelper().getAppMode(); final int colorActive = ContextCompat.getColor(mapActivity, nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light); final int colorDisabled = ContextCompat.getColor(mapActivity, R.color.description_font_and_bottom_sheet_icons); String text = null; - final boolean active = !mapActivity.getRoutingHelper().getVoiceRouter().isMute(); + boolean active = !mapActivity.getRoutingHelper().getVoiceRouter().isMuteForMode(appMode); if (mode.parameters.size() <= 2) { text = mapActivity.getString(active ? R.string.shared_string_on : R.string.shared_string_off); } @@ -1067,7 +1068,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener OsmandApplication app = getApp(); if (app != null) { app.getRoutingOptionsHelper().switchSound(); - boolean active = !app.getRoutingHelper().getVoiceRouter().isMute(); + boolean active = !app.getRoutingHelper().getVoiceRouter().isMuteForMode(appMode); String text = app.getString(active ? R.string.shared_string_on : R.string.shared_string_off); Drawable itemDrawable = app.getUIUtilities().getIcon(active ? parameter.getActiveIconId() : parameter.getDisabledIconId(), nightMode ? R.color.route_info_control_icon_color_dark : R.color.route_info_control_icon_color_light); diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteOptionsBottomSheet.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteOptionsBottomSheet.java index 4232ec40e3..3242b89383 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteOptionsBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteOptionsBottomSheet.java @@ -133,22 +133,22 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment { } private BaseBottomSheetItem createMuteSoundItem(final LocalRoutingParameter optionsItem) { + boolean active = !routingHelper.getVoiceRouter().isMuteForMode(applicationMode); final BottomSheetItemWithCompoundButton[] muteSoundItem = new BottomSheetItemWithCompoundButton[1]; muteSoundItem[0] = (BottomSheetItemWithCompoundButton) new BottomSheetItemWithCompoundButton.Builder() - .setChecked(!routingHelper.getVoiceRouter().isMute()) + .setChecked(active) .setDescription(getString(R.string.voice_announcements)) - .setIcon(getContentIcon((routingHelper.getVoiceRouter().isMute() ? optionsItem.getDisabledIconId() : optionsItem.getActiveIconId()))) + .setIcon(getContentIcon(active ? optionsItem.getActiveIconId() : optionsItem.getDisabledIconId())) .setTitle(getString(R.string.shared_string_sound)) .setLayoutId(R.layout.bottom_sheet_item_with_descr_and_switch_56dp) .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { routingOptionsHelper.addNewRouteMenuParameter(applicationMode, optionsItem); - boolean mt = !routingHelper.getVoiceRouter().isMute(); - settings.VOICE_MUTE.set(mt); - routingHelper.getVoiceRouter().setMute(mt); - muteSoundItem[0].setChecked(!routingHelper.getVoiceRouter().isMute()); - muteSoundItem[0].setIcon(getContentIcon((routingHelper.getVoiceRouter().isMute() ? optionsItem.getDisabledIconId() : optionsItem.getActiveIconId()))); + boolean active = !routingHelper.getVoiceRouter().isMuteForMode(applicationMode); + routingHelper.getVoiceRouter().setMuteForMode(applicationMode, active); + muteSoundItem[0].setChecked(!active); + muteSoundItem[0].setIcon(getContentIcon(!active ? optionsItem.getActiveIconId() : optionsItem.getDisabledIconId())); updateMenu(); } }) diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/RoutingOptionsHelper.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/RoutingOptionsHelper.java index bc1cda9b6f..5c90b98de2 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/RoutingOptionsHelper.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/RoutingOptionsHelper.java @@ -95,9 +95,9 @@ public class RoutingOptionsHelper { public void switchSound() { RoutingHelper routingHelper = app.getRoutingHelper(); - boolean mt = !routingHelper.getVoiceRouter().isMute(); - settings.VOICE_MUTE.set(mt); - routingHelper.getVoiceRouter().setMute(mt); + ApplicationMode mode = routingHelper.getAppMode(); + boolean mute = !routingHelper.getVoiceRouter().isMuteForMode(mode); + routingHelper.getVoiceRouter().setMuteForMode(mode, mute); } public void switchMusic() { diff --git a/OsmAnd/src/net/osmand/plus/routing/VoiceRouter.java b/OsmAnd/src/net/osmand/plus/routing/VoiceRouter.java index ef092063b1..a05ebe5a40 100644 --- a/OsmAnd/src/net/osmand/plus/routing/VoiceRouter.java +++ b/OsmAnd/src/net/osmand/plus/routing/VoiceRouter.java @@ -49,7 +49,6 @@ public class VoiceRouter { protected static CommandPlayer player; protected final OsmandSettings settings; - private static boolean mute = false; private static int currentStatus = STATUS_UNKNOWN; private static boolean playedAndArriveAtTarget = false; private static float playGoAheadDist = 0; @@ -87,7 +86,6 @@ public class VoiceRouter { VoiceRouter(RoutingHelper router, final OsmandSettings settings) { this.router = router; this.settings = settings; - mute = settings.VOICE_MUTE.get(); } public void setPlayer(CommandPlayer player) { @@ -104,13 +102,21 @@ public class VoiceRouter { public CommandPlayer getPlayer() { return player; } - + public void setMute(boolean mute) { - this.mute = mute; + settings.VOICE_MUTE.set(mute); } - + + public void setMuteForMode(ApplicationMode mode, boolean mute) { + settings.VOICE_MUTE.setModeValue(mode, mute); + } + public boolean isMute() { - return mute; + return settings.VOICE_MUTE.get(); + } + + public boolean isMuteForMode(ApplicationMode mode) { + return settings.VOICE_MUTE.getModeValue(mode); } private CommandBuilder getNewCommandPlayerToPlay() { @@ -907,13 +913,11 @@ public class VoiceRouter { } private void play(CommandBuilder p) { - if (settings.SPEAK_ROUTING_ALARMS.get()) { - if (p != null) { - List played = p.play(); - notifyOnVoiceMessage(p.getListCommands(), played); - } else { - notifyOnVoiceMessage(Collections.EMPTY_LIST, Collections.EMPTY_LIST); - } + if (p != null) { + List played = p.play(); + notifyOnVoiceMessage(p.getListCommands(), played); + } else { + notifyOnVoiceMessage(Collections.EMPTY_LIST, Collections.EMPTY_LIST); } } diff --git a/OsmAnd/src/net/osmand/plus/settings/NavigationFragment.java b/OsmAnd/src/net/osmand/plus/settings/NavigationFragment.java index 2a27514ba0..697cb5c423 100644 --- a/OsmAnd/src/net/osmand/plus/settings/NavigationFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/NavigationFragment.java @@ -4,6 +4,7 @@ import android.support.v7.preference.Preference; import android.support.v7.preference.SwitchPreferenceCompat; import net.osmand.plus.R; +import net.osmand.plus.activities.MapActivity; import net.osmand.plus.settings.preferences.SwitchPreferenceEx; public class NavigationFragment extends BaseSettingsFragment { @@ -14,7 +15,7 @@ public class NavigationFragment extends BaseSettingsFragment { protected void setupPreferences() { Preference routeParameters = findPreference("route_parameters"); SwitchPreferenceCompat showRoutingAlarms = (SwitchPreferenceCompat) findPreference(settings.SHOW_ROUTING_ALARMS.getId()); - SwitchPreferenceCompat speakRoutingAlarms = (SwitchPreferenceCompat) findPreference(settings.SPEAK_ROUTING_ALARMS.getId()); + SwitchPreferenceCompat speakRoutingAlarms = (SwitchPreferenceCompat) findPreference(settings.VOICE_MUTE.getId()); SwitchPreferenceCompat turnScreenOn = (SwitchPreferenceCompat) findPreference(settings.TURN_SCREEN_ON_ENABLED.getId()); SwitchPreferenceEx animateMyLocation = (SwitchPreferenceEx) findPreference(settings.ANIMATE_MY_LOCATION.getId()); @@ -24,13 +25,31 @@ public class NavigationFragment extends BaseSettingsFragment { turnScreenOn.setIcon(getContentIcon(R.drawable.ic_action_turn_screen_on)); setupVehicleParametersPref(); - + speakRoutingAlarms.setChecked(!settings.VOICE_MUTE.getModeValue(getSelectedAppMode())); animateMyLocation.setDescription(getString(R.string.animate_my_location_desc)); } + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + String key = preference.getKey(); + if (settings.VOICE_MUTE.getId().equals(key) && newValue instanceof Boolean) { + settings.VOICE_MUTE.setModeValue(getSelectedAppMode(), !(Boolean) newValue); + updateMenu(); + return true; + } + return super.onPreferenceChange(preference, newValue); + } + private void setupVehicleParametersPref() { Preference vehicleParameters = findPreference("vehicle_parameters"); int iconRes = getSelectedAppMode().getIconRes(); vehicleParameters.setIcon(getContentIcon(iconRes)); } + + private void updateMenu() { + MapActivity mapActivity = getMapActivity(); + if (mapActivity != null) { + mapActivity.getMapRouteInfoMenu().updateMenu(); + } + } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/settings/VoiceAnnouncesFragment.java b/OsmAnd/src/net/osmand/plus/settings/VoiceAnnouncesFragment.java index 0d6204e4fb..ec9d28988c 100644 --- a/OsmAnd/src/net/osmand/plus/settings/VoiceAnnouncesFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/VoiceAnnouncesFragment.java @@ -20,6 +20,7 @@ import net.osmand.plus.ApplicationMode; import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.Version; +import net.osmand.plus.activities.MapActivity; import net.osmand.plus.download.DownloadActivity; import net.osmand.plus.download.DownloadActivityType; import net.osmand.plus.helpers.FileNameTranslationHelper; @@ -41,10 +42,11 @@ public class VoiceAnnouncesFragment extends BaseSettingsFragment { @Override public void onClick(View view) { ApplicationMode selectedMode = getSelectedAppMode(); - boolean checked = !settings.SPEAK_ROUTING_ALARMS.getModeValue(selectedMode); - settings.SPEAK_ROUTING_ALARMS.setModeValue(selectedMode, checked); + boolean checked = !settings.VOICE_MUTE.getModeValue(selectedMode); + settings.VOICE_MUTE.setModeValue(selectedMode, checked); updateToolbarSwitch(); - enableDisablePreferences(checked); + enableDisablePreferences(!checked); + updateMenu(); } }); } @@ -60,7 +62,7 @@ public class VoiceAnnouncesFragment extends BaseSettingsFragment { if (view == null) { return; } - boolean checked = settings.SPEAK_ROUTING_ALARMS.getModeValue(getSelectedAppMode()); + boolean checked = !settings.VOICE_MUTE.getModeValue(getSelectedAppMode()); int color = checked ? getActiveProfileColor() : ContextCompat.getColor(app, R.color.preference_top_switch_off); View switchContainer = view.findViewById(R.id.toolbar_switch_container); @@ -88,7 +90,7 @@ public class VoiceAnnouncesFragment extends BaseSettingsFragment { setupAudioStreamGuidancePref(); setupInterruptMusicPref(); } - enableDisablePreferences(settings.SPEAK_ROUTING_ALARMS.getModeValue(getSelectedAppMode())); + enableDisablePreferences(!settings.VOICE_MUTE.getModeValue(getSelectedAppMode())); } private void setupSpeedLimitExceedPref() { @@ -218,6 +220,13 @@ public class VoiceAnnouncesFragment extends BaseSettingsFragment { bld.show(); } + private void updateMenu() { + MapActivity mapActivity = getMapActivity(); + if (mapActivity != null) { + mapActivity.getMapRouteInfoMenu().updateMenu(); + } + } + @Override public boolean onPreferenceChange(Preference preference, Object newValue) { String prefId = preference.getKey(); From e0950f4a57bf8b8c225798202b1f01cafb7a1577 Mon Sep 17 00:00:00 2001 From: Chumva Date: Tue, 26 Nov 2019 16:38:34 +0200 Subject: [PATCH 03/11] Improve preferences migration for prefs which become global --- .../src/net/osmand/plus/AppInitializer.java | 5 ++-- .../src/net/osmand/plus/OsmandSettings.java | 25 ++++++++++++------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/AppInitializer.java b/OsmAnd/src/net/osmand/plus/AppInitializer.java index 6edea04bcf..b9e70643ce 100644 --- a/OsmAnd/src/net/osmand/plus/AppInitializer.java +++ b/OsmAnd/src/net/osmand/plus/AppInitializer.java @@ -190,8 +190,9 @@ public class AppInitializer implements IProgress { app.getSettings().BILLING_PURCHASE_TOKENS_SENT.set(""); startPrefs.edit().putInt(VERSION_INSTALLED_NUMBER, VERSION_3_2).commit(); } - if (prevAppVersion < VERSION_3_5 || Version.getAppVersion(app).equals("3.5.3")) { - app.getSettings().migrateGlobalPrefsToProfile(); + if (prevAppVersion < VERSION_3_5 || Version.getAppVersion(app).equals("3.5.3") + || Version.getAppVersion(app).equals("3.5.4")) { + app.getSettings().migratePreferences(); startPrefs.edit().putInt(VERSION_INSTALLED_NUMBER, VERSION_3_5).commit(); } startPrefs.edit().putString(VERSION_INSTALLED, Version.getFullVersion(app)).commit(); diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index de79718817..8ef8dbcee0 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -229,24 +229,31 @@ public class OsmandSettings { return globalPreferences != null && globalPreferences.getBoolean(SETTING_CUSTOMIZED_ID, false); } - public void migrateGlobalPrefsToProfile() { - SharedPreferences sharedPreferences = (SharedPreferences) globalPreferences; - Map map = sharedPreferences.getAll(); - for (String key : map.keySet()) { + public void migratePreferences() { + SharedPreferences globalSharedPreferences = (SharedPreferences) globalPreferences; + Map globalPrefsMap = globalSharedPreferences.getAll(); + for (String key : globalPrefsMap.keySet()) { OsmandPreference pref = getPreference(key); if (pref instanceof CommonPreference) { CommonPreference commonPreference = (CommonPreference) pref; if (!commonPreference.global) { List modes = commonPreference.general ? Collections.singletonList(ApplicationMode.DEFAULT) : ApplicationMode.allPossibleValues(); - boolean valueSaved = false; for (ApplicationMode mode : modes) { if (!commonPreference.isSetForMode(mode)) { - valueSaved = setPreference(key, map.get(key), mode) || valueSaved; + setPreference(key, globalPrefsMap.get(key), mode); } } - if (valueSaved) { - settingsAPI.edit(globalPreferences).remove(key).commit(); - } + } + } + } + SharedPreferences defaultProfilePreferences = (SharedPreferences) this.defaultProfilePreferences; + Map defaultPrefsMap = defaultProfilePreferences.getAll(); + for (String key : defaultPrefsMap.keySet()) { + OsmandPreference pref = getPreference(key); + if (pref instanceof CommonPreference) { + CommonPreference commonPreference = (CommonPreference) pref; + if (commonPreference.global && !commonPreference.isSet()) { + setPreference(key, defaultPrefsMap.get(key)); } } } From 13f1924027904eb2da8c6cf9d79383875be4b18f Mon Sep 17 00:00:00 2001 From: max-klaus Date: Tue, 26 Nov 2019 17:57:54 +0300 Subject: [PATCH 04/11] Fix #7936 --- .../osmand/plus/download/ui/LocalIndexesFragment.java | 10 ++++++---- .../plus/monitoring/OnSaveCurrentTrackFragment.java | 11 +++++++---- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/download/ui/LocalIndexesFragment.java b/OsmAnd/src/net/osmand/plus/download/ui/LocalIndexesFragment.java index d4799e9f3d..3c883974cc 100644 --- a/OsmAnd/src/net/osmand/plus/download/ui/LocalIndexesFragment.java +++ b/OsmAnd/src/net/osmand/plus/download/ui/LocalIndexesFragment.java @@ -77,7 +77,8 @@ import android.widget.Toast; public class LocalIndexesFragment extends OsmandExpandableListFragment implements DownloadEvents { - public static final Pattern ILLEGAL_FILE_NAME_CHARACTERS = Pattern.compile("[?:\"*|/\\<>]"); + public static final Pattern ILLEGAL_FILE_NAME_CHARACTERS = Pattern.compile("[?:\"*|/<>]"); + public static final Pattern ILLEGAL_PATH_NAME_CHARACTERS = Pattern.compile("[?:\"*|<>]"); private LoadLocalIndexTask asyncLoader; private Map filesToUpdate = new HashMap<>(); @@ -301,7 +302,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement @Override public void onClick(View v) { OsmandApplication app = (OsmandApplication) a.getApplication(); - if (renameGpxFile(app, f, editText.getText().toString() + ext, callback) != null) { + if (renameGpxFile(app, f, editText.getText().toString() + ext, false, callback) != null) { alertDialog.dismiss(); } } @@ -312,12 +313,13 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement } } - public static File renameGpxFile(OsmandApplication ctx, File source, String newName, RenameCallback callback) { + public static File renameGpxFile(OsmandApplication ctx, File source, String newName, boolean dirAllowed, RenameCallback callback) { if (Algorithms.isEmpty(newName)) { Toast.makeText(ctx, R.string.empty_filename, Toast.LENGTH_LONG).show(); return null; } - if (ILLEGAL_FILE_NAME_CHARACTERS.matcher(newName).find()) { + Pattern illegalCharactersPattern = dirAllowed ? ILLEGAL_PATH_NAME_CHARACTERS : ILLEGAL_FILE_NAME_CHARACTERS; + if (illegalCharactersPattern.matcher(newName).find()) { Toast.makeText(ctx, R.string.file_name_containes_illegal_char, Toast.LENGTH_LONG).show(); return null; } diff --git a/OsmAnd/src/net/osmand/plus/monitoring/OnSaveCurrentTrackFragment.java b/OsmAnd/src/net/osmand/plus/monitoring/OnSaveCurrentTrackFragment.java index aa263aa154..93122c8fee 100644 --- a/OsmAnd/src/net/osmand/plus/monitoring/OnSaveCurrentTrackFragment.java +++ b/OsmAnd/src/net/osmand/plus/monitoring/OnSaveCurrentTrackFragment.java @@ -52,6 +52,7 @@ public class OnSaveCurrentTrackFragment extends BottomSheetDialogFragment { private boolean showOnMap = true; private boolean openTrack = false; private File file; + private String savedGpxDir = ""; private String savedGpxName = ""; private String newGpxName = ""; @@ -63,8 +64,10 @@ public class OnSaveCurrentTrackFragment extends BottomSheetDialogFragment { if (args != null && args.containsKey(SAVED_TRACKS_KEY)) { ArrayList savedGpxNames = args.getStringArrayList(SAVED_TRACKS_KEY); if (savedGpxNames != null && savedGpxNames.size() > 0) { - savedGpxName = savedGpxNames.get(savedGpxNames.size() - 1); - newGpxName = savedGpxName; + String fileName = savedGpxNames.get(savedGpxNames.size() - 1); + savedGpxDir = new File(fileName).getParent(); + savedGpxName = new File(fileName).getName(); + newGpxName = this.savedGpxName; } } else { dismiss(); @@ -168,7 +171,7 @@ public class OnSaveCurrentTrackFragment extends BottomSheetDialogFragment { private File renameGpxFile() { OsmandApplication app = requiredMyApplication(); - File savedFile = new File(app.getAppCustomization().getTracksDir(), savedGpxName + ".gpx"); + File savedFile = new File(app.getAppCustomization().getTracksDir(), new File(savedGpxDir, savedGpxName + ".gpx").getPath()); if (savedGpxName.equalsIgnoreCase(newGpxName)) { return savedFile; } @@ -176,7 +179,7 @@ public class OnSaveCurrentTrackFragment extends BottomSheetDialogFragment { Toast.makeText(app, R.string.empty_filename, Toast.LENGTH_LONG).show(); return null; } - return LocalIndexesFragment.renameGpxFile(app, savedFile, newGpxName + ".gpx", null); + return LocalIndexesFragment.renameGpxFile(app, savedFile, newGpxName + ".gpx", true, null); } private void showOnMap(File f, boolean animated) { From 853df21c253c1c05d0ac66ea25de5865334cc344 Mon Sep 17 00:00:00 2001 From: max-klaus Date: Tue, 26 Nov 2019 18:55:33 +0300 Subject: [PATCH 05/11] Fix string --- OsmAnd/res/values-tr/strings.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OsmAnd/res/values-tr/strings.xml b/OsmAnd/res/values-tr/strings.xml index cd8ef49954..161587f788 100644 --- a/OsmAnd/res/values-tr/strings.xml +++ b/OsmAnd/res/values-tr/strings.xml @@ -2627,7 +2627,7 @@ \n \n\'Ayarlar\' → \'Gizlilik ve Güvenlik\' bölümünde istediğiniz zaman yapılandırın. Ülke ve bölge haritası popülaritesini anlamamıza yardımcı olur. - %1$\'lerimizi kabul ediyorsanız \"İzin Ver\"e dokunun + %1$s\'lerimizi kabul ediyorsanız \"İzin Ver\"e dokunun Navigasyon türü routing.xml dosyasının değiştirilmiş versiyonunu ..osmand/routing dizinine ekleyebilirsiniz Pusula cetvelini göster From 750dd5a5b48103d38e3b6a1ef64e2577e7d1cf6c Mon Sep 17 00:00:00 2001 From: max-klaus Date: Tue, 26 Nov 2019 19:14:22 +0300 Subject: [PATCH 06/11] Fix DestinationReachedMenuFragment dismiss crash --- .../other/DestinationReachedMenuFragment.java | 90 ++++++++++++------- 1 file changed, 57 insertions(+), 33 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/DestinationReachedMenuFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/DestinationReachedMenuFragment.java index f11c45b891..f14ec16ba4 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/DestinationReachedMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/DestinationReachedMenuFragment.java @@ -37,15 +37,20 @@ public class DestinationReachedMenuFragment extends Fragment { @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); - if (menu == null) { - menu = new DestinationReachedMenu(getMapActivity()); + MapActivity mapActivity = getMapActivity(); + if (menu == null && mapActivity != null) { + menu = new DestinationReachedMenu(mapActivity); } } @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - ContextThemeWrapper ctx = new ContextThemeWrapper(getMapActivity(), menu.isLight() ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme); + MapActivity mapActivity = getMapActivity(); + if (mapActivity == null || menu == null) { + return null; + } + ContextThemeWrapper ctx = new ContextThemeWrapper(mapActivity, menu.isLight() ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme); LayoutInflater inf = LayoutInflater.from(ctx); View view = inf.inflate(R.layout.dest_reached_menu_fragment, container, false); AndroidUtils.addStatusBarPadding21v(ctx, view); @@ -56,7 +61,7 @@ public class DestinationReachedMenuFragment extends Fragment { } }); - UiUtilities iconsCache = getMapActivity().getMyApplication().getUIUtilities(); + UiUtilities iconsCache = mapActivity.getMyApplication().getUIUtilities(); ImageButton closeImageButton = (ImageButton) view.findViewById(R.id.closeImageButton); closeImageButton.setImageDrawable(iconsCache.getIcon(R.drawable.ic_action_remove_dark, menu.isLight())); @@ -83,23 +88,26 @@ public class DestinationReachedMenuFragment extends Fragment { recalcDestButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - TargetPointsHelper helper = getMapActivity().getMyApplication().getTargetPointsHelper(); - TargetPoint target = helper.getPointToNavigate(); + MapActivity mapActivity = getMapActivity(); + if (mapActivity != null) { + TargetPointsHelper helper = mapActivity.getMyApplication().getTargetPointsHelper(); + TargetPoint target = helper.getPointToNavigate(); - dismissMenu(); + dismissMenu(); - if (target != null) { - helper.navigateToPoint(new LatLon(target.getLatitude(), target.getLongitude()), - true, -1, target.getOriginalPointDescription()); - getMapActivity().getMapActions().recalculateRoute(false); - getMapActivity().getMapLayers().getMapControlsLayer().startNavigation(); + if (target != null) { + helper.navigateToPoint(new LatLon(target.getLatitude(), target.getLongitude()), + true, -1, target.getOriginalPointDescription()); + mapActivity.getMapActions().recalculateRoute(false); + mapActivity.getMapLayers().getMapControlsLayer().startNavigation(); + } } } }); Button findParkingButton = (Button) view.findViewById(R.id.findParkingButton); - ApplicationMode appMode = getMapActivity().getMyApplication().getRoutingHelper().getAppMode(); + ApplicationMode appMode = mapActivity.getMyApplication().getRoutingHelper().getAppMode(); if (!appMode.isDerivedRoutingFrom(ApplicationMode.CAR)) { findParkingButton.setVisibility(View.GONE); @@ -112,7 +120,7 @@ public class DestinationReachedMenuFragment extends Fragment { public void onClick(View v) { MapActivity mapActivity = getMapActivity(); if (mapActivity != null) { - PoiFiltersHelper helper = getMapActivity().getMyApplication().getPoiFilters(); + PoiFiltersHelper helper = mapActivity.getMyApplication().getPoiFilters(); PoiUIFilter parkingFilter = helper.getFilterById(PoiUIFilter.STD_PREFIX + "parking"); mapActivity.showQuickSearch(parkingFilter); } @@ -134,13 +142,19 @@ public class DestinationReachedMenuFragment extends Fragment { @Override public void onStart() { super.onStart(); - getMapActivity().getContextMenu().setBaseFragmentVisibility(false); + MapActivity mapActivity = getMapActivity(); + if (mapActivity != null) { + mapActivity.getContextMenu().setBaseFragmentVisibility(false); + } } @Override public void onStop() { super.onStop(); - getMapActivity().getContextMenu().setBaseFragmentVisibility(true); + MapActivity mapActivity = getMapActivity(); + if (mapActivity != null) { + mapActivity.getContextMenu().setBaseFragmentVisibility(true); + } } @Override @@ -150,19 +164,22 @@ public class DestinationReachedMenuFragment extends Fragment { } private void finishNavigation() { - getMapActivity().getMyApplication().getTargetPointsHelper().removeWayPoint(true, -1); - Object contextMenuObj = getMapActivity().getContextMenu().getObject(); - if (getMapActivity().getContextMenu().isActive() - && contextMenuObj instanceof TargetPoint) { - TargetPoint targetPoint = (TargetPoint) contextMenuObj; - if (!targetPoint.start && !targetPoint.intermediate) { - getMapActivity().getContextMenu().close(); + MapActivity mapActivity = getMapActivity(); + if (mapActivity != null) { + mapActivity.getMyApplication().getTargetPointsHelper().removeWayPoint(true, -1); + Object contextMenuObj = mapActivity.getContextMenu().getObject(); + if (mapActivity.getContextMenu().isActive() + && contextMenuObj instanceof TargetPoint) { + TargetPoint targetPoint = (TargetPoint) contextMenuObj; + if (!targetPoint.start && !targetPoint.intermediate) { + mapActivity.getContextMenu().close(); + } } + OsmandSettings settings = mapActivity.getMyApplication().getSettings(); + settings.APPLICATION_MODE.set(settings.DEFAULT_APPLICATION_MODE.get()); + mapActivity.getMapActions().stopNavigationWithoutConfirm(); + dismissMenu(); } - OsmandSettings settings = getMapActivity().getMyApplication().getSettings(); - settings.APPLICATION_MODE.set(settings.DEFAULT_APPLICATION_MODE.get()); - getMapActivity().getMapActions().stopNavigationWithoutConfirm(); - dismissMenu(); } public static boolean isExists() { @@ -175,19 +192,26 @@ public class DestinationReachedMenuFragment extends Fragment { DestinationReachedMenuFragment fragment = new DestinationReachedMenuFragment(); fragment.menu = menu; - menu.getMapActivity().getSupportFragmentManager().beginTransaction() - .setCustomAnimations(slideInAnim, slideOutAnim, slideInAnim, slideOutAnim) - .add(R.id.fragmentContainer, fragment, TAG) - .addToBackStack(TAG).commitAllowingStateLoss(); + MapActivity mapActivity = menu.getMapActivity(); + if (mapActivity != null) { + mapActivity.getSupportFragmentManager().beginTransaction() + .setCustomAnimations(slideInAnim, slideOutAnim, slideInAnim, slideOutAnim) + .add(R.id.fragmentContainer, fragment, TAG) + .addToBackStack(TAG).commitAllowingStateLoss(); + } } public void dismissMenu() { - getMapActivity().getSupportFragmentManager().popBackStack(); + MapActivity mapActivity = getMapActivity(); + if (mapActivity != null && !mapActivity.isActivityDestroyed()) { + mapActivity.getSupportFragmentManager().popBackStack(); + } } + @Nullable public MapActivity getMapActivity() { Activity activity = getActivity(); - if (activity != null && activity instanceof MapActivity) { + if (activity instanceof MapActivity) { return (MapActivity) activity; } else { return null; From 084f905c7a4dbf45b2d6488c2d9d25f7e2ac3c6a Mon Sep 17 00:00:00 2001 From: Chumva Date: Tue, 26 Nov 2019 18:21:20 +0200 Subject: [PATCH 07/11] Fix #7975 --- OsmAnd/AndroidManifest.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/OsmAnd/AndroidManifest.xml b/OsmAnd/AndroidManifest.xml index 6c2b182a15..c03c06fe4d 100644 --- a/OsmAnd/AndroidManifest.xml +++ b/OsmAnd/AndroidManifest.xml @@ -310,7 +310,9 @@ + + From 0471581466a6a43c5f916a2b8a3b713115a5993e Mon Sep 17 00:00:00 2001 From: max-klaus Date: Tue, 26 Nov 2019 19:34:49 +0300 Subject: [PATCH 08/11] Fix OnSaveCurrentTrackFragment crash --- .../OnSaveCurrentTrackFragment.java | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/monitoring/OnSaveCurrentTrackFragment.java b/OsmAnd/src/net/osmand/plus/monitoring/OnSaveCurrentTrackFragment.java index 93122c8fee..6765a435c1 100644 --- a/OsmAnd/src/net/osmand/plus/monitoring/OnSaveCurrentTrackFragment.java +++ b/OsmAnd/src/net/osmand/plus/monitoring/OnSaveCurrentTrackFragment.java @@ -25,7 +25,6 @@ import android.widget.Toast; import net.osmand.GPXUtilities; import net.osmand.GPXUtilities.WptPt; import net.osmand.plus.OsmandApplication; -import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.UiUtilities; import net.osmand.plus.UiUtilities.DialogButtonType; @@ -163,14 +162,19 @@ public class OnSaveCurrentTrackFragment extends BottomSheetDialogFragment { if (showOnMap) { showOnMap(file, !openTrack); } - if (openTrack) { - AvailableGPXFragment.openTrack(getActivity(), file); + FragmentActivity activity = getActivity(); + if (openTrack && activity != null) { + AvailableGPXFragment.openTrack(activity, file); } } } private File renameGpxFile() { - OsmandApplication app = requiredMyApplication(); + FragmentActivity activity = getActivity(); + if (activity == null) { + return null; + } + OsmandApplication app = (OsmandApplication) activity.getApplication(); File savedFile = new File(app.getAppCustomization().getTracksDir(), new File(savedGpxDir, savedGpxName + ".gpx").getPath()); if (savedGpxName.equalsIgnoreCase(newGpxName)) { return savedFile; @@ -183,14 +187,18 @@ public class OnSaveCurrentTrackFragment extends BottomSheetDialogFragment { } private void showOnMap(File f, boolean animated) { - OsmandApplication app = requiredMyApplication(); + FragmentActivity activity = getActivity(); + if (activity == null) { + return; + } + OsmandApplication app = (OsmandApplication) activity.getApplication(); + GpxInfo gpxInfo = new GpxInfo(); gpxInfo.setGpx(GPXUtilities.loadGPXFile(f)); if (gpxInfo.gpx != null) { WptPt loc = gpxInfo.gpx.findPointToShow(); if (loc != null) { app.getSelectedGpxHelper().setGpxFileToDisplay(gpxInfo.gpx); - FragmentActivity activity = getActivity(); if (activity instanceof MapActivity) { MapActivity mapActivity = (MapActivity) activity; if (animated) { From a44703c6b5c9a25a29a9cd6dac0ef0686d0e2182 Mon Sep 17 00:00:00 2001 From: max-klaus Date: Tue, 26 Nov 2019 19:42:23 +0300 Subject: [PATCH 09/11] Fix AudioVideoNotesPlugin crash --- .../audionotes/AudioVideoNotesPlugin.java | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java index 1e5328f2d6..33a30aa522 100644 --- a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java +++ b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java @@ -4,7 +4,6 @@ import android.Manifest; import android.annotation.TargetApi; import android.app.Activity; import android.content.ClipData; -import android.content.ComponentName; import android.content.Context; import android.content.DialogInterface; import android.content.DialogInterface.OnClickListener; @@ -408,8 +407,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { Method saveAttributes = exClass.getMethod("saveAttributes", new Class[]{}); saveAttributes.invoke(exInstance); } catch (Exception e) { - e.printStackTrace(); - log.error(e); + log.error(e.getMessage(), e); } } @@ -425,8 +423,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { Integer it = (Integer) getAttributeInt.invoke(exInstance, "Orientation", 1); orientation = it; } catch (Exception e) { - e.printStackTrace(); - log.error(e); + log.error(e.getMessage(), e); } return orientation; } @@ -1136,7 +1133,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { try { mediaRec.stop(); } catch (IllegalStateException e) { - e.printStackTrace(); + log.error(e.getMessage(), e); } indexFile(true, mediaRecFile); mediaRec.release(); @@ -1167,7 +1164,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { } catch (Exception e) { Toast.makeText(app, e.getMessage(), Toast.LENGTH_LONG).show(); - e.printStackTrace(); + log.error(e.getMessage(), e); res = false; } } @@ -1383,7 +1380,6 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { closeRecordingMenu(); closeCamera(); finishRecording(); - e.printStackTrace(); } } @@ -1418,7 +1414,6 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { closeRecordingMenu(); closeCamera(); finishRecording(); - e.printStackTrace(); } } }); @@ -1900,7 +1895,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { try { ctx.startActivity(vint); } catch (Exception e) { - e.printStackTrace(); + log.error(e.getMessage(), e); } return; } else if (r.isPhoto()) { @@ -1908,7 +1903,11 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { vint.setDataAndType(AndroidUtils.getUriForFile(ctx, r.file), "image/*"); vint.setFlags(0x10000000); vint.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); - ctx.startActivity(vint); + try { + ctx.startActivity(vint); + } catch (Exception e) { + log.error(e.getMessage(), e); + } return; } @@ -2063,7 +2062,6 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { closeRecordingMenu(); closeCamera(); finishRecording(); - e.printStackTrace(); } } } From 46a4b8b0d2aa2c3b40981be83a03766656b6f028 Mon Sep 17 00:00:00 2001 From: max-klaus Date: Tue, 26 Nov 2019 19:59:04 +0300 Subject: [PATCH 10/11] Fix SavingTrackHelper db issue --- .../plus/activities/SavingTrackHelper.java | 38 ++++++++++--------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/activities/SavingTrackHelper.java b/OsmAnd/src/net/osmand/plus/activities/SavingTrackHelper.java index c0687b6fe9..1234aa17cf 100644 --- a/OsmAnd/src/net/osmand/plus/activities/SavingTrackHelper.java +++ b/OsmAnd/src/net/osmand/plus/activities/SavingTrackHelper.java @@ -238,17 +238,21 @@ public class SavingTrackHelper extends SQLiteOpenHelper { } } - SQLiteDatabase db = getWritableDatabase(); - if (db != null && warnings.isEmpty() && db.isOpen()) { - try { - // remove all from db - db.execSQL("DELETE FROM " + TRACK_NAME + " WHERE " + TRACK_COL_DATE + " <= ?", new Object[] { System.currentTimeMillis() }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - db.execSQL("DELETE FROM " + POINT_NAME + " WHERE " + POINT_COL_DATE + " <= ?", new Object[] { System.currentTimeMillis() }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - // delete all - // db.execSQL("DELETE FROM " + TRACK_NAME + " WHERE 1 = 1", new Object[] { }); //$NON-NLS-1$ //$NON-NLS-2$ - // db.execSQL("DELETE FROM " + POINT_NAME + " WHERE 1 = 1", new Object[] { }); //$NON-NLS-1$ //$NON-NLS-2$ - } finally { - db.close(); + if (warnings.isEmpty()) { + SQLiteDatabase db = getWritableDatabase(); + if (db != null) { + try { + if (db.isOpen()) { + // remove all from db + db.execSQL("DELETE FROM " + TRACK_NAME + " WHERE " + TRACK_COL_DATE + " <= ?", new Object[]{System.currentTimeMillis()}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + db.execSQL("DELETE FROM " + POINT_NAME + " WHERE " + POINT_COL_DATE + " <= ?", new Object[]{System.currentTimeMillis()}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + // delete all + // db.execSQL("DELETE FROM " + TRACK_NAME + " WHERE 1 = 1", new Object[] { }); //$NON-NLS-1$ //$NON-NLS-2$ + // db.execSQL("DELETE FROM " + POINT_NAME + " WHERE 1 = 1", new Object[] { }); //$NON-NLS-1$ //$NON-NLS-2$ + } + } finally { + db.close(); + } } } distance = 0; @@ -609,14 +613,12 @@ public class SavingTrackHelper extends SQLiteOpenHelper { private synchronized void execWithClose(String script, Object[] objects) { SQLiteDatabase db = getWritableDatabase(); - try { - if (db != null) { + if (db != null) { + try { db.execSQL(script, objects); - } - } catch (RuntimeException e) { - log.error(e.getMessage(), e); - } finally { - if (db != null) { + } catch (RuntimeException e) { + log.error(e.getMessage(), e); + } finally { db.close(); } } From aa3a2b5752d2a15ec838bed856a8c756ca99bb73 Mon Sep 17 00:00:00 2001 From: max-klaus Date: Tue, 26 Nov 2019 20:59:23 +0300 Subject: [PATCH 11/11] Fix history share crash --- .../net/osmand/plus/search/QuickSearchDialogFragment.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java index 3162126e6f..292bf9d3d1 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java @@ -481,8 +481,10 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC List historyEntries = new ArrayList(); List selectedItems = historySearchFragment.getListAdapter().getSelectedItems(); for (QuickSearchListItem searchListItem : selectedItems) { - HistoryEntry historyEntry = (HistoryEntry) searchListItem.getSearchResult().object; - historyEntries.add(historyEntry); + Object object = searchListItem.getSearchResult().object; + if (object instanceof HistoryEntry) { + historyEntries.add((HistoryEntry) object); + } } if (historyEntries.size() > 0) { shareHistory(historyEntries);