This commit is contained in:
androiddevkotlin 2021-03-04 10:49:46 +02:00
parent ca4de9fc8a
commit cf8346187f
8 changed files with 103 additions and 102 deletions

View file

@ -5,14 +5,20 @@
android:orientation="vertical">
<net.osmand.plus.widgets.FlowLayout
android:id="@+id/select_color"
android:id="@+id/select_custom_color"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/content_padding"
android:layout_marginLeft="@dimen/content_padding"
android:layout_marginEnd="@dimen/content_padding"
android:layout_marginRight="@dimen/content_padding"
android:layout_height="wrap_content" />
<include
layout="@layout/simple_divider_item"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="@dimen/context_menu_padding_margin_tiny"
android:layout_marginBottom="@dimen/content_padding_half" />
<net.osmand.plus.widgets.FlowLayout
android:id="@+id/select_default_color"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>

View file

@ -1,15 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingStart="0dp"
android:paddingLeft="0dp"
android:paddingEnd="@dimen/favorites_select_icon_button_right_padding"
android:paddingRight="@dimen/favorites_select_icon_button_right_padding"
android:paddingBottom="@dimen/context_menu_buttons_padding_bottom">
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
@ -24,8 +15,8 @@
android:id="@+id/background"
android:layout_width="@dimen/favorites_icon_size"
android:layout_height="@dimen/favorites_icon_size"
android:padding="@dimen/favorites_icon_padding"
android:layout_gravity="center"
android:padding="@dimen/favorites_icon_padding"
app:srcCompat="@drawable/bg_point_circle" />
<androidx.appcompat.widget.AppCompatImageView
@ -35,7 +26,6 @@
android:layout_gravity="center"
android:clickable="false"
android:visibility="gone"
app:srcCompat="@drawable/mx_special_star_stroked"
/>
</FrameLayout>
app:srcCompat="@drawable/mx_special_star_stroked" />
</FrameLayout>

View file

@ -449,12 +449,15 @@
osmand:typeface="@string/font_roboto_medium" />
</LinearLayout>
<net.osmand.plus.widgets.FlowLayout
<LinearLayout
android:id="@+id/select_color"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/content_padding_small"
android:layout_marginTop="@dimen/context_menu_padding_margin_tiny"
android:layout_marginBottom="@dimen/content_padding_half" />
android:layout_marginBottom="@dimen/content_padding_half"
android:orientation="horizontal"
android:layout_marginStart="@dimen/content_padding_small" />
<View
android:layout_width="match_parent"

View file

@ -22,6 +22,7 @@ import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;
@ -476,9 +477,8 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment implemen
}
colorsCard = new ColorsCard(mapActivity, selectedColor, this, colors);
colorsCard.setListener(this);
FlowLayout selectColor = view.findViewById(R.id.select_color);
selectColor.addView(colorsCard.build(view.getContext()),
new FlowLayout.LayoutParams(0, 0, true));
LinearLayout selectColor = view.findViewById(R.id.select_color);
selectColor.addView(colorsCard.build(view.getContext()));
}
}
@ -521,7 +521,8 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment implemen
for (BackgroundType backgroundType : BackgroundType.values()) {
if (backgroundType.isSelected()) {
selectShape.addView(createShapeItemView(backgroundType, selectShape),
new FlowLayout.LayoutParams(0, 0, true));
new FlowLayout.LayoutParams(0, 0));
selectShape.setHorizontalAutoSpacing(true);
}
}
}
@ -644,7 +645,8 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment implemen
horizontalSelectionAdapter.notifyDataSetChanged();
iconCategoriesRecyclerView.smoothScrollToPosition(horizontalSelectionAdapter.getItemPositionByTitle(selectedIconCategory));
for (String name : iconNameList) {
selectIcon.addView(createIconItemView(name, selectIcon), new FlowLayout.LayoutParams(0, 0, true));
selectIcon.addView(createIconItemView(name, selectIcon), new FlowLayout.LayoutParams(0, 0));
selectIcon.setHorizontalAutoSpacing(true);
}
}
}

View file

@ -294,8 +294,8 @@ public class PublicTransportCard extends BaseCard {
if (walkingSegment != null) {
double walkTime = walkingSegment.getRoutingTime();
if (walkTime > 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));
}
}

View file

@ -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<Integer> 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);
}

View file

@ -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);

View file

@ -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;
}
}
}