From 6f569e956534f6e1151bdf5f3420878cb0663b7c Mon Sep 17 00:00:00 2001 From: Chumva Date: Wed, 25 Sep 2019 17:40:55 +0300 Subject: [PATCH] Preferences ui fixes --- OsmAnd/res/layout/preference_with_descr.xml | 26 +++++++---- .../layout/profile_preference_toolbar_big.xml | 10 +++-- OsmAnd/src/net/osmand/AndroidUtils.java | 7 ++- .../plus/activities/MapActivityActions.java | 12 ++--- .../profiles/ConfigureProfileMenuAdapter.java | 16 +++---- .../profiles/SelectProfileMenuAdapter.java | 8 +--- .../plus/settings/BaseSettingsFragment.java | 17 +++++-- .../settings/ConfigureProfileFragment.java | 31 +++++++++++++ .../plus/settings/MainSettingsFragment.java | 45 +++++++++++++++---- 9 files changed, 123 insertions(+), 49 deletions(-) diff --git a/OsmAnd/res/layout/preference_with_descr.xml b/OsmAnd/res/layout/preference_with_descr.xml index e85638b8fd..f8ac00eb23 100644 --- a/OsmAnd/res/layout/preference_with_descr.xml +++ b/OsmAnd/res/layout/preference_with_descr.xml @@ -14,15 +14,25 @@ android:minHeight="@dimen/bottom_sheet_list_item_height" tools:background="?android:attr/selectableItemBackground"> - + 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"> + + + + + android:paddingTop="@dimen/content_padding_half" + android:paddingRight="@dimen/content_padding" + android:paddingBottom="@dimen/content_padding_half"> diff --git a/OsmAnd/src/net/osmand/AndroidUtils.java b/OsmAnd/src/net/osmand/AndroidUtils.java index 847f81f994..d602297fb5 100644 --- a/OsmAnd/src/net/osmand/AndroidUtils.java +++ b/OsmAnd/src/net/osmand/AndroidUtils.java @@ -1,7 +1,6 @@ package net.osmand; -import android.annotation.SuppressLint; import android.app.Activity; import android.app.KeyguardManager; import android.content.Context; @@ -426,6 +425,12 @@ public class AndroidUtils { return outValue.resourceId; } + public static float getFloatValueFromRes(Context ctx, int resId) { + TypedValue outValue = new TypedValue(); + ctx.getResources().getValue(resId, outValue, true); + return outValue.getFloat(); + } + public static int getStatusBarHeight(Context ctx) { int result = 0; int resourceId = ctx.getResources().getIdentifier("status_bar_height", "dimen", "android"); diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java index 09ae214cbc..bd8c1d5233 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java @@ -60,11 +60,11 @@ import net.osmand.plus.measurementtool.MeasurementToolFragment; import net.osmand.plus.monitoring.OsmandMonitoringPlugin; import net.osmand.plus.profiles.AppModesBottomSheetDialogFragment; import net.osmand.plus.profiles.SelectAppModesBottomSheetDialogFragment; -import net.osmand.plus.profiles.SettingsProfileActivity; 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.BaseSettingsFragment; import net.osmand.plus.settings.ConfigureProfileFragment; import net.osmand.plus.views.BaseMapLayer; import net.osmand.plus.views.MapControlsLayer; @@ -74,7 +74,6 @@ import net.osmand.plus.wikivoyage.WikivoyageWelcomeDialogFragment; import net.osmand.plus.wikivoyage.data.TravelDbHelper; import net.osmand.plus.wikivoyage.explore.WikivoyageExploreActivity; import net.osmand.router.GeneralRouter; -import net.osmand.util.Algorithms; import org.apache.commons.logging.Log; @@ -639,13 +638,8 @@ public class MapActivityActions implements DialogProvider { //switch profile button ApplicationMode currentMode = app.getSettings().APPLICATION_MODE.get(); - String modeDescription; - if (currentMode.isCustomProfile()) { - modeDescription = String.format(app.getString(R.string.profile_type_descr_string), - Algorithms.capitalizeFirstLetterAndLowercase(currentMode.getParent().toHumanString(app))); - } else { - modeDescription = getString(R.string.profile_type_base_string); - } + String modeDescription = BaseSettingsFragment.getAppModeDescription(app, currentMode); + optionsMenuHelper.addItem(new ItemBuilder().setLayout(R.layout.main_menu_drawer_btn_switch_profile) .setIcon(currentMode.getIconRes()) .setColor(currentMode.getIconColorInfo().getColor(nightMode)) 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= 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)); diff --git a/OsmAnd/src/net/osmand/plus/settings/MainSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/MainSettingsFragment.java index af2de79cd2..d5fa61c920 100644 --- a/OsmAnd/src/net/osmand/plus/settings/MainSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/MainSettingsFragment.java @@ -1,19 +1,27 @@ 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.UiUtilities; import net.osmand.plus.profiles.SettingsProfileActivity; -import net.osmand.util.Algorithms; public class MainSettingsFragment extends BaseSettingsFragment { public static final String TAG = MainSettingsFragment.class.getSimpleName(); + private static final String CONFIGURE_PROFILE = "configure_profile"; + @Override protected String getFragmentTag() { return TAG; @@ -53,6 +61,31 @@ 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)); @@ -63,16 +96,10 @@ public class MainSettingsFragment extends BaseSettingsFragment { 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);