Fix element's alignment: icons and colors

https://github.com/osmandapp/OsmAnd-Issues/issues/472
This commit is contained in:
androiddevkotlin 2021-02-23 18:16:12 +02:00
parent 0125820d76
commit 7a738dd55c
8 changed files with 120 additions and 101 deletions

View file

@ -1,16 +1,17 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical"> android:orientation="vertical">
<com.google.android.material.internal.FlowLayout <net.osmand.plus.widgets.FlowLayout
android:id="@+id/select_color" android:id="@+id/select_color"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="@dimen/content_padding_small" android:layout_marginStart="@dimen/content_padding"
android:layout_marginLeft="@dimen/content_padding_small" android:layout_marginLeft="@dimen/content_padding"
android:layout_marginEnd="@dimen/content_padding"
android:layout_marginRight="@dimen/content_padding"
android:layout_marginTop="@dimen/context_menu_padding_margin_tiny" android:layout_marginTop="@dimen/context_menu_padding_margin_tiny"
android:layout_marginBottom="@dimen/content_padding_half" /> android:layout_marginBottom="@dimen/content_padding_half" />

View file

@ -84,6 +84,7 @@
android:drawableEnd="@drawable/btn_circle_transparent_full" android:drawableEnd="@drawable/btn_circle_transparent_full"
android:drawableRight="@drawable/btn_circle_transparent_full" android:drawableRight="@drawable/btn_circle_transparent_full"
android:drawablePadding="@dimen/favorites_list_item_height" android:drawablePadding="@dimen/favorites_list_item_height"
android:imeOptions="actionDone"
android:inputType="textMultiLine" android:inputType="textMultiLine"
android:maxLines="4" android:maxLines="4"
android:minHeight="@dimen/favorites_list_item_height" android:minHeight="@dimen/favorites_list_item_height"
@ -93,7 +94,6 @@
android:paddingRight="@dimen/content_padding_small" android:paddingRight="@dimen/content_padding_small"
android:scrollHorizontally="false" android:scrollHorizontally="false"
android:textSize="@dimen/default_list_text_size" android:textSize="@dimen/default_list_text_size"
android:imeOptions="actionDone"
tools:text="@string/lorem_ipsum" /> tools:text="@string/lorem_ipsum" />
</com.google.android.material.textfield.TextInputLayout> </com.google.android.material.textfield.TextInputLayout>
@ -137,6 +137,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="start" android:gravity="start"
android:imeOptions="actionDone"
android:maxLines="4" android:maxLines="4"
android:minHeight="@dimen/favorites_list_item_height" android:minHeight="@dimen/favorites_list_item_height"
android:paddingStart="@dimen/content_padding_small" android:paddingStart="@dimen/content_padding_small"
@ -144,7 +145,6 @@
android:paddingEnd="@dimen/content_padding_small" android:paddingEnd="@dimen/content_padding_small"
android:paddingRight="@dimen/content_padding_small" android:paddingRight="@dimen/content_padding_small"
android:textSize="@dimen/default_list_text_size" android:textSize="@dimen/default_list_text_size"
android:imeOptions="actionDone"
tools:text="@string/lorem_ipsum" /> tools:text="@string/lorem_ipsum" />
</com.google.android.material.textfield.TextInputLayout> </com.google.android.material.textfield.TextInputLayout>
@ -248,6 +248,7 @@
android:drawablePadding="8dp" android:drawablePadding="8dp"
android:duplicateParentState="true" android:duplicateParentState="true"
android:gravity="center" android:gravity="center"
android:imeOptions="actionDone"
android:paddingStart="@dimen/content_padding_half" android:paddingStart="@dimen/content_padding_half"
android:paddingLeft="@dimen/content_padding_half" android:paddingLeft="@dimen/content_padding_half"
android:paddingEnd="@dimen/content_padding_half" android:paddingEnd="@dimen/content_padding_half"
@ -255,7 +256,6 @@
android:text="@string/add_description" android:text="@string/add_description"
android:textSize="@dimen/default_desc_text_size" android:textSize="@dimen/default_desc_text_size"
osmand:typeface="@string/font_roboto_medium" osmand:typeface="@string/font_roboto_medium"
android:imeOptions="actionDone"
tools:text="@string/add_description" /> tools:text="@string/add_description" />
<View <View
@ -402,9 +402,11 @@
android:id="@+id/select_icon" android:id="@+id/select_icon"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="@dimen/content_padding_small" android:layout_marginStart="@dimen/content_padding"
android:layout_marginLeft="@dimen/content_padding_small" android:layout_marginLeft="@dimen/content_padding"
android:layout_marginTop="@dimen/context_menu_padding_margin_tiny" android:layout_marginTop="@dimen/context_menu_padding_margin_tiny"
android:layout_marginEnd="@dimen/content_padding"
android:layout_marginRight="@dimen/content_padding"
android:layout_marginBottom="@dimen/content_padding_half" /> android:layout_marginBottom="@dimen/content_padding_half" />
<View <View
@ -447,12 +449,10 @@
osmand:typeface="@string/font_roboto_medium" /> osmand:typeface="@string/font_roboto_medium" />
</LinearLayout> </LinearLayout>
<LinearLayout <net.osmand.plus.widgets.FlowLayout
android:id="@+id/select_color" android:id="@+id/select_color"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="@dimen/content_padding_small"
android:layout_marginLeft="@dimen/content_padding_small"
android:layout_marginTop="@dimen/context_menu_padding_margin_tiny" android:layout_marginTop="@dimen/context_menu_padding_margin_tiny"
android:layout_marginBottom="@dimen/content_padding_half" /> android:layout_marginBottom="@dimen/content_padding_half" />
@ -500,9 +500,11 @@
android:id="@+id/select_shape" android:id="@+id/select_shape"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="@dimen/content_padding_small" android:layout_marginStart="@dimen/content_padding"
android:layout_marginLeft="@dimen/content_padding_small" android:layout_marginLeft="@dimen/content_padding"
android:layout_marginTop="@dimen/context_menu_padding_margin_tiny" android:layout_marginTop="@dimen/context_menu_padding_margin_tiny"
android:layout_marginEnd="@dimen/content_padding"
android:layout_marginRight="@dimen/content_padding"
android:layout_marginBottom="@dimen/content_padding_half" android:layout_marginBottom="@dimen/content_padding_half"
android:gravity="start" /> android:gravity="start" />

