From 7088846e095bc5131307fec47523d2a84b667b3e Mon Sep 17 00:00:00 2001 From: Chumva Date: Fri, 9 Aug 2019 12:03:48 +0300 Subject: [PATCH] Change main settings fragment base class --- OsmAnd/res/layout/fragment_settings_main.xml | 293 ------------------ .../res/layout/global_preference_toolbar.xml | 4 +- OsmAnd/res/xml/configure_profile.xml | 1 - OsmAnd/res/xml/settings_main_screen.xml | 3 - .../osmand/plus/activities/MapActivity.java | 6 +- ...ragment.java => BaseSettingsFragment.java} | 27 +- .../settings/ConfigureProfileFragment.java | 8 +- .../settings/MapDuringNavigationFragment.java | 11 +- .../plus/settings/NavigationFragment.java | 3 +- .../plus/settings/ProfileGeneralSettings.java | 17 +- .../settings/RouteParametersFragment.java | 4 +- .../plus/settings/ScreenAlertsFragment.java | 2 +- .../plus/settings/SettingsMainFragment.java | 135 +++----- .../plus/settings/TurnScreenOnFragment.java | 2 +- .../settings/VehicleParametersFragment.java | 2 +- .../plus/settings/VoiceAnnouncesFragment.java | 2 +- 16 files changed, 70 insertions(+), 450 deletions(-) delete mode 100644 OsmAnd/res/layout/fragment_settings_main.xml rename OsmAnd/src/net/osmand/plus/settings/{BaseProfileSettingsFragment.java => BaseSettingsFragment.java} (94%) diff --git a/OsmAnd/res/layout/fragment_settings_main.xml b/OsmAnd/res/layout/fragment_settings_main.xml deleted file mode 100644 index b4b8ad9b4f..0000000000 --- a/OsmAnd/res/layout/fragment_settings_main.xml +++ /dev/null @@ -1,293 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ 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 dcd767e779..231aa41b27 100644 --- a/OsmAnd/res/layout/global_preference_toolbar.xml +++ b/OsmAnd/res/layout/global_preference_toolbar.xml @@ -10,7 +10,7 @@ app:contentInsetStart="4dp"> avoidParameters = new ArrayList(); @@ -154,7 +154,7 @@ public class RouteParametersFragment extends BaseProfileSettingsFragment { String key = preference.getKey(); switch (key) { case "avoid_in_routing": { - AvoidRoadsBottomSheetDialogFragment avoidRoadsFragment = new AvoidRoadsBottomSheetDialogFragment(false); + AvoidRoadsBottomSheetDialogFragment avoidRoadsFragment = new AvoidRoadsBottomSheetDialogFragment(true); avoidRoadsFragment.setTargetFragment(RouteParametersFragment.this, AvoidRoadsBottomSheetDialogFragment.REQUEST_CODE); avoidRoadsFragment.show(getActivity().getSupportFragmentManager(), AvoidRoadsBottomSheetDialogFragment.TAG); return true; diff --git a/OsmAnd/src/net/osmand/plus/settings/ScreenAlertsFragment.java b/OsmAnd/src/net/osmand/plus/settings/ScreenAlertsFragment.java index 0f2156b11c..b3043c0dd3 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ScreenAlertsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ScreenAlertsFragment.java @@ -11,7 +11,7 @@ import android.view.ViewGroup; import net.osmand.plus.R; -public class ScreenAlertsFragment extends BaseProfileSettingsFragment { +public class ScreenAlertsFragment extends BaseSettingsFragment { public static final String TAG = "ScreenAlertsFragment"; diff --git a/OsmAnd/src/net/osmand/plus/settings/SettingsMainFragment.java b/OsmAnd/src/net/osmand/plus/settings/SettingsMainFragment.java index 74892a3821..613730abfe 100644 --- a/OsmAnd/src/net/osmand/plus/settings/SettingsMainFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/SettingsMainFragment.java @@ -1,127 +1,73 @@ package net.osmand.plus.settings; -import android.app.Activity; import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; import android.support.v4.app.FragmentManager; -import android.support.v7.widget.Toolbar; -import android.util.TypedValue; +import android.support.v7.preference.Preference; +import android.support.v7.preference.PreferenceScreen; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.ImageView; -import android.widget.TextView; -import net.osmand.AndroidUtils; import net.osmand.plus.ApplicationMode; import net.osmand.plus.R; -import net.osmand.plus.base.BaseOsmAndFragment; -import net.osmand.plus.settings.profiles.SettingsProfileFragment; import net.osmand.util.Algorithms; -public class SettingsMainFragment extends BaseOsmAndFragment { +public class SettingsMainFragment extends BaseSettingsFragment { public static final String TAG = "SettingsMainFragment"; - @Nullable @Override - public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { - View view = inflater.inflate(R.layout.fragment_settings_main, null); + protected int getPreferenceResId() { + return R.xml.settings_main_screen; + } - AndroidUtils.addStatusBarPadding21v(getContext(), view); + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + View view = super.onCreateView(inflater, container, savedInstanceState); - Toolbar tb = (Toolbar) view.findViewById(R.id.toolbar); + return view; + } - tb.setTitle(R.string.shared_string_settings); - tb.setClickable(true); - tb.setNavigationIcon(getIcon(R.drawable.ic_arrow_back)); - tb.setNavigationContentDescription(R.string.access_shared_string_navigate_up); - tb.setBackgroundColor(getResources().getColor(resolveResourceId(getActivity(), R.attr.pstsTabBackground))); - tb.setTitleTextColor(getResources().getColor(resolveResourceId(getActivity(), R.attr.pstsTextColor))); - tb.setNavigationOnClickListener(new View.OnClickListener() { - @Override - public void onClick(final View v) { - getActivity().getSupportFragmentManager().popBackStack(); - } - }); + @Override + protected int getToolbarResId() { + return R.layout.global_preference_toolbar; + } - View personal_account_container = view.findViewById(R.id.personal_account_container); - personal_account_container.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - getMyApplication().showShortToastMessage("personal_account_container"); - } - }); - View global_settings_container = view.findViewById(R.id.global_settings_container); - global_settings_container.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - getMyApplication().showShortToastMessage("global_settings_container"); - } - }); - View browse_map_container = view.findViewById(R.id.browse_map_container); - browse_map_container.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - getMyApplication().showShortToastMessage("browse_map_container"); - } - }); + protected String getToolbarTitle() { + return getString(R.string.shared_string_settings); + } - final ApplicationMode selectedMode = getSettings().APPLICATION_MODE.get(); - View configure_profile_container = view.findViewById(R.id.configure_profile_container); + @Override + protected void createUI() { + PreferenceScreen screen = getPreferenceScreen(); + + Preference personal_account = findAndRegisterPreference("personal_account"); + Preference global_settings = findAndRegisterPreference("global_settings"); + Preference browse_map = findAndRegisterPreference("browse_map"); + Preference configure_profile = findAndRegisterPreference("configure_profile"); + Preference manage_profiles = findAndRegisterPreference("manage_profiles"); + + personal_account.setIcon(getContentIcon(R.drawable.ic_person)); + global_settings.setIcon(getContentIcon(R.drawable.ic_action_settings)); + browse_map.setIcon(getContentIcon(R.drawable.ic_world_globe_dark)); + manage_profiles.setIcon(getContentIcon(R.drawable.ic_action_manage_profiles)); + + final ApplicationMode selectedMode = getSelectedMode(); int iconRes = selectedMode.getIconRes(); int iconColor = selectedMode.getIconColorInfo().getColor(!getSettings().isLightContent()); String title = selectedMode.isCustomProfile() ? selectedMode.getCustomProfileName() : getResources().getString(selectedMode.getNameKeyResource()); - TextView profileTitle = (TextView) view.findViewById(R.id.configure_profile_title); - profileTitle.setText(title); - - String profileType = null; + 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); } - TextView profileDescription = (TextView) view.findViewById(R.id.configure_profile_description); - profileDescription.setText(profileType); - - ImageView profileIcon = (ImageView) view.findViewById(R.id.configure_profile_icon); - profileIcon.setImageDrawable(getIcon(iconRes, iconColor)); - - configure_profile_container.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - ConfigureProfileFragment.showInstance(getActivity().getSupportFragmentManager(), selectedMode); - } - }); - View manage_profiles_container = view.findViewById(R.id.manage_profiles_container); - manage_profiles_container.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - SettingsProfileFragment profileFragment = new SettingsProfileFragment(); - getActivity().getSupportFragmentManager() - .beginTransaction() - .replace(R.id.fragmentContainer, profileFragment, SettingsProfileFragment.TAG) - .addToBackStack(SettingsProfileFragment.TAG) - .commit(); - } - }); - - return view; - } - - @Override - public int getStatusBarColorId() { - return getSettings().isLightContent() ? R.color.status_bar_color_light : R.color.status_bar_color_dark; - } - - private int resolveResourceId(final Activity activity, final int attr) { - final TypedValue typedvalueattr = new TypedValue(); - activity.getTheme().resolveAttribute(attr, typedvalueattr, true); - return typedvalueattr.resourceId; + configure_profile.setIcon(getIcon(iconRes, iconColor)); + configure_profile.setTitle(title); + configure_profile.setSummary(profileType); } public static boolean showInstance(FragmentManager fragmentManager) { @@ -136,4 +82,9 @@ public class SettingsMainFragment extends BaseOsmAndFragment { return false; } } + + @Override + public int getStatusBarColorId() { + return getSettings().isLightContent() ? R.color.status_bar_color_light : R.color.status_bar_color_dark; + } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/settings/TurnScreenOnFragment.java b/OsmAnd/src/net/osmand/plus/settings/TurnScreenOnFragment.java index 9291df27d4..48e6f405cc 100644 --- a/OsmAnd/src/net/osmand/plus/settings/TurnScreenOnFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/TurnScreenOnFragment.java @@ -11,7 +11,7 @@ import android.view.ViewGroup; import net.osmand.plus.R; import net.osmand.plus.views.ListIntPreference; -public class TurnScreenOnFragment extends BaseProfileSettingsFragment { +public class TurnScreenOnFragment extends BaseSettingsFragment { public static final String TAG = "TurnScreenOnFragment"; diff --git a/OsmAnd/src/net/osmand/plus/settings/VehicleParametersFragment.java b/OsmAnd/src/net/osmand/plus/settings/VehicleParametersFragment.java index 723845cad2..587bb16dbd 100644 --- a/OsmAnd/src/net/osmand/plus/settings/VehicleParametersFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/VehicleParametersFragment.java @@ -27,7 +27,7 @@ import java.util.Map; import static net.osmand.plus.activities.SettingsNavigationActivity.getRouter; import static net.osmand.plus.activities.SettingsNavigationActivity.setupSpeedSlider; -public class VehicleParametersFragment extends BaseProfileSettingsFragment { +public class VehicleParametersFragment extends BaseSettingsFragment { public static final String TAG = "VehicleParametersFragment"; diff --git a/OsmAnd/src/net/osmand/plus/settings/VoiceAnnouncesFragment.java b/OsmAnd/src/net/osmand/plus/settings/VoiceAnnouncesFragment.java index 811a833f02..bbf21d2726 100644 --- a/OsmAnd/src/net/osmand/plus/settings/VoiceAnnouncesFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/VoiceAnnouncesFragment.java @@ -25,7 +25,7 @@ import java.util.Set; import static net.osmand.plus.activities.SettingsNavigationActivity.MORE_VALUE; -public class VoiceAnnouncesFragment extends BaseProfileSettingsFragment { +public class VoiceAnnouncesFragment extends BaseSettingsFragment { public static final String TAG = "VoiceAnnouncesFragment";