Remove unnecessary changes

This commit is contained in:
Vitaliy 2020-09-16 13:18:56 +03:00
parent 6e294d931b
commit f03f30469f
10 changed files with 102 additions and 136 deletions

View file

@ -34,20 +34,23 @@
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/color_hex_text_input"
style="@style/CompactInputLayoutStyle"
style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
app:boxBackgroundColor="@color/material_text_input_layout_bg"
app:hintEnabled="false"
app:prefixText="#">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/color_hex_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:maxLines="4"
android:inputType="text"
android:maxLines="1"
android:minHeight="@dimen/bottom_sheet_list_item_height"
android:paddingTop="@dimen/content_padding_small"
android:paddingBottom="@dimen/content_padding_small"
android:paddingStart="@dimen/content_padding_small"
android:paddingLeft="@dimen/content_padding_small"
android:paddingEnd="@dimen/content_padding_small"

View file

@ -793,19 +793,4 @@
<item name="hintTextColor">?android:textColorSecondary</item>
</style>
<style name="CompactInputLayoutStyle" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense">
<item name="materialThemeOverlay">@style/ThemeCompactOverlayOutlinedDense</item>
<item name="hintEnabled">false</item>
</style>
<style name="ThemeCompactOverlayOutlinedDense">
<item name="editTextStyle">@style/CompactTextInputEditTextOutlinedBoxDense</item>
</style>
<style name="CompactTextInputEditTextOutlinedBoxDense" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense">
<item name="android:paddingTop">@dimen/content_padding_half</item>
<item name="android:paddingBottom">@dimen/content_padding_half</item>
</style>
</resources>

View file

@ -63,7 +63,6 @@ import androidx.core.view.ViewCompat;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.base.OnVisibilityChangeListener;
import net.osmand.util.Algorithms;
import java.io.File;
@ -603,12 +602,6 @@ public class AndroidUtils {
return coordinates;
}
public static boolean isPointInsideView(@NonNull View view, float x, float y) {
boolean matchVertical = y >= view.getY() && y <= view.getY() + view.getHeight();
boolean mathHorizontal = x >= view.getX() && x <= view.getX() + view.getWidth();
return matchVertical && mathHorizontal;
}
public static void enterToFullScreen(Activity activity, View view) {
if (Build.VERSION.SDK_INT >= 21) {
requestLayout(view);
@ -896,20 +889,4 @@ public class AndroidUtils {
}
return builder;
}
public static void addVisibilityChangeListener(final @NonNull View parent,
final @NonNull View v,
final @NonNull OnVisibilityChangeListener listener) {
parent.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
int visibility = v.getVisibility();
@Override
public void onGlobalLayout() {
if (visibility != v.getVisibility()) {
visibility = v.getVisibility();
listener.onVisibilityChange(visibility);
}
}
});
}
}

View file

