diff --git a/OsmAnd/res/layout/bottom_sheet_item_preference_descr.xml b/OsmAnd/res/layout/bottom_sheet_item_preference_descr.xml
index 09e6f386ff..b66a1ec2f7 100644
--- a/OsmAnd/res/layout/bottom_sheet_item_preference_descr.xml
+++ b/OsmAnd/res/layout/bottom_sheet_item_preference_descr.xml
@@ -5,6 +5,7 @@
android:id="@+id/description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
+ android:letterSpacing="@dimen/description_letter_spacing"
android:minHeight="@dimen/bottom_sheet_list_item_height"
android:paddingLeft="@dimen/content_padding"
android:paddingTop="@dimen/bottom_sheet_image_text_margin_start"
diff --git a/OsmAnd/res/layout/bottom_sheet_item_preference_switch.xml b/OsmAnd/res/layout/bottom_sheet_item_preference_switch.xml
index 3e336b3212..e46dddd086 100644
--- a/OsmAnd/res/layout/bottom_sheet_item_preference_switch.xml
+++ b/OsmAnd/res/layout/bottom_sheet_item_preference_switch.xml
@@ -24,6 +24,7 @@
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:ellipsize="end"
+ android:letterSpacing="@dimen/title_letter_spacing"
android:maxLines="1"
android:textAppearance="@style/TextAppearance.ListItemTitle"
android:textColor="?attr/active_color_basic"
diff --git a/OsmAnd/res/layout/fragment_selected_profile.xml b/OsmAnd/res/layout/fragment_selected_profile.xml
index 3cfd869bf6..1e198657e2 100644
--- a/OsmAnd/res/layout/fragment_selected_profile.xml
+++ b/OsmAnd/res/layout/fragment_selected_profile.xml
@@ -1,9 +1,65 @@
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -226,8 +282,7 @@
@@ -379,7 +434,7 @@
android:textColor="@color/description_font_and_bottom_sheet_icons"/>
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+ android:textColor="@color/description_font_and_bottom_sheet_icons"
+ android:visibility="gone"
+ tools:text="@string/configure_profile_info"
+ tools:visibility="visible" />
@@ -612,4 +571,6 @@
-
\ No newline at end of file
+
+
+
\ No newline at end of file
diff --git a/OsmAnd/res/layout/global_preference_toolbar.xml b/OsmAnd/res/layout/global_preference_toolbar.xml
index 787bf2a928..9f14b4c110 100644
--- a/OsmAnd/res/layout/global_preference_toolbar.xml
+++ b/OsmAnd/res/layout/global_preference_toolbar.xml
@@ -5,7 +5,7 @@
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="@dimen/toolbar_height"
- android:background="@color/icon_color_osmand_light"
+ android:background="?attr/actionModeBackground"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp">
diff --git a/OsmAnd/res/layout/global_preferences_toolbar_with_switch.xml b/OsmAnd/res/layout/global_preferences_toolbar_with_switch.xml
new file mode 100644
index 0000000000..7c3e09ef55
--- /dev/null
+++ b/OsmAnd/res/layout/global_preferences_toolbar_with_switch.xml
@@ -0,0 +1,50 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/OsmAnd/res/layout/preference_category_with_descr.xml b/OsmAnd/res/layout/preference_category_with_descr.xml
index 8cef082e56..9f1d02989f 100644
--- a/OsmAnd/res/layout/preference_category_with_descr.xml
+++ b/OsmAnd/res/layout/preference_category_with_descr.xml
@@ -29,6 +29,7 @@
android:id="@android:id/title"
android:layout_width="match_parent"
android:layout_height="match_parent"
+ android:letterSpacing="@dimen/description_letter_spacing"
android:paddingTop="@dimen/list_header_settings_top_margin"
android:singleLine="true"
android:textColor="@color/preference_category_title"
@@ -40,6 +41,7 @@
android:id="@android:id/summary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
+ android:letterSpacing="@dimen/description_letter_spacing"
android:paddingBottom="@dimen/list_header_settings_top_margin"
android:textColor="?android:textColorSecondary"
android:textSize="@dimen/default_desc_text_size"
diff --git a/OsmAnd/res/layout/preference_info.xml b/OsmAnd/res/layout/preference_info.xml
index 075e94d733..69717fdf48 100644
--- a/OsmAnd/res/layout/preference_info.xml
+++ b/OsmAnd/res/layout/preference_info.xml
@@ -22,6 +22,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
+ android:letterSpacing="@dimen/description_letter_spacing"
android:paddingLeft="@dimen/content_padding"
android:paddingTop="@dimen/content_padding_small"
android:paddingRight="@dimen/content_padding"
diff --git a/OsmAnd/res/layout/preference_info_descr.xml b/OsmAnd/res/layout/preference_info_descr.xml
index 9fba9c6e36..27cf7ac368 100644
--- a/OsmAnd/res/layout/preference_info_descr.xml
+++ b/OsmAnd/res/layout/preference_info_descr.xml
@@ -11,6 +11,7 @@
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/content_padding"
android:layout_marginRight="@dimen/content_padding"
+ android:letterSpacing="@dimen/text_button_letter_spacing"
android:paddingTop="@dimen/content_padding_small"
android:textColor="?android:textColorSecondary"
android:textSize="@dimen/default_sub_text_size"
diff --git a/OsmAnd/res/layout/preference_radio_button.xml b/OsmAnd/res/layout/preference_radio_button.xml
index 6dfa5a942b..fb06767ffd 100644
--- a/OsmAnd/res/layout/preference_radio_button.xml
+++ b/OsmAnd/res/layout/preference_radio_button.xml
@@ -51,7 +51,7 @@
android:id="@android:id/summary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:maxLines="4"
+ android:letterSpacing="@dimen/description_letter_spacing"
android:paddingBottom="@dimen/gpx_small_text_margin"
android:textColor="?android:textColorSecondary"
android:textSize="@dimen/default_list_text_size"
diff --git a/OsmAnd/res/layout/preference_switch.xml b/OsmAnd/res/layout/preference_switch.xml
index 5280e7cabd..608ee34789 100644
--- a/OsmAnd/res/layout/preference_switch.xml
+++ b/OsmAnd/res/layout/preference_switch.xml
@@ -22,36 +22,17 @@
android:layout_marginLeft="@dimen/content_padding"
android:layout_marginRight="@dimen/content_padding" />
-
-
-
-
-
-
-
+ android:paddingRight="@dimen/content_padding"
+ android:textColor="?android:textColorPrimary"
+ android:textSize="@dimen/default_list_text_size"
+ osmand:typeface="@string/font_roboto_regular" />
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/OsmAnd/res/layout/preference_top_switch.xml b/OsmAnd/res/layout/preference_toolbar_switch.xml
similarity index 66%
rename from OsmAnd/res/layout/preference_top_switch.xml
rename to OsmAnd/res/layout/preference_toolbar_switch.xml
index cb9848a093..8b27a58b6e 100644
--- a/OsmAnd/res/layout/preference_top_switch.xml
+++ b/OsmAnd/res/layout/preference_toolbar_switch.xml
@@ -1,36 +1,35 @@
+ android:orientation="vertical">
-
-
+ android:minHeight="@dimen/toolbar_height">
+ osmand:typeface="@string/font_roboto_medium"
+ tools:text="@string/shared_string_off" />
-
+ android:layout_marginLeft="@dimen/content_padding_half"
+ android:layout_marginTop="@dimen/content_padding"
+ android:layout_marginRight="@dimen/content_padding_half"
+ android:layout_marginBottom="@dimen/content_padding">
+
+
+
+
diff --git a/OsmAnd/res/layout/profile_button_small.xml b/OsmAnd/res/layout/profile_button_small.xml
new file mode 100644
index 0000000000..3264451f40
--- /dev/null
+++ b/OsmAnd/res/layout/profile_button_small.xml
@@ -0,0 +1,18 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/OsmAnd/res/layout/profile_preference_toolbar.xml b/OsmAnd/res/layout/profile_preference_toolbar.xml
index 29d91c3dd0..9850799fc7 100644
--- a/OsmAnd/res/layout/profile_preference_toolbar.xml
+++ b/OsmAnd/res/layout/profile_preference_toolbar.xml
@@ -31,6 +31,7 @@
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical"
+ android:letterSpacing="@dimen/text_button_letter_spacing"
android:paddingLeft="@dimen/content_padding"
android:paddingRight="@dimen/content_padding"
android:textColor="?android:textColorPrimary"
@@ -38,24 +39,12 @@
osmand:typeface="@string/font_roboto_medium"
tools:text="@string/routing_settings_2" />
-
-
-
-
-
+ android:layout_marginRight="@dimen/content_padding_half" />
diff --git a/OsmAnd/res/layout/profile_preference_toolbar_big.xml b/OsmAnd/res/layout/profile_preference_toolbar_big.xml
index d878c085a8..e848d676d5 100644
--- a/OsmAnd/res/layout/profile_preference_toolbar_big.xml
+++ b/OsmAnd/res/layout/profile_preference_toolbar_big.xml
@@ -36,6 +36,7 @@
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical"
+ android:letterSpacing="@dimen/text_button_letter_spacing"
android:paddingLeft="@dimen/content_padding"
android:paddingRight="@dimen/content_padding"
android:textColor="?android:textColorPrimary"
@@ -46,7 +47,7 @@
+ android:paddingTop="@dimen/content_padding_half"
+ android:paddingRight="@dimen/content_padding"
+ android:paddingBottom="@dimen/content_padding_half">
diff --git a/OsmAnd/res/layout/profile_preference_toolbar_with_switch.xml b/OsmAnd/res/layout/profile_preference_toolbar_with_switch.xml
new file mode 100644
index 0000000000..9e06bb7350
--- /dev/null
+++ b/OsmAnd/res/layout/profile_preference_toolbar_with_switch.xml
@@ -0,0 +1,60 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/OsmAnd/res/layout/profiles_list_fragment.xml b/OsmAnd/res/layout/profiles_list_fragment.xml
index 77cf6b705e..2cc767fa13 100644
--- a/OsmAnd/res/layout/profiles_list_fragment.xml
+++ b/OsmAnd/res/layout/profiles_list_fragment.xml
@@ -1,6 +1,20 @@
+
+
+
+
+
+
+
+
-
\ No newline at end of file
+
+
+
\ No newline at end of file
diff --git a/OsmAnd/res/values/sizes.xml b/OsmAnd/res/values/sizes.xml
index 185b9c7878..5ec78f9bce 100644
--- a/OsmAnd/res/values/sizes.xml
+++ b/OsmAnd/res/values/sizes.xml
@@ -338,6 +338,8 @@
14dp
0.01
+ 0.02
+ 0.03
1.2
4dp
diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml
index 52235fb3a1..ee4522d503 100644
--- a/OsmAnd/res/values/strings.xml
+++ b/OsmAnd/res/values/strings.xml
@@ -11,6 +11,7 @@
Thx - Hardy
-->
+ By default
Plugin settings
Logcat buffer
Application profile changed to \"%s\"
diff --git a/OsmAnd/res/xml/configure_profile.xml b/OsmAnd/res/xml/configure_profile.xml
index 7abb3a1e87..a97690645e 100644
--- a/OsmAnd/res/xml/configure_profile.xml
+++ b/OsmAnd/res/xml/configure_profile.xml
@@ -1,7 +1,8 @@
+ xmlns:tools="http://schemas.android.com/tools"
+ android:title="@string/configure_profile">
+
+
diff --git a/OsmAnd/res/xml/coordinates_format.xml b/OsmAnd/res/xml/coordinates_format.xml
index 0f1a787cbc..db722783f8 100644
--- a/OsmAnd/res/xml/coordinates_format.xml
+++ b/OsmAnd/res/xml/coordinates_format.xml
@@ -1,6 +1,7 @@
+ xmlns:tools="http://schemas.android.com/tools"
+ android:title="@string/coordinates_format">
+ xmlns:app="http://schemas.android.com/apk/res-auto"
+ android:title="@string/general_settings_2">
diff --git a/OsmAnd/res/xml/global_settings.xml b/OsmAnd/res/xml/global_settings.xml
index ef77c52c52..5194192ab7 100644
--- a/OsmAnd/res/xml/global_settings.xml
+++ b/OsmAnd/res/xml/global_settings.xml
@@ -1,7 +1,8 @@
+ xmlns:tools="http://schemas.android.com/tools"
+ android:title="@string/osmand_settings">
-
+
+ xmlns:tools="http://schemas.android.com/tools"
+ android:title="@string/routing_settings_2">
+
+
\ No newline at end of file
diff --git a/OsmAnd/res/xml/proxy_preferences.xml b/OsmAnd/res/xml/proxy_preferences.xml
index 2e854f5406..6a47f90ed4 100644
--- a/OsmAnd/res/xml/proxy_preferences.xml
+++ b/OsmAnd/res/xml/proxy_preferences.xml
@@ -5,11 +5,6 @@
android:key="proxy"
android:title="@string/proxy_pref_title">
-
-
diff --git a/OsmAnd/res/xml/route_parameters.xml b/OsmAnd/res/xml/route_parameters.xml
index 859290e55e..157d7c267b 100644
--- a/OsmAnd/res/xml/route_parameters.xml
+++ b/OsmAnd/res/xml/route_parameters.xml
@@ -1,6 +1,7 @@
+ xmlns:tools="http://schemas.android.com/tools"
+ android:title="@string/route_parameters">
-
-
+ xmlns:tools="http://schemas.android.com/tools"
+ android:title="@string/screen_alerts">
diff --git a/OsmAnd/res/xml/settings_main_screen.xml b/OsmAnd/res/xml/settings_main_screen.xml
index 1f46a36458..77fa3843d3 100644
--- a/OsmAnd/res/xml/settings_main_screen.xml
+++ b/OsmAnd/res/xml/settings_main_screen.xml
@@ -1,7 +1,8 @@
+ xmlns:tools="http://schemas.android.com/tools"
+ android:title="@string/shared_string_settings">
-
-
-
+
+ xmlns:tools="http://schemas.android.com/tools"
+ android:title="@string/vehicle_parameters">
+
-
-
+ xmlns:tools="http://schemas.android.com/tools"
+ android:title="@string/voice_announces">
@@ -39,13 +31,11 @@
android:selectable="false" />
@@ -55,31 +45,26 @@
android:selectable="false" />
@@ -89,13 +74,11 @@
android:selectable="false" />
@@ -110,7 +93,6 @@
android:title="@string/language_and_output" />
enabledPlugins = app.getSettings().getEnabledPlugins();
+ for (OsmandPlugin plugin : allPlugins) {
+ if (enabledPlugins.contains(plugin.getId())) {
+ try {
+ if (plugin.init(app, null)) {
+ plugin.setActive(true);
+ }
+ } catch (Exception e) {
+ LOG.error("Plugin initialization failed " + plugin.getId(), e);
+ }
+ } else if (plugin.isActive()) {
+ plugin.setActive(false);
+ }
+ }
+ }
+
private static void checkMarketPlugin(@NonNull OsmandApplication app, @NonNull Set enabledPlugins,
@NonNull OsmandPlugin plugin, boolean paid, String id, String id2) {
boolean marketEnabled = Version.isMarketEnabled(app);
diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java
index aeb39499ee..870a77280d 100644
--- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java
+++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java
@@ -370,7 +370,7 @@ public class OsmandSettings {
OsmandAidlApi aidlApi = ctx.getAidlApi();
if (aidlApi != null) {
aidlApi.loadConnectedApps();
- OsmandPlugin.initPlugins(ctx);
+ OsmandPlugin.updateActivatedPlugins(ctx);
}
fireEvent(oldMode);
@@ -1644,7 +1644,7 @@ public class OsmandSettings {
public final CommonPreference NOTES_SORT_BY_MODE = new EnumIntPreference<>("notes_sort_by_mode", NotesSortByMode.BY_DATE, NotesSortByMode.values());
- public final OsmandPreference ANIMATE_MY_LOCATION = new BooleanPreference("animate_my_location", true).makeGlobal().cache();
+ public final OsmandPreference ANIMATE_MY_LOCATION = new BooleanPreference("animate_my_location", true).makeProfile().cache();
public final OsmandPreference EXTERNAL_INPUT_DEVICE = new IntPreference("external_input_device", 0).makeProfile();
diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java
index ef46000379..6db6f11c12 100644
--- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java
+++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java
@@ -128,7 +128,7 @@ import net.osmand.plus.search.QuickSearchDialogFragment;
import net.osmand.plus.search.QuickSearchDialogFragment.QuickSearchTab;
import net.osmand.plus.search.QuickSearchDialogFragment.QuickSearchType;
import net.osmand.plus.settings.BaseSettingsFragment;
-import net.osmand.plus.settings.MainSettingsFragment;
+import net.osmand.plus.settings.BaseSettingsFragment.SettingsScreenType;
import net.osmand.plus.views.AddGpxPointBottomSheetHelper.NewGpxPoint;
import net.osmand.plus.views.AnimateDraggingMapThread;
import net.osmand.plus.views.MapControlsLayer;
@@ -161,6 +161,8 @@ import java.util.concurrent.Executors;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import static net.osmand.plus.OsmAndCustomizationConstants.DRAWER_SETTINGS_ID;
+
public class MapActivity extends OsmandActionBarActivity implements DownloadEvents,
OnRequestPermissionsResultCallback, IRouteInformationListener, AMapPointUpdateListener,
MapMarkerChangedListener, OnDismissDialogFragmentListener, OnDrawMapListener,
@@ -639,6 +641,13 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
chooseRouteFragment.dismiss(true);
return;
}
+ EditProfileFragment editProfileFragment = getEditProfileFragment();
+ if (editProfileFragment != null) {
+ if (!editProfileFragment.onBackPressedAllowed()) {
+ editProfileFragment.confirmCancelDialog(this);
+ return;
+ }
+ }
if (mapContextMenu.isVisible() && mapContextMenu.isClosable()) {
if (mapContextMenu.getCurrentMenuState() != MenuState.HEADER_ONLY) {
mapContextMenu.openMenuHeaderOnly();
@@ -804,6 +813,13 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
}
setIntent(null);
}
+ if (intent.hasExtra(EditProfileFragment.OPEN_SETTINGS)) {
+ String settingsType = intent.getStringExtra(EditProfileFragment.OPEN_SETTINGS);
+ if (EditProfileFragment.OPEN_CONFIG_PROFILE.equals(settingsType)) {
+ BaseSettingsFragment.showInstance(this, SettingsScreenType.CONFIGURE_PROFILE);
+ }
+ setIntent(null);
+ }
if (intent.hasExtra(EditProfileFragment.OPEN_CONFIG_ON_MAP)) {
switch (intent.getStringExtra(EditProfileFragment.OPEN_CONFIG_ON_MAP)) {
case EditProfileFragment.MAP_CONFIG:
@@ -936,10 +952,13 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
if (Build.VERSION.SDK_INT >= 21) {
int colorId = -1;
BaseOsmAndFragment fragmentAboveDashboard = getVisibleBaseOsmAndFragment(R.id.fragmentContainer);
+ BaseSettingsFragment settingsFragmentAboveDashboard = getVisibleBaseSettingsFragment(R.id.fragmentContainer);
BaseOsmAndFragment fragmentBelowDashboard = getVisibleBaseOsmAndFragment(R.id.routeMenuContainer,
R.id.topFragmentContainer, R.id.bottomFragmentContainer);
if (fragmentAboveDashboard != null) {
colorId = fragmentAboveDashboard.getStatusBarColorId();
+ } else if (settingsFragmentAboveDashboard != null) {
+ colorId = settingsFragmentAboveDashboard.getStatusBarColorId();
} else if (dashboardOnMap.isVisible()) {
colorId = dashboardOnMap.getStatusBarColor();
} else if (fragmentBelowDashboard != null) {
@@ -989,6 +1008,17 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
return null;
}
+ private BaseSettingsFragment getVisibleBaseSettingsFragment(int... ids) {
+ for (int id : ids) {
+ Fragment fragment = getSupportFragmentManager().findFragmentById(id);
+ if (fragment != null && !fragment.isRemoving() && fragment.isVisible() && fragment instanceof BaseSettingsFragment
+ && ((BaseSettingsFragment) fragment).getStatusBarColorId() != -1) {
+ return (BaseSettingsFragment) fragment;
+ }
+ }
+ return null;
+ }
+
public boolean isInAppPurchaseAllowed() {
return true;
}
@@ -1943,25 +1973,31 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
@Override
public boolean onPreferenceStartFragment(PreferenceFragmentCompat caller, Preference pref) {
- if (caller instanceof BaseSettingsFragment) {
- BaseSettingsFragment baseFragment = (BaseSettingsFragment) caller;
+ try {
+ String fragmentName = pref.getFragment();
+ Fragment fragment = Fragment.instantiate(this, fragmentName);
- ApplicationMode mode = baseFragment.getSelectedAppMode();
- if (mode != null) {
- String fragmentName = pref.getFragment();
- Fragment fragment = Fragment.instantiate(this, fragmentName);
+ getSupportFragmentManager().beginTransaction()
+ .replace(R.id.fragmentContainer, fragment, fragment.getClass().getSimpleName())
+ .addToBackStack(DRAWER_SETTINGS_ID + ".new")
+ .commit();
- getSupportFragmentManager().beginTransaction()
- .replace(R.id.fragmentContainer, fragment, fragmentName)
- .addToBackStack(fragmentName)
- .commitAllowingStateLoss();
-
- return true;
- }
+ return true;
+ } catch (Exception e) {
+ LOG.error(e);
}
+
return false;
}
+ public void dismissSettingsScreens() {
+ try {
+ getSupportFragmentManager().popBackStack(DRAWER_SETTINGS_ID + ".new", FragmentManager.POP_BACK_STACK_INCLUSIVE);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
private class ScreenOffReceiver extends BroadcastReceiver {
@Override
@@ -2179,7 +2215,8 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
}
public void showSettings() {
- MainSettingsFragment.showInstance(getSupportFragmentManager());
+ dismissSettingsScreens();
+ BaseSettingsFragment.showInstance(this, SettingsScreenType.MAIN_SETTINGS);
}
private void hideContextMenu() {
@@ -2218,6 +2255,11 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
return fragment != null && !fragment.isDetached() && !fragment.isRemoving() ? (ChooseRouteFragment) fragment : null;
}
+ public EditProfileFragment getEditProfileFragment() {
+ Fragment fragment = getSupportFragmentManager().findFragmentByTag(EditProfileFragment.TAG);
+ return fragment != null && !fragment.isDetached() && !fragment.isRemoving() ? (EditProfileFragment) fragment : null;
+ }
+
public boolean isTopToolbarActive() {
MapInfoLayer mapInfoLayer = getMapLayers().getMapInfoLayer();
return mapInfoLayer.hasTopToolbar();
diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java
index 26a6501179..49d8080bf1 100644
--- a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java
+++ b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java
@@ -63,7 +63,7 @@ import net.osmand.plus.routepreparationmenu.MapRouteInfoMenu;
import net.osmand.plus.routepreparationmenu.WaypointsFragment;
import net.osmand.plus.routing.RouteProvider.GPXRouteParamsBuilder;
import net.osmand.plus.routing.RoutingHelper;
-import net.osmand.plus.settings.ConfigureProfileFragment;
+import net.osmand.plus.settings.BaseSettingsFragment;
import net.osmand.plus.views.BaseMapLayer;
import net.osmand.plus.views.MapControlsLayer;
import net.osmand.plus.views.MapTileLayer;
@@ -1009,7 +1009,8 @@ public class MapActivityActions implements DialogProvider {
.setListener(new ItemClickListener() {
@Override
public boolean onContextMenuClick(ArrayAdapter adapter, int itemId, int position, boolean isChecked, int[] viewCoordinates) {
- ConfigureProfileFragment.showInstance(mapActivity.getSupportFragmentManager());
+ mapActivity.dismissSettingsScreens();
+ BaseSettingsFragment.showInstance(mapActivity, BaseSettingsFragment.SettingsScreenType.CONFIGURE_PROFILE);
return true;
}
})
diff --git a/OsmAnd/src/net/osmand/plus/osmedit/AdvancedEditPoiFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/AdvancedEditPoiFragment.java
index 56214e57a7..f19fcb111b 100644
--- a/OsmAnd/src/net/osmand/plus/osmedit/AdvancedEditPoiFragment.java
+++ b/OsmAnd/src/net/osmand/plus/osmedit/AdvancedEditPoiFragment.java
@@ -1,7 +1,6 @@
package net.osmand.plus.osmedit;
-import static net.osmand.plus.osmedit.EditPoiDialogFragment.AMENITY_TEXT_LENGTH;
-
+import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.NonNull;
@@ -9,6 +8,7 @@ import android.support.annotation.Nullable;
import android.text.Editable;
import android.text.InputFilter;
import android.text.TextWatcher;
+import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnFocusChangeListener;
@@ -19,6 +19,7 @@ import android.widget.Button;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;
+
import net.osmand.PlatformUtil;
import net.osmand.osm.AbstractPoiType;
import net.osmand.osm.MapPoiTypes;
@@ -28,7 +29,6 @@ import net.osmand.osm.PoiType;
import net.osmand.osm.edit.OSMSettings;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
-import net.osmand.plus.UiUtilities;
import net.osmand.plus.base.BaseOsmAndFragment;
import net.osmand.util.Algorithms;
@@ -39,6 +39,8 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
+import static net.osmand.plus.osmedit.EditPoiDialogFragment.AMENITY_TEXT_LENGTH;
+
public class AdvancedEditPoiFragment extends BaseOsmAndFragment
implements EditPoiDialogFragment.OnFragmentActivatedListener {
private static final String TAG = "AdvancedEditPoiFragment";
@@ -60,7 +62,9 @@ public class AdvancedEditPoiFragment extends BaseOsmAndFragment
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
- final View view = inflater.inflate(R.layout.fragment_edit_poi_advanced, container, false);
+ int themeRes = requireMyApplication().getSettings().isLightActionBar() ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme;
+ Context themedContext = new ContextThemeWrapper(getContext(), themeRes);
+ final View view = inflater.cloneInContext(themedContext).inflate(R.layout.fragment_edit_poi_advanced, container, false);
OsmandApplication app = requireMyApplication();
deleteDrawable = app.getUIUtilities().getIcon(R.drawable.ic_action_remove_dark, app.getSettings().isLightContent());
diff --git a/OsmAnd/src/net/osmand/plus/osmedit/BasicEditPoiFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/BasicEditPoiFragment.java
index 59c48ff48e..d676609fee 100644
--- a/OsmAnd/src/net/osmand/plus/osmedit/BasicEditPoiFragment.java
+++ b/OsmAnd/src/net/osmand/plus/osmedit/BasicEditPoiFragment.java
@@ -1,5 +1,6 @@
package net.osmand.plus.osmedit;
+import android.content.Context;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
@@ -11,6 +12,7 @@ import android.text.InputFilter;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.TypedValue;
+import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -55,10 +57,12 @@ public class BasicEditPoiFragment extends BaseOsmAndFragment
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
- View view = inflater.inflate(R.layout.fragment_edit_poi_normal, container, false);
+ int themeRes = requireMyApplication().getSettings().isLightActionBar() ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme;
+ Context themedContext = new ContextThemeWrapper(getContext(), themeRes);
+ View view = inflater.cloneInContext(themedContext).inflate(R.layout.fragment_edit_poi_normal, container, false);
TypedValue typedValue = new TypedValue();
- Resources.Theme theme = getActivity().getTheme();
+ Resources.Theme theme = themedContext.getTheme();
theme.resolveAttribute(android.R.attr.textColorSecondary, typedValue, true);
int iconColor = typedValue.data;
diff --git a/OsmAnd/src/net/osmand/plus/profiles/ConfigureProfileMenuAdapter.java b/OsmAnd/src/net/osmand/plus/profiles/ConfigureProfileMenuAdapter.java
index dbb4d39161..e9ce8cf877 100644
--- a/OsmAnd/src/net/osmand/plus/profiles/ConfigureProfileMenuAdapter.java
+++ b/OsmAnd/src/net/osmand/plus/profiles/ConfigureProfileMenuAdapter.java
@@ -11,16 +11,19 @@ import android.view.ViewGroup;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Set;
import net.osmand.PlatformUtil;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
+import net.osmand.plus.settings.BaseSettingsFragment;
import net.osmand.util.Algorithms;
+
import org.apache.commons.logging.Log;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
public class ConfigureProfileMenuAdapter extends AbstractProfileMenuAdapter {
@@ -101,12 +104,7 @@ public class ConfigureProfileMenuAdapter extends AbstractProfileMenuAdapter getRoutingProfiles(OsmandApplication context) {
List profilesObjects = new ArrayList<>();
profilesObjects.add(new RoutingProfileDataObject(
diff --git a/OsmAnd/src/net/osmand/plus/profiles/SelectProfileBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/profiles/SelectProfileBottomSheetDialogFragment.java
index 61f78e5243..bfb229c68a 100644
--- a/OsmAnd/src/net/osmand/plus/profiles/SelectProfileBottomSheetDialogFragment.java
+++ b/OsmAnd/src/net/osmand/plus/profiles/SelectProfileBottomSheetDialogFragment.java
@@ -1,30 +1,30 @@
package net.osmand.plus.profiles;
-import static net.osmand.plus.profiles.EditProfileFragment.SELECTED_ICON;
-
import android.content.res.ColorStateList;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
-import android.support.v7.widget.SwitchCompat;
+import android.support.v4.app.FragmentActivity;
+import android.support.v4.app.FragmentManager;
import android.view.View;
import android.view.View.OnClickListener;
-import android.widget.Button;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
+
import net.osmand.PlatformUtil;
-import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.LongDescriptionItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
+
import org.apache.commons.logging.Log;
+import java.util.ArrayList;
+import java.util.List;
+
+import static net.osmand.plus.profiles.EditProfileFragment.SELECTED_ICON;
+
public class SelectProfileBottomSheetDialogFragment extends MenuBottomSheetDialogFragment {
private static final Log LOG = PlatformUtil
@@ -217,20 +217,27 @@ public class SelectProfileBottomSheetDialogFragment extends MenuBottomSheetDialo
private void getListener() {
- if (getActivity() != null && getActivity() instanceof EditProfileActivity) {
- EditProfileFragment f = (EditProfileFragment) getActivity().getSupportFragmentManager()
- .findFragmentByTag(EditProfileActivity.EDIT_PROFILE_FRAGMENT_TAG);
- if (type.equals(TYPE_BASE_APP_PROFILE)) {
- listener = f.getBaseProfileListener();
- } else if (type.equals(TYPE_NAV_PROFILE)) {
- listener = f.getNavProfileListener();
- } else if (type.equals(TYPE_ICON)) {
- listener = f.getIconListener();
+ FragmentActivity activity = getActivity();
+ if (activity != null) {
+ FragmentManager fragmentManager = activity.getSupportFragmentManager();
+ EditProfileFragment editProfileFragment = (EditProfileFragment) fragmentManager.findFragmentByTag(EditProfileFragment.TAG);
+ SettingsProfileFragment settingsProfileFragment = (SettingsProfileFragment) fragmentManager.findFragmentByTag(SettingsProfileFragment.TAG);
+
+ if (editProfileFragment != null) {
+ switch (type) {
+ case TYPE_BASE_APP_PROFILE:
+ listener = editProfileFragment.getBaseProfileListener();
+ break;
+ case TYPE_NAV_PROFILE:
+ listener = editProfileFragment.getNavProfileListener();
+ break;
+ case TYPE_ICON:
+ listener = editProfileFragment.getIconListener();
+ break;
+ }
+ } else if (settingsProfileFragment != null) {
+ listener = settingsProfileFragment.getBaseProfileListener();
}
- } else if (getActivity() != null && getActivity() instanceof SettingsProfileActivity) {
- SettingsProfileFragment f = (SettingsProfileFragment) getActivity().getSupportFragmentManager()
- .findFragmentByTag(SettingsProfileActivity.SETTINGS_PROFILE_FRAGMENT_TAG);
- listener = f.getBaseProfileListener();
}
}
diff --git a/OsmAnd/src/net/osmand/plus/profiles/SelectProfileMenuAdapter.java b/OsmAnd/src/net/osmand/plus/profiles/SelectProfileMenuAdapter.java
index ed0241a016..601c940e0a 100644
--- a/OsmAnd/src/net/osmand/plus/profiles/SelectProfileMenuAdapter.java
+++ b/OsmAnd/src/net/osmand/plus/profiles/SelectProfileMenuAdapter.java
@@ -18,6 +18,7 @@ import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
+import net.osmand.plus.settings.BaseSettingsFragment;
import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log;
@@ -95,12 +96,7 @@ public class SelectProfileMenuAdapter extends AbstractProfileMenuAdapter allAppModes;
private Set availableAppModes;
private List baseProfiles;
+ private boolean nightMode;
+
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -63,10 +75,36 @@ public class SettingsProfileFragment extends BaseOsmAndFragment
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
+ nightMode = !requireSettings().isLightContent();
- View view = inflater.inflate(R.layout.profiles_list_fragment, container, false);
- recyclerView = view.findViewById(R.id.profiles_list);
- addNewProfileBtn = view.findViewById(R.id.add_profile_btn);
+ int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
+ Context themedContext = new ContextThemeWrapper(getContext(), themeRes);
+ View view = inflater.cloneInContext(themedContext).inflate(R.layout.profiles_list_fragment, container, false);
+
+ AppBarLayout appBar = (AppBarLayout) view.findViewById(R.id.appbar);
+ if (!(getActivity() instanceof SettingsProfileActivity)) {
+ AndroidUtils.addStatusBarPadding21v(getContext(), view);
+ ViewCompat.setElevation(appBar, 5.0f);
+
+ TextView toolbarTitle = (TextView) view.findViewById(R.id.toolbar_title);
+ toolbarTitle.setText(R.string.application_profiles);
+
+ View closeButton = view.findViewById(R.id.close_button);
+ closeButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ MapActivity mapActivity = (MapActivity) getActivity();
+ if (mapActivity != null) {
+ mapActivity.onBackPressed();
+ }
+ }
+ });
+ } else {
+ AndroidUiHelper.updateVisibility(appBar, false);
+ }
+
+ RecyclerView recyclerView = view.findViewById(R.id.profiles_list);
+ LinearLayout addNewProfileBtn = view.findViewById(R.id.add_profile_btn);
addNewProfileBtn.setOnClickListener(new OnClickListener() {
@@ -102,16 +140,32 @@ public class SettingsProfileFragment extends BaseOsmAndFragment
adapter.updateItemsList(allAppModes, new LinkedHashSet<>(ApplicationMode.values(getMyApplication())));
}
+ @Override
+ public int getStatusBarColorId() {
+ return nightMode ? R.color.status_bar_color_dark : R.color.status_bar_color_light;
+ }
+
SelectProfileListener getBaseProfileListener() {
if (typeListener == null) {
typeListener = new SelectProfileListener() {
@Override
public void onSelectedType(int pos, String stringRes) {
- Intent intent = new Intent(getActivity(), EditProfileActivity.class);
- intent.putExtra(IS_NEW_PROFILE, true);
- intent.putExtra(IS_USER_PROFILE, true);
- intent.putExtra(PROFILE_STRING_KEY, baseProfiles.get(pos).getStringKey());
- startActivity(intent);
+ FragmentActivity activity = getActivity();
+ if (activity != null) {
+ if (activity instanceof SettingsProfileActivity) {
+ Intent intent = new Intent(getActivity(), EditProfileActivity.class);
+ intent.putExtra(IS_NEW_PROFILE, true);
+ intent.putExtra(IS_USER_PROFILE, true);
+ intent.putExtra(PROFILE_STRING_KEY, baseProfiles.get(pos).getStringKey());
+ activity.startActivity(intent);
+ } else {
+ FragmentManager fragmentManager = activity.getSupportFragmentManager();
+ if (fragmentManager != null) {
+ String profileKey = baseProfiles.get(pos).getStringKey();
+ EditProfileFragment.showInstance(fragmentManager, true, true, profileKey);
+ }
+ }
+ }
}
};
}
@@ -131,17 +185,28 @@ public class SettingsProfileFragment extends BaseOsmAndFragment
@Override
public void onProfilePressed(ApplicationMode item) {
- Intent intent = new Intent(getActivity(), EditProfileActivity.class);
- intent.putExtra(PROFILE_STRING_KEY, item.getStringKey());
- if (item.isCustomProfile()) {
- intent.putExtra(IS_USER_PROFILE, true);
+ FragmentActivity activity = getActivity();
+ if (activity != null) {
+ if (activity instanceof SettingsProfileActivity) {
+ Intent intent = new Intent(getActivity(), EditProfileActivity.class);
+ intent.putExtra(PROFILE_STRING_KEY, item.getStringKey());
+ if (item.isCustomProfile()) {
+ intent.putExtra(IS_USER_PROFILE, true);
+ }
+ activity.startActivity(intent);
+ } else {
+ FragmentManager fragmentManager = activity.getSupportFragmentManager();
+ if (fragmentManager != null) {
+ String profileKey = item.getStringKey();
+ EditProfileFragment.showInstance(fragmentManager, false, item.isCustomProfile(), profileKey);
+ }
+ }
}
- startActivity(intent);
}
@Override
public void onProfileSelected(ApplicationMode item, boolean isChecked) {
- if(isChecked) {
+ if (isChecked) {
availableAppModes.add(item);
} else {
availableAppModes.remove(item);
diff --git a/OsmAnd/src/net/osmand/plus/settings/BaseSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/BaseSettingsFragment.java
index 3dc47b5147..2163069af1 100644
--- a/OsmAnd/src/net/osmand/plus/settings/BaseSettingsFragment.java
+++ b/OsmAnd/src/net/osmand/plus/settings/BaseSettingsFragment.java
@@ -10,15 +10,14 @@ import android.os.Bundle;
import android.support.annotation.ColorInt;
import android.support.annotation.ColorRes;
import android.support.annotation.DrawableRes;
-import android.support.annotation.LayoutRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
-import android.support.annotation.StringRes;
-import android.support.annotation.XmlRes;
import android.support.design.widget.AppBarLayout;
+import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.content.ContextCompat;
+import android.support.v4.view.ViewCompat;
import android.support.v7.preference.EditTextPreference;
import android.support.v7.preference.ListPreference;
import android.support.v7.preference.Preference;
@@ -57,27 +56,64 @@ import net.osmand.plus.settings.bottomsheets.SingleSelectPreferenceBottomSheet;
import net.osmand.plus.settings.preferences.ListPreferenceEx;
import net.osmand.plus.settings.preferences.MultiSelectBooleanPreference;
import net.osmand.plus.settings.preferences.SwitchPreferenceEx;
+import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log;
+import static net.osmand.plus.OsmAndCustomizationConstants.DRAWER_SETTINGS_ID;
+
public abstract class BaseSettingsFragment extends PreferenceFragmentCompat implements OnPreferenceChangeListener,
OnPreferenceClickListener, AppModeChangedListener {
- protected final Log log = PlatformUtil.getLog(this.getClass());
+ private static final Log LOG = PlatformUtil.getLog(BaseSettingsFragment.class);
protected OsmandApplication app;
protected OsmandSettings settings;
protected UiUtilities iconsCache;
- private int themeRes;
+ protected int themeRes;
+
+ private SettingsScreenType currentScreenType;
+
+ private int statusBarColor = -1;
private boolean nightMode;
private boolean wasDrawerDisabled;
+ public enum SettingsScreenType {
+
+ MAIN_SETTINGS(MainSettingsFragment.class.getName(), false, R.xml.settings_main_screen, R.layout.global_preference_toolbar),
+ GLOBAL_SETTINGS(GlobalSettingsFragment.class.getName(), false, R.xml.global_settings, R.layout.global_preference_toolbar),
+ CONFIGURE_PROFILE(ConfigureProfileFragment.class.getName(), true, R.xml.configure_profile, R.layout.profile_preference_toolbar_big),
+ PROXY_SETTINGS(ProxySettingsFragment.class.getName(), false, R.xml.proxy_preferences, R.layout.global_preferences_toolbar_with_switch),
+ GENERAL_PROFILE(GeneralProfileSettingsFragment.class.getName(), true, R.xml.general_profile_settings, R.layout.profile_preference_toolbar_big),
+ NAVIGATION(NavigationFragment.class.getName(), true, R.xml.navigation_settings_new, R.layout.profile_preference_toolbar_big),
+ COORDINATES_FORMAT(CoordinatesFormatFragment.class.getName(), true, R.xml.coordinates_format, R.layout.profile_preference_toolbar),
+ ROUTE_PARAMETERS(RouteParametersFragment.class.getName(), true, R.xml.route_parameters, R.layout.profile_preference_toolbar),
+ SCREEN_ALERTS(ScreenAlertsFragment.class.getName(), true, R.xml.screen_alerts, R.layout.profile_preference_toolbar_with_switch),
+ VOICE_ANNOUNCES(VoiceAnnouncesFragment.class.getName(), true, R.xml.voice_announces, R.layout.profile_preference_toolbar_with_switch),
+ VEHICLE_PARAMETERS(VehicleParametersFragment.class.getName(), true, R.xml.vehicle_parameters, R.layout.profile_preference_toolbar),
+ MAP_DURING_NAVIGATION(MapDuringNavigationFragment.class.getName(), true, R.xml.map_during_navigation, R.layout.profile_preference_toolbar),
+ TURN_SCREEN_ON(TurnScreenOnFragment.class.getName(), true, R.xml.turn_screen_on, R.layout.profile_preference_toolbar_with_switch);
+
+ public final String fragmentName;
+ public final boolean profileDependent;
+ public final int preferencesResId;
+ public final int toolbarResId;
+
+ SettingsScreenType(String fragmentName, boolean profileDependent, int preferencesResId, int toolbarResId) {
+ this.fragmentName = fragmentName;
+ this.profileDependent = profileDependent;
+ this.preferencesResId = preferencesResId;
+ this.toolbarResId = toolbarResId;
+ }
+ }
+
@Override
public void onCreate(Bundle savedInstanceState) {
app = requireMyApplication();
settings = app.getSettings();
super.onCreate(savedInstanceState);
+ currentScreenType = getCurrentScreenType();
}
@Override
@@ -93,15 +129,21 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
View view = super.onCreateView(inflater, container, savedInstanceState);
if (view != null) {
AndroidUtils.addStatusBarPadding21v(getContext(), view);
+ updateAllSettings();
createToolbar(inflater, view);
setDivider(null);
- updateAllSettings();
view.setBackgroundColor(ContextCompat.getColor(app, getBackgroundColorRes()));
}
return view;
}
+ @Override
+ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
+ super.onViewCreated(view, savedInstanceState);
+ updateToolbar();
+ }
+
@Override
public RecyclerView onCreateRecyclerView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
Context themedContext = new ContextThemeWrapper(getActivity(), themeRes);
@@ -133,7 +175,6 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
@Override
public void onResume() {
super.onResume();
-
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
wasDrawerDisabled = mapActivity.isDrawerDisabled();
@@ -141,6 +182,21 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
mapActivity.disableDrawer();
}
}
+
+ if (Build.VERSION.SDK_INT >= 21) {
+ Activity activity = getActivity();
+ if (activity != null) {
+ int colorId = getStatusBarColorId();
+ if (colorId != -1) {
+ if (activity instanceof MapActivity) {
+ ((MapActivity) activity).updateStatusBarColor();
+ } else {
+ statusBarColor = activity.getWindow().getStatusBarColor();
+ activity.getWindow().setStatusBarColor(ContextCompat.getColor(activity, colorId));
+ }
+ }
+ }
+ }
}
@Override
@@ -151,6 +207,40 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
if (!wasDrawerDisabled && mapActivity != null) {
mapActivity.enableDrawer();
}
+
+ if (Build.VERSION.SDK_INT >= 21) {
+ Activity activity = getActivity();
+ if (activity != null) {
+ if (!(activity instanceof MapActivity) && statusBarColor != -1) {
+ activity.getWindow().setStatusBarColor(statusBarColor);
+ }
+ }
+ }
+ }
+
+ @Override
+ public void onDetach() {
+ super.onDetach();
+ if (Build.VERSION.SDK_INT >= 21 && getStatusBarColorId() != -1) {
+ Activity activity = getActivity();
+ if (activity instanceof MapActivity) {
+ ((MapActivity) activity).updateStatusBarColor();
+ }
+ }
+ }
+
+ @ColorRes
+ public int getStatusBarColorId() {
+ boolean nightMode = isNightMode();
+ if (currentScreenType.profileDependent) {
+ View view = getView();
+ if (view != null && Build.VERSION.SDK_INT >= 23 && !nightMode) {
+ view.setSystemUiVisibility(view.getSystemUiVisibility() | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
+ }
+ return nightMode ? R.color.list_background_color_dark : R.color.list_background_color_light;
+ } else {
+ return nightMode ? R.color.status_bar_color_dark : R.color.status_bar_color_light;
+ }
}
@Override
@@ -185,6 +275,7 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
@Override
public void onAppModeChanged() {
+ updateToolbar();
updateAllSettings();
}
@@ -206,40 +297,43 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
adapter.onPreferenceChange(preference);
}
- private void createToolbar(LayoutInflater inflater, View view) {
+ protected void createToolbar(LayoutInflater inflater, View view) {
AppBarLayout appBarLayout = (AppBarLayout) view.findViewById(R.id.appbar);
+ ViewCompat.setElevation(appBarLayout, 5.0f);
- int toolbarRes = getToolbarResId();
- if (toolbarRes != -1) {
- Context themedContext = new ContextThemeWrapper(getActivity(), themeRes);
- View toolbarContainer = inflater.cloneInContext(themedContext).inflate(toolbarRes, appBarLayout);
+ Context themedContext = new ContextThemeWrapper(getActivity(), themeRes);
+ View toolbarContainer = inflater.cloneInContext(themedContext).inflate(currentScreenType.toolbarResId, appBarLayout);
- toolbarContainer.findViewById(R.id.close_button).setOnClickListener(new View.OnClickListener() {
+ TextView toolbarTitle = (TextView) view.findViewById(R.id.toolbar_title);
+ toolbarTitle.setText(getPreferenceScreen().getTitle());
+
+ View closeButton = view.findViewById(R.id.close_button);
+ closeButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ MapActivity mapActivity = getMapActivity();
+ if (mapActivity != null) {
+ mapActivity.onBackPressed();
+ }
+ }
+ });
+ View switchProfile = toolbarContainer.findViewById(R.id.profile_button);
+ if (switchProfile != null) {
+ switchProfile.setContentDescription(getString(R.string.switch_profile));
+ switchProfile.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
- MapActivity mapActivity = getMapActivity();
- if (mapActivity != null) {
- mapActivity.onBackPressed();
+ FragmentManager fragmentManager = getFragmentManager();
+ if (fragmentManager != null) {
+ SelectAppModesBottomSheetDialogFragment.showInstance(fragmentManager, BaseSettingsFragment.this);
}
}
});
- View switchProfile = toolbarContainer.findViewById(R.id.switch_profile_button);
- if (switchProfile != null) {
- switchProfile.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- FragmentManager fragmentManager = getFragmentManager();
- if (fragmentManager != null) {
- SelectAppModesBottomSheetDialogFragment.showInstance(fragmentManager, BaseSettingsFragment.this);
- }
- }
- });
- }
- updateToolbar(toolbarContainer);
}
}
- private void updateToolbar(View view) {
+ protected void updateToolbar() {
+ View view = getView();
if (view == null) {
return;
}
@@ -247,10 +341,6 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
ApplicationMode selectedAppMode = getSelectedAppMode();
int iconColor = getActiveProfileColor();
- TextView toolbarTitle = (TextView) view.findViewById(R.id.toolbar_title);
- if (toolbarTitle != null) {
- toolbarTitle.setText(getToolbarTitle());
- }
ImageView profileIcon = (ImageView) view.findViewById(R.id.profile_icon);
if (profileIcon != null) {
int iconRes = selectedAppMode.getIconRes();
@@ -261,24 +351,30 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
String appName = selectedAppMode.toHumanString(app);
profileTitle.setText(appName);
}
- TextView profileType = (TextView) view.findViewById(R.id.profile_type);
- if (profileType != null) {
- profileType.setVisibility(View.GONE);
- }
View toolbarDivider = view.findViewById(R.id.toolbar_divider);
if (toolbarDivider != null) {
toolbarDivider.setBackgroundColor(iconColor);
}
- View profileButton = view.findViewById(R.id.switch_profile_button);
+ updateProfileButton();
+ }
+
+ private void updateProfileButton() {
+ View view = getView();
+ if (view == null) {
+ return;
+ }
+
+ View profileButton = view.findViewById(R.id.profile_button);
if (profileButton != null) {
- int toolbarRes = getToolbarResId();
+ int toolbarRes = currentScreenType.toolbarResId;
+ int iconColor = getActiveProfileColor();
int bgColor = UiUtilities.getColorWithAlpha(iconColor, 0.1f);
int selectedColor = UiUtilities.getColorWithAlpha(iconColor, 0.3f);
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
int bgResId = 0;
int selectableResId = 0;
- if (toolbarRes == R.layout.profile_preference_toolbar) {
+ if (toolbarRes == R.layout.profile_preference_toolbar || toolbarRes == R.layout.profile_preference_toolbar_with_switch) {
bgResId = R.drawable.circle_background_light;
selectableResId = R.drawable.ripple_circle;
} else if (toolbarRes == R.layout.profile_preference_toolbar_big) {
@@ -291,7 +387,7 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
AndroidUtils.setBackground(profileButton, new LayerDrawable(layers));
} else {
int bgResId = 0;
- if (toolbarRes == R.layout.profile_preference_toolbar) {
+ if (toolbarRes == R.layout.profile_preference_toolbar || toolbarRes == R.layout.profile_preference_toolbar_with_switch) {
bgResId = R.drawable.circle_background_light;
} else if (toolbarRes == R.layout.profile_preference_toolbar_big) {
bgResId = R.drawable.rectangle_rounded;
@@ -304,12 +400,12 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
private void updatePreferencesScreen() {
if (getSelectedAppMode() != null) {
- int resId = getPreferencesResId();
+ int resId = currentScreenType.preferencesResId;
if (resId != -1) {
addPreferencesFromResource(resId);
- setupPreferences();
- registerPreferences(getPreferenceScreen());
}
+ setupPreferences();
+ registerPreferences(getPreferenceScreen());
}
}
@@ -331,34 +427,25 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
getPreferenceScreen().removeAll();
}
updatePreferencesScreen();
- updateToolbar(getView());
}
- @XmlRes
- protected int getPreferencesResId() {
- return -1;
- }
-
- @LayoutRes
- protected int getToolbarResId() {
- return -1;
- }
-
- @StringRes
- protected int getToolbarTitle() {
- return R.string.shared_string_settings;
- }
-
- @ColorRes
- protected int getStatusBarColorId() {
- View view = getView();
- if (view != null) {
- if (Build.VERSION.SDK_INT >= 23 && !isNightMode()) {
- view.setSystemUiVisibility(view.getSystemUiVisibility() | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
+ protected void enableDisablePreferences(boolean enable) {
+ PreferenceScreen screen = getPreferenceScreen();
+ if (screen != null) {
+ for (int i = 0; i < screen.getPreferenceCount(); i++) {
+ screen.getPreference(i).setEnabled(enable);
}
- return isNightMode() ? R.color.list_background_color_dark : R.color.list_background_color_light;
}
- return -1;
+ }
+
+ private SettingsScreenType getCurrentScreenType() {
+ String fragmentName = this.getClass().getName();
+ for (SettingsScreenType type : SettingsScreenType.values()) {
+ if (type.fragmentName.equals(fragmentName)) {
+ return type;
+ }
+ }
+ return null;
}
@ColorInt
@@ -451,6 +538,22 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
return iconsCache;
}
+ @Nullable
+ protected OsmandSettings getSettings() {
+ OsmandApplication app = getMyApplication();
+ if (app != null) {
+ return app.getSettings();
+ } else {
+ return null;
+ }
+ }
+
+ @NonNull
+ protected OsmandSettings requireSettings() {
+ OsmandApplication app = requireMyApplication();
+ return app.getSettings();
+ }
+
protected Drawable getIcon(@DrawableRes int id) {
UiUtilities cache = getIconsCache();
return cache != null ? cache.getIcon(id) : null;
@@ -476,22 +579,6 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
return cache != null ? cache.getPaintedIcon(id, color) : null;
}
- @Nullable
- protected OsmandSettings getSettings() {
- OsmandApplication app = getMyApplication();
- if (app != null) {
- return app.getSettings();
- } else {
- return null;
- }
- }
-
- @NonNull
- protected OsmandSettings requireSettings() {
- OsmandApplication app = requireMyApplication();
- return app.getSettings();
- }
-
public SwitchPreferenceCompat createSwitchPreference(OsmandSettings.OsmandPreference b, int title, int summary, int layoutId) {
return createSwitchPreference(b, getString(title), getString(summary), layoutId);
}
@@ -509,10 +596,6 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
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);
@@ -540,4 +623,32 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
return listPreference;
}
+
+ public static String getAppModeDescription(Context ctx, ApplicationMode mode) {
+ String description;
+ if (mode.isCustomProfile()) {
+ description = String.format(ctx.getString(R.string.profile_type_descr_string),
+ Algorithms.capitalizeFirstLetterAndLowercase(mode.getParent().toHumanString(ctx)));
+ } else {
+ description = ctx.getString(R.string.profile_type_base_string);
+ }
+
+ return description;
+ }
+
+ public static boolean showInstance(FragmentActivity activity, SettingsScreenType screenType) {
+ try {
+ Fragment fragment = Fragment.instantiate(activity, screenType.fragmentName);
+
+ activity.getSupportFragmentManager().beginTransaction()
+ .replace(R.id.fragmentContainer, fragment, screenType.fragmentName)
+ .addToBackStack(DRAWER_SETTINGS_ID + ".new")
+ .commit();
+
+ return true;
+ } catch (Exception e) {
+ LOG.error(e);
+ }
+ return false;
+ }
}
\ No newline at end of file
diff --git a/OsmAnd/src/net/osmand/plus/settings/ConfigureProfileFragment.java b/OsmAnd/src/net/osmand/plus/settings/ConfigureProfileFragment.java
index 0076b66926..69c0554a26 100644
--- a/OsmAnd/src/net/osmand/plus/settings/ConfigureProfileFragment.java
+++ b/OsmAnd/src/net/osmand/plus/settings/ConfigureProfileFragment.java
@@ -7,8 +7,10 @@ import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
+import android.os.Build;
import android.os.Bundle;
import android.support.annotation.ColorRes;
+import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.content.ContextCompat;
import android.support.v7.preference.Preference;
@@ -20,8 +22,10 @@ import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
+import android.widget.TextView;
import net.osmand.AndroidUtils;
+import net.osmand.PlatformUtil;
import net.osmand.aidl.OsmandAidlApi;
import net.osmand.aidl.OsmandAidlApi.ConnectedApp;
import net.osmand.plus.ApplicationMode;
@@ -30,34 +34,27 @@ import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.PluginActivity;
+import net.osmand.plus.helpers.FontCache;
import net.osmand.plus.settings.preferences.SwitchPreferenceEx;
+import org.apache.commons.logging.Log;
+
import java.util.List;
import static net.osmand.plus.profiles.EditProfileFragment.MAP_CONFIG;
import static net.osmand.plus.profiles.EditProfileFragment.OPEN_CONFIG_ON_MAP;
+import static net.osmand.plus.profiles.EditProfileFragment.SCREEN_CONFIG;
import static net.osmand.plus.profiles.EditProfileFragment.SELECTED_ITEM;
public class ConfigureProfileFragment extends BaseSettingsFragment {
- public static final String TAG = "ConfigureProfileFragment";
+ public static final String TAG = ConfigureProfileFragment.class.getSimpleName();
+
+ private static final Log log = PlatformUtil.getLog(ConfigureProfileFragment.class);
private static final String PLUGIN_SETTINGS = "plugin_settings";
-
- @Override
- protected int getPreferencesResId() {
- return R.xml.configure_profile;
- }
-
- @Override
- protected int getToolbarResId() {
- return R.layout.profile_preference_toolbar_big;
- }
-
- @Override
- protected int getToolbarTitle() {
- return R.string.configure_profile;
- }
+ private static final String CONFIGURE_MAP = "configure_map";
+ private static final String CONFIGURE_SCREEN = "configure_screen";
@ColorRes
protected int getBackgroundColorRes() {
@@ -73,6 +70,35 @@ public class ConfigureProfileFragment extends BaseSettingsFragment {
return view;
}
+ @Override
+ protected void createToolbar(LayoutInflater inflater, View view) {
+ super.createToolbar(inflater, view);
+
+ TextView toolbarTitle = (TextView) view.findViewById(R.id.profile_title);
+ toolbarTitle.setTypeface(FontCache.getRobotoMedium(view.getContext()));
+
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
+ float letterSpacing = AndroidUtils.getFloatValueFromRes(view.getContext(), R.dimen.title_letter_spacing);
+ toolbarTitle.setLetterSpacing(letterSpacing);
+ }
+ TextView profileType = (TextView) view.findViewById(R.id.profile_type);
+ profileType.setVisibility(View.VISIBLE);
+ }
+
+ @Override
+ protected void updateToolbar() {
+ super.updateToolbar();
+
+ View view = getView();
+ if (view != null) {
+ ApplicationMode selectedMode = getSelectedAppMode();
+ String appModeType = getAppModeDescription(view.getContext(), selectedMode);
+
+ TextView profileType = (TextView) view.findViewById(R.id.profile_type);
+ profileType.setText(appModeType);
+ }
+ }
+
private RecyclerView.ItemDecoration createDividerItemDecoration() {
final Drawable dividerLight = new ColorDrawable(ContextCompat.getColor(app, R.color.list_background_color_light));
final Drawable dividerDark = new ColorDrawable(ContextCompat.getColor(app, R.color.list_background_color_dark));
@@ -127,6 +153,7 @@ public class ConfigureProfileFragment extends BaseSettingsFragment {
setupNavigationSettingsPref();
setupConfigureMapPref();
+ setupConfigureScreenPref();
PreferenceCategory pluginSettings = (PreferenceCategory) findPreference(PLUGIN_SETTINGS);
pluginSettings.setIconSpaceReserved(false);
@@ -138,9 +165,7 @@ public class ConfigureProfileFragment extends BaseSettingsFragment {
private void setupNavigationSettingsPref() {
Preference navigationSettings = findPreference("navigation_settings");
navigationSettings.setIcon(getContentIcon(R.drawable.ic_action_gdirections_dark));
- if (getSelectedAppMode() == ApplicationMode.DEFAULT) {
- navigationSettings.setVisible(false);
- }
+ navigationSettings.setVisible(!getSelectedAppMode().isDerivedRoutingFrom(ApplicationMode.DEFAULT));
}
private void setupConfigureMapPref() {
@@ -148,14 +173,27 @@ public class ConfigureProfileFragment extends BaseSettingsFragment {
if (ctx == null) {
return;
}
- Preference configureMap = findPreference("configure_map");
+ Preference configureMap = findPreference(CONFIGURE_MAP);
configureMap.setIcon(getContentIcon(R.drawable.ic_action_layers_dark));
Intent intent = new Intent(ctx, MapActivity.class);
intent.putExtra(OPEN_CONFIG_ON_MAP, MAP_CONFIG);
intent.putExtra(SELECTED_ITEM, getSelectedAppMode().getStringKey());
configureMap.setIntent(intent);
- configureMap.setVisible(false);
+ }
+
+ private void setupConfigureScreenPref() {
+ Context ctx = getContext();
+ if (ctx == null) {
+ return;
+ }
+ Preference configureMap = findPreference(CONFIGURE_SCREEN);
+ configureMap.setIcon(getContentIcon(R.drawable.ic_configure_screen_dark));
+
+ Intent intent = new Intent(ctx, MapActivity.class);
+ intent.putExtra(OPEN_CONFIG_ON_MAP, SCREEN_CONFIG);
+ intent.putExtra(SELECTED_ITEM, getSelectedAppMode().getStringKey());
+ configureMap.setIntent(intent);
}
private void setupConnectedAppsPref(PreferenceCategory preferenceCategory) {
@@ -214,6 +252,30 @@ public class ConfigureProfileFragment extends BaseSettingsFragment {
return intent;
}
+ @Override
+ public boolean onPreferenceClick(Preference preference) {
+ String prefId = preference.getKey();
+
+ if (CONFIGURE_MAP.equals(prefId) || CONFIGURE_SCREEN.equals(prefId)) {
+ FragmentActivity activity = getActivity();
+ if (activity != null) {
+ try {
+ FragmentManager fragmentManager = activity.getSupportFragmentManager();
+ if (fragmentManager != null) {
+ fragmentManager.beginTransaction()
+ .remove(this)
+ .addToBackStack(TAG)
+ .commitAllowingStateLoss();
+ }
+ } catch (Exception e) {
+ log.error(e);
+ }
+ }
+ }
+
+ return super.onPreferenceClick(preference);
+ }
+
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
String key = preference.getKey();
@@ -241,17 +303,4 @@ public class ConfigureProfileFragment extends BaseSettingsFragment {
return super.onPreferenceChange(preference, newValue);
}
-
- public static boolean showInstance(FragmentManager fragmentManager) {
- try {
- ConfigureProfileFragment configureProfileFragment = new ConfigureProfileFragment();
- fragmentManager.beginTransaction()
- .replace(R.id.fragmentContainer, configureProfileFragment, TAG)
- .addToBackStack(TAG)
- .commitAllowingStateLoss();
- return true;
- } catch (Exception e) {
- return false;
- }
- }
}
\ No newline at end of file
diff --git a/OsmAnd/src/net/osmand/plus/settings/CoordinatesFormatFragment.java b/OsmAnd/src/net/osmand/plus/settings/CoordinatesFormatFragment.java
index baf9dedf04..02afd073b4 100644
--- a/OsmAnd/src/net/osmand/plus/settings/CoordinatesFormatFragment.java
+++ b/OsmAnd/src/net/osmand/plus/settings/CoordinatesFormatFragment.java
@@ -22,6 +22,7 @@ import android.widget.TextView;
import net.osmand.Location;
import net.osmand.data.PointDescription;
+import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.R;
import net.osmand.plus.settings.bottomsheets.ChangeGeneralProfilesPrefBottomSheet;
@@ -30,7 +31,7 @@ import net.osmand.plus.wikipedia.WikipediaDialogFragment;
public class CoordinatesFormatFragment extends BaseSettingsFragment {
- public static final String TAG = "CoordinatesFormatFragment";
+ public static final String TAG = CoordinatesFormatFragment.class.getSimpleName();
private static final String UTM_FORMAT_WIKI_LINK = "https://en.wikipedia.org/wiki/Universal_Transverse_Mercator_coordinate_system";
@@ -40,21 +41,6 @@ public class CoordinatesFormatFragment extends BaseSettingsFragment {
private static final String UTM_FORMAT = "utm_format";
private static final String OLC_FORMAT = "olc_format";
- @Override
- protected int getPreferencesResId() {
- return R.xml.coordinates_format;
- }
-
- @Override
- protected int getToolbarResId() {
- return R.layout.profile_preference_toolbar;
- }
-
- @Override
- protected int getToolbarTitle() {
- return R.string.coordinates_format;
- }
-
@Override
protected void setupPreferences() {
Preference generalSettings = findPreference("coordinates_format_info");
@@ -178,10 +164,13 @@ public class CoordinatesFormatFragment extends BaseSettingsFragment {
int newFormat = getCoordinatesFormatForKey(key);
if (newFormat != -1) {
- if (settings.COORDINATES_FORMAT.isSetForMode(getSelectedAppMode())) {
- settings.COORDINATES_FORMAT.set(newFormat);
- updateSelectedFormatPrefs(key);
- return true;
+ ApplicationMode selectedAppMode = getSelectedAppMode();
+ if (settings.COORDINATES_FORMAT.isSetForMode(selectedAppMode)) {
+ if (!settings.COORDINATES_FORMAT.getModeValue(selectedAppMode).equals(newFormat)) {
+ settings.COORDINATES_FORMAT.set(newFormat);
+ updateSelectedFormatPrefs(key);
+ return true;
+ }
} else {
FragmentManager fragmentManager = getFragmentManager();
if (fragmentManager != null) {
diff --git a/OsmAnd/src/net/osmand/plus/settings/GeneralProfileSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/GeneralProfileSettingsFragment.java
index 472d54361d..447c5e8a36 100644
--- a/OsmAnd/src/net/osmand/plus/settings/GeneralProfileSettingsFragment.java
+++ b/OsmAnd/src/net/osmand/plus/settings/GeneralProfileSettingsFragment.java
@@ -7,43 +7,36 @@ import android.support.annotation.NonNull;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.AlertDialog;
import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceViewHolder;
+import android.support.v7.preference.TwoStatePreference;
import android.support.v7.widget.AppCompatCheckedTextView;
+import android.support.v7.widget.SwitchCompat;
+import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
+import android.widget.CompoundButton;
import android.widget.TextView;
+import net.osmand.AndroidUtils;
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.helpers.FontCache;
import net.osmand.plus.settings.bottomsheets.ChangeGeneralProfilesPrefBottomSheet;
import net.osmand.plus.settings.preferences.ListPreferenceEx;
import net.osmand.plus.settings.preferences.SwitchPreferenceEx;
+import net.osmand.plus.widgets.style.CustomTypefaceSpan;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
-public class GeneralProfileSettingsFragment extends BaseSettingsFragment {
+public class GeneralProfileSettingsFragment extends BaseSettingsFragment implements OnPreferenceChanged {
- public static final String TAG = "GeneralProfileSettingsFragment";
-
- @Override
- protected int getPreferencesResId() {
- return R.xml.general_profile_settings;
- }
-
- @Override
- protected int getToolbarResId() {
- return R.layout.profile_preference_toolbar_big;
- }
-
- @Override
- protected int getToolbarTitle() {
- return R.string.general_settings_2;
- }
+ public static final String TAG = GeneralProfileSettingsFragment.class.getSimpleName();
@Override
protected void setupPreferences() {
@@ -62,6 +55,57 @@ public class GeneralProfileSettingsFragment extends BaseSettingsFragment {
setupExternalInputDevicePref();
}
+ @Override
+ protected void onBindPreferenceViewHolder(Preference preference, PreferenceViewHolder holder) {
+ super.onBindPreferenceViewHolder(preference, holder);
+
+ String prefId = preference.getKey();
+ if (settings.EXTERNAL_INPUT_DEVICE.getId().equals(prefId)) {
+ boolean checked = settings.EXTERNAL_INPUT_DEVICE.get() != OsmandSettings.NO_EXTERNAL_DEVICE;
+
+ SwitchCompat switchView = (SwitchCompat) holder.findViewById(R.id.switchWidget);
+ switchView.setOnCheckedChangeListener(null);
+ switchView.setChecked(checked);
+ switchView.setOnCheckedChangeListener(externalInputDeviceListener);
+ }
+
+ OsmandSettings.OsmandPreference osmandPreference = settings.getPreference(prefId);
+ TextView summaryView = (TextView) holder.findViewById(android.R.id.summary);
+ if (osmandPreference != null && summaryView != null) {
+ CharSequence summary = null;
+
+ if (preference instanceof TwoStatePreference) {
+ TwoStatePreference statePreference = (TwoStatePreference) preference;
+ summary = statePreference.isChecked() ? statePreference.getSummaryOn() : statePreference.getSummaryOff();
+ }
+ if (TextUtils.isEmpty(summary)) {
+ summary = preference.getSummary();
+ }
+ if (!osmandPreference.isSetForMode(getSelectedAppMode())) {
+ String baseString = getString(R.string.shared_string_by_default) + ": %s";
+ summary = AndroidUtils.getStyledString(baseString, summary, new CustomTypefaceSpan(FontCache.getRobotoMedium(app)), null);
+ }
+ summaryView.setText(summary);
+ }
+ }
+
+ CompoundButton.OnCheckedChangeListener externalInputDeviceListener = new CompoundButton.OnCheckedChangeListener() {
+ @Override
+ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
+ ListPreferenceEx externalInputDevice = (ListPreferenceEx) findPreference(settings.EXTERNAL_INPUT_DEVICE.getId());
+ if (isChecked) {
+ getPreferenceManager().showDialog(externalInputDevice);
+ buttonView.setChecked(false);
+ } else {
+ if (externalInputDevice.callChangeListener(OsmandSettings.NO_EXTERNAL_DEVICE)) {
+ externalInputDevice.setValue(OsmandSettings.NO_EXTERNAL_DEVICE);
+ } else {
+ buttonView.setChecked(true);
+ }
+ }
+ }
+ };
+
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)});
@@ -181,15 +225,14 @@ public class GeneralProfileSettingsFragment extends BaseSettingsFragment {
private void setupExternalInputDevicePref() {
ListPreferenceEx externalInputDevice = (ListPreferenceEx) findPreference(settings.EXTERNAL_INPUT_DEVICE.getId());
+ externalInputDevice.setSummary(R.string.sett_no_ext_input);
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}
@@ -286,4 +329,18 @@ public class GeneralProfileSettingsFragment extends BaseSettingsFragment {
return true;
}
+
+ @Override
+ public void onPreferenceChanged(String prefId) {
+ Preference preference = findPreference(prefId);
+ if (preference != null) {
+ if (settings.OSMAND_THEME.getId().equals(prefId)) {
+ preference.setIcon(getOsmandThemeIcon());
+ } else if (settings.ROTATE_MAP.getId().equals(prefId)) {
+ preference.setIcon(getRotateMapIcon());
+ } else if (settings.MAP_SCREEN_ORIENTATION.getId().equals(prefId)) {
+ preference.setIcon(getMapScreenOrientationIcon());
+ }
+ }
+ }
}
\ No newline at end of file
diff --git a/OsmAnd/src/net/osmand/plus/settings/GlobalSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/GlobalSettingsFragment.java
index f58020bcd0..d3709fbc3c 100644
--- a/OsmAnd/src/net/osmand/plus/settings/GlobalSettingsFragment.java
+++ b/OsmAnd/src/net/osmand/plus/settings/GlobalSettingsFragment.java
@@ -19,25 +19,10 @@ import net.osmand.plus.settings.preferences.SwitchPreferenceEx;
public class GlobalSettingsFragment extends BaseSettingsFragment implements SendAnalyticsBottomSheetDialogFragment.OnSendAnalyticsPrefsUpdate, OnPreferenceChanged {
- public static final String TAG = "GlobalSettingsFragment";
+ public static final String TAG = GlobalSettingsFragment.class.getSimpleName();
private static final String SEND_ANONYMOUS_DATA_PREF_ID = "send_anonymous_data";
- @Override
- protected int getPreferencesResId() {
- return R.xml.global_settings;
- }
-
- @Override
- protected int getToolbarResId() {
- return R.layout.global_preference_toolbar;
- }
-
- @Override
- protected int getToolbarTitle() {
- return R.string.osmand_settings;
- }
-
@Override
protected void setupPreferences() {
setupDefaultAppModePref();
@@ -96,7 +81,7 @@ public class GlobalSettingsFragment extends BaseSettingsFragment implements Send
OsmandApplication app = getMyApplication();
if (app != null && activity != null) {
app.checkPreferredLocale();
- activity.recreate();
+ app.restartApp(activity);
}
}
}
diff --git a/OsmAnd/src/net/osmand/plus/settings/MainSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/MainSettingsFragment.java
index c00a72c16d..027da24688 100644
--- a/OsmAnd/src/net/osmand/plus/settings/MainSettingsFragment.java
+++ b/OsmAnd/src/net/osmand/plus/settings/MainSettingsFragment.java
@@ -1,39 +1,26 @@
package net.osmand.plus.settings;
-import android.content.Intent;
+import android.graphics.drawable.Drawable;
+import android.graphics.drawable.LayerDrawable;
+import android.os.Build;
import android.support.annotation.ColorRes;
-import android.support.v4.app.FragmentManager;
import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceViewHolder;
+import android.view.View;
+import net.osmand.AndroidUtils;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.R;
-import net.osmand.plus.profiles.SettingsProfileActivity;
-import net.osmand.util.Algorithms;
+import net.osmand.plus.UiUtilities;
+import net.osmand.plus.profiles.SettingsProfileFragment;
public class MainSettingsFragment extends BaseSettingsFragment {
- public static final String TAG = "MainSettingsFragment";
+ public static final String TAG = MainSettingsFragment.class.getSimpleName();
+
+ private static final String CONFIGURE_PROFILE = "configure_profile";
@Override
- protected int getPreferencesResId() {
- return R.xml.settings_main_screen;
- }
-
- @Override
- protected int getToolbarResId() {
- return R.layout.global_preference_toolbar;
- }
-
- @Override
- protected int getToolbarTitle() {
- return R.string.shared_string_settings;
- }
-
- @Override
- public int getStatusBarColorId() {
- return isNightMode() ? R.color.status_bar_color_light : R.color.status_bar_color_dark;
- }
-
@ColorRes
protected int getBackgroundColorRes() {
return isNightMode() ? R.color.activity_background_color_dark : R.color.activity_background_color_light;
@@ -48,41 +35,47 @@ public class MainSettingsFragment extends BaseSettingsFragment {
setupManageProfilesPref();
}
+ @Override
+ protected void onBindPreferenceViewHolder(Preference preference, PreferenceViewHolder holder) {
+ super.onBindPreferenceViewHolder(preference, holder);
+
+ String key = preference.getKey();
+ if (CONFIGURE_PROFILE.equals(key)) {
+ View iconContainer = holder.itemView.findViewById(R.id.icon_container);
+ if (iconContainer != null) {
+ int profileColor = getActiveProfileColor();
+ int bgColor = UiUtilities.getColorWithAlpha(profileColor, 0.1f);
+ Drawable backgroundDrawable;
+
+ if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
+ int selectedColor = UiUtilities.getColorWithAlpha(profileColor, 0.3f);
+ Drawable background = getPaintedIcon(R.drawable.circle_background_light, bgColor);
+ Drawable ripple = getPaintedIcon(R.drawable.ripple_circle, selectedColor);
+ backgroundDrawable = new LayerDrawable(new Drawable[] {background, ripple});
+ } else {
+ backgroundDrawable = getPaintedIcon(R.drawable.circle_background_light, bgColor);
+ }
+ AndroidUtils.setBackground(iconContainer, backgroundDrawable);
+ }
+ }
+ }
+
private void setupManageProfilesPref() {
Preference manageProfiles = findPreference("manage_profiles");
manageProfiles.setIcon(getIcon(R.drawable.ic_action_manage_profiles));
- manageProfiles.setIntent(new Intent(getActivity(), SettingsProfileActivity.class));
+ manageProfiles.setFragment(SettingsProfileFragment.class.getName());
}
private void setupConfigureProfilePref() {
ApplicationMode selectedMode = getSelectedAppMode();
String title = selectedMode.toHumanString(getContext());
- String profileType;
- if (selectedMode.isCustomProfile()) {
- profileType = String.format(getString(R.string.profile_type_descr_string), Algorithms.capitalizeFirstLetterAndLowercase(selectedMode.getParent().toHumanString(getContext())));
- } else {
- profileType = getString(R.string.profile_type_base_string);
- }
-
+ String profileType = getAppModeDescription(getContext(), selectedMode);
int iconRes = selectedMode.getIconRes();
- Preference configureProfile = findPreference("configure_profile");
+ Preference configureProfile = findPreference(CONFIGURE_PROFILE);
configureProfile.setIcon(getPaintedIcon(iconRes, getActiveProfileColor()));
configureProfile.setTitle(title);
configureProfile.setSummary(profileType);
}
-
- public static boolean showInstance(FragmentManager fragmentManager) {
- try {
- MainSettingsFragment MainSettingsFragment = new MainSettingsFragment();
- fragmentManager.beginTransaction()
- .replace(R.id.fragmentContainer, MainSettingsFragment, TAG)
- .addToBackStack(TAG)
- .commitAllowingStateLoss();
- return true;
- } catch (Exception e) {
- return false;
- }
- }
}
\ No newline at end of file
diff --git a/OsmAnd/src/net/osmand/plus/settings/MapDuringNavigationFragment.java b/OsmAnd/src/net/osmand/plus/settings/MapDuringNavigationFragment.java
index c81a52f334..3bbb1bf6fe 100644
--- a/OsmAnd/src/net/osmand/plus/settings/MapDuringNavigationFragment.java
+++ b/OsmAnd/src/net/osmand/plus/settings/MapDuringNavigationFragment.java
@@ -10,22 +10,7 @@ import net.osmand.plus.settings.preferences.SwitchPreferenceEx;
public class MapDuringNavigationFragment extends BaseSettingsFragment {
- public static final String TAG = "MapDuringNavigationFragment";
-
- @Override
- protected int getPreferencesResId() {
- return R.xml.map_during_navigation;
- }
-
- @Override
- protected int getToolbarResId() {
- return R.layout.profile_preference_toolbar;
- }
-
- @Override
- protected int getToolbarTitle() {
- return R.string.map_during_navigation;
- }
+ public static final String TAG = MapDuringNavigationFragment.class.getSimpleName();
@Override
protected void setupPreferences() {
diff --git a/OsmAnd/src/net/osmand/plus/settings/NavigationFragment.java b/OsmAnd/src/net/osmand/plus/settings/NavigationFragment.java
index f365d8bb6a..2a27514ba0 100644
--- a/OsmAnd/src/net/osmand/plus/settings/NavigationFragment.java
+++ b/OsmAnd/src/net/osmand/plus/settings/NavigationFragment.java
@@ -4,25 +4,11 @@ import android.support.v7.preference.Preference;
import android.support.v7.preference.SwitchPreferenceCompat;
import net.osmand.plus.R;
+import net.osmand.plus.settings.preferences.SwitchPreferenceEx;
public class NavigationFragment extends BaseSettingsFragment {
- public static final String TAG = "NavigationFragment";
-
- @Override
- protected int getPreferencesResId() {
- return R.xml.navigation_settings_new;
- }
-
- @Override
- protected int getToolbarResId() {
- return R.layout.profile_preference_toolbar_big;
- }
-
- @Override
- protected int getToolbarTitle() {
- return R.string.routing_settings_2;
- }
+ public static final String TAG = NavigationFragment.class.getSimpleName();
@Override
protected void setupPreferences() {
@@ -30,6 +16,7 @@ public class NavigationFragment extends BaseSettingsFragment {
SwitchPreferenceCompat showRoutingAlarms = (SwitchPreferenceCompat) findPreference(settings.SHOW_ROUTING_ALARMS.getId());
SwitchPreferenceCompat speakRoutingAlarms = (SwitchPreferenceCompat) findPreference(settings.SPEAK_ROUTING_ALARMS.getId());
SwitchPreferenceCompat turnScreenOn = (SwitchPreferenceCompat) findPreference(settings.TURN_SCREEN_ON_ENABLED.getId());
+ SwitchPreferenceEx animateMyLocation = (SwitchPreferenceEx) findPreference(settings.ANIMATE_MY_LOCATION.getId());
routeParameters.setIcon(getContentIcon(R.drawable.ic_action_route_distance));
showRoutingAlarms.setIcon(getContentIcon(R.drawable.ic_action_alert));
@@ -37,6 +24,8 @@ public class NavigationFragment extends BaseSettingsFragment {
turnScreenOn.setIcon(getContentIcon(R.drawable.ic_action_turn_screen_on));
setupVehicleParametersPref();
+
+ animateMyLocation.setDescription(getString(R.string.animate_my_location_desc));
}
private void setupVehicleParametersPref() {
diff --git a/OsmAnd/src/net/osmand/plus/settings/ProxySettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/ProxySettingsFragment.java
index b7bc316ec8..95a146f8f3 100644
--- a/OsmAnd/src/net/osmand/plus/settings/ProxySettingsFragment.java
+++ b/OsmAnd/src/net/osmand/plus/settings/ProxySettingsFragment.java
@@ -1,10 +1,18 @@
package net.osmand.plus.settings;
+import android.graphics.drawable.Drawable;
+import android.support.v4.content.ContextCompat;
import android.support.v7.preference.Preference;
+import android.support.v7.widget.SwitchCompat;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.widget.TextView;
import android.widget.Toast;
+import net.osmand.AndroidUtils;
import net.osmand.osm.io.NetworkUtils;
import net.osmand.plus.R;
+import net.osmand.plus.UiUtilities;
import net.osmand.plus.settings.preferences.EditTextPreferenceEx;
import static net.osmand.plus.activities.SettingsGeneralActivity.IP_ADDRESS_PATTERN;
@@ -13,21 +21,6 @@ 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 int getToolbarTitle() {
- return R.string.proxy_pref_title;
- }
-
@Override
protected void setupPreferences() {
Preference mapDuringNavigationInfo = findPreference("proxy_preferences_info");
@@ -37,6 +30,48 @@ public class ProxySettingsFragment extends BaseSettingsFragment {
setupProxyPortPref();
}
+ @Override
+ protected void createToolbar(LayoutInflater inflater, View view) {
+ super.createToolbar(inflater, view);
+
+ view.findViewById(R.id.toolbar_switch_container).setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ boolean checked = !settings.ENABLE_PROXY.get();
+ settings.ENABLE_PROXY.set(checked);
+ updateToolbarSwitch();
+ enableDisablePreferences(checked);
+ }
+ });
+ TextView title = (TextView) view.findViewById(R.id.switchButtonText);
+ title.setTextColor(ContextCompat.getColor(app, isNightMode() ? R.color.active_color_primary_dark : R.color.active_color_primary_light));
+ }
+
+ @Override
+ protected void updateToolbar() {
+ super.updateToolbar();
+ updateToolbarSwitch();
+ }
+
+ private void updateToolbarSwitch() {
+ View view = getView();
+ if (view == null) {
+ return;
+ }
+ boolean checked = settings.ENABLE_PROXY.get();
+
+ View selectableView = view.findViewById(R.id.selectable_item);
+
+ SwitchCompat switchView = (SwitchCompat) selectableView.findViewById(R.id.switchWidget);
+ switchView.setChecked(checked);
+
+ TextView title = (TextView) selectableView.findViewById(R.id.switchButtonText);
+ title.setText(checked ? R.string.shared_string_on : R.string.shared_string_off);
+
+ Drawable drawable = UiUtilities.getColoredSelectableDrawable(app, getActiveProfileColor(), 0.3f);
+ AndroidUtils.setBackground(selectableView, drawable);
+ }
+
private void setupProxyHostPref() {
EditTextPreferenceEx hostPref = (EditTextPreferenceEx) findPreference(settings.PROXY_HOST.getId());
hostPref.setPersistent(false);
diff --git a/OsmAnd/src/net/osmand/plus/settings/RouteParametersFragment.java b/OsmAnd/src/net/osmand/plus/settings/RouteParametersFragment.java
index c425ee8617..e71e40a906 100644
--- a/OsmAnd/src/net/osmand/plus/settings/RouteParametersFragment.java
+++ b/OsmAnd/src/net/osmand/plus/settings/RouteParametersFragment.java
@@ -33,7 +33,7 @@ import static net.osmand.plus.activities.SettingsNavigationActivity.getRouter;
public class RouteParametersFragment extends BaseSettingsFragment {
- public static final String TAG = "RouteParametersFragment";
+ public static final String TAG = RouteParametersFragment.class.getSimpleName();
private static final String AVOID_ROUTING_PARAMETER_PREFIX = "avoid_";
private static final String PREFER_ROUTING_PARAMETER_PREFIX = "prefer_";
@@ -46,20 +46,6 @@ public class RouteParametersFragment extends BaseSettingsFragment {
private List reliefFactorParameters = new ArrayList();
private List otherRoutingParameters = new ArrayList();
- @Override
- protected int getPreferencesResId() {
- return R.xml.route_parameters;
- }
-
- @Override
- protected int getToolbarResId() {
- return R.layout.profile_preference_toolbar;
- }
-
- @Override
- protected int getToolbarTitle() {
- return R.string.route_parameters;
- }
@Override
protected void setupPreferences() {
diff --git a/OsmAnd/src/net/osmand/plus/settings/ScreenAlertsFragment.java b/OsmAnd/src/net/osmand/plus/settings/ScreenAlertsFragment.java
index ac0fe3ac6b..804102646c 100644
--- a/OsmAnd/src/net/osmand/plus/settings/ScreenAlertsFragment.java
+++ b/OsmAnd/src/net/osmand/plus/settings/ScreenAlertsFragment.java
@@ -1,38 +1,28 @@
package net.osmand.plus.settings;
-import android.annotation.SuppressLint;
+import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.support.v4.content.ContextCompat;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceViewHolder;
import android.support.v7.preference.SwitchPreferenceCompat;
+import android.support.v7.widget.SwitchCompat;
+import android.view.LayoutInflater;
+import android.view.View;
import android.widget.ImageView;
+import android.widget.TextView;
+import net.osmand.AndroidUtils;
import net.osmand.plus.R;
public class ScreenAlertsFragment extends BaseSettingsFragment {
- public static final String TAG = "ScreenAlertsFragment";
+ public static final String TAG = ScreenAlertsFragment.class.getSimpleName();
private static final String SHOW_ROUTING_ALARMS_INFO = "show_routing_alarms_info";
private static final String SCREEN_ALERTS_IMAGE = "screen_alerts_image";
- @Override
- protected int getPreferencesResId() {
- return R.xml.screen_alerts;
- }
-
- @Override
- protected int getToolbarResId() {
- return R.layout.profile_preference_toolbar;
- }
-
- @Override
- protected int getToolbarTitle() {
- return R.string.screen_alerts;
- }
-
@Override
protected void setupPreferences() {
Preference showRoutingAlarmsInfo = findPreference(SHOW_ROUTING_ALARMS_INFO);
@@ -50,17 +40,51 @@ public class ScreenAlertsFragment extends BaseSettingsFragment {
setupScreenAlertsImage();
}
+ @Override
+ protected void createToolbar(LayoutInflater inflater, View view) {
+ super.createToolbar(inflater, view);
+
+ view.findViewById(R.id.toolbar_switch_container).setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ boolean checked = !settings.SHOW_ROUTING_ALARMS.get();
+ settings.SHOW_ROUTING_ALARMS.set(checked);
+ updateToolbarSwitch();
+ enableDisablePreferences(checked);
+ }
+ });
+ }
+
+ @Override
+ protected void updateToolbar() {
+ super.updateToolbar();
+ updateToolbarSwitch();
+ }
+
+ private void updateToolbarSwitch() {
+ View view = getView();
+ if (view == null) {
+ return;
+ }
+ boolean checked = settings.SHOW_ROUTING_ALARMS.get();
+
+ int color = checked ? getActiveProfileColor() : ContextCompat.getColor(app, R.color.preference_top_switch_off);
+ View switchContainer = view.findViewById(R.id.toolbar_switch_container);
+ AndroidUtils.setBackground(switchContainer, new ColorDrawable(color));
+
+ SwitchCompat switchView = (SwitchCompat) switchContainer.findViewById(R.id.switchWidget);
+ switchView.setChecked(checked);
+
+ TextView title = switchContainer.findViewById(R.id.switchButtonText);
+ title.setText(checked ? R.string.shared_string_on : R.string.shared_string_off);
+ }
+
@Override
protected void onBindPreferenceViewHolder(Preference preference, PreferenceViewHolder holder) {
super.onBindPreferenceViewHolder(preference, holder);
String key = preference.getKey();
- if (settings.SHOW_ROUTING_ALARMS.getId().equals(key)) {
- boolean checked = ((SwitchPreferenceCompat) preference).isChecked();
- int color = checked ? getActiveProfileColor() : ContextCompat.getColor(app, R.color.preference_top_switch_off);
-
- holder.itemView.setBackgroundColor(color);
- } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
if (SHOW_ROUTING_ALARMS_INFO.equals(key)) {
int colorRes = isNightMode() ? R.color.activity_background_color_dark : R.color.activity_background_color_light;
holder.itemView.setBackgroundColor(ContextCompat.getColor(app, colorRes));
@@ -74,7 +98,6 @@ public class ScreenAlertsFragment extends BaseSettingsFragment {
}
}
- @SuppressLint("RestrictedApi")
@Override
public boolean onPreferenceClick(Preference preference) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
diff --git a/OsmAnd/src/net/osmand/plus/settings/TurnScreenOnFragment.java b/OsmAnd/src/net/osmand/plus/settings/TurnScreenOnFragment.java
index 4c7f1d851e..0d1b26574d 100644
--- a/OsmAnd/src/net/osmand/plus/settings/TurnScreenOnFragment.java
+++ b/OsmAnd/src/net/osmand/plus/settings/TurnScreenOnFragment.java
@@ -3,8 +3,10 @@ package net.osmand.plus.settings;
import android.graphics.drawable.ColorDrawable;
import android.support.v4.content.ContextCompat;
import android.support.v7.preference.Preference;
-import android.support.v7.preference.PreferenceViewHolder;
-import android.support.v7.preference.SwitchPreferenceCompat;
+import android.support.v7.widget.SwitchCompat;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.widget.TextView;
import net.osmand.AndroidUtils;
import net.osmand.plus.R;
@@ -13,22 +15,7 @@ import net.osmand.plus.settings.preferences.SwitchPreferenceEx;
public class TurnScreenOnFragment extends BaseSettingsFragment {
- public static final String TAG = "TurnScreenOnFragment";
-
- @Override
- protected int getPreferencesResId() {
- return R.xml.turn_screen_on;
- }
-
- @Override
- protected int getToolbarResId() {
- return R.layout.profile_preference_toolbar;
- }
-
- @Override
- protected int getToolbarTitle() {
- return R.string.turn_screen_on;
- }
+ public static final String TAG = TurnScreenOnFragment.class.getSimpleName();
@Override
protected void setupPreferences() {
@@ -40,15 +27,42 @@ public class TurnScreenOnFragment extends BaseSettingsFragment {
}
@Override
- protected void onBindPreferenceViewHolder(Preference preference, PreferenceViewHolder holder) {
- super.onBindPreferenceViewHolder(preference, holder);
+ protected void createToolbar(LayoutInflater inflater, View view) {
+ super.createToolbar(inflater, view);
- if (settings.TURN_SCREEN_ON_ENABLED.getId().equals(preference.getKey())) {
- boolean checked = ((SwitchPreferenceCompat) preference).isChecked();
- int color = checked ? getActiveProfileColor() : ContextCompat.getColor(app, R.color.preference_top_switch_off);
+ view.findViewById(R.id.toolbar_switch_container).setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ boolean checked = !settings.TURN_SCREEN_ON_ENABLED.get();
+ settings.TURN_SCREEN_ON_ENABLED.set(checked);
+ updateToolbarSwitch();
+ enableDisablePreferences(checked);
+ }
+ });
+ }
- AndroidUtils.setBackground(holder.itemView, new ColorDrawable(color));
+ @Override
+ protected void updateToolbar() {
+ super.updateToolbar();
+ updateToolbarSwitch();
+ }
+
+ private void updateToolbarSwitch() {
+ View view = getView();
+ if (view == null) {
+ return;
}
+ boolean checked = settings.TURN_SCREEN_ON_ENABLED.get();
+
+ int color = checked ? getActiveProfileColor() : ContextCompat.getColor(app, R.color.preference_top_switch_off);
+ View switchContainer = view.findViewById(R.id.toolbar_switch_container);
+ AndroidUtils.setBackground(switchContainer, new ColorDrawable(color));
+
+ SwitchCompat switchView = (SwitchCompat) switchContainer.findViewById(R.id.switchWidget);
+ switchView.setChecked(checked);
+
+ TextView title = switchContainer.findViewById(R.id.switchButtonText);
+ title.setText(checked ? R.string.shared_string_on : R.string.shared_string_off);
}
private void setupTurnScreenOnTimePref() {
diff --git a/OsmAnd/src/net/osmand/plus/settings/VehicleParametersFragment.java b/OsmAnd/src/net/osmand/plus/settings/VehicleParametersFragment.java
index c974cf2ec3..bb6def6f65 100644
--- a/OsmAnd/src/net/osmand/plus/settings/VehicleParametersFragment.java
+++ b/OsmAnd/src/net/osmand/plus/settings/VehicleParametersFragment.java
@@ -19,22 +19,7 @@ import static net.osmand.plus.activities.SettingsNavigationActivity.showSeekbarS
public class VehicleParametersFragment extends BaseSettingsFragment {
- public static final String TAG = "VehicleParametersFragment";
-
- @Override
- protected int getPreferencesResId() {
- return R.xml.vehicle_parameters;
- }
-
- @Override
- protected int getToolbarResId() {
- return R.layout.profile_preference_toolbar;
- }
-
- @Override
- protected int getToolbarTitle() {
- return R.string.vehicle_parameters;
- }
+ public static final String TAG = VehicleParametersFragment.class.getSimpleName();
@Override
protected void setupPreferences() {
diff --git a/OsmAnd/src/net/osmand/plus/settings/VoiceAnnouncesFragment.java b/OsmAnd/src/net/osmand/plus/settings/VoiceAnnouncesFragment.java
index 6a043b7ec2..e2b0d41128 100644
--- a/OsmAnd/src/net/osmand/plus/settings/VoiceAnnouncesFragment.java
+++ b/OsmAnd/src/net/osmand/plus/settings/VoiceAnnouncesFragment.java
@@ -9,8 +9,11 @@ import android.media.AudioManager;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AlertDialog;
import android.support.v7.preference.Preference;
-import android.support.v7.preference.PreferenceViewHolder;
import android.support.v7.preference.SwitchPreferenceCompat;
+import android.support.v7.widget.SwitchCompat;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.widget.TextView;
import net.osmand.AndroidUtils;
import net.osmand.plus.ApplicationMode;
@@ -28,21 +31,45 @@ import static net.osmand.plus.activities.SettingsNavigationActivity.MORE_VALUE;
public class VoiceAnnouncesFragment extends BaseSettingsFragment {
- public static final String TAG = "VoiceAnnouncesFragment";
+ public static final String TAG = VoiceAnnouncesFragment.class.getSimpleName();
@Override
- protected int getPreferencesResId() {
- return R.xml.voice_announces;
+ protected void createToolbar(LayoutInflater inflater, View view) {
+ super.createToolbar(inflater, view);
+
+ view.findViewById(R.id.toolbar_switch_container).setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ boolean checked = !settings.SPEAK_ROUTING_ALARMS.get();
+ settings.SPEAK_ROUTING_ALARMS.set(checked);
+ updateToolbarSwitch();
+ enableDisablePreferences(checked);
+ }
+ });
}
@Override
- protected int getToolbarResId() {
- return R.layout.profile_preference_toolbar;
+ protected void updateToolbar() {
+ super.updateToolbar();
+ updateToolbarSwitch();
}
- @Override
- protected int getToolbarTitle() {
- return R.string.voice_announces;
+ private void updateToolbarSwitch() {
+ View view = getView();
+ if (view == null) {
+ return;
+ }
+ boolean checked = settings.SPEAK_ROUTING_ALARMS.get();
+
+ int color = checked ? getActiveProfileColor() : ContextCompat.getColor(app, R.color.preference_top_switch_off);
+ View switchContainer = view.findViewById(R.id.toolbar_switch_container);
+ AndroidUtils.setBackground(switchContainer, new ColorDrawable(color));
+
+ SwitchCompat switchView = (SwitchCompat) switchContainer.findViewById(R.id.switchWidget);
+ switchView.setChecked(checked);
+
+ TextView title = switchContainer.findViewById(R.id.switchButtonText);
+ title.setText(checked ? R.string.shared_string_on : R.string.shared_string_off);
}
@Override
@@ -60,18 +87,7 @@ public class VoiceAnnouncesFragment extends BaseSettingsFragment {
setupAudioStreamGuidancePref();
setupInterruptMusicPref();
}
- }
-
- @Override
- protected void onBindPreferenceViewHolder(Preference preference, PreferenceViewHolder holder) {
- super.onBindPreferenceViewHolder(preference, holder);
-
- if (settings.SPEAK_ROUTING_ALARMS.getId().equals(preference.getKey())) {
- boolean checked = ((SwitchPreferenceCompat) preference).isChecked();
- int color = checked ? getActiveProfileColor() : ContextCompat.getColor(app, R.color.preference_top_switch_off);
-
- AndroidUtils.setBackground(holder.itemView, new ColorDrawable(color));
- }
+ enableDisablePreferences(settings.SPEAK_ROUTING_ALARMS.get());
}
private void setupSpeedLimitExceedPref() {
@@ -170,18 +186,13 @@ public class VoiceAnnouncesFragment extends BaseSettingsFragment {
ListPreferenceEx audioStreamGuidance = createListPreferenceEx(settings.AUDIO_STREAM_GUIDANCE.getId(), streamTypes, streamIntTypes, R.string.choose_audio_stream, R.layout.preference_with_descr);
audioStreamGuidance.setIconSpaceReserved(true);
-
getPreferenceScreen().addPreference(audioStreamGuidance);
-
- audioStreamGuidance.setDependency(settings.SPEAK_ROUTING_ALARMS.getId());
}
private void setupInterruptMusicPref() {
- Preference interruptMusicPref = createSwitchPreference(settings.INTERRUPT_MUSIC, R.string.interrupt_music, R.string.interrupt_music_descr, R.layout.preference_switch);
+ Preference interruptMusicPref = createSwitchPreference(settings.INTERRUPT_MUSIC, R.string.interrupt_music, R.string.interrupt_music_descr, R.layout.preference_switch_with_descr);
interruptMusicPref.setIconSpaceReserved(true);
getPreferenceScreen().addPreference(interruptMusicPref);
-
- interruptMusicPref.setDependency(settings.SPEAK_ROUTING_ALARMS.getId());
}
public void confirmSpeedCamerasDlg() {
diff --git a/OsmAnd/src/net/osmand/plus/settings/bottomsheets/ChangeGeneralProfilesPrefBottomSheet.java b/OsmAnd/src/net/osmand/plus/settings/bottomsheets/ChangeGeneralProfilesPrefBottomSheet.java
index 447607ecac..a66573051b 100644
--- a/OsmAnd/src/net/osmand/plus/settings/bottomsheets/ChangeGeneralProfilesPrefBottomSheet.java
+++ b/OsmAnd/src/net/osmand/plus/settings/bottomsheets/ChangeGeneralProfilesPrefBottomSheet.java
@@ -28,7 +28,7 @@ import java.util.List;
public class ChangeGeneralProfilesPrefBottomSheet extends BasePreferenceBottomSheet {
- public static final String TAG = "ChangeGeneralProfilesPrefBottomSheet";
+ public static final String TAG = ChangeGeneralProfilesPrefBottomSheet.class.getSimpleName();
private static final Log LOG = PlatformUtil.getLog(ChangeGeneralProfilesPrefBottomSheet.class);