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"> android:orientation="vertical">
<net.osmand.plus.widgets.FlowLayout <net.osmand.plus.widgets.FlowLayout
android:id="@+id/select_color" android:id="@+id/select_custom_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"
android:layout_marginLeft="@dimen/content_padding" <include
android:layout_marginEnd="@dimen/content_padding" layout="@layout/simple_divider_item"
android:layout_marginRight="@dimen/content_padding" android:layout_width="match_parent"
android:layout_height="1dp"
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" />
<net.osmand.plus.widgets.FlowLayout
android:id="@+id/select_default_color"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout> </LinearLayout>

View file

@ -2,40 +2,30 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="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 <androidx.appcompat.widget.AppCompatImageView
android:layout_width="wrap_content" android:id="@+id/outline"
android:layout_height="wrap_content"> android:layout_width="@dimen/favorites_icon_outline_size"
android:layout_height="@dimen/favorites_icon_outline_size"
android:visibility="invisible"
app:srcCompat="@drawable/bg_point_circle_contour" />
<androidx.appcompat.widget.AppCompatImageView <androidx.appcompat.widget.AppCompatImageView
android:id="@+id/outline" android:id="@+id/background"
android:layout_width="@dimen/favorites_icon_outline_size" android:layout_width="@dimen/favorites_icon_size"
android:layout_height="@dimen/favorites_icon_outline_size" android:layout_height="@dimen/favorites_icon_size"
android:visibility="invisible" android:layout_gravity="center"
app:srcCompat="@drawable/bg_point_circle_contour" /> android:padding="@dimen/favorites_icon_padding"
app:srcCompat="@drawable/bg_point_circle" />
<androidx.appcompat.widget.AppCompatImageView <androidx.appcompat.widget.AppCompatImageView
android:id="@+id/background" android:id="@+id/icon"
android:layout_width="@dimen/favorites_icon_size" android:layout_width="@dimen/standard_icon_size"
android:layout_height="@dimen/favorites_icon_size" android:layout_height="@dimen/standard_icon_size"
android:padding="@dimen/favorites_icon_padding" android:layout_gravity="center"
android:layout_gravity="center" android:clickable="false"
app:srcCompat="@drawable/bg_point_circle" /> android:visibility="gone"
app:srcCompat="@drawable/mx_special_star_stroked" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/icon"
android:layout_width="@dimen/standard_icon_size"
android:layout_height="@dimen/standard_icon_size"
android:layout_gravity="center"
android:clickable="false"
android:visibility="gone"
app:srcCompat="@drawable/mx_special_star_stroked"
/>
</FrameLayout>
</FrameLayout> </FrameLayout>

View file

@ -449,12 +449,15 @@
osmand:typeface="@string/font_roboto_medium" /> osmand:typeface="@string/font_roboto_medium" />
</LinearLayout> </LinearLayout>
<net.osmand.plus.widgets.FlowLayout <LinearLayout
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_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"
android:orientation="horizontal"
android:layout_marginStart="@dimen/content_padding_small" />
<View <View
android:layout_width="match_parent" android:layout_width="match_parent"

View file

@ -22,6 +22,7 @@ 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;
@ -476,9 +477,8 @@ 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);
FlowLayout selectColor = view.findViewById(R.id.select_color); LinearLayout 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));
} }
} }
@ -521,7 +521,8 @@ 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, true)); new FlowLayout.LayoutParams(0, 0));
selectShape.setHorizontalAutoSpacing(true);
} }
} }
} }
@ -644,7 +645,8 @@ 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, 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) { 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, false)); routesBadges.addView(createWalkRouteBadge(walkingSegment, badgesRowClickable), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing));
routesBadges.addView(createArrow(), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing, false)); routesBadges.addView(createArrow(), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing));
} }
} 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, false)); routesBadges.addView(createWalkRouteBadge(walkTime, start, end, badgesRowClickable), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing));
routesBadges.addView(createArrow(), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing, false)); 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()) { if (iterator.hasNext()) {
routesBadges.addView(createArrow(), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing, false)); routesBadges.addView(createArrow(), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing));
} 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, false)); routesBadges.addView(createArrow(), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing));
routesBadges.addView(createWalkRouteBadge(walkingSegment, badgesRowClickable), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing, false)); routesBadges.addView(createWalkRouteBadge(walkingSegment, badgesRowClickable), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing));
} }
} 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, false)); routesBadges.addView(createArrow(), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing));
routesBadges.addView(createWalkRouteBadge(walkTime, start, end, badgesRowClickable)); routesBadges.addView(createWalkRouteBadge(walkTime, start, end, badgesRowClickable));
} }
} }

View file

