From 0ec0609b4fd66d9e695a1946e888495db95243e3 Mon Sep 17 00:00:00 2001 From: Nazar-Kutz Date: Thu, 11 Jun 2020 10:32:26 +0300 Subject: [PATCH 1/8] RTL - Step 3 --- OsmAnd/res/anim/slide_in_right.xml | 7 +++++++ OsmAnd/res/anim/slide_out_right.xml | 7 +++++++ OsmAnd/res/layout-land/track_details.xml | 3 +-- OsmAnd/res/layout/along_the_route_category_item.xml | 8 ++++---- OsmAnd/res/layout/gpx_route_card.xml | 2 +- OsmAnd/res/values/styles.xml | 1 + .../osmand/plus/mapcontextmenu/BaseMenuController.java | 7 +++++-- .../plus/mapcontextmenu/builders/AmenityMenuBuilder.java | 2 +- .../plus/mapcontextmenu/other/TrackDetailsMenu.java | 2 ++ .../routepreparationmenu/MapRouteInfoMenuFragment.java | 5 +++-- .../ShowAlongTheRouteBottomSheet.java | 3 ++- .../plus/routepreparationmenu/cards/MapMarkersCard.java | 2 +- .../routepreparationmenu/cards/PedestrianRouteCard.java | 7 +++++++ .../plus/routepreparationmenu/cards/TracksCard.java | 3 ++- 14 files changed, 44 insertions(+), 15 deletions(-) create mode 100644 OsmAnd/res/anim/slide_in_right.xml create mode 100644 OsmAnd/res/anim/slide_out_right.xml diff --git a/OsmAnd/res/anim/slide_in_right.xml b/OsmAnd/res/anim/slide_in_right.xml new file mode 100644 index 0000000000..a58a25ac16 --- /dev/null +++ b/OsmAnd/res/anim/slide_in_right.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/OsmAnd/res/anim/slide_out_right.xml b/OsmAnd/res/anim/slide_out_right.xml new file mode 100644 index 0000000000..7bc5c5a50b --- /dev/null +++ b/OsmAnd/res/anim/slide_out_right.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/OsmAnd/res/layout-land/track_details.xml b/OsmAnd/res/layout-land/track_details.xml index 5f10c6bcb8..969676e1db 100644 --- a/OsmAnd/res/layout-land/track_details.xml +++ b/OsmAnd/res/layout-land/track_details.xml @@ -12,8 +12,7 @@ android:id="@+id/main_view" android:layout_width="match_parent" android:layout_height="match_parent" - android:orientation="vertical" - android:background="@drawable/bg_left_menu_dark"> + android:orientation="vertical"> + tools:text="Some Title" /> @drawable/bg_map_context_menu_light @drawable/bg_bottom_menu_light @drawable/bg_left_menu_light + @drawable/bg_right_menu_light @drawable/bg_point_editor_view_light @color/divider_color_light @color/divider_color diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/BaseMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/BaseMenuController.java index 55a808272e..c753babe48 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/BaseMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/BaseMenuController.java @@ -5,6 +5,7 @@ import android.graphics.drawable.Drawable; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import net.osmand.AndroidUtils; import net.osmand.plus.R; import net.osmand.plus.UiUtilities; import net.osmand.plus.activities.MapActivity; @@ -67,7 +68,8 @@ public abstract class BaseMenuController { public int getSlideInAnimation() { if (isLandscapeLayout()) { - return R.anim.slide_in_left; + return AndroidUtils.isLayoutRtl(getMapActivity()) + ? R.anim.slide_in_right : R.anim.slide_in_left; } else { return R.anim.slide_in_bottom; } @@ -75,7 +77,8 @@ public abstract class BaseMenuController { public int getSlideOutAnimation() { if (isLandscapeLayout()) { - return R.anim.slide_out_left; + return AndroidUtils.isLayoutRtl(getMapActivity()) + ? R.anim.slide_out_right : R.anim.slide_out_left; } else { return R.anim.slide_out_bottom; } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java index 3fb8d61fa8..685335866b 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java @@ -278,7 +278,7 @@ public class AmenityMenuBuilder extends MenuBuilder { light ? R.color.ctx_menu_controller_button_text_color_light_n : R.color.ctx_menu_controller_button_text_color_dark_n); Drawable pressed = app.getUIUtilities().getIcon(R.drawable.ic_action_read_text, light ? R.color.ctx_menu_controller_button_text_color_light_p : R.color.ctx_menu_controller_button_text_color_dark_p); - button.setCompoundDrawablesWithIntrinsicBounds(Build.VERSION.SDK_INT >= 21 + AndroidUtils.setCompoundDrawablesWithIntrinsicBounds(button, Build.VERSION.SDK_INT >= 21 ? AndroidUtils.createPressedStateListDrawable(normal, pressed) : normal, null, null, null); button.setCompoundDrawablePadding(dpToPx(8f)); llText.addView(button); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenu.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenu.java index f5a27329b0..04628bcb48 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenu.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenu.java @@ -172,6 +172,8 @@ public class TrackDetailsMenu { } } }); + int navigationIconResId = AndroidUtils.getNavigationIconResId(mapActivity); + toolbarController.setBackBtnIconIds(navigationIconResId, navigationIconResId); toolbarController.setOnCloseButtonClickListener(new View.OnClickListener() { @Override public void onClick(View v) { diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenuFragment.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenuFragment.java index 5b1705157f..e8b7100c0a 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenuFragment.java @@ -511,8 +511,9 @@ public class MapRouteInfoMenuFragment extends ContextMenuFragment { slideInAnim = R.anim.slide_in_bottom; slideOutAnim = R.anim.slide_out_bottom; } else { - slideInAnim = R.anim.slide_in_left; - slideOutAnim = R.anim.slide_out_left; + boolean isLayoutRtl = AndroidUtils.isLayoutRtl(mapActivity); + slideInAnim = isLayoutRtl ? R.anim.slide_in_right : R.anim.slide_in_left; + slideOutAnim = isLayoutRtl ? R.anim.slide_out_right : R.anim.slide_out_left; } } diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/ShowAlongTheRouteBottomSheet.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/ShowAlongTheRouteBottomSheet.java index 20c93dadc6..34c655ae0b 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/ShowAlongTheRouteBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/ShowAlongTheRouteBottomSheet.java @@ -82,7 +82,8 @@ public class ShowAlongTheRouteBottomSheet extends MenuBottomSheetDialogFragment int expandType = args.getInt(EXPAND_TYPE_KEY, -1); final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; - final View titleView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.bottom_sheet_item_toolbar_title, null); + final View titleView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), + R.layout.bottom_sheet_item_toolbar_title, null); TextView textView = (TextView) titleView.findViewById(R.id.title); textView.setText(R.string.show_along_the_route); diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/MapMarkersCard.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/MapMarkersCard.java index 8da0063324..f4bbd99d8c 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/MapMarkersCard.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/MapMarkersCard.java @@ -114,7 +114,7 @@ public class MapMarkersCard extends BaseCard { if (i > 0) { View div = new View(ctx); LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, AndroidUtils.dpToPx(ctx, 1f)); - p.setMargins(listTextPadding, 0, 0, 0); + AndroidUtils.setMargins(p, listTextPadding, 0, 0, 0); div.setLayoutParams(p); AndroidUtils.setBackgroundColor(ctx, div, nightMode, R.color.divider_color_light, R.color.divider_color_dark); div.setVisibility(View.VISIBLE); diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/PedestrianRouteCard.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/PedestrianRouteCard.java index e331ee1be5..37129373b7 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/PedestrianRouteCard.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/PedestrianRouteCard.java @@ -1,12 +1,14 @@ package net.osmand.plus.routepreparationmenu.cards; import android.graphics.Typeface; +import android.graphics.drawable.Drawable; import android.os.Build; import android.text.SpannableString; import android.text.Spanned; import android.text.style.StyleSpan; import android.view.View; import android.widget.FrameLayout; +import android.widget.ImageView; import android.widget.TextView; import androidx.annotation.NonNull; @@ -59,6 +61,11 @@ public class PedestrianRouteCard extends BaseCard { } else { AndroidUtils.setBackground(app, buttonDescr, nightMode, R.drawable.btn_border_trans_light, R.drawable.btn_border_trans_dark); } + Drawable icPedestrian = app.getUIUtilities().getIcon( + R.drawable.ic_action_pedestrian_dark, + R.color.description_font_and_bottom_sheet_icons); + ((ImageView) view.findViewById(R.id.image)).setImageDrawable( + AndroidUtils.getDrawableForDirection(app, icPedestrian)); view.findViewById(R.id.card_divider).setVisibility(View.VISIBLE); view.findViewById(R.id.top_divider).setVisibility(View.GONE); } diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/TracksCard.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/TracksCard.java index b223049553..b04cfb77aa 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/TracksCard.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/TracksCard.java @@ -11,6 +11,7 @@ import androidx.annotation.NonNull; import androidx.appcompat.view.ContextThemeWrapper; import androidx.core.content.ContextCompat; +import net.osmand.AndroidUtils; import net.osmand.GPXUtilities.GPXFile; import net.osmand.IndexConstants; import net.osmand.plus.GPXDatabase.GpxDataItem; @@ -110,7 +111,7 @@ public class TracksCard extends BaseCard { img.setVisibility(View.VISIBLE); LinearLayout container = (LinearLayout) v.findViewById(R.id.container); container.setMinimumHeight(minCardHeight); - container.setPadding(listContentPadding, 0, 0, 0); + AndroidUtils.setPadding(container, listContentPadding, 0, 0, 0); v.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { From 1f1aad244633e9f168a4a5fc5d25509998c7a1db Mon Sep 17 00:00:00 2001 From: Nazar-Kutz Date: Thu, 11 Jun 2020 10:34:02 +0300 Subject: [PATCH 2/8] RTL - Step 3 (Share button) --- .../EditFavoriteGroupDialogFragment.java | 7 ++++- .../activities/FavoritesTreeFragment.java | 2 +- .../ItemMenuBottomSheetDialogFragment.java | 8 ++++- .../osmand/plus/audionotes/NotesFragment.java | 31 +++++++++++++------ .../base/OsmandExpandableListFragment.java | 15 +++++++-- .../plus/development/LogcatActivity.java | 6 +++- .../plus/myplaces/AvailableGPXFragment.java | 3 +- .../plus/myplaces/TrackPointFragment.java | 2 +- .../plus/myplaces/TrackSegmentFragment.java | 5 ++- .../osmand/plus/osmedit/OsmEditsFragment.java | 5 ++- .../ChooseRouteFragment.java | 11 +++++-- .../MapRouteInfoMenu.java | 5 ++- .../search/QuickSearchDialogFragment.java | 8 ++++- .../osmand/plus/views/MapControlsLayer.java | 5 +++ 14 files changed, 90 insertions(+), 23 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/activities/EditFavoriteGroupDialogFragment.java b/OsmAnd/src/net/osmand/plus/activities/EditFavoriteGroupDialogFragment.java index 80027675b4..8e319c7c8f 100644 --- a/OsmAnd/src/net/osmand/plus/activities/EditFavoriteGroupDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/activities/EditFavoriteGroupDialogFragment.java @@ -3,6 +3,7 @@ package net.osmand.plus.activities; import android.app.Activity; import android.content.Context; import android.content.DialogInterface; +import android.graphics.drawable.Drawable; import android.os.Bundle; import android.view.ContextThemeWrapper; import android.view.Gravity; @@ -197,8 +198,12 @@ public class EditFavoriteGroupDialogFragment extends MenuBottomSheetDialogFragme .create(); items.add(markersGroupItem); + Drawable shareIcon = getContentIcon(R.drawable.ic_action_gshare_dark); + if (shareIcon != null) { + shareIcon = AndroidUtils.getDrawableForDirection(app, shareIcon); + } BaseBottomSheetItem shareItem = new SimpleBottomSheetItem.Builder() - .setIcon(getContentIcon(R.drawable.ic_action_gshare_dark)) + .setIcon(shareIcon) .setTitle(getString(R.string.shared_string_share)) .setLayoutId(R.layout.bottom_sheet_item_simple) .setOnClickListener(new View.OnClickListener() { diff --git a/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java b/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java index 71084c00e2..7f0f1b287d 100644 --- a/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java +++ b/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java @@ -454,7 +454,7 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment implemen if (!MenuItemCompat.isActionViewExpanded(mi)) { createMenuItem(menu, IMPORT_FAVOURITES_ID, R.string.shared_string_add_to_favorites, R.drawable.ic_action_plus, MenuItemCompat.SHOW_AS_ACTION_ALWAYS); - createMenuItem(menu, SHARE_ID, R.string.shared_string_share, R.drawable.ic_action_gshare_dark, MenuItemCompat.SHOW_AS_ACTION_ALWAYS); + createMenuItem(menu, SHARE_ID, R.string.shared_string_share, R.drawable.ic_action_gshare_dark, MenuItemCompat.SHOW_AS_ACTION_ALWAYS, true); createMenuItem(menu, SELECT_MAP_MARKERS_ID, R.string.select_map_markers, R.drawable.ic_action_flag, MenuItemCompat.SHOW_AS_ACTION_ALWAYS); createMenuItem(menu, DELETE_ID, R.string.shared_string_delete, R.drawable.ic_action_delete_dark, MenuItemCompat.SHOW_AS_ACTION_ALWAYS); } diff --git a/OsmAnd/src/net/osmand/plus/audionotes/ItemMenuBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/audionotes/ItemMenuBottomSheetDialogFragment.java index 35bec8bcb0..feed27ec7e 100644 --- a/OsmAnd/src/net/osmand/plus/audionotes/ItemMenuBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/audionotes/ItemMenuBottomSheetDialogFragment.java @@ -1,8 +1,10 @@ package net.osmand.plus.audionotes; +import android.graphics.drawable.Drawable; import android.os.Bundle; import android.view.View; +import net.osmand.AndroidUtils; import net.osmand.plus.R; import net.osmand.plus.audionotes.AudioVideoNotesPlugin.Recording; import net.osmand.plus.base.MenuBottomSheetDialogFragment; @@ -49,8 +51,12 @@ public class ItemMenuBottomSheetDialogFragment extends MenuBottomSheetDialogFrag .create(); items.add(playItem); + Drawable shareIcon = getContentIcon(R.drawable.ic_action_gshare_dark); + if (shareIcon != null) { + AndroidUtils.getDrawableForDirection(requireContext(), shareIcon); + } BaseBottomSheetItem shareItem = new SimpleBottomSheetItem.Builder() - .setIcon(getContentIcon(R.drawable.ic_action_gshare_dark)) + .setIcon(shareIcon) .setTitle(getString(R.string.shared_string_share)) .setLayoutId(R.layout.bottom_sheet_item_simple) .setOnClickListener(new View.OnClickListener() { diff --git a/OsmAnd/src/net/osmand/plus/audionotes/NotesFragment.java b/OsmAnd/src/net/osmand/plus/audionotes/NotesFragment.java index 9ebd955757..09acdca8d8 100644 --- a/OsmAnd/src/net/osmand/plus/audionotes/NotesFragment.java +++ b/OsmAnd/src/net/osmand/plus/audionotes/NotesFragment.java @@ -3,6 +3,7 @@ package net.osmand.plus.audionotes; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; +import android.graphics.drawable.Drawable; import android.media.MediaScannerConnection; import android.net.Uri; import android.os.Build; @@ -21,10 +22,12 @@ import android.widget.ImageView; import android.widget.ListView; import android.widget.Toast; +import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.AlertDialog; import androidx.appcompat.view.ActionMode; import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentManager; import net.osmand.AndroidUtils; @@ -33,6 +36,7 @@ import net.osmand.GPXUtilities.GPXFile; import net.osmand.GPXUtilities.WptPt; import net.osmand.PlatformUtil; import net.osmand.data.PointDescription; +import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.settings.backend.OsmandSettings.NotesSortByMode; import net.osmand.plus.R; @@ -163,14 +167,18 @@ public class NotesFragment extends OsmAndListFragment implements FavoritesFragme } @Override - public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { - menu.clear(); - if (AndroidUiHelper.isOrientationPortrait(getActivity())) { - menu = ((ActionBarProgressActivity) getActivity()).getClearToolbar(true).getMenu(); - } else { - ((ActionBarProgressActivity) getActivity()).getClearToolbar(false); + public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) { + FragmentActivity activity = getActivity(); + if (activity == null) { + return; } - ((ActionBarProgressActivity) getActivity()).updateListViewFooter(footerView); + menu.clear(); + if (AndroidUiHelper.isOrientationPortrait(activity)) { + menu = ((ActionBarProgressActivity) activity).getClearToolbar(true).getMenu(); + } else { + ((ActionBarProgressActivity) activity).getClearToolbar(false); + } + ((ActionBarProgressActivity) activity).updateListViewFooter(footerView); MenuItem item = menu.add(R.string.shared_string_sort).setIcon(R.drawable.ic_action_list_sort); item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @@ -182,7 +190,9 @@ public class NotesFragment extends OsmAndListFragment implements FavoritesFragme }); item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); - item = menu.add(R.string.shared_string_share).setIcon(R.drawable.ic_action_gshare_dark); + Drawable shareIcon = AndroidUtils.getDrawableForDirection(activity, + getMyApplication().getUIUtilities().getIcon(R.drawable.ic_action_gshare_dark)); + item = menu.add(R.string.shared_string_share).setIcon(shareIcon); item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { @@ -377,13 +387,16 @@ public class NotesFragment extends OsmAndListFragment implements FavoritesFragme @Override public boolean onCreateActionMode(final ActionMode mode, Menu menu) { LOG.debug("onCreateActionMode"); + OsmandApplication app = getMyApplication(); if (type == MODE_SHARE) { listAdapter.insert(SHARE_LOCATION_FILE, 0); } switchSelectionMode(true); int titleRes = type == MODE_DELETE ? R.string.shared_string_delete_all : R.string.shared_string_share; int iconRes = type == MODE_DELETE ? R.drawable.ic_action_delete_dark : R.drawable.ic_action_gshare_dark; - MenuItem item = menu.add(titleRes).setIcon(iconRes); + Drawable icon = AndroidUtils.getDrawableForDirection(app, + app.getUIUtilities().getIcon(iconRes)); + MenuItem item = menu.add(titleRes).setIcon(icon); item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { diff --git a/OsmAnd/src/net/osmand/plus/base/OsmandExpandableListFragment.java b/OsmAnd/src/net/osmand/plus/base/OsmandExpandableListFragment.java index e28adac58e..2293f74ef8 100644 --- a/OsmAnd/src/net/osmand/plus/base/OsmandExpandableListFragment.java +++ b/OsmAnd/src/net/osmand/plus/base/OsmandExpandableListFragment.java @@ -15,6 +15,7 @@ import android.widget.ExpandableListView.OnChildClickListener; import androidx.annotation.NonNull; import androidx.core.view.MenuItemCompat; +import net.osmand.AndroidUtils; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.activities.OsmandActionBarActivity; @@ -83,10 +84,20 @@ public abstract class OsmandExpandableListFragment extends BaseOsmAndFragment } public MenuItem createMenuItem(Menu m, int id, int titleRes, int iconId, int menuItemType) { - Drawable d = iconId == 0 ? null : requireMyApplication().getUIUtilities().getIcon(iconId, - isLightActionBar() ? R.color.active_buttons_and_links_text_light : R.color.active_buttons_and_links_text_dark); + return createMenuItem(m, id, titleRes, iconId, menuItemType, false); + } + + public MenuItem createMenuItem(Menu m, int id, int titleRes, int iconId, int menuItemType, + boolean useLayoutDirectionForIcon) { + OsmandApplication app = requireMyApplication(); + Drawable d = iconId == 0 ? null : app.getUIUtilities().getIcon(iconId, isLightActionBar() ? + R.color.active_buttons_and_links_text_light : + R.color.active_buttons_and_links_text_dark); MenuItem menuItem = m.add(0, id, 0, titleRes); if (d != null) { + if (useLayoutDirectionForIcon) { + d = AndroidUtils.getDrawableForDirection(app, d); + } menuItem.setIcon(d); } menuItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { diff --git a/OsmAnd/src/net/osmand/plus/development/LogcatActivity.java b/OsmAnd/src/net/osmand/plus/development/LogcatActivity.java index 65f8ac210d..20f5c4ba4a 100644 --- a/OsmAnd/src/net/osmand/plus/development/LogcatActivity.java +++ b/OsmAnd/src/net/osmand/plus/development/LogcatActivity.java @@ -1,5 +1,6 @@ package net.osmand.plus.development; +import android.graphics.drawable.Drawable; import android.os.AsyncTask; import android.os.Bundle; import android.view.Gravity; @@ -15,6 +16,7 @@ import androidx.appcompat.app.ActionBar; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; +import net.osmand.AndroidUtils; import net.osmand.PlatformUtil; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; @@ -94,8 +96,10 @@ public class LogcatActivity extends ActionBarProgressActivity { @Override public boolean onCreateOptionsMenu(Menu menu) { + OsmandApplication app = getMyApplication(); + Drawable shareIcon = app.getUIUtilities().getIcon(R.drawable.ic_action_gshare_dark); MenuItem share = menu.add(0, SHARE_ID, 0, R.string.shared_string_export); - share.setIcon(R.drawable.ic_action_gshare_dark); + share.setIcon(AndroidUtils.getDrawableForDirection(app, shareIcon)); share.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); diff --git a/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java b/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java index 2e5bafeecd..fb317dc696 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java @@ -1492,8 +1492,9 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment implement return true; } }); + Drawable shareIcon = iconsCache.getThemedIcon((R.drawable.ic_action_gshare_dark)); item = optionsMenu.getMenu().add(R.string.shared_string_share) - .setIcon(iconsCache.getThemedIcon(R.drawable.ic_action_gshare_dark)); + .setIcon(AndroidUtils.getDrawableForDirection(app, shareIcon)); item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { diff --git a/OsmAnd/src/net/osmand/plus/myplaces/TrackPointFragment.java b/OsmAnd/src/net/osmand/plus/myplaces/TrackPointFragment.java index 274dd3a379..b33ff20497 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/TrackPointFragment.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/TrackPointFragment.java @@ -393,7 +393,7 @@ public class TrackPointFragment extends OsmandExpandableListFragment implements if (!mi.isActionViewExpanded()) { - createMenuItem(menu, SHARE_ID, R.string.shared_string_share, R.drawable.ic_action_gshare_dark, MenuItem.SHOW_AS_ACTION_NEVER); + createMenuItem(menu, SHARE_ID, R.string.shared_string_share, R.drawable.ic_action_gshare_dark, MenuItem.SHOW_AS_ACTION_NEVER, true); GPXFile gpxFile = getGpx(); if (gpxFile != null && gpxFile.path != null) { final MapMarkersHelper markersHelper = app.getMapMarkersHelper(); diff --git a/OsmAnd/src/net/osmand/plus/myplaces/TrackSegmentFragment.java b/OsmAnd/src/net/osmand/plus/myplaces/TrackSegmentFragment.java index 71e229030c..8207d401ff 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/TrackSegmentFragment.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/TrackSegmentFragment.java @@ -6,6 +6,7 @@ import android.content.DialogInterface; import android.content.Intent; import android.graphics.Bitmap; import android.graphics.Matrix; +import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.AsyncTask; import android.os.Bundle; @@ -152,7 +153,9 @@ public class TrackSegmentFragment extends OsmAndListFragment implements TrackBit GPXFile gpxFile = getGpx(); if (gpxFile != null) { if (gpxFile.path != null && !gpxFile.showCurrentTrack) { - MenuItem item = menu.add(R.string.shared_string_share).setIcon(R.drawable.ic_action_gshare_dark) + Drawable shareIcon = app.getUIUtilities().getIcon((R.drawable.ic_action_gshare_dark)); + MenuItem item = menu.add(R.string.shared_string_share) + .setIcon(AndroidUtils.getDrawableForDirection(app, shareIcon)) .setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java index 4a7334bd0f..5d4dcff60f 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java @@ -4,6 +4,7 @@ import android.app.Dialog; import android.app.ProgressDialog; import android.content.DialogInterface; import android.content.Intent; +import android.graphics.drawable.Drawable; import android.os.AsyncTask; import android.os.Build; import android.os.Bundle; @@ -248,7 +249,9 @@ public class OsmEditsFragment extends OsmAndListFragment implements SendPoiDialo }); item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); - item = menu.add(R.string.shared_string_export).setIcon(R.drawable.ic_action_gshare_dark); + Drawable shareIcon = getMyApplication().getUIUtilities().getIcon((R.drawable.ic_action_gshare_dark)); + item = menu.add(R.string.shared_string_export) + .setIcon(AndroidUtils.getDrawableForDirection(getMyApplication(), shareIcon)); item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/ChooseRouteFragment.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/ChooseRouteFragment.java index 1d925023bb..205993a316 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/ChooseRouteFragment.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/ChooseRouteFragment.java @@ -19,6 +19,7 @@ import android.view.ViewGroup; import android.view.animation.DecelerateInterpolator; import android.widget.FrameLayout; import android.widget.ImageButton; +import android.widget.ImageView; import android.widget.LinearLayout; import androidx.annotation.DrawableRes; @@ -485,6 +486,7 @@ public class ChooseRouteFragment extends BaseOsmAndFragment implements ContextMe } private void buildMenuButtons(@NonNull View view) { + OsmandApplication app = getMyApplication(); AppCompatImageView backButton = (AppCompatImageView) view.findViewById(R.id.back_button); AppCompatImageButton backButtonFlow = (AppCompatImageButton) view.findViewById(R.id.back_button_flow); OnClickListener backOnClick = new OnClickListener() { @@ -525,8 +527,13 @@ public class ChooseRouteFragment extends BaseOsmAndFragment implements ContextMe saveRoute.setOnClickListener(saveOnClick); saveRouteFlow.setOnClickListener(saveOnClick); - View shareRoute = view.findViewById(R.id.share_as_gpx); - View shareRouteFlow = view.findViewById(R.id.share_as_gpx_flow); + ImageView shareRoute = (ImageView) view.findViewById(R.id.share_as_gpx); + ImageView shareRouteFlow = (ImageView) view.findViewById(R.id.share_as_gpx_flow); + Drawable shareIcon = getIcon(R.drawable.ic_action_gshare_dark, nightMode ? + R.color.text_color_secondary_dark : R.color.text_color_secondary_light); + shareIcon = AndroidUtils.getDrawableForDirection(app, shareIcon); + shareRoute.setImageDrawable(shareIcon); + shareRouteFlow.setImageDrawable(shareIcon); OnClickListener shareOnClick = new OnClickListener() { @Override public void onClick(View v) { diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java index 9e623cd7bd..1bbd71e61d 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java @@ -967,6 +967,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener RoutingHelper routingHelper = app.getRoutingHelper(); final ApplicationMode applicationMode = routingHelper.getAppMode(); final RouteMenuAppModes mode = app.getRoutingOptionsHelper().getRouteMenuAppMode(applicationMode); + boolean isLayoutRTL = AndroidUtils.isLayoutRtl(app); updateControlButtons(mapActivity, mainView); LinearLayout optionsButton = (LinearLayout) mainView.findViewById(R.id.map_options_route_button); @@ -984,7 +985,9 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener clickRouteParams(); } }); - AndroidUtils.setBackground(app, optionsButton, nightMode, R.drawable.route_info_trans_gradient_light, R.drawable.route_info_trans_gradient_dark); + AndroidUtils.setBackground(app, optionsButton, nightMode, + isLayoutRTL ? R.drawable.route_info_trans_gradient_left_light : R.drawable.route_info_trans_gradient_light, + isLayoutRTL ? R.drawable.route_info_trans_gradient_left_dark :R.drawable.route_info_trans_gradient_dark); HorizontalScrollView scrollView = mainView.findViewById(R.id.route_options_scroll_container); scrollView.setVerticalScrollBarEnabled(false); diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java index 673af0c9e1..0ef39d0299 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java @@ -242,6 +242,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC Bundle savedInstanceState) { final MapActivity mapActivity = getMapActivity(); final View view = inflater.inflate(R.layout.search_dialog_fragment, container, false); + final boolean nightMode = !app.getSettings().isLightContent(); toolbarController = new QuickSearchToolbarController(); toolbarController.setOnBackButtonClickListener(new OnClickListener() { @@ -483,7 +484,12 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC ); titleEdit = (TextView) view.findViewById(R.id.titleEdit); - view.findViewById(R.id.shareButton).setOnClickListener( + Drawable shareIcon = app.getUIUtilities().getIcon(R.drawable.ic_action_gshare_dark, + nightMode ? R.color.text_color_secondary_dark : R.color.text_color_secondary_light); + shareIcon = AndroidUtils.getDrawableForDirection(app, shareIcon); + ImageView shareButton = (ImageView) view.findViewById(R.id.shareButton); + shareButton.setImageDrawable(shareIcon); + shareButton.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { diff --git a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java index c308dce187..545804fd23 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java @@ -396,6 +396,7 @@ public class MapControlsLayer extends OsmandMapLayer { routePlanningBtn = createHudButton(routePlanButton, R.drawable.ic_action_gdirections_dark, ROUTE_PLANNING_HUD_ID) .setIconColorId(R.color.map_button_icon_color_light, R.color.map_button_icon_color_dark) .setBg(R.drawable.btn_round, R.drawable.btn_round_night); + routePlanningBtn.flipIconForRtl = true; controls.add(routePlanningBtn); routePlanButton.setOnClickListener(new View.OnClickListener() { @Override @@ -990,6 +991,7 @@ public class MapControlsLayer extends OsmandMapLayer { int resClrLight = R.color.map_button_icon_color_light; int resClrDark = R.color.map_button_icon_color_dark; String id; + boolean flipIconForRtl; boolean nightMode = false; boolean f = true; @@ -1158,6 +1160,9 @@ public class MapControlsLayer extends OsmandMapLayer { d = ctx.getUIUtilities().getIcon(resLightId); } else if (resId != 0) { d = ctx.getUIUtilities().getIcon(resId, nightMode ? resClrDark : resClrLight); + if (flipIconForRtl) { + d = AndroidUtils.getDrawableForDirection(ctx, d); + } } if (iv instanceof ImageView) { if (compass) { From dafbd22b5d963dedf798459367e45d02c6271733 Mon Sep 17 00:00:00 2001 From: Nazar-Kutz Date: Thu, 11 Jun 2020 10:34:54 +0300 Subject: [PATCH 3/8] RTL - Step 3 (Menu controller) --- .../AudioVideoNoteMenuController.java | 8 +-- .../MapContextMenuFragment.java | 63 +++++++++++-------- .../plus/mapcontextmenu/MenuController.java | 30 ++++----- .../controllers/AMapPointMenuController.java | 4 +- .../controllers/AmenityMenuController.java | 2 +- .../ImpassibleRoadsMenuController.java | 3 +- .../controllers/MapDataMenuController.java | 8 +-- .../controllers/MapMarkerMenuController.java | 4 +- .../PointDescriptionMenuController.java | 2 +- .../TargetPointMenuController.java | 4 +- .../controllers/TransportRouteController.java | 8 +-- .../plus/osmedit/EditPOIMenuController.java | 4 +- .../plus/osmedit/OsmBugMenuController.java | 4 +- .../ParkingPositionMenuController.java | 2 +- .../menu/WikivoyageWptPtMenuController.java | 2 +- 15 files changed, 78 insertions(+), 70 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNoteMenuController.java b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNoteMenuController.java index 30c0b1f7ea..f2f31e3a26 100644 --- a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNoteMenuController.java +++ b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNoteMenuController.java @@ -71,7 +71,7 @@ public class AudioVideoNoteMenuController extends MenuController { } }; rightTitleButtonController.caption = mapActivity.getString(R.string.shared_string_delete); - rightTitleButtonController.leftIconId = R.drawable.ic_action_delete_dark; + rightTitleButtonController.startIconId = R.drawable.ic_action_delete_dark; } updateData(); @@ -164,7 +164,7 @@ public class AudioVideoNoteMenuController extends MenuController { if (!mRecording.isPhoto()) { if (mPlugin.isPlaying(mRecording)) { leftTitleButtonController.caption = mapActivity.getString(R.string.shared_string_control_stop); - leftTitleButtonController.leftIconId = R.drawable.ic_action_rec_stop; + leftTitleButtonController.startIconId = R.drawable.ic_action_rec_stop; int pos = mPlugin.getPlayingPosition(); String durationStr; if (pos == -1) { @@ -177,14 +177,14 @@ public class AudioVideoNoteMenuController extends MenuController { rightTitleButtonController.visible = false; } else { leftTitleButtonController.caption = mapActivity.getString(R.string.recording_context_menu_play); - leftTitleButtonController.leftIconId = R.drawable.ic_play_dark; + leftTitleButtonController.startIconId = R.drawable.ic_play_dark; String durationStr = mRecording.getPlainDuration(accessibilityEnabled); leftTitleButtonController.needRightText = true; leftTitleButtonController.rightTextCaption = "— " + durationStr; } } else { leftTitleButtonController.caption = mapActivity.getString(R.string.recording_context_menu_show); - leftTitleButtonController.leftIconId = R.drawable.ic_action_view; + leftTitleButtonController.startIconId = R.drawable.ic_action_view; } } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java index e84811c376..9080f88ca6 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java @@ -628,7 +628,8 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo } Drawable drawable = getIcon(iconResId, bottomButtonsColor); directionsButton.setTextColor(ContextCompat.getColor(mapActivity, bottomButtonsColor)); - AndroidUtils.setCompoundDrawablesWithIntrinsicBounds(directionsButton, null, null, drawable, null); + AndroidUtils.setCompoundDrawablesWithIntrinsicBounds( + directionsButton, null, null, drawable, null); int contentPaddingHalf = (int) getResources().getDimension(R.dimen.content_padding_half); directionsButton.setCompoundDrawablePadding(contentPaddingHalf); directionsButton.setOnClickListener(new View.OnClickListener() { @@ -1147,11 +1148,12 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo setupButton(leftTitleButtonView, leftTitleButtonController.enabled, title); if (leftTitleButtonController.visible) { leftTitleButtonView.setVisibility(View.VISIBLE); - Drawable leftIcon = leftTitleButtonController.getLeftIcon(); - Drawable rightIcon = leftTitleButtonController.getRightIcon(); - leftTitleButton.setCompoundDrawablesWithIntrinsicBounds(leftIcon, null, rightIcon, null); + Drawable startIcon = leftTitleButtonController.getStartIcon(); + Drawable endIcon = leftTitleButtonController.getEndIcon(); + AndroidUtils.setCompoundDrawablesWithIntrinsicBounds( + leftTitleButton, startIcon, null, endIcon, null); leftTitleButton.setCompoundDrawablePadding(view.getResources().getDimensionPixelSize(R.dimen.content_padding_half)); - ((LinearLayout) leftTitleButtonView).setGravity(rightIcon != null ? Gravity.END : Gravity.START); + ((LinearLayout) leftTitleButtonView).setGravity(endIcon != null ? Gravity.END : Gravity.START); } else { leftTitleButtonView.setVisibility(View.INVISIBLE); } @@ -1166,11 +1168,12 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo setupButton(rightTitleButtonView, rightTitleButtonController.enabled, rightTitleButtonController.caption); rightTitleButtonView.setVisibility(rightTitleButtonController.visible ? View.VISIBLE : View.INVISIBLE); - Drawable leftIcon = rightTitleButtonController.getLeftIcon(); - Drawable rightIcon = rightTitleButtonController.getRightIcon(); - rightTitleButton.setCompoundDrawablesWithIntrinsicBounds(leftIcon, null, rightIcon, null); + Drawable startIcon = rightTitleButtonController.getStartIcon(); + Drawable endIcon = rightTitleButtonController.getEndIcon(); + AndroidUtils.setCompoundDrawablesWithIntrinsicBounds( + rightTitleButton, startIcon, null, endIcon, null); rightTitleButton.setCompoundDrawablePadding(view.getResources().getDimensionPixelSize(R.dimen.content_padding_half)); - ((LinearLayout) rightTitleButtonView).setGravity(rightIcon != null ? Gravity.END : Gravity.START); + ((LinearLayout) rightTitleButtonView).setGravity(endIcon != null ? Gravity.END : Gravity.START); } else { rightTitleButtonView.setVisibility(View.INVISIBLE); } @@ -1182,11 +1185,12 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo setupButton(bottomTitleButtonView, bottomTitleButtonController.enabled, bottomTitleButtonController.caption); bottomTitleButtonView.setVisibility(bottomTitleButtonController.visible ? View.VISIBLE : View.GONE); - Drawable leftIcon = bottomTitleButtonController.getLeftIcon(); - Drawable rightIcon = bottomTitleButtonController.getRightIcon(); - bottomTitleButton.setCompoundDrawablesWithIntrinsicBounds(leftIcon, null, rightIcon, null); + Drawable startIcon = bottomTitleButtonController.getStartIcon(); + Drawable endIcon = bottomTitleButtonController.getEndIcon(); + AndroidUtils.setCompoundDrawablesWithIntrinsicBounds( + bottomTitleButton, startIcon, null, endIcon, null); bottomTitleButton.setCompoundDrawablePadding(view.getResources().getDimensionPixelSize(R.dimen.content_padding_half)); - ((LinearLayout) bottomTitleButtonView).setGravity(rightIcon != null ? Gravity.END : Gravity.START); + ((LinearLayout) bottomTitleButtonView).setGravity(endIcon != null ? Gravity.END : Gravity.START); } else { bottomTitleButtonView.setVisibility(View.GONE); } @@ -1206,11 +1210,12 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo setupButton(leftDownloadButtonView, leftDownloadButtonController.enabled, leftDownloadButtonController.caption); leftDownloadButtonView.setVisibility(leftDownloadButtonController.visible ? View.VISIBLE : View.INVISIBLE); - Drawable leftIcon = leftDownloadButtonController.getLeftIcon(); - Drawable rightIcon = leftDownloadButtonController.getRightIcon(); - leftDownloadButton.setCompoundDrawablesWithIntrinsicBounds(leftIcon, null, rightIcon, null); + Drawable startIcon = leftDownloadButtonController.getStartIcon(); + Drawable endIcon = leftDownloadButtonController.getEndIcon(); + AndroidUtils.setCompoundDrawablesWithIntrinsicBounds( + leftDownloadButton, startIcon, null, endIcon, null); leftDownloadButton.setCompoundDrawablePadding(view.getResources().getDimensionPixelSize(R.dimen.content_padding_half)); - ((LinearLayout) leftDownloadButtonView).setGravity(rightIcon != null ? Gravity.END : Gravity.START); + ((LinearLayout) leftDownloadButtonView).setGravity(endIcon != null ? Gravity.END : Gravity.START); } else { leftDownloadButtonView.setVisibility(View.INVISIBLE); } @@ -1222,11 +1227,12 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo setupButton(rightDownloadButtonView, rightDownloadButtonController.enabled, rightDownloadButtonController.caption); rightDownloadButtonView.setVisibility(rightDownloadButtonController.visible ? View.VISIBLE : View.INVISIBLE); - Drawable leftIcon = rightDownloadButtonController.getLeftIcon(); - Drawable rightIcon = rightDownloadButtonController.getRightIcon(); - rightDownloadButton.setCompoundDrawablesWithIntrinsicBounds(leftIcon, null, rightIcon, null); + Drawable startIcon = rightDownloadButtonController.getStartIcon(); + Drawable endIcon = rightDownloadButtonController.getEndIcon(); + AndroidUtils.setCompoundDrawablesWithIntrinsicBounds( + rightDownloadButton, startIcon, null, endIcon, null); rightDownloadButton.setCompoundDrawablePadding(view.getResources().getDimensionPixelSize(R.dimen.content_padding_half)); - ((LinearLayout) rightDownloadButtonView).setGravity(rightIcon != null ? Gravity.END : Gravity.START); + ((LinearLayout) rightDownloadButtonView).setGravity(endIcon != null ? Gravity.END : Gravity.START); } else { rightDownloadButtonView.setVisibility(View.INVISIBLE); } @@ -1292,11 +1298,12 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo setupButton(buttonView, buttonController.enabled, buttonController.caption); buttonView.setVisibility(buttonController.visible ? View.VISIBLE : View.INVISIBLE); - Drawable leftIcon = buttonController.getLeftIcon(); - Drawable rightIcon = buttonController.getRightIcon(); - buttonText.setCompoundDrawablesWithIntrinsicBounds(leftIcon, null, rightIcon, null); + Drawable startIcon = buttonController.getStartIcon(); + Drawable endIcon = buttonController.getEndIcon(); + AndroidUtils.setCompoundDrawablesWithIntrinsicBounds( + buttonText, startIcon, null, endIcon, null); buttonText.setCompoundDrawablePadding(view.getResources().getDimensionPixelSize(R.dimen.content_padding_half)); - ((LinearLayout) buttonView).setGravity(rightIcon != null ? Gravity.END : Gravity.START); + ((LinearLayout) buttonView).setGravity(endIcon != null ? Gravity.END : Gravity.START); buttonView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -1805,7 +1812,8 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo if (!Algorithms.isEmpty(typeStr)) { line2Str.append(typeStr); Drawable icon = menu.getTypeIcon(); - line2.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null); + AndroidUtils.setCompoundDrawablesWithIntrinsicBounds( + line2, icon, null, null, null); line2.setCompoundDrawablePadding(dpToPx(5f)); } if (!Algorithms.isEmpty(streetStr) && !menu.displayStreetNameInTitle()) { @@ -1830,7 +1838,8 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo line3.setVisibility(View.VISIBLE); line3.setText(subtypeStr); Drawable icon = menu.getSubtypeIcon(); - line3.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null); + AndroidUtils.setCompoundDrawablesWithIntrinsicBounds( + line3, icon, null, null, null); line3.setCompoundDrawablePadding(dpToPx(5f)); } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java index 5ce2472c63..10189546ac 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java @@ -659,7 +659,7 @@ public abstract class MenuController extends BaseMenuController implements Colla } leftDownloadButtonController.visible = !downloaded; - leftDownloadButtonController.leftIconId = R.drawable.ic_action_import; + leftDownloadButtonController.startIconId = R.drawable.ic_action_import; boolean internetConnectionAvailable = mapActivity.getMyApplication().getSettings().isInternetConnectionAvailable(); @@ -712,33 +712,33 @@ public abstract class MenuController extends BaseMenuController implements Colla public abstract class TitleButtonController { public String caption = ""; - public int leftIconId = 0; - public int rightIconId = 0; + public int startIconId = 0; + public int endIconId = 0; public boolean needRightText = false; public String rightTextCaption = ""; public boolean visible = true; public boolean tintIcon = true; - public Drawable leftIcon; - public Drawable rightIcon; + public Drawable startIcon; + public Drawable endIcon; public boolean enabled = true; @Nullable - public Drawable getLeftIcon() { + public Drawable getStartIcon() { return getIconDrawable(true); } @Nullable - public Drawable getRightIcon() { + public Drawable getEndIcon() { return getIconDrawable(false); } @Nullable - private Drawable getIconDrawable(boolean left) { - Drawable drawable = left ? leftIcon : rightIcon; + private Drawable getIconDrawable(boolean start) { + Drawable drawable = start ? startIcon : endIcon; if (drawable != null) { return drawable; } - int resId = left ? leftIconId : rightIconId; + int resId = start ? startIconId : endIconId; if (resId != 0) { if (tintIcon) { return enabled ? getNormalIcon(resId) : getDisabledIcon(resId); @@ -751,11 +751,11 @@ public abstract class MenuController extends BaseMenuController implements Colla public void clearIcon(boolean left) { if (left) { - leftIcon = null; - leftIconId = 0; + startIcon = null; + startIconId = 0; } else { - rightIcon = null; - rightIconId = 0; + endIcon = null; + endIconId = 0; } } @@ -893,7 +893,7 @@ public abstract class MenuController extends BaseMenuController implements Colla }; leftDownloadButtonController.caption = downloadRegion != null ? downloadRegion.getLocaleName() : mapActivity.getString(R.string.shared_string_download); - leftDownloadButtonController.leftIconId = R.drawable.ic_action_import; + leftDownloadButtonController.startIconId = R.drawable.ic_action_import; titleProgressController = new TitleProgressController() { @Override diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AMapPointMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AMapPointMenuController.java index 020041a10d..73a43404a7 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AMapPointMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AMapPointMenuController.java @@ -201,8 +201,8 @@ public class AMapPointMenuController extends MenuController { OsmandApplication app = mapActivity.getMyApplication(); titleButtonController.caption = contextMenuButton.getLeftTextCaption(); titleButtonController.rightTextCaption = contextMenuButton.getRightTextCaption(); - titleButtonController.leftIconId = AndroidUtils.getDrawableId(app, contextMenuButton.getLeftIconName()); - titleButtonController.rightIconId = AndroidUtils.getDrawableId(app, contextMenuButton.getRightIconName()); + titleButtonController.startIconId = AndroidUtils.getDrawableId(app, contextMenuButton.getLeftIconName()); + titleButtonController.endIconId = AndroidUtils.getDrawableId(app, contextMenuButton.getRightIconName()); titleButtonController.enabled = contextMenuButton.isEnabled(); titleButtonController.tintIcon = contextMenuButton.isTintIcon(); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AmenityMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AmenityMenuController.java index 17336f769e..3e6ad7083c 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AmenityMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AmenityMenuController.java @@ -79,7 +79,7 @@ public class AmenityMenuController extends MenuController { } }; leftTitleButtonController.caption = mapActivity.getString(R.string.context_menu_read_article); - leftTitleButtonController.leftIconId = R.drawable.ic_action_read_text; + leftTitleButtonController.startIconId = R.drawable.ic_action_read_text; } openingHoursInfo = OpeningHoursParser.getInfo(amenity.getOpeningHours()); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/ImpassibleRoadsMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/ImpassibleRoadsMenuController.java index 9bad770437..2d29f217ff 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/ImpassibleRoadsMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/ImpassibleRoadsMenuController.java @@ -4,7 +4,6 @@ import android.graphics.drawable.Drawable; import androidx.annotation.NonNull; import androidx.appcompat.content.res.AppCompatResources; -import androidx.core.content.ContextCompat; import net.osmand.data.PointDescription; import net.osmand.plus.OsmandApplication; @@ -41,7 +40,7 @@ public class ImpassibleRoadsMenuController extends MenuController { } }; leftTitleButtonController.caption = mapActivity.getString(R.string.shared_string_remove); - leftTitleButtonController.leftIconId = R.drawable.ic_action_delete_dark; + leftTitleButtonController.startIconId = R.drawable.ic_action_delete_dark; } @Override diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/MapDataMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/MapDataMenuController.java index 8bde5fbe6d..9bfde65368 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/MapDataMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/MapDataMenuController.java @@ -124,7 +124,7 @@ public class MapDataMenuController extends MenuController { } }; leftDownloadButtonController.caption = mapActivity.getString(R.string.shared_string_download); - leftDownloadButtonController.leftIconId = R.drawable.ic_action_import; + leftDownloadButtonController.startIconId = R.drawable.ic_action_import; rightDownloadButtonController = new TitleButtonController() { @Override @@ -154,7 +154,7 @@ public class MapDataMenuController extends MenuController { } }; rightDownloadButtonController.caption = mapActivity.getString(R.string.download_select_map_types); - rightDownloadButtonController.leftIconId = R.drawable.ic_plugin_srtm; + rightDownloadButtonController.startIconId = R.drawable.ic_plugin_srtm; bottomTitleButtonController = new TitleButtonController() { @Override @@ -171,7 +171,7 @@ public class MapDataMenuController extends MenuController { } }; bottomTitleButtonController.caption = mapActivity.getString(R.string.shared_string_delete); - bottomTitleButtonController.leftIconId = R.drawable.ic_action_delete_dark; + bottomTitleButtonController.startIconId = R.drawable.ic_action_delete_dark; titleProgressController = new TitleProgressController() { @Override @@ -396,7 +396,7 @@ public class MapDataMenuController extends MenuController { } leftDownloadButtonController.visible = true; - leftDownloadButtonController.leftIconId = R.drawable.ic_action_import; + leftDownloadButtonController.startIconId = R.drawable.ic_action_import; if (backuped) { leftDownloadButtonController.caption = mapActivity.getString(R.string.local_index_mi_restore); } else if (indexItem != null) { diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/MapMarkerMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/MapMarkerMenuController.java index 5641f125ec..3cdf3398a6 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/MapMarkerMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/MapMarkerMenuController.java @@ -48,7 +48,7 @@ public class MapMarkerMenuController extends MenuController { } }; leftTitleButtonController.caption = mapActivity.getString(mapMarker.history ? R.string.shared_string_restore : R.string.mark_passed); - leftTitleButtonController.leftIcon = createPassedIcon(getPassedIconBgNormalColorId()); + leftTitleButtonController.startIcon = createPassedIcon(getPassedIconBgNormalColorId()); if (!mapMarker.history) { rightTitleButtonController = new TitleButtonController() { @@ -69,7 +69,7 @@ public class MapMarkerMenuController extends MenuController { } }; rightTitleButtonController.caption = mapActivity.getString(R.string.make_active); - rightTitleButtonController.leftIcon = createShowOnTopbarIcon(getDeviceTopNormalColorId()); + rightTitleButtonController.startIcon = createShowOnTopbarIcon(getDeviceTopNormalColorId()); } } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/PointDescriptionMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/PointDescriptionMenuController.java index 114a6fb6f1..7578fa7d5a 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/PointDescriptionMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/PointDescriptionMenuController.java @@ -39,7 +39,7 @@ public class PointDescriptionMenuController extends MenuController { } }; leftTitleButtonController.caption = mapActivity.getString(R.string.avoid_road); - leftTitleButtonController.leftIconId = R.drawable.ic_action_road_works_dark; + leftTitleButtonController.startIconId = R.drawable.ic_action_road_works_dark; } } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TargetPointMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TargetPointMenuController.java index 5cf76ab694..ac887edc89 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TargetPointMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TargetPointMenuController.java @@ -52,10 +52,10 @@ public class TargetPointMenuController extends MenuController { }; if (nav && intermediatePointsCount == 0 && !targetPoint.start) { leftTitleButtonController.caption = mapActivity.getString(R.string.cancel_navigation); - leftTitleButtonController.leftIconId = R.drawable.ic_action_remove_dark; + leftTitleButtonController.startIconId = R.drawable.ic_action_remove_dark; } else { leftTitleButtonController.caption = mapActivity.getString(R.string.shared_string_remove); - leftTitleButtonController.leftIconId = R.drawable.ic_action_delete_dark; + leftTitleButtonController.startIconId = R.drawable.ic_action_delete_dark; } } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportRouteController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportRouteController.java index 585ba61f62..7d9fc87d32 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportRouteController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportRouteController.java @@ -82,11 +82,11 @@ public class TransportRouteController extends MenuController { rightTitleButtonController.caption = mapActivity.getString(R.string.shared_string_next); if (AndroidUtils.isLayoutRtl(mapActivity)) { - leftTitleButtonController.rightIconId = R.drawable.ic_arrow_forward; - rightTitleButtonController.leftIconId = R.drawable.ic_arrow_back; + leftTitleButtonController.endIconId = R.drawable.ic_arrow_forward; + rightTitleButtonController.startIconId = R.drawable.ic_arrow_back; } else { - leftTitleButtonController.leftIconId = R.drawable.ic_arrow_back; - rightTitleButtonController.rightIconId = R.drawable.ic_arrow_forward; + leftTitleButtonController.startIconId = R.drawable.ic_arrow_back; + rightTitleButtonController.endIconId = R.drawable.ic_arrow_forward; } } diff --git a/OsmAnd/src/net/osmand/plus/osmedit/EditPOIMenuController.java b/OsmAnd/src/net/osmand/plus/osmedit/EditPOIMenuController.java index b8146e5b7f..2511dafdf2 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/EditPOIMenuController.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/EditPOIMenuController.java @@ -46,7 +46,7 @@ public class EditPOIMenuController extends MenuController { } }; leftTitleButtonController.caption = mapActivity.getString(R.string.shared_string_upload); - leftTitleButtonController.leftIconId = R.drawable.ic_action_export; + leftTitleButtonController.startIconId = R.drawable.ic_action_export; rightTitleButtonController = new TitleButtonController() { @Override @@ -80,7 +80,7 @@ public class EditPOIMenuController extends MenuController { } }; rightTitleButtonController.caption = mapActivity.getString(R.string.shared_string_delete); - rightTitleButtonController.leftIconId = R.drawable.ic_action_delete_dark; + rightTitleButtonController.startIconId = R.drawable.ic_action_delete_dark; categoryDescr = getCategoryDescr(); diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmBugMenuController.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmBugMenuController.java index 3692da70f8..97ffee1b2f 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmBugMenuController.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmBugMenuController.java @@ -42,7 +42,7 @@ public class OsmBugMenuController extends MenuController { } else { leftTitleButtonController.caption = mapActivity.getString(R.string.poi_dialog_reopen); } - leftTitleButtonController.leftIconId = R.drawable.ic_action_note_dark; + leftTitleButtonController.startIconId = R.drawable.ic_action_note_dark; rightTitleButtonController = new TitleButtonController() { @Override @@ -54,7 +54,7 @@ public class OsmBugMenuController extends MenuController { } }; rightTitleButtonController.caption = mapActivity.getString(R.string.shared_string_close); - rightTitleButtonController.leftIconId = R.drawable.ic_action_remove_dark; + rightTitleButtonController.startIconId = R.drawable.ic_action_remove_dark; updateData(); } diff --git a/OsmAnd/src/net/osmand/plus/parkingpoint/ParkingPositionMenuController.java b/OsmAnd/src/net/osmand/plus/parkingpoint/ParkingPositionMenuController.java index a0bbd48bf8..97563be6b1 100644 --- a/OsmAnd/src/net/osmand/plus/parkingpoint/ParkingPositionMenuController.java +++ b/OsmAnd/src/net/osmand/plus/parkingpoint/ParkingPositionMenuController.java @@ -34,7 +34,7 @@ public class ParkingPositionMenuController extends MenuController { } }; leftTitleButtonController.caption = mapActivity.getString(R.string.shared_string_delete); - leftTitleButtonController.leftIconId = R.drawable.ic_action_delete_dark; + leftTitleButtonController.startIconId = R.drawable.ic_action_delete_dark; } private void buildParkingDescription(MapActivity mapActivity) { diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/menu/WikivoyageWptPtMenuController.java b/OsmAnd/src/net/osmand/plus/wikivoyage/menu/WikivoyageWptPtMenuController.java index b923e617a3..1ea04be8b4 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/menu/WikivoyageWptPtMenuController.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/menu/WikivoyageWptPtMenuController.java @@ -32,7 +32,7 @@ public class WikivoyageWptPtMenuController extends WptPtMenuController { } }; leftTitleButtonController.caption = mapActivity.getString(R.string.context_menu_read_article); - leftTitleButtonController.leftIconId = R.drawable.ic_action_read_text; + leftTitleButtonController.startIconId = R.drawable.ic_action_read_text; } private static TravelArticle getTravelArticle(@NonNull MapActivity mapActivity, @NonNull WptPt wpt) { From 312d5775ee6949e542a4b2c6d90bdd356861052c Mon Sep 17 00:00:00 2001 From: Nazar-Kutz Date: Thu, 11 Jun 2020 10:41:14 +0300 Subject: [PATCH 4/8] rename useLayoutDirectionForIcon -> flipIconForRtl --- .../net/osmand/plus/base/OsmandExpandableListFragment.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/base/OsmandExpandableListFragment.java b/OsmAnd/src/net/osmand/plus/base/OsmandExpandableListFragment.java index 2293f74ef8..cc2f0b47af 100644 --- a/OsmAnd/src/net/osmand/plus/base/OsmandExpandableListFragment.java +++ b/OsmAnd/src/net/osmand/plus/base/OsmandExpandableListFragment.java @@ -88,14 +88,14 @@ public abstract class OsmandExpandableListFragment extends BaseOsmAndFragment } public MenuItem createMenuItem(Menu m, int id, int titleRes, int iconId, int menuItemType, - boolean useLayoutDirectionForIcon) { + boolean flipIconForRtl) { OsmandApplication app = requireMyApplication(); Drawable d = iconId == 0 ? null : app.getUIUtilities().getIcon(iconId, isLightActionBar() ? R.color.active_buttons_and_links_text_light : R.color.active_buttons_and_links_text_dark); MenuItem menuItem = m.add(0, id, 0, titleRes); if (d != null) { - if (useLayoutDirectionForIcon) { + if (flipIconForRtl) { d = AndroidUtils.getDrawableForDirection(app, d); } menuItem.setIcon(d); From cb105deda0d5957c134e68122f487082cc896196 Mon Sep 17 00:00:00 2001 From: Nazar-Kutz Date: Thu, 11 Jun 2020 15:24:54 +0300 Subject: [PATCH 5/8] RTL - Step 3 (PopUp Menu) --- OsmAnd/res/layout/popup_menu_item.xml | 31 ++++++++ .../plus/SimplePopUpMenuItemAdapter.java | 78 +++++++++++++++++++ OsmAnd/src/net/osmand/plus/UiUtilities.java | 44 +++++++++++ .../other/TrackDetailsMenu.java | 75 +++++++++--------- 4 files changed, 188 insertions(+), 40 deletions(-) create mode 100644 OsmAnd/res/layout/popup_menu_item.xml create mode 100644 OsmAnd/src/net/osmand/plus/SimplePopUpMenuItemAdapter.java diff --git a/OsmAnd/res/layout/popup_menu_item.xml b/OsmAnd/res/layout/popup_menu_item.xml new file mode 100644 index 0000000000..66509ffa4d --- /dev/null +++ b/OsmAnd/res/layout/popup_menu_item.xml @@ -0,0 +1,31 @@ + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/SimplePopUpMenuItemAdapter.java b/OsmAnd/src/net/osmand/plus/SimplePopUpMenuItemAdapter.java new file mode 100644 index 0000000000..3dadf98f60 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/SimplePopUpMenuItemAdapter.java @@ -0,0 +1,78 @@ +package net.osmand.plus; + +import android.content.Context; +import android.graphics.drawable.Drawable; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.ImageView; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import java.util.List; + +public class SimplePopUpMenuItemAdapter + extends ArrayAdapter { + + private List items; + + public SimplePopUpMenuItemAdapter(@NonNull Context context, int resource, + List items) { + super(context, resource); + this.items = items; + } + + @Override + public int getCount() { + return items.size(); + } + + @NonNull + @Override + public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) { + LayoutInflater inflater = LayoutInflater.from(getContext()); + if (convertView == null) { + convertView = inflater.inflate(R.layout.popup_menu_item, null); + } + SimplePopUpMenuItem item = getItem(position); + if (item != null) { + TextView tvTitle = convertView.findViewById(R.id.title); + tvTitle.setText(item.title); + ImageView ivIcon = convertView.findViewById(R.id.icon); + Drawable icon = item.icon; + if (icon != null) { + ivIcon.setImageDrawable(icon); + } else { + ivIcon.setVisibility(View.GONE); + } + } + return convertView; + } + + @Nullable + @Override + public SimplePopUpMenuItem getItem(int position) { + return items.get(position); + } + + public static class SimplePopUpMenuItem { + private CharSequence title; + private Drawable icon; + + public SimplePopUpMenuItem(CharSequence title, Drawable icon) { + this.title = title; + this.icon = icon; + } + + public CharSequence getTitle() { + return title; + } + + public Drawable getIcon() { + return icon; + } + } +} diff --git a/OsmAnd/src/net/osmand/plus/UiUtilities.java b/OsmAnd/src/net/osmand/plus/UiUtilities.java index 0a168ffec9..d93bdbc6dc 100644 --- a/OsmAnd/src/net/osmand/plus/UiUtilities.java +++ b/OsmAnd/src/net/osmand/plus/UiUtilities.java @@ -3,6 +3,7 @@ package net.osmand.plus; import android.content.Context; import android.content.res.ColorStateList; import android.graphics.Color; +import android.graphics.Paint; import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; import android.graphics.drawable.LayerDrawable; @@ -19,6 +20,7 @@ import android.view.View; import android.view.ViewGroup; import android.view.ViewParent; import android.view.WindowManager; +import android.widget.AdapterView; import android.widget.CompoundButton; import android.widget.ImageView; import android.widget.LinearLayout; @@ -31,6 +33,7 @@ import androidx.annotation.NonNull; import androidx.annotation.StringRes; import androidx.appcompat.content.res.AppCompatResources; import androidx.appcompat.view.ContextThemeWrapper; +import androidx.appcompat.widget.ListPopupWindow; import androidx.appcompat.widget.SwitchCompat; import androidx.core.content.ContextCompat; import androidx.core.graphics.drawable.DrawableCompat; @@ -52,6 +55,8 @@ import net.osmand.plus.widgets.TextViewEx; import org.apache.commons.logging.Log; +import java.util.List; + import gnu.trove.map.hash.TLongObjectHashMap; public class UiUtilities { @@ -645,4 +650,43 @@ public class UiUtilities { return spannable; } } + + public static ListPopupWindow createListPopupWindow(Context themedCtx, View v, + List items, + final AdapterView.OnItemClickListener listener) { + int contentPadding = themedCtx.getResources().getDimensionPixelSize(R.dimen.content_padding); + int contentPaddingHalf = themedCtx.getResources().getDimensionPixelSize(R.dimen.content_padding_half); + + Paint paint = new Paint(); + paint.setTextSize(themedCtx.getResources().getDimensionPixelSize(R.dimen.default_list_text_size)); + CharSequence longestTitle = ""; + for (SimplePopUpMenuItemAdapter.SimplePopUpMenuItem item : items) { + if (item.getTitle().length() > longestTitle.length()) { + longestTitle = item.getTitle(); + } + } + float titleTextWidth = paint.measureText(longestTitle.toString()); + float itemWidth = titleTextWidth + contentPadding; + float minWidth = v.getWidth(); + + SimplePopUpMenuItemAdapter adapter = + new SimplePopUpMenuItemAdapter(themedCtx, R.layout.popup_menu_item, items); + final ListPopupWindow listPopupWindow = new ListPopupWindow(themedCtx); + listPopupWindow.setAnchorView(v); + listPopupWindow.setContentWidth((int) (Math.max(itemWidth, minWidth))); + listPopupWindow.setDropDownGravity(Gravity.END | Gravity.TOP); + listPopupWindow.setVerticalOffset(-v.getHeight() + contentPaddingHalf); + listPopupWindow.setModal(true); + listPopupWindow.setAdapter(adapter); + listPopupWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + if (listener != null) { + listener.onItemClick(parent, view, position, id); + } + listPopupWindow.dismiss(); + } + }); + return listPopupWindow; + } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenu.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenu.java index 04628bcb48..39e5dd1bac 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenu.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenu.java @@ -2,15 +2,14 @@ package net.osmand.plus.mapcontextmenu.other; import android.content.Context; import android.graphics.Matrix; -import android.view.MenuItem; import android.view.MotionEvent; import android.view.View; +import android.widget.AdapterView; import android.widget.ImageView; import android.widget.TextView; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.appcompat.widget.PopupMenu; import com.github.mikephil.charting.charts.LineChart; import com.github.mikephil.charting.data.Entry; @@ -33,9 +32,9 @@ import net.osmand.data.RotatedTileBox; import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; +import net.osmand.plus.SimplePopUpMenuItemAdapter; import net.osmand.plus.UiUtilities; import net.osmand.plus.activities.MapActivity; -import net.osmand.plus.dialogs.DirectionsDialogs; import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.helpers.GpxUiHelper; import net.osmand.plus.helpers.GpxUiHelper.GPXDataSetAxisType; @@ -653,23 +652,22 @@ public class TrackDetailsMenu { yAxis.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - PopupMenu optionsMenu = new PopupMenu(v.getContext(), v); - DirectionsDialogs.setupPopUpMenuIcon(optionsMenu); - for (final GPXDataSetType[] types : availableTypes) { - MenuItem menuItem = optionsMenu.getMenu() - .add(GPXDataSetType.getName(app, types)) - .setIcon(GPXDataSetType.getImageDrawable(app, types)); - menuItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { - @Override - public boolean onMenuItemClick(MenuItem mItem) { - GpxDisplayItem gpxItem = getGpxItem(); - gpxItem.chartTypes = types; - update(); - return true; - } - }); + Context themedContext = UiUtilities.getThemedContext(v.getContext(), true); + List items = new ArrayList<>(); + for (GPXDataSetType[] types : availableTypes) { + items.add(new SimplePopUpMenuItemAdapter.SimplePopUpMenuItem( + GPXDataSetType.getName(app, types), + GPXDataSetType.getImageDrawable(app, types))); } - optionsMenu.show(); + UiUtilities.createListPopupWindow( + themedContext, v, items, new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + GpxDisplayItem gpxItem = getGpxItem(); + gpxItem.chartTypes = availableTypes.get(position); + update(); + } + }).show(); } }); yAxisArrow.setVisibility(View.VISIBLE); @@ -697,28 +695,25 @@ public class TrackDetailsMenu { xAxis.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - final PopupMenu optionsMenu = new PopupMenu(v.getContext(), v); - DirectionsDialogs.setupPopUpMenuIcon(optionsMenu); - for (final GPXDataSetAxisType type : GPXDataSetAxisType.values()) { - MenuItem menuItem = optionsMenu.getMenu() - .add(type.getStringId()).setIcon(type.getImageDrawable(app)); - menuItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { - @Override - public boolean onMenuItemClick(MenuItem mItem) { - GpxDisplayItem gpxItem = getGpxItem(); - if (gpxItem != null) { - gpxItem.chartAxisType = type; - gpxItem.chartHighlightPos = -1; - gpxItem.chartMatrix = null; - update(); - return true; - } else { - return false; - } - } - }); + Context themedContext = UiUtilities.getThemedContext(v.getContext(), true); + List items = new ArrayList<>(); + for (GPXDataSetAxisType type : GPXDataSetAxisType.values()) { + items.add(new SimplePopUpMenuItemAdapter.SimplePopUpMenuItem( + app.getString(type.getStringId()), type.getImageDrawable(app))); } - optionsMenu.show(); + UiUtilities.createListPopupWindow(themedContext, + v, items, new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + GpxDisplayItem gpxItem = getGpxItem(); + if (gpxItem != null) { + gpxItem.chartAxisType = GPXDataSetAxisType.values()[position]; + gpxItem.chartHighlightPos = -1; + gpxItem.chartMatrix = null; + update(); + } + } + }).show(); } }); xAxisArrow.setVisibility(View.VISIBLE); From 7ba03d94e4396bb7c66f6a8f1a5b3d7df6a92e79 Mon Sep 17 00:00:00 2001 From: Nazar-Kutz Date: Fri, 12 Jun 2020 12:23:16 +0300 Subject: [PATCH 6/8] RTL - Step 3 (Fixes) --- OsmAnd/src/net/osmand/AndroidUtils.java | 11 +++++++ .../plus/SimplePopUpMenuItemAdapter.java | 6 ++-- OsmAnd/src/net/osmand/plus/UiUtilities.java | 32 +++++++++---------- .../other/TrackDetailsMenu.java | 25 ++++++++------- .../other/TrackDetailsMenuFragment.java | 4 +-- .../ShowAlongTheRouteBottomSheet.java | 5 ++- .../search/QuickSearchDialogFragment.java | 3 +- 7 files changed, 49 insertions(+), 37 deletions(-) diff --git a/OsmAnd/src/net/osmand/AndroidUtils.java b/OsmAnd/src/net/osmand/AndroidUtils.java index 3c8eed9206..3a91f288ef 100644 --- a/OsmAnd/src/net/osmand/AndroidUtils.java +++ b/OsmAnd/src/net/osmand/AndroidUtils.java @@ -425,6 +425,17 @@ public class AndroidUtils { : ctx.getResources().getColor(R.color.text_color_secondary_light)); } + public static int getPopupMenuWidth(Context ctx, float textSize, List titles) { + int width = 0; + for (String title : titles) { + int titleWidth = getTextWidth(textSize, title); + if (titleWidth > width) { + width = titleWidth; + } + } + return width + dpToPx(ctx, 34); + } + public static int getTextWidth(float textSize, String text) { Paint paint = new Paint(); paint.setTextSize(textSize); diff --git a/OsmAnd/src/net/osmand/plus/SimplePopUpMenuItemAdapter.java b/OsmAnd/src/net/osmand/plus/SimplePopUpMenuItemAdapter.java index 3dadf98f60..406f3d265c 100644 --- a/OsmAnd/src/net/osmand/plus/SimplePopUpMenuItemAdapter.java +++ b/OsmAnd/src/net/osmand/plus/SimplePopUpMenuItemAdapter.java @@ -12,10 +12,12 @@ import android.widget.TextView; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import static net.osmand.plus.SimplePopUpMenuItemAdapter.SimplePopUpMenuItem; + import java.util.List; public class SimplePopUpMenuItemAdapter - extends ArrayAdapter { + extends ArrayAdapter { private List items; @@ -35,7 +37,7 @@ public class SimplePopUpMenuItemAdapter public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) { LayoutInflater inflater = LayoutInflater.from(getContext()); if (convertView == null) { - convertView = inflater.inflate(R.layout.popup_menu_item, null); + convertView = inflater.inflate(R.layout.popup_menu_item, parent, false); } SimplePopUpMenuItem item = getItem(position); if (item != null) { diff --git a/OsmAnd/src/net/osmand/plus/UiUtilities.java b/OsmAnd/src/net/osmand/plus/UiUtilities.java index d93bdbc6dc..bef961ce16 100644 --- a/OsmAnd/src/net/osmand/plus/UiUtilities.java +++ b/OsmAnd/src/net/osmand/plus/UiUtilities.java @@ -55,10 +55,13 @@ import net.osmand.plus.widgets.TextViewEx; import org.apache.commons.logging.Log; +import java.util.ArrayList; import java.util.List; import gnu.trove.map.hash.TLongObjectHashMap; +import static net.osmand.plus.SimplePopUpMenuItemAdapter.SimplePopUpMenuItem; + public class UiUtilities { private static final Log LOG = PlatformUtil.getLog(UiUtilities.class); @@ -363,15 +366,15 @@ public class UiUtilities { } return screenOrientation; } - + public static void setupSnackbar(Snackbar snackbar, boolean nightMode) { setupSnackbar(snackbar, nightMode, null, null, null, null); } - + public static void setupSnackbar(Snackbar snackbar, boolean nightMode, Integer maxLines) { setupSnackbar(snackbar, nightMode, null, null, null, maxLines); } - + public static void setupSnackbar(Snackbar snackbar, boolean nightMode, @ColorRes Integer backgroundColor, @ColorRes Integer messageColor, @ColorRes Integer actionColor, Integer maxLines) { if (snackbar == null) { @@ -556,7 +559,7 @@ public class UiUtilities { // label behavior slider.setLabelBehavior(Slider.LABEL_GONE); } - + public static void setupDialogButton(boolean nightMode, View buttonView, DialogButtonType buttonType, @StringRes int buttonTextId) { setupDialogButton(nightMode, buttonView, buttonType, buttonView.getContext().getString(buttonTextId)); } @@ -651,23 +654,18 @@ public class UiUtilities { } } - public static ListPopupWindow createListPopupWindow(Context themedCtx, View v, - List items, + public static ListPopupWindow createListPopupWindow(Context themedCtx, + View v, int minWidth, + List items, final AdapterView.OnItemClickListener listener) { - int contentPadding = themedCtx.getResources().getDimensionPixelSize(R.dimen.content_padding); int contentPaddingHalf = themedCtx.getResources().getDimensionPixelSize(R.dimen.content_padding_half); + int defaultListTextSize = themedCtx.getResources().getDimensionPixelSize(R.dimen.default_list_text_size); - Paint paint = new Paint(); - paint.setTextSize(themedCtx.getResources().getDimensionPixelSize(R.dimen.default_list_text_size)); - CharSequence longestTitle = ""; - for (SimplePopUpMenuItemAdapter.SimplePopUpMenuItem item : items) { - if (item.getTitle().length() > longestTitle.length()) { - longestTitle = item.getTitle(); - } + List titles = new ArrayList<>(); + for (SimplePopUpMenuItem item : items) { + titles.add(String.valueOf(item.getTitle())); } - float titleTextWidth = paint.measureText(longestTitle.toString()); - float itemWidth = titleTextWidth + contentPadding; - float minWidth = v.getWidth(); + float itemWidth = AndroidUtils.getPopupMenuWidth(themedCtx, defaultListTextSize, titles); SimplePopUpMenuItemAdapter adapter = new SimplePopUpMenuItemAdapter(themedCtx, R.layout.popup_menu_item, items); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenu.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenu.java index 39e5dd1bac..4e19df5fcf 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenu.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenu.java @@ -32,7 +32,6 @@ import net.osmand.data.RotatedTileBox; import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; -import net.osmand.plus.SimplePopUpMenuItemAdapter; import net.osmand.plus.UiUtilities; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.helpers.AndroidUiHelper; @@ -48,6 +47,8 @@ import java.util.Collections; import java.util.Comparator; import java.util.List; +import static net.osmand.plus.SimplePopUpMenuItemAdapter.SimplePopUpMenuItem; + public class TrackDetailsMenu { @Nullable @@ -490,6 +491,9 @@ public class TrackDetailsMenu { if (mapActivity == null || gpxItem == null) { return; } + final OsmandApplication app = mapActivity.getMyApplication(); + final UiUtilities ic = app.getUIUtilities(); + final boolean nightMode = app.getDaynightHelper().isNightModeForMapControls(); GPXTrackAnalysis analysis = gpxItem.analysis; if (analysis == null || gpxItem.chartTypes == null) { parentView.setVisibility(View.GONE); @@ -576,9 +580,6 @@ public class TrackDetailsMenu { } }); - final OsmandApplication app = mapActivity.getMyApplication(); - final UiUtilities ic = app.getUIUtilities(); - GpxUiHelper.setupGPXChart(app, chart, 4); List dataSets = new ArrayList<>(); @@ -652,15 +653,15 @@ public class TrackDetailsMenu { yAxis.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - Context themedContext = UiUtilities.getThemedContext(v.getContext(), true); - List items = new ArrayList<>(); + Context themedContext = UiUtilities.getThemedContext(v.getContext(), nightMode); + List items = new ArrayList<>(); for (GPXDataSetType[] types : availableTypes) { - items.add(new SimplePopUpMenuItemAdapter.SimplePopUpMenuItem( + items.add(new SimplePopUpMenuItem( GPXDataSetType.getName(app, types), GPXDataSetType.getImageDrawable(app, types))); } UiUtilities.createListPopupWindow( - themedContext, v, items, new AdapterView.OnItemClickListener() { + themedContext, v, v.getWidth(), items, new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView parent, View view, int position, long id) { GpxDisplayItem gpxItem = getGpxItem(); @@ -695,14 +696,14 @@ public class TrackDetailsMenu { xAxis.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - Context themedContext = UiUtilities.getThemedContext(v.getContext(), true); - List items = new ArrayList<>(); + Context themedContext = UiUtilities.getThemedContext(v.getContext(), nightMode); + List items = new ArrayList<>(); for (GPXDataSetAxisType type : GPXDataSetAxisType.values()) { - items.add(new SimplePopUpMenuItemAdapter.SimplePopUpMenuItem( + items.add(new SimplePopUpMenuItem( app.getString(type.getStringId()), type.getImageDrawable(app))); } UiUtilities.createListPopupWindow(themedContext, - v, items, new AdapterView.OnItemClickListener() { + v, v.getWidth(), items, new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView parent, View view, int position, long id) { GpxDisplayItem gpxItem = getGpxItem(); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenuFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenuFragment.java index fad7483291..843992ec9f 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenuFragment.java @@ -30,6 +30,7 @@ public class TrackDetailsMenuFragment extends BaseOsmAndFragment { private TrackDetailsMenu menu; private View mainView; private boolean paused = true; + private boolean nightMode; @Nullable private MapActivity getMapActivity() { @@ -46,7 +47,7 @@ public class TrackDetailsMenuFragment extends BaseOsmAndFragment { Bundle savedInstanceState) { MapActivity mapActivity = requireMapActivity(); menu = mapActivity.getTrackDetailsMenu(); - boolean nightMode = mapActivity.getMyApplication().getDaynightHelper().isNightModeForMapControls(); + nightMode = mapActivity.getMyApplication().getDaynightHelper().isNightModeForMapControls(); ContextThemeWrapper context = new ContextThemeWrapper(mapActivity, !nightMode ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme); View view = LayoutInflater.from(context).inflate(R.layout.track_details, container, false); @@ -192,7 +193,6 @@ public class TrackDetailsMenuFragment extends BaseOsmAndFragment { if (ctx != null) { boolean portraitMode = AndroidUiHelper.isOrientationPortrait(ctx); boolean landscapeLayout = !portraitMode; - boolean nightMode = ctx.getMyApplication().getDaynightHelper().isNightModeForMapControls(); if (!landscapeLayout) { AndroidUtils.setBackground(ctx, mainView, nightMode, R.drawable.bg_bottom_menu_light, R.drawable.bg_bottom_menu_dark); } else { diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/ShowAlongTheRouteBottomSheet.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/ShowAlongTheRouteBottomSheet.java index 34c655ae0b..7272b7a2ea 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/ShowAlongTheRouteBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/ShowAlongTheRouteBottomSheet.java @@ -81,9 +81,8 @@ public class ShowAlongTheRouteBottomSheet extends MenuBottomSheetDialogFragment } int expandType = args.getInt(EXPAND_TYPE_KEY, -1); - final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; - final View titleView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), - R.layout.bottom_sheet_item_toolbar_title, null); + final View titleView = UiUtilities.getInflater(ctx, nightMode) + .inflate(R.layout.bottom_sheet_item_toolbar_title, null); TextView textView = (TextView) titleView.findViewById(R.id.title); textView.setText(R.string.show_along_the_route); diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java index 0ef39d0299..75664e9f5d 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java @@ -173,6 +173,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC private SearchUICore searchUICore; private SearchResultListener defaultResultListener; private String searchQuery; + private boolean nightMode; private LatLon centerLatLon; private net.osmand.Location location = null; @@ -229,6 +230,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); app = getMyApplication(); + nightMode = !app.getSettings().isLightContent(); navigationInfo = new NavigationInfo(app); accessibilityAssistant = new AccessibilityAssistant(getActivity()); boolean isLightTheme = app.getSettings().OSMAND_THEME.get() == OsmandSettings.OSMAND_LIGHT_THEME; @@ -242,7 +244,6 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC Bundle savedInstanceState) { final MapActivity mapActivity = getMapActivity(); final View view = inflater.inflate(R.layout.search_dialog_fragment, container, false); - final boolean nightMode = !app.getSettings().isLightContent(); toolbarController = new QuickSearchToolbarController(); toolbarController.setOnBackButtonClickListener(new OnClickListener() { From 68336d36a7f05c44057c36f115ebc201ae395c79 Mon Sep 17 00:00:00 2001 From: Nazar-Kutz Date: Fri, 12 Jun 2020 12:43:13 +0300 Subject: [PATCH 7/8] RTL - Step 3 (Fixes 2) --- OsmAnd/src/net/osmand/AndroidUtils.java | 4 ++-- OsmAnd/src/net/osmand/plus/UiUtilities.java | 5 +++-- .../net/osmand/plus/search/QuickSearchDialogFragment.java | 1 - 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/OsmAnd/src/net/osmand/AndroidUtils.java b/OsmAnd/src/net/osmand/AndroidUtils.java index 3a91f288ef..36b8dee6d0 100644 --- a/OsmAnd/src/net/osmand/AndroidUtils.java +++ b/OsmAnd/src/net/osmand/AndroidUtils.java @@ -425,7 +425,7 @@ public class AndroidUtils { : ctx.getResources().getColor(R.color.text_color_secondary_light)); } - public static int getPopupMenuWidth(Context ctx, float textSize, List titles) { + public static int getTextWidth(Context ctx, float textSize, List titles) { int width = 0; for (String title : titles) { int titleWidth = getTextWidth(textSize, title); @@ -433,7 +433,7 @@ public class AndroidUtils { width = titleWidth; } } - return width + dpToPx(ctx, 34); + return width; } public static int getTextWidth(float textSize, String text) { diff --git a/OsmAnd/src/net/osmand/plus/UiUtilities.java b/OsmAnd/src/net/osmand/plus/UiUtilities.java index bef961ce16..38c36a9fc5 100644 --- a/OsmAnd/src/net/osmand/plus/UiUtilities.java +++ b/OsmAnd/src/net/osmand/plus/UiUtilities.java @@ -3,7 +3,6 @@ package net.osmand.plus; import android.content.Context; import android.content.res.ColorStateList; import android.graphics.Color; -import android.graphics.Paint; import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; import android.graphics.drawable.LayerDrawable; @@ -658,6 +657,7 @@ public class UiUtilities { View v, int minWidth, List items, final AdapterView.OnItemClickListener listener) { + int contentPadding = themedCtx.getResources().getDimensionPixelSize(R.dimen.content_padding); int contentPaddingHalf = themedCtx.getResources().getDimensionPixelSize(R.dimen.content_padding_half); int defaultListTextSize = themedCtx.getResources().getDimensionPixelSize(R.dimen.default_list_text_size); @@ -665,7 +665,8 @@ public class UiUtilities { for (SimplePopUpMenuItem item : items) { titles.add(String.valueOf(item.getTitle())); } - float itemWidth = AndroidUtils.getPopupMenuWidth(themedCtx, defaultListTextSize, titles); + float itemWidth = + AndroidUtils.getTextWidth(themedCtx, defaultListTextSize, titles) + contentPadding; SimplePopUpMenuItemAdapter adapter = new SimplePopUpMenuItemAdapter(themedCtx, R.layout.popup_menu_item, items); diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java index 75664e9f5d..7457667ceb 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java @@ -1212,7 +1212,6 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC if (SearchUICore.isDebugMode()) { LOG.info("UI >> Start loading categories"); } - final boolean nightMode = !app.getSettings().isLightContent(); SearchResultCollection res = searchUICore.shallowSearch(SearchAmenityTypesAPI.class, "", null); if (res != null) { List rows = new ArrayList<>(); From ec43a3b5309da75a88eb7b7d74d2ad2ae73a9caf Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Fri, 12 Jun 2020 15:46:21 +0300 Subject: [PATCH 8/8] Remove unnecessary changes --- OsmAnd/src/net/osmand/AndroidUtils.java | 2 +- OsmAnd/src/net/osmand/plus/UiUtilities.java | 3 +-- .../settings/bottomsheets/VehicleParametersBottomSheet.java | 1 - 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/OsmAnd/src/net/osmand/AndroidUtils.java b/OsmAnd/src/net/osmand/AndroidUtils.java index 36b8dee6d0..0c488b384c 100644 --- a/OsmAnd/src/net/osmand/AndroidUtils.java +++ b/OsmAnd/src/net/osmand/AndroidUtils.java @@ -425,7 +425,7 @@ public class AndroidUtils { : ctx.getResources().getColor(R.color.text_color_secondary_light)); } - public static int getTextWidth(Context ctx, float textSize, List titles) { + public static int getTextMaxWidth(float textSize, List titles) { int width = 0; for (String title : titles) { int titleWidth = getTextWidth(textSize, title); diff --git a/OsmAnd/src/net/osmand/plus/UiUtilities.java b/OsmAnd/src/net/osmand/plus/UiUtilities.java index 38c36a9fc5..588cc66c55 100644 --- a/OsmAnd/src/net/osmand/plus/UiUtilities.java +++ b/OsmAnd/src/net/osmand/plus/UiUtilities.java @@ -665,8 +665,7 @@ public class UiUtilities { for (SimplePopUpMenuItem item : items) { titles.add(String.valueOf(item.getTitle())); } - float itemWidth = - AndroidUtils.getTextWidth(themedCtx, defaultListTextSize, titles) + contentPadding; + float itemWidth = AndroidUtils.getTextMaxWidth(defaultListTextSize, titles) + contentPadding; SimplePopUpMenuItemAdapter adapter = new SimplePopUpMenuItemAdapter(themedCtx, R.layout.popup_menu_item, items); diff --git a/OsmAnd/src/net/osmand/plus/settings/bottomsheets/VehicleParametersBottomSheet.java b/OsmAnd/src/net/osmand/plus/settings/bottomsheets/VehicleParametersBottomSheet.java index 2e50c74ae0..d452a4c7b0 100644 --- a/OsmAnd/src/net/osmand/plus/settings/bottomsheets/VehicleParametersBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/settings/bottomsheets/VehicleParametersBottomSheet.java @@ -9,7 +9,6 @@ import android.widget.TextView; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.core.content.ContextCompat; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; import androidx.recyclerview.widget.RecyclerView;