From ffb50f1c7822c229723c06fef6b1efd2aa805e65 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Mon, 30 Mar 2020 12:42:54 +0300 Subject: [PATCH] Fix UI, fix rtl, fix icon size --- OsmAnd/assets/poi_categories.json | 25 ----------- OsmAnd/res/layout/favorites_list_item.xml | 19 ++++---- .../res/layout/point_editor_fragment_new.xml | 9 ++-- OsmAnd/res/values/styles.xml | 2 + .../plus/base/FavoriteImageDrawable.java | 23 +++++++--- .../editors/PointEditorFragmentNew.java | 16 ++++++- .../editors/WptPtEditorFragmentNew.java | 10 +++-- .../net/osmand/plus/widgets/FlowLayout.java | 43 +++++++++++-------- 8 files changed, 81 insertions(+), 66 deletions(-) delete mode 100644 OsmAnd/assets/poi_categories.json diff --git a/OsmAnd/assets/poi_categories.json b/OsmAnd/assets/poi_categories.json deleted file mode 100644 index f386828f4d..0000000000 --- a/OsmAnd/assets/poi_categories.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "categories": { - "special": { - "icons": [ - "special_star", - "special_star_stroked", - "special_marker", - "special_flag_stroke", - "special_house", - "special_building" - ] - }, - "amenity": { - "icons": [ - "amenity_bar", - "amenity_cafe", - "amenity_atm", - "amenity_biergarten", - "amenity_cinema", - "amenity_fire_station", - "amenity_parking" - ] - } - } -} \ No newline at end of file diff --git a/OsmAnd/res/layout/favorites_list_item.xml b/OsmAnd/res/layout/favorites_list_item.xml index d54fb5c371..7ce1d0f3f2 100644 --- a/OsmAnd/res/layout/favorites_list_item.xml +++ b/OsmAnd/res/layout/favorites_list_item.xml @@ -49,11 +49,12 @@ + android:scaleType="center" + android:layout_marginRight="@dimen/list_header_settings_top_margin" + android:layout_marginEnd="@dimen/list_header_settings_top_margin" /> + android:paddingEnd="@dimen/list_content_padding"> + android:layout_marginStart="2dp" /> + android:layout_marginStart="4dp" /> + android:layout_marginStart="2dp" /> @@ -129,7 +130,7 @@ android:background="?attr/dashboard_button" android:src="@drawable/ic_action_test_light" android:visibility="gone" - android:layout_marginStart="@dimen/dashFavIconMargin" /> + android:layout_marginStart="@dimen/dashFavIconMargin" /> @@ -134,7 +135,7 @@ android:layout_height="wrap_content" android:inputType="textMultiLine" android:maxLines="4" - android:minHeight="50dp" + android:minHeight="60dp" android:paddingStart="12dp" android:paddingLeft="12dp" android:paddingRight="12dp" diff --git a/OsmAnd/res/values/styles.xml b/OsmAnd/res/values/styles.xml index e458172437..c3e1eeb4d4 100644 --- a/OsmAnd/res/values/styles.xml +++ b/OsmAnd/res/values/styles.xml @@ -101,11 +101,13 @@ diff --git a/OsmAnd/src/net/osmand/plus/base/FavoriteImageDrawable.java b/OsmAnd/src/net/osmand/plus/base/FavoriteImageDrawable.java index d4e908a195..490e7c538f 100644 --- a/OsmAnd/src/net/osmand/plus/base/FavoriteImageDrawable.java +++ b/OsmAnd/src/net/osmand/plus/base/FavoriteImageDrawable.java @@ -8,7 +8,6 @@ import android.graphics.Canvas; import android.graphics.Color; import android.graphics.ColorFilter; import android.graphics.Paint; -import android.graphics.PixelFormat; import android.graphics.PorterDuff; import android.graphics.PorterDuffColorFilter; import android.graphics.Rect; @@ -98,9 +97,11 @@ public class FavoriteImageDrawable extends Drawable { super.onBoundsChange(bounds); Rect bs = new Rect(bounds); if (!withShadow && !synced) { - uiBackgroundIcon.setBounds(bounds); - bs.inset(bs.width() / 5, bs.height() / 5); - uiListIcon.setBounds(bs); + uiBackgroundIcon.setBounds(0, 0, uiBackgroundIcon.getIntrinsicWidth(), uiBackgroundIcon.getIntrinsicHeight()); + int offsetX = bounds.centerX() - uiListIcon.getIntrinsicWidth() / 2; + int offsetY = bounds.centerY() - uiListIcon.getIntrinsicHeight() / 2; + uiListIcon.setBounds(offsetX, offsetY, uiListIcon.getIntrinsicWidth() + offsetX, + uiListIcon.getIntrinsicHeight() + offsetY); } else if (withShadow) { bs.inset(bs.width() / 3, bs.height() / 3); favIcon.setBounds(bs); @@ -109,12 +110,22 @@ public class FavoriteImageDrawable extends Drawable { @Override public int getIntrinsicHeight() { - return synced ? syncedShadow.getHeight() : favBackgroundCenter.getHeight(); + if (synced) { + return syncedShadow.getHeight(); + } else if (withShadow) { + return favBackgroundCenter.getHeight(); + } + return uiBackgroundIcon.getIntrinsicHeight(); } @Override public int getIntrinsicWidth() { - return synced ? syncedShadow.getWidth() : favBackgroundCenter.getWidth(); + if (synced) { + return syncedShadow.getWidth(); + } else if (withShadow) { + return favBackgroundCenter.getWidth(); + } + return uiBackgroundIcon.getIntrinsicWidth(); } @Override diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragmentNew.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragmentNew.java index 61136d3c7d..d1f00c9a77 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragmentNew.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragmentNew.java @@ -105,7 +105,7 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment { toolbar.setBackgroundColor(ContextCompat.getColor(requireContext(), nightMode ? R.color.app_bar_color_dark : R.color.list_background_color_light)); toolbar.setTitle(getToolbarTitle()); - Drawable icBack = app.getUIUtilities().getIcon(R.drawable.ic_arrow_back, + Drawable icBack = app.getUIUtilities().getIcon(AndroidUtils.getNavigationIconResId(app), nightMode ? R.color.active_buttons_and_links_text_dark : R.color.description_font_and_bottom_sheet_icons); toolbar.setNavigationIcon(icBack); toolbar.setNavigationContentDescription(R.string.access_shared_string_navigate_up); @@ -471,9 +471,15 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment { oldIcon.findViewById(R.id.outline).setVisibility(View.INVISIBLE); ImageView background = oldIcon.findViewById(R.id.background); setIconSelectorBackground(background); + ImageView iconView = oldIcon.findViewById(R.id.icon); + iconView.setImageDrawable(UiUtilities.tintDrawable(ContextCompat.getDrawable(app, selectedIcon), + ContextCompat.getColor(app, R.color.icon_color_default_light))); } View icon = rootView.findViewWithTag(iconRes); if (icon != null) { + ImageView iconView = icon.findViewById(R.id.icon); + iconView.setImageDrawable(UiUtilities.tintDrawable(ContextCompat.getDrawable(app, iconRes), + ContextCompat.getColor(app, R.color.color_white))); icon.findViewById(R.id.outline).setVisibility(View.VISIBLE); ImageView backgroundCircle = icon.findViewById(R.id.background); AndroidUtils.setBackground(backgroundCircle, @@ -760,6 +766,14 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment { Drawable iconAdd = app.getUIUtilities().getIcon(R.drawable.ic_action_add, activeColorResId); ((ImageView) view.findViewById(R.id.groupIcon)).setImageDrawable(iconAdd); ((TextView) view.findViewById(R.id.groupName)).setText(requireMyApplication().getString(R.string.add_group)); + GradientDrawable rectContourDrawable = (GradientDrawable) ContextCompat.getDrawable(app, + R.drawable.bg_select_group_button_outline); + if (rectContourDrawable != null) { + int strokeColor = ContextCompat.getColor(app, nightMode ? R.color.stroked_buttons_and_links_outline_dark + : R.color.stroked_buttons_and_links_outline_light); + rectContourDrawable.setStroke(AndroidUtils.dpToPx(app, 1), strokeColor); + ((ImageView) view.findViewById(R.id.outlineRect)).setImageDrawable(rectContourDrawable); + } } ((TextView) view.findViewById(R.id.groupName)).setTextColor(getResources().getColor(activeColorResId)); return new GroupsViewHolder(view); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditorFragmentNew.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditorFragmentNew.java index a4b3d17dab..d61a47caad 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditorFragmentNew.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditorFragmentNew.java @@ -347,7 +347,7 @@ public class WptPtEditorFragmentNew extends PointEditorFragmentNew { if (categoriesMap != null) { categoriesMap.put(name, color); } - this.color = color; + this.color = this.color == 0 ? color : this.color; super.setCategory(name, color); } @@ -411,12 +411,16 @@ public class WptPtEditorFragmentNew extends PointEditorFragmentNew { @Override public int getDefaultColor() { - return 0; + return defaultColor; } @Override public int getPointColor() { - return color == 0 ? defaultColor : color; + if (color != 0) { + return color; + } else { + return getCategoryColor(getCategoryTextValue()); + } } @Override diff --git a/OsmAnd/src/net/osmand/plus/widgets/FlowLayout.java b/OsmAnd/src/net/osmand/plus/widgets/FlowLayout.java index 2c19103613..c59ebb37fa 100644 --- a/OsmAnd/src/net/osmand/plus/widgets/FlowLayout.java +++ b/OsmAnd/src/net/osmand/plus/widgets/FlowLayout.java @@ -1,19 +1,20 @@ package net.osmand.plus.widgets; import android.content.Context; +import android.os.Build; import android.util.AttributeSet; import android.view.View; import android.view.ViewGroup; - public class FlowLayout extends ViewGroup { private int line_height; + private boolean rtl = false; public static class LayoutParams extends ViewGroup.LayoutParams { - public final int horizontal_spacing; - public final int vertical_spacing; + final int horizontal_spacing; + final int vertical_spacing; /** * @param horizontal_spacing Pixels between items, horizontally @@ -36,24 +37,22 @@ public class FlowLayout extends ViewGroup { @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - assert (MeasureSpec.getMode(widthMeasureSpec) != MeasureSpec.UNSPECIFIED); + if ((MeasureSpec.getMode(widthMeasureSpec) == MeasureSpec.UNSPECIFIED)) throw new AssertionError(); final int width = MeasureSpec.getSize(widthMeasureSpec) - getPaddingLeft() - getPaddingRight(); int height = MeasureSpec.getSize(heightMeasureSpec) - getPaddingTop() - getPaddingBottom(); final int count = getChildCount(); int line_height = 0; - int xpos = getPaddingLeft(); int ypos = getPaddingTop(); - int childHeightMeasureSpec; + if (MeasureSpec.getMode(heightMeasureSpec) == MeasureSpec.AT_MOST) { childHeightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.AT_MOST); } else { childHeightMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED); } - for (int i = 0; i < count; i++) { final View child = getChildAt(i); if (child.getVisibility() != GONE) { @@ -61,20 +60,17 @@ public class FlowLayout extends ViewGroup { child.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.AT_MOST), childHeightMeasureSpec); final int childw = child.getMeasuredWidth(); line_height = Math.max(line_height, child.getMeasuredHeight() + lp.vertical_spacing); - if (xpos + childw > width) { xpos = getPaddingLeft(); ypos += line_height; } - xpos += childw + lp.horizontal_spacing; } } - this.line_height = line_height; + this.line_height = line_height; if (MeasureSpec.getMode(heightMeasureSpec) == MeasureSpec.UNSPECIFIED) { height = ypos + line_height; - } else if (MeasureSpec.getMode(heightMeasureSpec) == MeasureSpec.AT_MOST) { if (ypos + line_height < height) { height = ypos + line_height; @@ -95,23 +91,34 @@ public class FlowLayout extends ViewGroup { @Override protected void onLayout(boolean changed, int l, int t, int r, int b) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { + rtl = getLayoutDirection() == LAYOUT_DIRECTION_RTL; + } final int count = getChildCount(); final int width = r - l; - int xpos = getPaddingLeft(); + int xpos = rtl ? width - getPaddingRight() : getPaddingLeft(); int ypos = getPaddingTop(); - for (int i = 0; i < count; i++) { final View child = getChildAt(i); if (child.getVisibility() != GONE) { final int childw = child.getMeasuredWidth(); final int childh = child.getMeasuredHeight(); final LayoutParams lp = (LayoutParams) child.getLayoutParams(); - if (xpos + childw > width) { - xpos = getPaddingLeft(); - ypos += line_height; + if (rtl) { + if (xpos - childw < l) { + xpos = width - getPaddingRight(); + ypos += line_height; + } + child.layout(xpos - childw, ypos, xpos, ypos + childh); + xpos -= childw - lp.horizontal_spacing; + } else { + if (xpos + childw > width) { + xpos = getPaddingLeft(); + ypos += line_height; + } + child.layout(xpos, ypos, xpos + childw, ypos + childh); + xpos += childw + lp.horizontal_spacing; } - child.layout(xpos, ypos, xpos + childw, ypos + childh); - xpos += childw + lp.horizontal_spacing; } } }