View file

@ -21,8 +21,8 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="horizontal" android:orientation="horizontal"
android:paddingTop="@dimen/context_menu_padding_margin_tiny" android:paddingTop="@dimen/context_menu_padding_margin_tiny"
android:visibility="gone" android:paddingBottom="@dimen/content_padding"
android:paddingBottom="@dimen/content_padding"> android:visibility="gone">
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view" android:id="@+id/recycler_view"
@ -41,13 +41,15 @@
</LinearLayout> </LinearLayout>
<com.google.android.material.internal.FlowLayout <net.osmand.plus.widgets.FlowLayout
android:id="@+id/select_color" android:id="@+id/select_color"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="@dimen/content_padding_small" android:layout_marginStart="@dimen/content_padding"
android:layout_marginLeft="@dimen/content_padding_small" android:layout_marginLeft="@dimen/content_padding"
android:layout_marginTop="@dimen/context_menu_padding_margin_tiny" android:layout_marginTop="@dimen/context_menu_padding_margin_tiny"
android:layout_marginEnd="@dimen/content_padding"
android:layout_marginRight="@dimen/content_padding"
android:layout_marginBottom="@dimen/content_padding_half" /> android:layout_marginBottom="@dimen/content_padding_half" />
</LinearLayout> </LinearLayout>

View file

