From 050f9a190e1b153d399672718a990143231c7dd9 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Fri, 10 Nov 2017 12:46:23 +0200 Subject: [PATCH 1/4] Remove unnecessary TextView, fix icons; increase text size --- .../fragment_marker_options_bottom_sheet_dialog.xml | 11 ----------- .../mapmarkers/OptionsBottomSheetDialogFragment.java | 12 +++--------- .../src/net/osmand/plus/views/MapMarkersLayer.java | 2 +- 3 files changed, 4 insertions(+), 21 deletions(-) diff --git a/OsmAnd/res/layout/fragment_marker_options_bottom_sheet_dialog.xml b/OsmAnd/res/layout/fragment_marker_options_bottom_sheet_dialog.xml index d6ccfd5352..a2341f32ed 100644 --- a/OsmAnd/res/layout/fragment_marker_options_bottom_sheet_dialog.xml +++ b/OsmAnd/res/layout/fragment_marker_options_bottom_sheet_dialog.xml @@ -89,17 +89,6 @@ android:maxLines="1" android:text="@string/show_direction" android:textAppearance="@style/TextAppearance.ListItemTitle"/> - - Date: Fri, 10 Nov 2017 13:26:04 +0200 Subject: [PATCH 2/4] Add landscape layout --- .../fragment_direction_indication_dialog.xml | 413 ++++++++++++++++++ OsmAnd/res/values-large/sizes.xml | 2 + OsmAnd/res/values/sizes.xml | 4 +- .../DirectionIndicationDialogFragment.java | 39 +- 4 files changed, 439 insertions(+), 19 deletions(-) create mode 100644 OsmAnd/res/layout-land/fragment_direction_indication_dialog.xml diff --git a/OsmAnd/res/layout-land/fragment_direction_indication_dialog.xml b/OsmAnd/res/layout-land/fragment_direction_indication_dialog.xml new file mode 100644 index 0000000000..c31d3c99ff --- /dev/null +++ b/OsmAnd/res/layout-land/fragment_direction_indication_dialog.xml @@ -0,0 +1,413 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/OsmAnd/res/values-large/sizes.xml b/OsmAnd/res/values-large/sizes.xml index cbc1ce5530..04cc37505e 100644 --- a/OsmAnd/res/values-large/sizes.xml +++ b/OsmAnd/res/values-large/sizes.xml @@ -127,6 +127,8 @@ 15dp 84dp + 354dp + 102dp 330dp 105dp diff --git a/OsmAnd/res/values/sizes.xml b/OsmAnd/res/values/sizes.xml index 18dce59e43..bf63973a07 100644 --- a/OsmAnd/res/values/sizes.xml +++ b/OsmAnd/res/values/sizes.xml @@ -189,7 +189,9 @@ 64dp 10dp 56dp - + + 236dp + 68dp 220dp 70dp diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/DirectionIndicationDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/DirectionIndicationDialogFragment.java index 926f5edc76..a2e0096ebc 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/DirectionIndicationDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/DirectionIndicationDialogFragment.java @@ -34,6 +34,7 @@ import net.osmand.plus.OsmandSettings.OsmandPreference; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.base.BaseOsmAndDialogFragment; +import net.osmand.plus.helpers.AndroidUiHelper; import java.util.LinkedList; @@ -73,30 +74,32 @@ public class DirectionIndicationDialogFragment extends BaseOsmAndDialogFragment appModeTv.setText(appMode.getStringResource()); appModeTv.setCompoundDrawablesWithIntrinsicBounds(null, null, getIconsCache().getIcon(appMode.getSmallIconDark()), null); - ((ObservableScrollView) mainView.findViewById(R.id.scroll_view)).setScrollViewCallbacks(new ObservableScrollViewCallbacks() { - @Override - public void onScrollChanged(int scrollY, boolean firstScroll, boolean dragging) { - if (scrollY >= helpImgHeight) { - if (!shadowVisible) { - mainView.findViewById(R.id.app_bar_shadow).setVisibility(View.VISIBLE); - shadowVisible = true; + if (AndroidUiHelper.isOrientationPortrait(getActivity())) { + ((ObservableScrollView) mainView.findViewById(R.id.scroll_view)).setScrollViewCallbacks(new ObservableScrollViewCallbacks() { + @Override + public void onScrollChanged(int scrollY, boolean firstScroll, boolean dragging) { + if (scrollY >= helpImgHeight) { + if (!shadowVisible) { + mainView.findViewById(R.id.app_bar_shadow).setVisibility(View.VISIBLE); + shadowVisible = true; + } + } else if (shadowVisible) { + mainView.findViewById(R.id.app_bar_shadow).setVisibility(View.GONE); + shadowVisible = false; } - } else if (shadowVisible) { - mainView.findViewById(R.id.app_bar_shadow).setVisibility(View.GONE); - shadowVisible = false; } - } - @Override - public void onDownMotionEvent() { + @Override + public void onDownMotionEvent() { - } + } - @Override - public void onUpOrCancelMotionEvent(ScrollState scrollState) { + @Override + public void onUpOrCancelMotionEvent(ScrollState scrollState) { - } - }); + } + }); + } updateHelpImage(); From c95d234c8a03972ce2e3fedab19d55bf8585c7de Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Fri, 10 Nov 2017 15:32:34 +0200 Subject: [PATCH 3/4] Fix popup menu --- .../DirectionIndicationDialogFragment.java | 68 +++++++++++-------- 1 file changed, 39 insertions(+), 29 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/DirectionIndicationDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/DirectionIndicationDialogFragment.java index a2e0096ebc..5346b74308 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/DirectionIndicationDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/DirectionIndicationDialogFragment.java @@ -2,24 +2,25 @@ package net.osmand.plus.mapmarkers; import android.app.Activity; import android.content.res.ColorStateList; +import android.graphics.Paint; import android.graphics.drawable.Drawable; import android.graphics.drawable.LayerDrawable; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.content.ContextCompat; import android.support.v4.widget.CompoundButtonCompat; +import android.support.v7.widget.ListPopupWindow; import android.support.v7.widget.Toolbar; import android.text.SpannableString; import android.text.style.ForegroundColorSpan; +import android.view.Gravity; import android.view.LayoutInflater; -import android.view.Menu; -import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; import android.widget.CompoundButton; import android.widget.ImageView; -import android.widget.PopupMenu; -import android.widget.PopupMenu.OnMenuItemClickListener; import android.widget.RadioButton; import android.widget.TextView; @@ -27,6 +28,7 @@ import com.github.ksoichiro.android.observablescrollview.ObservableScrollView; import com.github.ksoichiro.android.observablescrollview.ObservableScrollViewCallbacks; import com.github.ksoichiro.android.observablescrollview.ScrollState; +import net.osmand.AndroidUtils; import net.osmand.plus.ApplicationMode; import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings.MapMarkersMode; @@ -109,26 +111,28 @@ public class DirectionIndicationDialogFragment extends BaseOsmAndDialogFragment menuTv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - int count = settings.DISPLAYED_MARKERS_WIDGETS_COUNT.get(); - PopupMenu popupMenu = new PopupMenu(getActivity(), menuTv); - Menu menu = popupMenu.getMenu(); - popupMenu.getMenuInflater().inflate(R.menu.active_markers_menu, menu); - setupActiveMenuItem(menu.findItem(count == 1 ? R.id.action_one : R.id.action_two)); - popupMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() { + CharSequence[] titles = getMenuTitles(); + Paint paint = new Paint(); + paint.setTextSize(getResources().getDimensionPixelSize(R.dimen.default_list_text_size)); + float titleTextWidth = Math.max(paint.measureText(titles[0].toString()), paint.measureText(titles[1].toString())); + float itemWidth = titleTextWidth + AndroidUtils.dpToPx(getActivity(), 32); + float minWidth = AndroidUtils.dpToPx(getActivity(), 100); + final ListPopupWindow listPopupWindow = new ListPopupWindow(getActivity()); + listPopupWindow.setAnchorView(menuTv); + listPopupWindow.setContentWidth((int) (Math.max(itemWidth, minWidth))); + listPopupWindow.setDropDownGravity(Gravity.END | Gravity.TOP); + listPopupWindow.setHorizontalOffset(AndroidUtils.dpToPx(getActivity(), 8)); + listPopupWindow.setVerticalOffset(-menuTv.getHeight()); + listPopupWindow.setModal(true); + listPopupWindow.setAdapter(new ArrayAdapter<>(getActivity(), R.layout.popup_list_text_item, titles)); + listPopupWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override - public boolean onMenuItemClick(MenuItem item) { - switch (item.getItemId()) { - case R.id.action_one: - updateDisplayedMarkersCount(1); - return true; - case R.id.action_two: - updateDisplayedMarkersCount(2); - return true; - } - return false; + public void onItemClick(AdapterView parent, View view, int position, long id) { + updateDisplayedMarkersCount(position == 0 ? 1 : 2); + listPopupWindow.dismiss(); } }); - popupMenu.show(); + listPopupWindow.show(); } }); @@ -194,6 +198,20 @@ public class DirectionIndicationDialogFragment extends BaseOsmAndDialogFragment return null; } + private CharSequence[] getMenuTitles() { + if (getSettings().DISPLAYED_MARKERS_WIDGETS_COUNT.get() == 1) { + return new CharSequence[]{getActiveString(R.string.shared_string_one), getString(R.string.shared_string_two)}; + } + return new CharSequence[]{getString(R.string.shared_string_one), getActiveString(R.string.shared_string_two)}; + } + + private SpannableString getActiveString(int id) { + SpannableString res = new SpannableString(getString(id)); + res.setSpan(new ForegroundColorSpan(ContextCompat.getColor(getActivity(), getSettings().isLightContent() + ? R.color.dashboard_blue : R.color.osmand_orange)), 0, res.length(), 0); + return res; + } + private void updateHelpImage() { OsmandSettings settings = getSettings(); int count = settings.DISPLAYED_MARKERS_WIDGETS_COUNT.get(); @@ -273,14 +291,6 @@ public class DirectionIndicationDialogFragment extends BaseOsmAndDialogFragment ? R.drawable.img_help_markers_direction_device_day : R.drawable.img_help_markers_direction_device_night); } - private void setupActiveMenuItem(MenuItem item) { - int stringId = item.getItemId() == R.id.action_one ? R.string.shared_string_one : R.string.shared_string_two; - SpannableString title = new SpannableString(getString(stringId)); - title.setSpan(new ForegroundColorSpan(ContextCompat.getColor(getActivity(), getSettings().isLightContent() - ? R.color.dashboard_blue : R.color.osmand_orange)), 0, title.length(), 0); - item.setTitle(title); - } - private Drawable getIconBackground(boolean active) { return active ? getIcon(R.drawable.ic_action_device_top, R.color.dashboard_blue) : getContentIcon(R.drawable.ic_action_device_top); From c08ef7a60be99cfcfce3034afa95fae5c4d277ca Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Fri, 10 Nov 2017 16:57:18 +0200 Subject: [PATCH 4/4] Extract constants to resources --- OsmAnd/res/values/sizes.xml | 3 +++ .../net/osmand/plus/views/MapMarkersLayer.java | 17 ++++++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/OsmAnd/res/values/sizes.xml b/OsmAnd/res/values/sizes.xml index 4012fb9081..0c9d3c1a12 100644 --- a/OsmAnd/res/values/sizes.xml +++ b/OsmAnd/res/values/sizes.xml @@ -143,6 +143,9 @@ 150dp 128dp + + 14sp + 6dp 42dp 30dp diff --git a/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java b/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java index 9769c66bc5..cfb8acd1e1 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java @@ -50,8 +50,6 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi private static final long USE_FINGER_LOCATION_DELAY = 1000; private static final int MAP_REFRESH_MESSAGE = OsmAndConstants.UI_HANDLER_MAP_VIEW + 6; protected static final int DIST_TO_SHOW = 80; - private static final int TEXT_SIZE = 14; - private static final int VERTICAL_OFFSET = 10; private final MapActivity map; private OsmandMapTileView view; @@ -84,6 +82,9 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi private final RenderingLineAttributes planRouteAttrs = new RenderingLineAttributes("markerPlanRouteline"); private TrkSegment route; + private float textSize; + private int verticalOffset; + private TIntArrayList tx = new TIntArrayList(); private TIntArrayList ty = new TIntArrayList(); private Path linePath = new Path(); @@ -146,6 +147,9 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi widgetsFactory = new MapMarkersWidgetsFactory(map); contextMenuLayer = view.getLayerByClass(ContextMenuLayer.class); + + textSize = map.getResources().getDimensionPixelSize(R.dimen.guide_line_text_size); + verticalOffset = map.getResources().getDimensionPixelSize(R.dimen.guide_line_vertical_offset); } private Paint createPaintDest(int colorId) { @@ -239,7 +243,6 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi } if (map.getMyApplication().getSettings().SHOW_LINES_TO_FIRST_MARKERS.get() && myLoc != null) { - float textSize = TEXT_SIZE * map.getResources().getDisplayMetrics().density * map.getMyApplication().getSettings().TEXT_SCALE.get(); textAttrs.paint.setTextSize(textSize); textAttrs.paint2.setTextSize(textSize); @@ -292,12 +295,12 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi canvas.drawPath(linePath, lineAttrs.paint); if (locX >= markerX) { canvas.rotate(180, pos[0], pos[1]); - canvas.drawTextOnPath(text, linePath, hOffset, bounds.height() + VERTICAL_OFFSET, textAttrs.paint2); - canvas.drawTextOnPath(text, linePath, hOffset, bounds.height() + VERTICAL_OFFSET, textAttrs.paint); + canvas.drawTextOnPath(text, linePath, hOffset, bounds.height() + verticalOffset, textAttrs.paint2); + canvas.drawTextOnPath(text, linePath, hOffset, bounds.height() + verticalOffset, textAttrs.paint); canvas.rotate(-180, pos[0], pos[1]); } else { - canvas.drawTextOnPath(text, linePath, hOffset, -VERTICAL_OFFSET, textAttrs.paint2); - canvas.drawTextOnPath(text, linePath, hOffset, -VERTICAL_OFFSET, textAttrs.paint); + canvas.drawTextOnPath(text, linePath, hOffset, -verticalOffset, textAttrs.paint2); + canvas.drawTextOnPath(text, linePath, hOffset, -verticalOffset, textAttrs.paint); } canvas.rotate(tileBox.getRotate(), tileBox.getCenterPixelX(), tileBox.getCenterPixelY()); }