Profile settings third part

This commit is contained in:
Chumva 2019-08-30 15:58:36 +03:00
parent 074c5c50d4
commit f7f29c5b0b
72 changed files with 4257 additions and 2202 deletions

View file

@ -897,6 +897,15 @@
<receiver android:name="net.osmand.plus.liveupdates.LiveUpdatesAlarmReceiver"/> <receiver android:name="net.osmand.plus.liveupdates.LiveUpdatesAlarmReceiver"/>
<activity
android:configChanges="keyboardHidden|orientation"
android:label="Application profiles"
android:name=".profiles.SettingsProfileActivity"/>
<activity
android:name=".profiles.EditProfileActivity"
android:label="Application profiles"/>
<activity android:name=".activities.PrivacyAndSecurityActivity" <activity android:name=".activities.PrivacyAndSecurityActivity"
android:configChanges="keyboardHidden|orientation" /> android:configChanges="keyboardHidden|orientation" />

View file

@ -1,9 +1,9 @@
<ripple xmlns:android="http://schemas.android.com/apk/res/android" <ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="#D9F0B400"> android:color="#D9F0B400">
<item android:id="@android:id/mask"> <item android:id="@android:id/mask">
<shape android:shape="rectangle"> <shape android:shape="rectangle">
<solid android:color="@color/active_color_primary_light" /> <solid android:color="@color/active_color_primary_light" />
<corners android:radius="4dp" /> <corners android:radius="4dp" />
</shape> </shape>
</item> </item>
</ripple> </ripple>

File diff suppressed because it is too large Load diff

View file

@ -28,4 +28,11 @@
tools:text="Toolbar" tools:text="Toolbar"
tools:visibility="visible" /> tools:visibility="visible" />
<ProgressBar
android:id="@+id/ProgressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:visibility="gone" />
</android.support.v7.widget.Toolbar> </android.support.v7.widget.Toolbar>

View file

@ -0,0 +1,67 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:osmand="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:gravity="center_vertical"
android:minHeight="72dp">
<ImageView
android:id="@android:id/icon"
android:layout_width="@dimen/standard_icon_size"
android:layout_height="@dimen/standard_icon_size"
android:layout_gravity="center"
android:layout_marginStart="@dimen/content_padding"
android:layout_marginLeft="@dimen/content_padding"
android:layout_marginEnd="@dimen/content_padding_half"
android:layout_marginRight="@dimen/content_padding_half" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:paddingLeft="@dimen/content_padding"
android:paddingRight="@dimen/content_padding">
<net.osmand.plus.widgets.TextViewEx
android:id="@android:id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
android:singleLine="true"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_list_text_size"
osmand:typeface="@string/font_roboto_regular" />
<net.osmand.plus.widgets.TextViewEx
android:id="@android:id/summary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="4"
android:textColor="?android:textColorSecondary"
android:textSize="@dimen/default_list_text_size"
osmand:typeface="@string/font_roboto_regular" />
</LinearLayout>
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:layout_marginTop="18dp"
android:layout_marginBottom="18dp"
android:background="?attr/divider_color_basic" />
<Switch
android:id="@android:id/switch_widget"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="@null"
android:clickable="true"
android:focusable="true"
android:paddingLeft="@dimen/content_padding"
android:paddingRight="@dimen/content_padding" />
</LinearLayout>

View file

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:osmand="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="72dp">
<ImageView
android:id="@android:id/icon"
android:layout_width="@dimen/standard_icon_size"
android:layout_height="@dimen/standard_icon_size"
android:layout_marginLeft="@dimen/content_padding"
android:layout_marginTop="@dimen/content_padding"
android:layout_marginRight="@dimen/content_padding"
tools:icon="@drawable/ic_action_info_dark"
tools:tint="?attr/default_icon_color" />
<net.osmand.plus.widgets.TextViewEx
android:id="@android:id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/content_padding"
android:layout_marginTop="@dimen/content_padding_small"
android:layout_marginRight="@dimen/content_padding"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_desc_text_size"
osmand:typeface="@string/font_roboto_regular" />
</LinearLayout>

View file

@ -0,0 +1,60 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:osmand="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:gravity="center_vertical"
android:minHeight="72dp">
<ImageView
android:id="@android:id/icon"
android:layout_width="@dimen/standard_icon_size"
android:layout_height="@dimen/standard_icon_size"
android:layout_gravity="center"
android:layout_marginStart="@dimen/content_padding"
android:layout_marginLeft="@dimen/content_padding"
android:layout_marginEnd="@dimen/content_padding_half"
android:layout_marginRight="@dimen/content_padding_half" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:paddingLeft="@dimen/content_padding"
android:paddingRight="@dimen/content_padding">
<net.osmand.plus.widgets.TextViewEx
android:id="@android:id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
android:singleLine="true"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_list_text_size"
osmand:typeface="@string/font_roboto_regular" />
<net.osmand.plus.widgets.TextViewEx
android:id="@android:id/summary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="4"
android:textColor="?android:textColorSecondary"
android:textSize="@dimen/default_list_text_size"
osmand:typeface="@string/font_roboto_regular" />
</LinearLayout>
<Switch
android:id="@android:id/switch_widget"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="@null"
android:clickable="true"
android:focusable="true"
android:paddingLeft="@dimen/content_padding"
android:paddingRight="@dimen/content_padding" />
</LinearLayout>

View file

@ -0,0 +1,42 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:osmand="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:gravity="center_vertical"
android:minHeight="@dimen/bottom_sheet_selected_item_title_height"
android:orientation="horizontal">
<ImageView
android:id="@android:id/icon"
android:layout_width="@dimen/standard_icon_size"
android:layout_height="@dimen/standard_icon_size"
android:layout_marginStart="@dimen/content_padding"
android:layout_marginLeft="@dimen/content_padding"
android:layout_marginEnd="@dimen/content_padding_half"
android:layout_marginRight="@dimen/content_padding_half" />
<net.osmand.plus.widgets.TextViewEx
android:id="@android:id/summary"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/content_padding"
android:layout_marginRight="@dimen/content_padding"
android:layout_weight="1"
android:textColor="#FFFFFF"
android:textSize="@dimen/default_list_text_size"
osmand:typeface="@string/font_roboto_regular" />
<android.support.v7.widget.SwitchCompat
android:id="@android:id/switch_widget"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="@null"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:paddingLeft="@dimen/content_padding"
android:paddingRight="@dimen/content_padding" />
</LinearLayout>

View file

@ -47,4 +47,4 @@
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>

View file

@ -67,4 +67,4 @@
</LinearLayout> </LinearLayout>
</android.support.v7.widget.Toolbar> </android.support.v7.widget.Toolbar>

View file

@ -51,7 +51,8 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center" android:layout_gravity="center"
android:padding="@dimen/content_padding" android:padding="@dimen/content_padding"
android:src="@drawable/ic_overflow_menu_dark" /> android:src="@drawable/ic_overflow_menu_dark"
android:visibility="gone" />
</LinearLayout> </LinearLayout>
@ -141,4 +142,4 @@
</LinearLayout> </LinearLayout>
</android.support.v7.widget.Toolbar> </android.support.v7.widget.Toolbar>

View file

@ -1,68 +1,50 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <RelativeLayout
xmlns:osmand="http://schemas.android.com/apk/res-auto" xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="?attr/activity_background_color" android:background="?attr/activity_background_color"
android:orientation="vertical"> android:orientation="vertical">
<android.support.design.widget.AppBarLayout <android.support.v7.widget.RecyclerView
android:id="@+id/appbar" android:id="@+id/profiles_list"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content"
<android.support.v7.widget.Toolbar android:clipToPadding="false"
android:id="@+id/toolbar" android:paddingBottom="72dp"/>
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="56dp"
osmand:theme="@style/ThemeOverlay.AppCompat.ActionBar">
</android.support.v7.widget.Toolbar> <LinearLayout
android:id="@+id/add_profile_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:clickable="true"
android:focusable="true"
android:layout_gravity="bottom|center_horizontal"
android:background="@drawable/fab_extended_drawable"
android:orientation="horizontal"
android:gravity="center_vertical">
</android.support.design.widget.AppBarLayout> <android.support.v7.widget.AppCompatImageView
android:layout_gravity="center_vertical"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginLeft="14dp"
android:layout_marginStart="14dp"
android:src="@drawable/ic_action_plus"/>
<FrameLayout <android.support.v7.widget.AppCompatTextView
android:layout_width="match_parent" android:layout_width="wrap_content"
android:layout_height="match_parent"> android:layout_height="wrap_content"
android:text="@string/shared_string_add"
android:textColor="@color/color_white"
android:layout_marginRight="20dp"
android:layout_marginEnd="20dp"
/>
<android.support.v7.widget.RecyclerView </LinearLayout>
android:id="@+id/profiles_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false"
android:paddingBottom="72dp" />
<LinearLayout </RelativeLayout>
android:id="@+id/add_profile_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:background="@drawable/fab_extended_drawable"
android:clickable="true"
android:focusable="true"
android:gravity="center_vertical"
android:orientation="horizontal">
<android.support.v7.widget.AppCompatImageView
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_gravity="center_vertical"
android:layout_marginStart="14dp"
android:layout_marginLeft="14dp"
android:src="@drawable/ic_action_plus" />
<android.support.v7.widget.AppCompatTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="20dp"
android:layout_marginRight="20dp"
android:text="@string/shared_string_add"
android:textColor="@color/color_white" />
</LinearLayout>
</FrameLayout>
</LinearLayout>

View file

@ -19,9 +19,9 @@
android:paddingLeft="@dimen/content_padding" android:paddingLeft="@dimen/content_padding"
android:paddingRight="@dimen/content_padding" android:paddingRight="@dimen/content_padding"
android:singleLine="true" android:singleLine="true"
android:textColor="?android:textColorPrimary" android:textColor="@color/preference_category_title"
android:textSize="@dimen/default_desc_text_size" android:textSize="@dimen/default_desc_text_size"
osmand:typeface="@string/font_roboto_medium" osmand:typeface="@string/font_roboto_medium"
tools:text="@string/shared_string_other" /> tools:text="@string/shared_string_other" />
</LinearLayout> </LinearLayout>

View file

@ -423,6 +423,8 @@
<color name="text_field_box_dark">#3F474B</color> <color name="text_field_box_dark">#3F474B</color>
<color name="text_field_box_light">#eeeeee</color> <color name="text_field_box_light">#eeeeee</color>
<color name="preference_category_title">#7E33FF</color>
<!-- Basic colors --> <!-- Basic colors -->
<color name="app_bar_main_dark">#101112</color> <color name="app_bar_main_dark">#101112</color>
<color name="app_bar_main_light">#ff8800</color> <color name="app_bar_main_light">#ff8800</color>

View file

@ -11,6 +11,42 @@
Thx - Hardy Thx - Hardy
--> -->
<string name="start_up_message_pref">Start up message</string>
<string name="analytics_pref_title">Analytics</string>
<string name="turn_screen_on_info">Show map during navigation above the lock screen.</string>
<string name="vehicle_parameters_info">These settings affect the construction of the route. Will be applied only to the selected profile: %1$s.</string>
<string name="wake_time">Wake time</string>
<string name="units_and_formats">Units &amp; formats</string>
<string name="appearance">Appearance</string>
<string name="map_look_descr">icons, widgets</string>
<string name="map_look">Map look</string>
<string name="list_of_installed_plugins">List of installed plugins</string>
<string name="configure_navigation">Configure navigation</string>
<string name="general_settings_profile_descr">App theme, units, region</string>
<string name="configure_profile">Configure profile</string>
<string name="screen_alerts_descr">Alerts will be shown on left bottom corner of the screen during the navigation.</string>
<string name="switch_profile">Switch profile</string>
<string name="language_and_output">Language and output</string>
<string name="reset_to_default">Reset to default</string>
<string name="manage_profiles_descr">Create, import, edit profiles</string>
<string name="manage_profiles">Manage application profiles…</string>
<string name="osmand_settings_descr">Affect the entire application</string>
<string name="osmand_settings">OsmAnd settings</string>
<string name="personal_account_descr">Create or Log in into personal account</string>
<string name="personal_account">Personal account</string>
<string name="copy_from_other_profile">Copy from other profile</string>
<string name="turn_screen_on">Turn screen on</string>
<string name="map_during_navigation_info">Map during navigation</string>
<string name="map_during_navigation">Map during navigation</string>
<string name="shared_string_other">Other</string>
<string name="vehicle_parameters_descr">Weight, height, speed</string>
<string name="vehicle_parameters">Vehicle parameters</string>
<string name="voice_announces_info">Voice announces are played only during navigation.</string>
<string name="voice_announces_descr">Navigation instruction and announces</string>
<string name="voice_announces">Voice announces</string>
<string name="screen_alerts">Screen alerts</string>
<string name="route_parameters_descr">Configure route parameters</string>
<string name="route_parameters">Route parameters</string>
<string name="day">Day</string> <string name="day">Day</string>
<string name="days_2_4">Days</string> <string name="days_2_4">Days</string>
<string name="days_5">Days</string> <string name="days_5">Days</string>
@ -34,37 +70,6 @@
<string name="price_and_discount">%1$s • Save %2$s</string> <string name="price_and_discount">%1$s • Save %2$s</string>
<string name="app_mode_wagon">Wagon</string> <string name="app_mode_wagon">Wagon</string>
<string name="app_mode_pickup_truck">Pickup truck</string> <string name="app_mode_pickup_truck">Pickup truck</string>
<string name="units_and_formats">Units &amp; formats</string>
<string name="appearance">Appearance</string>
<string name="map_look_descr">icons, widgets</string>
<string name="map_look">Map look</string>
<string name="list_of_installed_plugins">List of installed plugins</string>
<string name="configure_navigation">Configure navigation</string>
<string name="general_settings_profile_descr">App theme, units, region</string>
<string name="configure_profile">Configure profile</string>
<string name="screen_alerts_descr">Alerts will be shown on left bottom corner of the screen during the navigation.</string>
<string name="switch_profile">Switch profile</string>
<string name="language_and_output">Language and output</string>
<string name="reset_to_default">Reset to default</string>
<string name="manage_profiles_descr">Create, import, edit profiles</string>
<string name="manage_profiles">Manage application profiles…</string>
<string name="osmand_settings_descr">Affect the entire application</string>
<string name="osmand_settings">OsmAnd settings</string>
<string name="personal_account_descr">Create or Log in into personal account</string>
<string name="personal_account">Personal account</string>
<string name="copy_from_other_profile">Copy from other profile</string>
<string name="turn_screen_on">Turn screen on</string>
<string name="map_during_navigation_descr">Map during navigation</string>
<string name="map_during_navigation">Map during navigation</string>
<string name="shared_string_other">Other</string>
<string name="vehicle_parameters_descr">Weight, height, speed</string>
<string name="vehicle_parameters">Vehicle parameters</string>
<string name="voice_announces_info">Voice announces are played only during navigation.</string>
<string name="voice_announces_descr">Navigation instruction and announces</string>
<string name="voice_announces">Voice announces</string>
<string name="screen_alerts">Screen alerts</string>
<string name="route_parameters_descr">Configure route parameters</string>
<string name="route_parameters">Route parameters</string>
<string name="shared_string_default">Default</string> <string name="shared_string_default">Default</string>
<string name="gpx_join_gaps">Join gaps</string> <string name="gpx_join_gaps">Join gaps</string>
<string name="app_mode_camper">Camper</string> <string name="app_mode_camper">Camper</string>

View file

@ -100,18 +100,8 @@
<item name="android:textColor">@color/active_color_primary_dark</item> <item name="android:textColor">@color/active_color_primary_dark</item>
</style> </style>
<!-- Custom Preference Theme -->
<style name="AppPreferenceTheme" parent="@style/PreferenceThemeOverlay.v14.Material">
<item name="preferenceFragmentCompatStyle">@style/AppPreferenceFragmentCompatStyle</item>
</style>
<!-- Custom Style for PreferenceFragmentCompat -->
<style name="AppPreferenceFragmentCompatStyle" parent="@style/PreferenceFragment.Material">
<item name="android:layout">@layout/pref_screen</item>
</style>
<!-- Osmand themes styles --> <!-- Osmand themes styles -->
<style name="OsmandLightTheme" parent="Theme.AppCompat.Light"> <style name="OsmandLightTheme" parent="Theme.AppCompat.Light">
<item name="preferenceTheme">@style/AppPreferenceTheme</item>
<item name="android:statusBarColor">@color/status_bar_color_light</item> <item name="android:statusBarColor">@color/status_bar_color_light</item>
<item name="mapBackground">@color/map_background_color_light</item> <item name="mapBackground">@color/map_background_color_light</item>
<item name="chart_marker_background">@drawable/chart_marker_background_light</item> <item name="chart_marker_background">@drawable/chart_marker_background_light</item>
@ -273,6 +263,7 @@
<item name="buttonBarNeutralButtonStyle">@style/DialogButtonStyleLight</item> <item name="buttonBarNeutralButtonStyle">@style/DialogButtonStyleLight</item>
<item name="colorBackgroundFloating">@color/list_background_color_light</item> <item name="colorBackgroundFloating">@color/list_background_color_light</item>
<item name="android:colorBackgroundFloating">@color/list_background_color_light</item> <item name="android:colorBackgroundFloating">@color/list_background_color_light</item>
<item name="preferenceTheme">@style/OsmandPreferenceTheme</item>
</style> </style>
<style name="OverflowMenuButton" parent="@style/Widget.AppCompat.ActionButton.Overflow"> <style name="OverflowMenuButton" parent="@style/Widget.AppCompat.ActionButton.Overflow">
@ -385,7 +376,6 @@
</style> </style>
<style name="OsmandDarkTheme" parent="Theme.AppCompat"> <style name="OsmandDarkTheme" parent="Theme.AppCompat">
<item name="preferenceTheme">@style/AppPreferenceTheme</item>
<item name="android:statusBarColor">@color/status_bar_color_dark</item> <item name="android:statusBarColor">@color/status_bar_color_dark</item>
<item name="mapBackground">@color/map_background_color_dark</item> <item name="mapBackground">@color/map_background_color_dark</item>
<item name="chart_marker_background">@drawable/chart_marker_background_dark</item> <item name="chart_marker_background">@drawable/chart_marker_background_dark</item>
@ -535,6 +525,7 @@
<item name="buttonBarNeutralButtonStyle">@style/DialogButtonStyleDark</item> <item name="buttonBarNeutralButtonStyle">@style/DialogButtonStyleDark</item>
<item name="colorBackgroundFloating">@color/list_background_color_dark</item> <item name="colorBackgroundFloating">@color/list_background_color_dark</item>
<item name="android:colorBackgroundFloating">@color/list_background_color_dark</item> <item name="android:colorBackgroundFloating">@color/list_background_color_dark</item>
<item name="preferenceTheme">@style/OsmandPreferenceTheme</item>
</style> </style>
<style name="FreeVersionBanner" parent="OsmandDarkTheme"> <style name="FreeVersionBanner" parent="OsmandDarkTheme">
@ -557,6 +548,10 @@
<item name="android:textColor">@color/active_color_primary_dark</item> <item name="android:textColor">@color/active_color_primary_dark</item>
</style> </style>
<style name="OsmandPreferenceTheme" parent="@style/PreferenceThemeOverlay.v14.Material">
<item name="android:layout">@layout/pref_screen</item>
</style>
<!-- Standard action bar override --> <!-- Standard action bar override -->
<style name="Widget.Styled.ActionBarDark" parent="Widget.AppCompat.Light.ActionBar.Solid.Inverse"> <style name="Widget.Styled.ActionBarDark" parent="Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="background">@color/app_bar_color_dark</item> <item name="background">@color/app_bar_color_dark</item>

View file

@ -9,7 +9,7 @@
android:persistent="false" android:persistent="false"
android:summary="@string/general_settings_profile_descr" android:summary="@string/general_settings_profile_descr"
android:title="@string/general_settings_2" android:title="@string/general_settings_2"
app:fragment="net.osmand.plus.settings.ProfileGeneralSettings" app:fragment="net.osmand.plus.settings.GeneralProfileSettings"
tools:icon="@drawable/ic_action_settings" /> tools:icon="@drawable/ic_action_settings" />
<Preference <Preference
@ -35,4 +35,4 @@
android:summary="@string/list_of_installed_plugins" android:summary="@string/list_of_installed_plugins"
android:title="@string/plugin_settings" /> android:title="@string/plugin_settings" />
</PreferenceScreen> </PreferenceScreen>

View file

@ -1,92 +1,80 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<Preference <PreferenceCategory
android:key="appearance_category" android:key="appearance_category"
android:layout="@layout/simple_preference_category" android:layout="@layout/simple_preference_category"
android:selectable="false"
android:title="@string/appearance" /> android:title="@string/appearance" />
<net.osmand.plus.views.ListIntPreference <net.osmand.plus.settings.preferences.ListPreferenceEx
android:defaultValue="1"
android:key="osmand_theme" android:key="osmand_theme"
android:layout="@layout/preference_with_descr" android:layout="@layout/preference_with_descr"
android:summary="@string/choose_osmand_theme_descr"
android:title="@string/choose_osmand_theme" /> android:title="@string/choose_osmand_theme" />
<net.osmand.plus.views.ListIntPreference <net.osmand.plus.settings.preferences.ListPreferenceEx
android:defaultValue="0"
android:key="rotate_map" android:key="rotate_map"
android:layout="@layout/preference_with_descr" android:layout="@layout/preference_with_descr"
android:summary="@string/rotate_map_to_bearing_descr"
android:title="@string/rotate_map_to_bearing" /> android:title="@string/rotate_map_to_bearing" />
<net.osmand.plus.views.ListIntPreference <net.osmand.plus.settings.preferences.ListPreferenceEx
android:defaultValue="-1"
android:key="map_screen_orientation" android:key="map_screen_orientation"
android:layout="@layout/preference_with_descr" android:layout="@layout/preference_with_descr"
android:summary="@string/map_screen_orientation_descr"
android:title="@string/map_screen_orientation" /> android:title="@string/map_screen_orientation" />
<Preference <PreferenceCategory
android:key="units_and_formats" android:key="units_and_formats"
android:layout="@layout/simple_preference_category" android:layout="@layout/simple_preference_category"
android:selectable="false"
android:title="@string/units_and_formats" /> android:title="@string/units_and_formats" />
<Preference <Preference
android:key="default_driving_region" android:key="default_driving_region"
android:layout="@layout/preference_with_descr" android:layout="@layout/preference_with_descr"
android:summary="@string/driving_region_descr"
android:title="@string/driving_region" /> android:title="@string/driving_region" />
<ListPreference <net.osmand.plus.settings.preferences.ListPreferenceEx
android:key="default_metric_system" android:key="default_metric_system"
android:layout="@layout/preference_with_descr" android:layout="@layout/preference_with_descr"
android:summary="@string/unit_of_length_descr"
android:title="@string/unit_of_length" /> android:title="@string/unit_of_length" />
<net.osmand.plus.views.ListIntPreference <net.osmand.plus.settings.preferences.ListPreferenceEx
android:key="coordinates_format" android:key="coordinates_format"
android:layout="@layout/preference_with_descr" android:layout="@layout/preference_with_descr"
android:summary="@string/coords_format_descr"
android:title="@string/coords_format" /> android:title="@string/coords_format" />
<ListPreference <net.osmand.plus.settings.preferences.ListPreferenceEx
android:key="angular_measurement" android:key="angular_measurement"
android:layout="@layout/preference_with_descr" android:layout="@layout/preference_with_descr"
android:summary="@string/angular_measeurement_descr"
android:title="@string/angular_measeurement" /> android:title="@string/angular_measeurement" />
<Preference <PreferenceCategory
android:key="other" android:key="other"
android:layout="@layout/simple_preference_category" android:layout="@layout/simple_preference_category"
android:selectable="false"
android:title="@string/shared_string_other" /> android:title="@string/shared_string_other" />
<SwitchPreference <net.osmand.plus.settings.preferences.SwitchPreferenceEx
android:key="use_kalman_filter_compass" android:key="use_kalman_filter_compass"
android:layout="@layout/preference_fragment_and_switch" android:layout="@layout/preference_dialog_and_switch"
android:title="@string/use_kalman_filter_compass" /> android:title="@string/use_kalman_filter_compass" />
<SwitchPreference <net.osmand.plus.settings.preferences.SwitchPreferenceEx
android:key="use_magnetic_field_sensor_compass" android:key="use_magnetic_field_sensor_compass"
android:layout="@layout/preference_fragment_and_switch" android:layout="@layout/preference_dialog_and_switch"
android:title="@string/use_magnetic_sensor" /> android:title="@string/use_magnetic_sensor" />
<SwitchPreference <net.osmand.plus.settings.preferences.SwitchPreferenceEx
android:key="full_screen_mode" android:key="map_empty_state_allowed"
android:layout="@layout/preference_fragment_and_switch" android:layout="@layout/preference_dialog_and_switch"
android:title="@string/use_kalman_filter_compass" /> android:title="@string/tap_on_map_to_hide_interface" />
<SwitchPreference <SwitchPreference
android:key="do_not_use_animations" android:key="do_not_use_animations"
android:layout="@layout/preference_fragment_and_switch" android:layout="@layout/preference_switch"
android:title="@string/tap_on_map_to_hide_interface" /> android:summary="@string/do_not_use_animations_descr"
android:title="@string/do_not_use_animations" />
<net.osmand.plus.views.ListIntPreference <net.osmand.plus.settings.preferences.ListPreferenceEx
android:key="external_input_device" android:key="external_input_device"
android:layout="@layout/preference_fragment_and_switch" android:layout="@layout/preference_dialog_and_switch"
android:title="@string/external_input_device" /> android:title="@string/external_input_device" />
</PreferenceScreen> </PreferenceScreen>

View file

@ -0,0 +1,49 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto">
<net.osmand.plus.settings.preferences.ListPreferenceEx
android:icon="@drawable/ic_world_globe_dark"
android:key="default_application_mode_string"
android:layout="@layout/preference_with_descr"
android:title="@string/settings_preset" />
<net.osmand.plus.settings.preferences.ListPreferenceEx
android:icon="@drawable/ic_action_map_language"
android:key="preferred_locale"
android:layout="@layout/preference_with_descr"
android:title="@string/preferred_locale" />
<Preference
android:icon="@drawable/ic_action_folder"
android:key="external_storage_dir"
android:layout="@layout/preference_with_descr"
android:persistent="false"
android:title="@string/application_dir" />
<PreferenceCategory
android:key="privacy_and_security"
android:layout="@layout/simple_preference_category"
android:title="@string/application_profiles" />
<net.osmand.plus.settings.preferences.SwitchPreferenceEx
android:icon="@drawable/ic_action_privacy_and_security"
android:key="send_anonymous_data"
android:layout="@layout/preference_dialog_and_switch"
android:title="@string/analytics_pref_title" />
<SwitchPreference
android:icon="@drawable/ic_action_notification"
android:key="do_not_show_startup_messages"
android:layout="@layout/preference_switch"
android:title="@string/start_up_message_pref" />
<net.osmand.plus.settings.preferences.SwitchPreferenceEx
android:key="enable_proxy"
android:layout="@layout/preference_dialog_and_switch"
android:title="@string/proxy_pref_title"
app:fragment="net.osmand.plus.settings.ProxySettingsFragment"
tools:icon="@drawable/ic_action_proxy" />
</PreferenceScreen>

View file

@ -1,29 +1,30 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<net.osmand.plus.views.ListIntPreference <Preference
android:key="map_during_navigation_info"
android:selectable="false"
android:layout="@layout/preference_info"
android:title="@string/map_during_navigation_info" />
<net.osmand.plus.settings.preferences.ListPreferenceEx
android:key="auto_follow_route" android:key="auto_follow_route"
android:summary="@string/choose_auto_follow_route_descr" android:layout="@layout/preference_with_descr"
android:title="@string/choose_auto_follow_route" /> android:title="@string/choose_auto_follow_route" />
<Preference <net.osmand.plus.settings.preferences.ListPreferenceEx
android:key="auto_zoom_map_on_off" android:key="auto_zoom_map_on_off"
android:summary="@string/auto_zoom_map_descr" android:layout="@layout/preference_with_descr"
android:title="@string/auto_zoom_map" /> android:title="@string/auto_zoom_map" />
<SwitchPreference <net.osmand.plus.settings.preferences.SwitchPreferenceEx
android:key="snap_to_road" android:key="snap_to_road"
android:summary="@string/snap_to_road_descr" android:layout="@layout/preference_dialog_and_switch"
android:title="@string/snap_to_road" /> android:title="@string/snap_to_road" />
<net.osmand.plus.views.ListFloatPreference <net.osmand.plus.settings.preferences.ListPreferenceEx
android:key="speed_for_map_to_direction_of_movement" android:key="speed_for_map_to_direction_of_movement"
android:summary="@string/map_orientation_change_in_accordance_with_speed_descr" android:layout="@layout/preference_with_descr"
android:title="@string/map_orientation_change_in_accordance_with_speed" /> android:title="@string/map_orientation_change_in_accordance_with_speed" />
<!--<CheckBoxPreference-->
<!--android:key="show_zoom_buttons_navigation"-->
<!--android:summary="@string/show_zoom_buttons_navigation_descr"-->
<!--android:title="@string/show_zoom_buttons_navigation" />-->
</PreferenceScreen> </PreferenceScreen>

View file

@ -1,72 +1,106 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" <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">
<Preference <PreferenceCategory
android:key="route_parameters" android:key="routing_preferences"
android:layout="@layout/preference_with_descr" android:title="@string/routing_preferences_descr">
android:summary="@string/route_parameters_descr" <CheckBoxPreference
android:title="@string/route_parameters" android:key="fast_route_mode"
app:fragment="net.osmand.plus.settings.RouteParametersFragment" android:summary="@string/fast_route_mode_descr"
tools:icon="@drawable/ic_action_track_16" /> android:title="@string/fast_route_mode"/>
<Preference
android:key="avoid_in_routing"
android:summary="@string/avoid_in_routing_descr"
android:title="@string/avoid_in_routing_title"/>
<Preference
android:key="prefer_in_routing"
android:summary="@string/prefer_in_routing_descr"
android:title="@string/prefer_in_routing_title"/>
</PreferenceCategory>
<net.osmand.plus.views.SwitchFragmentPreference <PreferenceCategory
android:key="show_routing_alarms" android:key="guidance_preferences"
android:layout="@layout/preference_fragment_and_switch" android:title="@string/guidance_preferences_descr">
android:switchTextOff="@string/shared_string_off" <ListPreference
android:switchTextOn="@string/shared_string_on" android:key="auto_follow_route"
android:title="@string/screen_alerts" android:summary="@string/choose_auto_follow_route_descr"
app:fragment="net.osmand.plus.settings.ScreenAlertsFragment" android:title="@string/choose_auto_follow_route"/>
tools:icon="@drawable/ic_action_alert" /> <Preference
android:key="auto_zoom_map_on_off"
android:summary="@string/auto_zoom_map_descr"
android:title="@string/auto_zoom_map"/>
<CheckBoxPreference
android:key="snap_to_road"
android:summary="@string/snap_to_road_descr"
android:title="@string/snap_to_road"/>
<CheckBoxPreference
android:key="enable_time_conditional_routing"
android:title="@string/temporary_conditional_routing"/>
<Preference
android:key="show_routing_alarms"
android:summary="@string/show_warnings_descr"
android:title="@string/show_warnings_title"/>
<Preference
android:key="speak_routing_alarms"
android:summary="@string/speak_descr"
android:title="@string/speak_title"/>
<ListPreference
android:key="keep_informing"
android:summary="@string/keep_informing_descr"
android:title="@string/keep_informing"/>
<ListPreference
android:key="arrival_distance_factor"
android:summary="@string/arrival_distance_descr"
android:title="@string/arrival_distance"/>
<ListPreference
android:key="default_speed_system"
android:summary="@string/default_speed_system_descr"
android:title="@string/default_speed_system"/>
<ListPreference
android:key="speed_limit_exceed"
android:summary="@string/speed_limit_exceed_message"
android:title="@string/speed_limit_exceed"/>
<ListPreference
android:key="speed_for_map_to_direction_of_movement"
android:summary="@string/map_orientation_change_in_accordance_with_speed_descr"
android:title="@string/map_orientation_change_in_accordance_with_speed"/>
<!--
<CheckBoxPreference android:title="@string/show_zoom_buttons_navigation" android:summary="@string/show_zoom_buttons_navigation_descr" android:key="show_zoom_buttons_navigation" />
-->
<!--
<ListPreference
android:key="delay_to_start_navigation"
android:title="@string/delay_to_start_navigation"
android:summary="@string/delay_to_start_navigation_descr" />
-->
</PreferenceCategory>
<net.osmand.plus.views.SwitchFragmentPreference <PreferenceCategory
android:key="speak_routing_alarms" android:key="turn_screen_on"
android:layout="@layout/preference_fragment_and_switch" android:title="@string/wake_on_voice">
android:summary="@string/voice_announces_descr"
android:title="@string/voice_announces"
app:fragment="net.osmand.plus.settings.VoiceAnnouncesFragment"
tools:icon="@drawable/ic_action_volume_up" />
<Preference <Preference
android:key="vehicle_parameters" android:selectable="false"
android:layout="@layout/preference_with_descr" android:summary="@string/wake_on_voice_descr" />
android:summary="@string/vehicle_parameters_descr"
android:title="@string/vehicle_parameters"
app:fragment="net.osmand.plus.settings.VehicleParametersFragment"
tools:icon="@drawable/ic_action_car_dark" />
<Preference <ListPreference
android:key="other" android:key="turn_screen_on_time_int"
android:layout="@layout/simple_preference_category" android:summary="@string/turn_screen_on_time_descr"
android:selectable="false" android:title="@string/shared_string_time"/>
android:title="@string/shared_string_other" />
<CheckBoxPreference
android:key="turn_screen_on_sensor"
android:summary="@string/turn_screen_on_sensor_descr"
android:title="@string/turn_screen_on_sensor"/>
</PreferenceCategory>
<Preference <PreferenceCategory
android:key="map_during_navigation" android:key="voice"
android:layout="@layout/preference_with_descr" android:title="@string/voice_pref_title">
android:summary="@string/map_during_navigation" <ListPreference
android:title="@string/map_during_navigation" android:key="voice_provider"
app:fragment="net.osmand.plus.settings.MapDuringNavigationFragment" android:summary="@string/voice_provider_descr"
tools:icon="@drawable/ic_action_copy" /> android:title="@string/voice_provider"/>
</PreferenceCategory>
<net.osmand.plus.views.SwitchFragmentPreference
android:key="turn_screen_on"
android:layout="@layout/preference_fragment_and_switch"
android:switchTextOff="@string/shared_string_off"
android:switchTextOn="@string/shared_string_on"
android:title="@string/turn_screen_on"
app:fragment="net.osmand.plus.settings.TurnScreenOnFragment"
tools:icon="@drawable/ic_action_copy" />
<Preference
android:key="copy_from_other_profile"
android:title="@string/copy_from_other_profile"
tools:icon="@drawable/ic_action_copy" />
<Preference
android:key="reset_to_default"
android:title="@string/reset_to_default"
tools:icon="@drawable/ic_action_undo_dark" />
</PreferenceScreen> </PreferenceScreen>

View file