@ -22,7 +22,6 @@ import android.view.inputmethod.InputMethodManager;
import android.widget.EditText; import android.widget.EditText;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ScrollView; import android.widget.ScrollView;
import android.widget.TextView; import android.widget.TextView;
@ -66,6 +65,7 @@ import org.json.JSONObject;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
@ -124,7 +124,7 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment implemen
@SuppressLint("ClickableViewAccessibility") @SuppressLint("ClickableViewAccessibility")
@Override @Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { Bundle savedInstanceState) {
app = requireMyApplication(); app = requireMyApplication();
nightMode = app.getDaynightHelper().isNightModeForMapControls(); nightMode = app.getDaynightHelper().isNightModeForMapControls();
@ -144,7 +144,7 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment implemen
selectedShape = getBackgroundType(); selectedShape = getBackgroundType();
selectedIcon = getIconId(); selectedIcon = getIconId();
Toolbar toolbar = (Toolbar) view.findViewById(R.id.toolbar); Toolbar toolbar = view.findViewById(R.id.toolbar);
toolbar.setBackgroundColor(ContextCompat.getColor(requireContext(), toolbar.setBackgroundColor(ContextCompat.getColor(requireContext(),
nightMode ? R.color.app_bar_color_dark : R.color.list_background_color_light)); nightMode ? R.color.app_bar_color_dark : R.color.list_background_color_light));
toolbar.setTitle(getToolbarTitle()); toolbar.setTitle(getToolbarTitle());
@ -159,7 +159,7 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment implemen
} }
}); });
final ScrollView scrollView = (ScrollView) view.findViewById(R.id.editor_scroll_view); final ScrollView scrollView = view.findViewById(R.id.editor_scroll_view);
scrollViewY = scrollView.getScrollY(); scrollViewY = scrollView.getScrollY();
scrollView.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() { scrollView.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
@Override @Override
@ -175,14 +175,14 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment implemen
}); });
final int activeColorResId = getActiveColorRes(); final int activeColorResId = getActiveColorRes();
ImageView toolbarAction = (ImageView) view.findViewById(R.id.toolbar_action); ImageView toolbarAction = view.findViewById(R.id.toolbar_action);
view.findViewById(R.id.background_layout).setBackgroundResource(nightMode view.findViewById(R.id.background_layout).setBackgroundResource(nightMode
? R.color.app_bar_color_dark : R.color.list_background_color_light); ? R.color.app_bar_color_dark : R.color.list_background_color_light);
ImageView replaceIcon = (ImageView) view.findViewById(R.id.replace_action_icon); ImageView replaceIcon = view.findViewById(R.id.replace_action_icon);
replaceIcon.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_replace, activeColorResId)); replaceIcon.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_replace, activeColorResId));
ImageView deleteIcon = (ImageView) view.findViewById(R.id.delete_action_icon); ImageView deleteIcon = view.findViewById(R.id.delete_action_icon);
deleteIcon.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_delete_dark, activeColorResId)); deleteIcon.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_delete_dark, activeColorResId));
ImageView groupListIcon = (ImageView) view.findViewById(R.id.group_list_button_icon); ImageView groupListIcon = view.findViewById(R.id.group_list_button_icon);
groupListIcon.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_group_select_all, activeColorResId)); groupListIcon.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_group_select_all, activeColorResId));
addToHiddenGroupInfo = view.findViewById(R.id.add_hidden_group_info); addToHiddenGroupInfo = view.findViewById(R.id.add_hidden_group_info);
addToHiddenGroupInfo.setText(getString(R.string.add_hidden_group_info, getString(R.string.shared_string_my_places))); addToHiddenGroupInfo.setText(getString(R.string.add_hidden_group_info, getString(R.string.shared_string_my_places)));
@ -217,10 +217,10 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment implemen
UiUtilities.setupDialogButton(nightMode, cancelButton, UiUtilities.DialogButtonType.SECONDARY, R.string.shared_string_cancel); UiUtilities.setupDialogButton(nightMode, cancelButton, UiUtilities.DialogButtonType.SECONDARY, R.string.shared_string_cancel);
UiUtilities.setupDialogButton(nightMode, saveButton, UiUtilities.DialogButtonType.PRIMARY, R.string.shared_string_save); UiUtilities.setupDialogButton(nightMode, saveButton, UiUtilities.DialogButtonType.PRIMARY, R.string.shared_string_save);
final TextInputLayout nameCaption = (TextInputLayout) view.findViewById(R.id.name_caption); final TextInputLayout nameCaption = view.findViewById(R.id.name_caption);
nameCaption.setHint(getString(R.string.shared_string_name)); nameCaption.setHint(getString(R.string.shared_string_name));
nameEdit = (EditText) view.findViewById(R.id.name_edit); nameEdit = view.findViewById(R.id.name_edit);
nameEdit.setText(getNameInitValue()); nameEdit.setText(getNameInitValue());
nameEdit.addTextChangedListener(new TextWatcher() { nameEdit.addTextChangedListener(new TextWatcher() {
@Override @Override
@ -238,15 +238,15 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment implemen
}); });
checkEmptyName(nameEdit.getText(), nameCaption, saveButton); checkEmptyName(nameEdit.getText(), nameCaption, saveButton);
nameIcon = (ImageView) view.findViewById(R.id.name_icon); nameIcon = view.findViewById(R.id.name_icon);
TextView categoryEdit = view.findViewById(R.id.groupName); TextView categoryEdit = view.findViewById(R.id.groupName);
if (categoryEdit != null) { if (categoryEdit != null) {
AndroidUtils.setTextPrimaryColor(view.getContext(), categoryEdit, nightMode); AndroidUtils.setTextPrimaryColor(view.getContext(), categoryEdit, nightMode);
categoryEdit.setText(getCategoryInitValue()); categoryEdit.setText(getCategoryInitValue());
} }
descriptionEdit = (EditText) view.findViewById(R.id.description_edit); descriptionEdit = view.findViewById(R.id.description_edit);
addressEdit = (EditText) view.findViewById(R.id.address_edit); addressEdit = view.findViewById(R.id.address_edit);
AndroidUtils.setTextPrimaryColor(view.getContext(), descriptionEdit, nightMode); AndroidUtils.setTextPrimaryColor(view.getContext(), descriptionEdit, nightMode);
AndroidUtils.setTextPrimaryColor(view.getContext(), addressEdit, nightMode); AndroidUtils.setTextPrimaryColor(view.getContext(), addressEdit, nightMode);
AndroidUtils.setHintTextSecondaryColor(view.getContext(), descriptionEdit, nightMode); AndroidUtils.setHintTextSecondaryColor(view.getContext(), descriptionEdit, nightMode);
@ -257,7 +257,7 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment implemen
descriptionCaption = view.findViewById(R.id.description); descriptionCaption = view.findViewById(R.id.description);
addressCaption = view.findViewById(R.id.address); addressCaption = view.findViewById(R.id.address);
addDelDescription = (TextView) view.findViewById(R.id.description_button); addDelDescription = view.findViewById(R.id.description_button);
addAddressBtn = view.findViewById(R.id.address_button); addAddressBtn = view.findViewById(R.id.address_button);
deleteAddressIcon = view.findViewById(R.id.delete_address_icon); deleteAddressIcon = view.findViewById(R.id.delete_address_icon);
deleteAddressIcon.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_trash_basket_16, activeColorResId)); deleteAddressIcon.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_trash_basket_16, activeColorResId));
@ -476,8 +476,9 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment implemen
} }
colorsCard = new ColorsCard(mapActivity, selectedColor, this, colors); colorsCard = new ColorsCard(mapActivity, selectedColor, this, colors);
colorsCard.setListener(this); colorsCard.setListener(this);
LinearLayout selectColor = view.findViewById(R.id.select_color); FlowLayout selectColor = view.findViewById(R.id.select_color);
selectColor.addView(colorsCard.build(view.getContext())); selectColor.addView(colorsCard.build(view.getContext()),
new FlowLayout.LayoutParams(0, 0, true));
} }
} }
@ -520,7 +521,7 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment implemen
for (BackgroundType backgroundType : BackgroundType.values()) { for (BackgroundType backgroundType : BackgroundType.values()) {
if (backgroundType.isSelected()) { if (backgroundType.isSelected()) {
selectShape.addView(createShapeItemView(backgroundType, selectShape), selectShape.addView(createShapeItemView(backgroundType, selectShape),
new FlowLayout.LayoutParams(0, 0)); new FlowLayout.LayoutParams(0, 0, true));
} }
} }
} }
@ -561,7 +562,7 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment implemen
((TextView) rootView.findViewById(R.id.shape_name)).setText(backgroundType.getNameId()); ((TextView) rootView.findViewById(R.id.shape_name)).setText(backgroundType.getNameId());
ImageView background = newShape.findViewById(R.id.background); ImageView background = newShape.findViewById(R.id.background);
background.setImageDrawable(UiUtilities.tintDrawable(AppCompatResources.getDrawable(app, backgroundType.getIconId()), background.setImageDrawable(UiUtilities.tintDrawable(AppCompatResources.getDrawable(app, backgroundType.getIconId()),
selectedColor)); selectedColor));
selectedShape = backgroundType; selectedShape = backgroundType;
setBackgroundType(backgroundType); setBackgroundType(backgroundType);
updateNameIcon(); updateNameIcon();
@ -569,9 +570,9 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment implemen
private void setShapeSelectorBackground(BackgroundType backgroundType, ImageView background) { private void setShapeSelectorBackground(BackgroundType backgroundType, ImageView background) {
background.setImageDrawable(UiUtilities.tintDrawable(AppCompatResources.getDrawable(app, backgroundType.getIconId()), background.setImageDrawable(UiUtilities.tintDrawable(AppCompatResources.getDrawable(app, backgroundType.getIconId()),
ContextCompat.getColor(app, ContextCompat.getColor(app,
nightMode ? R.color.inactive_buttons_and_links_bg_dark nightMode ? R.color.inactive_buttons_and_links_bg_dark
: R.color.inactive_buttons_and_links_bg_light))); : R.color.inactive_buttons_and_links_bg_light)));
} }
private String getInitCategory() { private String getInitCategory() {
@ -643,7 +644,7 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment implemen
horizontalSelectionAdapter.notifyDataSetChanged(); horizontalSelectionAdapter.notifyDataSetChanged();
iconCategoriesRecyclerView.smoothScrollToPosition(horizontalSelectionAdapter.getItemPositionByTitle(selectedIconCategory)); iconCategoriesRecyclerView.smoothScrollToPosition(horizontalSelectionAdapter.getItemPositionByTitle(selectedIconCategory));
for (String name : iconNameList) { for (String name : iconNameList) {
selectIcon.addView(createIconItemView(name, selectIcon), new FlowLayout.LayoutParams(0, 0)); selectIcon.addView(createIconItemView(name, selectIcon), new FlowLayout.LayoutParams(0, 0, true));
} }
} }
} }
@ -701,9 +702,9 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment implemen
private void setIconSelectorBackground(ImageView backgroundCircle) { private void setIconSelectorBackground(ImageView backgroundCircle) {
backgroundCircle.setImageDrawable(UiUtilities.tintDrawable(AppCompatResources.getDrawable(app, R.drawable.bg_point_circle), backgroundCircle.setImageDrawable(UiUtilities.tintDrawable(AppCompatResources.getDrawable(app, R.drawable.bg_point_circle),
ContextCompat.getColor(app, nightMode ContextCompat.getColor(app, nightMode
? R.color.inactive_buttons_and_links_bg_dark ? R.color.inactive_buttons_and_links_bg_dark
: R.color.inactive_buttons_and_links_bg_light))); : R.color.inactive_buttons_and_links_bg_light)));
} }
private void updateNameIcon() { private void updateNameIcon() {
@ -720,7 +721,7 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment implemen
byte[] buffer = new byte[size]; byte[] buffer = new byte[size];
is.read(buffer); is.read(buffer);
is.close(); is.close();
json = new String(buffer, "UTF-8"); json = new String(buffer, StandardCharsets.UTF_8);
} catch (IOException ex) { } catch (IOException ex) {
ex.printStackTrace(); ex.printStackTrace();
return null; return null;
@ -887,8 +888,6 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment implemen
return true; return true;
} }
;
String getNameTextValue() { String getNameTextValue() {
EditText nameEdit = view.findViewById(R.id.name_edit); EditText nameEdit = view.findViewById(R.id.name_edit);
return nameEdit.getText().toString().trim(); return nameEdit.getText().toString().trim();

View file

@ -294,8 +294,8 @@ public class PublicTransportCard extends BaseCard {
if (walkingSegment != null) { if (walkingSegment != null) {
double walkTime = walkingSegment.getRoutingTime(); double walkTime = walkingSegment.getRoutingTime();
if (walkTime > MIN_WALK_TIME) { if (walkTime > MIN_WALK_TIME) {
routesBadges.addView(createWalkRouteBadge(walkingSegment, badgesRowClickable), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing)); routesBadges.addView(createWalkRouteBadge(walkingSegment, badgesRowClickable), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing, false));
routesBadges.addView(createArrow(), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing)); routesBadges.addView(createArrow(), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing, false));
} }
} else if (s.walkDist > 0) { } else if (s.walkDist > 0) {
double walkTime = getWalkTime(s.walkDist, routeResult.getWalkSpeed()); double walkTime = getWalkTime(s.walkDist, routeResult.getWalkSpeed());
@ -307,20 +307,20 @@ public class PublicTransportCard extends BaseCard {
} else { } else {
start = this.startLocation; start = this.startLocation;
} }
routesBadges.addView(createWalkRouteBadge(walkTime, start, end, badgesRowClickable), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing)); routesBadges.addView(createWalkRouteBadge(walkTime, start, end, badgesRowClickable), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing, false));
routesBadges.addView(createArrow(), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing)); routesBadges.addView(createArrow(), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing, false));
} }
} }
routesBadges.addView(createRouteBadge(s, badgesRowClickable), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing)); routesBadges.addView(createRouteBadge(s, badgesRowClickable), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing, false));
if (iterator.hasNext()) { if (iterator.hasNext()) {
routesBadges.addView(createArrow(), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing)); routesBadges.addView(createArrow(), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing, false));
} else { } else {
walkingSegment = transportRoutingHelper.getWalkingRouteSegment(s, null); walkingSegment = transportRoutingHelper.getWalkingRouteSegment(s, null);
if (walkingSegment != null) { if (walkingSegment != null) {
double walkTime = walkingSegment.getRoutingTime(); double walkTime = walkingSegment.getRoutingTime();
if (walkTime > MIN_WALK_TIME) { if (walkTime > MIN_WALK_TIME) {
routesBadges.addView(createArrow(), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing)); routesBadges.addView(createArrow(), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing, false));
routesBadges.addView(createWalkRouteBadge(walkingSegment, badgesRowClickable), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing)); routesBadges.addView(createWalkRouteBadge(walkingSegment, badgesRowClickable), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing, false));
} }
} else { } else {
double finishWalkDist = routeResult.getFinishWalkDist(); double finishWalkDist = routeResult.getFinishWalkDist();
@ -329,7 +329,7 @@ public class PublicTransportCard extends BaseCard {
if (walkTime > MIN_WALK_TIME) { if (walkTime > MIN_WALK_TIME) {
LatLon start = s.getEnd().getLocation(); LatLon start = s.getEnd().getLocation();
LatLon end = this.endLocation; LatLon end = this.endLocation;
routesBadges.addView(createArrow(), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing)); routesBadges.addView(createArrow(), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing, false));
routesBadges.addView(createWalkRouteBadge(walkTime, start, end, badgesRowClickable)); routesBadges.addView(createWalkRouteBadge(walkTime, start, end, badgesRowClickable));
} }
} }

