Fix scroll

This commit is contained in:
PavelRatushny 2017-07-07 03:33:53 +03:00
parent aa93e8e8b6
commit 3bf6eca3a7

View file

@ -1,17 +1,13 @@
package net.osmand.plus.myplaces; package net.osmand.plus.myplaces;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.content.res.ColorStateList; import android.content.res.ColorStateList;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v7.widget.ListPopupWindow; import android.support.v7.widget.ListPopupWindow;
import android.util.Log;
import android.view.Gravity; import android.view.Gravity;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.AbsListView; import android.widget.AbsListView;
@ -61,7 +57,6 @@ public class SplitSegmentFragment extends OsmAndListFragment {
private TIntArrayList timeSplit = new TIntArrayList(); private TIntArrayList timeSplit = new TIntArrayList();
private int selectedSplitInterval; private int selectedSplitInterval;
private IconsCache ic; private IconsCache ic;
private float listViewYPos;
@Override @Override
public void onCreate(@Nullable Bundle savedInstanceState) { public void onCreate(@Nullable Bundle savedInstanceState) {
@ -99,85 +94,40 @@ public class SplitSegmentFragment extends OsmAndListFragment {
listView.addHeaderView(getActivity().getLayoutInflater().inflate(R.layout.gpx_split_segments_empty_header, null, false)); listView.addHeaderView(getActivity().getLayoutInflater().inflate(R.layout.gpx_split_segments_empty_header, null, false));
listView.addFooterView(getActivity().getLayoutInflater().inflate(R.layout.list_shadow_footer, null, false)); listView.addFooterView(getActivity().getLayoutInflater().inflate(R.layout.list_shadow_footer, null, false));
updateHeader();
updateContent(); updateContent();
updateHeader();
setListAdapter(adapter); setListAdapter(adapter);
listView.setOnScrollListener(new AbsListView.OnScrollListener() { listView.setOnScrollListener(new AbsListView.OnScrollListener() {
int previousYPos = -1;
int initialYPos;
boolean changed;
int visibility = View.VISIBLE;
@Override @Override
public void onScrollStateChanged(AbsListView absListView, int i) { public void onScrollStateChanged(AbsListView absListView, int i) {
initialYPos = -1; if (i == SCROLL_STATE_IDLE) {
changed = false; previousYPos = -1;
}
} }
@Override @Override
public void onScroll(AbsListView absListView, int i, int i1, int i2) { public void onScroll(AbsListView absListView, int i, int i1, int i2) {
View c = absListView.getChildAt(0); View c = absListView.getChildAt(1);
if (c != null) { if (c != null) {
int currentYPos = -c.getTop() + absListView.getFirstVisiblePosition() * c.getHeight(); int currentYPos = -c.getTop() + absListView.getFirstVisiblePosition() * c.getHeight();
if (initialYPos == -1) { if (previousYPos == -1) {
initialYPos = currentYPos; previousYPos = currentYPos;
} }
if (currentYPos < headerView.getHeight() && changed && visibility == View.GONE) { float yTranslationToSet = headerView.getTranslationY() + (previousYPos - currentYPos);
changed = false; if (yTranslationToSet < 0 && yTranslationToSet > -headerView.getHeight()) {
initialYPos = currentYPos; headerView.setTranslationY(yTranslationToSet);
} else if (yTranslationToSet < -headerView.getHeight()) {
headerView.setTranslationY(-headerView.getHeight());
} else if (yTranslationToSet > 0) {
headerView.setTranslationY(0);
} }
previousYPos = currentYPos;
if (currentYPos < initialYPos && !changed && visibility == View.GONE) {
if (currentYPos <= headerView.getHeight()) {
headerView.clearAnimation();
headerView.setTranslationY(-currentYPos);
} else {
headerView.clearAnimation();
headerView.animate().translationY(0);
visibility = View.VISIBLE;
changed = true;
}
} else if (currentYPos > initialYPos && !changed && visibility == View.VISIBLE) {
if (currentYPos <= headerView.getHeight()) {
headerView.clearAnimation();
headerView.setTranslationY(-currentYPos);
} else {
headerView.clearAnimation();
headerView.animate().translationY(-headerView.getHeight());
visibility = View.GONE;
changed = true;
}
}
// Log.d("onScroll", "currentYpos: " + currentYPos);
// Log.d("onScroll", "visibility: " + visibility);
// Log.d("onScroll", "headerView.getHeight(): " + headerView.getHeight());
// Log.d("onScroll", "headerView.getTranslationY(): " + headerView.getTranslationY());
// if (headerView.getHeight() != 0) {
// if (visibility == View.VISIBLE) {
// if (currentYPos < headerView.getHeight()) {
// headerView.setTranslationY(-currentYPos);
// } else if (!changed) {
// headerView.animate().translationY(-headerView.getHeight());
// visibility = View.GONE;
// changed = true;
// }
// }
//
// if (visibility == View.GONE) {
// if (currentYPos < headerView.getHeight()) {
// headerView.setTranslationY(currentYPos - headerView.getHeight());
// } else if (!changed) {
// headerView.animate().translationY(0);
// visibility = View.VISIBLE;
// changed = true;
// }
// }
// }
} }
} }
}); });