Merge pull request #10993 from osmandapp/fix-alignment

Fix element's alignment: icons and colors
This commit is contained in:
Vitaliy 2021-03-06 21:21:33 +02:00 committed by GitHub
commit fa38d19aff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 180 additions and 157 deletions

View file

@ -1,17 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<com.google.android.material.internal.FlowLayout
android:id="@+id/select_color"
android:layout_width="match_parent"
<net.osmand.plus.widgets.FlowLayout
android:id="@+id/select_custom_color"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/content_padding_small"
android:layout_marginLeft="@dimen/content_padding_small"
android:layout_marginStart="@dimen/list_content_padding"
android:layout_marginLeft="@dimen/list_content_padding"
android:layout_marginEnd="@dimen/list_content_padding"
android:layout_marginRight="@dimen/list_content_padding" />
<include
layout="@layout/simple_divider_item"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginStart="@dimen/list_content_padding"
android:layout_marginLeft="@dimen/list_content_padding"
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="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/list_content_padding"
android:layout_marginLeft="@dimen/list_content_padding"
android:layout_marginEnd="@dimen/list_content_padding"
android:layout_marginRight="@dimen/list_content_padding" />
</LinearLayout>

View file

@ -2,40 +2,30 @@
<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">
android:layout_height="wrap_content">
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/outline"
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
android:id="@+id/outline"
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
android:id="@+id/background"
android:layout_width="@dimen/favorites_icon_size"
android:layout_height="@dimen/favorites_icon_size"
android:layout_gravity="center"
android:padding="@dimen/favorites_icon_padding"
app:srcCompat="@drawable/bg_point_circle" />
<androidx.appcompat.widget.AppCompatImageView
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"
app:srcCompat="@drawable/bg_point_circle" />
<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" />
<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>

View file

@ -84,6 +84,7 @@
android:drawableEnd="@drawable/btn_circle_transparent_full"
android:drawableRight="@drawable/btn_circle_transparent_full"
android:drawablePadding="@dimen/favorites_list_item_height"
android:imeOptions="actionDone"
android:inputType="textMultiLine"
android:maxLines="4"
android:minHeight="@dimen/favorites_list_item_height"
@ -93,7 +94,6 @@
android:paddingRight="@dimen/content_padding_small"
android:scrollHorizontally="false"
android:textSize="@dimen/default_list_text_size"
android:imeOptions="actionDone"
tools:text="@string/lorem_ipsum" />
</com.google.android.material.textfield.TextInputLayout>
@ -137,6 +137,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="start"
android:imeOptions="actionDone"
android:maxLines="4"
android:minHeight="@dimen/favorites_list_item_height"
android:paddingStart="@dimen/content_padding_small"
@ -144,7 +145,6 @@
android:paddingEnd="@dimen/content_padding_small"
android:paddingRight="@dimen/content_padding_small"
android:textSize="@dimen/default_list_text_size"
android:imeOptions="actionDone"
tools:text="@string/lorem_ipsum" />
</com.google.android.material.textfield.TextInputLayout>
@ -248,6 +248,7 @@
android:drawablePadding="8dp"
android:duplicateParentState="true"
android:gravity="center"
android:imeOptions="actionDone"
android:paddingStart="@dimen/content_padding_half"
android:paddingLeft="@dimen/content_padding_half"
android:paddingEnd="@dimen/content_padding_half"
@ -255,7 +256,6 @@
android:text="@string/add_description"
android:textSize="@dimen/default_desc_text_size"
osmand:typeface="@string/font_roboto_medium"
android:imeOptions="actionDone"
tools:text="@string/add_description" />
<View
@ -402,9 +402,11 @@
android:id="@+id/select_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/content_padding_small"
android:layout_marginLeft="@dimen/content_padding_small"
android:layout_marginStart="@dimen/content_padding"
android:layout_marginLeft="@dimen/content_padding"
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" />
<View
@ -451,10 +453,9 @@
android:id="@+id/select_color"
android:layout_width="match_parent"
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_marginBottom="@dimen/content_padding_half" />
android:layout_marginBottom="@dimen/content_padding_half"
android:orientation="horizontal" />
<View
android:layout_width="match_parent"
@ -500,9 +501,11 @@
android:id="@+id/select_shape"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/content_padding_small"
android:layout_marginLeft="@dimen/content_padding_small"
android:layout_marginStart="@dimen/content_padding"
android:layout_marginLeft="@dimen/content_padding"
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:gravity="start" />