@ -0,0 +1,59 @@
<?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">
<Preference
android:key="route_parameters"
android:layout="@layout/preference_with_descr"
android:summary="@string/route_parameters_descr"
android:title="@string/route_parameters"
app:fragment="net.osmand.plus.settings.RouteParametersFragment"
tools:icon="@drawable/ic_action_route_distance" />
<net.osmand.plus.settings.preferences.SwitchPreferenceEx
android:key="show_routing_alarms"
android:layout="@layout/preference_dialog_and_switch"
android:switchTextOff="@string/shared_string_off"
android:switchTextOn="@string/shared_string_on"
android:title="@string/screen_alerts"
app:fragment="net.osmand.plus.settings.ScreenAlertsFragment"
tools:icon="@drawable/ic_action_alert" />
<net.osmand.plus.settings.preferences.SwitchPreferenceEx
android:key="speak_routing_alarms"
android:layout="@layout/preference_dialog_and_switch"
android:summary="@string/voice_announces_descr"
android:title="@string/voice_announces"
app:fragment="net.osmand.plus.settings.VoiceAnnouncesFragment"
tools:icon="@drawable/ic_action_volume_up" />
<Preference
android:key="vehicle_parameters"
android:layout="@layout/preference_with_descr"
android:summary="@string/vehicle_parameters_descr"
android:title="@string/vehicle_parameters"
app:fragment="net.osmand.plus.settings.VehicleParametersFragment"
tools:icon="@drawable/ic_action_car_dark" />
<PreferenceCategory
android:key="other"
android:layout="@layout/simple_preference_category"
android:title="@string/shared_string_other" />
<Preference
android:key="map_during_navigation"
android:layout="@layout/preference_with_descr"
android:title="@string/map_during_navigation"
app:fragment="net.osmand.plus.settings.MapDuringNavigationFragment" />
<net.osmand.plus.settings.preferences.SwitchPreferenceEx
android:key="turn_screen_on"
android:layout="@layout/preference_dialog_and_switch"
android:switchTextOff="@string/shared_string_off"
android:switchTextOn="@string/shared_string_on"
android:title="@string/turn_screen_on"
app:fragment="net.osmand.plus.settings.TurnScreenOnFragment"
tools:icon="@drawable/ic_action_turn_screen_on"/>
</PreferenceScreen>

View file

@ -0,0 +1,32 @@
<?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:description="@string/proxy_pref_descr"
android:key="proxy"
android:title="@string/proxy_pref_title">
<SwitchPreference
android:key="enable_proxy"
tools:title="@string/enable_proxy_title" />
<Preference
android:key="proxy_preferences_info"
android:layout="@layout/preference_info"
android:persistent="false"
android:selectable="false"
android:title="@string/enable_proxy_descr"
tools:icon="@drawable/ic_action_info_dark" />
<net.osmand.plus.settings.preferences.EditTextPreferenceEx
android:dependency="enable_proxy"
android:key="proxy_host"
android:summary="@string/proxy_host_descr"
android:title="@string/proxy_host_title" />
<net.osmand.plus.settings.preferences.EditTextPreferenceEx
android:dependency="enable_proxy"
android:key="proxy_port"
android:summary="@string/proxy_port_descr"
android:title="@string/proxy_port_title" />
</PreferenceScreen>

View file

@ -2,31 +2,11 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"> xmlns:tools="http://schemas.android.com/tools">
<SwitchPreference
android:key="fast_route_mode"
android:summary="@string/fast_route_mode_descr"
android:title="@string/fast_route_mode"
tools:icon="@drawable/ic_action_fastest_route" />
<Preference <Preference
android:key="avoid_in_routing" android:key="route_parameters_info"
android:summary="@string/avoid_in_routing_descr" android:layout="@layout/preference_info"
android:title="@string/avoid_in_routing_title" android:persistent="false"
tools:icon="@drawable/ic_action_alert" /> android:selectable="false"
tools:title="@string/route_parameters" />
<Preference
android:key="prefer_in_routing"
android:summary="@string/prefer_in_routing_descr"
android:title="@string/prefer_in_routing_title" />
<SwitchPreference
android:key="enable_time_conditional_routing"
android:title="@string/temporary_conditional_routing"
tools:icon="@drawable/ic_action_road_works_dark" />
<!--<ListPreference-->
<!--android:key="delay_to_start_navigation"-->
<!--android:title="@string/delay_to_start_navigation"-->
<!--android:summary="@string/delay_to_start_navigation_descr" />-->
</PreferenceScreen> </PreferenceScreen>

View file

@ -1,15 +1,18 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<SwitchPreference <SwitchPreference
android:key="show_routing_alarms" android:key="show_routing_alarms"
android:title="@string/shared_string_on" /> android:layout="@layout/preference_top_switch"
tools:summary="@string/shared_string_on" />
<Preference <Preference
android:icon="@drawable/ic_action_info_dark" android:icon="@drawable/ic_action_info_dark"
android:key="show_routing_alarms_descr" android:key="show_routing_alarms_info"
android:selectable="false" android:selectable="false"
android:summary="@string/screen_alerts_descr" /> android:layout="@layout/preference_info"
android:title="@string/screen_alerts_descr" />
<SwitchPreference <SwitchPreference
android:key="show_traffic_warnings" android:key="show_traffic_warnings"
@ -23,10 +26,6 @@
android:key="show_cameras" android:key="show_cameras"
android:title="@string/show_cameras" /> android:title="@string/show_cameras" />
<SwitchPreference
android:key="show_lanes"
android:title="@string/show_lanes" />
<SwitchPreference <SwitchPreference
android:key="show_tunnels" android:key="show_tunnels"
android:title="@string/show_tunnels" /> android:title="@string/show_tunnels" />

View file

@ -15,34 +15,35 @@
android:layout="@layout/preference_with_descr" android:layout="@layout/preference_with_descr"
android:summary="@string/osmand_settings_descr" android:summary="@string/osmand_settings_descr"
android:title="@string/osmand_settings" android:title="@string/osmand_settings"
app:fragment="net.osmand.plus.settings.GlobalSettingsFragment"
tools:icon="@drawable/ic_action_settings" /> tools:icon="@drawable/ic_action_settings" />
<Preference <PreferenceCategory
android:key="application_profiles" android:key="application_profiles"
android:layout="@layout/simple_preference_category" android:layout="@layout/simple_preference_category"
android:selectable="false" android:title="@string/application_profiles">
android:title="@string/application_profiles" />
<Preference <Preference
android:key="browse_map" android:key="browse_map"
android:layout="@layout/preference_with_descr" android:layout="@layout/preference_with_descr"
android:summary="@string/map_look_descr" android:summary="@string/map_look_descr"
android:title="@string/rendering_value_browse_map_name" android:title="@string/rendering_value_browse_map_name"
tools:icon="@drawable/ic_world_globe_dark" /> tools:icon="@drawable/ic_world_globe_dark" />
<Preference <Preference
android:key="configure_profile" android:key="configure_profile"
android:layout="@layout/preference_with_descr" android:layout="@layout/preference_with_descr"
android:title="@string/configure_profile" android:title="@string/configure_profile"
app:fragment="net.osmand.plus.settings.ConfigureProfileFragment" app:fragment="net.osmand.plus.settings.ConfigureProfileFragment"
tools:icon="@drawable/ic_action_car_dark" /> tools:icon="@drawable/ic_action_car_dark" />
<Preference <Preference
android:key="manage_profiles" android:key="manage_profiles"
android:layout="@layout/preference_with_descr" android:layout="@layout/preference_with_descr"
android:summary="@string/manage_profiles_descr" android:summary="@string/manage_profiles_descr"
android:title="@string/manage_profiles" android:title="@string/manage_profiles"
app:fragment="net.osmand.plus.settings.profiles.SettingsProfileFragment" tools:icon="@drawable/ic_action_manage_profiles" />
tools:icon="@drawable/ic_action_manage_profiles" />
</PreferenceScreen> </PreferenceCategory>
</PreferenceScreen>

View file

@ -3,21 +3,21 @@
<SwitchPreference <SwitchPreference
android:key="turn_screen_on" android:key="turn_screen_on"
android:title="@string/shared_string_on" /> android:layout="@layout/preference_top_switch" />
<Preference <Preference
android:key="turn_screen_on_descr" android:key="turn_screen_on_info"
android:layout="@layout/preference_info"
android:selectable="false" android:selectable="false"
android:summary="@string/wake_on_voice_descr" /> android:title="@string/turn_screen_on_info" />
<net.osmand.plus.views.ListIntPreference <net.osmand.plus.settings.preferences.ListPreferenceEx
android:key="turn_screen_on_time_int" android:key="turn_screen_on_time_int"
android:summary="@string/turn_screen_on_time_descr" android:title="@string/wake_time" />
android:title="@string/shared_string_time" />
<SwitchPreference <net.osmand.plus.settings.preferences.SwitchPreferenceEx
android:key="turn_screen_on_sensor" android:key="turn_screen_on_sensor"
android:summary="@string/turn_screen_on_sensor_descr" android:layout="@layout/preference_dialog_and_switch"
android:title="@string/turn_screen_on_sensor" /> android:title="@string/turn_screen_on_sensor" />
</PreferenceScreen> </PreferenceScreen>

View file

@ -1,9 +1,11 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<Preference <Preference
android:key="default_speed" android:key="vehicle_parameters_info"
android:summary="@string/default_speed_setting_descr" android:layout="@layout/preference_info"
android:title="@string/default_speed_setting_title" /> android:selectable="false"
tools:title="@string/vehicle_parameters_info" />
</PreferenceScreen> </PreferenceScreen>

View file

@ -4,74 +4,85 @@
<SwitchPreference <SwitchPreference
android:key="speak_routing_alarms" android:key="speak_routing_alarms"
android:title="@string/shared_string_on" /> android:layout="@layout/preference_top_switch"
tools:summary="@string/shared_string_on" />
<Preference <Preference
android:key="voice_announces_info" android:key="voice_announces_info"
android:selectable="false" android:selectable="false"
android:persistent="false"
android:summary="@string/voice_announces_info" android:summary="@string/voice_announces_info"
tools:icon="@drawable/ic_action_info_dark" /> tools:icon="@drawable/ic_action_info_dark" />
<SwitchPreference <SwitchPreference
android:key="speak_street_names" android:key="speak_street_names"
android:layout="@layout/preference_switch"
android:title="@string/speak_street_names" /> android:title="@string/speak_street_names" />
<SwitchPreference <SwitchPreference
android:key="speak_traffic_warnings" android:key="speak_traffic_warnings"
android:layout="@layout/preference_switch"
android:title="@string/speak_traffic_warnings" /> android:title="@string/speak_traffic_warnings" />
<SwitchPreference <SwitchPreference
android:key="speak_pedestrian" android:key="speak_pedestrian"
android:layout="@layout/preference_switch"
android:title="@string/speak_pedestrian" /> android:title="@string/speak_pedestrian" />
<SwitchPreference <SwitchPreference
android:key="speak_speed_limit" android:key="speak_speed_limit"
android:layout="@layout/preference_switch"
android:title="@string/speak_speed_limit" /> android:title="@string/speak_speed_limit" />
<net.osmand.plus.views.ListFloatPreference <net.osmand.plus.settings.preferences.ListPreferenceEx
android:key="speed_limit_exceed" android:key="speed_limit_exceed"
android:summary="@string/speed_limit_exceed_message" android:layout="@layout/preference_with_descr"
android:title="@string/speed_limit_exceed" /> android:title="@string/speed_limit_exceed" />
<SwitchPreference <SwitchPreference
android:key="speak_cameras" android:key="speak_cameras"
android:layout="@layout/preference_switch"
android:title="@string/speak_cameras" /> android:title="@string/speak_cameras" />
<SwitchPreference <SwitchPreference
android:key="speak_tunnels" android:key="speak_tunnels"
android:layout="@layout/preference_switch"
android:title="@string/show_tunnels" /> android:title="@string/show_tunnels" />
<SwitchPreference <SwitchPreference
android:key="announce_wpt" android:key="announce_wpt"
android:layout="@layout/preference_switch"
android:title="@string/shared_string_gpx_waypoints" /> android:title="@string/shared_string_gpx_waypoints" />
<SwitchPreference <SwitchPreference
android:key="announce_nearby_favorites" android:key="announce_nearby_favorites"
android:layout="@layout/preference_switch"
android:title="@string/speak_favorites" /> android:title="@string/speak_favorites" />
<SwitchPreference <SwitchPreference
android:key="announce_nearby_poi" android:key="announce_nearby_poi"
android:layout="@layout/preference_switch"
android:title="@string/speak_poi" /> android:title="@string/speak_poi" />
<net.osmand.plus.views.ListIntPreference <net.osmand.plus.settings.preferences.ListPreferenceEx
android:key="keep_informing" android:key="keep_informing"
android:summary="@string/keep_informing_descr" android:layout="@layout/preference_with_descr"
android:title="@string/keep_informing" /> android:title="@string/keep_informing" />
<net.osmand.plus.views.ListFloatPreference <net.osmand.plus.settings.preferences.ListPreferenceEx
android:key="arrival_distance_factor" android:key="arrival_distance_factor"
android:summary="@string/arrival_distance_descr" android:layout="@layout/preference_with_descr"
android:title="@string/arrival_distance" /> android:title="@string/arrival_distance" />
<Preference <PreferenceCategory
android:key="language_and_output" android:key="language_and_output"
android:layout="@layout/simple_preference_category" android:layout="@layout/simple_preference_category"
android:selectable="false"
android:title="@string/language_and_output" /> android:title="@string/language_and_output" />
<ListPreference <net.osmand.plus.settings.preferences.ListPreferenceEx
android:key="voice_provider" android:key="voice_provider"
android:summary="@string/voice_provider_descr" android:layout="@layout/preference_with_descr"
android:title="@string/voice_provider" /> android:title="@string/voice_provider"
tools:icon="@drawable/ic_action_volume_up"/>
</PreferenceScreen> </PreferenceScreen>

View file