@ -413,7 +413,8 @@ 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, true)); colorItems.addView(colorItem, new FlowLayout.LayoutParams(0, 0));
colorItems.setHorizontalAutoSpacing(true);
} }
updateColorSelector(changedProfile.color); updateColorSelector(changedProfile.color);
} else if (ICON_ITEMS.equals(preference.getKey())) { } else if (ICON_ITEMS.equals(preference.getKey())) {
@ -422,7 +423,8 @@ 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,true)); iconItems.addView(iconItem, new FlowLayout.LayoutParams(0, 0));
iconItems.setHorizontalAutoSpacing(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 +432,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, false)); locationIconItems.addView(iconItemView, new FlowLayout.LayoutParams(0, 0));
} }
updateLocationIconSelector(changedProfile.locationIcon); updateLocationIconSelector(changedProfile.locationIcon);
} else if (NAV_ICON_ITEMS.equals(preference.getKey())) { } else if (NAV_ICON_ITEMS.equals(preference.getKey())) {
@ -438,7 +440,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, false)); navIconItems.addView(iconItemView, new FlowLayout.LayoutParams(0, 0));
} }
updateNavigationIconSelector(changedProfile.navigationIcon); updateNavigationIconSelector(changedProfile.navigationIcon);
} }

View file

@ -3,9 +3,7 @@ package net.osmand.plus.track;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout;
import androidx.annotation.ColorInt; import androidx.annotation.ColorInt;
import androidx.annotation.NonNull; 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.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.plus.widgets.FlowLayout;
import net.osmand.plus.widgets.FlowLayout.LayoutParams;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
@ -87,35 +86,41 @@ public class ColorsCard extends BaseCard implements ColorPickerListener {
@Override @Override
protected void updateContent() { protected void updateContent() {
createColorSelector(); createColorSelector();
updateColorSelector(selectedColor, view); updateColorSelector(selectedColor);
} }
private void createColorSelector() { private void createColorSelector() {
FlowLayout selectColor = view.findViewById(R.id.select_color); FlowLayout selectCustomColor = view.findViewById(R.id.select_custom_color);
selectColor.removeAllViews(); selectCustomColor.removeAllViews();
selectCustomColor.setHorizontalAutoSpacing(true);
int minimalPaddingBetweenIcon = app.getResources().getDimensionPixelSize(R.dimen.favorites_select_icon_button_right_padding);
for (int color : customColors) { 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) { 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) { 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) { private void updateColorSelector(int color) {
View oldColor = rootView.findViewWithTag(selectedColor); View oldColor = view.findViewWithTag(selectedColor);
if (oldColor != null) { if (oldColor != null) {
oldColor.findViewById(R.id.outline).setVisibility(View.INVISIBLE); oldColor.findViewById(R.id.outline).setVisibility(View.INVISIBLE);
ImageView icon = oldColor.findViewById(R.id.icon); 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) { if (newColor != null) {
newColor.findViewById(R.id.outline).setVisibility(View.VISIBLE); newColor.findViewById(R.id.outline).setVisibility(View.VISIBLE);
} }
@ -137,7 +142,7 @@ public class ColorsCard extends BaseCard implements ColorPickerListener {
backgroundCircle.setOnClickListener(new View.OnClickListener() { backgroundCircle.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
updateColorSelector(color, rootView); updateColorSelector(color);
selectedColor = color; selectedColor = color;
CardListener listener = getListener(); CardListener listener = getListener();
@ -187,17 +192,7 @@ public class ColorsCard extends BaseCard implements ColorPickerListener {
return colorItemView; return colorItemView;
} }
private View createDividerView(FlowLayout rootView) { private View createCircleView(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) {
LayoutInflater themedInflater = UiUtilities.getInflater(view.getContext(), nightMode); LayoutInflater themedInflater = UiUtilities.getInflater(view.getContext(), nightMode);
View circleView = themedInflater.inflate(R.layout.point_editor_button, rootView, false); View circleView = themedInflater.inflate(R.layout.point_editor_button, rootView, false);
ImageView outline = circleView.findViewById(R.id.outline); ImageView outline = circleView.findViewById(R.id.outline);

View file

@ -10,23 +10,21 @@ import net.osmand.AndroidUtils;
public class FlowLayout extends ViewGroup { public class FlowLayout extends ViewGroup {
private int line_height; private int line_height;
private boolean horizontalAutoSpacing;
public static class LayoutParams extends ViewGroup.LayoutParams { public static class LayoutParams extends ViewGroup.LayoutParams {
final int horizontal_spacing; final int horizontalSpacing;
final int vertical_spacing; final int verticalSpacing;
final boolean isHorizontalAutoSpacing;
/** /**
* @param horizontal_spacing Pixels between items, horizontally * @param horizontalSpacing Pixels between items, horizontally
* @param vertical_spacing Pixels between items, vertically * @param verticalSpacing Pixels between items, vertically
* @param isHorizontalAutoSpacing Pixels between items to fit screen width. When is enabled horizontal_spacing does not take into account.
*/ */
public LayoutParams(int horizontal_spacing, int vertical_spacing, boolean isHorizontalAutoSpacing) { public LayoutParams(int horizontalSpacing, int verticalSpacing) {
super(0, 0); super(0, 0);
this.horizontal_spacing = horizontal_spacing; this.horizontalSpacing = horizontalSpacing;
this.vertical_spacing = vertical_spacing; this.verticalSpacing = verticalSpacing;
this.isHorizontalAutoSpacing = isHorizontalAutoSpacing;
} }
} }
@ -38,6 +36,11 @@ public class FlowLayout extends ViewGroup {
super(context, attrs); super(context, attrs);
} }
// If true available horizontal space is added to items horizontalSpacing.
public void setHorizontalAutoSpacing(boolean horizontalAutoSpacing) {
this.horizontalAutoSpacing = horizontalAutoSpacing;
}
@Override @Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
if ((MeasureSpec.getMode(widthMeasureSpec) == MeasureSpec.UNSPECIFIED)) if ((MeasureSpec.getMode(widthMeasureSpec) == MeasureSpec.UNSPECIFIED))
@ -63,12 +66,12 @@ public class FlowLayout extends ViewGroup {
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), childHeightMeasureSpec);
final int childWidth = 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.verticalSpacing);
if (horizontalPosition + childWidth > width) { if (horizontalPosition + childWidth > width) {
horizontalPosition = getPaddingLeft(); horizontalPosition = getPaddingLeft();
verticalPosition += line_height; verticalPosition += line_height;
} }
horizontalPosition += childWidth + lp.horizontal_spacing; horizontalPosition += childWidth + lp.horizontalSpacing;
} }
} }
@ -85,7 +88,7 @@ public class FlowLayout extends ViewGroup {
@Override @Override
protected ViewGroup.LayoutParams generateDefaultLayoutParams() { protected ViewGroup.LayoutParams generateDefaultLayoutParams() {
return new LayoutParams(1, 1, false); // default of 1px spacing return new LayoutParams(1, 1); // default of 1px spacing
} }
@Override @Override
@ -113,21 +116,21 @@ public class FlowLayout extends ViewGroup {
} else { } else {
freeSizeSpacing = width % childWidth / itemsCount; freeSizeSpacing = width % childWidth / itemsCount;
} }
if (lp.isHorizontalAutoSpacing) { if (horizontalAutoSpacing) {
if (isLayoutRtl) { if (isLayoutRtl) {
if (horizontalPosition - childWidth < getPaddingLeft()) { if (horizontalPosition - childWidth < getPaddingLeft()) {
horizontalPosition = width - getPaddingRight(); horizontalPosition = width - getPaddingRight();
verticalPosition += line_height; verticalPosition += line_height;
} }
child.layout(horizontalPosition - childWidth, verticalPosition, horizontalPosition, verticalPosition + childHeight); child.layout(horizontalPosition - childWidth, verticalPosition, horizontalPosition, verticalPosition + childHeight);
horizontalPosition -= childWidth + lp.horizontal_spacing + freeSizeSpacing; horizontalPosition -= childWidth + lp.horizontalSpacing + freeSizeSpacing;
} else { } else {
if (horizontalPosition + childWidth > width) { if (horizontalPosition + childWidth > width) {
horizontalPosition = getPaddingLeft(); horizontalPosition = getPaddingLeft();
verticalPosition += line_height; verticalPosition += line_height;
} }
child.layout(horizontalPosition, verticalPosition, horizontalPosition + childWidth, verticalPosition + childHeight); child.layout(horizontalPosition, verticalPosition, horizontalPosition + childWidth, verticalPosition + childHeight);
horizontalPosition += childWidth + lp.horizontal_spacing + freeSizeSpacing; horizontalPosition += childWidth + lp.horizontalSpacing + freeSizeSpacing;
} }
} else { } else {
if (isLayoutRtl) { if (isLayoutRtl) {
@ -136,14 +139,14 @@ public class FlowLayout extends ViewGroup {
verticalPosition += line_height; verticalPosition += line_height;
} }
child.layout(horizontalPosition - childWidth, verticalPosition, horizontalPosition, verticalPosition + childHeight); child.layout(horizontalPosition - childWidth, verticalPosition, horizontalPosition, verticalPosition + childHeight);
horizontalPosition -= childWidth + lp.horizontal_spacing; horizontalPosition -= childWidth + lp.horizontalSpacing;
} else { } else {
if (horizontalPosition + childWidth > width) { if (horizontalPosition + childWidth > width) {
horizontalPosition = getPaddingLeft(); horizontalPosition = getPaddingLeft();
verticalPosition += line_height; verticalPosition += line_height;
} }
child.layout(horizontalPosition, verticalPosition, horizontalPosition + childWidth, verticalPosition + childHeight); child.layout(horizontalPosition, verticalPosition, horizontalPosition + childWidth, verticalPosition + childHeight);
horizontalPosition += childWidth + lp.horizontal_spacing; horizontalPosition += childWidth + lp.horizontalSpacing;
} }
} }
} }