View file

@ -413,7 +413,7 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment implements O
colorItems.removeAllViews(); colorItems.removeAllViews();
for (ProfileIconColors color : ProfileIconColors.values()) { for (ProfileIconColors color : ProfileIconColors.values()) {
View colorItem = createColorItemView(color, colorItems); View colorItem = createColorItemView(color, colorItems);
colorItems.addView(colorItem, new FlowLayout.LayoutParams(0, 0)); colorItems.addView(colorItem, new FlowLayout.LayoutParams(0, 0, true));
} }
updateColorSelector(changedProfile.color); updateColorSelector(changedProfile.color);
} else if (ICON_ITEMS.equals(preference.getKey())) { } else if (ICON_ITEMS.equals(preference.getKey())) {
@ -422,7 +422,7 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment implements O
ArrayList<Integer> icons = ProfileIcons.getIcons(); ArrayList<Integer> icons = ProfileIcons.getIcons();
for (int iconRes : icons) { for (int iconRes : icons) {
View iconItem = createIconItemView(iconRes, iconItems); View iconItem = createIconItemView(iconRes, iconItems);
iconItems.addView(iconItem, new FlowLayout.LayoutParams(0, 0)); iconItems.addView(iconItem, new FlowLayout.LayoutParams(0, 0,true));
} }
setIconColor(changedProfile.iconRes); setIconColor(changedProfile.iconRes);
} else if (LOCATION_ICON_ITEMS.equals(preference.getKey())) { } else if (LOCATION_ICON_ITEMS.equals(preference.getKey())) {
@ -430,7 +430,7 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment implements O
locationIconItems.removeAllViews(); locationIconItems.removeAllViews();
for (LocationIcon locationIcon : LocationIcon.values()) { for (LocationIcon locationIcon : LocationIcon.values()) {
View iconItemView = createLocationIconView(locationIcon, locationIconItems); View iconItemView = createLocationIconView(locationIcon, locationIconItems);
locationIconItems.addView(iconItemView, new FlowLayout.LayoutParams(0, 0)); locationIconItems.addView(iconItemView, new FlowLayout.LayoutParams(0, 0, false));
} }
updateLocationIconSelector(changedProfile.locationIcon); updateLocationIconSelector(changedProfile.locationIcon);
} else if (NAV_ICON_ITEMS.equals(preference.getKey())) { } else if (NAV_ICON_ITEMS.equals(preference.getKey())) {
@ -438,7 +438,7 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment implements O
navIconItems.removeAllViews(); navIconItems.removeAllViews();
for (NavigationIcon navigationIcon : NavigationIcon.values()) { for (NavigationIcon navigationIcon : NavigationIcon.values()) {
View iconItemView = createNavigationIconView(navigationIcon, navIconItems); View iconItemView = createNavigationIconView(navigationIcon, navIconItems);
navIconItems.addView(iconItemView, new FlowLayout.LayoutParams(0, 0)); navIconItems.addView(iconItemView, new FlowLayout.LayoutParams(0, 0, false));
} }
updateNavigationIconSelector(changedProfile.navigationIcon); updateNavigationIconSelector(changedProfile.navigationIcon);
} }