@ -377,7 +377,7 @@ public class OsmandAidlApi {
} }
private void registerReceiver(BroadcastReceiver rec, MapActivity ma, private void registerReceiver(BroadcastReceiver rec, MapActivity ma,
String filter) { String filter) {
receivers.put(filter, rec); receivers.put(filter, rec);
ma.registerReceiver(rec, new IntentFilter(filter)); ma.registerReceiver(rec, new IntentFilter(filter));
} }
@ -1254,7 +1254,7 @@ public class OsmandAidlApi {
@SuppressLint("StaticFieldLeak") @SuppressLint("StaticFieldLeak")
private void finishGpxImport(boolean destinationExists, File destination, String color, boolean show) { private void finishGpxImport(boolean destinationExists, File destination, String color, boolean show) {
int col = ConfigureMapMenu.GpxAppearanceAdapter.parseTrackColor( int col = ConfigureMapMenu.GpxAppearanceAdapter.parseTrackColor(
app.getRendererRegistry().getCurrentSelectedRenderer(), color); app.getRendererRegistry().getCurrentSelectedRenderer(), color);
if (!destinationExists) { if (!destinationExists) {
GpxDataItem gpxDataItem = new GpxDataItem(destination, col); GpxDataItem gpxDataItem = new GpxDataItem(destination, col);
gpxDataItem.setApiImported(true); gpxDataItem.setApiImported(true);
@ -1472,19 +1472,19 @@ public class OsmandAidlApi {
List<GpxDataItem> gpxDataItems = app.getGpxDatabase().getItems(); List<GpxDataItem> gpxDataItems = app.getGpxDatabase().getItems();
for (GpxDataItem dataItem : gpxDataItems) { for (GpxDataItem dataItem : gpxDataItems) {
//if (dataItem.isApiImported()) { //if (dataItem.isApiImported()) {
File file = dataItem.getFile(); File file = dataItem.getFile();
if (file.exists()) { if (file.exists()) {
String fileName = file.getName(); String fileName = file.getName();
boolean active = app.getSelectedGpxHelper().getSelectedFileByPath(file.getAbsolutePath()) != null; boolean active = app.getSelectedGpxHelper().getSelectedFileByPath(file.getAbsolutePath()) != null;
long modifiedTime = dataItem.getFileLastModifiedTime(); long modifiedTime = dataItem.getFileLastModifiedTime();
long fileSize = file.length(); long fileSize = file.length();
AGpxFileDetails details = null; AGpxFileDetails details = null;
GPXTrackAnalysis analysis = dataItem.getAnalysis(); GPXTrackAnalysis analysis = dataItem.getAnalysis();
if (analysis != null) { if (analysis != null) {
details = createGpxFileDetails(analysis); details = createGpxFileDetails(analysis);
}
files.add(new AGpxFile(fileName, modifiedTime, fileSize, active, details));
} }
files.add(new AGpxFile(fileName, modifiedTime, fileSize, active, details));
}
//} //}
} }
return true; return true;
@ -1661,8 +1661,8 @@ public class OsmandAidlApi {
} }
boolean navigate(String startName, double startLat, double startLon, boolean navigate(String startName, double startLat, double startLon,
String destName, double destLat, double destLon, String destName, double destLat, double destLon,
String profile, boolean force) { String profile, boolean force) {
Intent intent = new Intent(); Intent intent = new Intent();
intent.setAction(AIDL_NAVIGATE); intent.setAction(AIDL_NAVIGATE);
intent.putExtra(AIDL_START_NAME, startName); intent.putExtra(AIDL_START_NAME, startName);
@ -1678,8 +1678,8 @@ public class OsmandAidlApi {
} }
boolean navigateSearch(String startName, double startLat, double startLon, boolean navigateSearch(String startName, double startLat, double startLon,
String searchQuery, double searchLat, double searchLon, String searchQuery, double searchLat, double searchLon,
String profile, boolean force) { String profile, boolean force) {
Intent intent = new Intent(); Intent intent = new Intent();
intent.setAction(AIDL_NAVIGATE_SEARCH); intent.setAction(AIDL_NAVIGATE_SEARCH);
intent.putExtra(AIDL_START_NAME, startName); intent.putExtra(AIDL_START_NAME, startName);
@ -1740,7 +1740,7 @@ public class OsmandAidlApi {
} }
boolean search(final String searchQuery, final int searchType, final double latitude, final double longitude, boolean search(final String searchQuery, final int searchType, final double latitude, final double longitude,
final int radiusLevel, final int totalLimit, final SearchCompleteCallback callback) { final int radiusLevel, final int totalLimit, final SearchCompleteCallback callback) {
if (Algorithms.isEmpty(searchQuery) || latitude == 0 || longitude == 0 || callback == null) { if (Algorithms.isEmpty(searchQuery) || latitude == 0 || longitude == 0 || callback == null) {
return false; return false;
} }
@ -1762,7 +1762,7 @@ public class OsmandAidlApi {
} }
boolean registerForOsmandInitialization(final OsmandAppInitCallback callback) boolean registerForOsmandInitialization(final OsmandAppInitCallback callback)
throws RemoteException { throws RemoteException {
if (app.isApplicationInitializing()) { if (app.isApplicationInitializing()) {
app.getAppInitializer().addListener(new AppInitializeListener() { app.getAppInitializer().addListener(new AppInitializeListener() {
@Override @Override
@ -2090,7 +2090,7 @@ public class OsmandAidlApi {
} }
boolean getBitmapForGpx(final Uri gpxUri, final float density, final int widthPixels, boolean getBitmapForGpx(final Uri gpxUri, final float density, final int widthPixels,
final int heightPixels, final int color, final GpxBitmapCreatedCallback callback) { final int heightPixels, final int color, final GpxBitmapCreatedCallback callback) {
if (gpxUri == null || callback == null) { if (gpxUri == null || callback == null) {
return false; return false;
} }

View file

@ -16,8 +16,10 @@ import android.support.annotation.DrawableRes;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.annotation.StringRes; import android.support.annotation.StringRes;
import android.support.v4.util.Pair; import android.support.v4.util.Pair;
import android.support.v7.preference.PreferenceDataStore;
import net.osmand.IndexConstants; import net.osmand.IndexConstants;
import net.osmand.PlatformUtil;
import net.osmand.StateChangedListener; import net.osmand.StateChangedListener;
import net.osmand.ValueHolder; import net.osmand.ValueHolder;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
@ -38,6 +40,8 @@ import net.osmand.plus.render.RendererRegistry;
import net.osmand.render.RenderingRulesStorage; import net.osmand.render.RenderingRulesStorage;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
@ -128,6 +132,7 @@ public class OsmandSettings {
/// Settings variables /// Settings variables
private final OsmandApplication ctx; private final OsmandApplication ctx;
private PreferencesDataStore dataStore;
private SettingsAPI settingsAPI; private SettingsAPI settingsAPI;
private Object globalPreferences; private Object globalPreferences;
private Object defaultProfilePreferences; private Object defaultProfilePreferences;
@ -144,6 +149,7 @@ public class OsmandSettings {
protected OsmandSettings(OsmandApplication clientContext, SettingsAPI settinsAPI) { protected OsmandSettings(OsmandApplication clientContext, SettingsAPI settinsAPI) {
ctx = clientContext; ctx = clientContext;
this.settingsAPI = settinsAPI; this.settingsAPI = settinsAPI;
dataStore = new PreferencesDataStore();
initPrefs(); initPrefs();
} }
@ -182,6 +188,10 @@ public class OsmandSettings {
return settingsAPI; return settingsAPI;
} }
public PreferencesDataStore getDataStore() {
return dataStore;
}
public static String getSharedPreferencesName(ApplicationMode mode) { public static String getSharedPreferencesName(ApplicationMode mode) {
String sharedPreferencesName = !Algorithms.isEmpty(CUSTOM_SHARED_PREFERENCES_NAME) ? CUSTOM_SHARED_PREFERENCES_NAME : SHARED_PREFERENCES_NAME; String sharedPreferencesName = !Algorithms.isEmpty(CUSTOM_SHARED_PREFERENCES_NAME) ? CUSTOM_SHARED_PREFERENCES_NAME : SHARED_PREFERENCES_NAME;
if (mode == null) { if (mode == null) {
@ -203,6 +213,10 @@ public class OsmandSettings {
return settingsAPI.getPreferenceObject(getSharedPreferencesName(mode)); return settingsAPI.getPreferenceObject(getSharedPreferencesName(mode));
} }
public OsmandPreference getPreference(String key) {
return registeredPreferences.get(key);
}
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public boolean setPreference(String key, Object value) { public boolean setPreference(String key, Object value) {
OsmandPreference<?> preference = registeredPreferences.get(key); OsmandPreference<?> preference = registeredPreferences.get(key);
@ -224,31 +238,30 @@ public class OsmandSettings {
DEFAULT_APPLICATION_MODE.set(appMode); DEFAULT_APPLICATION_MODE.set(appMode);
return true; return true;
} }
} } else if (value instanceof ApplicationMode) {
} else if (preference == METRIC_SYSTEM) { DEFAULT_APPLICATION_MODE.set((ApplicationMode) value);
if (value instanceof String) {
String metricSystemName = (String) value;
MetricsConstants metricSystem;
try {
metricSystem = MetricsConstants.valueOf(metricSystemName);
} catch (IllegalArgumentException e) {
return false;
}
METRIC_SYSTEM.set(metricSystem);
return true; return true;
} }
} else if (preference == SPEED_SYSTEM) { } else if (preference == METRIC_SYSTEM && value instanceof String) {
if (value instanceof String) { String metricSystemName = (String) value;
String speedSystemName = (String) value; MetricsConstants metricSystem;
SpeedConstants speedSystem; try {
try { metricSystem = MetricsConstants.valueOf(metricSystemName);
speedSystem = SpeedConstants.valueOf(speedSystemName); } catch (IllegalArgumentException e) {
} catch (IllegalArgumentException e) { return false;
return false;
}
SPEED_SYSTEM.set(speedSystem);
return true;
} }
METRIC_SYSTEM.set(metricSystem);
return true;
} else if (preference == SPEED_SYSTEM && value instanceof String) {
String speedSystemName = (String) value;
SpeedConstants speedSystem;
try {
speedSystem = SpeedConstants.valueOf(speedSystemName);
} catch (IllegalArgumentException e) {
return false;
}
SPEED_SYSTEM.set(speedSystem);
return true;
} else if (preference instanceof BooleanPreference) { } else if (preference instanceof BooleanPreference) {
if (value instanceof Boolean) { if (value instanceof Boolean) {
((BooleanPreference) preference).set((Boolean) value); ((BooleanPreference) preference).set((Boolean) value);
@ -276,16 +289,10 @@ public class OsmandSettings {
} }
} else if (preference instanceof EnumIntPreference) { } else if (preference instanceof EnumIntPreference) {
EnumIntPreference enumPref = (EnumIntPreference) preference; EnumIntPreference enumPref = (EnumIntPreference) preference;
if (value instanceof String) { if (value instanceof Integer) {
String name = (String) value; int newVal = (Integer) value;
Enum enumValue = null; if (enumPref.values.length > newVal) {
for (int i = 0; i < enumPref.values.length; i++) { Enum enumValue = enumPref.values[newVal];
if (name.equals(enumPref.values[i].name())) {
enumValue = enumPref.values[i];
break;
}
}
if (enumValue != null) {
return enumPref.set(enumValue); return enumPref.set(enumValue);
} }
return false; return false;
@ -544,7 +551,7 @@ public class OsmandSettings {
} }
private class BooleanPreference extends CommonPreference<Boolean> { public class BooleanPreference extends CommonPreference<Boolean> {
private BooleanPreference(String id, boolean defaultValue) { private BooleanPreference(String id, boolean defaultValue) {
@ -640,7 +647,7 @@ public class OsmandSettings {
} }
private class StringPreference extends CommonPreference<String> { public class StringPreference extends CommonPreference<String> {
private StringPreference(String id, String defaultValue) { private StringPreference(String id, String defaultValue) {
super(id, defaultValue); super(id, defaultValue);
@ -958,8 +965,7 @@ public class OsmandSettings {
return DrivingRegion.EUROPE_ASIA; return DrivingRegion.EUROPE_ASIA;
} }
; }.makeProfile().cache();
}.makeGlobal().cache();
public final CommonPreference<Boolean> METRIC_SYSTEM_CHANGED_MANUALLY = new BooleanPreference("metric_system_changed_manually", false).makeGlobal(); public final CommonPreference<Boolean> METRIC_SYSTEM_CHANGED_MANUALLY = new BooleanPreference("metric_system_changed_manually", false).makeGlobal();
@ -971,7 +977,6 @@ public class OsmandSettings {
return DRIVING_REGION.get().defMetrics; return DRIVING_REGION.get().defMetrics;
} }
;
}.makeProfile(); }.makeProfile();
//public final OsmandPreference<Integer> COORDINATES_FORMAT = new IntPreference("coordinates_format", PointDescription.FORMAT_DEGREES).makeGlobal(); //public final OsmandPreference<Integer> COORDINATES_FORMAT = new IntPreference("coordinates_format", PointDescription.FORMAT_DEGREES).makeGlobal();
@ -982,8 +987,7 @@ public class OsmandSettings {
protected AngularConstants getValue(Object prefs, AngularConstants defaultValue) { protected AngularConstants getValue(Object prefs, AngularConstants defaultValue) {
return super.getValue(prefs, defaultValue); return super.getValue(prefs, defaultValue);
} }
}.makeGlobal(); }.makeProfile();
public final OsmandPreference<SpeedConstants> SPEED_SYSTEM = new EnumIntPreference<SpeedConstants>( public final OsmandPreference<SpeedConstants> SPEED_SYSTEM = new EnumIntPreference<SpeedConstants>(
@ -1082,13 +1086,15 @@ public class OsmandSettings {
public final OsmandPreference<Boolean> DO_NOT_SHOW_STARTUP_MESSAGES = new BooleanPreference("do_not_show_startup_messages", false).makeGlobal().cache(); public final OsmandPreference<Boolean> DO_NOT_SHOW_STARTUP_MESSAGES = new BooleanPreference("do_not_show_startup_messages", false).makeGlobal().cache();
public final OsmandPreference<Boolean> DO_NOT_USE_ANIMATIONS = new BooleanPreference("do_not_use_animations", false).makeProfile().cache(); public final OsmandPreference<Boolean> DO_NOT_USE_ANIMATIONS = new BooleanPreference("do_not_use_animations", false).makeProfile().cache();
public final OsmandPreference<Boolean> SEND_ANONYMOUS_DATA = new BooleanPreference("send_anonymous_data", false).makeGlobal().cache();
public final OsmandPreference<Boolean> SEND_ANONYMOUS_MAP_DOWNLOADS_DATA = new BooleanPreference("send_anonymous_map_downloads_data", false).makeGlobal().cache(); public final OsmandPreference<Boolean> SEND_ANONYMOUS_MAP_DOWNLOADS_DATA = new BooleanPreference("send_anonymous_map_downloads_data", false).makeGlobal().cache();
public final OsmandPreference<Boolean> SEND_ANONYMOUS_APP_USAGE_DATA = new BooleanPreference("send_anonymous_app_usage_data", false).makeGlobal().cache(); public final OsmandPreference<Boolean> SEND_ANONYMOUS_APP_USAGE_DATA = new BooleanPreference("send_anonymous_app_usage_data", false).makeGlobal().cache();
public final OsmandPreference<Boolean> SEND_ANONYMOUS_DATA_REQUEST_PROCESSED = new BooleanPreference("send_anonymous_data_request_processed", false).makeGlobal().cache(); public final OsmandPreference<Boolean> SEND_ANONYMOUS_DATA_REQUEST_PROCESSED = new BooleanPreference("send_anonymous_data_request_processed", false).makeGlobal().cache();
public final OsmandPreference<Integer> SEND_ANONYMOUS_DATA_REQUESTS_COUNT = new IntPreference("send_anonymous_data_requests_count", 0).makeGlobal().cache(); public final OsmandPreference<Integer> SEND_ANONYMOUS_DATA_REQUESTS_COUNT = new IntPreference("send_anonymous_data_requests_count", 0).makeGlobal().cache();
public final OsmandPreference<Integer> SEND_ANONYMOUS_DATA_LAST_REQUEST_NS = new IntPreference("send_anonymous_data_last_request_ns", -1).makeGlobal().cache(); public final OsmandPreference<Integer> SEND_ANONYMOUS_DATA_LAST_REQUEST_NS = new IntPreference("send_anonymous_data_last_request_ns", -1).makeGlobal().cache();
public final OsmandPreference<Boolean> MAP_EMPTY_STATE_ALLOWED = new BooleanPreference("map_empty_state_allowed", true).makeGlobal().cache(); public final OsmandPreference<Boolean> MAP_EMPTY_STATE_ALLOWED = new BooleanPreference("map_empty_state_allowed", true).makeProfile().cache();
public final CommonPreference<Float> TEXT_SCALE = new FloatPreference("text_scale", 1f).makeProfile().cache(); public final CommonPreference<Float> TEXT_SCALE = new FloatPreference("text_scale", 1f).makeProfile().cache();
@ -1415,7 +1421,7 @@ public class OsmandSettings {
KEEP_INFORMING.setModeDefaultValue(ApplicationMode.BICYCLE, 0); KEEP_INFORMING.setModeDefaultValue(ApplicationMode.BICYCLE, 0);
KEEP_INFORMING.setModeDefaultValue(ApplicationMode.PEDESTRIAN, 0); KEEP_INFORMING.setModeDefaultValue(ApplicationMode.PEDESTRIAN, 0);
} }
public final CommonPreference<Boolean> TURN_SCREEN_ON = new BooleanPreference("turn_screen_on", false).makeProfile(); public final CommonPreference<Boolean> TURN_SCREEN_ON = new BooleanPreference("turn_screen_on", false).makeProfile();
public final CommonPreference<Integer> TURN_SCREEN_ON_TIME_INT = new IntPreference("turn_screen_on_time_int", 0).makeProfile(); public final CommonPreference<Integer> TURN_SCREEN_ON_TIME_INT = new IntPreference("turn_screen_on_time_int", 0).makeProfile();
@ -2722,8 +2728,7 @@ public class OsmandSettings {
// this value string is synchronized with settings_pref.xml preference name // this value string is synchronized with settings_pref.xml preference name
public final OsmandPreference<String> CONTRIBUTION_INSTALL_APP_DATE = new StringPreference("CONTRIBUTION_INSTALL_APP_DATE", null).makeGlobal(); public final OsmandPreference<String> CONTRIBUTION_INSTALL_APP_DATE = new StringPreference("CONTRIBUTION_INSTALL_APP_DATE", null).makeGlobal();
public final OsmandPreference<Integer> COORDINATES_FORMAT = new IntPreference("coordinates_format", PointDescription.FORMAT_DEGREES).makeProfile();
public final OsmandPreference<Integer> COORDINATES_FORMAT = new IntPreference("coordinates_format", PointDescription.FORMAT_DEGREES).makeGlobal();
public final OsmandPreference<Boolean> FOLLOW_THE_ROUTE = new BooleanPreference("follow_to_route", false).makeGlobal(); public final OsmandPreference<Boolean> FOLLOW_THE_ROUTE = new BooleanPreference("follow_to_route", false).makeGlobal();
public final OsmandPreference<String> FOLLOW_THE_GPX_ROUTE = new StringPreference("follow_gpx", null).makeGlobal(); public final OsmandPreference<String> FOLLOW_THE_GPX_ROUTE = new StringPreference("follow_gpx", null).makeGlobal();
@ -3084,4 +3089,114 @@ public class OsmandSettings {
} }
} }
public class PreferencesDataStore extends PreferenceDataStore {
private final Log log = PlatformUtil.getLog(PreferencesDataStore.class);
@Override
public void putString(String key, @Nullable String value) {
setPreference(key, value);
log.debug("putString key " + key + " value " + value);
}
@Override
public void putStringSet(String key, @Nullable Set<String> values) {
setPreference(key, values);
log.debug("putStringSet key " + key + " value " + values);
}
@Override
public void putInt(String key, int value) {
setPreference(key, value);
log.debug("putInt key " + key + " value " + value);
}
@Override
public void putLong(String key, long value) {
setPreference(key, value);
log.debug("putLong key " + key + " value " + value);
}
@Override
public void putFloat(String key, float value) {
setPreference(key, value);
log.debug("putFloat key " + key + " value " + value);
}
@Override
public void putBoolean(String key, boolean value) {
setPreference(key, value);
log.debug("putBoolean key " + key + " value " + value);
}
public void putValue(String key, Object value) {
setPreference(key, value);
log.debug("putValue key " + key + " value " + value);
}
@Nullable
@Override
public String getString(String key, @Nullable String defValue) {
OsmandPreference preference = getPreference(key);
if (preference instanceof StringPreference) {
return ((StringPreference) preference).get();
} else {
Object value = preference.get();
if (value != null) {
return value.toString();
}
}
return defValue;
}
@Nullable
@Override
public Set<String> getStringSet(String key, @Nullable Set<String> defValues) {
return super.getStringSet(key, defValues);
}
@Override
public int getInt(String key, int defValue) {
OsmandPreference preference = getPreference(key);
if (preference instanceof IntPreference) {
return ((IntPreference) preference).get();
}
return defValue;
}
@Override
public long getLong(String key, long defValue) {
OsmandPreference preference = getPreference(key);
if (preference instanceof LongPreference) {
return ((LongPreference) preference).get();
}
return defValue;
}
@Override
public float getFloat(String key, float defValue) {
OsmandPreference preference = getPreference(key);
if (preference instanceof FloatPreference) {
return ((FloatPreference) preference).get();
}
return defValue;
}
@Override
public boolean getBoolean(String key, boolean defValue) {
OsmandPreference preference = getPreference(key);
if (preference instanceof BooleanPreference) {
return ((BooleanPreference) preference).get();
}
return defValue;
}
public Object getValue(String key, Object defValue) {
OsmandPreference preference = getPreference(key);
if (preference != null) {
return preference.get();
}
return defValue;
}
}
} }

View file

@ -113,6 +113,7 @@ import net.osmand.plus.mapmarkers.PlanRouteFragment;
import net.osmand.plus.measurementtool.MeasurementEditingContext; import net.osmand.plus.measurementtool.MeasurementEditingContext;
import net.osmand.plus.measurementtool.MeasurementToolFragment; import net.osmand.plus.measurementtool.MeasurementToolFragment;
import net.osmand.plus.measurementtool.NewGpxData; import net.osmand.plus.measurementtool.NewGpxData;
import net.osmand.plus.profiles.EditProfileFragment;
import net.osmand.plus.render.RendererRegistry; import net.osmand.plus.render.RendererRegistry;
import net.osmand.plus.resources.ResourceManager; import net.osmand.plus.resources.ResourceManager;
import net.osmand.plus.routepreparationmenu.ChooseRouteFragment; import net.osmand.plus.routepreparationmenu.ChooseRouteFragment;
@ -127,7 +128,6 @@ import net.osmand.plus.search.QuickSearchDialogFragment.QuickSearchTab;
import net.osmand.plus.search.QuickSearchDialogFragment.QuickSearchType; import net.osmand.plus.search.QuickSearchDialogFragment.QuickSearchType;
import net.osmand.plus.settings.BaseSettingsFragment; import net.osmand.plus.settings.BaseSettingsFragment;
import net.osmand.plus.settings.SettingsMainFragment; import net.osmand.plus.settings.SettingsMainFragment;
import net.osmand.plus.settings.profiles.EditProfileFragment;
import net.osmand.plus.views.AddGpxPointBottomSheetHelper.NewGpxPoint; import net.osmand.plus.views.AddGpxPointBottomSheetHelper.NewGpxPoint;
import net.osmand.plus.views.AnimateDraggingMapThread; import net.osmand.plus.views.AnimateDraggingMapThread;
import net.osmand.plus.views.MapControlsLayer; import net.osmand.plus.views.MapControlsLayer;
@ -160,8 +160,8 @@ import java.util.concurrent.Executors;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import static net.osmand.plus.settings.profiles.SettingsProfileFragment.IS_USER_PROFILE; import static net.osmand.plus.profiles.SettingsProfileFragment.IS_USER_PROFILE;
import static net.osmand.plus.settings.profiles.SettingsProfileFragment.PROFILE_STRING_KEY; import static net.osmand.plus.profiles.SettingsProfileFragment.PROFILE_STRING_KEY;
public class MapActivity extends OsmandActionBarActivity implements DownloadEvents, public class MapActivity extends OsmandActionBarActivity implements DownloadEvents,
OnRequestPermissionsResultCallback, IRouteInformationListener, AMapPointUpdateListener, OnRequestPermissionsResultCallback, IRouteInformationListener, AMapPointUpdateListener,
@ -231,7 +231,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
private boolean stopped = true; private boolean stopped = true;
private ExecutorService singleThreadExecutor = Executors.newSingleThreadExecutor(); private ExecutorService singleThreadExecutor = Executors.newSingleThreadExecutor();
private LockHelper lockHelper; private LockHelper lockHelper;
@Override @Override
@ -351,7 +351,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
registerReceiver(screenOffReceiver, filter); registerReceiver(screenOffReceiver, filter);
app.getAidlApi().onCreateMapActivity(this); app.getAidlApi().onCreateMapActivity(this);
lockHelper.setLockUIAdapter(this); lockHelper.setLockUIAdapter(this);
mIsDestroyed = false; mIsDestroyed = false;
@ -1943,7 +1943,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
if (caller instanceof BaseSettingsFragment) { if (caller instanceof BaseSettingsFragment) {
BaseSettingsFragment baseFragment = (BaseSettingsFragment) caller; BaseSettingsFragment baseFragment = (BaseSettingsFragment) caller;
ApplicationMode mode = baseFragment.getSelectedMode(); ApplicationMode mode = baseFragment.getSelectedAppMode();
if (mode != null) { if (mode != null) {
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putString(PROFILE_STRING_KEY, mode.getStringKey()); args.putString(PROFILE_STRING_KEY, mode.getStringKey());
@ -2080,7 +2080,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
} }
public void showQuickSearch(@NonNull ShowQuickSearchMode mode, boolean showCategories, public void showQuickSearch(@NonNull ShowQuickSearchMode mode, boolean showCategories,
@NonNull String searchQuery, @Nullable LatLon searchLocation) { @NonNull String searchQuery, @Nullable LatLon searchLocation) {
if (mode == ShowQuickSearchMode.CURRENT) { if (mode == ShowQuickSearchMode.CURRENT) {
mapContextMenu.close(); mapContextMenu.close();
} else { } else {
@ -2133,7 +2133,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
} }
public void showQuickSearch(@NonNull ShowQuickSearchMode mode, QuickSearchTab showSearchTab, public void showQuickSearch(@NonNull ShowQuickSearchMode mode, QuickSearchTab showSearchTab,
@NonNull String searchQuery, @Nullable LatLon searchLocation) { @NonNull String searchQuery, @Nullable LatLon searchLocation) {
if (mode == ShowQuickSearchMode.CURRENT) { if (mode == ShowQuickSearchMode.CURRENT) {
mapContextMenu.close(); mapContextMenu.close();
} else { } else {

View file

@ -109,7 +109,7 @@ public class MapActivityActions implements DialogProvider {
public static final String KEY_NAME = "name"; public static final String KEY_NAME = "name";
public static final String KEY_ZOOM = "zoom"; public static final String KEY_ZOOM = "zoom";
public static final int REQUEST_LOCATION_FOR_DIRECTIONS_NAVIGATION_PERMISSION = 203; public static final int REQUEST_LOCATION_FOR_DIRECTIONS_NAVIGATION_PERMISSION = 203;
// Constants for determining the order of items in the additional actions context menu // Constants for determining the order of items in the additional actions context menu
@ -144,7 +144,7 @@ public class MapActivityActions implements DialogProvider {
routingHelper = mapActivity.getMyApplication().getRoutingHelper(); routingHelper = mapActivity.getMyApplication().getRoutingHelper();
drawerLogoHeader = new ImageView(mapActivity); drawerLogoHeader = new ImageView(mapActivity);
drawerLogoHeader.setPadding(-AndroidUtils.dpToPx(mapActivity, 8f), AndroidUtils.dpToPx(mapActivity, 16f), 0, drawerLogoHeader.setPadding(-AndroidUtils.dpToPx(mapActivity, 8f), AndroidUtils.dpToPx(mapActivity, 16f), 0,
0); 0);
drawerOsmAndFooter = mapActivity.getLayoutInflater().inflate(R.layout.powered_by_osmand_item, null); drawerOsmAndFooter = mapActivity.getLayoutInflater().inflate(R.layout.powered_by_osmand_item, null);
} }
@ -457,12 +457,12 @@ public class MapActivityActions implements DialogProvider {
} }
public void enterRoutePlanningModeGivenGpx(GPXFile gpxFile, LatLon from, PointDescription fromName, public void enterRoutePlanningModeGivenGpx(GPXFile gpxFile, LatLon from, PointDescription fromName,
boolean useIntermediatePointsByDefault, boolean showMenu) { boolean useIntermediatePointsByDefault, boolean showMenu) {
enterRoutePlanningModeGivenGpx(gpxFile, from, fromName, useIntermediatePointsByDefault, showMenu, MapRouteInfoMenu.DEFAULT_MENU_STATE); enterRoutePlanningModeGivenGpx(gpxFile, from, fromName, useIntermediatePointsByDefault, showMenu, MapRouteInfoMenu.DEFAULT_MENU_STATE);
} }
public void enterRoutePlanningModeGivenGpx(GPXFile gpxFile, LatLon from, PointDescription fromName, public void enterRoutePlanningModeGivenGpx(GPXFile gpxFile, LatLon from, PointDescription fromName,
boolean useIntermediatePointsByDefault, boolean showMenu, int menuState) { boolean useIntermediatePointsByDefault, boolean showMenu, int menuState) {
settings.USE_INTERMEDIATE_POINTS_NAVIGATION.set(useIntermediatePointsByDefault); settings.USE_INTERMEDIATE_POINTS_NAVIGATION.set(useIntermediatePointsByDefault);
OsmandApplication app = mapActivity.getMyApplication(); OsmandApplication app = mapActivity.getMyApplication();
TargetPointsHelper targets = app.getTargetPointsHelper(); TargetPointsHelper targets = app.getTargetPointsHelper();
@ -479,7 +479,7 @@ public class MapActivityActions implements DialogProvider {
targets.setStartPoint(from, false, fromName); targets.setStartPoint(from, false, fromName);
// then set gpx // then set gpx
setGPXRouteParams(gpxFile); setGPXRouteParams(gpxFile);
// then update start and destination point // then update start and destination point
targets.updateRouteAndRefresh(true); targets.updateRouteAndRefresh(true);
mapActivity.getMapViewTrackingUtilities().switchToRoutePlanningMode(); mapActivity.getMapViewTrackingUtilities().switchToRoutePlanningMode();
@ -685,7 +685,7 @@ public class MapActivityActions implements DialogProvider {
} }
}).createItem()); }).createItem());
optionsMenuHelper.addItem(new ItemBuilder().setTitleId(R.string.get_directions, mapActivity) optionsMenuHelper.addItem(new ItemBuilder().setTitleId(R.string.get_directions, mapActivity)
.setId(DRAWER_DIRECTIONS_ID) .setId(DRAWER_DIRECTIONS_ID)
.setIcon(R.drawable.ic_action_gdirections_dark) .setIcon(R.drawable.ic_action_gdirections_dark)
@ -963,24 +963,24 @@ public class MapActivityActions implements DialogProvider {
} }
public void restoreOrReturnDialog(final String packageName) { public void restoreOrReturnDialog(final String packageName) {
AlertDialog.Builder builder = new AlertDialog.Builder(mapActivity); AlertDialog.Builder builder = new AlertDialog.Builder(mapActivity);
builder.setTitle("Restore OsmAnd"); builder.setTitle("Restore OsmAnd");
builder.setMessage("Do you want to Restore OsmAnd or get back to the Client App?"); builder.setMessage("Do you want to Restore OsmAnd or get back to the Client App?");
builder.setPositiveButton("Restore", new DialogInterface.OnClickListener() { builder.setPositiveButton("Restore", new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialogInterface, int i) { public void onClick(DialogInterface dialogInterface, int i) {
restoreOsmand(); restoreOsmand();
} }
}); });
builder.setNeutralButton("Return", new DialogInterface.OnClickListener() { builder.setNeutralButton("Return", new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialogInterface, int i) { public void onClick(DialogInterface dialogInterface, int i) {
executeHeadersIntent(packageName); executeHeadersIntent(packageName);
} }
}); });
builder.setNegativeButton("Cancel", null); builder.setNegativeButton("Cancel", null);
builder.show(); builder.show();
} }
protected void updateDrawerMenu() { protected void updateDrawerMenu() {
boolean nightMode = getMyApplication().getDaynightHelper().isNightModeForMapControls(); boolean nightMode = getMyApplication().getDaynightHelper().isNightModeForMapControls();
@ -1014,17 +1014,17 @@ public class MapActivityActions implements DialogProvider {
boolean hasHeader = menuItemsListView.getHeaderViewsCount() > 0; boolean hasHeader = menuItemsListView.getHeaderViewsCount() > 0;
boolean hasFooter = menuItemsListView.getFooterViewsCount() > 0; boolean hasFooter = menuItemsListView.getFooterViewsCount() > 0;
if (hasHeader && position ==0 || (hasFooter && position== menuItemsListView.getCount() - 1)) { if (hasHeader && position ==0 || (hasFooter && position== menuItemsListView.getCount() - 1)) {
if(navDrawerLogoParams!=null) executeHeadersIntent(navDrawerLogoParams.get(0)); if(navDrawerLogoParams!=null) executeHeadersIntent(navDrawerLogoParams.get(0));
else restoreOsmand(); else restoreOsmand();
} else { } else {
position -= menuItemsListView.getHeaderViewsCount(); position -= menuItemsListView.getHeaderViewsCount();
ContextMenuItem item = contextMenuAdapter.getItem(position); ContextMenuItem item = contextMenuAdapter.getItem(position);
ItemClickListener click = item.getItemClickListener(); ItemClickListener click = item.getItemClickListener();
if (click != null && click.onContextMenuClick(simpleListAdapter, item.getTitleId(), if (click != null && click.onContextMenuClick(simpleListAdapter, item.getTitleId(),
position, false, AndroidUtils.getCenterViewCoordinates(view))) { position, false, AndroidUtils.getCenterViewCoordinates(view))) {
mapActivity.closeDrawer(); mapActivity.closeDrawer();
} }
} }
} }
}); });
@ -1076,7 +1076,7 @@ public class MapActivityActions implements DialogProvider {
private void showReturnConfirmationDialog(String packageName) { private void showReturnConfirmationDialog(String packageName) {
restoreOrReturnDialog(packageName); restoreOrReturnDialog(packageName);
mapActivity.closeDrawer(); mapActivity.closeDrawer();
} }
private void restoreOsmand(){ private void restoreOsmand(){

View file

@ -14,6 +14,7 @@ import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.Version; import net.osmand.plus.Version;
import net.osmand.plus.liveupdates.OsmLiveActivity; import net.osmand.plus.liveupdates.OsmLiveActivity;
import net.osmand.plus.profiles.SettingsProfileActivity;
public class SettingsActivity extends SettingsBaseActivity { public class SettingsActivity extends SettingsBaseActivity {
@ -95,7 +96,7 @@ public class SettingsActivity extends SettingsBaseActivity {
startActivity(new Intent(this, SettingsGeneralActivity.class)); startActivity(new Intent(this, SettingsGeneralActivity.class));
return true; return true;
} else if (preference == profiles){ } else if (preference == profiles){
// startActivity(new Intent(this, SettingsProfileActivity.class)); startActivity(new Intent(this, SettingsProfileActivity.class));
return true; return true;
} else if (preference == routing) { } else if (preference == routing) {
startActivity(new Intent(this, SettingsNavigationActivity.class)); startActivity(new Intent(this, SettingsNavigationActivity.class));

View file

@ -27,8 +27,8 @@ import net.osmand.plus.OsmandSettings;
import net.osmand.plus.OsmandSettings.CommonPreference; import net.osmand.plus.OsmandSettings.CommonPreference;
import net.osmand.plus.OsmandSettings.OsmandPreference; import net.osmand.plus.OsmandSettings.OsmandPreference;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.settings.profiles.AppProfileArrayAdapter; import net.osmand.plus.profiles.AppProfileArrayAdapter;
import net.osmand.plus.settings.profiles.ProfileDataObject; import net.osmand.plus.profiles.ProfileDataObject;
import net.osmand.plus.views.SeekBarPreference; import net.osmand.plus.views.SeekBarPreference;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;

View file

@ -60,7 +60,7 @@ import java.util.List;
public class SettingsGeneralActivity extends SettingsBaseActivity implements OnRequestPermissionsResultCallback { public class SettingsGeneralActivity extends SettingsBaseActivity implements OnRequestPermissionsResultCallback {
private static final String IP_ADDRESS_PATTERN = public static final String IP_ADDRESS_PATTERN =
"^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." + "^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." +
"([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." +
"([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." +

View file

@ -1,6 +1,7 @@
package net.osmand.plus.activities; package net.osmand.plus.activities;
import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener; import android.content.DialogInterface.OnClickListener;
@ -104,7 +105,7 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
} }
private void createUI() { private void createUI() {
addPreferencesFromResource(R.xml.navigation_settings_old); addPreferencesFromResource(R.xml.navigation_settings);
PreferenceScreen screen = getPreferenceScreen(); PreferenceScreen screen = getPreferenceScreen();
RouteService[] vls = RouteService.getAvailableRouters(getMyApplication()); RouteService[] vls = RouteService.getAvailableRouters(getMyApplication());
String[] entries = new String[vls.length]; String[] entries = new String[vls.length];
@ -387,12 +388,12 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
} }
} }
public String getRoutinParameterTitle(Context context, RoutingParameter routingParameter) { public static String getRoutinParameterTitle(Context context, RoutingParameter routingParameter) {
return SettingsBaseActivity.getRoutingStringPropertyName(context, routingParameter.getId(), return SettingsBaseActivity.getRoutingStringPropertyName(context, routingParameter.getId(),
routingParameter.getName()); routingParameter.getName());
} }
public boolean isRoutingParameterSelected(OsmandSettings settings, ApplicationMode am, RoutingParameter routingParameter) { public static boolean isRoutingParameterSelected(OsmandSettings settings, ApplicationMode am, RoutingParameter routingParameter) {
final OsmandSettings.CommonPreference<Boolean> property = final OsmandSettings.CommonPreference<Boolean> property =
settings.getCustomRoutingBooleanProperty(routingParameter.getId(), routingParameter.getDefaultBoolean()); settings.getCustomRoutingBooleanProperty(routingParameter.getId(), routingParameter.getDefaultBoolean());
if(am != null) { if(am != null) {
@ -402,10 +403,9 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
} }
} }
public void setRoutingParameterSelected(OsmandSettings settings, ApplicationMode am, RoutingParameter routingParameter, boolean isChecked) { public static void setRoutingParameterSelected(OsmandSettings settings, ApplicationMode am, String routingParameterId, boolean defaultBoolean, boolean isChecked) {
final OsmandSettings.CommonPreference<Boolean> property = final OsmandSettings.CommonPreference<Boolean> property = settings.getCustomRoutingBooleanProperty(routingParameterId, defaultBoolean);
settings.getCustomRoutingBooleanProperty(routingParameter.getId(), routingParameter.getDefaultBoolean()); if (am != null) {
if(am != null) {
property.setModeValue(am, isChecked); property.setModeValue(am, isChecked);
} else { } else {
property.set(isChecked); property.set(isChecked);
@ -468,7 +468,7 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
vals[i] = SettingsBaseActivity.getRoutingStringPropertyName(this, p.getId(), p.getName()); vals[i] = SettingsBaseActivity.getRoutingStringPropertyName(this, p.getId(), p.getName());
bls[i] = settings.getCustomRoutingBooleanProperty(p.getId(), p.getDefaultBoolean()); bls[i] = settings.getCustomRoutingBooleanProperty(p.getId(), p.getDefaultBoolean());
} }
showBooleanSettings(vals, bls, preference.getTitle()); showBooleanSettings(this, vals, bls, preference.getTitle());
return true; return true;
} else if (preference == autoZoom) { } else if (preference == autoZoom) {
final ApplicationMode am = settings.getApplicationMode(); final ApplicationMode am = settings.getApplicationMode();
@ -597,7 +597,8 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
int position = selectedPosition[0]; int position = selectedPosition[0];
if (position >= 0 && position < reliefFactorParameters.size()) { if (position >= 0 && position < reliefFactorParameters.size()) {
for (int i = 0; i < reliefFactorParameters.size(); i++) { for (int i = 0; i < reliefFactorParameters.size(); i++) {
setRoutingParameterSelected(settings, am, reliefFactorParameters.get(i), i == position); RoutingParameter parameter = reliefFactorParameters.get(i);
setRoutingParameterSelected(settings, am, parameter.getId(), parameter.getDefaultBoolean(), i == position);
} }
//mapActivity.getRoutingHelper().recalculateRouteDueToSettingsChange(); //mapActivity.getRoutingHelper().recalculateRouteDueToSettingsChange();
//updateParameters(); //updateParameters();
@ -609,12 +610,12 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
builder.create().show(); builder.create().show();
return true; return true;
} else if (preference == showAlarms) { } else if (preference == showAlarms) {
showBooleanSettings(new String[] { getString(R.string.show_traffic_warnings), getString(R.string.show_pedestrian_warnings), showBooleanSettings(this, new String[] { getString(R.string.show_traffic_warnings), getString(R.string.show_pedestrian_warnings),
getString(R.string.show_cameras), getString(R.string.show_lanes), getString(R.string.show_tunnels) }, new OsmandPreference[] { settings.SHOW_TRAFFIC_WARNINGS, getString(R.string.show_cameras), getString(R.string.show_lanes), getString(R.string.show_tunnels) }, new OsmandPreference[] { settings.SHOW_TRAFFIC_WARNINGS,
settings.SHOW_PEDESTRIAN, settings.SHOW_CAMERAS, settings.SHOW_LANES, settings.SHOW_TUNNELS }, preference.getTitle()); settings.SHOW_PEDESTRIAN, settings.SHOW_CAMERAS, settings.SHOW_LANES, settings.SHOW_TUNNELS }, preference.getTitle());
return true; return true;
} else if (preference == speakAlarms) { } else if (preference == speakAlarms) {
AlertDialog dlg = showBooleanSettings(new String[] { getString(R.string.speak_street_names), AlertDialog dlg = showBooleanSettings(this, new String[] { getString(R.string.speak_street_names),
getString(R.string.speak_traffic_warnings), getString(R.string.speak_pedestrian), getString(R.string.speak_traffic_warnings), getString(R.string.speak_pedestrian),
getString(R.string.speak_speed_limit), getString(R.string.speak_cameras), getString(R.string.show_tunnels), getString(R.string.speak_speed_limit), getString(R.string.speak_cameras), getString(R.string.show_tunnels),
getString(R.string.shared_string_gpx_waypoints), getString(R.string.speak_favorites), getString(R.string.shared_string_gpx_waypoints), getString(R.string.speak_favorites),
@ -644,7 +645,7 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
if (!initialSpeedCam) { if (!initialSpeedCam) {
if (settings.SPEAK_SPEED_CAMERA.get()) { if (settings.SPEAK_SPEED_CAMERA.get()) {
settings.SPEAK_SPEED_CAMERA.set(false); settings.SPEAK_SPEED_CAMERA.set(false);
confirmSpeedCamerasDlg(); confirmSpeedCamerasDlg(SettingsNavigationActivity.this, settings);
} }
} }
@ -653,13 +654,13 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
}); });
return true; return true;
} else if (preference == defaultSpeed) { } else if (preference == defaultSpeed) {
showSeekbarSettingsDialog(); showSeekbarSettingsDialog(this);
} }
return false; return false;
} }
private void confirmSpeedCamerasDlg() { public static void confirmSpeedCamerasDlg(Activity activity, final OsmandSettings settings) {
AlertDialog.Builder bld = new AlertDialog.Builder(this); AlertDialog.Builder bld = new AlertDialog.Builder(activity);
bld.setMessage(R.string.confirm_usage_speed_cameras); bld.setMessage(R.string.confirm_usage_speed_cameras);
bld.setPositiveButton(R.string.shared_string_yes, new OnClickListener() { bld.setPositiveButton(R.string.shared_string_yes, new OnClickListener() {
@ -672,8 +673,8 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
bld.show(); bld.show();
} }
public AlertDialog showBooleanSettings(String[] vals, final OsmandPreference<Boolean>[] prefs, final CharSequence title) { public static AlertDialog showBooleanSettings(Context ctx, String[] vals, final OsmandPreference<Boolean>[] prefs, final CharSequence title) {
AlertDialog.Builder bld = new AlertDialog.Builder(this); AlertDialog.Builder bld = new AlertDialog.Builder(ctx);
boolean[] checkedItems = new boolean[prefs.length]; boolean[] checkedItems = new boolean[prefs.length];
for (int i = 0; i < prefs.length; i++) { for (int i = 0; i < prefs.length; i++) {
checkedItems[i] = prefs[i].get(); checkedItems[i] = prefs[i].get();
@ -707,11 +708,17 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
return bld.show(); return bld.show();
} }
private void showSeekbarSettingsDialog() { public static void showSeekbarSettingsDialog(Activity activity) {
if (activity == null) {
return;
}
final OsmandApplication app = (OsmandApplication) activity.getApplication();
final OsmandSettings settings = app.getSettings();
final ApplicationMode mode = settings.getApplicationMode(); final ApplicationMode mode = settings.getApplicationMode();
GeneralRouter router = getRouter(getMyApplication().getRoutingConfig(), mode); GeneralRouter router = getRouter(app.getRoutingConfig(), mode);
SpeedConstants units = settings.SPEED_SYSTEM.get(); SpeedConstants units = settings.SPEED_SYSTEM.get();
String speedUnits = units.toShortString(this); String speedUnits = units.toShortString(activity);
final float[] ratio = new float[1]; final float[] ratio = new float[1];
switch (units) { switch (units) {
case MILES_PER_HOUR: case MILES_PER_HOUR:
@ -722,7 +729,7 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
break; break;
case MINUTES_PER_KILOMETER: case MINUTES_PER_KILOMETER:
ratio[0] = 3600 / OsmAndFormatter.METERS_IN_KILOMETER; ratio[0] = 3600 / OsmAndFormatter.METERS_IN_KILOMETER;
speedUnits = getString(R.string.km_h); speedUnits = activity.getString(R.string.km_h);
break; break;
case NAUTICALMILES_PER_HOUR: case NAUTICALMILES_PER_HOUR:
ratio[0] = 3600 / OsmAndFormatter.METERS_IN_ONE_NAUTICALMILE; ratio[0] = 3600 / OsmAndFormatter.METERS_IN_ONE_NAUTICALMILE;
@ -732,22 +739,22 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
float settingsMinSpeed = settings.MIN_SPEED.get(); float settingsMinSpeed = settings.MIN_SPEED.get();
float settingsMaxSpeed = settings.MAX_SPEED.get(); float settingsMaxSpeed = settings.MAX_SPEED.get();
final int[] defaultValue = { Math.round(mode.getDefaultSpeed() * ratio[0]) }; final int[] defaultValue = {Math.round(mode.getDefaultSpeed() * ratio[0])};
final int[] minValue = { Math.round((settingsMinSpeed > 0 ? settingsMinSpeed : router.getMinSpeed()) * ratio[0]) }; final int[] minValue = {Math.round((settingsMinSpeed > 0 ? settingsMinSpeed : router.getMinSpeed()) * ratio[0])};
final int[] maxValue = { Math.round((settingsMaxSpeed > 0 ? settingsMaxSpeed : router.getMaxSpeed()) * ratio[0]) }; final int[] maxValue = {Math.round((settingsMaxSpeed > 0 ? settingsMaxSpeed : router.getMaxSpeed()) * ratio[0])};
final int min = Math.round(router.getMinSpeed() * ratio[0] / 2f); final int min = Math.round(router.getMinSpeed() * ratio[0] / 2f);
final int max = Math.round(router.getMaxSpeed() * ratio[0] * 1.5f); final int max = Math.round(router.getMaxSpeed() * ratio[0] * 1.5f);
AlertDialog.Builder builder = new AlertDialog.Builder(this); AlertDialog.Builder builder = new AlertDialog.Builder(activity);
boolean lightMode = getMyApplication().getSettings().isLightContent(); boolean lightMode = app.getSettings().isLightContent();
int themeRes = lightMode ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme; int themeRes = lightMode ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme;
View seekbarView = LayoutInflater.from(new ContextThemeWrapper(this, themeRes)) View seekbarView = LayoutInflater.from(new ContextThemeWrapper(activity, themeRes))
.inflate(R.layout.default_speed_dialog, null, false); .inflate(R.layout.default_speed_dialog, null, false);
builder.setView(seekbarView); builder.setView(seekbarView);
builder.setPositiveButton(R.string.shared_string_ok, new OnClickListener() { builder.setPositiveButton(R.string.shared_string_ok, new OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
mode.setDefaultSpeed(getMyApplication(), defaultValue[0] / ratio[0]); mode.setDefaultSpeed(app, defaultValue[0] / ratio[0]);
settings.MIN_SPEED.set(minValue[0] / ratio[0]); settings.MIN_SPEED.set(minValue[0] / ratio[0]);
settings.MAX_SPEED.set(maxValue[0] / ratio[0]); settings.MAX_SPEED.set(maxValue[0] / ratio[0]);
} }
@ -756,7 +763,7 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
builder.setNeutralButton("Revert", new OnClickListener() { builder.setNeutralButton("Revert", new OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
mode.resetDefaultSpeed(getMyApplication()); mode.resetDefaultSpeed(app);
settings.MIN_SPEED.set(0f); settings.MIN_SPEED.set(0f);
settings.MAX_SPEED.set(0f); settings.MAX_SPEED.set(0f);
} }
@ -769,13 +776,13 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
builder.show(); builder.show();
} }
public enum SpeedSliderType { private enum SpeedSliderType {
DEFAULT_SPEED, DEFAULT_SPEED,
MIN_SPEED, MIN_SPEED,
MAX_SPEED, MAX_SPEED,
} }
public static void setupSpeedSlider(final SpeedSliderType type, String speedUnits, final int[] minValue, final int[] defaultValue, final int[] maxValue, final int min, final int max, View seekbarView) { private static void setupSpeedSlider(final SpeedSliderType type, String speedUnits, final int[] minValue, final int[] defaultValue, final int[] maxValue, final int min, final int max, View seekbarView) {
View seekbarLayout; View seekbarLayout;
int titleId; int titleId;
final int[] speedValue; final int[] speedValue;

View file

@ -183,11 +183,6 @@ public class BaseOsmAndFragment extends Fragment implements TransitionAnimator {
return cache != null ? cache.getIcon(id, colorId) : null; return cache != null ? cache.getIcon(id, colorId) : null;
} }
protected Drawable getIcon(@DrawableRes int id) {
UiUtilities cache = getIconsCache();
return cache != null ? cache.getIcon(id) : null;
}
protected Drawable getContentIcon(@DrawableRes int id) { protected Drawable getContentIcon(@DrawableRes int id) {
UiUtilities cache = getIconsCache(); UiUtilities cache = getIconsCache();
return cache != null ? cache.getThemedIcon(id) : null; return cache != null ? cache.getThemedIcon(id) : null;

View file

@ -11,15 +11,25 @@ import android.preference.Preference;
import android.preference.Preference.OnPreferenceClickListener; import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceCategory; import android.preference.PreferenceCategory;
import android.preference.PreferenceScreen; import android.preference.PreferenceScreen;
import android.support.v7.app.AlertDialog;
import android.view.View;
import net.osmand.PlatformUtil;
import net.osmand.StateChangedListener;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmAndLocationSimulation; import net.osmand.plus.OsmAndLocationSimulation;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.SettingsBaseActivity; import net.osmand.plus.activities.SettingsBaseActivity;
import net.osmand.plus.activities.actions.AppModeDialog;
import net.osmand.plus.profiles.SettingsProfileFragment;
import net.osmand.util.SunriseSunset; import net.osmand.util.SunriseSunset;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
//import net.osmand.plus.development.OsmandDevelopmentPlugin; //import net.osmand.plus.development.OsmandDevelopmentPlugin;

View file

@ -1,7 +1,7 @@
package net.osmand.plus.settings.profiles; package net.osmand.plus.profiles;
import static net.osmand.plus.settings.profiles.SettingsProfileFragment.IS_USER_PROFILE; import static net.osmand.plus.profiles.SettingsProfileFragment.IS_USER_PROFILE;
import static net.osmand.plus.settings.profiles.SettingsProfileFragment.PROFILE_STRING_KEY; import static net.osmand.plus.profiles.SettingsProfileFragment.PROFILE_STRING_KEY;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
@ -22,7 +22,7 @@ import net.osmand.plus.R;
import net.osmand.plus.base.MenuBottomSheetDialogFragment; import net.osmand.plus.base.MenuBottomSheetDialogFragment;
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem; import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem; import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
import net.osmand.plus.settings.profiles.ProfileMenuAdapter.ProfileMenuAdapterListener; import net.osmand.plus.profiles.ProfileMenuAdapter.ProfileMenuAdapterListener;
public class AppModesBottomSheetDialogFragment extends MenuBottomSheetDialogFragment { public class AppModesBottomSheetDialogFragment extends MenuBottomSheetDialogFragment {
@ -68,20 +68,20 @@ public class AppModesBottomSheetDialogFragment extends MenuBottomSheetDialogFrag
@Override @Override
public void onProfilePressed(ApplicationMode item) { public void onProfilePressed(ApplicationMode item) {
// Intent intent = new Intent(getActivity(), EditProfileActivity.class); Intent intent = new Intent(getActivity(), EditProfileActivity.class);
// intent.putExtra(PROFILE_STRING_KEY, item.getStringKey()); intent.putExtra(PROFILE_STRING_KEY, item.getStringKey());
// if (item.isCustomProfile()) { if (item.isCustomProfile()) {
// intent.putExtra(IS_USER_PROFILE, true); intent.putExtra(IS_USER_PROFILE, true);
// } }
// startActivity(intent); startActivity(intent);
} }
@Override @Override
public void onButtonPressed() { public void onButtonPressed() {
// OsmandApplication app = requiredMyApplication(); OsmandApplication app = requiredMyApplication();
// Intent intent = new Intent(app, SettingsProfileActivity.class); Intent intent = new Intent(app, SettingsProfileActivity.class);
// intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// app.startActivity(intent); app.startActivity(intent);
} }
}; };
} }

View file

@ -1,8 +1,10 @@
package net.osmand.plus.settings.profiles; package net.osmand.plus.profiles;
import android.app.Activity; import android.app.Activity;
import android.app.Application;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.system.Os;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;

View file

@ -0,0 +1,74 @@
package net.osmand.plus.profiles;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.view.MenuItemCompat;
import android.view.Menu;
import android.view.MenuItem;
import net.osmand.PlatformUtil;
import net.osmand.plus.R;
import net.osmand.plus.activities.OsmandActionBarActivity;
public class EditProfileActivity extends OsmandActionBarActivity {
public static final int DELETE_ID = 1010;
public static final String EDIT_PROFILE_FRAGMENT_TAG = "editProfileFragment";
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
getMyApplication().applyTheme(this);
super.onCreate(savedInstanceState);
setContentView(R.layout.single_fragment_layout);
if (savedInstanceState == null) {
EditProfileFragment editProfileFragment = new EditProfileFragment();
editProfileFragment.setArguments(getIntent().getExtras());
getSupportFragmentManager().beginTransaction().add(android.R.id.content,
editProfileFragment, EDIT_PROFILE_FRAGMENT_TAG).commit();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
int activeButtonsAndLinksTextResId = getMyApplication().getSettings().isLightContent() ?
R.color.active_buttons_and_links_text_light : R.color.active_buttons_and_links_text_dark;
Drawable icDelete = getMyApplication().getUIUtilities().getIcon(R.drawable.ic_action_delete_dark, activeButtonsAndLinksTextResId);
MenuItem m = menu.add(0, DELETE_ID, 0, R.string.action_delete)
.setIcon(icDelete);
MenuItemCompat.setShowAsAction(m, MenuItem.SHOW_AS_ACTION_ALWAYS);
super.onCreateOptionsMenu(menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int itemId = item.getItemId();
switch (itemId) {
case android.R.id.home:
onBackPressed();
return true;
case DELETE_ID:
((EditProfileFragment) getSupportFragmentManager().findFragmentByTag(
EDIT_PROFILE_FRAGMENT_TAG)).onDeleteProfileClick();
return true;
}
return false;
}
@Override
public void onBackPressed() {
final EditProfileFragment epf = (EditProfileFragment) getSupportFragmentManager()
.findFragmentByTag(EDIT_PROFILE_FRAGMENT_TAG);
if (epf.onBackPressedAllowed()) {
super.onBackPressed();
} else {
epf.confirmCancelDialog(this);
}
}
}

View file

@ -1,14 +1,14 @@
package net.osmand.plus.settings.profiles; package net.osmand.plus.profiles;
import static net.osmand.plus.activities.SettingsNavigationActivity.INTENT_SKIP_DIALOG; import static net.osmand.plus.activities.SettingsNavigationActivity.INTENT_SKIP_DIALOG;
import static net.osmand.plus.settings.profiles.SelectProfileBottomSheetDialogFragment.DIALOG_TYPE; import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.DIALOG_TYPE;
import static net.osmand.plus.settings.profiles.SelectProfileBottomSheetDialogFragment.SELECTED_KEY; import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.SELECTED_KEY;
import static net.osmand.plus.settings.profiles.SelectProfileBottomSheetDialogFragment.TYPE_BASE_APP_PROFILE; import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.TYPE_BASE_APP_PROFILE;
import static net.osmand.plus.settings.profiles.SelectProfileBottomSheetDialogFragment.TYPE_ICON; import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.TYPE_ICON;
import static net.osmand.plus.settings.profiles.SelectProfileBottomSheetDialogFragment.TYPE_NAV_PROFILE; import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.TYPE_NAV_PROFILE;
import static net.osmand.plus.settings.profiles.SettingsProfileFragment.IS_NEW_PROFILE; import static net.osmand.plus.profiles.SettingsProfileFragment.IS_NEW_PROFILE;
import static net.osmand.plus.settings.profiles.SettingsProfileFragment.IS_USER_PROFILE; import static net.osmand.plus.profiles.SettingsProfileFragment.IS_USER_PROFILE;
import static net.osmand.plus.settings.profiles.SettingsProfileFragment.PROFILE_STRING_KEY; import static net.osmand.plus.profiles.SettingsProfileFragment.PROFILE_STRING_KEY;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
@ -25,7 +25,6 @@ import android.support.annotation.Nullable;
import android.support.v7.app.ActionBar; import android.support.v7.app.ActionBar;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.support.v7.app.AlertDialog.Builder; import android.support.v7.app.AlertDialog.Builder;
import android.support.v7.app.AppCompatActivity;
import android.text.Editable; import android.text.Editable;
import android.text.TextWatcher; import android.text.TextWatcher;
import android.view.Gravity; import android.view.Gravity;
@ -61,7 +60,7 @@ import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.OsmandActionBarActivity; import net.osmand.plus.activities.OsmandActionBarActivity;
import net.osmand.plus.activities.SettingsNavigationActivity; import net.osmand.plus.activities.SettingsNavigationActivity;
import net.osmand.plus.base.BaseOsmAndFragment; import net.osmand.plus.base.BaseOsmAndFragment;
import net.osmand.plus.settings.profiles.SelectProfileBottomSheetDialogFragment.SelectProfileListener; import net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.SelectProfileListener;
import net.osmand.plus.routing.RouteProvider.RouteService; import net.osmand.plus.routing.RouteProvider.RouteService;
import net.osmand.plus.widgets.OsmandTextFieldBoxes; import net.osmand.plus.widgets.OsmandTextFieldBoxes;
import net.osmand.router.GeneralRouter; import net.osmand.router.GeneralRouter;
@ -140,7 +139,7 @@ public class EditProfileFragment extends BaseOsmAndFragment {
@Override @Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) { @Nullable Bundle savedInstanceState) {
final AppCompatActivity activity = (AppCompatActivity) getActivity(); final EditProfileActivity activity = (EditProfileActivity) getActivity();
final View view = inflater.inflate(R.layout.fragment_selected_profile, container, false); final View view = inflater.inflate(R.layout.fragment_selected_profile, container, false);
profileIcon = view.findViewById(R.id.profile_icon_img); profileIcon = view.findViewById(R.id.profile_icon_img);
@ -235,17 +234,18 @@ public class EditProfileFragment extends BaseOsmAndFragment {
for (RoutingProfileDataObject rp : routingProfileDataObjects) { for (RoutingProfileDataObject rp : routingProfileDataObjects) {
if (profile.stringKey.equals(rp.getStringKey())) { if (profile.stringKey.equals(rp.getStringKey())) {
navTypeEt.setText( navTypeEt.setText(
RoutingProfilesResources.valueOf(rp.getStringKey().toUpperCase()) RoutingProfilesResources.valueOf(rp.getStringKey().toUpperCase())
.getStringRes()); .getStringRes());
} }
} }
navTypeEt.clearFocus(); navTypeEt.clearFocus();
} }
profileNameEt.clearFocus(); profileNameEt.clearFocus();
if (activity != null && activity.getSupportActionBar() != null) { if (getActivity() != null
activity.getSupportActionBar().setTitle(title); && ((EditProfileActivity) getActivity()).getSupportActionBar() != null) {
activity.getSupportActionBar().setElevation(5.0f); ((EditProfileActivity) getActivity()).getSupportActionBar().setTitle(title);
((EditProfileActivity) getActivity()).getSupportActionBar().setElevation(5.0f);
} }
int iconColor = profile.iconColor.getColor(nightMode); int iconColor = profile.iconColor.getColor(nightMode);

View file

@ -1,4 +1,4 @@
package net.osmand.plus.settings.profiles; package net.osmand.plus.profiles;
import android.support.annotation.ColorRes; import android.support.annotation.ColorRes;
import net.osmand.plus.ApplicationMode.ProfileIconColors; import net.osmand.plus.ApplicationMode.ProfileIconColors;

View file

@ -1,4 +1,4 @@
package net.osmand.plus.settings.profiles; package net.osmand.plus.profiles;
import android.support.annotation.ColorRes; import android.support.annotation.ColorRes;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
@ -21,7 +21,7 @@ import net.osmand.PlatformUtil;
import net.osmand.plus.ApplicationMode; import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.settings.profiles.ProfileMenuAdapter.ProfileViewHolder; import net.osmand.plus.profiles.ProfileMenuAdapter.ProfileViewHolder;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;

View file

@ -1,4 +1,7 @@
package net.osmand.plus.settings.profiles; package net.osmand.plus.profiles;
import android.os.Parcel;
import net.osmand.plus.ApplicationMode.ProfileIconColors;
public class RoutingProfileDataObject extends ProfileDataObject { public class RoutingProfileDataObject extends ProfileDataObject {

View file

@ -1,26 +1,28 @@
package net.osmand.plus.settings.profiles; package net.osmand.plus.profiles;
import static net.osmand.plus.settings.profiles.EditProfileFragment.SELECTED_ICON; import static net.osmand.plus.profiles.EditProfileFragment.SELECTED_ICON;
import android.content.res.ColorStateList; import android.content.res.ColorStateList;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v7.widget.SwitchCompat;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.widget.Button;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.base.MenuBottomSheetDialogFragment; import net.osmand.plus.base.MenuBottomSheetDialogFragment;
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton; import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.LongDescriptionItem; import net.osmand.plus.base.bottomsheetmenu.simpleitems.LongDescriptionItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem; import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
public class SelectProfileBottomSheetDialogFragment extends MenuBottomSheetDialogFragment { public class SelectProfileBottomSheetDialogFragment extends MenuBottomSheetDialogFragment {
@ -215,21 +217,21 @@ public class SelectProfileBottomSheetDialogFragment extends MenuBottomSheetDialo
private void getListener() { private void getListener() {
// if (getActivity() != null && getActivity() instanceof EditProfileActivity) { if (getActivity() != null && getActivity() instanceof EditProfileActivity) {
// EditProfileFragment f = (EditProfileFragment) getActivity().getSupportFragmentManager() EditProfileFragment f = (EditProfileFragment) getActivity().getSupportFragmentManager()
// .findFragmentByTag(EditProfileActivity.EDIT_PROFILE_FRAGMENT_TAG); .findFragmentByTag(EditProfileActivity.EDIT_PROFILE_FRAGMENT_TAG);
// if (type.equals(TYPE_BASE_APP_PROFILE)) { if (type.equals(TYPE_BASE_APP_PROFILE)) {
// listener = f.getBaseProfileListener(); listener = f.getBaseProfileListener();
// } else if (type.equals(TYPE_NAV_PROFILE)) { } else if (type.equals(TYPE_NAV_PROFILE)) {
// listener = f.getNavProfileListener(); listener = f.getNavProfileListener();
// } else if (type.equals(TYPE_ICON)) { } else if (type.equals(TYPE_ICON)) {
// listener = f.getIconListener(); listener = f.getIconListener();
// } }
// } else if (getActivity() != null && getActivity() instanceof SettingsProfileActivity) { } else if (getActivity() != null && getActivity() instanceof SettingsProfileActivity) {
// SettingsProfileFragment f = (SettingsProfileFragment) getActivity().getSupportFragmentManager() SettingsProfileFragment f = (SettingsProfileFragment) getActivity().getSupportFragmentManager()
// .findFragmentByTag(SettingsProfileActivity.SETTINGS_PROFILE_FRAGMENT_TAG); .findFragmentByTag(SettingsProfileActivity.SETTINGS_PROFILE_FRAGMENT_TAG);
// listener = f.getBaseProfileListener(); listener = f.getBaseProfileListener();
// } }
} }
private List<IconResWithDescr> getProfileIcons() { private List<IconResWithDescr> getProfileIcons() {

View file

@ -0,0 +1,44 @@
package net.osmand.plus.profiles;
import android.os.Bundle;
import android.view.MenuItem;
import net.osmand.plus.R;
import net.osmand.plus.activities.OsmandActionBarActivity;
public class SettingsProfileActivity extends OsmandActionBarActivity {
public static final String SETTINGS_PROFILE_FRAGMENT_TAG = "settingsProfileFragment";
@Override
public void onCreate(Bundle savedInstanceState) {
getMyApplication().applyTheme(this);
super.onCreate(savedInstanceState);
setContentView(R.layout.single_fragment_layout);
getSupportActionBar().setElevation(5.0f);
getSupportActionBar().setTitle(R.string.application_profiles);
if (savedInstanceState == null) {
SettingsProfileFragment profileFragment = new SettingsProfileFragment();
profileFragment.setArguments(getIntent().getExtras());
getSupportFragmentManager().beginTransaction()
.add(android.R.id.content, profileFragment, SETTINGS_PROFILE_FRAGMENT_TAG).commit();
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int itemId = item.getItemId();
switch (itemId) {
case android.R.id.home:
finish();
return true;
}
return false;
}
@Override
protected void onResume() {
super.onResume();
}
}

View file

@ -1,9 +1,9 @@
package net.osmand.plus.settings.profiles; package net.osmand.plus.profiles;
import static net.osmand.plus.settings.profiles.SelectProfileBottomSheetDialogFragment.DIALOG_TYPE; import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.DIALOG_TYPE;
import static net.osmand.plus.settings.profiles.SelectProfileBottomSheetDialogFragment.TYPE_BASE_APP_PROFILE; import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.TYPE_BASE_APP_PROFILE;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
@ -25,8 +25,8 @@ import net.osmand.PlatformUtil;
import net.osmand.plus.ApplicationMode; import net.osmand.plus.ApplicationMode;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.base.BaseOsmAndFragment; import net.osmand.plus.base.BaseOsmAndFragment;
import net.osmand.plus.settings.profiles.ProfileMenuAdapter.ProfileMenuAdapterListener; import net.osmand.plus.profiles.ProfileMenuAdapter.ProfileMenuAdapterListener;
import net.osmand.plus.settings.profiles.SelectProfileBottomSheetDialogFragment.SelectProfileListener; import net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.SelectProfileListener;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
@ -108,12 +108,12 @@ public class SettingsProfileFragment extends BaseOsmAndFragment {
@Override @Override
public void onProfilePressed(ApplicationMode item) { public void onProfilePressed(ApplicationMode item) {
// Intent intent = new Intent(getActivity(), EditProfileActivity.class); Intent intent = new Intent(getActivity(), EditProfileActivity.class);
// intent.putExtra(PROFILE_STRING_KEY, item.getStringKey()); intent.putExtra(PROFILE_STRING_KEY, item.getStringKey());
// if (item.isCustomProfile()) { if (item.isCustomProfile()) {
// intent.putExtra(IS_USER_PROFILE, true); intent.putExtra(IS_USER_PROFILE, true);
// } }
// startActivity(intent); startActivity(intent);
} }
@Override @Override
@ -135,11 +135,11 @@ public class SettingsProfileFragment extends BaseOsmAndFragment {
typeListener = new SelectProfileListener() { typeListener = new SelectProfileListener() {
@Override @Override
public void onSelectedType(int pos, String stringRes) { public void onSelectedType(int pos, String stringRes) {
// Intent intent = new Intent(getActivity(), EditProfileActivity.class); Intent intent = new Intent(getActivity(), EditProfileActivity.class);
// intent.putExtra(IS_NEW_PROFILE, true); intent.putExtra(IS_NEW_PROFILE, true);
// intent.putExtra(IS_USER_PROFILE, true); intent.putExtra(IS_USER_PROFILE, true);
// intent.putExtra(PROFILE_STRING_KEY, baseProfiles.get(pos).getStringKey()); intent.putExtra(PROFILE_STRING_KEY, baseProfiles.get(pos).getStringKey());
// startActivity(intent); startActivity(intent);
} }
}; };
} }

View file

@ -66,8 +66,8 @@ import net.osmand.plus.helpers.WaypointHelper;
import net.osmand.plus.mapcontextmenu.other.TrackDetailsMenuFragment; import net.osmand.plus.mapcontextmenu.other.TrackDetailsMenuFragment;
import net.osmand.plus.mapmarkers.MapMarkerSelectionFragment; import net.osmand.plus.mapmarkers.MapMarkerSelectionFragment;
import net.osmand.plus.poi.PoiUIFilter; import net.osmand.plus.poi.PoiUIFilter;
import net.osmand.plus.settings.profiles.AppModesBottomSheetDialogFragment; import net.osmand.plus.profiles.AppModesBottomSheetDialogFragment;
import net.osmand.plus.settings.profiles.AppModesBottomSheetDialogFragment.UpdateMapRouteMenuListener; import net.osmand.plus.profiles.AppModesBottomSheetDialogFragment.UpdateMapRouteMenuListener;
import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.AvoidPTTypesRoutingParameter; import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.AvoidPTTypesRoutingParameter;
import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.AvoidRoadsRoutingParameter; import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.AvoidRoadsRoutingParameter;
import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.LocalRoutingParameter; import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.LocalRoutingParameter;

View file

@ -5,7 +5,6 @@ import android.content.DialogInterface;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.ColorInt;
import android.support.annotation.ColorRes; import android.support.annotation.ColorRes;
import android.support.annotation.DrawableRes; import android.support.annotation.DrawableRes;
import android.support.annotation.LayoutRes; import android.support.annotation.LayoutRes;
@ -15,12 +14,14 @@ import android.support.annotation.XmlRes;
import android.support.design.widget.AppBarLayout; import android.support.design.widget.AppBarLayout;
import android.support.v14.preference.SwitchPreference; import android.support.v14.preference.SwitchPreference;
import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.support.v7.preference.EditTextPreference;
import android.support.v7.preference.ListPreference; import android.support.v7.preference.ListPreference;
import android.support.v7.preference.Preference; import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceFragmentCompat; import android.support.v7.preference.PreferenceFragmentCompat;
import android.support.v7.preference.PreferenceScreen;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ImageView; import android.widget.ImageView;
@ -35,12 +36,12 @@ import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.OsmandActionBarActivity; import net.osmand.plus.activities.OsmandActionBarActivity;
import net.osmand.plus.activities.OsmandInAppPurchaseActivity; import net.osmand.plus.activities.OsmandInAppPurchaseActivity;
import net.osmand.plus.settings.profiles.AppProfileArrayAdapter; import net.osmand.plus.profiles.AppProfileArrayAdapter;
import net.osmand.plus.settings.profiles.ProfileDataObject; import net.osmand.plus.profiles.ProfileDataObject;
import net.osmand.plus.views.SwitchFragmentPreference; import net.osmand.plus.settings.preferences.ListPreferenceEx;
import net.osmand.plus.settings.preferences.SwitchPreferenceEx;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
public abstract class BaseSettingsFragment extends PreferenceFragmentCompat implements Preference.OnPreferenceChangeListener, Preference.OnPreferenceClickListener { public abstract class BaseSettingsFragment extends PreferenceFragmentCompat implements Preference.OnPreferenceChangeListener, Preference.OnPreferenceClickListener {
@ -49,7 +50,6 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
protected OsmandSettings settings; protected OsmandSettings settings;
protected UiUtilities iconsCache; protected UiUtilities iconsCache;
protected List<ApplicationMode> modes = new ArrayList<ApplicationMode>(); protected List<ApplicationMode> modes = new ArrayList<ApplicationMode>();
protected ApplicationMode selectedAppMode = null;
private boolean nightMode; private boolean nightMode;
private boolean wasDrawerDisabled; private boolean wasDrawerDisabled;
@ -59,14 +59,9 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
app = requireMyApplication(); app = requireMyApplication();
settings = app.getSettings(); settings = app.getSettings();
nightMode = !settings.isLightContent(); nightMode = !settings.isLightContent();
selectedAppMode = settings.APPLICATION_MODE.get();
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
modes.clear(); modes.clear();
for (ApplicationMode a : ApplicationMode.values(app)) { modes.addAll(ApplicationMode.values(app));
if (a != ApplicationMode.DEFAULT) {
modes.add(a);
}
}
} }
@Override @Override
@ -134,6 +129,7 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
return; return;
} }
ApplicationMode selectedAppMode = getSelectedAppMode();
int iconRes = selectedAppMode.getIconRes(); int iconRes = selectedAppMode.getIconRes();
int iconColor = selectedAppMode.getIconColorInfo().getColor(nightMode); int iconColor = selectedAppMode.getIconColorInfo().getColor(nightMode);
String title = selectedAppMode.isCustomProfile() ? selectedAppMode.getCustomProfileName() : getResources().getString(selectedAppMode.getNameKeyResource()); String title = selectedAppMode.isCustomProfile() ? selectedAppMode.getCustomProfileName() : getResources().getString(selectedAppMode.getNameKeyResource());
@ -158,25 +154,99 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
@Override @Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
getPreferenceManager().setPreferenceDataStore(settings.getDataStore());
updatePreferencesScreen(); updatePreferencesScreen();
} }
private void updatePreferencesScreen() { private void updatePreferencesScreen() {
if (selectedAppMode != null) { if (getSelectedAppMode() != null) {
String sharedPreferencesName = OsmandSettings.getSharedPreferencesName(selectedAppMode); int resId = getPreferencesResId();
getPreferenceManager().setSharedPreferencesName(sharedPreferencesName);
int resId = getPreferenceResId();
if (resId != -1) { if (resId != -1) {
addPreferencesFromResource(getPreferenceResId()); addPreferencesFromResource(getPreferencesResId());
setupPreferences();
registerPreferences();
} }
createUI();
} }
} }
protected abstract void createUI(); protected abstract void setupPreferences();
private void registerPreferences() {
PreferenceScreen screen = getPreferenceScreen();
if (screen != null) {
for (int i = 0; i < screen.getPreferenceCount(); i++) {
Preference preference = screen.getPreference(i);
registerPreference(preference);
}
}
}
protected AlertDialog.Builder selectAppModeDialog() {
AlertDialog.Builder singleSelectDialogBuilder = new AlertDialog.Builder(getContext());
singleSelectDialogBuilder.setTitle(R.string.profile_settings);
final List<ProfileDataObject> activeModes = new ArrayList<>();
for (ApplicationMode am : ApplicationMode.values(getMyApplication())) {
boolean isSelected = false;
if (am == getSelectedAppMode()) {
isSelected = true;
}
activeModes.add(new ProfileDataObject(
am.toHumanString(getMyApplication()),
getAppModeDescription(am),
am.getStringKey(),
am.getIconRes(),
isSelected,
am.getIconColorInfo()
));
}
final AppProfileArrayAdapter modeNames = new AppProfileArrayAdapter(
getActivity(), R.layout.bottom_sheet_item_with_descr_and_radio_btn, activeModes, true);
singleSelectDialogBuilder.setNegativeButton(R.string.shared_string_cancel,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
singleSelectDialogBuilder.setAdapter(modeNames, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
ApplicationMode selectedAppMode = modes.get(which);
requireSettings().APPLICATION_MODE.set(selectedAppMode);
updateAllSettings();
}
});
return singleSelectDialogBuilder;
}
private String getAppModeDescription(ApplicationMode mode) {
String descr;
if (!mode.isCustomProfile()) {
descr = getString(R.string.profile_type_base_string);
} else {
descr = String.format(getString(R.string.profile_type_descr_string),
mode.getParent().toHumanString(getMyApplication()));
if (mode.getRoutingProfile() != null && mode.getRoutingProfile().contains("/")) {
descr = descr.concat(", " + mode.getRoutingProfile()
.substring(0, mode.getRoutingProfile().indexOf("/")));
}
}
return descr;
}
public void updateAllSettings() {
String sharedPreferencesName = OsmandSettings.getSharedPreferencesName(getSelectedAppMode());
getPreferenceManager().setSharedPreferencesName(sharedPreferencesName);
updateToolbar(getView());
getPreferenceScreen().removeAll();
updatePreferencesScreen();
}
@XmlRes @XmlRes
protected int getPreferenceResId() { protected int getPreferencesResId() {
return -1; return -1;
} }
@ -201,21 +271,21 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
return -1; return -1;
} }
protected Preference findAndRegisterPreference(String key) {
Preference preference = getPreferenceScreen().findPreference(key);
registerPreference(preference);
return preference;
}
protected void registerPreference(Preference preference) { protected void registerPreference(Preference preference) {
if (preference != null) { if (preference != null) {
preference.setOnPreferenceChangeListener(this); preference.setOnPreferenceChangeListener(this);
preference.setOnPreferenceClickListener(this); preference.setOnPreferenceClickListener(this);
preference.setIconSpaceReserved(true);
if (preference instanceof ListPreference) {
ListPreference listPreference = (ListPreference) preference;
assert listPreference.getEntryValues().length == listPreference.getEntries().length;
}
} }
} }
public ApplicationMode getSelectedMode() { public ApplicationMode getSelectedAppMode() {
return selectedAppMode; return settings.APPLICATION_MODE.get();
} }
public boolean isNightMode() { public boolean isNightMode() {
@ -277,11 +347,6 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
return iconsCache; return iconsCache;
} }
protected Drawable getPaintedContentIcon(@DrawableRes int id, @ColorInt int color) {
UiUtilities cache = getIconsCache();
return cache != null ? cache.getPaintedIcon(id, color) : null;
}
protected Drawable getIcon(@DrawableRes int id, @ColorRes int colorId) { protected Drawable getIcon(@DrawableRes int id, @ColorRes int colorId) {
UiUtilities cache = getIconsCache(); UiUtilities cache = getIconsCache();
return cache != null ? cache.getIcon(id, colorId) : null; return cache != null ? cache.getIcon(id, colorId) : null;
@ -297,10 +362,6 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
return cache != null ? cache.getThemedIcon(id) : null; return cache != null ? cache.getThemedIcon(id) : null;
} }
protected void setThemedDrawable(View view, @DrawableRes int iconId) {
((ImageView) view).setImageDrawable(getContentIcon(iconId));
}
@Nullable @Nullable
protected OsmandSettings getSettings() { protected OsmandSettings getSettings() {
OsmandApplication app = getMyApplication(); OsmandApplication app = getMyApplication();
@ -317,139 +378,85 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
return app.getSettings(); return app.getSettings();
} }
// ------------------------------------------------------------------------------------------------
public SwitchPreference createSwitchPreference(OsmandSettings.OsmandPreference<Boolean> b, int title, int summary) {
SwitchPreference p = new SwitchPreference(getContext());
p.setTitle(title);
p.setKey(b.getId());
p.setSummary(summary);
p.setOnPreferenceChangeListener(this);
return p;
}
public SwitchPreference createSwitchFragmentPreference(OsmandSettings.OsmandPreference<Boolean> b, int title, int summary) {
SwitchFragmentPreference p = new SwitchFragmentPreference(getContext());
p.setTitle(title);
p.setKey(b.getId());
p.setSummary(summary);
p.setOnPreferenceChangeListener(this);
return p;
}
public SwitchPreference createSwitchPreference(OsmandSettings.OsmandPreference<Boolean> b) {
SwitchPreference p = new SwitchPreference(getContext());
p.setKey(b.getId());
p.setOnPreferenceChangeListener(this);
p.setSelectable(true);
return p;
}
public <T> ListPreference createListPreference(OsmandSettings.OsmandPreference<T> b, String[] names, T[] values, String title, String summary) {
ListPreference p = new ListPreference(getContext());
p.setTitle(title);
p.setKey(b.getId());
p.setDialogTitle(title);
p.setSummary(summary);
p.setOnPreferenceChangeListener(this);
prepareListPreference(b, names, values, p);
return p;
}
private <T> void prepareListPreference(OsmandSettings.OsmandPreference<T> b, String[] names, T[] values, ListPreference p) {
p.setOnPreferenceChangeListener(this);
LinkedHashMap<String, Object> vals = new LinkedHashMap<String, Object>();
assert names.length == values.length;
for (int i = 0; i < names.length; i++) {
vals.put(names[i], values[i]);
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int itemId = item.getItemId();
switch (itemId) {
case android.R.id.home:
// finish();
return true;
}
return false;
}
protected AlertDialog.Builder selectAppModeDialog() {
AlertDialog.Builder singleSelectDialogBuilder = new AlertDialog.Builder(getContext());
singleSelectDialogBuilder.setTitle(R.string.profile_settings);
final List<ProfileDataObject> activeModes = new ArrayList<>();
for (ApplicationMode am : ApplicationMode.values(getMyApplication())) {
boolean isSelected = false;
if (am == selectedAppMode) {
isSelected = true;
}
if (am != ApplicationMode.DEFAULT) {
activeModes.add(new ProfileDataObject(
am.toHumanString(getMyApplication()),
getAppModeDescription(am),
am.getStringKey(),
am.getIconRes(),
isSelected,
am.getIconColorInfo()
));
}
}
final AppProfileArrayAdapter modeNames = new AppProfileArrayAdapter(
getActivity(), R.layout.bottom_sheet_item_with_descr_and_radio_btn, activeModes, true);
singleSelectDialogBuilder.setNegativeButton(R.string.shared_string_cancel,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
singleSelectDialogBuilder.setAdapter(modeNames, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
selectedAppMode = modes.get(which);
requireSettings().APPLICATION_MODE.set(selectedAppMode);
updateAllSettings();
}
});
return singleSelectDialogBuilder;
}
private String getAppModeDescription(ApplicationMode mode) {
String descr;
if (!mode.isCustomProfile()) {
descr = getString(R.string.profile_type_base_string);
} else {
descr = String.format(getString(R.string.profile_type_descr_string),
mode.getParent().toHumanString(getMyApplication()));
if (mode.getRoutingProfile() != null && mode.getRoutingProfile().contains("/")) {
descr = descr.concat(", " + mode.getRoutingProfile()
.substring(0, mode.getRoutingProfile().indexOf("/")));
}
}
return descr;
}
public void updateAllSettings() {
updateToolbar(getView());
getPreferenceScreen().removeAll();
updatePreferencesScreen();
}
@SuppressWarnings("unchecked")
@Override @Override
public boolean onPreferenceChange(Preference preference, Object newValue) { public boolean onPreferenceChange(Preference preference, Object newValue) {
String key = preference.getKey(); return true;
return settings.setPreference(key, newValue); }
@Override
public void onDisplayPreferenceDialog(Preference preference) {
if (preference instanceof ListPreferenceEx) {
FragmentManager fragmentManager = getFragmentManager();
if (fragmentManager != null) {
SingleSelectPreferenceBottomSheet.showInstance(fragmentManager, preference.getKey(), this);
}
} else if (preference instanceof SwitchPreferenceEx) {
FragmentManager fragmentManager = getFragmentManager();
if (fragmentManager != null) {
BooleanPreferenceBottomSheet.showInstance(fragmentManager, preference.getKey(), this);
}
} else if (preference instanceof EditTextPreference) {
FragmentManager fragmentManager = getFragmentManager();
if (fragmentManager != null) {
EditTextPreferenceBottomSheet.showInstance(fragmentManager, preference.getKey(), this);
}
} else {
super.onDisplayPreferenceDialog(preference);
}
} }
@Override @Override
public boolean onPreferenceClick(Preference preference) { public boolean onPreferenceClick(Preference preference) {
return false; return false;
} }
public SwitchPreference createSwitchPreference(OsmandSettings.OsmandPreference<Boolean> b, int title, int summary, int layoutId) {
return createSwitchPreference(b, getString(title), getString(summary), layoutId);
}
public SwitchPreference createSwitchPreference(OsmandSettings.OsmandPreference<Boolean> b, String title, String summary, int layoutId) {
SwitchPreference p = new SwitchPreference(getContext());
p.setTitle(title);
p.setKey(b.getId());
p.setSummary(summary);
p.setLayoutResource(layoutId);
return p;
}
public SwitchPreferenceEx createSwitchPreferenceEx(String prefId, int title, int layoutId) {
return createSwitchPreferenceEx(prefId, getString(title), null, layoutId);
}
public SwitchPreferenceEx createSwitchPreferenceEx(String prefId, int title, int summary, int layoutId) {
return createSwitchPreferenceEx(prefId, getString(title), getString(summary), layoutId);
}
public SwitchPreferenceEx createSwitchPreferenceEx(String prefId, String title, String summary, int layoutId) {
SwitchPreferenceEx p = new SwitchPreferenceEx(getContext());
p.setKey(prefId);
p.setTitle(title);
p.setSummary(summary);
p.setLayoutResource(layoutId);
return p;
}
public ListPreferenceEx createListPreferenceEx(String prefId, String[] names, Object[] values, int title, int layoutId) {
return createListPreferenceEx(prefId, names, values, getString(title), layoutId);
}
public ListPreferenceEx createListPreferenceEx(String prefId, String[] names, Object[] values, String title, int layoutId) {
ListPreferenceEx listPreference = new ListPreferenceEx(getContext());
listPreference.setKey(prefId);
listPreference.setTitle(title);
listPreference.setDialogTitle(title);
listPreference.setEntries(names);
listPreference.setEntryValues(values);
if (layoutId != 0) {
listPreference.setLayoutResource(layoutId);
}
return listPreference;
}
} }

View file

@ -0,0 +1,119 @@
package net.osmand.plus.settings;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v7.preference.DialogPreference;
import android.view.View;
import net.osmand.PlatformUtil;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.OsmandSettings.BooleanPreference;
import net.osmand.plus.OsmandSettings.OsmandPreference;
import net.osmand.plus.R;
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton;
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
import net.osmand.plus.settings.preferences.SwitchPreferenceEx;
import org.apache.commons.logging.Log;
public class BooleanPreferenceBottomSheet extends MenuBottomSheetDialogFragment {
public static final String TAG = BooleanPreferenceBottomSheet.class.getSimpleName();
private static final String PREFERENCE_ID = "preference_id";
private static final Log LOG = PlatformUtil.getLog(BooleanPreferenceBottomSheet.class);
private SwitchPreferenceEx switchPreference;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
switchPreference = getListPreference();
}
@Override
public void createMenuItems(Bundle savedInstanceState) {
OsmandApplication app = getMyApplication();
Bundle args = getArguments();
if (app == null || args == null || switchPreference == null) {
return;
}
String title = switchPreference.getTitle().toString();
String description = switchPreference.getDescription();
OsmandPreference preference = app.getSettings().getPreference(switchPreference.getKey());
if (!(preference instanceof BooleanPreference)) {
return;
}
items.add(new TitleItem(title));
final OsmandSettings.BooleanPreference pref = (BooleanPreference) preference;
final String on = getString(R.string.shared_string_on);
final String off = getString(R.string.shared_string_off);
boolean checked = pref.get();
final BottomSheetItemWithCompoundButton[] preferenceBtn = new BottomSheetItemWithCompoundButton[1];
preferenceBtn[0] = (BottomSheetItemWithCompoundButton) new BottomSheetItemWithCompoundButton.Builder()
.setChecked(checked)
.setTitle(checked ? on : off)
.setLayoutId(R.layout.bottom_sheet_item_with_switch)
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
boolean newValue = !pref.get();
if (switchPreference.callChangeListener(newValue)) {
switchPreference.setChecked(newValue);
preferenceBtn[0].setTitle(newValue ? on : off);
preferenceBtn[0].setChecked(newValue);
}
}
})
.create();
items.add(preferenceBtn[0]);
if (description != null) {
BaseBottomSheetItem preferenceDescription = new BottomSheetItemWithDescription.Builder()
.setDescription(description)
.setLayoutId(R.layout.bottom_sheet_item_description_long)
.create();
items.add(preferenceDescription);
}
}
private SwitchPreferenceEx getListPreference() {
if (switchPreference == null) {
final String key = getArguments().getString(PREFERENCE_ID);
final DialogPreference.TargetFragment fragment = (DialogPreference.TargetFragment) getTargetFragment();
switchPreference = (SwitchPreferenceEx) fragment.findPreference(key);
}
return switchPreference;
}
@Override
protected int getDismissButtonTextId() {
return R.string.shared_string_close;
}
public static void showInstance(@NonNull FragmentManager fm, String prefId, Fragment target) {
try {
if (fm.findFragmentByTag(BooleanPreferenceBottomSheet.TAG) == null) {
Bundle args = new Bundle();
args.putString(PREFERENCE_ID, prefId);
BooleanPreferenceBottomSheet fragment = new BooleanPreferenceBottomSheet();
fragment.setArguments(args);
fragment.setTargetFragment(target, 0);
fragment.show(fm, BooleanPreferenceBottomSheet.TAG);
}
} catch (RuntimeException e) {
LOG.error("showInstance", e);
}
}
}

View file

@ -16,11 +16,11 @@ import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.PluginActivity; import net.osmand.plus.activities.PluginActivity;
import net.osmand.plus.views.SwitchFragmentPreference; import net.osmand.plus.settings.preferences.SwitchPreferenceEx;
import java.util.List; import java.util.List;
import static net.osmand.plus.settings.profiles.SettingsProfileFragment.PROFILE_STRING_KEY; import static net.osmand.plus.profiles.SettingsProfileFragment.PROFILE_STRING_KEY;
public class ConfigureProfileFragment extends BaseSettingsFragment { public class ConfigureProfileFragment extends BaseSettingsFragment {
@ -34,7 +34,7 @@ public class ConfigureProfileFragment extends BaseSettingsFragment {
} }
@Override @Override
protected int getPreferenceResId() { protected int getPreferencesResId() {
return R.xml.configure_profile; return R.xml.configure_profile;
} }
@ -48,12 +48,12 @@ public class ConfigureProfileFragment extends BaseSettingsFragment {
} }
@Override @Override
protected void createUI() { protected void setupPreferences() {
PreferenceScreen screen = getPreferenceScreen(); PreferenceScreen screen = getPreferenceScreen();
Preference generalSettings = findAndRegisterPreference("general_settings"); Preference generalSettings = findPreference("general_settings");
Preference navigationSettings = findAndRegisterPreference("navigation_settings"); Preference navigationSettings = findPreference("navigation_settings");
Preference configureMap = findAndRegisterPreference("configure_map"); Preference configureMap = findPreference("configure_map");
generalSettings.setIcon(getContentIcon(R.drawable.ic_action_settings)); generalSettings.setIcon(getContentIcon(R.drawable.ic_action_settings));
navigationSettings.setIcon(getContentIcon(R.drawable.ic_action_gdirections_dark)); navigationSettings.setIcon(getContentIcon(R.drawable.ic_action_gdirections_dark));
@ -68,20 +68,18 @@ public class ConfigureProfileFragment extends BaseSettingsFragment {
preference.setTitle(connectedApp.getName()); preference.setTitle(connectedApp.getName());
preference.setIcon(connectedApp.getIcon()); preference.setIcon(connectedApp.getIcon());
preference.setChecked(connectedApp.isEnabled()); preference.setChecked(connectedApp.isEnabled());
preference.setLayoutResource(R.layout.preference_fragment_and_switch); preference.setLayoutResource(R.layout.preference_dialog_and_switch);
registerPreference(preference);
screen.addPreference(preference); screen.addPreference(preference);
} }
for (OsmandPlugin plugin : plugins) { for (OsmandPlugin plugin : plugins) {
SwitchFragmentPreference preference = new SwitchFragmentPreference(getContext()); SwitchPreferenceEx preference = new SwitchPreferenceEx(getContext());
preference.setKey(plugin.getId()); preference.setKey(plugin.getId());
preference.setPersistent(false);
preference.setTitle(plugin.getName()); preference.setTitle(plugin.getName());
preference.setSummaryOn("");
preference.setIcon(getContentIcon(plugin.getLogoResourceId())); preference.setIcon(getContentIcon(plugin.getLogoResourceId()));
preference.setChecked(plugin.isActive()); preference.setChecked(plugin.isActive());
preference.setLayoutResource(R.layout.preference_fragment_and_switch); preference.setLayoutResource(R.layout.preference_dialog_and_switch);
registerPreference(preference);
Intent intent = new Intent(getContext(), PluginActivity.class); Intent intent = new Intent(getContext(), PluginActivity.class);
intent.putExtra(PluginActivity.EXTRA_PLUGIN_ID, plugin.getId()); intent.putExtra(PluginActivity.EXTRA_PLUGIN_ID, plugin.getId());
@ -104,7 +102,7 @@ public class ConfigureProfileFragment extends BaseSettingsFragment {
return getMyApplication().getAidlApi().switchEnabled(connectedApp); return getMyApplication().getAidlApi().switchEnabled(connectedApp);
} }
return false; return super.onPreferenceChange(preference, newValue);
} }
public static boolean showInstance(FragmentManager fragmentManager, ApplicationMode mode) { public static boolean showInstance(FragmentManager fragmentManager, ApplicationMode mode) {

View file

@ -0,0 +1,115 @@
package net.osmand.plus.settings;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v7.preference.DialogPreference;
import android.widget.EditText;
import net.osmand.plus.R;
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.LongDescriptionItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
import net.osmand.plus.settings.preferences.EditTextPreferenceEx;
import net.osmand.util.Algorithms;
public class EditTextPreferenceBottomSheet extends MenuBottomSheetDialogFragment {
public static final String TAG = EditTextPreferenceBottomSheet.class.getSimpleName();
private static final String PREFERENCE_ID = "preference_id";
private static final String EDIT_TEXT_PREFERENCE_KEY = "edit_text_preference_key";
private EditTextPreferenceEx editTextPreference;
private EditText editText;
private String text;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
editTextPreference = getEditTextPreference();
if (savedInstanceState == null) {
text = getEditTextPreference().getText();
} else {
text = savedInstanceState.getString(EDIT_TEXT_PREFERENCE_KEY);
}
}
@Override
public void createMenuItems(Bundle savedInstanceState) {
final Context context = getContext();
if (context == null || editTextPreference == null) {
return;
}
items.add(new TitleItem(editTextPreference.getDialogTitle().toString()));
editText = new EditText(context);
editText.setText(text);
items.add(new SimpleBottomSheetItem.Builder().setCustomView(editText).create());
String description = editTextPreference.getDescription();
if (!Algorithms.isEmpty(description)) {
items.add(new LongDescriptionItem(description));
}
}
@Override
public void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
outState.putString(EDIT_TEXT_PREFERENCE_KEY, text);
}
@Override
protected int getDismissButtonTextId() {
return R.string.shared_string_close;
}
@Override
protected int getRightBottomButtonTextId() {
return R.string.shared_string_apply;
}
@Override
protected void onRightBottomButtonClick() {
String value = editText.getText().toString();
if (editTextPreference.callChangeListener(value)) {
editTextPreference.setText(value);
}
dismiss();
}
private EditTextPreferenceEx getEditTextPreference() {
if (editTextPreference == null) {
Bundle args = getArguments();
if (args != null) {
final String key = args.getString(PREFERENCE_ID);
Fragment targetFragment = getTargetFragment();
if (targetFragment instanceof DialogPreference.TargetFragment) {
DialogPreference.TargetFragment fragment = (DialogPreference.TargetFragment) targetFragment;
editTextPreference = (EditTextPreferenceEx) fragment.findPreference(key);
}
}
}
return editTextPreference;
}
public static boolean showInstance(@NonNull FragmentManager fragmentManager, String key, Fragment target) {
try {
Bundle args = new Bundle();
args.putString(PREFERENCE_ID, key);
EditTextPreferenceBottomSheet fragment = new EditTextPreferenceBottomSheet();
fragment.setTargetFragment(target, 0);
fragment.setArguments(args);
fragment.show(fragmentManager, TAG);
return true;
} catch (RuntimeException e) {
return false;
}
}
}

View file

@ -0,0 +1,327 @@
package net.osmand.plus.settings;
import android.content.Context;
import android.content.DialogInterface;
import android.content.pm.ActivityInfo;
import android.graphics.drawable.Drawable;
import android.support.annotation.NonNull;
import android.support.v14.preference.SwitchPreference;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.AlertDialog;
import android.support.v7.preference.Preference;
import android.support.v7.widget.AppCompatCheckedTextView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import net.osmand.StateChangedListener;
import net.osmand.data.PointDescription;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.base.MapViewTrackingUtilities;
import net.osmand.plus.settings.preferences.ListPreferenceEx;
import net.osmand.plus.settings.preferences.SwitchPreferenceEx;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class GeneralProfileSettings extends BaseSettingsFragment {
public static final String TAG = "GeneralProfileSettings";
@Override
protected int getPreferencesResId() {
return R.xml.general_profile_settings;
}
@Override
protected int getToolbarResId() {
return R.layout.profile_preference_toolbar_big;
}
protected String getToolbarTitle() {
return getString(R.string.general_settings_2);
}
protected void setupPreferences() {
setupAppThemePref();
setupRotateMapPref();
setupMapScreenOrientationPref();
setupDrivingRegionPref();
setupUnitsOfLengthPref();
setupCoordinatesFormatPref();
setupAngularUnitsPref();
setupKalmanFilterPref();
setupMagneticFieldSensorPref();
setupMapEmptyStateAllowedPref();
setupDoNotUseAnimationsPref();
setupExternalInputDevicePref();
}
private void setupAppThemePref() {
final ListPreferenceEx appTheme = (ListPreferenceEx) findPreference(settings.OSMAND_THEME.getId());
appTheme.setEntries(new String[] {getString(R.string.dark_theme), getString(R.string.light_theme)});
appTheme.setEntryValues(new Integer[] {OsmandSettings.OSMAND_DARK_THEME, OsmandSettings.OSMAND_LIGHT_THEME});
appTheme.setIcon(getOsmandThemeIcon());
settings.OSMAND_THEME.addListener(new StateChangedListener<Integer>() {
@Override
public void stateChanged(Integer change) {
appTheme.setIcon(getOsmandThemeIcon());
}
});
}
private Drawable getOsmandThemeIcon() {
return getIcon(settings.isLightContent() ? R.drawable.ic_action_sun : R.drawable.ic_action_moon);
}
private void setupRotateMapPref() {
final ListPreferenceEx rotateMap = (ListPreferenceEx) findPreference(settings.ROTATE_MAP.getId());
rotateMap.setEntries(new String[] {getString(R.string.rotate_map_none_opt), getString(R.string.rotate_map_bearing_opt), getString(R.string.rotate_map_compass_opt)});
rotateMap.setEntryValues(new Integer[] {OsmandSettings.ROTATE_MAP_NONE, OsmandSettings.ROTATE_MAP_BEARING, OsmandSettings.ROTATE_MAP_COMPASS});
rotateMap.setIcon(getRotateMapIcon());
settings.ROTATE_MAP.addListener(new StateChangedListener<Integer>() {
@Override
public void stateChanged(Integer change) {
rotateMap.setIcon(getRotateMapIcon());
}
});
}
private Drawable getRotateMapIcon() {
switch (settings.ROTATE_MAP.get()) {
case OsmandSettings.ROTATE_MAP_NONE:
return getIcon(R.drawable.ic_action_direction_north);
case OsmandSettings.ROTATE_MAP_BEARING:
return getIcon(R.drawable.ic_action_direction_movement);
default:
return getIcon(R.drawable.ic_action_direction_compass);
}
}
private void setupMapScreenOrientationPref() {
final ListPreferenceEx mapScreenOrientation = (ListPreferenceEx) findPreference(settings.MAP_SCREEN_ORIENTATION.getId());
mapScreenOrientation.setEntries(new String[] {getString(R.string.map_orientation_portrait), getString(R.string.map_orientation_landscape), getString(R.string.map_orientation_default)});
mapScreenOrientation.setEntryValues(new Integer[] {ActivityInfo.SCREEN_ORIENTATION_PORTRAIT, ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE, ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED});
mapScreenOrientation.setIcon(getMapScreenOrientationIcon());
settings.MAP_SCREEN_ORIENTATION.addListener(new StateChangedListener<Integer>() {
@Override
public void stateChanged(Integer change) {
mapScreenOrientation.setIcon(getMapScreenOrientationIcon());
}
});
}
private Drawable getMapScreenOrientationIcon() {
switch (settings.MAP_SCREEN_ORIENTATION.get()) {
case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
return getIcon(R.drawable.ic_action_phone_portrait_orientation);
case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
return getIcon(R.drawable.ic_action_phone_landscape_orientation);
default:
return getIcon(R.drawable.ic_action_phone_device_orientation);
}
}
private void setupDrivingRegionPref() {
Preference defaultDrivingRegion = findPreference(settings.DRIVING_REGION.getId());
defaultDrivingRegion.setIcon(getContentIcon(R.drawable.ic_action_car_dark));
}
private void setupUnitsOfLengthPref() {
OsmandSettings.MetricsConstants[] metricsConstants = OsmandSettings.MetricsConstants.values();
String[] entries = new String[metricsConstants.length];
Integer[] entryValues = new Integer[metricsConstants.length];
for (int i = 0; i < entries.length; i++) {
entries[i] = metricsConstants[i].toHumanString(app);
entryValues[i] = metricsConstants[i].ordinal();
}
ListPreferenceEx unitsOfLength = (ListPreferenceEx) findPreference(settings.METRIC_SYSTEM.getId());
unitsOfLength.setEntries(entries);
unitsOfLength.setEntryValues(entryValues);
unitsOfLength.setIcon(getIcon(R.drawable.ic_action_ruler_unit));
}
private void setupCoordinatesFormatPref() {
Context ctx = getContext();
if (ctx == null) {
return;
}
ListPreferenceEx coordinatesFormat = (ListPreferenceEx) findPreference(settings.COORDINATES_FORMAT.getId());
coordinatesFormat.setIcon(getContentIcon(R.drawable.ic_action_coordinates_widget));
coordinatesFormat.setEntries(new String[] {
PointDescription.formatToHumanString(ctx, PointDescription.FORMAT_DEGREES),
PointDescription.formatToHumanString(ctx, PointDescription.FORMAT_MINUTES),
PointDescription.formatToHumanString(ctx, PointDescription.FORMAT_SECONDS),
PointDescription.formatToHumanString(ctx, PointDescription.UTM_FORMAT),
PointDescription.formatToHumanString(ctx, PointDescription.OLC_FORMAT)
});
coordinatesFormat.setEntryValues(new Integer[] {
PointDescription.FORMAT_DEGREES,
PointDescription.FORMAT_MINUTES,
PointDescription.FORMAT_SECONDS,
PointDescription.UTM_FORMAT,
PointDescription.OLC_FORMAT
});
}
private void setupAngularUnitsPref() {
OsmandSettings.AngularConstants[] ac = OsmandSettings.AngularConstants.values();
String[] entries = new String[ac.length];
Integer[] entryValues = new Integer[ac.length];
for (int i = 0; i < entries.length; i++) {
if (ac[i] == OsmandSettings.AngularConstants.DEGREES) {
entries[i] = OsmandSettings.AngularConstants.DEGREES.toHumanString(app) + " 180";
entryValues[i] = OsmandSettings.AngularConstants.DEGREES.ordinal();
} else if (ac[i] == OsmandSettings.AngularConstants.DEGREES360) {
entries[i] = OsmandSettings.AngularConstants.DEGREES.toHumanString(app) + " 360";
entryValues[i] = OsmandSettings.AngularConstants.DEGREES360.ordinal();
} else {
entries[i] = ac[i].toHumanString(app);
entryValues[i] = OsmandSettings.AngularConstants.MILLIRADS.ordinal();
}
}
ListPreferenceEx angularUnits = (ListPreferenceEx) findPreference(settings.ANGULAR_UNITS.getId());
angularUnits.setEntries(entries);
angularUnits.setEntryValues(entryValues);
angularUnits.setIcon(getContentIcon(R.drawable.ic_action_angular_unit));
}
private void setupKalmanFilterPref() {
SwitchPreferenceEx kalmanFilterPref = (SwitchPreferenceEx) findPreference(settings.USE_KALMAN_FILTER_FOR_COMPASS.getId());
kalmanFilterPref.setSummaryOn(R.string.shared_string_on);
kalmanFilterPref.setSummaryOff(R.string.shared_string_off);
kalmanFilterPref.setTitle(getString(R.string.use_kalman_filter_compass));
kalmanFilterPref.setDescription(getString(R.string.use_kalman_filter_compass_descr));
}
private void setupMagneticFieldSensorPref() {
SwitchPreferenceEx useMagneticSensorPref = (SwitchPreferenceEx) findPreference(settings.USE_MAGNETIC_FIELD_SENSOR_COMPASS.getId());
useMagneticSensorPref.setSummaryOn(R.string.shared_string_on);
useMagneticSensorPref.setSummaryOff(R.string.shared_string_off);
useMagneticSensorPref.setTitle(getString(R.string.use_magnetic_sensor));
useMagneticSensorPref.setDescription(getString(R.string.use_magnetic_sensor_descr));
}
private void setupMapEmptyStateAllowedPref() {
SwitchPreferenceEx mapEmptyStateAllowedPref = (SwitchPreferenceEx) findPreference(settings.MAP_EMPTY_STATE_ALLOWED.getId());
mapEmptyStateAllowedPref.setSummaryOn(R.string.shared_string_on);
mapEmptyStateAllowedPref.setSummaryOff(R.string.shared_string_off);
mapEmptyStateAllowedPref.setTitle(getString(R.string.tap_on_map_to_hide_interface));
mapEmptyStateAllowedPref.setDescription(getString(R.string.tap_on_map_to_hide_interface_descr));
}
private void setupDoNotUseAnimationsPref() {
SwitchPreference doNotUseAnimations = (SwitchPreference) findPreference(settings.DO_NOT_USE_ANIMATIONS.getId());
doNotUseAnimations.setSummaryOn(R.string.shared_string_on);
doNotUseAnimations.setSummaryOff(R.string.shared_string_off);
}
private void setupExternalInputDevicePref() {
ListPreferenceEx externalInputDevice = (ListPreferenceEx) findPreference(settings.EXTERNAL_INPUT_DEVICE.getId());
externalInputDevice.setEntries(new String[] {
getString(R.string.sett_no_ext_input),
getString(R.string.sett_generic_ext_input),
getString(R.string.sett_wunderlinq_ext_input),
getString(R.string.sett_parrot_ext_input)
});
externalInputDevice.setEntryValues(new Integer[] {
OsmandSettings.NO_EXTERNAL_DEVICE,
OsmandSettings.GENERIC_EXTERNAL_DEVICE,
OsmandSettings.WUNDERLINQ_EXTERNAL_DEVICE,
OsmandSettings.PARROT_EXTERNAL_DEVICE}
);
}
private void showDrivingRegionDialog() {
final AlertDialog.Builder b = new AlertDialog.Builder(getActivity());
b.setTitle(getString(R.string.driving_region));
final List<OsmandSettings.DrivingRegion> drs = new ArrayList<>();
drs.add(null);
drs.addAll(Arrays.asList(OsmandSettings.DrivingRegion.values()));
int sel = -1;
OsmandSettings.DrivingRegion selectedDrivingRegion = settings.DRIVING_REGION.get();
if (settings.DRIVING_REGION_AUTOMATIC.get()) {
sel = 0;
}
for (int i = 1; i < drs.size(); i++) {
if (sel == -1 && drs.get(i) == selectedDrivingRegion) {
sel = i;
break;
}
}
final int selected = sel;
final ArrayAdapter<OsmandSettings.DrivingRegion> singleChoiceAdapter =
new ArrayAdapter<OsmandSettings.DrivingRegion>(getActivity(), R.layout.single_choice_description_item, R.id.text1, drs) {
@NonNull
@Override
public View getView(int position, View convertView, @NonNull ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater inflater = getActivity().getLayoutInflater();
v = inflater.inflate(R.layout.single_choice_description_item, parent, false);
}
OsmandSettings.DrivingRegion item = getItem(position);
AppCompatCheckedTextView title = (AppCompatCheckedTextView) v.findViewById(R.id.text1);
TextView desc = (TextView) v.findViewById(R.id.description);
if (item != null) {
title.setText(getString(item.name));
desc.setVisibility(View.VISIBLE);
desc.setText(item.getDescription(v.getContext()));
} else {
title.setText(getString(R.string.driving_region_automatic));
desc.setVisibility(View.GONE);
}
title.setChecked(position == selected);
return v;
}
};
b.setAdapter(singleChoiceAdapter, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (drs.get(which) == null) {
settings.DRIVING_REGION_AUTOMATIC.set(true);
MapViewTrackingUtilities mapViewTrackingUtilities = getMyApplication().getMapViewTrackingUtilities();
if (mapViewTrackingUtilities != null) {
mapViewTrackingUtilities.resetDrivingRegionUpdate();
}
} else {
settings.DRIVING_REGION_AUTOMATIC.set(false);
settings.DRIVING_REGION.set(drs.get(which));
}
updateAllSettings();
}
});
b.setNegativeButton(R.string.shared_string_cancel, null);
b.show();
}
@Override
public boolean onPreferenceClick(Preference preference) {
if (preference.getKey().equals(settings.DRIVING_REGION.getId())) {
showDrivingRegionDialog();
return true;
}
return super.onPreferenceClick(preference);
}
}

View file

@ -0,0 +1,547 @@
package net.osmand.plus.settings;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.pm.PackageManager;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.os.StatFs;
import android.support.v14.preference.SwitchPreference;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.AlertDialog;
import android.support.v7.preference.Preference;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.Toast;
import net.osmand.IProgress;
import net.osmand.IndexConstants;
import net.osmand.StateChangedListener;
import net.osmand.ValueHolder;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.Version;
import net.osmand.plus.dashboard.DashChooseAppDirFragment;
import net.osmand.plus.dialogs.ConfigureMapMenu;
import net.osmand.plus.dialogs.SendAnalyticsBottomSheetDialogFragment;
import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.settings.preferences.ListPreferenceEx;
import net.osmand.plus.settings.preferences.SwitchPreferenceEx;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
public class GlobalSettingsFragment extends BaseSettingsFragment {
public static final String TAG = "GlobalSettingsFragment";
private Preference applicationDir;
private boolean permissionRequested;
private boolean permissionGranted;
@Override
protected int getPreferencesResId() {
return R.xml.global_settings;
}
@Override
protected int getToolbarResId() {
return R.layout.global_preference_toolbar;
}
@Override
protected String getToolbarTitle() {
return getString(R.string.osmand_settings);
}
@Override
protected void setupPreferences() {
setupDefaultAppModePref();
setupPreferredLocalePref();
setupExternalStorageDirPref();
setupSendAnonymousDataPref();
setupDoNotShowStartupMessagesPref();
setupEnableProxyPref();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = super.onCreateView(inflater, container, savedInstanceState);
AndroidUiHelper.updateVisibility(view.findViewById(R.id.ProgressBar), false);
return view;
}
private void setupDefaultAppModePref() {
ApplicationMode selectedMode = getSelectedAppMode();
int iconRes = selectedMode.getIconRes();
String title = selectedMode.toHumanString(getContext());
ApplicationMode[] appModes = ApplicationMode.values(app).toArray(new ApplicationMode[0]);
String[] entries = new String[appModes.length];
for (int i = 0; i < entries.length; i++) {
entries[i] = appModes[i].toHumanString(app);
}
final ListPreferenceEx defaultApplicationMode = (ListPreferenceEx) findPreference(settings.DEFAULT_APPLICATION_MODE.getId());
defaultApplicationMode.setIcon(getContentIcon(iconRes));
defaultApplicationMode.setSummary(title);
defaultApplicationMode.setEntries(entries);
defaultApplicationMode.setEntryValues(appModes);
}
private void setupPreferredLocalePref() {
// See language list and statistics at: https://hosted.weblate.org/projects/osmand/main/
// Hardy maintenance 2016-05-29:
// - Include languages if their translation is >= ~10% (but any language will be visible if it is the device's system locale)
// - Mark as "incomplete" if < ~80%
String incompleteSuffix = " (" + getString(R.string.incomplete_locale) + ")";
// Add " (Device language)" to system default entry in Latin letters, so it can be more easily identified if a foreign language has been selected by mistake
String latinSystemDefaultSuffix = " (" + getString(R.string.system_locale_no_translate) + ")";
//getResources().getAssets().getLocales();
String[] entrieValues = new String[] {"",
"en",
"af",
"ar",
"ast",
"az",
"be",
//"be_BY",
"bg",
"ca",
"cs",
"cy",
"da",
"de",
"el",
"en_GB",
"eo",
"es",
"es_AR",
"es_US",
"eu",
"fa",
"fi",
"fr",
"gl",
"he",
"hr",
"hsb",
"hu",
"hy",
"is",
"it",
"ja",
"ka",
"kab",
"kn",
"ko",
"lt",
"lv",
"ml",
"mr",
"nb",
"nl",
"nn",
"oc",
"pl",
"pt",
"pt_BR",
"ro",
"ru",
"sc",
"sk",
"sl",
"sr",
"sr+Latn",
"sv",
"tr",
"uk",
"vi",
"zh_CN",
"zh_TW"};
String[] entries = new String[] {getString(R.string.system_locale) + latinSystemDefaultSuffix,
getString(R.string.lang_en),
getString(R.string.lang_af) + incompleteSuffix,
getString(R.string.lang_ar),
getString(R.string.lang_ast) + incompleteSuffix,
getString(R.string.lang_az),
getString(R.string.lang_be),
// getString(R.string.lang_be_by),
getString(R.string.lang_bg),
getString(R.string.lang_ca),
getString(R.string.lang_cs),
getString(R.string.lang_cy) + incompleteSuffix,
getString(R.string.lang_da),
getString(R.string.lang_de),
getString(R.string.lang_el) + incompleteSuffix,
getString(R.string.lang_en_gb),
getString(R.string.lang_eo),
getString(R.string.lang_es),
getString(R.string.lang_es_ar),
getString(R.string.lang_es_us),
getString(R.string.lang_eu),
getString(R.string.lang_fa),
getString(R.string.lang_fi) + incompleteSuffix,
getString(R.string.lang_fr),
getString(R.string.lang_gl),
getString(R.string.lang_he) + incompleteSuffix,
getString(R.string.lang_hr) + incompleteSuffix,
getString(R.string.lang_hsb) + incompleteSuffix,
getString(R.string.lang_hu),
getString(R.string.lang_hy),
getString(R.string.lang_is),
getString(R.string.lang_it),
getString(R.string.lang_ja),
getString(R.string.lang_ka) + incompleteSuffix,
getString(R.string.lang_kab) + incompleteSuffix,
getString(R.string.lang_kn) + incompleteSuffix,
getString(R.string.lang_ko),
getString(R.string.lang_lt),
getString(R.string.lang_lv),
getString(R.string.lang_ml) + incompleteSuffix,
getString(R.string.lang_mr) + incompleteSuffix,
getString(R.string.lang_nb),
getString(R.string.lang_nl),
getString(R.string.lang_nn) + incompleteSuffix,
getString(R.string.lang_oc) + incompleteSuffix,
getString(R.string.lang_pl),
getString(R.string.lang_pt),
getString(R.string.lang_pt_br),
getString(R.string.lang_ro) + incompleteSuffix,
getString(R.string.lang_ru),
getString(R.string.lang_sc),
getString(R.string.lang_sk),
getString(R.string.lang_sl),
getString(R.string.lang_sr) + incompleteSuffix,
getString(R.string.lang_sr_latn) + incompleteSuffix,
getString(R.string.lang_sv),
getString(R.string.lang_tr),
getString(R.string.lang_uk),
getString(R.string.lang_vi) + incompleteSuffix,
getString(R.string.lang_zh_cn) + incompleteSuffix,
getString(R.string.lang_zh_tw)};
String[] valuesPl = ConfigureMapMenu.getSortedMapNamesIds(getContext(), entries, entries);
String[] idsPl = ConfigureMapMenu.getSortedMapNamesIds(getContext(), entrieValues, entries);
ListPreferenceEx preferredLocale = (ListPreferenceEx) findPreference(settings.PREFERRED_LOCALE.getId());
preferredLocale.setIcon(getContentIcon(R.drawable.ic_action_map_language));
preferredLocale.setSummary(settings.PREFERRED_LOCALE.get());
preferredLocale.setEntries(valuesPl);
preferredLocale.setEntryValues(idsPl);
// Add " (Display language)" to menu title in Latin letters for all non-en languages
if (!getResources().getString(R.string.preferred_locale).equals(getResources().getString(R.string.preferred_locale_no_translate))) {
preferredLocale.setTitle(getString(R.string.preferred_locale) + " (" + getString(R.string.preferred_locale_no_translate) + ")");
}
// This setting now only in "Confgure map" menu
//String[] values = ConfigureMapMenu.getMapNamesValues(this, ConfigureMapMenu.mapNamesIds);
//String[] ids = ConfigureMapMenu.getSortedMapNamesIds(this, ConfigureMapMenu.mapNamesIds, values);
//registerListPreference(settings.MAP_PREFERRED_LOCALE, screen, ConfigureMapMenu.getMapNamesValues(this, ids), ids);
settings.PREFERRED_LOCALE.addListener(new StateChangedListener<String>() {
@Override
public void stateChanged(String change) {
// restart application to update locale
OsmandApplication app = getMyApplication();
if (app != null) {
app.checkPreferredLocale();
app.restartApp(getContext());
}
}
});
}
private void setupExternalStorageDirPref() {
applicationDir = findPreference(OsmandSettings.EXTERNAL_STORAGE_DIR);
if (!Version.isBlackberry(app)) {
int type;
if (settings.getExternalStorageDirectoryTypeV19() >= 0) {
type = settings.getExternalStorageDirectoryTypeV19();
} else {
ValueHolder<Integer> vh = new ValueHolder<Integer>();
settings.getExternalStorageDirectory(vh);
if (vh.value != null && vh.value >= 0) {
type = vh.value;
} else {
type = 0;
}
}
String appDirType = "";
if (type == OsmandSettings.EXTERNAL_STORAGE_TYPE_INTERNAL_FILE) {
appDirType = getString(R.string.storage_directory_internal_app);
} else if (type == OsmandSettings.EXTERNAL_STORAGE_TYPE_DEFAULT) {
appDirType = getString(R.string.storage_directory_shared);
} else if (type == OsmandSettings.EXTERNAL_STORAGE_TYPE_EXTERNAL_FILE) {
appDirType = getString(R.string.storage_directory_external);
} else if (type == OsmandSettings.EXTERNAL_STORAGE_TYPE_OBB) {
appDirType = getString(R.string.storage_directory_multiuser);
} else if (type == OsmandSettings.EXTERNAL_STORAGE_TYPE_SPECIFIED) {
appDirType = getString(R.string.storage_directory_manual);
}
File currentAppFile = settings.getExternalStorageDirectory();
applicationDir.setSummary(appDirType + " \u2022 " + getFreeSpace(currentAppFile));
applicationDir.setIcon(getContentIcon(R.drawable.ic_action_folder));
} else {
getPreferenceScreen().removePreference(applicationDir);
}
}
private String getFreeSpace(File dir) {
if (dir.canRead()) {
StatFs fs = new StatFs(dir.getAbsolutePath());
return DownloadActivity.formatGb.format(new Object[] {(float) (fs.getAvailableBlocks()) * fs.getBlockSize() / (1 << 30)});
}
return "";
}
private void setupSendAnonymousDataPref() {
SwitchPreferenceEx sendAnonymousData = (SwitchPreferenceEx) findPreference(settings.SEND_ANONYMOUS_DATA.getId());
sendAnonymousData.setSummaryOn(R.string.shared_string_on);
sendAnonymousData.setSummaryOff(R.string.shared_string_off);
}
private void setupDoNotShowStartupMessagesPref() {
SwitchPreference doNotShowStartupMessages = (SwitchPreference) findPreference(settings.DO_NOT_SHOW_STARTUP_MESSAGES.getId());
doNotShowStartupMessages.setSummaryOn(R.string.shared_string_on);
doNotShowStartupMessages.setSummaryOff(R.string.shared_string_off);
}
private void setupEnableProxyPref() {
SwitchPreferenceEx enableProxy = (SwitchPreferenceEx) findPreference(settings.ENABLE_PROXY.getId());
enableProxy.setIcon(getContentIcon(R.drawable.ic_action_proxy));
enableProxy.setSummaryOn(R.string.shared_string_on);
enableProxy.setSummaryOff(R.string.shared_string_off);
}
@Override
public void onDisplayPreferenceDialog(Preference preference) {
if (preference.getKey().equals(settings.SEND_ANONYMOUS_DATA.getId())) {
FragmentManager fragmentManager = getFragmentManager();
if (fragmentManager != null) {
SendAnalyticsBottomSheetDialogFragment.showInstance(app, fragmentManager);
}
} else {
super.onDisplayPreferenceDialog(preference);
}
}
@Override
public boolean onPreferenceClick(Preference preference) {
String prefId = preference.getKey();
if (prefId.equals(OsmandSettings.EXTERNAL_STORAGE_DIR)) {
showAppDirDialog();
return true;
}
return super.onPreferenceClick(preference);
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
String prefId = preference.getKey();
if (prefId.equals(settings.DEFAULT_APPLICATION_MODE.getId()) && newValue instanceof ApplicationMode) {
preference.setIcon(getContentIcon(((ApplicationMode) newValue).getIconRes()));
settings.APPLICATION_MODE.set((ApplicationMode) newValue);
}
return super.onPreferenceChange(preference, newValue);
}
public void showAppDirDialog() {
if (Build.VERSION.SDK_INT >= 19) {
showAppDirDialogV19();
return;
}
AlertDialog.Builder editalert = new AlertDialog.Builder(getContext());
editalert.setTitle(R.string.application_dir);
final EditText input = new EditText(getContext());
input.setText(settings.getExternalStorageDirectory().getAbsolutePath());
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT);
lp.leftMargin = lp.rightMargin = 5;
lp.bottomMargin = lp.topMargin = 5;
input.setLayoutParams(lp);
settings.getExternalStorageDirectory().getAbsolutePath();
editalert.setView(input);
editalert.setNegativeButton(R.string.shared_string_cancel, null);
editalert.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
warnAboutChangingStorage(input.getText().toString());
}
});
editalert.show();
}
private void showAppDirDialogV19() {
AlertDialog.Builder bld = new AlertDialog.Builder(getContext());
DashChooseAppDirFragment.ChooseAppDirFragment chooseAppDirFragment = new DashChooseAppDirFragment.ChooseAppDirFragment(getActivity(), (Dialog) null) {
@Override
protected void successCallback() {
updateApplicationDirTextAndSummary();
}
};
if (permissionRequested && !permissionGranted) {
chooseAppDirFragment.setPermissionDenied();
}
bld.setView(chooseAppDirFragment.initView(getLayoutInflater(), null, null));
AlertDialog dlg = bld.show();
chooseAppDirFragment.setDialog(dlg);
}
private void warnAboutChangingStorage(final String newValue) {
String newDir = newValue != null ? newValue.trim() : newValue;
if (!newDir.replace('/', ' ').trim().
toLowerCase().endsWith(IndexConstants.APP_DIR.replace('/', ' ').trim())) {
newDir += "/" + IndexConstants.APP_DIR;
}
final File path = new File(newDir);
path.mkdirs();
if (!path.canRead() || !path.exists()) {
Toast.makeText(getContext(), R.string.specified_dir_doesnt_exist, Toast.LENGTH_LONG).show();
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder.setMessage(getString(R.string.application_dir_change_warning3));
builder.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
DashChooseAppDirFragment.MoveFilesToDifferentDirectory task =
new DashChooseAppDirFragment.MoveFilesToDifferentDirectory(getContext(),
settings.getExternalStorageDirectory(), path);
task.setRunOnSuccess(new Runnable() {
@Override
public void run() {
updateSettingsToNewDir(path.getParentFile().getAbsolutePath());
}
});
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
});
builder.setNeutralButton(R.string.shared_string_no, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
updateSettingsToNewDir(path.getParentFile().getAbsolutePath());
}
});
builder.setNegativeButton(R.string.shared_string_cancel, null);
builder.show();
}
private void updateSettingsToNewDir(final String newDir) {
// edit the preference
settings.setExternalStorageDirectoryPre19(newDir);
app.getResourceManager().resetStoreDirectory();
reloadIndexes();
updateApplicationDirTextAndSummary();
}
private void updateApplicationDirTextAndSummary() {
if (applicationDir != null) {
String storageDir = settings.getExternalStorageDirectory().getAbsolutePath();
applicationDir.setSummary(storageDir);
}
}
public void reloadIndexes() {
final Toolbar toolbar = getView().findViewById(R.id.toolbar);
setProgressVisibility(true);
final CharSequence oldTitle = toolbar.getTitle();
toolbar.setTitle(getString(R.string.loading_data));
toolbar.setSubtitle(getString(R.string.reading_indexes));
new AsyncTask<Void, Void, List<String>>() {
@Override
protected List<String> doInBackground(Void... params) {
return getMyApplication().getResourceManager().reloadIndexes(IProgress.EMPTY_PROGRESS,
new ArrayList<String>());
}
protected void onPostExecute(List<String> result) {
showWarnings(result);
toolbar.setTitle(oldTitle);
toolbar.setSubtitle("");
setProgressVisibility(false);
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
protected void setProgressVisibility(boolean visibility) {
if (visibility) {
getView().findViewById(R.id.ProgressBar).setVisibility(View.VISIBLE);
} else {
getView().findViewById(R.id.ProgressBar).setVisibility(View.GONE);
}
}
protected void showWarnings(List<String> warnings) {
if (!warnings.isEmpty()) {
final StringBuilder b = new StringBuilder();
boolean f = true;
for (String w : warnings) {
if (f) {
f = false;
} else {
b.append('\n');
}
b.append(w);
}
app.runInUIThread(new Runnable() {
@Override
public void run() {
Toast.makeText(getContext(), b.toString(), Toast.LENGTH_LONG).show();
}
});
}
}
@Override
public void onResume() {
super.onResume();
if (permissionRequested) {
showAppDirDialogV19();
permissionRequested = false;
}
}
@Override
public void onRequestPermissionsResult(int requestCode,
String permissions[], int[] grantResults) {
permissionRequested = requestCode == DownloadActivity.PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE;
if (permissionRequested
&& grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
permissionGranted = true;
} else {
permissionGranted = false;
Toast.makeText(getContext(),
R.string.missing_write_external_storage_permission,
Toast.LENGTH_LONG).show();
}
}
}

View file

@ -1,33 +1,19 @@
package net.osmand.plus.settings; package net.osmand.plus.settings;
import android.os.Bundle;
import android.support.v14.preference.SwitchPreference;
import android.support.v4.app.FragmentManager;
import android.support.v7.preference.Preference; import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
import net.osmand.plus.OsmandSettings.AutoZoomMap;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.views.ListFloatPreference; import net.osmand.plus.settings.preferences.ListPreferenceEx;
import net.osmand.plus.views.ListIntPreference; import net.osmand.plus.settings.preferences.SwitchPreferenceEx;
public class MapDuringNavigationFragment extends BaseSettingsFragment { public class MapDuringNavigationFragment extends BaseSettingsFragment {
public static final String TAG = "MapDuringNavigationFragment"; public static final String TAG = "MapDuringNavigationFragment";
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { protected int getPreferencesResId() {
View view = super.onCreateView(inflater, container, savedInstanceState);
return view;
}
@Override
protected int getPreferenceResId() {
return R.xml.map_during_navigation; return R.xml.map_during_navigation;
} }
@ -36,74 +22,114 @@ public class MapDuringNavigationFragment extends BaseSettingsFragment {
return R.layout.profile_preference_toolbar; return R.layout.profile_preference_toolbar;
} }
@Override
protected String getToolbarTitle() { protected String getToolbarTitle() {
return getString(R.string.map_during_navigation); return getString(R.string.map_during_navigation);
} }
protected void createUI() { @Override
PreferenceScreen screen = getPreferenceScreen(); protected void setupPreferences() {
Preference mapDuringNavigationInfo = findPreference("map_during_navigation_info");
mapDuringNavigationInfo.setTitle(R.string.map_during_navigation_info);
mapDuringNavigationInfo.setIcon(getContentIcon(R.drawable.ic_action_info_dark));
int[] intValues = new int[]{0, 5, 10, 15, 20, 25, 30, 45, 60, 90}; setupAutoFollowPref();
String[] entries = new String[intValues.length]; setupAutoZoomMapPref();
setupSnapToRoadPref();
setupMapDirectionToCompassPref();
}
private void setupAutoFollowPref() {
Integer[] entryValues = new Integer[] {0, 5, 10, 15, 20, 25, 30, 45, 60, 90};
String[] entries = new String[entryValues.length];
entries[0] = getString(R.string.shared_string_never); entries[0] = getString(R.string.shared_string_never);
for (int i = 1; i < intValues.length; i++) { for (int i = 1; i < entryValues.length; i++) {
entries[i] = intValues[i] + " " + getString(R.string.int_seconds); entries[i] = (int) entryValues[i] + " " + getString(R.string.int_seconds);
} }
ListIntPreference autoFollowRoute = (ListIntPreference) findAndRegisterPreference(settings.AUTO_FOLLOW_ROUTE.getId());
ListPreferenceEx autoFollowRoute = (ListPreferenceEx) findPreference(settings.AUTO_FOLLOW_ROUTE.getId());
autoFollowRoute.setEntries(entries); autoFollowRoute.setEntries(entries);
autoFollowRoute.setEntryValues(intValues); autoFollowRoute.setEntryValues(entryValues);
}
Preference autoZoomMap = findAndRegisterPreference(settings.AUTO_ZOOM_MAP.getId()); private void setupAutoZoomMapPref() {
autoZoomMap.setOnPreferenceClickListener(this); Integer[] entryValues = new Integer[AutoZoomMap.values().length + 1];
String[] entries = new String[entryValues.length];
SwitchPreference snapToRoad = (SwitchPreference) findAndRegisterPreference(settings.SNAP_TO_ROAD.getId()); int i = 0;
int selectedIndex = -1;
entries[i] = getString(R.string.auto_zoom_none);
entryValues[0] = 0;
if (!settings.AUTO_ZOOM_MAP.get()) {
selectedIndex = 0;
}
i++;
for (AutoZoomMap autoZoomMap : AutoZoomMap.values()) {
entries[i] = getString(autoZoomMap.name);
entryValues[i] = i;
if (selectedIndex == -1 && settings.AUTO_ZOOM_MAP_SCALE.get() == autoZoomMap) {
selectedIndex = i;
}
i++;
}
if (selectedIndex == -1) {
selectedIndex = 0;
}
String[] speedNamesPos; ListPreferenceEx autoZoomMapPref = (ListPreferenceEx) findPreference(settings.AUTO_ZOOM_MAP.getId());
float[] speedLimitsPos; autoZoomMapPref.setEntries(entries);
autoZoomMapPref.setEntryValues(entryValues);
autoZoomMapPref.setValue(selectedIndex);
autoZoomMapPref.setPersistent(false);
}
private void setupSnapToRoadPref() {
SwitchPreferenceEx snapToRoad = (SwitchPreferenceEx) findPreference(settings.SNAP_TO_ROAD.getId());
snapToRoad.setTitle(getString(R.string.snap_to_road));
snapToRoad.setSummaryOn(R.string.shared_string_on);
snapToRoad.setSummaryOff(R.string.shared_string_off);
snapToRoad.setDescription(getString(R.string.snap_to_road_descr));
}
private void setupMapDirectionToCompassPref() {
String[] entries;
Float[] entryValues;
if (settings.METRIC_SYSTEM.get() == OsmandSettings.MetricsConstants.KILOMETERS_AND_METERS) { if (settings.METRIC_SYSTEM.get() == OsmandSettings.MetricsConstants.KILOMETERS_AND_METERS) {
speedLimitsPos = new float[]{0f, 5f, 7f, 10f, 15f, 20f}; entryValues = new Float[] {0f, 5f, 7f, 10f, 15f, 20f};
speedNamesPos = new String[speedLimitsPos.length]; entries = new String[entryValues.length];
for (int i = 0; i < speedLimitsPos.length; i++) {
speedNamesPos[i] = (int) speedLimitsPos[i] + " " + getString(R.string.km_h); for (int i = 0; i < entryValues.length; i++) {
entries[i] = entryValues[i].intValue() + " " + getString(R.string.km_h);
} }
} else { } else {
Float[] speedLimitsMiles = new Float[]{-7f, -5f, -3f, 0f, 3f, 5f, 7f, 10f, 15f}; Float[] speedLimitsMiles = new Float[] {-7f, -5f, -3f, 0f, 3f, 5f, 7f, 10f, 15f};
speedLimitsPos = new float[]{0f, 3f, 5f, 7f, 10f, 15f}; entryValues = new Float[] {0f, 3f, 5f, 7f, 10f, 15f};
entries = new String[entryValues.length];
String[] speedNames = new String[speedLimitsMiles.length]; for (int i = 0; i < entries.length; i++) {
for (int i = 0; i < speedNames.length; i++) { entries[i] = speedLimitsMiles[i].intValue() + " " + getString(R.string.mile_per_hour);
speedNames[i] = speedLimitsMiles[i].intValue() + " " + getString(R.string.mile_per_hour);
}
speedNamesPos = new String[speedLimitsPos.length];
for (int i = 0; i < speedNamesPos.length; i++) {
speedNamesPos[i] = speedLimitsMiles[i].intValue() + " " + getString(R.string.mile_per_hour);
} }
} }
ListFloatPreference switchMapDirectionToCompass = (ListFloatPreference) findAndRegisterPreference(settings.SWITCH_MAP_DIRECTION_TO_COMPASS.getId()); ListPreferenceEx switchMapDirectionToCompass = (ListPreferenceEx) findPreference(settings.SWITCH_MAP_DIRECTION_TO_COMPASS.getId());
switchMapDirectionToCompass.setEntries(speedNamesPos); switchMapDirectionToCompass.setEntries(entries);
switchMapDirectionToCompass.setEntryValues(speedLimitsPos); switchMapDirectionToCompass.setEntryValues(entryValues);
} }
@Override @Override
public void onDisplayPreferenceDialog(Preference preference) { public boolean onPreferenceChange(Preference preference, Object newValue) {
String key = preference.getKey(); if (preference.getKey().equals(settings.AUTO_ZOOM_MAP.getId())) {
if (key != null && key.equals(settings.AUTO_ZOOM_MAP.getId())) { if (newValue instanceof Integer) {
Toast.makeText(getContext(), "onDisplayPreferenceDialog AUTO_ZOOM_MAP", Toast.LENGTH_LONG).show(); int position = (int) newValue;
} if (position == 0) {
super.onDisplayPreferenceDialog(preference); settings.AUTO_ZOOM_MAP.set(false);
} } else {
settings.AUTO_ZOOM_MAP.set(true);
public static boolean showInstance(FragmentManager fragmentManager) { settings.AUTO_ZOOM_MAP_SCALE.set(OsmandSettings.AutoZoomMap.values()[position - 1]);
try { }
MapDuringNavigationFragment settingsNavigationFragment = new MapDuringNavigationFragment(); return true;
fragmentManager.beginTransaction() }
.add(R.id.fragmentContainer, settingsNavigationFragment, MapDuringNavigationFragment.TAG)
.addToBackStack(MapDuringNavigationFragment.TAG)
.commitAllowingStateLoss();
return true;
} catch (Exception e) {
return false;
} }
return super.onPreferenceChange(preference, newValue);
} }
} }

View file

@ -0,0 +1,182 @@
package net.osmand.plus.settings;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.view.View;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.activities.SettingsBaseActivity;
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.LongDescriptionItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper;
import net.osmand.router.GeneralRouter;
import net.osmand.util.Algorithms;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class MultiSelectPreferencesBottomSheet extends MenuBottomSheetDialogFragment {
public static final String TAG = MultiSelectPreferencesBottomSheet.class.getSimpleName();
private static final String TITLE_KEY = "title_key";
private static final String DESCRIPTION_KEY = "description_key";
private static final String PREFERENCES_PARAMETERS_KEY = "preferences_parameters_key";
private RoutingOptionsHelper routingOptionsHelper;
private HashMap<String, Boolean> routingParametersMap;
private String title = "";
private String description = "";
String[] vals = null;
OsmandSettings.OsmandPreference[] bls = null;
@Override
public void createMenuItems(Bundle savedInstanceState) {
final OsmandApplication app = getMyApplication();
if (app == null) {
return;
}
routingOptionsHelper = app.getRoutingOptionsHelper();
if (savedInstanceState != null) {
if (savedInstanceState.containsKey(TITLE_KEY)) {
title = savedInstanceState.getString(PREFERENCES_PARAMETERS_KEY);
}
if (savedInstanceState.containsKey(DESCRIPTION_KEY)) {
description = savedInstanceState.getString(PREFERENCES_PARAMETERS_KEY);
}
if (savedInstanceState.containsKey(PREFERENCES_PARAMETERS_KEY)) {
routingParametersMap = (HashMap<String, Boolean>) savedInstanceState.getSerializable(PREFERENCES_PARAMETERS_KEY);
}
}
if (routingParametersMap == null) {
routingParametersMap = getRoutingParametersMap(app);
}
items.add(new TitleItem(title));
if (!Algorithms.isEmpty(description)) {
items.add(new LongDescriptionItem(description));
}
populateImpassableRoadsTypes();
}
private void populateImpassableRoadsTypes() {
OsmandApplication app = getMyApplication();
if (app == null) {
return;
}
for (Map.Entry<String, Boolean> entry : routingParametersMap.entrySet()) {
final String parameterId = entry.getKey();
boolean selected = entry.getValue();
GeneralRouter.RoutingParameter parameter = routingOptionsHelper.getRoutingPrefsForAppModeById(app.getRoutingHelper().getAppMode(), parameterId);
String defValue = "";
if (parameter != null) {
defValue = parameter.getName();
}
String parameterName = SettingsBaseActivity.getRoutingStringPropertyName(app, parameterId, defValue);
final BottomSheetItemWithCompoundButton[] item = new BottomSheetItemWithCompoundButton[1];
item[0] = (BottomSheetItemWithCompoundButton) new BottomSheetItemWithCompoundButton.Builder()
.setChecked(selected)
.setTitle(parameterName)
.setLayoutId(R.layout.bottom_sheet_item_with_switch_no_icon)
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
item[0].setChecked(!item[0].isChecked());
routingParametersMap.put(parameterId, item[0].isChecked());
}
})
.setTag(parameterId)
.create();
items.add(item[0]);
}
}
@Override
public void onResume() {
super.onResume();
for (BaseBottomSheetItem item : items) {
if (item instanceof BottomSheetItemWithCompoundButton) {
final String routingParameterId = (String) item.getTag();
((BottomSheetItemWithCompoundButton) item).setChecked(routingParametersMap.get(routingParameterId));
}
}
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putSerializable(PREFERENCES_PARAMETERS_KEY, routingParametersMap);
}
@Override
protected int getRightBottomButtonTextId() {
return R.string.shared_string_apply;
}
@Override
protected void onRightBottomButtonClick() {
final OsmandApplication app = getMyApplication();
if (app == null) {
return;
}
for (Map.Entry<String, Boolean> entry : routingParametersMap.entrySet()) {
String parameterId = entry.getKey();
GeneralRouter.RoutingParameter parameter = routingOptionsHelper.getRoutingPrefsForAppModeById(app.getRoutingHelper().getAppMode(), parameterId);
if (parameter != null) {
boolean checked = entry.getValue();
OsmandSettings.CommonPreference<Boolean> preference = app.getSettings().getCustomRoutingBooleanProperty(parameter.getId(), parameter.getDefaultBoolean());
preference.setModeValue(app.getRoutingHelper().getAppMode(), checked);
}
}
app.getRoutingHelper().recalculateRouteDueToSettingsChange();
dismiss();
}
@NonNull
private HashMap<String, Boolean> getRoutingParametersMap(OsmandApplication app) {
HashMap<String, Boolean> res = new HashMap<>();
List<GeneralRouter.RoutingParameter> avoidParameters = routingOptionsHelper.getAvoidRoutingPrefsForAppMode(app.getRoutingHelper().getAppMode());
for (GeneralRouter.RoutingParameter parameter : avoidParameters) {
OsmandSettings.CommonPreference<Boolean> preference = app.getSettings().getCustomRoutingBooleanProperty(parameter.getId(), parameter.getDefaultBoolean());
res.put(parameter.getId(), preference.getModeValue(app.getRoutingHelper().getAppMode()));
}
return res;
}
public static boolean showInstance(@NonNull FragmentManager fragmentManager, String title, String description, String[] vals, OsmandSettings.OsmandPreference[] bls, Fragment target) {
try {
Bundle args = new Bundle();
MultiSelectPreferencesBottomSheet fragment = new MultiSelectPreferencesBottomSheet();
fragment.title = title;
fragment.description = description;
fragment.vals = vals;
fragment.bls = bls;
fragment.setTargetFragment(target, 0);
fragment.setArguments(args);
fragment.show(fragmentManager, TAG);
return true;
} catch (RuntimeException e) {
return false;
}
}
}

View file

@ -1,82 +1,45 @@
package net.osmand.plus.settings; package net.osmand.plus.settings;
import android.os.Bundle;
import android.support.v14.preference.SwitchPreference; import android.support.v14.preference.SwitchPreference;
import android.support.v4.app.FragmentManager;
import android.support.v7.preference.Preference; import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.R; import net.osmand.plus.R;
import static net.osmand.plus.settings.profiles.SettingsProfileFragment.PROFILE_STRING_KEY;
public class NavigationFragment extends BaseSettingsFragment { public class NavigationFragment extends BaseSettingsFragment {
public static final String TAG = "NavigationFragment"; public static final String TAG = "NavigationFragment";
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { protected int getPreferencesResId() {
View view = super.onCreateView(inflater, container, savedInstanceState); return R.xml.navigation_settings_new;
return view;
} }
@Override
protected int getPreferenceResId() {
return R.xml.navigation_settings;
}
@Override @Override
protected int getToolbarResId() { protected int getToolbarResId() {
return R.layout.profile_preference_toolbar_big; return R.layout.profile_preference_toolbar_big;
} }
@Override
protected String getToolbarTitle() { protected String getToolbarTitle() {
return getString(R.string.routing_settings_2); return getString(R.string.routing_settings_2);
} }
@Override @Override
protected void createUI() { protected void setupPreferences() {
PreferenceScreen screen = getPreferenceScreen(); Preference routeParameters = findPreference("route_parameters");
SwitchPreference showRoutingAlarms = (SwitchPreference) findPreference("show_routing_alarms");
SwitchPreference speakRoutingAlarms = (SwitchPreference) findPreference("speak_routing_alarms");
Preference vehicleParameters = findPreference("vehicle_parameters");
Preference mapDuringNavigation = findPreference("map_during_navigation");
SwitchPreference turnScreenOn = (SwitchPreference) findPreference("turn_screen_on");
Preference route_parameters = findAndRegisterPreference("route_parameters"); routeParameters.setIcon(getContentIcon(R.drawable.ic_action_route_distance));
showRoutingAlarms.setIcon(getContentIcon(R.drawable.ic_action_alert));
speakRoutingAlarms.setIcon(getContentIcon(R.drawable.ic_action_volume_up));
SwitchPreference show_routing_alarms = (SwitchPreference) findAndRegisterPreference("show_routing_alarms"); int iconRes = getSelectedAppMode().getIconRes();
SwitchPreference speak_routing_alarms = (SwitchPreference) findAndRegisterPreference("speak_routing_alarms"); vehicleParameters.setIcon(getContentIcon(iconRes));
Preference vehicle_parameters = findAndRegisterPreference("vehicle_parameters");
Preference map_during_navigation = findAndRegisterPreference("map_during_navigation");
SwitchPreference turn_screen_on = (SwitchPreference) findAndRegisterPreference("turn_screen_on");
Preference reset_to_default = findAndRegisterPreference("reset_to_default");
route_parameters.setIcon(getContentIcon(R.drawable.ic_action_track_16)); turnScreenOn.setIcon(getContentIcon(R.drawable.ic_action_turn_screen_on));
show_routing_alarms.setIcon(getContentIcon(R.drawable.ic_action_alert));
speak_routing_alarms.setIcon(getContentIcon(R.drawable.ic_action_volume_up));
vehicle_parameters.setIcon(getContentIcon(R.drawable.ic_action_car_dark));
map_during_navigation.setIcon(getContentIcon(R.drawable.ic_action_mapillary));
turn_screen_on.setIcon(getContentIcon(R.drawable.ic_action_appearance));
reset_to_default.setIcon(getContentIcon(R.drawable.ic_action_undo_dark));
}
public static boolean showInstance(FragmentManager fragmentManager, ApplicationMode mode) {
try {
Bundle args = new Bundle();
args.putString(PROFILE_STRING_KEY, mode.getStringKey());
NavigationFragment settingsNavigationFragment = new NavigationFragment();
settingsNavigationFragment.setArguments(args);
fragmentManager.beginTransaction()
.add(R.id.fragmentContainer, settingsNavigationFragment, NavigationFragment.TAG)
.addToBackStack(NavigationFragment.TAG)
.commitAllowingStateLoss();
return true;
} catch (Exception e) {
return false;
}
} }
} }

View file

@ -1,298 +0,0 @@
package net.osmand.plus.settings;
import android.content.DialogInterface;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.AlertDialog;
import android.support.v7.preference.ListPreference;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
import android.support.v7.widget.AppCompatCheckedTextView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import net.osmand.data.PointDescription;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.base.MapViewTrackingUtilities;
import net.osmand.plus.views.ListIntPreference;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class ProfileGeneralSettings extends BaseSettingsFragment {
public static final String TAG = "ProfileGeneralSettings";
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = super.onCreateView(inflater, container, savedInstanceState);
return view;
}
@Override
protected int getPreferenceResId() {
return R.xml.general_profile_settings;
}
@Override
protected int getToolbarResId() {
return R.layout.profile_preference_toolbar;
}
protected String getToolbarTitle() {
return getString(R.string.general_settings_2);
}
protected void createUI() {
PreferenceScreen screen = getPreferenceScreen();
ListIntPreference appTheme = (ListIntPreference) findAndRegisterPreference(settings.OSMAND_THEME.getId());
appTheme.setEntries(new String[]{getString(R.string.dark_theme), getString(R.string.light_theme)});
appTheme.setEntryValues(new int[]{OsmandSettings.OSMAND_DARK_THEME, OsmandSettings.OSMAND_LIGHT_THEME});
updateAppThemePref();
ListIntPreference rotateMap = (ListIntPreference) findAndRegisterPreference(settings.ROTATE_MAP.getId());
rotateMap.setEntries(new String[]{getString(R.string.rotate_map_none_opt), getString(R.string.rotate_map_bearing_opt), getString(R.string.rotate_map_compass_opt)});
rotateMap.setEntryValues(new int[]{OsmandSettings.ROTATE_MAP_NONE, OsmandSettings.ROTATE_MAP_BEARING, OsmandSettings.ROTATE_MAP_COMPASS});
updateRotateMapPref();
ListIntPreference mapScreenOrientation = (ListIntPreference) findAndRegisterPreference(settings.MAP_SCREEN_ORIENTATION.getId());
mapScreenOrientation.setEntries(new String[]{getString(R.string.map_orientation_portrait), getString(R.string.map_orientation_landscape), getString(R.string.map_orientation_default)});
mapScreenOrientation.setEntryValues(new int[]{ActivityInfo.SCREEN_ORIENTATION_PORTRAIT, ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE, ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED});
updateMapScreenOrientationPref();
Preference defaultDrivingRegion = findAndRegisterPreference(settings.DRIVING_REGION.getId());
defaultDrivingRegion.setIcon(getContentIcon(R.drawable.ic_action_car_dark));
createUnitsOfLengthPref();
createCoordinatesFormatPref();
createAngularUnitsPref();
createExternalInputDevicePref();
}
private void createUnitsOfLengthPref() {
OsmandSettings.MetricsConstants[] mvls = OsmandSettings.MetricsConstants.values();
String[] entries = new String[mvls.length];
String[] entryValues = new String[mvls.length];
for (int i = 0; i < entries.length; i++) {
entries[i] = mvls[i].toHumanString(app);
entryValues[i] = mvls[i].name();
}
ListPreference unitsOfLength = (ListPreference) findAndRegisterPreference(settings.METRIC_SYSTEM.getId());
unitsOfLength.setEntries(entries);
unitsOfLength.setEntryValues(entryValues);
unitsOfLength.setIcon(getContentIcon(R.drawable.ic_action_ruler_unit));
}
private void createExternalInputDevicePref() {
String[] entries = new String[]{
getString(R.string.sett_no_ext_input),
getString(R.string.sett_generic_ext_input),
getString(R.string.sett_wunderlinq_ext_input),
getString(R.string.sett_parrot_ext_input)};
int[] entryValues = new int[]{
OsmandSettings.NO_EXTERNAL_DEVICE,
OsmandSettings.GENERIC_EXTERNAL_DEVICE,
OsmandSettings.WUNDERLINQ_EXTERNAL_DEVICE,
OsmandSettings.PARROT_EXTERNAL_DEVICE};
ListIntPreference externalInputDevice = (ListIntPreference) findAndRegisterPreference(settings.EXTERNAL_INPUT_DEVICE.getId());
externalInputDevice.setEntries(entries);
externalInputDevice.setEntryValues(entryValues);
int index = settings.EXTERNAL_INPUT_DEVICE.get();
externalInputDevice.setSummary(entries[index]);
}
private void createCoordinatesFormatPref() {
int[] cvls = new int[5];
cvls[0] = PointDescription.FORMAT_DEGREES;
cvls[1] = PointDescription.FORMAT_MINUTES;
cvls[2] = PointDescription.FORMAT_SECONDS;
cvls[3] = PointDescription.UTM_FORMAT;
cvls[4] = PointDescription.OLC_FORMAT;
String[] entries = new String[5];
entries[0] = PointDescription.formatToHumanString(getContext(), PointDescription.FORMAT_DEGREES);
entries[1] = PointDescription.formatToHumanString(getContext(), PointDescription.FORMAT_MINUTES);
entries[2] = PointDescription.formatToHumanString(getContext(), PointDescription.FORMAT_SECONDS);
entries[3] = PointDescription.formatToHumanString(getContext(), PointDescription.UTM_FORMAT);
entries[4] = PointDescription.formatToHumanString(getContext(), PointDescription.OLC_FORMAT);
ListIntPreference coordinatesFormat = (ListIntPreference) findAndRegisterPreference(settings.COORDINATES_FORMAT.getId());
coordinatesFormat.setEntries(entries);
coordinatesFormat.setEntryValues(cvls);
coordinatesFormat.setIcon(getContentIcon(R.drawable.ic_action_coordinates_widget));
}
private void createAngularUnitsPref() {
OsmandSettings.AngularConstants[] ac = OsmandSettings.AngularConstants.values();
String[] entries = new String[ac.length];
String[] entryValues = new String[ac.length];
for (int i = 0; i < entries.length; i++) {
if (ac[i] == OsmandSettings.AngularConstants.DEGREES) {
entries[i] = OsmandSettings.AngularConstants.DEGREES.toHumanString(app) + " 180";
entryValues[i] = OsmandSettings.AngularConstants.DEGREES.name();
} else if (ac[i] == OsmandSettings.AngularConstants.DEGREES360) {
entries[i] = OsmandSettings.AngularConstants.DEGREES.toHumanString(app) + " 360";
entryValues[i] = OsmandSettings.AngularConstants.DEGREES360.name();
} else {
entries[i] = ac[i].toHumanString(app);
entryValues[i] = OsmandSettings.AngularConstants.MILLIRADS.name();
}
}
ListPreference angularUnits = (ListPreference) findAndRegisterPreference(settings.ANGULAR_UNITS.getId());
angularUnits.setEntries(entries);
angularUnits.setEntryValues(entryValues);
angularUnits.setIcon(getContentIcon(R.drawable.ic_action_angular_unit));
}
private void updateAppThemePref() {
ListIntPreference appTheme = (ListIntPreference) findAndRegisterPreference(settings.OSMAND_THEME.getId());
int iconRes = settings.isLightContent() ? R.drawable.ic_action_sun : R.drawable.ic_action_moon;
appTheme.setIcon(getContentIcon(iconRes));
}
private void updateRotateMapPref() {
ListIntPreference rotateMap = (ListIntPreference) findAndRegisterPreference(settings.ROTATE_MAP.getId());
int iconRes;
if (settings.ROTATE_MAP.get() == OsmandSettings.ROTATE_MAP_NONE) {
iconRes = R.drawable.ic_action_direction_north;
} else if (settings.ROTATE_MAP.get() == OsmandSettings.ROTATE_MAP_BEARING) {
iconRes = R.drawable.ic_action_direction_movement;
} else {
iconRes = R.drawable.ic_action_direction_compass;
}
rotateMap.setIcon(getContentIcon(iconRes));
}
private void updateMapScreenOrientationPref() {
ListIntPreference mapScreenOrientation = (ListIntPreference) findAndRegisterPreference(settings.MAP_SCREEN_ORIENTATION.getId());
int iconRes;
if (settings.MAP_SCREEN_ORIENTATION.get() == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) {
iconRes = R.drawable.ic_action_phone_portrait_orientation;
} else if (settings.MAP_SCREEN_ORIENTATION.get() == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
iconRes = R.drawable.ic_action_phone_landscape_orientation;
} else {
iconRes = R.drawable.ic_action_phone_device_orientation;
}
mapScreenOrientation.setIcon(getContentIcon(iconRes));
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
boolean changed = super.onPreferenceChange(preference, newValue);
if (changed) {
String key = preference.getKey();
if (key.equals(settings.OSMAND_THEME.getId())) {
updateAppThemePref();
} else if (key.equals(settings.ROTATE_MAP.getId())) {
updateRotateMapPref();
} else if (key.equals(settings.MAP_SCREEN_ORIENTATION.getId())) {
updateMapScreenOrientationPref();
}
}
return changed;
}
@Override
public boolean onPreferenceClick(Preference preference) {
if (preference.getKey().equals(settings.DRIVING_REGION.getId())) {
showDrivingRegionDialog();
return true;
}
return false;
}
private void showDrivingRegionDialog() {
final AlertDialog.Builder b = new AlertDialog.Builder(getActivity());
b.setTitle(getString(R.string.driving_region));
final List<OsmandSettings.DrivingRegion> drs = new ArrayList<>();
drs.add(null);
drs.addAll(Arrays.asList(OsmandSettings.DrivingRegion.values()));
int sel = -1;
OsmandSettings.DrivingRegion selectedDrivingRegion = settings.DRIVING_REGION.get();
if (settings.DRIVING_REGION_AUTOMATIC.get()) {
sel = 0;
}
for (int i = 1; i < drs.size(); i++) {
if (sel == -1 && drs.get(i) == selectedDrivingRegion) {
sel = i;
break;
}
}
final int selected = sel;
final ArrayAdapter<OsmandSettings.DrivingRegion> singleChoiceAdapter =
new ArrayAdapter<OsmandSettings.DrivingRegion>(getActivity(), R.layout.single_choice_description_item, R.id.text1, drs) {
@NonNull
@Override
public View getView(int position, View convertView, @NonNull ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater inflater = getActivity().getLayoutInflater();
v = inflater.inflate(R.layout.single_choice_description_item, parent, false);
}
OsmandSettings.DrivingRegion item = getItem(position);
AppCompatCheckedTextView title = (AppCompatCheckedTextView) v.findViewById(R.id.text1);
TextView desc = (TextView) v.findViewById(R.id.description);
if (item != null) {
title.setText(getString(item.name));
desc.setVisibility(View.VISIBLE);
desc.setText(item.getDescription(v.getContext()));
} else {
title.setText(getString(R.string.driving_region_automatic));
desc.setVisibility(View.GONE);
}
title.setChecked(position == selected);
return v;
}
};
b.setAdapter(singleChoiceAdapter, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (drs.get(which) == null) {
settings.DRIVING_REGION_AUTOMATIC.set(true);
MapViewTrackingUtilities mapViewTrackingUtilities = getMyApplication().getMapViewTrackingUtilities();
if (mapViewTrackingUtilities != null) {
mapViewTrackingUtilities.resetDrivingRegionUpdate();
}
} else {
settings.DRIVING_REGION_AUTOMATIC.set(false);
settings.DRIVING_REGION.set(drs.get(which));
}
updateAllSettings();
}
});
b.setNegativeButton(R.string.shared_string_cancel, null);
b.show();
}
public static boolean showInstance(FragmentManager fragmentManager) {
try {
ProfileGeneralSettings profileGeneralSettingsSettings = new ProfileGeneralSettings();
fragmentManager.beginTransaction()
.add(R.id.fragmentContainer, profileGeneralSettingsSettings, ProfileGeneralSettings.TAG)
.addToBackStack(ProfileGeneralSettings.TAG)
.commitAllowingStateLoss();
return true;
} catch (Exception e) {
return false;
}
}
}

View file

@ -0,0 +1,101 @@
package net.osmand.plus.settings;
import android.support.v14.preference.SwitchPreference;
import android.support.v7.preference.Preference;
import android.widget.Toast;
import net.osmand.osm.io.NetworkUtils;
import net.osmand.plus.R;
import net.osmand.plus.settings.preferences.EditTextPreferenceEx;
import static net.osmand.plus.activities.SettingsGeneralActivity.IP_ADDRESS_PATTERN;
public class ProxySettingsFragment extends BaseSettingsFragment {
public static final String TAG = ProxySettingsFragment.class.getSimpleName();
@Override
protected int getPreferencesResId() {
return R.xml.proxy_preferences;
}
@Override
protected int getToolbarResId() {
return R.layout.global_preference_toolbar;
}
@Override
protected String getToolbarTitle() {
return getString(R.string.proxy_pref_title);
}
@Override
protected void setupPreferences() {
Preference mapDuringNavigationInfo = findPreference("proxy_preferences_info");
mapDuringNavigationInfo.setIcon(getContentIcon(R.drawable.ic_action_info_dark));
setupEnableProxyPref();
setupProxyHostPref();
setupProxyPortPref();
}
private void setupEnableProxyPref() {
SwitchPreference enableProxyPref = (SwitchPreference) findPreference(settings.ENABLE_PROXY.getId());
enableProxyPref.setSummaryOn(R.string.shared_string_on);
enableProxyPref.setSummaryOff(R.string.shared_string_off);
}
private void setupProxyHostPref() {
EditTextPreferenceEx hostPref = (EditTextPreferenceEx) findPreference(settings.PROXY_HOST.getId());
hostPref.setSummary(settings.PROXY_HOST.get());
hostPref.setDescription(R.string.proxy_host_descr);
}
private void setupProxyPortPref() {
EditTextPreferenceEx portPref = (EditTextPreferenceEx) findPreference(settings.PROXY_PORT.getId());
portPref.setSummary(String.valueOf(settings.PROXY_PORT.get()));
portPref.setDescription(R.string.proxy_port_descr);
}
protected void enableProxy(boolean enable) {
settings.ENABLE_PROXY.set(enable);
if (enable) {
NetworkUtils.setProxy(settings.PROXY_HOST.get(), settings.PROXY_PORT.get());
} else {
NetworkUtils.setProxy(null, 0);
}
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
String prefId = preference.getKey();
if (prefId.equals(settings.ENABLE_PROXY.getId())) {
enableProxy((Boolean) newValue);
} else if (prefId.equals(settings.PROXY_HOST.getId())) {
String ipAddress = (String) newValue;
if (ipAddress.matches(IP_ADDRESS_PATTERN)) {
settings.PROXY_HOST.set(ipAddress);
enableProxy(NetworkUtils.getProxy() != null);
setupProxyHostPref();
return true;
} else {
Toast.makeText(getContext(), getString(R.string.wrong_format), Toast.LENGTH_SHORT).show();
return false;
}
} else if (prefId.equals(settings.PROXY_PORT.getId())) {
int port = -1;
String portString = (String) newValue;
try {
port = Integer.valueOf(portString.replaceAll("[^0-9]", ""));
} catch (NumberFormatException e1) {
}
settings.PROXY_PORT.set(port);
enableProxy(NetworkUtils.getProxy() != null);
setupProxyPortPref();
return true;
}
return super.onPreferenceChange(preference, newValue);
}
}

View file

@ -1,22 +1,20 @@
package net.osmand.plus.settings; package net.osmand.plus.settings;
import android.os.Bundle; import android.content.Context;
import android.graphics.drawable.Drawable;
import android.support.v14.preference.SwitchPreference; import android.support.v14.preference.SwitchPreference;
import android.support.v4.app.FragmentManager;
import android.support.v7.preference.ListPreference;
import android.support.v7.preference.Preference; import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen; import android.support.v7.preference.PreferenceScreen;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
import net.osmand.plus.ApplicationMode; import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.SettingsBaseActivity; import net.osmand.plus.activities.SettingsBaseActivity;
import net.osmand.plus.routepreparationmenu.AvoidRoadsBottomSheetDialogFragment; import net.osmand.plus.activities.SettingsNavigationActivity;
import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper; import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper;
import net.osmand.plus.routing.RouteProvider; import net.osmand.plus.routing.RouteProvider;
import net.osmand.plus.settings.preferences.ListPreferenceEx;
import net.osmand.plus.settings.preferences.SwitchPreferenceEx;
import net.osmand.router.GeneralRouter; import net.osmand.router.GeneralRouter;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
@ -29,19 +27,18 @@ import static net.osmand.plus.activities.SettingsNavigationActivity.getRouter;
public class RouteParametersFragment extends BaseSettingsFragment { public class RouteParametersFragment extends BaseSettingsFragment {
public static final String TAG = "RouteParametersFragment"; public static final String TAG = "RouteParametersFragment";
private static final String AVOID_ROUTING_PARAMETER_PREFIX = "avoid_";
private static final String PREFER_ROUTING_PARAMETER_PREFIX = "prefer_";
private static final String RELIEF_SMOOTHNESS_FACTOR = "relief_smoothness_factor";
private List<GeneralRouter.RoutingParameter> avoidParameters = new ArrayList<GeneralRouter.RoutingParameter>(); private List<GeneralRouter.RoutingParameter> avoidParameters = new ArrayList<GeneralRouter.RoutingParameter>();
private List<GeneralRouter.RoutingParameter> preferParameters = new ArrayList<GeneralRouter.RoutingParameter>(); private List<GeneralRouter.RoutingParameter> preferParameters = new ArrayList<GeneralRouter.RoutingParameter>();
private List<GeneralRouter.RoutingParameter> reliefFactorParameters = new ArrayList<GeneralRouter.RoutingParameter>(); private List<GeneralRouter.RoutingParameter> reliefFactorParameters = new ArrayList<GeneralRouter.RoutingParameter>();
private List<GeneralRouter.RoutingParameter> otherRoutingParameters = new ArrayList<GeneralRouter.RoutingParameter>();
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { protected int getPreferencesResId() {
View view = super.onCreateView(inflater, container, savedInstanceState);
return view;
}
@Override
protected int getPreferenceResId() {
return R.xml.route_parameters; return R.xml.route_parameters;
} }
@ -50,82 +47,121 @@ public class RouteParametersFragment extends BaseSettingsFragment {
return R.layout.profile_preference_toolbar; return R.layout.profile_preference_toolbar;
} }
@Override
protected String getToolbarTitle() { protected String getToolbarTitle() {
return getString(R.string.route_parameters); return getString(R.string.route_parameters);
} }
public static boolean showInstance(FragmentManager fragmentManager) { @Override
try { protected void setupPreferences() {
RouteParametersFragment settingsNavigationFragment = new RouteParametersFragment(); setupRoutingPrefs();
fragmentManager.beginTransaction() setupTimeConditionalRoutingPref();
.add(R.id.fragmentContainer, settingsNavigationFragment, RouteParametersFragment.TAG)
.addToBackStack(RouteParametersFragment.TAG)
.commitAllowingStateLoss();
return true;
} catch (Exception e) {
return false;
}
} }
@Override private void setupTimeConditionalRoutingPref() {
protected void createUI() { SwitchPreference timeConditionalRouting = createSwitchPreferenceEx(settings.ENABLE_TIME_CONDITIONAL_ROUTING.getId(), R.string.temporary_conditional_routing, R.layout.preference_dialog_and_switch);
timeConditionalRouting.setIcon(getRoutingPrefIcon(settings.ENABLE_TIME_CONDITIONAL_ROUTING.getId()));
timeConditionalRouting.setSummaryOn(R.string.shared_string_enable);
timeConditionalRouting.setSummaryOff(R.string.shared_string_disable);
getPreferenceScreen().addPreference(timeConditionalRouting);
}
private void setupRoutingPrefs() {
Context ctx = getContext();
if (ctx == null) {
return;
}
PreferenceScreen screen = getPreferenceScreen(); PreferenceScreen screen = getPreferenceScreen();
SwitchPreference fastRoute = (SwitchPreference) findAndRegisterPreference(settings.FAST_ROUTE_MODE.getId()); SwitchPreferenceEx fastRoute = createSwitchPreferenceEx(settings.FAST_ROUTE_MODE.getId(), R.string.fast_route_mode, R.layout.preference_dialog_and_switch);
fastRoute.setIcon(getContentIcon(R.drawable.ic_action_fastest_route)); fastRoute.setIcon(getRoutingPrefIcon(settings.FAST_ROUTE_MODE.getId()));
fastRoute.setDescription(getString(R.string.fast_route_mode_descr));
fastRoute.setSummaryOn(R.string.shared_string_enable);
fastRoute.setSummaryOff(R.string.shared_string_disable);
if (settings.getApplicationMode().getRouteService() != RouteProvider.RouteService.OSMAND) { if (settings.getApplicationMode().getRouteService() != RouteProvider.RouteService.OSMAND) {
screen.addPreference(fastRoute); screen.addPreference(fastRoute);
} else { } else {
ApplicationMode am = settings.getApplicationMode(); ApplicationMode am = settings.getApplicationMode();
GeneralRouter router = getRouter(getMyApplication().getRoutingConfig(), am); GeneralRouter router = getRouter(getMyApplication().getRoutingConfig(), am);
clearParameters(); clearParameters();
if (router != null) { Map<String, GeneralRouter.RoutingParameter> parameters = router.getParameters(); if (router != null) {
Map<String, GeneralRouter.RoutingParameter> parameters = router.getParameters();
if (parameters.containsKey(GeneralRouter.USE_SHORTEST_WAY)) { if (parameters.containsKey(GeneralRouter.USE_SHORTEST_WAY)) {
screen.addPreference(fastRoute); screen.addPreference(fastRoute);
} else {
screen.removePreference(fastRoute);
} }
List<GeneralRouter.RoutingParameter> others = new ArrayList<GeneralRouter.RoutingParameter>();
for (Map.Entry<String, GeneralRouter.RoutingParameter> e : parameters.entrySet()) { for (Map.Entry<String, GeneralRouter.RoutingParameter> e : parameters.entrySet()) {
String param = e.getKey(); String param = e.getKey();
GeneralRouter.RoutingParameter routingParameter = e.getValue(); GeneralRouter.RoutingParameter routingParameter = e.getValue();
if (param.startsWith("avoid_")) { if (param.startsWith(AVOID_ROUTING_PARAMETER_PREFIX)) {
avoidParameters.add(routingParameter); avoidParameters.add(routingParameter);
} else if (param.startsWith("prefer_")) { } else if (param.startsWith(PREFER_ROUTING_PARAMETER_PREFIX)) {
preferParameters.add(routingParameter); preferParameters.add(routingParameter);
} else if ("relief_smoothness_factor".equals(routingParameter.getGroup())) { } else if (RELIEF_SMOOTHNESS_FACTOR.equals(routingParameter.getGroup())) {
reliefFactorParameters.add(routingParameter); reliefFactorParameters.add(routingParameter);
} else if (!param.equals(GeneralRouter.USE_SHORTEST_WAY) } else if (!param.equals(GeneralRouter.USE_SHORTEST_WAY)
&& !RoutingOptionsHelper.DRIVING_STYLE.equals(routingParameter.getGroup()) && !param.equals(GeneralRouter.VEHICLE_HEIGHT)
&& !param.equals(GeneralRouter.VEHICLE_WEIGHT) && !param.equals(GeneralRouter.VEHICLE_WEIGHT)
&& !param.equals(GeneralRouter.VEHICLE_HEIGHT)) { && !RoutingOptionsHelper.DRIVING_STYLE.equals(routingParameter.getGroup())) {
others.add(routingParameter); otherRoutingParameters.add(routingParameter);
} }
} }
Preference avoidRouting = findAndRegisterPreference("avoid_in_routing");
if (avoidParameters.size() > 0) { if (avoidParameters.size() > 0) {
avoidRouting.setOnPreferenceClickListener(this); Preference avoidRouting = new Preference(ctx);
avoidRouting.setIcon(getContentIcon(R.drawable.ic_action_alert)); avoidRouting.setKey(AVOID_ROUTING_PARAMETER_PREFIX);
} else { avoidRouting.setTitle(R.string.avoid_in_routing_title);
screen.removePreference(avoidRouting); avoidRouting.setSummary(R.string.avoid_in_routing_descr);
avoidRouting.setLayoutResource(R.layout.preference_with_descr);
avoidRouting.setIcon(getRoutingPrefIcon(AVOID_ROUTING_PARAMETER_PREFIX));
screen.addPreference(avoidRouting);
} }
Preference preferRouting = findAndRegisterPreference("prefer_in_routing");
if (preferParameters.size() > 0) { if (preferParameters.size() > 0) {
preferRouting.setOnPreferenceClickListener(this); Preference preferRouting = new Preference(ctx);
} else { preferRouting.setKey(PREFER_ROUTING_PARAMETER_PREFIX);
screen.removePreference(preferRouting); preferRouting.setTitle(R.string.prefer_in_routing_title);
preferRouting.setSummary(R.string.prefer_in_routing_descr);
preferRouting.setLayoutResource(R.layout.preference_with_descr);
screen.addPreference(preferRouting);
} }
if (reliefFactorParameters.size() > 0) { if (reliefFactorParameters.size() > 0) {
Preference reliefFactorRouting = new Preference(getContext()); String defaultTitle = Algorithms.capitalizeFirstLetterAndLowercase(RELIEF_SMOOTHNESS_FACTOR.replace('_', ' '));
reliefFactorRouting.setTitle(SettingsBaseActivity.getRoutingStringPropertyName(getContext(), reliefFactorParameters.get(0).getGroup(), String title = SettingsBaseActivity.getRoutingStringPropertyName(ctx, RELIEF_SMOOTHNESS_FACTOR, defaultTitle);
Algorithms.capitalizeFirstLetterAndLowercase(reliefFactorParameters.get(0).getGroup().replace('_', ' '))));
reliefFactorRouting.setSummary(R.string.relief_smoothness_factor_descr); Object[] entryValues = new Object[reliefFactorParameters.size()];
String[] entries = new String[entryValues.length];
String selectedParameterId = null;
for (int i = 0; i < reliefFactorParameters.size(); i++) {
GeneralRouter.RoutingParameter parameter = reliefFactorParameters.get(i);
entryValues[i] = parameter.getId();
entries[i] = SettingsNavigationActivity.getRoutinParameterTitle(getContext(), parameter);
if (SettingsNavigationActivity.isRoutingParameterSelected(settings, am, parameter)) {
selectedParameterId = parameter.getId();
}
}
ListPreferenceEx reliefFactorRouting = createListPreferenceEx(RELIEF_SMOOTHNESS_FACTOR, entries, entryValues, title, R.layout.preference_with_descr);
reliefFactorRouting.setPersistent(false);
reliefFactorRouting.setValue(selectedParameterId);
reliefFactorRouting.setDescription(R.string.relief_smoothness_factor_descr);
screen.addPreference(reliefFactorRouting); screen.addPreference(reliefFactorRouting);
} }
for (GeneralRouter.RoutingParameter p : others) { for (GeneralRouter.RoutingParameter p : otherRoutingParameters) {
Preference basePref; String title = SettingsBaseActivity.getRoutingStringPropertyName(ctx, p.getId(), p.getName());
String description = SettingsBaseActivity.getRoutingStringPropertyDescription(ctx, p.getId(), p.getDescription());
if (p.getType() == GeneralRouter.RoutingParameterType.BOOLEAN) { if (p.getType() == GeneralRouter.RoutingParameterType.BOOLEAN) {
basePref = createSwitchPreference(settings.getCustomRoutingBooleanProperty(p.getId(), p.getDefaultBoolean())); OsmandSettings.OsmandPreference pref = settings.getCustomRoutingBooleanProperty(p.getId(), p.getDefaultBoolean());
SwitchPreferenceEx switchPreferenceEx = (SwitchPreferenceEx) createSwitchPreferenceEx(pref.getId(), title, description, R.layout.preference_dialog_and_switch);
switchPreferenceEx.setDescription(description);
switchPreferenceEx.setIcon(getRoutingPrefIcon(p.getId()));
switchPreferenceEx.setSummaryOn(R.string.shared_string_enable);
switchPreferenceEx.setSummaryOff(R.string.shared_string_disable);
screen.addPreference(switchPreferenceEx);
} else { } else {
Object[] vls = p.getPossibleValues(); Object[] vls = p.getPossibleValues();
String[] svlss = new String[vls.length]; String[] svlss = new String[vls.length];
@ -133,17 +169,15 @@ public class RouteParametersFragment extends BaseSettingsFragment {
for (Object o : vls) { for (Object o : vls) {
svlss[i++] = o.toString(); svlss[i++] = o.toString();
} }
basePref = createListPreference(settings.getCustomRoutingProperty(p.getId(), OsmandSettings.OsmandPreference pref = settings.getCustomRoutingProperty(p.getId(), p.getType() == GeneralRouter.RoutingParameterType.NUMERIC ? "0.0" : "-");
p.getType() == GeneralRouter.RoutingParameterType.NUMERIC ? "0.0" : "-"),
p.getPossibleValueDescriptions(), svlss, ListPreferenceEx listPreferenceEx = (ListPreferenceEx) createListPreferenceEx(pref.getId(), p.getPossibleValueDescriptions(), svlss, title, R.layout.preference_with_descr);
SettingsBaseActivity.getRoutingStringPropertyName(getContext(), p.getId(), p.getName()),
SettingsBaseActivity.getRoutingStringPropertyDescription(getContext(), p.getId(), p.getDescription())); listPreferenceEx.setDescription(description);
((ListPreference) basePref).setEntries(p.getPossibleValueDescriptions()); listPreferenceEx.setIcon(getRoutingPrefIcon(p.getId()));
((ListPreference) basePref).setEntryValues(svlss);
screen.addPreference(listPreferenceEx);
} }
basePref.setTitle(SettingsBaseActivity.getRoutingStringPropertyName(getContext(), p.getId(), p.getName()));
basePref.setSummary(SettingsBaseActivity.getRoutingStringPropertyDescription(getContext(), p.getId(), p.getDescription()));
screen.addPreference(basePref);
} }
} }
} }
@ -152,28 +186,63 @@ public class RouteParametersFragment extends BaseSettingsFragment {
@Override @Override
public boolean onPreferenceClick(Preference preference) { public boolean onPreferenceClick(Preference preference) {
String key = preference.getKey(); String key = preference.getKey();
switch (key) {
case "avoid_in_routing": { if (key.equals(AVOID_ROUTING_PARAMETER_PREFIX) || key.equals(PREFER_ROUTING_PARAMETER_PREFIX)) {
AvoidRoadsBottomSheetDialogFragment avoidRoadsFragment = new AvoidRoadsBottomSheetDialogFragment(true); List<GeneralRouter.RoutingParameter> prms = key.equals(AVOID_ROUTING_PARAMETER_PREFIX) ? avoidParameters : preferParameters;
avoidRoadsFragment.setTargetFragment(RouteParametersFragment.this, AvoidRoadsBottomSheetDialogFragment.REQUEST_CODE); String[] vals = new String[prms.size()];
avoidRoadsFragment.show(getActivity().getSupportFragmentManager(), AvoidRoadsBottomSheetDialogFragment.TAG); OsmandSettings.OsmandPreference[] bls = new OsmandSettings.OsmandPreference[prms.size()];
return true; for (int i = 0; i < prms.size(); i++) {
} GeneralRouter.RoutingParameter p = prms.get(i);
case "prefer_in_routing": { vals[i] = SettingsBaseActivity.getRoutingStringPropertyName(getContext(), p.getId(), p.getName());
// AvoidRoadsBottomSheetDialogFragment avoidRoadsFragment = new AvoidRoadsBottomSheetDialogFragment(true); bls[i] = settings.getCustomRoutingBooleanProperty(p.getId(), p.getDefaultBoolean());
// avoidRoadsFragment.setTargetFragment(RouteParametersFragment.this, AvoidRoadsBottomSheetDialogFragment.REQUEST_CODE);
// avoidRoadsFragment.show(getActivity().getSupportFragmentManager(), AvoidRoadsBottomSheetDialogFragment.TAG);
Toast.makeText(getContext(), "prefer_in_routing", Toast.LENGTH_LONG).show();
return true;
} }
SettingsNavigationActivity.showBooleanSettings(getContext(), vals, bls, preference.getTitle());
MultiSelectPreferencesBottomSheet.showInstance(getFragmentManager(), preference.getTitle().toString(), preference.getTitle().toString(), vals, bls, this);
return false;
} }
return false; return super.onPreferenceClick(preference);
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
String key = preference.getKey();
if (RELIEF_SMOOTHNESS_FACTOR.equals(key)) {
if (newValue instanceof String) {
String selectedParameterId = (String) newValue;
for (GeneralRouter.RoutingParameter parameter : reliefFactorParameters) {
String parameterId = parameter.getId();
SettingsNavigationActivity.setRoutingParameterSelected(settings, getSelectedAppMode(), parameterId, parameter.getDefaultBoolean(), parameterId.equals(selectedParameterId));
}
}
return true;
}
return super.onPreferenceChange(preference, newValue);
} }
private void clearParameters() { private void clearParameters() {
preferParameters.clear(); preferParameters.clear();
avoidParameters.clear(); avoidParameters.clear();
reliefFactorParameters.clear(); reliefFactorParameters.clear();
otherRoutingParameters.clear();
}
private Drawable getRoutingPrefIcon(String prefId) {
switch (prefId) {
case GeneralRouter.ALLOW_PRIVATE:
return getIcon(R.drawable.ic_action_private_access);
case AVOID_ROUTING_PARAMETER_PREFIX:
return getContentIcon(R.drawable.ic_action_alert);
case "fast_route_mode":
return getIcon(R.drawable.ic_action_fastest_route);
case "enable_time_conditional_routing":
return getContentIcon(R.drawable.ic_action_road_works_dark);
default:
return null;
}
} }
} }

View file

@ -1,13 +1,7 @@
package net.osmand.plus.settings; package net.osmand.plus.settings;
import android.os.Bundle;
import android.support.v14.preference.SwitchPreference; import android.support.v14.preference.SwitchPreference;
import android.support.v4.app.FragmentManager;
import android.support.v7.preference.Preference; import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import net.osmand.plus.R; import net.osmand.plus.R;
@ -16,14 +10,7 @@ public class ScreenAlertsFragment extends BaseSettingsFragment {
public static final String TAG = "ScreenAlertsFragment"; public static final String TAG = "ScreenAlertsFragment";
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { protected int getPreferencesResId() {
View view = super.onCreateView(inflater, container, savedInstanceState);
return view;
}
@Override
protected int getPreferenceResId() {
return R.xml.screen_alerts; return R.xml.screen_alerts;
} }
@ -37,35 +24,22 @@ public class ScreenAlertsFragment extends BaseSettingsFragment {
} }
@Override @Override
protected void createUI() { protected void setupPreferences() {
PreferenceScreen screen = getPreferenceScreen(); Preference showRoutingAlarmsInfo = findPreference("show_routing_alarms_info");
SwitchPreference SHOW_ROUTING_ALARMS = (SwitchPreference) findAndRegisterPreference(settings.SHOW_ROUTING_ALARMS.getId()); SwitchPreference showRoutingAlarms = (SwitchPreference) findPreference(settings.SHOW_ROUTING_ALARMS.getId());
Preference SHOW_TRAFFIC_WARNINGS_DESCR = findAndRegisterPreference("show_routing_alarms_descr"); showRoutingAlarms.setSummaryOn(R.string.shared_string_on);
SwitchPreference SHOW_TRAFFIC_WARNINGS = (SwitchPreference) findAndRegisterPreference(settings.SHOW_TRAFFIC_WARNINGS.getId()); showRoutingAlarms.setSummaryOff(R.string.shared_string_off);
SwitchPreference SHOW_PEDESTRIAN = (SwitchPreference) findAndRegisterPreference(settings.SHOW_PEDESTRIAN.getId());
SwitchPreference SHOW_CAMERAS = (SwitchPreference) findAndRegisterPreference(settings.SHOW_CAMERAS.getId());
SwitchPreference SHOW_LANES = (SwitchPreference) findAndRegisterPreference(settings.SHOW_LANES.getId());
SwitchPreference SHOW_TUNNELS = (SwitchPreference) findAndRegisterPreference(settings.SHOW_TUNNELS.getId());
SHOW_TRAFFIC_WARNINGS_DESCR.setIcon(getContentIcon(R.drawable.ic_action_info_dark)); SwitchPreference showTrafficWarnings = (SwitchPreference) findPreference(settings.SHOW_TRAFFIC_WARNINGS.getId());
SHOW_TRAFFIC_WARNINGS.setIcon(getIcon(R.drawable.list_warnings_traffic_calming)); SwitchPreference showPedestrian = (SwitchPreference) findPreference(settings.SHOW_PEDESTRIAN.getId());
SHOW_PEDESTRIAN.setIcon(getIcon(R.drawable.list_warnings_pedestrian)); SwitchPreference showCameras = (SwitchPreference) findPreference(settings.SHOW_CAMERAS.getId());
SHOW_CAMERAS.setIcon(getIcon(R.drawable.list_warnings_speed_camera)); SwitchPreference showTunnels = (SwitchPreference) findPreference(settings.SHOW_TUNNELS.getId());
SHOW_LANES.setIcon(getIcon(R.drawable.ic_action_lanes));
SHOW_TUNNELS.setIcon(getIcon(R.drawable.list_warnings_tunnel));
}
public static boolean showInstance(FragmentManager fragmentManager) { showRoutingAlarmsInfo.setIcon(getContentIcon(R.drawable.ic_action_info_dark));
try { showTrafficWarnings.setIcon(getIcon(R.drawable.list_warnings_traffic_calming));
ScreenAlertsFragment settingsNavigationFragment = new ScreenAlertsFragment(); showPedestrian.setIcon(getIcon(R.drawable.list_warnings_pedestrian));
fragmentManager.beginTransaction() showCameras.setIcon(getIcon(R.drawable.list_warnings_speed_camera));
.add(R.id.fragmentContainer, settingsNavigationFragment, ScreenAlertsFragment.TAG) showTunnels.setIcon(getIcon(R.drawable.list_warnings_tunnel));
.addToBackStack(ScreenAlertsFragment.TAG)
.commitAllowingStateLoss();
return true;
} catch (Exception e) {
return false;
}
} }
} }

View file

@ -1,68 +1,56 @@
package net.osmand.plus.settings; package net.osmand.plus.settings;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentManager;
import android.support.v7.preference.Preference; import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import net.osmand.plus.ApplicationMode; import net.osmand.plus.ApplicationMode;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.profiles.SettingsProfileActivity;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import static net.osmand.plus.settings.profiles.EditProfileFragment.MAP_CONFIG; import static net.osmand.plus.profiles.EditProfileFragment.MAP_CONFIG;
import static net.osmand.plus.settings.profiles.EditProfileFragment.OPEN_CONFIG_ON_MAP; import static net.osmand.plus.profiles.EditProfileFragment.OPEN_CONFIG_ON_MAP;
import static net.osmand.plus.settings.profiles.EditProfileFragment.SELECTED_ITEM; import static net.osmand.plus.profiles.EditProfileFragment.SELECTED_ITEM;
public class SettingsMainFragment extends BaseSettingsFragment { public class SettingsMainFragment extends BaseSettingsFragment {
public static final String TAG = "SettingsMainFragment"; public static final String TAG = "SettingsMainFragment";
@Override @Override
protected int getPreferenceResId() { protected int getPreferencesResId() {
return R.xml.settings_main_screen; return R.xml.settings_main_screen;
} }
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = super.onCreateView(inflater, container, savedInstanceState);
return view;
}
@Override @Override
protected int getToolbarResId() { protected int getToolbarResId() {
return R.layout.global_preference_toolbar; return R.layout.global_preference_toolbar;
} }
@Override
protected String getToolbarTitle() { protected String getToolbarTitle() {
return getString(R.string.shared_string_settings); return getString(R.string.shared_string_settings);
} }
@Override @Override
protected void createUI() { protected void setupPreferences() {
PreferenceScreen screen = getPreferenceScreen(); Preference personalAccount = findPreference("personal_account");
Preference globalSettings = findPreference("global_settings");
Preference browseMap = findPreference("browse_map");
Preference configureProfile = findPreference("configure_profile");
Preference manageProfiles = findPreference("manage_profiles");
Preference personal_account = findAndRegisterPreference("personal_account"); personalAccount.setIcon(getContentIcon(R.drawable.ic_action_user));
Preference global_settings = findAndRegisterPreference("global_settings"); globalSettings.setIcon(getContentIcon(R.drawable.ic_action_settings));
Preference browse_map = findAndRegisterPreference("browse_map"); browseMap.setIcon(getContentIcon(R.drawable.ic_world_globe_dark));
Preference configure_profile = findAndRegisterPreference("configure_profile"); manageProfiles.setIcon(getIcon(R.drawable.ic_action_manage_profiles));
Preference manage_profiles = findAndRegisterPreference("manage_profiles");
personal_account.setIcon(getContentIcon(R.drawable.ic_person)); ApplicationMode selectedMode = getSelectedAppMode();
global_settings.setIcon(getContentIcon(R.drawable.ic_action_settings));
browse_map.setIcon(getContentIcon(R.drawable.ic_world_globe_dark));
manage_profiles.setIcon(getContentIcon(R.drawable.ic_action_manage_profiles));
final ApplicationMode selectedMode = getSelectedMode();
int iconRes = selectedMode.getIconRes(); int iconRes = selectedMode.getIconRes();
int iconColor = selectedMode.getIconColorInfo().getColor(!getSettings().isLightContent()); int iconColor = selectedMode.getIconColorInfo().getColor(isNightMode());
String title = selectedMode.isCustomProfile() ? selectedMode.getCustomProfileName() : getResources().getString(selectedMode.getNameKeyResource()); String title = selectedMode.toHumanString(getContext());
String profileType; String profileType;
if (selectedMode.isCustomProfile()) { if (selectedMode.isCustomProfile()) {
@ -71,9 +59,30 @@ public class SettingsMainFragment extends BaseSettingsFragment {
profileType = getString(R.string.profile_type_base_string); profileType = getString(R.string.profile_type_base_string);
} }
configure_profile.setIcon(getIcon(iconRes, iconColor)); configureProfile.setIcon(getIcon(iconRes, iconColor));
configure_profile.setTitle(title); configureProfile.setTitle(title);
configure_profile.setSummary(profileType); configureProfile.setSummary(profileType);
}
@Override
public int getStatusBarColorId() {
return isNightMode() ? R.color.status_bar_color_light : R.color.status_bar_color_dark;
}
@Override
public boolean onPreferenceClick(Preference preference) {
if (preference.getKey().equals("browse_map")) {
Intent intent = new Intent(getActivity(), MapActivity.class);
intent.putExtra(OPEN_CONFIG_ON_MAP, MAP_CONFIG);
intent.putExtra(SELECTED_ITEM, getSelectedAppMode().getStringKey());
startActivity(intent);
getActivity().getSupportFragmentManager().beginTransaction().remove(this).commit();
return true;
} else if (preference.getKey().equals("manage_profiles")) {
startActivity(new Intent(getActivity(), SettingsProfileActivity.class));
return true;
}
return super.onPreferenceClick(preference);
} }
public static boolean showInstance(FragmentManager fragmentManager) { public static boolean showInstance(FragmentManager fragmentManager) {
@ -88,23 +97,4 @@ public class SettingsMainFragment extends BaseSettingsFragment {
return false; return false;
} }
} }
@Override
public int getStatusBarColorId() {
return getSettings().isLightContent() ? R.color.status_bar_color_light : R.color.status_bar_color_dark;
}
@Override
public boolean onPreferenceClick(Preference preference) {
if (preference.getKey().equals("browse_map")) {
Intent intent = new Intent(getActivity(), MapActivity.class);
intent.putExtra(OPEN_CONFIG_ON_MAP, MAP_CONFIG);
intent.putExtra(SELECTED_ITEM, getSelectedMode().getStringKey());
startActivity(intent);
getActivity().getSupportFragmentManager().beginTransaction().remove(this).commit();
return true;
}
return super.onPreferenceClick(preference);
}
} }

View file

@ -0,0 +1,155 @@
package net.osmand.plus.settings;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v7.preference.DialogPreference;
import android.view.View;
import net.osmand.AndroidUtils;
import net.osmand.plus.R;
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.LongDescriptionItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
import net.osmand.plus.settings.preferences.ListPreferenceEx;
import net.osmand.util.Algorithms;
public class SingleSelectPreferenceBottomSheet extends MenuBottomSheetDialogFragment {
public static final String TAG = SingleSelectPreferenceBottomSheet.class.getSimpleName();
private static final String PREFERENCE_ID = "preference_id";
private static final String SELECTED_ENTRY_INDEX_KEY = "selected_entry_index_key";
private ListPreferenceEx listPreference;
private String[] entries;
private Object[] entryValues;
private int selectedEntryIndex = -1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
listPreference = getListPreference();
if (listPreference != null) {
entries = listPreference.getEntries();
entryValues = listPreference.getEntryValues();
if (savedInstanceState != null) {
selectedEntryIndex = savedInstanceState.getInt(SELECTED_ENTRY_INDEX_KEY);
} else {
selectedEntryIndex = listPreference.findIndexOfValue(listPreference.getValue());
}
}
}
@Override
public void createMenuItems(Bundle savedInstanceState) {
final Context context = getContext();
if (context == null || listPreference == null || entries == null || entryValues == null) {
return;
}
items.add(new TitleItem(listPreference.getDialogTitle().toString()));
String description = listPreference.getDescription();
if (!Algorithms.isEmpty(description)) {
items.add(new LongDescriptionItem(description));
}
for (int i = 0; i < entries.length; i++) {
final BaseBottomSheetItem[] preferenceItem = new BottomSheetItemWithCompoundButton[1];
preferenceItem[0] = new BottomSheetItemWithCompoundButton.Builder()
.setChecked(i == selectedEntryIndex)
.setButtonTintList(AndroidUtils.createCheckedColorStateList(context, R.color.icon_color_default_light, getActiveColorId()))
.setTitle(entries[i])
.setTag(i)
.setLayoutId(R.layout.bottom_sheet_item_with_radio_btn_left)
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
selectedEntryIndex = (int) preferenceItem[0].getTag();
updateItems();
}
})
.create();
items.add(preferenceItem[0]);
}
}
@Override
public void onResume() {
super.onResume();
updateItems();
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putInt(SELECTED_ENTRY_INDEX_KEY, selectedEntryIndex);
}
private void updateItems() {
for (BaseBottomSheetItem item : items) {
if (item instanceof BottomSheetItemWithCompoundButton) {
boolean checked = item.getTag().equals(selectedEntryIndex);
((BottomSheetItemWithCompoundButton) item).setChecked(checked);
}
}
}
private ListPreferenceEx getListPreference() {
if (listPreference == null) {
Bundle args = getArguments();
if (args != null) {
final String key = args.getString(PREFERENCE_ID);
Fragment targetFragment = getTargetFragment();
if (targetFragment instanceof DialogPreference.TargetFragment) {
DialogPreference.TargetFragment fragment = (DialogPreference.TargetFragment) targetFragment;
listPreference = (ListPreferenceEx) fragment.findPreference(key);
}
}
}
return listPreference;
}
@Override
protected int getDismissButtonTextId() {
return R.string.shared_string_close;
}
@Override
protected int getRightBottomButtonTextId() {
return R.string.shared_string_apply;
}
@Override
protected void onRightBottomButtonClick() {
if (selectedEntryIndex >= 0) {
Object value = entryValues[selectedEntryIndex];
if (listPreference.callChangeListener(value)) {
listPreference.setValue(value);
}
}
dismiss();
}
public static boolean showInstance(@NonNull FragmentManager fragmentManager, String key, Fragment target) {
try {
Bundle args = new Bundle();
args.putString(PREFERENCE_ID, key);
SingleSelectPreferenceBottomSheet fragment = new SingleSelectPreferenceBottomSheet();
fragment.setTargetFragment(target, 0);
fragment.setArguments(args);
fragment.show(fragmentManager, TAG);
return true;
} catch (RuntimeException e) {
return false;
}
}
}

View file

@ -1,71 +1,72 @@
package net.osmand.plus.settings; package net.osmand.plus.settings;
import android.os.Bundle;
import android.support.v14.preference.SwitchPreference; import android.support.v14.preference.SwitchPreference;
import android.support.v4.app.FragmentManager; import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.views.ListIntPreference; import net.osmand.plus.settings.preferences.ListPreferenceEx;
import net.osmand.plus.settings.preferences.SwitchPreferenceEx;
public class TurnScreenOnFragment extends BaseSettingsFragment { public class TurnScreenOnFragment extends BaseSettingsFragment {
public static final String TAG = "TurnScreenOnFragment"; public static final String TAG = "TurnScreenOnFragment";
@Override @Override
protected int getPreferenceResId() { protected int getPreferencesResId() {
return R.xml.turn_screen_on; return R.xml.turn_screen_on;
} }
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = super.onCreateView(inflater, container, savedInstanceState);
return view;
}
@Override @Override
protected int getToolbarResId() { protected int getToolbarResId() {
return R.layout.profile_preference_toolbar; return R.layout.profile_preference_toolbar;
} }
@Override
protected String getToolbarTitle() { protected String getToolbarTitle() {
return getString(R.string.turn_screen_on); return getString(R.string.turn_screen_on);
} }
@Override @Override
protected void createUI() { protected void setupPreferences() {
PreferenceScreen screen = getPreferenceScreen(); setupTurnScreenOnPref();
SwitchPreference turnScreenOn = (SwitchPreference) findAndRegisterPreference(settings.TURN_SCREEN_ON.getId()); Preference turnScreenOnInfo = findPreference("turn_screen_on_info");
turnScreenOnInfo.setIcon(getContentIcon(R.drawable.ic_action_info_dark));
int[] screenPowerSaveValues = new int[]{0, 5, 10, 15, 20, 30, 45, 60}; setupTurnScreenOnTimePref();
String[] screenPowerSaveNames = new String[screenPowerSaveValues.length]; setupTurnScreenOnSensorPref();
screenPowerSaveNames[0] = getString(R.string.shared_string_never);
for (int i = 1; i < screenPowerSaveValues.length; i++) {
screenPowerSaveNames[i] = screenPowerSaveValues[i] + " " + getString(R.string.int_seconds);
}
ListIntPreference turnScreenOnTime = (ListIntPreference) findAndRegisterPreference(settings.TURN_SCREEN_ON_TIME_INT.getId());
turnScreenOnTime.setEntries(screenPowerSaveNames);
turnScreenOnTime.setEntryValues(screenPowerSaveValues);
SwitchPreference turnScreenOnSensor = (SwitchPreference) findAndRegisterPreference(settings.TURN_SCREEN_ON_SENSOR.getId());
} }
public static boolean showInstance(FragmentManager fragmentManager) { private void setupTurnScreenOnPref() {
try { SwitchPreference turnScreenOn = (SwitchPreference) findPreference(settings.TURN_SCREEN_ON.getId());
TurnScreenOnFragment settingsNavigationFragment = new TurnScreenOnFragment(); turnScreenOn.setSummaryOn(R.string.shared_string_on);
fragmentManager.beginTransaction() turnScreenOn.setSummaryOff(R.string.shared_string_off);
.add(R.id.fragmentContainer, settingsNavigationFragment, TurnScreenOnFragment.TAG) }
.addToBackStack(TurnScreenOnFragment.TAG)
.commitAllowingStateLoss(); private void setupTurnScreenOnTimePref() {
return true; Integer[] entryValues = new Integer[] {0, 5, 10, 15, 20, 30, 45, 60};
} catch (Exception e) { String[] entries = new String[entryValues.length];
return false;
entries[0] = getString(R.string.shared_string_never);
for (int i = 1; i < entryValues.length; i++) {
entries[i] = entryValues[i] + " " + getString(R.string.int_seconds);
} }
ListPreferenceEx turnScreenOnTime = (ListPreferenceEx) findPreference(settings.TURN_SCREEN_ON_TIME_INT.getId());
turnScreenOnTime.setEntries(entries);
turnScreenOnTime.setEntryValues(entryValues);
turnScreenOnTime.setIcon(getContentIcon(R.drawable.ic_action_time_span));
}
private void setupTurnScreenOnSensorPref() {
String title = getString(R.string.turn_screen_on_sensor);
String description = getString(R.string.turn_screen_on_sensor_descr);
SwitchPreferenceEx turnScreenOnSensor = (SwitchPreferenceEx) findPreference(settings.TURN_SCREEN_ON_SENSOR.getId());
turnScreenOnSensor.setIcon(getContentIcon(R.drawable.ic_action_sensor_interaction));
turnScreenOnSensor.setTitle(title);
turnScreenOnSensor.setSummaryOn(R.string.shared_string_on);
turnScreenOnSensor.setSummaryOff(R.string.shared_string_off);
turnScreenOnSensor.setDescription(description);
} }
} }

View file

@ -1,189 +1,129 @@
package net.osmand.plus.settings; package net.osmand.plus.settings;
import android.content.DialogInterface; import android.content.Context;
import android.os.Bundle; import android.graphics.drawable.Drawable;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.AlertDialog;
import android.support.v7.preference.ListPreference;
import android.support.v7.preference.Preference; import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import net.osmand.plus.ApplicationMode; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.SettingsBaseActivity; import net.osmand.plus.activities.SettingsBaseActivity;
import net.osmand.plus.activities.SettingsNavigationActivity; import net.osmand.plus.routing.RouteProvider;
import net.osmand.plus.settings.preferences.ListPreferenceEx;
import net.osmand.router.GeneralRouter; import net.osmand.router.GeneralRouter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map; import java.util.Map;
import static net.osmand.plus.activities.SettingsNavigationActivity.getRouter; import static net.osmand.plus.activities.SettingsNavigationActivity.getRouter;
import static net.osmand.plus.activities.SettingsNavigationActivity.setupSpeedSlider; import static net.osmand.plus.activities.SettingsNavigationActivity.showSeekbarSettingsDialog;
public class VehicleParametersFragment extends BaseSettingsFragment { public class VehicleParametersFragment extends BaseSettingsFragment {
public static final String TAG = "VehicleParametersFragment"; public static final String TAG = "VehicleParametersFragment";
@Override @Override
protected int getPreferenceResId() { protected int getPreferencesResId() {
return R.xml.vehicle_parameters; return R.xml.vehicle_parameters;
} }
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = super.onCreateView(inflater, container, savedInstanceState);
return view;
}
@Override @Override
protected int getToolbarResId() { protected int getToolbarResId() {
return R.layout.profile_preference_toolbar; return R.layout.profile_preference_toolbar;
} }
@Override
protected String getToolbarTitle() { protected String getToolbarTitle() {
return getString(R.string.vehicle_parameters); return getString(R.string.vehicle_parameters);
} }
@Override @Override
protected void createUI() { protected void setupPreferences() {
PreferenceScreen screen = getPreferenceScreen(); OsmandApplication app = getMyApplication();
if (app == null) {
return;
}
GeneralRouter router = getRouter(getMyApplication().getRoutingConfig(), getSelectedMode()); Preference vehicleParametersInfo = findPreference("vehicle_parameters_info");
if (router != null) { vehicleParametersInfo.setIcon(getContentIcon(R.drawable.ic_action_info_dark));
Map<String, GeneralRouter.RoutingParameter> parameters = router.getParameters(); vehicleParametersInfo.setTitle(getString(R.string.vehicle_parameters_info, getSelectedAppMode().toHumanString(getContext())));
List<GeneralRouter.RoutingParameter> others = new ArrayList<GeneralRouter.RoutingParameter>();
for (Map.Entry<String, GeneralRouter.RoutingParameter> e : parameters.entrySet()) { if (settings.getApplicationMode().getRouteService() == RouteProvider.RouteService.OSMAND) {
String param = e.getKey(); GeneralRouter router = getRouter(app.getRoutingConfig(), getSelectedAppMode());
GeneralRouter.RoutingParameter routingParameter = e.getValue(); if (router != null) {
if (param.equals(GeneralRouter.VEHICLE_HEIGHT) || param.equals(GeneralRouter.VEHICLE_WEIGHT)) { Map<String, GeneralRouter.RoutingParameter> parameters = router.getParameters();
others.add(routingParameter);
GeneralRouter.RoutingParameter vehicleHeight = parameters.get(GeneralRouter.VEHICLE_HEIGHT);
if (vehicleHeight != null) {
setupCustomRoutingPropertyPref(vehicleHeight);
} }
} GeneralRouter.RoutingParameter vehicleWeight = parameters.get(GeneralRouter.VEHICLE_WEIGHT);
if (vehicleWeight != null) {
for (GeneralRouter.RoutingParameter p : others) { setupCustomRoutingPropertyPref(vehicleWeight);
Preference basePref; }
if (p.getType() == GeneralRouter.RoutingParameterType.BOOLEAN) { if (router.getProfile() != GeneralRouter.GeneralRouterProfile.PUBLIC_TRANSPORT) {
basePref = createSwitchPreference(settings.getCustomRoutingBooleanProperty(p.getId(), p.getDefaultBoolean())); setupDefaultSpeedPref();
} 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() == GeneralRouter.RoutingParameterType.NUMERIC ? "0.0" : "-"),
p.getPossibleValueDescriptions(), svlss,
SettingsBaseActivity.getRoutingStringPropertyName(getActivity(), p.getId(), p.getName()),
SettingsBaseActivity.getRoutingStringPropertyDescription(getActivity(), p.getId(), p.getDescription()));
((ListPreference) basePref).setEntries(p.getPossibleValueDescriptions());
((ListPreference) basePref).setEntryValues(svlss);
} }
basePref.setTitle(SettingsBaseActivity.getRoutingStringPropertyName(getActivity(), p.getId(), p.getName()));
basePref.setSummary(SettingsBaseActivity.getRoutingStringPropertyDescription(getActivity(), p.getId(), p.getDescription()));
screen.addPreference(basePref);
}
GeneralRouter.GeneralRouterProfile routerProfile = router.getProfile();
Preference defaultSpeed = findAndRegisterPreference("default_speed");
if (routerProfile != GeneralRouter.GeneralRouterProfile.PUBLIC_TRANSPORT) {
defaultSpeed.setOnPreferenceClickListener(this);
} else {
screen.removePreference(defaultSpeed);
} }
} }
} }
private void showSeekbarSettingsDialog() { private void setupCustomRoutingPropertyPref(GeneralRouter.RoutingParameter parameter) {
final ApplicationMode mode = settings.getApplicationMode(); Context ctx = getContext();
GeneralRouter router = getRouter(getMyApplication().getRoutingConfig(), mode); if (ctx == null) {
OsmandSettings.SpeedConstants units = settings.SPEED_SYSTEM.get(); return;
String speedUnits = units.toShortString(getActivity()); }
final float[] ratio = new float[1]; String parameterId = parameter.getId();
switch (units) { String title = SettingsBaseActivity.getRoutingStringPropertyName(ctx, parameterId, parameter.getName());
case MILES_PER_HOUR: String description = SettingsBaseActivity.getRoutingStringPropertyDescription(ctx, parameterId, parameter.getDescription());
ratio[0] = 3600 / OsmAndFormatter.METERS_IN_ONE_MILE;
break; String defValue = parameter.getType() == GeneralRouter.RoutingParameterType.NUMERIC ? "0.0" : "-";
case KILOMETERS_PER_HOUR: OsmandSettings.StringPreference pref = (OsmandSettings.StringPreference) settings.getCustomRoutingProperty(parameterId, defValue);
ratio[0] = 3600 / OsmAndFormatter.METERS_IN_KILOMETER;
break; Object[] values = parameter.getPossibleValues();
case MINUTES_PER_KILOMETER: String[] valuesStr = new String[values.length];
ratio[0] = 3600 / OsmAndFormatter.METERS_IN_KILOMETER; for (int i = 0; i < values.length; i++) {
speedUnits = getString(R.string.km_h); valuesStr[i] = values[i].toString();
break;
case NAUTICALMILES_PER_HOUR:
ratio[0] = 3600 / OsmAndFormatter.METERS_IN_ONE_NAUTICALMILE;
break;
} }
float settingsMinSpeed = settings.MIN_SPEED.get(); ListPreferenceEx listPreference = createListPreferenceEx(pref.getId(), parameter.getPossibleValueDescriptions(), valuesStr, title, R.layout.preference_with_descr);
float settingsMaxSpeed = settings.MAX_SPEED.get(); listPreference.setDescription(description);
listPreference.setIcon(getPreferenceIcon(parameterId));
getPreferenceScreen().addPreference(listPreference);
}
final int[] defaultValue = {Math.round(mode.getDefaultSpeed() * ratio[0])}; private void setupDefaultSpeedPref() {
final int[] minValue = {Math.round((settingsMinSpeed > 0 ? settingsMinSpeed : router.getMinSpeed()) * ratio[0])}; Context ctx = getContext();
final int[] maxValue = {Math.round((settingsMaxSpeed > 0 ? settingsMaxSpeed : router.getMaxSpeed()) * ratio[0])}; if (ctx == null) {
final int min = Math.round(router.getMinSpeed() * ratio[0] / 2f); return;
final int max = Math.round(router.getMaxSpeed() * ratio[0] * 1.5f); }
Preference defaultSpeedPref = new Preference(ctx);
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); defaultSpeedPref.setKey(GeneralRouter.DEFAULT_SPEED);
boolean lightMode = getMyApplication().getSettings().isLightContent(); defaultSpeedPref.setTitle(R.string.default_speed_setting_title);
int themeRes = lightMode ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme; defaultSpeedPref.setSummary(R.string.default_speed_setting_descr);
View seekbarView = LayoutInflater.from(new ContextThemeWrapper(getActivity(), themeRes)) defaultSpeedPref.setIcon(getPreferenceIcon(GeneralRouter.DEFAULT_SPEED));
.inflate(R.layout.default_speed_dialog, null, false); defaultSpeedPref.setLayoutResource(R.layout.preference_with_descr);
builder.setView(seekbarView); getPreferenceScreen().addPreference(defaultSpeedPref);
builder.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
mode.setDefaultSpeed(getMyApplication(), defaultValue[0] / ratio[0]);
settings.MIN_SPEED.set(minValue[0] / ratio[0]);
settings.MAX_SPEED.set(maxValue[0] / ratio[0]);
}
});
builder.setNegativeButton(R.string.shared_string_cancel, null);
builder.setNeutralButton("Revert", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
mode.resetDefaultSpeed(getMyApplication());
settings.MIN_SPEED.set(0f);
settings.MAX_SPEED.set(0f);
}
});
setupSpeedSlider(SettingsNavigationActivity.SpeedSliderType.MIN_SPEED, speedUnits, minValue, defaultValue, maxValue, min, max, seekbarView);
setupSpeedSlider(SettingsNavigationActivity.SpeedSliderType.DEFAULT_SPEED, speedUnits, minValue, defaultValue, maxValue, min, max, seekbarView);
setupSpeedSlider(SettingsNavigationActivity.SpeedSliderType.MAX_SPEED, speedUnits, minValue, defaultValue, maxValue, min, max, seekbarView);
builder.show();
} }
@Override @Override
public boolean onPreferenceClick(Preference preference) { public boolean onPreferenceClick(Preference preference) {
if (preference.getKey().equals("default_speed")) { if (preference.getKey().equals(GeneralRouter.DEFAULT_SPEED)) {
showSeekbarSettingsDialog(); showSeekbarSettingsDialog(getActivity());
return true; return true;
} }
return false; return super.onPreferenceClick(preference);
} }
public static boolean showInstance(FragmentManager fragmentManager) { private Drawable getPreferenceIcon(String prefId) {
try { switch (prefId) {
VehicleParametersFragment settingsNavigationFragment = new VehicleParametersFragment(); case GeneralRouter.DEFAULT_SPEED:
fragmentManager.beginTransaction() return getContentIcon(R.drawable.ic_action_speed);
.add(R.id.fragmentContainer, settingsNavigationFragment, VehicleParametersFragment.TAG) case GeneralRouter.VEHICLE_HEIGHT:
.addToBackStack(VehicleParametersFragment.TAG) return getIcon(R.drawable.ic_action_height_limit);
.commitAllowingStateLoss(); case GeneralRouter.VEHICLE_WEIGHT:
return true; return getIcon(R.drawable.ic_action_weight_limit);
} catch (Exception e) { default:
return false; return null;
} }
} }
} }

