use of net.osmand.plus.ApplicationMode in project Osmand by osmandapp.
the class MapActivity method onResume.
@Override
protected void onResume() {
super.onResume();
long tm = System.currentTimeMillis();
if (app.getMapMarkersHelper().getPlanRouteContext().isFragmentVisible()) {
PlanRouteFragment.showInstance(this);
}
if (app.isApplicationInitializing() || DashboardOnMap.staticVisible) {
if (!dashboardOnMap.isVisible()) {
if (settings.SHOW_DASHBOARD_ON_START.get()) {
dashboardOnMap.setDashboardVisibility(true, DashboardOnMap.staticVisibleType);
} else {
if (ErrorBottomSheetDialog.shouldShow(settings, this)) {
SecondSplashScreenFragment.SHOW = false;
new ErrorBottomSheetDialog().show(getSupportFragmentManager(), "dialog");
} else if (RateUsBottomSheetDialog.shouldShow(app)) {
SecondSplashScreenFragment.SHOW = false;
new RateUsBottomSheetDialog().show(getSupportFragmentManager(), "dialog");
}
}
} else {
dashboardOnMap.updateDashboard();
}
}
dashboardOnMap.updateLocation(true, true, false);
getMyApplication().getNotificationHelper().refreshNotifications();
// fixing bug with action bar appearing on android 2.3.3
if (getSupportActionBar() != null) {
getSupportActionBar().hide();
}
app.getLocationProvider().checkIfLastKnownLocationIsValid();
// for voice navigation
ApplicationMode routingAppMode = getRoutingHelper().getAppMode();
if (routingAppMode != null && settings.AUDIO_STREAM_GUIDANCE.getModeValue(routingAppMode) != null) {
setVolumeControlStream(settings.AUDIO_STREAM_GUIDANCE.getModeValue(routingAppMode));
} else {
setVolumeControlStream(AudioManager.STREAM_MUSIC);
}
changeKeyguardFlags();
applicationModeListener = new StateChangedListener<ApplicationMode>() {
@Override
public void stateChanged(ApplicationMode change) {
updateApplicationModeSettings();
}
};
settings.APPLICATION_MODE.addListener(applicationModeListener);
updateApplicationModeSettings();
// if destination point was changed try to recalculate route
TargetPointsHelper targets = app.getTargetPointsHelper();
RoutingHelper routingHelper = app.getRoutingHelper();
if (routingHelper.isFollowingMode() && (!Algorithms.objectEquals(targets.getPointToNavigate().point, routingHelper.getFinalLocation()) || !Algorithms.objectEquals(targets.getIntermediatePointsLatLonNavigation(), routingHelper.getIntermediatePoints()))) {
targets.updateRouteAndRefresh(true);
}
app.getLocationProvider().resumeAllUpdates();
if (settings != null && settings.isLastKnownMapLocation() && !intentLocation) {
LatLon l = settings.getLastKnownMapLocation();
mapView.setLatLon(l.getLatitude(), l.getLongitude());
mapView.setIntZoom(settings.getLastKnownMapZoom());
} else {
intentLocation = false;
}
settings.MAP_ACTIVITY_ENABLED.set(true);
checkExternalStorage();
showAndHideMapPosition();
readLocationToShow();
OsmandPlugin.onMapActivityResume(this);
final Intent intent = getIntent();
if (intent != null) {
if (Intent.ACTION_VIEW.equals(intent.getAction())) {
if (intent.getData() != null) {
final Uri data = intent.getData();
final String scheme = data.getScheme();
if ("file".equals(scheme)) {
importHelper.handleFileImport(data, new File(data.getPath()).getName(), true);
setIntent(null);
} else if ("content".equals(scheme)) {
importHelper.handleContentImport(data, true);
setIntent(null);
} else if ("google.navigation".equals(scheme) || "osmand.navigation".equals(scheme)) {
parseNavigationIntent(data);
} else if ("osmand.api".equals(scheme)) {
ExternalApiHelper apiHelper = new ExternalApiHelper(this);
Intent result = apiHelper.processApiRequest(intent);
setResult(apiHelper.getResultCode(), result);
result.setAction(null);
setIntent(result);
if (apiHelper.needFinish()) {
finish();
}
}
}
}
if (intent.hasExtra(MapMarkersDialogFragment.OPEN_MAP_MARKERS_GROUPS)) {
Bundle openMapMarkersGroupsExtra = intent.getBundleExtra(MapMarkersDialogFragment.OPEN_MAP_MARKERS_GROUPS);
if (openMapMarkersGroupsExtra != null) {
MapMarkersDialogFragment.showInstance(this, openMapMarkersGroupsExtra.getString(MapMarkersHelper.MapMarkersGroup.MARKERS_SYNC_GROUP_ID));
}
setIntent(null);
}
}
mapView.refreshMap(true);
if (atlasMapRendererView != null) {
atlasMapRendererView.handleOnResume();
}
app.getDownloadThread().setUiActivity(this);
if (mapViewTrackingUtilities.getShowRouteFinishDialog()) {
DestinationReachedMenu.show(this);
mapViewTrackingUtilities.setShowRouteFinishDialog(false);
}
routingHelper.addListener(this);
app.getMapMarkersHelper().addListener(this);
DiscountHelper.checkAndDisplay(this);
QuickSearchDialogFragment searchDialogFragment = getQuickSearchDialogFragment();
if (searchDialogFragment != null) {
if (searchDialogFragment.isSearchHidden()) {
searchDialogFragment.hide();
searchDialogFragment.restoreToolbar();
}
}
getMyApplication().getAppCustomization().resumeActivity(MapActivity.class, this);
if (System.currentTimeMillis() - tm > 50) {
System.err.println("OnCreate for MapActivity took " + (System.currentTimeMillis() - tm) + " ms");
}
boolean showWelcomeScreen = ((app.getAppInitializer().isFirstTime() && Version.isDeveloperVersion(app)) || !app.getResourceManager().isAnyMapInstalled()) && FirstUsageWelcomeFragment.SHOW;
if (!showWelcomeScreen && !permissionDone && !app.getAppInitializer().isFirstTime()) {
if (!permissionAsked) {
if (app.isExternalStorageDirectoryReadOnly() && getSupportFragmentManager().findFragmentByTag(DataStoragePlaceDialogFragment.TAG) == null) {
if (DownloadActivity.hasPermissionToWriteExternalStorage(this)) {
DataStoragePlaceDialogFragment.showInstance(getSupportFragmentManager(), true);
} else {
ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, DownloadActivity.PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE);
}
}
} else {
if (permissionGranted) {
restartApp();
} else if (getSupportFragmentManager().findFragmentByTag(DataStoragePlaceDialogFragment.TAG) == null) {
DataStoragePlaceDialogFragment.showInstance(getSupportFragmentManager(), true);
}
permissionAsked = false;
permissionGranted = false;
permissionDone = true;
}
}
enableDrawer();
if (showWelcomeScreen) {
SecondSplashScreenFragment.SHOW = false;
getSupportFragmentManager().beginTransaction().add(R.id.fragmentContainer, new FirstUsageWelcomeFragment(), FirstUsageWelcomeFragment.TAG).commitAllowingStateLoss();
} else if (!isFirstScreenShowing() && XMasDialogFragment.shouldShowXmasDialog(app)) {
SecondSplashScreenFragment.SHOW = false;
new XMasDialogFragment().show(getSupportFragmentManager(), XMasDialogFragment.TAG);
}
FirstUsageWelcomeFragment.SHOW = false;
if (SecondSplashScreenFragment.SHOW) {
SecondSplashScreenFragment.SHOW = false;
SecondSplashScreenFragment.VISIBLE = true;
getSupportFragmentManager().beginTransaction().add(R.id.fragmentContainer, new SecondSplashScreenFragment(), SecondSplashScreenFragment.TAG).commitAllowingStateLoss();
mapView.setOnDrawMapListener(this);
splashScreenTimer = new Timer();
splashScreenTimer.schedule(new TimerTask() {
@Override
public void run() {
dismissSecondSplashScreen();
}
}, SECOND_SPLASH_TIME_OUT);
} else {
if (SecondSplashScreenFragment.VISIBLE) {
dismissSecondSplashScreen();
}
// setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
if (settings.MAP_SCREEN_ORIENTATION.get() != getRequestedOrientation()) {
setRequestedOrientation(settings.MAP_SCREEN_ORIENTATION.get());
}
}
}
use of net.osmand.plus.ApplicationMode in project Osmand by osmandapp.
the class MapActivity method createProgressBarForRouting.
private void createProgressBarForRouting() {
final ProgressBar pb = (ProgressBar) findViewById(R.id.map_horizontal_progress);
final View pbExtView = findViewById(R.id.progress_layout_external);
final ProgressBar pbExt = (ProgressBar) findViewById(R.id.map_horizontal_progress_external);
app.getRoutingHelper().setProgressBar(new RouteCalculationProgressCallback() {
@Override
public void updateProgress(int progress) {
if (findViewById(R.id.MapHudButtonsOverlay).getVisibility() == View.VISIBLE) {
if (pbExtView.getVisibility() == View.VISIBLE) {
pbExtView.setVisibility(View.GONE);
}
if (pb.getVisibility() == View.GONE) {
pb.setVisibility(View.VISIBLE);
}
pb.setProgress(progress);
pb.invalidate();
pb.requestLayout();
} else {
if (pb.getVisibility() == View.VISIBLE) {
pb.setVisibility(View.GONE);
}
if (pbExtView.getVisibility() == View.GONE) {
pbExtView.setVisibility(View.VISIBLE);
}
pbExt.setProgress(progress);
pbExt.invalidate();
pbExt.requestLayout();
}
}
@Override
public void requestPrivateAccessRouting() {
if (!settings.FORCE_PRIVATE_ACCESS_ROUTING_ASKED.getModeValue(getRoutingHelper().getAppMode())) {
final OsmandSettings.CommonPreference<Boolean> allowPrivate = settings.getCustomRoutingBooleanProperty(GeneralRouter.ALLOW_PRIVATE, false);
final List<ApplicationMode> modes = ApplicationMode.values(settings);
for (ApplicationMode mode : modes) {
if (!allowPrivate.getModeValue(mode)) {
settings.FORCE_PRIVATE_ACCESS_ROUTING_ASKED.setModeValue(mode, true);
}
}
if (!allowPrivate.getModeValue(getRoutingHelper().getAppMode())) {
AlertDialog.Builder dlg = new AlertDialog.Builder(MapActivity.this);
dlg.setMessage(R.string.private_access_routing_req);
dlg.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
for (ApplicationMode mode : modes) {
if (!allowPrivate.getModeValue(mode)) {
allowPrivate.setModeValue(mode, true);
}
}
getRoutingHelper().recalculateRouteDueToSettingsChange();
}
});
dlg.setNegativeButton(R.string.shared_string_no, null);
dlg.show();
}
}
}
@Override
public void finish() {
pbExtView.setVisibility(View.GONE);
pb.setVisibility(View.GONE);
}
});
}
use of net.osmand.plus.ApplicationMode in project Osmand by osmandapp.
the class SettingsBaseActivity method profileDialog.
protected void profileDialog() {
AlertDialog.Builder b = new AlertDialog.Builder(this);
final Set<ApplicationMode> selected = new LinkedHashSet<ApplicationMode>();
View v = AppModeDialog.prepareAppModeView(this, selected, false, null, true, true, false, new View.OnClickListener() {
@Override
public void onClick(View v) {
if (selected.size() > 0) {
// test
setSelectedAppMode(selected.iterator().next());
}
if (profileDialog != null && profileDialog.isShowing()) {
profileDialog.dismiss();
}
profileDialog = null;
}
});
b.setTitle(R.string.profile_settings);
b.setView(v);
profileDialog = b.show();
}
use of net.osmand.plus.ApplicationMode in project Osmand by osmandapp.
the class SettingsNavigationActivity method prepareRoutingPrefs.
private void prepareRoutingPrefs(PreferenceScreen screen) {
PreferenceCategory cat = (PreferenceCategory) screen.findPreference("routing_preferences");
cat.removeAll();
CheckBoxPreference fastRoute = createCheckBoxPreference(settings.FAST_ROUTE_MODE, R.string.fast_route_mode, R.string.fast_route_mode_descr);
if (settings.ROUTER_SERVICE.get() != RouteService.OSMAND) {
cat.addPreference(fastRoute);
} else {
ApplicationMode am = settings.getApplicationMode();
GeneralRouter router = getRouter(getMyApplication().getDefaultRoutingConfig(), am);
clearParameters();
if (router != null) {
Map<String, RoutingParameter> parameters = router.getParameters();
if (parameters.containsKey("short_way")) {
cat.addPreference(fastRoute);
}
List<RoutingParameter> others = new ArrayList<GeneralRouter.RoutingParameter>();
for (Map.Entry<String, RoutingParameter> e : parameters.entrySet()) {
String param = e.getKey();
RoutingParameter routingParameter = e.getValue();
if (param.startsWith("avoid_")) {
avoidParameters.add(routingParameter);
} else if (param.startsWith("prefer_")) {
preferParameters.add(routingParameter);
} else if ("relief_smoothness_factor".equals(routingParameter.getGroup())) {
reliefFactorParameters.add(routingParameter);
} else if (!param.equals("short_way") && !"driving_style".equals(routingParameter.getGroup())) {
others.add(routingParameter);
}
}
if (avoidParameters.size() > 0) {
avoidRouting = new Preference(this);
avoidRouting.setTitle(R.string.avoid_in_routing_title);
avoidRouting.setSummary(R.string.avoid_in_routing_descr);
avoidRouting.setOnPreferenceClickListener(this);
cat.addPreference(avoidRouting);
}
if (preferParameters.size() > 0) {
preferRouting = new Preference(this);
preferRouting.setTitle(R.string.prefer_in_routing_title);
preferRouting.setSummary(R.string.prefer_in_routing_descr);
preferRouting.setOnPreferenceClickListener(this);
cat.addPreference(preferRouting);
}
if (reliefFactorParameters.size() > 0) {
reliefFactorRouting = new Preference(this);
reliefFactorRouting.setTitle(SettingsBaseActivity.getRoutingStringPropertyName(this, reliefFactorParameters.get(0).getGroup(), Algorithms.capitalizeFirstLetterAndLowercase(reliefFactorParameters.get(0).getGroup().replace('_', ' '))));
reliefFactorRouting.setSummary(R.string.relief_smoothness_factor_descr);
reliefFactorRouting.setOnPreferenceClickListener(this);
cat.addPreference(reliefFactorRouting);
}
for (RoutingParameter p : others) {
Preference basePref;
if (p.getType() == RoutingParameterType.BOOLEAN) {
basePref = createCheckBoxPreference(settings.getCustomRoutingBooleanProperty(p.getId(), p.getDefaultBoolean()));
} else {
Object[] vls = p.getPossibleValues();
String[] svlss = new String[vls.length];
int i = 0;
for (Object o : vls) {
svlss[i++] = o.toString();
}
basePref = createListPreference(settings.getCustomRoutingProperty(p.getId(), p.getType() == RoutingParameterType.NUMERIC ? "0.0" : "-"), p.getPossibleValueDescriptions(), svlss, SettingsBaseActivity.getRoutingStringPropertyName(this, p.getId(), p.getName()), SettingsBaseActivity.getRoutingStringPropertyDescription(this, p.getId(), p.getDescription()));
}
basePref.setTitle(SettingsBaseActivity.getRoutingStringPropertyName(this, p.getId(), p.getName()));
basePref.setSummary(SettingsBaseActivity.getRoutingStringPropertyDescription(this, p.getId(), p.getDescription()));
cat.addPreference(basePref);
}
}
ApplicationMode mode = getMyApplication().getSettings().getApplicationMode();
if (mode.isDerivedRoutingFrom(ApplicationMode.CAR)) {
PreferenceCategory category = (PreferenceCategory) screen.findPreference("guidance_preferences");
category.addPreference(speedLimitExceed);
} else {
PreferenceCategory category = (PreferenceCategory) screen.findPreference("guidance_preferences");
category.removePreference(speedLimitExceed);
}
}
}
use of net.osmand.plus.ApplicationMode in project Osmand by osmandapp.
the class AppModeDialog method prepareAppModeView.
public static View prepareAppModeView(Activity a, final List<ApplicationMode> values, final Set<ApplicationMode> selected, ViewGroup parent, final boolean singleSelection, boolean useListBg, boolean useMapTheme, final View.OnClickListener onClickListener) {
View ll = a.getLayoutInflater().inflate(R.layout.mode_toggles, parent);
boolean nightMode = isNightMode(((OsmandApplication) a.getApplication()), useMapTheme);
if (useListBg) {
AndroidUtils.setListItemBackground(a, ll, nightMode);
} else {
ll.setBackgroundColor(ContextCompat.getColor(a, nightMode ? R.color.route_info_bg_dark : R.color.route_info_bg_light));
}
final View[] buttons = new View[values.size()];
int k = 0;
for (ApplicationMode ma : values) {
buttons[k++] = createToggle(a.getLayoutInflater(), (OsmandApplication) a.getApplication(), (LinearLayout) ll.findViewById(R.id.app_modes_content), ma, useMapTheme);
}
for (int i = 0; i < buttons.length; i++) {
updateButtonState((OsmandApplication) a.getApplication(), values, selected, onClickListener, buttons, i, singleSelection, useMapTheme);
}
return ll;
}
Aggregations