View file

@ -13,8 +13,6 @@ import androidx.core.content.ContextCompat;
import androidx.core.graphics.ColorUtils; import androidx.core.graphics.ColorUtils;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import com.google.android.material.internal.FlowLayout;
import net.osmand.AndroidUtils; import net.osmand.AndroidUtils;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
@ -23,6 +21,7 @@ import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.routepreparationmenu.cards.BaseCard; import net.osmand.plus.routepreparationmenu.cards.BaseCard;
import net.osmand.plus.track.CustomColorBottomSheet.ColorPickerListener; import net.osmand.plus.track.CustomColorBottomSheet.ColorPickerListener;
import net.osmand.plus.widgets.FlowLayout;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
@ -96,15 +95,15 @@ public class ColorsCard extends BaseCard implements ColorPickerListener {
selectColor.removeAllViews(); selectColor.removeAllViews();
for (int color : customColors) { for (int color : customColors) {
selectColor.addView(createColorItemView(color, selectColor, true)); selectColor.addView(createColorItemView(color, selectColor, true), new FlowLayout.LayoutParams(0, 0, true));
} }
if (customColors.size() < 6) { if (customColors.size() < 6) {
selectColor.addView(createAddCustomColorItemView(selectColor)); selectColor.addView(createAddCustomColorItemView(selectColor), new FlowLayout.LayoutParams(0, 0, true));
} }
selectColor.addView(createDividerView(selectColor)); selectColor.addView(createDividerView(selectColor), new FlowLayout.LayoutParams(0, 0, false));
for (int color : colors) { for (int color : colors) {
selectColor.addView(createColorItemView(color, selectColor, false)); selectColor.addView(createColorItemView(color, selectColor, false), new FlowLayout.LayoutParams(0, 0, true));
} }
updateColorSelector(selectedColor, selectColor); updateColorSelector(selectedColor, selectColor);
} }
@ -195,7 +194,6 @@ public class ColorsCard extends BaseCard implements ColorPickerListener {
LinearLayout dividerContainer = new LinearLayout(view.getContext()); LinearLayout dividerContainer = new LinearLayout(view.getContext());
dividerContainer.addView(divider); dividerContainer.addView(divider);
dividerContainer.setPadding(0, AndroidUtils.dpToPx(app, 1), 0, AndroidUtils.dpToPx(app, 5)); dividerContainer.setPadding(0, AndroidUtils.dpToPx(app, 1), 0, AndroidUtils.dpToPx(app, 5));
return dividerContainer; return dividerContainer;
} }