View file

@ -2,23 +2,17 @@ package net.osmand.plus.settings;
import android.media.AudioAttributes; import android.media.AudioAttributes;
import android.media.AudioManager; import android.media.AudioManager;
import android.os.Bundle;
import android.support.v14.preference.SwitchPreference; import android.support.v14.preference.SwitchPreference;
import android.support.v4.app.FragmentManager;
import android.support.v7.preference.ListPreference;
import android.support.v7.preference.Preference; import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import net.osmand.StateChangedListener;
import net.osmand.plus.ApplicationMode; import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.Version; import net.osmand.plus.Version;
import net.osmand.plus.activities.SettingsNavigationActivity;
import net.osmand.plus.helpers.FileNameTranslationHelper; import net.osmand.plus.helpers.FileNameTranslationHelper;
import net.osmand.plus.views.ListFloatPreference; import net.osmand.plus.settings.preferences.ListPreferenceEx;
import net.osmand.plus.views.ListIntPreference;
import net.osmand.plus.voice.CommandPlayer; import net.osmand.plus.voice.CommandPlayer;
import java.util.Set; import java.util.Set;
@ -30,14 +24,7 @@ public class VoiceAnnouncesFragment extends BaseSettingsFragment {
public static final String TAG = "VoiceAnnouncesFragment"; public static final String TAG = "VoiceAnnouncesFragment";
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { protected int getPreferencesResId() {
View view = super.onCreateView(inflater, container, savedInstanceState);
return view;
}
@Override
protected int getPreferenceResId() {
return R.xml.voice_announces; return R.xml.voice_announces;
} }
@ -50,155 +37,191 @@ public class VoiceAnnouncesFragment extends BaseSettingsFragment {
return getString(R.string.voice_announces); return getString(R.string.voice_announces);
} }
protected void createUI() { protected void setupPreferences() {
PreferenceScreen screen = getPreferenceScreen(); SwitchPreference speakRoutingAlarms = (SwitchPreference) findPreference(settings.SPEAK_ROUTING_ALARMS.getId());
speakRoutingAlarms.setSummaryOn(R.string.shared_string_on);
speakRoutingAlarms.setSummaryOff(R.string.shared_string_off);
SwitchPreference SPEAK_ROUTING_ALARMS = (SwitchPreference) findAndRegisterPreference(settings.SPEAK_ROUTING_ALARMS.getId()); Preference voiceAnnouncesInfo = findPreference("voice_announces_info");
Preference voiceAnnouncesInfo = findAndRegisterPreference("voice_announces_info");
voiceAnnouncesInfo.setIcon(getContentIcon(R.drawable.ic_action_info_dark)); voiceAnnouncesInfo.setIcon(getContentIcon(R.drawable.ic_action_info_dark));
SwitchPreference SPEAK_STREET_NAMES = (SwitchPreference) findAndRegisterPreference(settings.SPEAK_STREET_NAMES.getId()); SwitchPreference speakStreetNames = (SwitchPreference) findPreference(settings.SPEAK_STREET_NAMES.getId());
SwitchPreference SPEAK_TRAFFIC_WARNINGS = (SwitchPreference) findAndRegisterPreference(settings.SPEAK_TRAFFIC_WARNINGS.getId()); SwitchPreference speakTrafficWarnings = (SwitchPreference) findPreference(settings.SPEAK_TRAFFIC_WARNINGS.getId());
SwitchPreference SPEAK_PEDESTRIAN = (SwitchPreference) findAndRegisterPreference(settings.SPEAK_PEDESTRIAN.getId()); SwitchPreference speakPedestrian = (SwitchPreference) findPreference(settings.SPEAK_PEDESTRIAN.getId());
SwitchPreference SPEAK_SPEED_LIMIT = (SwitchPreference) findAndRegisterPreference(settings.SPEAK_SPEED_LIMIT.getId()); SwitchPreference speakSpeedLimit = (SwitchPreference) findPreference(settings.SPEAK_SPEED_LIMIT.getId());
SwitchPreference SPEAK_SPEED_CAMERA = (SwitchPreference) findAndRegisterPreference(settings.SPEAK_SPEED_CAMERA.getId());
SwitchPreference SPEAK_TUNNELS = (SwitchPreference) findAndRegisterPreference(settings.SPEAK_TUNNELS.getId()); setupSpeedLimitExceedPref();
SwitchPreference ANNOUNCE_WPT = (SwitchPreference) findAndRegisterPreference(settings.ANNOUNCE_WPT.getId()); setupSpeakSpeedCameraPref();
SwitchPreference ANNOUNCE_NEARBY_FAVORITES = (SwitchPreference) findAndRegisterPreference(settings.ANNOUNCE_NEARBY_FAVORITES.getId());
SwitchPreference ANNOUNCE_NEARBY_POI = (SwitchPreference) findAndRegisterPreference(settings.ANNOUNCE_NEARBY_POI.getId()); SwitchPreference speakTunnels = (SwitchPreference) findPreference(settings.SPEAK_TUNNELS.getId());
SwitchPreference announceWpt = (SwitchPreference) findPreference(settings.ANNOUNCE_WPT.getId());
SwitchPreference announceNearbyFavorites = (SwitchPreference) findPreference(settings.ANNOUNCE_NEARBY_FAVORITES.getId());
SwitchPreference announceNearbyPoi = (SwitchPreference) findPreference(settings.ANNOUNCE_NEARBY_POI.getId());
setupKeepInformingPref();
setupArrivalAnnouncementPref();
setupVoiceProviderPref();
if (!Version.isBlackberry(app)) {
setupAudioStreamGuidancePref();
setupInterruptMusicPref();
}
}
private void setupSpeedLimitExceedPref() {
Float[] speedLimitValues;
String[] speedLimitNames;
String[] speedNames;
float[] speedLimits;
if (settings.METRIC_SYSTEM.get() == OsmandSettings.MetricsConstants.KILOMETERS_AND_METERS) { if (settings.METRIC_SYSTEM.get() == OsmandSettings.MetricsConstants.KILOMETERS_AND_METERS) {
speedLimits = new float[]{-10f, -7f, -5f, 0f, 5f, 7f, 10f, 15f, 20f}; speedLimitValues = new Float[] {-10f, -7f, -5f, 0f, 5f, 7f, 10f, 15f, 20f};
speedNames = new String[speedLimits.length]; speedLimitNames = new String[speedLimitValues.length];
for (int i = 0; i < speedLimits.length; i++) {
speedNames[i] = (int) speedLimits[i] + " " + getString(R.string.km_h); for (int i = 0; i < speedLimitValues.length; i++) {
speedLimitNames[i] = speedLimitValues[i].intValue() + " " + getString(R.string.km_h);
} }
} else { } else {
speedLimits = new float[]{-7f, -5f, -3f, 0f, 3f, 5f, 7f, 10f, 15f}; speedLimitValues = new Float[] {-7f, -5f, -3f, 0f, 3f, 5f, 7f, 10f, 15f};
speedNames = new String[speedLimits.length]; speedLimitNames = new String[speedLimitValues.length];
for (int i = 0; i < speedNames.length; i++) {
speedNames[i] = (int) speedLimits[i] + " " + getString(R.string.mile_per_hour); for (int i = 0; i < speedLimitNames.length; i++) {
speedLimitNames[i] = speedLimitValues[i].intValue() + " " + getString(R.string.mile_per_hour);
} }
} }
ListFloatPreference SPEED_LIMIT_EXCEED = (ListFloatPreference) findAndRegisterPreference(settings.SPEED_LIMIT_EXCEED.getId());
SPEED_LIMIT_EXCEED.setEntries(speedNames);
SPEED_LIMIT_EXCEED.setEntryValues(speedLimits);
//keep informing option: ListPreferenceEx voiceProvider = (ListPreferenceEx) findPreference(settings.SPEED_LIMIT_EXCEED.getId());
int[] keepInformingValues = new int[]{0, 1, 2, 3, 5, 7, 10, 15, 20, 25, 30}; voiceProvider.setEntries(speedLimitNames);
voiceProvider.setEntryValues(speedLimitValues);
}
private void setupSpeakSpeedCameraPref() {
settings.SPEAK_SPEED_CAMERA.addListener(new StateChangedListener<Boolean>() {
@Override
public void stateChanged(Boolean change) {
SwitchPreference speakSpeedCamera = (SwitchPreference) findPreference(settings.SPEAK_SPEED_CAMERA.getId());
if (speakSpeedCamera != null) {
speakSpeedCamera.setChecked(change);
}
}
});
}
private void setupKeepInformingPref() {
Integer[] keepInformingValues = new Integer[] {0, 1, 2, 3, 5, 7, 10, 15, 20, 25, 30};
String[] keepInformingNames = new String[keepInformingValues.length]; String[] keepInformingNames = new String[keepInformingValues.length];
keepInformingNames[0] = getString(R.string.keep_informing_never); keepInformingNames[0] = getString(R.string.keep_informing_never);
for (int i = 1; i < keepInformingValues.length; i++) { for (int i = 1; i < keepInformingValues.length; i++) {
keepInformingNames[i] = keepInformingValues[i] + " " + getString(R.string.int_min); keepInformingNames[i] = keepInformingValues[i] + " " + getString(R.string.int_min);
} }
ListIntPreference KEEP_INFORMING = (ListIntPreference) findAndRegisterPreference(settings.KEEP_INFORMING.getId());
KEEP_INFORMING.setEntries(keepInformingNames);
KEEP_INFORMING.setEntryValues(keepInformingValues);
float[] arrivalValues = new float[]{1.5f, 1f, 0.5f, 0.25f}; ListPreferenceEx voiceProvider = (ListPreferenceEx) findPreference(settings.KEEP_INFORMING.getId());
String[] arrivalNames = new String[]{ voiceProvider.setEntries(keepInformingNames);
voiceProvider.setEntryValues(keepInformingValues);
}
private void setupArrivalAnnouncementPref() {
Float[] arrivalValues = new Float[] {1.5f, 1f, 0.5f, 0.25f};
String[] arrivalNames = new String[] {
getString(R.string.arrival_distance_factor_early), getString(R.string.arrival_distance_factor_early),
getString(R.string.arrival_distance_factor_normally), getString(R.string.arrival_distance_factor_normally),
getString(R.string.arrival_distance_factor_late), getString(R.string.arrival_distance_factor_late),
getString(R.string.arrival_distance_factor_at_last) getString(R.string.arrival_distance_factor_at_last)
}; };
ListFloatPreference ARRIVAL_DISTANCE_FACTOR = (ListFloatPreference) findAndRegisterPreference(settings.ARRIVAL_DISTANCE_FACTOR.getId()); ListPreferenceEx voiceProvider = (ListPreferenceEx) findPreference(settings.ARRIVAL_DISTANCE_FACTOR.getId());
ARRIVAL_DISTANCE_FACTOR.setEntries(arrivalNames); voiceProvider.setEntries(arrivalNames);
ARRIVAL_DISTANCE_FACTOR.setEntryValues(arrivalValues); voiceProvider.setEntryValues(arrivalValues);
reloadVoiceListPreference(screen);
addVoicePrefs(screen);
} }
private void reloadVoiceListPreference(PreferenceScreen screen) { private void setupVoiceProviderPref() {
String[] entries; Set<String> voiceFiles = app.getRoutingOptionsHelper().getVoiceFiles(getActivity());
String[] entrieValues; String[] entries = new String[voiceFiles.size() + 2];
Set<String> voiceFiles = getMyApplication().getRoutingOptionsHelper().getVoiceFiles(getActivity()); String[] entryValues = new String[voiceFiles.size() + 2];
entries = new String[voiceFiles.size() + 2];
entrieValues = new String[voiceFiles.size() + 2];
int k = 0; int k = 0;
// entries[k++] = getString(R.string.shared_string_none); // entries[k++] = getString(R.string.shared_string_none);
entrieValues[k] = OsmandSettings.VOICE_PROVIDER_NOT_USE; entryValues[k] = OsmandSettings.VOICE_PROVIDER_NOT_USE;
entries[k++] = getString(R.string.shared_string_do_not_use); entries[k++] = getString(R.string.shared_string_do_not_use);
for (String s : voiceFiles) { for (String s : voiceFiles) {
entries[k] = (s.contains("tts") ? getString(R.string.ttsvoice) + " " : "") + entries[k] = (s.contains("tts") ? getString(R.string.ttsvoice) + " " : "") + FileNameTranslationHelper.getVoiceName(getActivity(), s);
FileNameTranslationHelper.getVoiceName(getMyActivity(), s); entryValues[k] = s;
entrieValues[k] = s;
k++; k++;
} }
entrieValues[k] = MORE_VALUE; entryValues[k] = MORE_VALUE;
entries[k] = getString(R.string.install_more); entries[k] = getString(R.string.install_more);
ListPreference voiceProvider = (ListPreference) findAndRegisterPreference(settings.VOICE_PROVIDER.getId());
ListPreferenceEx voiceProvider = (ListPreferenceEx) findPreference(settings.VOICE_PROVIDER.getId());
voiceProvider.setEntries(entries); voiceProvider.setEntries(entries);
voiceProvider.setEntryValues(entrieValues); voiceProvider.setEntryValues(entryValues);
voiceProvider.setIcon(getContentIcon(R.drawable.ic_action_volume_mute)); voiceProvider.setIcon(getContentIcon(R.drawable.ic_action_volume_up));
} }
private void addVoicePrefs(PreferenceScreen screen) { private void setupAudioStreamGuidancePref() {
if (!Version.isBlackberry(getMyApplication())) { String[] streamTypes = new String[] {
String[] streamTypes = new String[]{getString(R.string.voice_stream_music), getString(R.string.voice_stream_music),
getString(R.string.voice_stream_notification), getString(R.string.voice_stream_voice_call)}; getString(R.string.voice_stream_notification),
//getString(R.string.shared_string_default)}; getString(R.string.voice_stream_voice_call)
Integer[] streamIntTypes = new Integer[]{AudioManager.STREAM_MUSIC, };
AudioManager.STREAM_NOTIFICATION, AudioManager.STREAM_VOICE_CALL}; //getString(R.string.shared_string_default)};
String[] streamIntTypesStr = new String[]{String.valueOf(AudioManager.STREAM_MUSIC),
String.valueOf(AudioManager.STREAM_NOTIFICATION), String.valueOf(AudioManager.STREAM_VOICE_CALL)};
//AudioManager.USE_DEFAULT_STREAM_TYPE};
ListIntPreference lp = new ListIntPreference(getContext());
lp.setTitle(R.string.choose_audio_stream);
lp.setKey(settings.AUDIO_STREAM_GUIDANCE.getId());
lp.setDialogTitle(R.string.choose_audio_stream);
lp.setSummary(R.string.choose_audio_stream_descr);
lp.setEntries(streamTypes);
lp.setEntryValues(streamIntTypesStr);
registerPreference(lp);
final Preference.OnPreferenceChangeListener prev = lp.getOnPreferenceChangeListener();
lp.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override Integer[] streamIntTypes = new Integer[] {
public boolean onPreferenceChange(Preference preference, Object newValue) { AudioManager.STREAM_MUSIC,
prev.onPreferenceChange(preference, newValue); AudioManager.STREAM_NOTIFICATION,
CommandPlayer player = getMyApplication().getPlayer(); AudioManager.STREAM_VOICE_CALL
if (player != null) { };
player.updateAudioStream(settings.AUDIO_STREAM_GUIDANCE.get()); //AudioManager.USE_DEFAULT_STREAM_TYPE};
}
// Sync corresponding AUDIO_USAGE value
ApplicationMode mode = getMyApplication().getSettings().getApplicationMode();
int stream = settings.AUDIO_STREAM_GUIDANCE.getModeValue(mode);
if (stream == AudioManager.STREAM_MUSIC) {
settings.AUDIO_USAGE.setModeValue(mode, AudioAttributes.USAGE_ASSISTANCE_NAVIGATION_GUIDANCE);
} else if (stream == AudioManager.STREAM_NOTIFICATION) {
settings.AUDIO_USAGE.setModeValue(mode, AudioAttributes.USAGE_NOTIFICATION);
} else if (stream == AudioManager.STREAM_VOICE_CALL) {
settings.AUDIO_USAGE.setModeValue(mode, AudioAttributes.USAGE_VOICE_COMMUNICATION);
}
// Sync DEFAULT value with CAR value, as we have other way to set it for now ListPreferenceEx lp = createListPreferenceEx(settings.AUDIO_STREAM_GUIDANCE.getId(), streamTypes, streamIntTypes, R.string.choose_audio_stream, R.layout.preference_with_descr);
settings.AUDIO_STREAM_GUIDANCE.setModeValue(ApplicationMode.DEFAULT, settings.AUDIO_STREAM_GUIDANCE.getModeValue(ApplicationMode.CAR)); getPreferenceScreen().addPreference(lp);
settings.AUDIO_USAGE.setModeValue(ApplicationMode.DEFAULT, settings.AUDIO_USAGE.getModeValue(ApplicationMode.CAR)); }
return true;
} private void setupInterruptMusicPref() {
}); Preference interruptMusicPref = createSwitchPreference(settings.INTERRUPT_MUSIC, R.string.interrupt_music, R.string.interrupt_music_descr, R.layout.preference_switch);
screen.addPreference(lp); getPreferenceScreen().addPreference(interruptMusicPref);
screen.addPreference(createSwitchPreference(settings.INTERRUPT_MUSIC, R.string.interrupt_music, }
R.string.interrupt_music_descr));
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
String prefId = preference.getKey();
if (prefId.equals(settings.ANNOUNCE_NEARBY_POI.getId())) {
settings.SHOW_NEARBY_POI.set(settings.ANNOUNCE_NEARBY_POI.get());
} }
} if (prefId.equals(settings.ANNOUNCE_NEARBY_FAVORITES.getId())) {
settings.SHOW_NEARBY_FAVORITES.set(settings.ANNOUNCE_NEARBY_FAVORITES.get());
}
if (prefId.equals(settings.ANNOUNCE_WPT.getId())) {
settings.SHOW_WPT.set(settings.ANNOUNCE_WPT.get());
}
if (prefId.equals(settings.SPEAK_SPEED_CAMERA.getId())) {
if (!settings.SPEAK_SPEED_CAMERA.get()) {
SettingsNavigationActivity.confirmSpeedCamerasDlg(getActivity(), settings);
return false;
} else {
return true;
}
}
if (prefId.equals(settings.AUDIO_STREAM_GUIDANCE.getId())) {
CommandPlayer player = app.getPlayer();
if (player != null) {
player.updateAudioStream(settings.AUDIO_STREAM_GUIDANCE.get());
}
// Sync corresponding AUDIO_USAGE value
ApplicationMode mode = getSelectedAppMode();
int stream = settings.AUDIO_STREAM_GUIDANCE.getModeValue(mode);
if (stream == AudioManager.STREAM_MUSIC) {
settings.AUDIO_USAGE.setModeValue(mode, AudioAttributes.USAGE_ASSISTANCE_NAVIGATION_GUIDANCE);
} else if (stream == AudioManager.STREAM_NOTIFICATION) {
settings.AUDIO_USAGE.setModeValue(mode, AudioAttributes.USAGE_NOTIFICATION);
} else if (stream == AudioManager.STREAM_VOICE_CALL) {
settings.AUDIO_USAGE.setModeValue(mode, AudioAttributes.USAGE_VOICE_COMMUNICATION);
}
public static boolean showInstance(FragmentManager fragmentManager) { // Sync DEFAULT value with CAR value, as we have other way to set it for now
try { settings.AUDIO_STREAM_GUIDANCE.setModeValue(ApplicationMode.DEFAULT, settings.AUDIO_STREAM_GUIDANCE.getModeValue(ApplicationMode.CAR));
VoiceAnnouncesFragment settingsNavigationFragment = new VoiceAnnouncesFragment(); settings.AUDIO_USAGE.setModeValue(ApplicationMode.DEFAULT, settings.AUDIO_USAGE.getModeValue(ApplicationMode.CAR));
fragmentManager.beginTransaction()
.add(R.id.fragmentContainer, settingsNavigationFragment, VoiceAnnouncesFragment.TAG)
.addToBackStack(VoiceAnnouncesFragment.TAG)
.commitAllowingStateLoss();
return true; return true;
} catch (Exception e) {
return false;
} }
return super.onPreferenceChange(preference, newValue);
} }
} }

