From cf8346187fba3eac2c4e82cb3db41905206ffa8f Mon Sep 17 00:00:00 2001
From: androiddevkotlin <64539346+androiddevkotlin@users.noreply.github.com>
Date: Thu, 4 Mar 2021 10:49:46 +0200
Subject: [PATCH] Review
---
OsmAnd/res/layout/colors_card.xml | 18 ++++---
OsmAnd/res/layout/point_editor_button.xml | 54 ++++++++-----------
.../res/layout/point_editor_fragment_new.xml | 7 ++-
.../editors/PointEditorFragmentNew.java | 12 +++--
.../cards/PublicTransportCard.java | 18 +++----
.../fragments/ProfileAppearanceFragment.java | 10 ++--
.../src/net/osmand/plus/track/ColorsCard.java | 47 ++++++++--------
.../net/osmand/plus/widgets/FlowLayout.java | 39 +++++++-------
8 files changed, 103 insertions(+), 102 deletions(-)
diff --git a/OsmAnd/res/layout/colors_card.xml b/OsmAnd/res/layout/colors_card.xml
index 5461aa1d9f..cade718b70 100644
--- a/OsmAnd/res/layout/colors_card.xml
+++ b/OsmAnd/res/layout/colors_card.xml
@@ -5,14 +5,20 @@
android:orientation="vertical">
+
+
+
+
\ No newline at end of file
diff --git a/OsmAnd/res/layout/point_editor_button.xml b/OsmAnd/res/layout/point_editor_button.xml
index a5677280e9..5b1a130ac1 100644
--- a/OsmAnd/res/layout/point_editor_button.xml
+++ b/OsmAnd/res/layout/point_editor_button.xml
@@ -2,40 +2,30 @@
+ android:layout_height="wrap_content">
-
+
-
+
-
+
-
-
diff --git a/OsmAnd/res/layout/point_editor_fragment_new.xml b/OsmAnd/res/layout/point_editor_fragment_new.xml
index 3e8657cd22..7339cbd460 100644
--- a/OsmAnd/res/layout/point_editor_fragment_new.xml
+++ b/OsmAnd/res/layout/point_editor_fragment_new.xml
@@ -449,12 +449,15 @@
osmand:typeface="@string/font_roboto_medium" />
-
+ android:layout_marginBottom="@dimen/content_padding_half"
+ android:orientation="horizontal"
+ android:layout_marginStart="@dimen/content_padding_small" />
MIN_WALK_TIME) {
- routesBadges.addView(createWalkRouteBadge(walkingSegment, badgesRowClickable), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing, false));
- routesBadges.addView(createArrow(), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing, false));
+ routesBadges.addView(createWalkRouteBadge(walkingSegment, badgesRowClickable), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing));
+ routesBadges.addView(createArrow(), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing));
}
} else if (s.walkDist > 0) {
double walkTime = getWalkTime(s.walkDist, routeResult.getWalkSpeed());
@@ -307,20 +307,20 @@ public class PublicTransportCard extends BaseCard {
} else {
start = this.startLocation;
}
- routesBadges.addView(createWalkRouteBadge(walkTime, start, end, badgesRowClickable), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing, false));
- routesBadges.addView(createArrow(), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing, false));
+ routesBadges.addView(createWalkRouteBadge(walkTime, start, end, badgesRowClickable), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing));
+ routesBadges.addView(createArrow(), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing));
}
}
- routesBadges.addView(createRouteBadge(s, badgesRowClickable), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing, false));
+ routesBadges.addView(createRouteBadge(s, badgesRowClickable), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing));
if (iterator.hasNext()) {
- routesBadges.addView(createArrow(), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing, false));
+ routesBadges.addView(createArrow(), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing));
} else {
walkingSegment = transportRoutingHelper.getWalkingRouteSegment(s, null);
if (walkingSegment != null) {
double walkTime = walkingSegment.getRoutingTime();
if (walkTime > MIN_WALK_TIME) {
- routesBadges.addView(createArrow(), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing, false));
- routesBadges.addView(createWalkRouteBadge(walkingSegment, badgesRowClickable), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing, false));
+ routesBadges.addView(createArrow(), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing));
+ routesBadges.addView(createWalkRouteBadge(walkingSegment, badgesRowClickable), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing));
}
} else {
double finishWalkDist = routeResult.getFinishWalkDist();
@@ -329,7 +329,7 @@ public class PublicTransportCard extends BaseCard {
if (walkTime > MIN_WALK_TIME) {
LatLon start = s.getEnd().getLocation();
LatLon end = this.endLocation;
- routesBadges.addView(createArrow(), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing, false));
+ routesBadges.addView(createArrow(), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing));
routesBadges.addView(createWalkRouteBadge(walkTime, start, end, badgesRowClickable));
}
}
diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/ProfileAppearanceFragment.java b/OsmAnd/src/net/osmand/plus/settings/fragments/ProfileAppearanceFragment.java
index 9b5a101e16..6bf120f61d 100644
--- a/OsmAnd/src/net/osmand/plus/settings/fragments/ProfileAppearanceFragment.java
+++ b/OsmAnd/src/net/osmand/plus/settings/fragments/ProfileAppearanceFragment.java
@@ -413,7 +413,8 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment implements O
colorItems.removeAllViews();
for (ProfileIconColors color : ProfileIconColors.values()) {
View colorItem = createColorItemView(color, colorItems);
- colorItems.addView(colorItem, new FlowLayout.LayoutParams(0, 0, true));
+ colorItems.addView(colorItem, new FlowLayout.LayoutParams(0, 0));
+ colorItems.setHorizontalAutoSpacing(true);
}
updateColorSelector(changedProfile.color);
} else if (ICON_ITEMS.equals(preference.getKey())) {
@@ -422,7 +423,8 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment implements O
ArrayList icons = ProfileIcons.getIcons();
for (int iconRes : icons) {
View iconItem = createIconItemView(iconRes, iconItems);
- iconItems.addView(iconItem, new FlowLayout.LayoutParams(0, 0,true));
+ iconItems.addView(iconItem, new FlowLayout.LayoutParams(0, 0));
+ iconItems.setHorizontalAutoSpacing(true);
}
setIconColor(changedProfile.iconRes);
} else if (LOCATION_ICON_ITEMS.equals(preference.getKey())) {
@@ -430,7 +432,7 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment implements O
locationIconItems.removeAllViews();
for (LocationIcon locationIcon : LocationIcon.values()) {
View iconItemView = createLocationIconView(locationIcon, locationIconItems);
- locationIconItems.addView(iconItemView, new FlowLayout.LayoutParams(0, 0, false));
+ locationIconItems.addView(iconItemView, new FlowLayout.LayoutParams(0, 0));
}
updateLocationIconSelector(changedProfile.locationIcon);
} else if (NAV_ICON_ITEMS.equals(preference.getKey())) {
@@ -438,7 +440,7 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment implements O
navIconItems.removeAllViews();
for (NavigationIcon navigationIcon : NavigationIcon.values()) {
View iconItemView = createNavigationIconView(navigationIcon, navIconItems);
- navIconItems.addView(iconItemView, new FlowLayout.LayoutParams(0, 0, false));
+ navIconItems.addView(iconItemView, new FlowLayout.LayoutParams(0, 0));
}
updateNavigationIconSelector(changedProfile.navigationIcon);
}
diff --git a/OsmAnd/src/net/osmand/plus/track/ColorsCard.java b/OsmAnd/src/net/osmand/plus/track/ColorsCard.java
index bbea36737c..8b74e0319b 100644
--- a/OsmAnd/src/net/osmand/plus/track/ColorsCard.java
+++ b/OsmAnd/src/net/osmand/plus/track/ColorsCard.java
@@ -3,9 +3,7 @@ package net.osmand.plus.track;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
-import android.view.ViewGroup;
import android.widget.ImageView;
-import android.widget.LinearLayout;
import androidx.annotation.ColorInt;
import androidx.annotation.NonNull;
@@ -22,6 +20,7 @@ import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.routepreparationmenu.cards.BaseCard;
import net.osmand.plus.track.CustomColorBottomSheet.ColorPickerListener;
import net.osmand.plus.widgets.FlowLayout;
+import net.osmand.plus.widgets.FlowLayout.LayoutParams;
import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log;
@@ -87,35 +86,41 @@ public class ColorsCard extends BaseCard implements ColorPickerListener {
@Override
protected void updateContent() {
createColorSelector();
- updateColorSelector(selectedColor, view);
+ updateColorSelector(selectedColor);
}
private void createColorSelector() {
- FlowLayout selectColor = view.findViewById(R.id.select_color);
- selectColor.removeAllViews();
+ FlowLayout selectCustomColor = view.findViewById(R.id.select_custom_color);
+ selectCustomColor.removeAllViews();
+ selectCustomColor.setHorizontalAutoSpacing(true);
+ int minimalPaddingBetweenIcon = app.getResources().getDimensionPixelSize(R.dimen.favorites_select_icon_button_right_padding);
for (int color : customColors) {
- selectColor.addView(createColorItemView(color, selectColor, true), new FlowLayout.LayoutParams(0, 0, true));
+ selectCustomColor.addView(createColorItemView(color, selectCustomColor, true), new LayoutParams(minimalPaddingBetweenIcon, 0));
}
if (customColors.size() < 6) {
- selectColor.addView(createAddCustomColorItemView(selectColor), new FlowLayout.LayoutParams(0, 0, true));
+ selectCustomColor.addView(createAddCustomColorItemView(selectCustomColor), new LayoutParams(minimalPaddingBetweenIcon, 0));
}
- selectColor.addView(createDividerView(selectColor), new FlowLayout.LayoutParams(0, 0, false));
+
+ FlowLayout selectDefaultColor = view.findViewById(R.id.select_default_color);
+ selectDefaultColor.removeAllViews();
+ selectDefaultColor.setHorizontalAutoSpacing(true);
for (int color : colors) {
- selectColor.addView(createColorItemView(color, selectColor, false), new FlowLayout.LayoutParams(0, 0, true));
+ selectDefaultColor.addView(createColorItemView(color, selectDefaultColor, false), new LayoutParams(minimalPaddingBetweenIcon, 0));
}
- updateColorSelector(selectedColor, selectColor);
+ updateColorSelector(selectedColor);
}
- private void updateColorSelector(int color, View rootView) {
- View oldColor = rootView.findViewWithTag(selectedColor);
+ private void updateColorSelector(int color) {
+ View oldColor = view.findViewWithTag(selectedColor);
if (oldColor != null) {
oldColor.findViewById(R.id.outline).setVisibility(View.INVISIBLE);
ImageView icon = oldColor.findViewById(R.id.icon);
- icon.setImageDrawable(UiUtilities.tintDrawable(icon.getDrawable(), R.color.icon_color_default_light));
+ icon.setImageDrawable(UiUtilities.tintDrawable(icon.getDrawable(),
+ getResolvedColor(nightMode ? R.color.icon_color_default_dark : R.color.icon_color_default_light)));
}
- View newColor = rootView.findViewWithTag(color);
+ View newColor = view.findViewWithTag(color);
if (newColor != null) {
newColor.findViewById(R.id.outline).setVisibility(View.VISIBLE);
}
@@ -137,7 +142,7 @@ public class ColorsCard extends BaseCard implements ColorPickerListener {
backgroundCircle.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
- updateColorSelector(color, rootView);
+ updateColorSelector(color);
selectedColor = color;
CardListener listener = getListener();
@@ -187,17 +192,7 @@ public class ColorsCard extends BaseCard implements ColorPickerListener {
return colorItemView;
}
- private View createDividerView(FlowLayout rootView) {
- LayoutInflater themedInflater = UiUtilities.getInflater(view.getContext(), nightMode);
- View divider = themedInflater.inflate(R.layout.simple_divider_item, rootView, false);
-
- LinearLayout dividerContainer = new LinearLayout(view.getContext());
- dividerContainer.addView(divider);
- dividerContainer.setPadding(0, AndroidUtils.dpToPx(app, 1), 0, AndroidUtils.dpToPx(app, 5));
- return dividerContainer;
- }
-
- private View createCircleView(ViewGroup rootView) {
+ private View createCircleView(FlowLayout rootView) {
LayoutInflater themedInflater = UiUtilities.getInflater(view.getContext(), nightMode);
View circleView = themedInflater.inflate(R.layout.point_editor_button, rootView, false);
ImageView outline = circleView.findViewById(R.id.outline);
diff --git a/OsmAnd/src/net/osmand/plus/widgets/FlowLayout.java b/OsmAnd/src/net/osmand/plus/widgets/FlowLayout.java
index f34fcd9306..4b50139870 100644
--- a/OsmAnd/src/net/osmand/plus/widgets/FlowLayout.java
+++ b/OsmAnd/src/net/osmand/plus/widgets/FlowLayout.java
@@ -10,23 +10,21 @@ import net.osmand.AndroidUtils;
public class FlowLayout extends ViewGroup {
private int line_height;
+ private boolean horizontalAutoSpacing;
public static class LayoutParams extends ViewGroup.LayoutParams {
- final int horizontal_spacing;
- final int vertical_spacing;
- final boolean isHorizontalAutoSpacing;
+ final int horizontalSpacing;
+ final int verticalSpacing;
/**
- * @param horizontal_spacing Pixels between items, horizontally
- * @param vertical_spacing Pixels between items, vertically
- * @param isHorizontalAutoSpacing Pixels between items to fit screen width. When is enabled horizontal_spacing does not take into account.
+ * @param horizontalSpacing Pixels between items, horizontally
+ * @param verticalSpacing Pixels between items, vertically
*/
- public LayoutParams(int horizontal_spacing, int vertical_spacing, boolean isHorizontalAutoSpacing) {
+ public LayoutParams(int horizontalSpacing, int verticalSpacing) {
super(0, 0);
- this.horizontal_spacing = horizontal_spacing;
- this.vertical_spacing = vertical_spacing;
- this.isHorizontalAutoSpacing = isHorizontalAutoSpacing;
+ this.horizontalSpacing = horizontalSpacing;
+ this.verticalSpacing = verticalSpacing;
}
}
@@ -38,6 +36,11 @@ public class FlowLayout extends ViewGroup {
super(context, attrs);
}
+ // If true available horizontal space is added to items horizontalSpacing.
+ public void setHorizontalAutoSpacing(boolean horizontalAutoSpacing) {
+ this.horizontalAutoSpacing = horizontalAutoSpacing;
+ }
+
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
if ((MeasureSpec.getMode(widthMeasureSpec) == MeasureSpec.UNSPECIFIED))
@@ -63,12 +66,12 @@ public class FlowLayout extends ViewGroup {
final LayoutParams lp = (LayoutParams) child.getLayoutParams();
child.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.AT_MOST), childHeightMeasureSpec);
final int childWidth = child.getMeasuredWidth();
- line_height = Math.max(line_height, child.getMeasuredHeight() + lp.vertical_spacing);
+ line_height = Math.max(line_height, child.getMeasuredHeight() + lp.verticalSpacing);
if (horizontalPosition + childWidth > width) {
horizontalPosition = getPaddingLeft();
verticalPosition += line_height;
}
- horizontalPosition += childWidth + lp.horizontal_spacing;
+ horizontalPosition += childWidth + lp.horizontalSpacing;
}
}
@@ -85,7 +88,7 @@ public class FlowLayout extends ViewGroup {
@Override
protected ViewGroup.LayoutParams generateDefaultLayoutParams() {
- return new LayoutParams(1, 1, false); // default of 1px spacing
+ return new LayoutParams(1, 1); // default of 1px spacing
}
@Override
@@ -113,21 +116,21 @@ public class FlowLayout extends ViewGroup {
} else {
freeSizeSpacing = width % childWidth / itemsCount;
}
- if (lp.isHorizontalAutoSpacing) {
+ if (horizontalAutoSpacing) {
if (isLayoutRtl) {
if (horizontalPosition - childWidth < getPaddingLeft()) {
horizontalPosition = width - getPaddingRight();
verticalPosition += line_height;
}
child.layout(horizontalPosition - childWidth, verticalPosition, horizontalPosition, verticalPosition + childHeight);
- horizontalPosition -= childWidth + lp.horizontal_spacing + freeSizeSpacing;
+ horizontalPosition -= childWidth + lp.horizontalSpacing + freeSizeSpacing;
} else {
if (horizontalPosition + childWidth > width) {
horizontalPosition = getPaddingLeft();
verticalPosition += line_height;
}
child.layout(horizontalPosition, verticalPosition, horizontalPosition + childWidth, verticalPosition + childHeight);
- horizontalPosition += childWidth + lp.horizontal_spacing + freeSizeSpacing;
+ horizontalPosition += childWidth + lp.horizontalSpacing + freeSizeSpacing;
}
} else {
if (isLayoutRtl) {
@@ -136,14 +139,14 @@ public class FlowLayout extends ViewGroup {
verticalPosition += line_height;
}
child.layout(horizontalPosition - childWidth, verticalPosition, horizontalPosition, verticalPosition + childHeight);
- horizontalPosition -= childWidth + lp.horizontal_spacing;
+ horizontalPosition -= childWidth + lp.horizontalSpacing;
} else {
if (horizontalPosition + childWidth > width) {
horizontalPosition = getPaddingLeft();
verticalPosition += line_height;
}
child.layout(horizontalPosition, verticalPosition, horizontalPosition + childWidth, verticalPosition + childHeight);
- horizontalPosition += childWidth + lp.horizontal_spacing;
+ horizontalPosition += childWidth + lp.horizontalSpacing;
}
}
}