View file

@ -21,8 +21,8 @@
android:layout_height="wrap_content"
android:orientation="horizontal"
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
android:id="@+id/recycler_view"
@ -41,13 +41,15 @@
</LinearLayout>
<com.google.android.material.internal.FlowLayout
<net.osmand.plus.widgets.FlowLayout
android:id="@+id/select_color"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/content_padding_small"
android:layout_marginLeft="@dimen/content_padding_small"
android:layout_marginStart="@dimen/content_padding"
android:layout_marginLeft="@dimen/content_padding"
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" />
</LinearLayout>

View file

@ -50,7 +50,6 @@ import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.BaseOsmAndFragment;
import net.osmand.plus.base.BottomSheetDialogFragment;
import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.helpers.ColorDialogs;
import net.osmand.plus.mapcontextmenu.MapContextMenu;
@ -68,6 +67,7 @@ import org.json.JSONObject;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
@ -126,7 +126,7 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment implemen
@SuppressLint("ClickableViewAccessibility")
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Bundle savedInstanceState) {
app = requireMyApplication();
nightMode = app.getDaynightHelper().isNightModeForMapControls();
@ -146,7 +146,7 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment implemen
selectedShape = getBackgroundType();
selectedIcon = getIconId();
Toolbar toolbar = (Toolbar) view.findViewById(R.id.toolbar);
Toolbar toolbar = view.findViewById(R.id.toolbar);
toolbar.setBackgroundColor(ContextCompat.getColor(requireContext(),
nightMode ? R.color.app_bar_color_dark : R.color.list_background_color_light));
toolbar.setTitle(getToolbarTitle());
@ -161,7 +161,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();
scrollView.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
@Override
@ -177,14 +177,14 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment implemen
});
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
? 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));
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));
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));
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)));
@ -193,7 +193,7 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment implemen
@Override
public void onClick(View v) {
FragmentManager fragmentManager = getFragmentManager();
DialogFragment dialogFragment = createSelectCategoryDialog();
DialogFragment dialogFragment = createSelectCategoryDialog();
if (fragmentManager != null && dialogFragment != null) {
dialogFragment.show(fragmentManager, SelectFavoriteCategoryBottomSheet.class.getSimpleName());
}
@ -220,10 +220,10 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment implemen
UiUtilities.setupDialogButton(nightMode, cancelButton, UiUtilities.DialogButtonType.SECONDARY, R.string.shared_string_cancel);
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));
nameEdit = (EditText) view.findViewById(R.id.name_edit);
nameEdit = view.findViewById(R.id.name_edit);
nameEdit.setText(getNameInitValue());
nameEdit.addTextChangedListener(new TextWatcher() {
@Override
@ -241,15 +241,15 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment implemen
});
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);
if (categoryEdit != null) {
AndroidUtils.setTextPrimaryColor(view.getContext(), categoryEdit, nightMode);
categoryEdit.setText(getCategoryInitValue());
}
descriptionEdit = (EditText) view.findViewById(R.id.description_edit);
addressEdit = (EditText) view.findViewById(R.id.address_edit);
descriptionEdit = view.findViewById(R.id.description_edit);
addressEdit = view.findViewById(R.id.address_edit);
AndroidUtils.setTextPrimaryColor(view.getContext(), descriptionEdit, nightMode);
AndroidUtils.setTextPrimaryColor(view.getContext(), addressEdit, nightMode);
AndroidUtils.setHintTextSecondaryColor(view.getContext(), descriptionEdit, nightMode);
@ -260,7 +260,7 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment implemen
descriptionCaption = view.findViewById(R.id.description);
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);
deleteAddressIcon = view.findViewById(R.id.delete_address_icon);
deleteAddressIcon.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_trash_basket_16, activeColorResId));
@ -524,6 +524,7 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment implemen
if (backgroundType.isSelected()) {
selectShape.addView(createShapeItemView(backgroundType, selectShape),
new FlowLayout.LayoutParams(0, 0));
selectShape.setHorizontalAutoSpacing(true);
}
}
}
@ -564,7 +565,7 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment implemen
((TextView) rootView.findViewById(R.id.shape_name)).setText(backgroundType.getNameId());
ImageView background = newShape.findViewById(R.id.background);
background.setImageDrawable(UiUtilities.tintDrawable(AppCompatResources.getDrawable(app, backgroundType.getIconId()),
selectedColor));
selectedColor));
selectedShape = backgroundType;
setBackgroundType(backgroundType);
updateNameIcon();
@ -572,9 +573,9 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment implemen
private void setShapeSelectorBackground(BackgroundType backgroundType, ImageView background) {
background.setImageDrawable(UiUtilities.tintDrawable(AppCompatResources.getDrawable(app, backgroundType.getIconId()),
ContextCompat.getColor(app,
nightMode ? R.color.inactive_buttons_and_links_bg_dark
: R.color.inactive_buttons_and_links_bg_light)));
ContextCompat.getColor(app,
nightMode ? R.color.inactive_buttons_and_links_bg_dark
: R.color.inactive_buttons_and_links_bg_light)));
}
private String getInitCategory() {
@ -646,7 +647,9 @@ 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));
int minimalPaddingBetweenIcon = app.getResources().getDimensionPixelSize(R.dimen.favorites_select_icon_button_right_padding);
selectIcon.addView(createIconItemView(name, selectIcon), new FlowLayout.LayoutParams(minimalPaddingBetweenIcon, 0));
selectIcon.setHorizontalAutoSpacing(true);
}
}
}
@ -704,9 +707,9 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment implemen
private void setIconSelectorBackground(ImageView backgroundCircle) {
backgroundCircle.setImageDrawable(UiUtilities.tintDrawable(AppCompatResources.getDrawable(app, R.drawable.bg_point_circle),
ContextCompat.getColor(app, nightMode
? R.color.inactive_buttons_and_links_bg_dark
: R.color.inactive_buttons_and_links_bg_light)));
ContextCompat.getColor(app, nightMode
? R.color.inactive_buttons_and_links_bg_dark
: R.color.inactive_buttons_and_links_bg_light)));
}
private void updateNameIcon() {
@ -723,7 +726,7 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment implemen
byte[] buffer = new byte[size];
is.read(buffer);
is.close();
json = new String(buffer, "UTF-8");
json = new String(buffer, StandardCharsets.UTF_8);
} catch (IOException ex) {
ex.printStackTrace();
return null;

View file

@ -432,6 +432,7 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment implements O
for (int iconRes : icons) {
View iconItem = createIconItemView(iconRes, iconItems);
iconItems.addView(iconItem, new FlowLayout.LayoutParams(0, 0));
iconItems.setHorizontalAutoSpacing(true);
}
setIconColor(changedProfile.iconRes);
} else if (LOCATION_ICON_ITEMS.equals(preference.getKey())) {

View file

@ -3,13 +3,13 @@ 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 com.google.android.material.internal.FlowLayout;
import androidx.annotation.ColorInt;
import androidx.core.content.ContextCompat;
import androidx.core.graphics.ColorUtils;
import androidx.fragment.app.Fragment;
import net.osmand.AndroidUtils;
import net.osmand.PlatformUtil;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
@ -19,6 +19,8 @@ import net.osmand.plus.routepreparationmenu.cards.BaseCard;
import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.settings.backend.ListStringPreference;
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;
@ -26,11 +28,6 @@ import org.apache.commons.logging.Log;
import java.util.ArrayList;
import java.util.List;
import androidx.annotation.ColorInt;
import androidx.core.content.ContextCompat;
import androidx.core.graphics.ColorUtils;
import androidx.fragment.app.Fragment;
public class ColorsCard extends BaseCard implements ColorPickerListener {
public static final int MAX_CUSTOM_COLORS = 6;
@ -40,13 +37,13 @@ public class ColorsCard extends BaseCard implements ColorPickerListener {
public static final int INVALID_VALUE = -1;
private Fragment targetFragment;
private final Fragment targetFragment;
private ApplicationMode appMode;
private ListStringPreference colorsListPreference;
private List<Integer> colors;
private List<Integer> customColors;
private final List<Integer> colors;
private final List<Integer> customColors;
private int selectedColor;
@ -94,35 +91,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));
selectCustomColor.addView(createColorItemView(color, selectCustomColor, true), new LayoutParams(minimalPaddingBetweenIcon, 0));
}
if (customColors.size() < 6) {
selectColor.addView(createAddCustomColorItemView(selectColor));
selectCustomColor.addView(createAddCustomColorItemView(selectCustomColor), new LayoutParams(minimalPaddingBetweenIcon, 0));
}
selectColor.addView(createDividerView(selectColor));
FlowLayout selectDefaultColor = view.findViewById(R.id.select_default_color);
selectDefaultColor.removeAllViews();
selectDefaultColor.setHorizontalAutoSpacing(true);
for (int color : colors) {
selectColor.addView(createColorItemView(color, selectColor, false));
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);
}
@ -144,7 +147,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();
@ -194,18 +197,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

