Fix several possible exceptions
This commit is contained in:
parent
9ca1dbd9cf
commit
30eac3412f
11 changed files with 80 additions and 64 deletions
|
@ -553,7 +553,8 @@ public class AppInitializer implements IProgress {
|
|||
|
||||
customConfigs.put(fileName, builder);
|
||||
} catch (XmlPullParserException | IOException e) {
|
||||
throw new IllegalStateException(e);
|
||||
Algorithms.removeAllFiles(f);
|
||||
LOG.error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -166,17 +166,18 @@ public class OsmandInAppPurchaseActivity extends AppCompatActivity implements In
|
|||
|
||||
@Override
|
||||
public void onItemPurchased(String sku, boolean active) {
|
||||
FragmentManager fragmentManager = getSupportFragmentManager();
|
||||
if (purchaseHelper != null && purchaseHelper.getLiveUpdates().containsSku(sku)) {
|
||||
getMyApplication().logEvent("live_osm_subscription_purchased");
|
||||
|
||||
if (!active) {
|
||||
if (!active && !fragmentManager.isStateSaved()) {
|
||||
OsmLiveRestartBottomSheetDialogFragment fragment = new OsmLiveRestartBottomSheetDialogFragment();
|
||||
fragment.setUsedOnMap(this instanceof MapActivity);
|
||||
fragment.show(getSupportFragmentManager(), OsmLiveRestartBottomSheetDialogFragment.TAG);
|
||||
fragment.show(fragmentManager, OsmLiveRestartBottomSheetDialogFragment.TAG);
|
||||
}
|
||||
}
|
||||
onInAppPurchaseItemPurchased(sku);
|
||||
fireInAppPurchaseItemPurchasedOnFragments(getSupportFragmentManager(), sku, active);
|
||||
fireInAppPurchaseItemPurchasedOnFragments(fragmentManager, sku, active);
|
||||
}
|
||||
|
||||
public void fireInAppPurchaseItemPurchasedOnFragments(@NonNull FragmentManager fragmentManager,
|
||||
|
|
|
@ -215,7 +215,7 @@ public class SettingsDevelopmentActivity extends SettingsBaseActivity {
|
|||
SunriseSunset sunriseSunset = getMyApplication().getDaynightHelper().getSunriseSunset();
|
||||
pref = new Preference(this);
|
||||
pref.setTitle(R.string.day_night_info);
|
||||
if (sunriseSunset != null) {
|
||||
if (sunriseSunset != null && sunriseSunset.getSunrise() != null && sunriseSunset.getSunset() != null) {
|
||||
SimpleDateFormat prt = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
||||
pref.setSummary(getString(R.string.day_night_info_description, prt.format(sunriseSunset.getSunrise()),
|
||||
prt.format(sunriseSunset.getSunset())));
|
||||
|
|
|
@ -504,7 +504,7 @@ public class ConfigureMapMenu {
|
|||
|
||||
String description = "";
|
||||
SunriseSunset sunriseSunset = activity.getMyApplication().getDaynightHelper().getSunriseSunset();
|
||||
if (sunriseSunset != null) {
|
||||
if (sunriseSunset != null && sunriseSunset.getSunrise() != null && sunriseSunset.getSunset() != null) {
|
||||
DateFormat dateFormat = DateFormat.getTimeInstance(DateFormat.SHORT);
|
||||
String sunriseTime = dateFormat.format(sunriseSunset.getSunrise());
|
||||
String sunsetTime = dateFormat.format(sunriseSunset.getSunset());
|
||||
|
|
|
@ -768,13 +768,15 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
int itemId = item.getItemId();
|
||||
for (int i = 0; i < optionsMenuAdapter.length(); i++) {
|
||||
ContextMenuItem contextMenuItem = optionsMenuAdapter.getItem(i);
|
||||
if (itemId == contextMenuItem.getTitleId()) {
|
||||
contextMenuItem.getItemClickListener().onContextMenuClick(null, itemId, i, false, null);
|
||||
return true;
|
||||
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
||||
if (optionsMenuAdapter != null) {
|
||||
int itemId = item.getItemId();
|
||||
for (int i = 0; i < optionsMenuAdapter.length(); i++) {
|
||||
ContextMenuItem contextMenuItem = optionsMenuAdapter.getItem(i);
|
||||
if (itemId == contextMenuItem.getTitleId()) {
|
||||
contextMenuItem.getItemClickListener().onContextMenuClick(null, itemId, i, false, null);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
|
|
|
@ -17,11 +17,8 @@ import net.osmand.data.LocationPoint;
|
|||
import net.osmand.data.PointDescription;
|
||||
import net.osmand.data.WptLocationPoint;
|
||||
import net.osmand.osm.PoiType;
|
||||
import net.osmand.plus.settings.backend.ApplicationMode;
|
||||
import net.osmand.plus.OsmAndFormatter;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.settings.backend.OsmandSettings;
|
||||
import net.osmand.plus.settings.backend.OsmandSettings.MetricsConstants;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.TargetPointsHelper.TargetPoint;
|
||||
import net.osmand.plus.UiUtilities;
|
||||
|
@ -33,6 +30,9 @@ import net.osmand.plus.routing.AlarmInfo;
|
|||
import net.osmand.plus.routing.AlarmInfo.AlarmInfoType;
|
||||
import net.osmand.plus.routing.RouteCalculationResult;
|
||||
import net.osmand.plus.routing.VoiceRouter;
|
||||
import net.osmand.plus.settings.backend.ApplicationMode;
|
||||
import net.osmand.plus.settings.backend.OsmandSettings;
|
||||
import net.osmand.plus.settings.backend.OsmandSettings.MetricsConstants;
|
||||
import net.osmand.util.MapUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -627,20 +627,21 @@ public class WaypointHelper {
|
|||
amenities.addAll(pf.searchAmenitiesOnThePath(locs, poiSearchDeviationRadius));
|
||||
}
|
||||
for (Amenity a : amenities) {
|
||||
AmenityRoutePoint rp = a.getRoutePoint();
|
||||
int i = locs.indexOf(rp.pointA);
|
||||
if (i >= 0) {
|
||||
LocationPointWrapper lwp = new LocationPointWrapper(route, POI, new AmenityLocationPoint(a),
|
||||
(float) rp.deviateDistance, i);
|
||||
lwp.deviationDirectionRight = rp.deviationDirectionRight;
|
||||
lwp.setAnnounce(announcePOI);
|
||||
locationPoints.add(lwp);
|
||||
AmenityRoutePoint routePoint = a.getRoutePoint();
|
||||
if (routePoint != null) {
|
||||
int i = locs.indexOf(routePoint.pointA);
|
||||
if (i >= 0) {
|
||||
LocationPointWrapper lwp = new LocationPointWrapper(route, POI, new AmenityLocationPoint(a),
|
||||
(float) routePoint.deviateDistance, i);
|
||||
lwp.deviationDirectionRight = routePoint.deviationDirectionRight;
|
||||
lwp.setAnnounce(announcePOI);
|
||||
locationPoints.add(lwp);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void calculateAlarms(RouteCalculationResult route, List<LocationPointWrapper> array, ApplicationMode mode) {
|
||||
AlarmInfo prevSpeedCam = null;
|
||||
for (AlarmInfo i : route.getAlarmInfo()) {
|
||||
|
|
|
@ -25,19 +25,19 @@ import com.google.android.material.slider.Slider;
|
|||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.Location;
|
||||
import net.osmand.ValueHolder;
|
||||
import net.osmand.plus.settings.backend.ApplicationMode;
|
||||
import net.osmand.plus.NavigationService;
|
||||
import net.osmand.plus.OsmAndFormatter;
|
||||
import net.osmand.plus.OsmAndTaskManager.OsmAndTaskRunnable;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandPlugin;
|
||||
import net.osmand.plus.settings.backend.OsmandSettings;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.UiUtilities;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.activities.SavingTrackHelper;
|
||||
import net.osmand.plus.activities.SavingTrackHelper.SaveGpxResult;
|
||||
import net.osmand.plus.dashboard.tools.DashFragmentData;
|
||||
import net.osmand.plus.settings.backend.ApplicationMode;
|
||||
import net.osmand.plus.settings.backend.OsmandSettings;
|
||||
import net.osmand.plus.settings.fragments.BaseSettingsFragment;
|
||||
import net.osmand.plus.views.MapInfoLayer;
|
||||
import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
|
||||
|
@ -333,18 +333,20 @@ public class OsmandMonitoringPlugin extends OsmandPlugin {
|
|||
startGPXMonitoring(activity, showTrackSelection);
|
||||
}
|
||||
} else if (item == R.string.clear_recorded_data) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(UiUtilities.getThemedContext(activity, nightMode));
|
||||
builder.setTitle(R.string.clear_recorded_data);
|
||||
builder.setMessage(R.string.are_you_sure);
|
||||
builder.setNegativeButton(R.string.shared_string_cancel, null).setPositiveButton(
|
||||
R.string.shared_string_ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
app.getSavingTrackHelper().clearRecordedData(true);
|
||||
app.getNotificationHelper().refreshNotifications();
|
||||
}
|
||||
});
|
||||
builder.show();
|
||||
if (AndroidUtils.isActivityNotDestroyed(activity)) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(UiUtilities.getThemedContext(activity, nightMode));
|
||||
builder.setTitle(R.string.clear_recorded_data);
|
||||
builder.setMessage(R.string.are_you_sure);
|
||||
builder.setNegativeButton(R.string.shared_string_cancel, null).setPositiveButton(
|
||||
R.string.shared_string_ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
app.getSavingTrackHelper().clearRecordedData(true);
|
||||
app.getNotificationHelper().refreshNotifications();
|
||||
}
|
||||
});
|
||||
builder.show();
|
||||
}
|
||||
} else if(item == R.string.gpx_monitoring_stop) {
|
||||
stopRecording();
|
||||
} else if(item == R.string.gpx_start_new_segment) {
|
||||
|
@ -481,19 +483,21 @@ public class OsmandMonitoringPlugin extends OsmandPlugin {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public static void showIntervalChooseDialog(final Context uiCtx, final String patternMsg,
|
||||
public static void showIntervalChooseDialog(final Activity activity, final String patternMsg,
|
||||
String title, final int[] seconds, final int[] minutes,
|
||||
final ValueHolder<Boolean> choice, final ValueHolder<Integer> v,
|
||||
final boolean showTrackSelection, OnClickListener onclick) {
|
||||
final OsmandApplication app = (OsmandApplication) uiCtx.getApplicationContext();
|
||||
if (!AndroidUtils.isActivityNotDestroyed(activity)) {
|
||||
return;
|
||||
}
|
||||
final OsmandApplication app = (OsmandApplication) activity.getApplicationContext();
|
||||
boolean nightMode;
|
||||
if (uiCtx instanceof MapActivity) {
|
||||
if (activity instanceof MapActivity) {
|
||||
nightMode = app.getDaynightHelper().isNightModeForMapControls();
|
||||
} else {
|
||||
nightMode = !app.getSettings().isLightContent();
|
||||
}
|
||||
Context themedContext = UiUtilities.getThemedContext(uiCtx, nightMode);
|
||||
Context themedContext = UiUtilities.getThemedContext(activity, nightMode);
|
||||
AlertDialog.Builder dlg = new AlertDialog.Builder(themedContext);
|
||||
dlg.setTitle(title);
|
||||
LinearLayout ll = createIntervalChooseLayout(app, themedContext, patternMsg, seconds, minutes, choice, v, showTrackSelection, nightMode);
|
||||
|
|
|
@ -7,13 +7,13 @@ import android.widget.ImageView;
|
|||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceViewHolder;
|
||||
|
||||
import net.osmand.plus.settings.backend.ApplicationMode;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.settings.backend.OsmandSettings;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.SettingsBaseActivity;
|
||||
import net.osmand.plus.routing.RouteProvider.RouteService;
|
||||
import net.osmand.plus.routing.RoutingHelper;
|
||||
import net.osmand.plus.settings.backend.ApplicationMode;
|
||||
import net.osmand.plus.settings.backend.OsmandSettings;
|
||||
import net.osmand.plus.settings.preferences.ListPreferenceEx;
|
||||
import net.osmand.router.GeneralRouter;
|
||||
|
||||
|
@ -123,7 +123,8 @@ public class VehicleParametersFragment extends BaseSettingsFragment implements O
|
|||
public boolean onPreferenceClick(Preference preference) {
|
||||
if (preference.getKey().equals(GeneralRouter.DEFAULT_SPEED)) {
|
||||
RouteService routeService = getSelectedAppMode().getRouteService();
|
||||
showSeekbarSettingsDialog(getActivity(), routeService == RouteService.STRAIGHT, getSelectedAppMode());
|
||||
boolean defaultSpeedOnly = routeService == RouteService.STRAIGHT || routeService == RouteService.DIRECT_TO;
|
||||
showSeekbarSettingsDialog(getActivity(), defaultSpeedOnly, getSelectedAppMode());
|
||||
return true;
|
||||
}
|
||||
return super.onPreferenceClick(preference);
|
||||
|
|
|
@ -35,8 +35,6 @@ import net.osmand.plus.ContextMenuAdapter;
|
|||
import net.osmand.plus.ContextMenuItem;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandPlugin;
|
||||
import net.osmand.plus.settings.backend.OsmandSettings;
|
||||
import net.osmand.plus.settings.backend.OsmandSettings.TerrainMode;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.UiUtilities;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
|
@ -46,6 +44,8 @@ import net.osmand.plus.download.DownloadResources;
|
|||
import net.osmand.plus.download.DownloadValidationManager;
|
||||
import net.osmand.plus.download.IndexItem;
|
||||
import net.osmand.plus.helpers.FontCache;
|
||||
import net.osmand.plus.settings.backend.OsmandSettings;
|
||||
import net.osmand.plus.settings.backend.OsmandSettings.TerrainMode;
|
||||
import net.osmand.plus.widgets.style.CustomTypefaceSpan;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
@ -53,10 +53,10 @@ import org.apache.commons.logging.Log;
|
|||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import static net.osmand.plus.settings.backend.OsmandSettings.TerrainMode.HILLSHADE;
|
||||
import static net.osmand.plus.settings.backend.OsmandSettings.TerrainMode.SLOPE;
|
||||
import static net.osmand.plus.download.DownloadActivityType.HILLSHADE_FILE;
|
||||
import static net.osmand.plus.download.DownloadActivityType.SLOPE_FILE;
|
||||
import static net.osmand.plus.settings.backend.OsmandSettings.TerrainMode.HILLSHADE;
|
||||
import static net.osmand.plus.settings.backend.OsmandSettings.TerrainMode.SLOPE;
|
||||
import static net.osmand.plus.srtmplugin.SRTMPlugin.TERRAIN_MAX_ZOOM;
|
||||
import static net.osmand.plus.srtmplugin.SRTMPlugin.TERRAIN_MIN_ZOOM;
|
||||
|
||||
|
@ -527,18 +527,18 @@ public class TerrainFragment extends BaseOsmAndFragment implements View.OnClickL
|
|||
@Override
|
||||
public void downloadInProgress() {
|
||||
DownloadIndexesThread downloadThread = app.getDownloadThread();
|
||||
IndexItem downloadIndexItem = downloadThread.getCurrentDownloadingItem();
|
||||
if (downloadIndexItem != null) {
|
||||
int downloadProgress = downloadThread.getCurrentDownloadingItemProgress();
|
||||
ArrayAdapter<ContextMenuItem> adapter = (ArrayAdapter<ContextMenuItem>) listAdapter;
|
||||
for (int i = 0; i < adapter.getCount(); i++) {
|
||||
ContextMenuItem item = adapter.getItem(i);
|
||||
if (item != null && item.getProgressListener() != null) {
|
||||
item.getProgressListener().onProgressChanged(
|
||||
downloadIndexItem, downloadProgress, adapter, (int) adapter.getItemId(i), i);
|
||||
}
|
||||
IndexItem downloadIndexItem = downloadThread.getCurrentDownloadingItem();
|
||||
if (downloadIndexItem != null && listAdapter != null) {
|
||||
int downloadProgress = downloadThread.getCurrentDownloadingItemProgress();
|
||||
ArrayAdapter<ContextMenuItem> adapter = (ArrayAdapter<ContextMenuItem>) listAdapter;
|
||||
for (int i = 0; i < adapter.getCount(); i++) {
|
||||
ContextMenuItem item = adapter.getItem(i);
|
||||
if (item != null && item.getProgressListener() != null) {
|
||||
item.getProgressListener().onProgressChanged(
|
||||
downloadIndexItem, downloadProgress, adapter, (int) adapter.getItemId(i), i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -8,6 +8,7 @@ import android.webkit.WebViewClient;
|
|||
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.data.Amenity;
|
||||
|
||||
import static net.osmand.plus.wikipedia.WikiArticleHelper.WIKI_DOMAIN;
|
||||
|
@ -41,7 +42,9 @@ public class WikipediaWebViewClient extends WebViewClient {
|
|||
WikiArticleHelper.warnAboutExternalLoad(url, context, nightMode);
|
||||
} else {
|
||||
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
|
||||
context.startActivity(i);
|
||||
if (AndroidUtils.isIntentSafe(context, i)) {
|
||||
context.startActivity(i);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -12,12 +12,13 @@ import androidx.annotation.Nullable;
|
|||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.GPXUtilities;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.data.PointDescription;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.settings.backend.OsmandSettings;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.settings.backend.OsmandSettings;
|
||||
import net.osmand.plus.wikipedia.WikiArticleHelper;
|
||||
import net.osmand.plus.wikivoyage.article.WikivoyageArticleDialogFragment;
|
||||
import net.osmand.plus.wikivoyage.data.TravelArticle;
|
||||
|
@ -124,7 +125,9 @@ public class WikivoyageWebViewClient extends WebViewClient {
|
|||
}
|
||||
} else {
|
||||
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
|
||||
activity.startActivity(i);
|
||||
if (AndroidUtils.isIntentSafe(activity, i)) {
|
||||
activity.startActivity(i);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue