Add live monitoring preferences screen

This commit is contained in:
Vitaliy 2020-01-16 16:50:48 +02:00
parent 7a6128201f
commit cdcb67b95c
5 changed files with 190 additions and 1 deletions

View file

@ -11,6 +11,7 @@
Thx - Hardy
-->
<string name="live_monitoring_descr">Allow you to share current location using trip recording.</string>
<string name="live_monitoring">Online tracking</string>
<string name="save_track_logging_accuracy">Logging accuracy</string>
<string name="tracks_view_descr">You can find all your recorded tracks in Menu — My place — Tracks or in OsmAd folder using file manager.</string>

View file

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:key="proxy"
android:title="@string/live_monitoring">
<Preference
android:key="live_monitoring_info"
android:layout="@layout/preference_info"
android:persistent="false"
android:selectable="false"
android:title="@string/live_monitoring_descr" />
<net.osmand.plus.settings.preferences.EditTextPreferenceEx
android:key="live_monitoring_url"
android:layout="@layout/preference_with_descr"
android:title="@string/live_monitoring_url"
tools:icon="@drawable/ic_world_globe_dark"
tools:summary="@string/live_monitoring_m_descr" />
<net.osmand.plus.settings.preferences.ListPreferenceEx
android:key="live_monitoring_interval"
android:layout="@layout/preference_with_descr"
android:title="@string/live_monitoring_interval"
tools:icon="@drawable/ic_action_time_span"
tools:summary="5 seconds" />
<net.osmand.plus.settings.preferences.ListPreferenceEx
android:key="live_monitoring_maximum_interval_to_send"
android:layout="@layout/preference_with_descr"
android:title="@string/live_monitoring_max_interval_to_send"
tools:icon="@drawable/ic_action_time_span"
tools:summary="15 min" />
</PreferenceScreen>

View file

@ -1,7 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:title="@string/audionotes_plugin_name">
android:title="@string/monitoring_settings">
<PreferenceCategory
android:key="navigation"
@ -81,6 +82,7 @@
android:summaryOff="@string/shared_string_disabled"
android:summaryOn="@string/shared_string_enabled"
android:title="@string/live_monitoring"
app:fragment="net.osmand.plus.settings.LiveMonitoringFragment"
tools:icon="@drawable/ic_world_globe_dark" />
<Preference

View file

@ -89,6 +89,7 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
OPEN_STREET_MAP_EDITING(OsmEditingFragment.class.getName(), false, R.xml.osm_editing, R.layout.global_preference_toolbar),
CONFIGURE_PROFILE(ConfigureProfileFragment.class.getName(), true, R.xml.configure_profile, R.layout.profile_preference_toolbar_with_switch),
PROXY_SETTINGS(ProxySettingsFragment.class.getName(), false, R.xml.proxy_preferences, R.layout.global_preferences_toolbar_with_switch),
LIVE_MONITORING(LiveMonitoringFragment.class.getName(), false, R.xml.live_monitoring, R.layout.global_preferences_toolbar_with_switch),
GENERAL_PROFILE(GeneralProfileSettingsFragment.class.getName(), true, R.xml.general_profile_settings, R.layout.profile_preference_toolbar_big),
NAVIGATION(NavigationFragment.class.getName(), true, R.xml.navigation_settings_new, R.layout.profile_preference_toolbar),
COORDINATES_FORMAT(CoordinatesFormatFragment.class.getName(), true, R.xml.coordinates_format, R.layout.profile_preference_toolbar),

View file