@ -1,7 +1,6 @@
package net.osmand.plus.widgets;
import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
@ -11,22 +10,7 @@ import net.osmand.AndroidUtils;
public class FlowLayout extends ViewGroup {
private int line_height;
public static class LayoutParams extends ViewGroup.LayoutParams {
final int horizontal_spacing;
final int vertical_spacing;
/**
* @param horizontal_spacing Pixels between items, horizontally
* @param vertical_spacing Pixels between items, vertically
*/
public LayoutParams(int horizontal_spacing, int vertical_spacing) {
super(0, 0);
this.horizontal_spacing = horizontal_spacing;
this.vertical_spacing = vertical_spacing;
}
}
private boolean horizontalAutoSpacing;
public FlowLayout(Context context) {
super(context);
@ -36,16 +20,22 @@ public class FlowLayout extends ViewGroup {
super(context, attrs);
}
// If true, available horizontal space is added to items horizontalSpacing to fit the screen width.
public void setHorizontalAutoSpacing(boolean horizontalAutoSpacing) {
this.horizontalAutoSpacing = horizontalAutoSpacing;
}
@Override
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();
int height = MeasureSpec.getSize(heightMeasureSpec) - getPaddingTop() - getPaddingBottom();
final int count = getChildCount();
int line_height = 0;
int xpos = getPaddingLeft();
int ypos = getPaddingTop();
int horizontalPosition = getPaddingLeft();
int verticalPosition = getPaddingTop();
int childHeightMeasureSpec;
if (MeasureSpec.getMode(heightMeasureSpec) == MeasureSpec.AT_MOST) {
@ -59,22 +49,22 @@ public class FlowLayout extends ViewGroup {
if (child.getVisibility() != GONE) {
final LayoutParams lp = (LayoutParams) child.getLayoutParams();
child.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.AT_MOST), childHeightMeasureSpec);
final int childw = child.getMeasuredWidth();
line_height = Math.max(line_height, child.getMeasuredHeight() + lp.vertical_spacing);
if (xpos + childw > width) {
xpos = getPaddingLeft();
ypos += line_height;
final int childWidth = child.getMeasuredWidth();
line_height = Math.max(line_height, child.getMeasuredHeight() + lp.verticalSpacing);
if (horizontalPosition + childWidth > width) {
horizontalPosition = getPaddingLeft();
verticalPosition += line_height;
}
xpos += childw + lp.horizontal_spacing;
horizontalPosition += childWidth + lp.horizontalSpacing;
}
}
this.line_height = line_height;
if (MeasureSpec.getMode(heightMeasureSpec) == MeasureSpec.UNSPECIFIED) {
height = ypos + line_height;
height = verticalPosition + line_height;
} else if (MeasureSpec.getMode(heightMeasureSpec) == MeasureSpec.AT_MOST) {
if (ypos + line_height < height) {
height = ypos + line_height;
if (verticalPosition + line_height < height) {
height = verticalPosition + line_height;
}
}
setMeasuredDimension(width, height);
@ -95,30 +85,55 @@ public class FlowLayout extends ViewGroup {
final int count = getChildCount();
final int width = r - l;
boolean isLayoutRtl = AndroidUtils.isLayoutRtl(getContext());
int xpos = isLayoutRtl ? width - getPaddingRight() : getPaddingLeft();
int ypos = getPaddingTop();
int horizontalPosition = isLayoutRtl ? width - getPaddingRight() : getPaddingLeft();
int verticalPosition = getPaddingTop();
for (int i = 0; i < count; i++) {
final View child = getChildAt(i);
if (child.getVisibility() != GONE) {
final int childw = child.getMeasuredWidth();
final int childh = child.getMeasuredHeight();
final LayoutParams lp = (LayoutParams) child.getLayoutParams();
final int childWidth = child.getMeasuredWidth();
final int childHeight = child.getMeasuredHeight();
int freeSizeSpacing = getFreeSizeSpacing(width, lp, childWidth);
if (isLayoutRtl) {
if (xpos - childw < l) {
xpos = width - getPaddingRight();
ypos += line_height;
if (horizontalPosition - childWidth < getPaddingLeft()) {
horizontalPosition = width - getPaddingRight();
verticalPosition += line_height;
}
child.layout(xpos - childw, ypos, xpos, ypos + childh);
xpos -= childw + lp.horizontal_spacing;
child.layout(horizontalPosition - childWidth, verticalPosition, horizontalPosition, verticalPosition + childHeight);
horizontalPosition -= childWidth + freeSizeSpacing;
} else {
if (xpos + childw > width) {
xpos = getPaddingLeft();
ypos += line_height;
if (horizontalPosition + childWidth > width) {
horizontalPosition = getPaddingLeft();
verticalPosition += line_height;
}
child.layout(xpos, ypos, xpos + childw, ypos + childh);
xpos += childw + lp.horizontal_spacing;
child.layout(horizontalPosition, verticalPosition, horizontalPosition + childWidth, verticalPosition + childHeight);
horizontalPosition += childWidth + freeSizeSpacing;
}
}
}
}
private int getFreeSizeSpacing(int width, LayoutParams lp, int childWidth) {
int itemsCount = width / (childWidth + lp.horizontalSpacing);
if (itemsCount > 1 && horizontalAutoSpacing) {
return (width % childWidth / (itemsCount - 1)) + lp.horizontalSpacing;
}
return lp.horizontalSpacing;
}
public static class LayoutParams extends ViewGroup.LayoutParams {
final int horizontalSpacing;
final int verticalSpacing;
/**
* @param horizontalSpacing Pixels between items, horizontally
* @param verticalSpacing Pixels between items, vertically
*/
public LayoutParams(int horizontalSpacing, int verticalSpacing) {
super(0, 0);
this.horizontalSpacing = horizontalSpacing;
this.verticalSpacing = verticalSpacing;
}
}
}