Merge pull request #7821 from osmandapp/Fix_7235

Fix 7235
This commit is contained in:
max-klaus 2019-11-02 11:22:57 +03:00 committed by GitHub
commit 5fd2b62e0f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 130 additions and 41 deletions

View file

@ -1535,10 +1535,10 @@ public class OsmandSettings {
public static final String SAVE_CURRENT_TRACK = "save_current_track"; //$NON-NLS-1$
public final CommonPreference<Boolean> SAVE_GLOBAL_TRACK_TO_GPX = new BooleanPreference("save_global_track_to_gpx", false).makeGlobal().cache();
public final CommonPreference<Integer> SAVE_GLOBAL_TRACK_INTERVAL = new IntPreference("save_global_track_interval", 5000).makeGlobal().cache();
public final CommonPreference<Boolean> SAVE_GLOBAL_TRACK_REMEMBER = new BooleanPreference("save_global_track_remember", false).makeGlobal().cache();
public final CommonPreference<Integer> SAVE_GLOBAL_TRACK_INTERVAL = new IntPreference("save_global_track_interval", 5000).makeProfile().makeGeneral().cache();
public final CommonPreference<Boolean> SAVE_GLOBAL_TRACK_REMEMBER = new BooleanPreference("save_global_track_remember", false).makeProfile().makeGeneral().cache();
// this value string is synchronized with settings_pref.xml preference name
public final CommonPreference<Boolean> SAVE_TRACK_TO_GPX = new BooleanPreference("save_track_to_gpx", false).makeProfile().cache();
public final CommonPreference<Boolean> SAVE_TRACK_TO_GPX = new BooleanPreference("save_track_to_gpx", false).makeProfile().makeGeneral().cache();
{
SAVE_TRACK_TO_GPX.setModeDefaultValue(ApplicationMode.CAR, false);
@ -1550,9 +1550,9 @@ public class OsmandSettings {
public static final Integer MONTHLY_DIRECTORY = 1;
public static final Integer DAILY_DIRECTORY = 2;
public final CommonPreference<Boolean> DISABLE_RECORDING_ONCE_APP_KILLED = new BooleanPreference("disable_recording_once_app_killed", false).makeGlobal();
public final CommonPreference<Boolean> DISABLE_RECORDING_ONCE_APP_KILLED = new BooleanPreference("disable_recording_once_app_killed", false).makeProfile().makeGeneral();
public final CommonPreference<Integer> TRACK_STORAGE_DIRECTORY = new IntPreference("track_storage_directory", 0).makeGlobal();
public final CommonPreference<Integer> TRACK_STORAGE_DIRECTORY = new IntPreference("track_storage_directory", 0).makeProfile().makeGeneral();
// this value string is synchronized with settings_pref.xml preference name
public final OsmandPreference<Boolean> FAST_ROUTE_MODE = new BooleanPreference("fast_route_mode", true).makeProfile();
@ -1660,7 +1660,7 @@ public class OsmandSettings {
public final CommonPreference<Integer> CURRENT_TRACK_COLOR = new IntPreference("current_track_color", 0).makeGlobal().cache();
// this value string is synchronized with settings_pref.xml preference name
public final CommonPreference<Integer> SAVE_TRACK_INTERVAL = new IntPreference("save_track_interval", 5000).makeProfile();
public final CommonPreference<Integer> SAVE_TRACK_INTERVAL = new IntPreference("save_track_interval", 5000).makeProfile().makeGeneral();
{
SAVE_TRACK_INTERVAL.setModeDefaultValue(ApplicationMode.CAR, 3000);
@ -1669,40 +1669,40 @@ public class OsmandSettings {
}
// Please note that SAVE_TRACK_MIN_DISTANCE, SAVE_TRACK_PRECISION, SAVE_TRACK_MIN_SPEED should all be "0" for the default profile, as we have no interface to change them
public final CommonPreference<Float> SAVE_TRACK_MIN_DISTANCE = new FloatPreference("save_track_min_distance", 0).makeGlobal();
public final CommonPreference<Float> SAVE_TRACK_MIN_DISTANCE = new FloatPreference("save_track_min_distance", 0).makeProfile().makeGeneral();
//{
// SAVE_TRACK_MIN_DISTANCE.setModeDefaultValue(ApplicationMode.CAR, 5.f);
// SAVE_TRACK_MIN_DISTANCE.setModeDefaultValue(ApplicationMode.BICYCLE, 5.f);
// SAVE_TRACK_MIN_DISTANCE.setModeDefaultValue(ApplicationMode.PEDESTRIAN, 5.f);
//}
public final CommonPreference<Float> SAVE_TRACK_PRECISION = new FloatPreference("save_track_precision", 50.0f).makeGlobal();
public final CommonPreference<Float> SAVE_TRACK_PRECISION = new FloatPreference("save_track_precision", 50.0f).makeProfile().makeGeneral();
//{
// SAVE_TRACK_PRECISION.setModeDefaultValue(ApplicationMode.CAR, 50.f);
// SAVE_TRACK_PRECISION.setModeDefaultValue(ApplicationMode.BICYCLE, 50.f);
// SAVE_TRACK_PRECISION.setModeDefaultValue(ApplicationMode.PEDESTRIAN, 50.f);
//}
public final CommonPreference<Float> SAVE_TRACK_MIN_SPEED = new FloatPreference("save_track_min_speed", 0.f).makeGlobal();
public final CommonPreference<Float> SAVE_TRACK_MIN_SPEED = new FloatPreference("save_track_min_speed", 0.f).makeProfile().makeGeneral();
//{
// SAVE_TRACK_MIN_SPEED.setModeDefaultValue(ApplicationMode.CAR, 2.f);
// SAVE_TRACK_MIN_SPEED.setModeDefaultValue(ApplicationMode.BICYCLE, 1.f);
// SAVE_TRACK_MIN_SPEED.setModeDefaultValue(ApplicationMode.PEDESTRIAN, 0.f);
//}
public final CommonPreference<Boolean> AUTO_SPLIT_RECORDING = new BooleanPreference("auto_split_recording", true).makeGlobal();
public final CommonPreference<Boolean> AUTO_SPLIT_RECORDING = new BooleanPreference("auto_split_recording", true).makeProfile().makeGeneral();
public final CommonPreference<Boolean> SHOW_TRIP_REC_NOTIFICATION = new BooleanPreference("show_trip_recording_notification", true).makeGlobal();
public final CommonPreference<Boolean> SHOW_TRIP_REC_NOTIFICATION = new BooleanPreference("show_trip_recording_notification", true).makeProfile().makeGeneral();
// this value string is synchronized with settings_pref.xml preference name
public final CommonPreference<Boolean> LIVE_MONITORING = new BooleanPreference("live_monitoring", false).makeGlobal();
public final CommonPreference<Boolean> LIVE_MONITORING = new BooleanPreference("live_monitoring", false).makeProfile().makeGeneral();
// this value string is synchronized with settings_pref.xml preference name
public final CommonPreference<Integer> LIVE_MONITORING_INTERVAL = new IntPreference("live_monitoring_interval", 5000).makeGlobal();
public final CommonPreference<Integer> LIVE_MONITORING_INTERVAL = new IntPreference("live_monitoring_interval", 5000).makeProfile().makeGeneral();
// this value string is synchronized with settings_pref.xml preference name
public final CommonPreference<Integer> LIVE_MONITORING_MAX_INTERVAL_TO_SEND = new IntPreference("live_monitoring_maximum_interval_to_send", 900000).makeGlobal();
public final CommonPreference<Integer> LIVE_MONITORING_MAX_INTERVAL_TO_SEND = new IntPreference("live_monitoring_maximum_interval_to_send", 900000).makeProfile().makeGeneral();
// this value string is synchronized with settings_pref.xml preference name
public final CommonPreference<String> LIVE_MONITORING_URL = new StringPreference("live_monitoring_url",
"https://example.com?lat={0}&lon={1}&timestamp={2}&hdop={3}&altitude={4}&speed={5}").makeGlobal();
"https://example.com?lat={0}&lon={1}&timestamp={2}&hdop={3}&altitude={4}&speed={5}").makeProfile().makeGeneral();
public final CommonPreference<String> GPS_STATUS_APP = new StringPreference("gps_status_app", "").makeGlobal();

View file

@ -354,10 +354,14 @@ public abstract class SettingsBaseActivity extends ActionBarPreferenceActivity
if (profileSettings) {
modes.clear();
findViewById(R.id.selector_shadow).setVisibility(View.VISIBLE);
for (ApplicationMode a : ApplicationMode.values(app)) {
if (a != ApplicationMode.DEFAULT) {
modes.add(a);
if (this instanceof SettingsNavigationActivity) {
for (ApplicationMode a : ApplicationMode.values(app)) {
if (a != ApplicationMode.DEFAULT) {
modes.add(a);
}
}
} else {
modes.addAll(ApplicationMode.values(app));
}
getTypeButton().setVisibility(View.VISIBLE);
@ -378,18 +382,16 @@ public abstract class SettingsBaseActivity extends ActionBarPreferenceActivity
final List<ProfileDataObject> activeModes = new ArrayList<>();
for (ApplicationMode am : ApplicationMode.values(getMyApplication())) {
boolean isSelected = false;
if (am == selectedAppMode) {
isSelected = true;
}
if (am != ApplicationMode.DEFAULT) {
boolean isSelected = am == selectedAppMode;
if (am != ApplicationMode.DEFAULT || !(this instanceof SettingsNavigationActivity)) {
activeModes.add(new ProfileDataObject(
am.toHumanString(getMyApplication()),
getAppModeDescription(am),
am.getStringKey(),
am.getIconRes(),
isSelected,
am.getIconColorInfo()
am.toHumanString(getMyApplication()),
getAppModeDescription(am),
am.getStringKey(),
am.getIconRes(),
isSelected,
am.getIconColorInfo()
));
}
}
@ -586,6 +588,10 @@ public abstract class SettingsBaseActivity extends ActionBarPreferenceActivity
return true;
}
protected Map<String, Map<String, ?>> getListPrefValues() {
return listPrefValues;
}
protected OsmandApplication getMyApplication() {
return (OsmandApplication) getApplication();
}

View file

@ -1,24 +1,43 @@
package net.osmand.plus.monitoring;
import net.osmand.plus.OsmAndTaskManager.OsmAndTaskRunnable;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.activities.SavingTrackHelper;
import net.osmand.plus.activities.SettingsBaseActivity;
import net.osmand.plus.OsmAndFormatter;
import android.content.BroadcastReceiver;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceCategory;
import android.preference.PreferenceScreen;
import android.support.annotation.NonNull;
import android.support.v7.app.AlertDialog;
import android.text.SpannableString;
import android.text.style.StyleSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmAndTaskManager.OsmAndTaskRunnable;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.SavingTrackHelper;
import net.osmand.plus.activities.SettingsBaseActivity;
import java.util.Map;
import static net.osmand.plus.OsmandSettings.DAILY_DIRECTORY;
import static net.osmand.plus.OsmandSettings.MONTHLY_DIRECTORY;
import static net.osmand.plus.OsmandSettings.REC_DIRECTORY;
import static net.osmand.plus.profiles.SettingsProfileFragment.PROFILE_STRING_KEY;
public class SettingsMonitoringActivity extends SettingsBaseActivity {
@ -47,8 +66,15 @@ public class SettingsMonitoringActivity extends SettingsBaseActivity {
createLoggingSection(grp);
createLiveSection(grp);
createNotificationSection(grp);
selectAppModeDialog().show();
}
Intent intent = getIntent();
if (intent != null && intent.hasExtra(PROFILE_STRING_KEY)) {
String modeName = intent.getStringExtra(PROFILE_STRING_KEY);
selectedAppMode = ApplicationMode.valueOfStringKey(modeName, ApplicationMode.CAR);
} else {
selectAppModeDialog().show();
}
}
private void createLoggingSection(PreferenceScreen grp) {
@ -198,7 +224,62 @@ public class SettingsMonitoringActivity extends SettingsBaseActivity {
}
}
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
String prefId = preference.getKey();
if (preference instanceof ListPreference) {
int ind = ((ListPreference) preference).findIndexOfValue((String) newValue);
CharSequence entry = ((ListPreference) preference).getEntries()[ind];
Map<String, ?> map = getListPrefValues().get(prefId);
if (map != null) {
newValue = map.get(entry);
}
}
showConfirmDialog(prefId, newValue);
return false;
}
protected void showConfirmDialog(final String prefId, final Object newValue) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.change_default_settings);
String appModeName = selectedAppMode.toHumanString(this);
String currentModeText = getString(R.string.apply_to_current_profile, appModeName);
int start = currentModeText.indexOf(appModeName);
SpannableString[] strings = new SpannableString[2];
strings[0] = new SpannableString(getString(R.string.apply_to_all_profiles));
strings[1] = new SpannableString(currentModeText);
strings[1].setSpan(new StyleSpan(Typeface.BOLD), start, start + appModeName.length(), 0);
final LayoutInflater themedInflater = UiUtilities.getInflater(this, !settings.isLightContent());
final ArrayAdapter<SpannableString> singleChoiceAdapter = new ArrayAdapter<SpannableString>(this, R.layout.simple_list_menu_item, R.id.title, strings) {
@NonNull
@Override
public View getView(int position, View convertView, @NonNull ViewGroup parent) {
View v = convertView;
if (v == null) {
v = themedInflater.inflate(R.layout.simple_list_menu_item, parent, false);
}
TextView title = (TextView) v.findViewById(R.id.title);
title.setText(getItem(position));
return v;
}
};
builder.setAdapter(singleChoiceAdapter, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (which == 0) {
settings.setSharedGeneralPreference(prefId, newValue);
} else {
settings.setPreference(prefId, newValue);
}
updateAllSettings();
}
});
builder.setNegativeButton(R.string.discard_changes, null);
builder.show();
}
}

View file

@ -45,6 +45,7 @@ import static net.osmand.plus.profiles.EditProfileFragment.MAP_CONFIG;
import static net.osmand.plus.profiles.EditProfileFragment.OPEN_CONFIG_ON_MAP;
import static net.osmand.plus.profiles.EditProfileFragment.SCREEN_CONFIG;
import static net.osmand.plus.profiles.EditProfileFragment.SELECTED_ITEM;
import static net.osmand.plus.profiles.SettingsProfileFragment.PROFILE_STRING_KEY;
public class ConfigureProfileFragment extends BaseSettingsFragment {
@ -245,6 +246,7 @@ public class ConfigureProfileFragment extends BaseSettingsFragment {
final Class<? extends Activity> settingsActivity = plugin.getSettingsActivity();
if (settingsActivity != null && !plugin.needsInstallation()) {
intent = new Intent(getContext(), settingsActivity);
intent.putExtra(PROFILE_STRING_KEY, getSelectedAppMode().getStringKey());
} else {
intent = new Intent(getContext(), PluginActivity.class);
intent.putExtra(PluginActivity.EXTRA_PLUGIN_ID, plugin.getId());