@ -0,0 +1,150 @@
package net.osmand.plus.settings;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.support.v4.app.FragmentManager;
import android.support.v4.content.ContextCompat;
import android.support.v7.preference.Preference;
import android.support.v7.widget.SwitchCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import net.osmand.AndroidUtils;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.settings.bottomsheets.ChangeGeneralProfilesPrefBottomSheet;
import net.osmand.plus.settings.preferences.EditTextPreferenceEx;
import net.osmand.plus.settings.preferences.ListPreferenceEx;
import java.io.Serializable;
import static net.osmand.plus.UiUtilities.CompoundButtonType.TOOLBAR;
import static net.osmand.plus.monitoring.OsmandMonitoringPlugin.MAX_INTERVAL_TO_SEND_MINUTES;
import static net.osmand.plus.monitoring.OsmandMonitoringPlugin.MINUTES;
import static net.osmand.plus.monitoring.OsmandMonitoringPlugin.SECONDS;
public class LiveMonitoringFragment extends BaseSettingsFragment {
@Override
protected void setupPreferences() {
setupLiveMonitoringUrlPref();
setupLiveMonitoringIntervalPref();
setupLiveMonitoringBufferPref();
enableDisablePreferences(settings.LIVE_MONITORING.getModeValue(getSelectedAppMode()));
}
@Override
protected void createToolbar(LayoutInflater inflater, View view) {
super.createToolbar(inflater, view);
view.findViewById(R.id.toolbar_switch_container).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ApplicationMode appMode = getSelectedAppMode();
boolean checked = !settings.LIVE_MONITORING.getModeValue(appMode);
settings.LIVE_MONITORING.setModeValue(appMode, checked);
updateToolbarSwitch();
enableDisablePreferences(checked);
}
});
TextView title = (TextView) view.findViewById(R.id.switchButtonText);
title.setTextColor(ContextCompat.getColor(app, isNightMode() ? R.color.active_color_primary_dark : R.color.active_color_primary_light));
}
@Override
protected void updateToolbar() {
super.updateToolbar();
updateToolbarSwitch();
}
private void updateToolbarSwitch() {
View view = getView();
if (view == null) {
return;
}
boolean checked = settings.LIVE_MONITORING.getModeValue(getSelectedAppMode());
int color = checked ? getActiveProfileColor() : ContextCompat.getColor(app, R.color.preference_top_switch_off);
View selectableView = view.findViewById(R.id.selectable_item);
View switchContainer = view.findViewById(R.id.toolbar_switch_container);
AndroidUtils.setBackground(switchContainer, new ColorDrawable(color));
SwitchCompat switchView = (SwitchCompat) selectableView.findViewById(R.id.switchWidget);
switchView.setChecked(checked);
UiUtilities.setupCompoundButton(switchView, isNightMode(), TOOLBAR);
TextView title = (TextView) selectableView.findViewById(R.id.switchButtonText);
title.setText(checked ? R.string.shared_string_enabled : R.string.shared_string_disabled);
title.setTextColor(ContextCompat.getColor(app, isNightMode() ? R.color.text_color_tab_active_dark : R.color.text_color_tab_active_light));
Drawable drawable = UiUtilities.getColoredSelectableDrawable(app, getActiveProfileColor(), 0.3f);
AndroidUtils.setBackground(selectableView, drawable);
}
private void setupLiveMonitoringUrlPref() {
EditTextPreferenceEx liveMonitoringUrl = (EditTextPreferenceEx) findPreference(settings.LIVE_MONITORING_URL.getId());
liveMonitoringUrl.setSummary(settings.LIVE_MONITORING_URL.getModeValue(getSelectedAppMode()));
liveMonitoringUrl.setDescription(R.string.live_monitoring_m_descr);
liveMonitoringUrl.setIcon(getContentIcon(R.drawable.ic_world_globe_dark));
}
private void setupLiveMonitoringIntervalPref() {
Integer[] entryValues = new Integer[SECONDS.length + MINUTES.length];
String[] entries = new String[entryValues.length];
int k = 0;
for (int second : SECONDS) {
entryValues[k] = second * 1000;
entries[k] = second + " " + getString(R.string.int_seconds);
k++;
}
for (int minute : MINUTES) {
entryValues[k] = (minute * 60) * 1000;
entries[k] = minute + " " + getString(R.string.int_min);
k++;
}
ListPreferenceEx liveMonitoringInterval = (ListPreferenceEx) findPreference(settings.LIVE_MONITORING_INTERVAL.getId());
liveMonitoringInterval.setEntries(entries);
liveMonitoringInterval.setEntryValues(entryValues);
liveMonitoringInterval.setIcon(getContentIcon(R.drawable.ic_action_time_span));
liveMonitoringInterval.setDescription(R.string.live_monitoring_interval_descr);
}
private void setupLiveMonitoringBufferPref() {
Integer[] entryValues = new Integer[MAX_INTERVAL_TO_SEND_MINUTES.length];
String[] entries = new String[entryValues.length];
for (int i = 0; i < MAX_INTERVAL_TO_SEND_MINUTES.length; i++) {
int minute = MAX_INTERVAL_TO_SEND_MINUTES[i];
entryValues[i] = (minute * 60) * 1000;
entries[i] = minute + " " + getString(R.string.int_min);
}
ListPreferenceEx liveMonitoringBuffer = (ListPreferenceEx) findPreference(settings.LIVE_MONITORING_MAX_INTERVAL_TO_SEND.getId());
liveMonitoringBuffer.setEntries(entries);
liveMonitoringBuffer.setEntryValues(entryValues);
liveMonitoringBuffer.setIcon(getContentIcon(R.drawable.ic_action_time_span));
liveMonitoringBuffer.setDescription(R.string.live_monitoring_max_interval_to_send_desrc);
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
String prefId = preference.getKey();
OsmandSettings.OsmandPreference pref = settings.getPreference(prefId);
if (pref instanceof OsmandSettings.CommonPreference && !((OsmandSettings.CommonPreference) pref).hasDefaultValueForMode(getSelectedAppMode())) {
FragmentManager fragmentManager = getFragmentManager();
if (fragmentManager != null && newValue instanceof Serializable) {
ChangeGeneralProfilesPrefBottomSheet.showInstance(fragmentManager, prefId,
(Serializable) newValue, this, false, getSelectedAppMode());
}
return false;
}
return true;
}
}