View file

@ -1,7 +1,6 @@
package net.osmand.plus.widgets; package net.osmand.plus.widgets;
import android.content.Context; import android.content.Context;
import android.os.Build;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -16,15 +15,17 @@ public class FlowLayout extends ViewGroup {
final int horizontal_spacing; final int horizontal_spacing;
final int vertical_spacing; final int vertical_spacing;
final boolean horizontalAutoSpacing;
/** /**
* @param horizontal_spacing Pixels between items, horizontally * @param horizontal_spacing Pixels between items, horizontally
* @param vertical_spacing Pixels between items, vertically * @param vertical_spacing Pixels between items, vertically
*/ */
public LayoutParams(int horizontal_spacing, int vertical_spacing) { public LayoutParams(int horizontal_spacing, int vertical_spacing, boolean horizontalAutoSpacing) {
super(0, 0); super(0, 0);
this.horizontal_spacing = horizontal_spacing; this.horizontal_spacing = horizontal_spacing;
this.vertical_spacing = vertical_spacing; this.vertical_spacing = vertical_spacing;
this.horizontalAutoSpacing = horizontalAutoSpacing;
} }
} }
@ -38,43 +39,44 @@ public class FlowLayout extends ViewGroup {
@Override @Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
if ((MeasureSpec.getMode(widthMeasureSpec) == MeasureSpec.UNSPECIFIED)) throw new AssertionError(); if ((MeasureSpec.getMode(widthMeasureSpec) == MeasureSpec.UNSPECIFIED))
throw new AssertionError();
final int width = MeasureSpec.getSize(widthMeasureSpec) - getPaddingLeft() - getPaddingRight(); final int width = MeasureSpec.getSize(widthMeasureSpec) - getPaddingLeft() - getPaddingRight();
int height = MeasureSpec.getSize(heightMeasureSpec) - getPaddingTop() - getPaddingBottom(); int height = MeasureSpec.getSize(heightMeasureSpec) - getPaddingTop() - getPaddingBottom();
final int count = getChildCount(); final int count = getChildCount();
int line_height = 0; int line_height = 0;
int xpos = getPaddingLeft(); int horizontalPosition = getPaddingLeft();
int ypos = getPaddingTop(); int verticalPosition = getPaddingTop();
int childHeightMeasureSpec; int childHeighteightMeasureSpec;
if (MeasureSpec.getMode(heightMeasureSpec) == MeasureSpec.AT_MOST) { if (MeasureSpec.getMode(heightMeasureSpec) == MeasureSpec.AT_MOST) {
childHeightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.AT_MOST); childHeighteightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.AT_MOST);
} else { } else {
childHeightMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED); childHeighteightMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
} }
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
final View child = getChildAt(i); final View child = getChildAt(i);
if (child.getVisibility() != GONE) { if (child.getVisibility() != GONE) {
final LayoutParams lp = (LayoutParams) child.getLayoutParams(); final LayoutParams lp = (LayoutParams) child.getLayoutParams();
child.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.AT_MOST), childHeightMeasureSpec); child.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.AT_MOST), childHeighteightMeasureSpec);
final int childw = child.getMeasuredWidth(); 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.vertical_spacing);
if (xpos + childw > width) { if (horizontalPosition + childWidth > width) {
xpos = getPaddingLeft(); horizontalPosition = getPaddingLeft();
ypos += line_height; verticalPosition += line_height;
} }
xpos += childw + lp.horizontal_spacing; horizontalPosition += childWidth + lp.horizontal_spacing;
} }
} }
this.line_height = line_height; this.line_height = line_height;
if (MeasureSpec.getMode(heightMeasureSpec) == MeasureSpec.UNSPECIFIED) { if (MeasureSpec.getMode(heightMeasureSpec) == MeasureSpec.UNSPECIFIED) {
height = ypos + line_height; height = verticalPosition + line_height;
} else if (MeasureSpec.getMode(heightMeasureSpec) == MeasureSpec.AT_MOST) { } else if (MeasureSpec.getMode(heightMeasureSpec) == MeasureSpec.AT_MOST) {
if (ypos + line_height < height) { if (verticalPosition + line_height < height) {
height = ypos + line_height; height = verticalPosition + line_height;
} }
} }
setMeasuredDimension(width, height); setMeasuredDimension(width, height);
@ -82,7 +84,7 @@ public class FlowLayout extends ViewGroup {
@Override @Override
protected ViewGroup.LayoutParams generateDefaultLayoutParams() { protected ViewGroup.LayoutParams generateDefaultLayoutParams() {
return new LayoutParams(1, 1); // default of 1px spacing return new LayoutParams(1, 1, false); // default of 1px spacing
} }
@Override @Override
@ -94,29 +96,44 @@ public class FlowLayout extends ViewGroup {
protected void onLayout(boolean changed, int l, int t, int r, int b) { protected void onLayout(boolean changed, int l, int t, int r, int b) {
final int count = getChildCount(); final int count = getChildCount();
final int width = r - l; final int width = r - l;
int freeSizeSpacing;
boolean isLayoutRtl = AndroidUtils.isLayoutRtl(getContext()); boolean isLayoutRtl = AndroidUtils.isLayoutRtl(getContext());
int xpos = isLayoutRtl ? width - getPaddingRight() : getPaddingLeft(); int horizontalPosition = isLayoutRtl ? width - getPaddingRight() : getPaddingLeft();
int ypos = getPaddingTop(); int verticalPosition = getPaddingTop();
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
final View child = getChildAt(i); final View child = getChildAt(i);
if (child.getVisibility() != GONE) { if (child.getVisibility() != GONE) {
final int childw = child.getMeasuredWidth(); final int childWidth = child.getMeasuredWidth();
final int childh = child.getMeasuredHeight(); final int childHeight = child.getMeasuredHeight();
final LayoutParams lp = (LayoutParams) child.getLayoutParams(); final LayoutParams lp = (LayoutParams) child.getLayoutParams();
if (isLayoutRtl) { int itemsCount = width / childWidth;
if (xpos - childw < l) { if (itemsCount > 1) {
xpos = width - getPaddingRight(); freeSizeSpacing = width % childWidth / (itemsCount - 1);
ypos += line_height;
}
child.layout(xpos - childw, ypos, xpos, ypos + childh);
xpos -= childw + lp.horizontal_spacing;
} else { } else {
if (xpos + childw > width) { freeSizeSpacing = width % childWidth / itemsCount;
xpos = getPaddingLeft(); }
ypos += line_height; if (isLayoutRtl) {
if (horizontalPosition - childWidth < l) {
horizontalPosition = width - getPaddingRight();
verticalPosition += line_height;
}
child.layout(horizontalPosition - childWidth, verticalPosition, horizontalPosition, verticalPosition + childHeight);
if (lp.horizontalAutoSpacing) {
horizontalPosition -= childWidth + lp.horizontal_spacing + freeSizeSpacing;
} else {
horizontalPosition -= childWidth + lp.horizontal_spacing;
}
} else {
if (horizontalPosition + childWidth > width) {
horizontalPosition = getPaddingLeft();
verticalPosition += line_height;
}
child.layout(horizontalPosition, verticalPosition, horizontalPosition + childWidth, verticalPosition + childHeight);
if (lp.horizontalAutoSpacing) {
horizontalPosition += childWidth + lp.horizontal_spacing + freeSizeSpacing;
} else {
horizontalPosition += childWidth + lp.horizontal_spacing;
} }
child.layout(xpos, ypos, xpos + childw, ypos + childh);
xpos += childw + lp.horizontal_spacing;
} }
} }
} }