@ -24,7 +24,6 @@ import android.view.animation.DecelerateInterpolator;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.OverScroller;
import android.widget.ScrollView;
import android.widget.Toast;
import androidx.annotation.IdRes;
@ -47,10 +46,11 @@ import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.mapcontextmenu.InterceptorLinearLayout;
import net.osmand.plus.views.controls.HorizontalSwipeConfirm;
import net.osmand.plus.views.controls.SingleTapConfirm;
import static net.osmand.plus.mapcontextmenu.MapContextMenuFragment.CURRENT_Y_UNDEFINED;
public abstract class ContextMenuFragment extends BaseOsmAndFragment implements OnNeedScrollUiAdapter {
public abstract class ContextMenuFragment extends BaseOsmAndFragment {
public static class MenuState {
public static final int HEADER_ONLY = 1;
@ -68,7 +68,7 @@ public abstract class ContextMenuFragment extends BaseOsmAndFragment implements
private OnLayoutChangeListener containerLayoutListener;
private View topShadow;
private ViewGroup topView;
private ScrollView bottomScrollView;
private View bottomScrollView;
private LinearLayout cardsContainer;
private FrameLayout bottomContainer;
@ -248,7 +248,7 @@ public abstract class ContextMenuFragment extends BaseOsmAndFragment implements
return bottomContainer;
}
public ScrollView getBottomScrollView() {
public View getBottomScrollView() {
return bottomScrollView;
}
@ -316,11 +316,10 @@ public abstract class ContextMenuFragment extends BaseOsmAndFragment implements
processScreenHeight(container);
minHalfY = getMinHalfY(mapActivity);
final GestureDetector swipeDetector = new GestureDetector(app, new HorizontalSwipeConfirm(true));
final GestureDetector singleTapDetector = new GestureDetector(view.getContext(), new SingleTapConfirm());
final GestureDetector swipeDetector = new GestureDetector(view.getContext(), new HorizontalSwipeConfirm(true));
final OnTouchListener slideTouchListener = new OnTouchListener() {
private static final int SHORT_CLICK_DURATION_TOP_LIMIT = 500;
private float dy;
private float dyMain;
private float mDownY;
@ -332,9 +331,8 @@ public abstract class ContextMenuFragment extends BaseOsmAndFragment implements
private boolean slidingUp;
private boolean slidingDown;
private boolean isHolding;
private long downMotionEventTimeMs;
private boolean hasMoved;
{
OsmandApplication app = requireMyApplication();
@ -346,7 +344,15 @@ public abstract class ContextMenuFragment extends BaseOsmAndFragment implements
@Override
public boolean onTouch(View v, MotionEvent event) {
if (!hasMoved && getHeaderViewHeight() > 0 && event.getY() <= getHeaderViewHeight()) {
if (singleTapDetector.onTouchEvent(event)) {
moving = false;
onHeaderClick();
recycleVelocityTracker();
return true;
}
}
if (!portrait) {
if (swipeDetector.onTouchEvent(event)) {
dismiss();
@ -358,10 +364,7 @@ public abstract class ContextMenuFragment extends BaseOsmAndFragment implements
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
if (!isHolding) {
isHolding = true;
downMotionEventTimeMs = event.getDownTime();
}
hasMoved = false;
mDownY = event.getRawY();
dy = event.getY();
dyMain = getViewY();
@ -375,6 +378,7 @@ public abstract class ContextMenuFragment extends BaseOsmAndFragment implements
moving = true;
}
if (moving) {
hasMoved = true;
float y = event.getY();
float newY = getViewY() + (y - dy);
if (!portrait && newY > topScreenPosY) {
@ -398,9 +402,9 @@ public abstract class ContextMenuFragment extends BaseOsmAndFragment implements
break;
case MotionEvent.ACTION_UP:
isHolding = false;
if (moving) {
moving = false;
hasMoved = false;
int currentY = getViewY();
int fullScreenTopPosY = getMenuStatePosY(MenuState.FULL_SCREEN);
final VelocityTracker velocityTracker = this.velocityTracker;
@ -423,13 +427,12 @@ public abstract class ContextMenuFragment extends BaseOsmAndFragment implements
}
changeMenuState(currentY, slidingUp, slidingDown, true);
} else if (isShortClick(event.getEventTime())) {
onShortClick(v, event);
}
recycleVelocityTracker();
break;
case MotionEvent.ACTION_CANCEL:
moving = false;
hasMoved = false;
recycleVelocityTracker();
break;
@ -458,11 +461,6 @@ public abstract class ContextMenuFragment extends BaseOsmAndFragment implements
velocityTracker = null;
}
}
private boolean isShortClick(long upActionTime) {
long holdingDuration = upActionTime - downMotionEventTimeMs;
return holdingDuration <= SHORT_CLICK_DURATION_TOP_LIMIT;
}
};
if (mainView instanceof InterceptorLinearLayout) {
@ -485,8 +483,6 @@ public abstract class ContextMenuFragment extends BaseOsmAndFragment implements
return view;
}
protected void onShortClick(View v, MotionEvent event) { }
public float getToolbarAlpha(int y) {
float a = 0;
if (portrait) {
@ -923,6 +919,10 @@ public abstract class ContextMenuFragment extends BaseOsmAndFragment implements
runLayoutListener();
}
protected void onHeaderClick() {
}
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
protected void runLayoutListener() {
if (view != null) {
@ -1071,16 +1071,4 @@ public abstract class ContextMenuFragment extends BaseOsmAndFragment implements
return false;
}
}
@Override
public void onNeedVerticalScroll(String tag, int y) { }
public void verticalScrollToYPosition(final int y) {
bottomScrollView.post(new Runnable() {
@Override
public void run() {
bottomScrollView.smoothScrollTo(0, y);
}
});
}
}

View file

@ -1,5 +0,0 @@
package net.osmand.plus.base;
public interface OnNeedScrollUiAdapter {
void onNeedVerticalScroll(String tag, int yPosition);
}

View file

@ -1,5 +0,0 @@
package net.osmand.plus.base;
public interface OnVisibilityChangeListener {
void onVisibilityChange(int visibility);
}

View file

@ -55,7 +55,9 @@ public class CustomColorBottomSheet extends MenuBottomSheetDialogFragment implem
public void createMenuItems(Bundle savedInstanceState) {
if (savedInstanceState != null) {
newColor = savedInstanceState.getInt(NEW_SELECTED_COLOR);
prevColor = savedInstanceState.getInt(PREV_SELECTED_COLOR);
if (savedInstanceState.containsKey(PREV_SELECTED_COLOR)) {
prevColor = savedInstanceState.getInt(PREV_SELECTED_COLOR);
}
} else {
Bundle args = getArguments();
if (args != null) {

View file

@ -7,13 +7,13 @@ import android.os.Build;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import androidx.activity.OnBackPressedCallback;
import androidx.annotation.ColorInt;
@ -369,11 +369,8 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement
}
@Override
protected void onShortClick(View v, MotionEvent event) {
if (routeMenuTopShadowAll != null &&
AndroidUtils.isPointInsideView(routeMenuTopShadowAll, event.getX(), event.getY())) {
adjustMapPosition(getViewY());
}
protected void onHeaderClick() {
adjustMapPosition(getViewY());
}
private void adjustMapPosition(int y) {
@ -606,7 +603,21 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement
trackColoringCard.setListener(this);
cardsContainer.addView(trackColoringCard.build(mapActivity));
trackWidthCard = new TrackWidthCard(mapActivity, trackDrawInfo, this);
trackWidthCard = new TrackWidthCard(mapActivity, trackDrawInfo, new OnNeedScrollListener() {
@Override
public void onVerticalScrollNeeded(int y) {
View view = trackWidthCard.getView();
if (view != null) {
int resultYPosition = view.getTop() + y;
int dialogHeight = getInnerScrollableHeight();
ScrollView scrollView = (ScrollView) getBottomScrollView();
if (resultYPosition > (scrollView.getScrollY() + dialogHeight)) {
scrollView.smoothScrollTo(0, resultYPosition - dialogHeight);
}
}
}
});
trackWidthCard.setListener(this);
cardsContainer.addView(trackWidthCard.build(mapActivity));
}
@ -649,21 +660,6 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement
}
}
@Override
public void onNeedVerticalScroll(@NonNull String tag, int y) {
if (tag.equals(TrackWidthCard.TAG)) {
View trackWidthCardView = trackWidthCard.getView();
if (trackWidthCardView == null) return;
int currentScrollYPosition = getBottomScrollView().getScrollY();
int dialogHeight = getInnerScrollableHeight();
int resultYPosition = trackWidthCardView.getTop() + y;
if (resultYPosition > (currentScrollYPosition + dialogHeight)) {
verticalScrollToYPosition(resultYPosition - dialogHeight);
}
}
}
public int getInnerScrollableHeight() {
int totalScreenHeight = getViewHeight() - getMenuStatePosY(getCurrentMenuState());
int frameTotalHeight = routeMenuTopShadowAll.getHeight()
@ -723,4 +719,8 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement
return R.drawable.ic_action_track_line_thin_direction;
}
}
public interface OnNeedScrollListener {
void onVerticalScrollNeeded(int y);
}
}

View file

@ -23,6 +23,8 @@ import com.google.android.material.internal.FlowLayout;
import net.osmand.AndroidUtils;
import net.osmand.PlatformUtil;
import net.osmand.plus.GPXDatabase.GpxDataItem;
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
@ -294,16 +296,45 @@ public class TrackColoringCard extends BaseCard implements ColorPickerListener {
@Override
public void onColorSelected(Integer prevColor, int newColor) {
if (prevColor == null && customColors.size() < 6) {
customColors.add(newColor);
trackDrawInfo.setColor(newColor);
} else if (!Algorithms.isEmpty(customColors)) {
if (prevColor != null) {
int index = customColors.indexOf(prevColor);
if (index != INVALID_VALUE) {
customColors.set(index, newColor);
saveCustomColorsToTracks(prevColor, newColor);
}
if (trackDrawInfo.getColor() == prevColor) {
trackDrawInfo.setColor(newColor);
}
} else if (customColors.size() < 6) {
customColors.add(newColor);
trackDrawInfo.setColor(newColor);
}
saveCustomColors();
updateContent();
}
private void saveCustomColorsToTracks(int prevColor, int newColor) {
List<GpxDataItem> gpxDataItems = app.getGpxDbHelper().getItems();
for (GpxDataItem dataItem : gpxDataItems) {
if (prevColor == dataItem.getColor()) {
app.getGpxDbHelper().updateColor(dataItem, newColor);
}
}
updateContent();
List<SelectedGpxFile> files = app.getSelectedGpxHelper().getSelectedGPXFiles();
for (SelectedGpxFile selectedGpxFile : files) {
if (prevColor == selectedGpxFile.getGpxFile().getColor(0)) {
selectedGpxFile.getGpxFile().setColor(newColor);
}
}
}
private void saveCustomColors() {
List<String> colorNames = new ArrayList<>();
for (Integer color : customColors) {
String colorHex = Algorithms.colorToString(color);
colorNames.add(colorHex);
}
app.getSettings().CUSTOM_TRACK_COLORS.setStringsList(colorNames);
}
private class TrackColoringAdapter extends RecyclerView.Adapter<TrackAppearanceViewHolder> {

View file

@ -14,32 +14,31 @@ import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.github.ksoichiro.android.observablescrollview.ScrollUtils;
import com.google.android.material.slider.Slider;
import net.osmand.AndroidUtils;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.OnNeedScrollUiAdapter;
import net.osmand.plus.base.OnVisibilityChangeListener;
import net.osmand.plus.dialogs.GpxAppearanceAdapter;
import net.osmand.plus.dialogs.GpxAppearanceAdapter.AppearanceListItem;
import net.osmand.plus.dialogs.GpxAppearanceAdapter.GpxAppearanceAdapterType;
import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.routepreparationmenu.cards.BaseCard;
import net.osmand.plus.track.TrackAppearanceFragment.OnNeedScrollListener;
import net.osmand.util.Algorithms;
import java.util.List;
public class TrackWidthCard extends BaseCard {
public final static String TAG = TrackWidthCard.class.getName();
private final static String CUSTOM_WIDTH = "custom_width";
private final static int CUSTOM_WIDTH_MIN = 1;
private final static int CUSTOM_WIDTH_MAX = 24;
private TrackDrawInfo trackDrawInfo;
private OnNeedScrollUiAdapter onNeedScrollUiAdapter;
private OnNeedScrollListener onNeedScrollListener;
private AppearanceListItem selectedItem;
private List<AppearanceListItem> appearanceItems;
@ -48,10 +47,10 @@ public class TrackWidthCard extends BaseCard {
private View sliderContainer;
public TrackWidthCard(MapActivity mapActivity, TrackDrawInfo trackDrawInfo,
OnNeedScrollUiAdapter onNeedScrollUiAdapter) {
OnNeedScrollListener onNeedScrollListener) {
super(mapActivity);
this.trackDrawInfo = trackDrawInfo;
this.onNeedScrollUiAdapter = onNeedScrollUiAdapter;
this.onNeedScrollListener = onNeedScrollListener;
appearanceItems = getWidthAppearanceItems();
}
@ -157,16 +156,14 @@ public class TrackWidthCard extends BaseCard {
}
});
UiUtilities.setupSlider(widthSlider, nightMode, null);
AndroidUtils.addVisibilityChangeListener(view, sliderContainer,
new OnVisibilityChangeListener() {
@Override
public void onVisibilityChange(int visibility) {
if (visibility == View.VISIBLE) {
onNeedScrollUiAdapter.onNeedVerticalScroll(TAG, sliderContainer.getBottom());
}
}
ScrollUtils.addOnGlobalLayoutListener(sliderContainer, new Runnable() {
@Override
public void run() {
if (sliderContainer.getVisibility() == View.VISIBLE) {
onNeedScrollListener.onVerticalScrollNeeded(sliderContainer.getBottom());
}
);
}
});
AndroidUiHelper.updateVisibility(sliderContainer, true);
} else {
AndroidUiHelper.updateVisibility(sliderContainer, false);
@ -227,13 +224,6 @@ public class TrackWidthCard extends BaseCard {
if (listener != null) {
listener.onCardPressed(TrackWidthCard.this);
}
if (CUSTOM_WIDTH.equals(selectedItem.getAttrName())
&& sliderContainer != null
&& onNeedScrollUiAdapter != null
&& sliderContainer.getVisibility() == View.VISIBLE) {
onNeedScrollUiAdapter.onNeedVerticalScroll(TAG, sliderContainer.getBottom());
}
}
});
}