View file

@ -0,0 +1,38 @@
package net.osmand.plus.settings.preferences;
import android.content.Context;
import android.support.v7.preference.EditTextPreference;
import android.util.AttributeSet;
public class EditTextPreferenceEx extends EditTextPreference {
private String description;
public EditTextPreferenceEx(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
public EditTextPreferenceEx(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
public EditTextPreferenceEx(Context context, AttributeSet attrs) {
super(context, attrs);
}
public EditTextPreferenceEx(Context context) {
super(context);
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public void setDescription(int descriptionResId) {
setDescription(getContext().getString(descriptionResId));
}
}

View file

@ -0,0 +1,147 @@
package net.osmand.plus.settings.preferences;
import android.content.Context;
import android.content.res.TypedArray;
import android.support.v7.preference.DialogPreference;
import android.support.v7.preference.PreferenceDataStore;
import android.util.AttributeSet;
import net.osmand.plus.OsmandSettings.PreferencesDataStore;
public class ListPreferenceEx extends DialogPreference {
private String[] entries;
private Object[] entryValues;
private Object selectedValue;
private String description;
public ListPreferenceEx(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
public ListPreferenceEx(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
public ListPreferenceEx(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ListPreferenceEx(Context context) {
super(context);
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public void setDescription(int descriptionResId) {
setDescription(getContext().getString(descriptionResId));
}
public void setEntries(String[] entries) {
this.entries = entries;
}
public String[] getEntries() {
return entries;
}
public void setEntryValues(Object[] entryValues) {
this.entryValues = entryValues;
}
public Object[] getEntryValues() {
return entryValues;
}
public void setValueIndex(int index) {
if (entryValues != null && index >= 0 && index < entryValues.length) {
setValue(entryValues[index]);
}
}
public Object getValue() {
return selectedValue;
}
public String getEntry() {
int index = getValueIndex();
return index >= 0 && entries != null ? entries[index] : null;
}
public int findIndexOfValue(Object value) {
if (value != null && entryValues != null) {
for (int i = 0; i < entryValues.length; i++) {
if (entryValues[i].equals(value)) {
return i;
}
}
}
return -1;
}
private int getValueIndex() {
return findIndexOfValue(selectedValue);
}
@Override
public CharSequence getDialogTitle() {
CharSequence dialogTitle = super.getDialogTitle();
return dialogTitle != null ? dialogTitle : getTitle();
}
@Override
public CharSequence getSummary() {
String entry = getEntry();
return entry != null ? entry : super.getSummary();
}
@Override
protected Object onGetDefaultValue(TypedArray a, int index) {
return getPersistedValue(null);
}
@Override
protected void onSetInitialValue(boolean restoreValue, Object defaultValue) {
selectedValue = restoreValue ? getPersistedValue(selectedValue) : (String) defaultValue;
notifyChanged();
}
public void setValue(Object value) {
// Always persist/notify the first time.
final boolean changed = selectedValue == null || !selectedValue.equals(value);
if (changed) {
selectedValue = value;
persistValue(value);
notifyChanged();
}
}
private Object getPersistedValue(Object defaultValue) {
PreferenceDataStore dataStore = getPreferenceDataStore();
if (dataStore instanceof PreferencesDataStore) {
Object value = ((PreferencesDataStore) dataStore).getValue(getKey(), defaultValue);
if (value instanceof Enum) {
return ((Enum) value).ordinal();
} else {
return value;
}
}
return null;
}
private void persistValue(Object value) {
if (!shouldPersist()) {
return;
}
PreferenceDataStore dataStore = getPreferenceDataStore();
if (dataStore instanceof PreferencesDataStore) {
((PreferencesDataStore) dataStore).putValue(getKey(), value);
}
}
}

View file

@ -0,0 +1,41 @@
package net.osmand.plus.settings.preferences;
import android.content.Context;
import android.support.v14.preference.SwitchPreference;
import android.util.AttributeSet;
public class SwitchPreferenceEx extends SwitchPreference {
private String description;
public SwitchPreferenceEx(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
public SwitchPreferenceEx(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
public SwitchPreferenceEx(Context context, AttributeSet attrs) {
super(context, attrs);
}
public SwitchPreferenceEx(Context context) {
super(context);
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
@Override
protected void onClick() {
if (getFragment() == null) {
getPreferenceManager().showDialog(this);
}
}
}

View file

@ -366,6 +366,7 @@ public class MapWidgetRegistry {
}).setLayout(R.layout.list_item_text_button).createItem()); }).setLayout(R.layout.list_item_text_button).createItem());
addControlId(map, cm, R.string.map_widget_transparent, settings.TRANSPARENT_MAP_THEME); addControlId(map, cm, R.string.map_widget_transparent, settings.TRANSPARENT_MAP_THEME);
addControlId(map, cm, R.string.always_center_position_on_map, settings.CENTER_POSITION_ON_MAP); addControlId(map, cm, R.string.always_center_position_on_map, settings.CENTER_POSITION_ON_MAP);
addControlId(map, cm, R.string.show_lanes, settings.SHOW_LANES);
} }
public void updateMapMarkersMode(MapActivity mapActivity) { public void updateMapMarkersMode(MapActivity mapActivity) {