Fix scroll when interacting with graphic
This commit is contained in:
parent
ef4b003d91
commit
6f44845ab9
1 changed files with 16 additions and 44 deletions
|
@ -38,7 +38,6 @@ import android.widget.AdapterView;
|
|||
import android.widget.ArrayAdapter;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ListAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
@ -140,27 +139,6 @@ public class TrackSegmentFragment extends OsmAndListFragment {
|
|||
private Bitmap mapBitmap;
|
||||
private Bitmap mapTrackBitmap;
|
||||
|
||||
public static void setListViewHeightBasedOnChildren(ListView listView) {
|
||||
ListAdapter listAdapter = listView.getAdapter();
|
||||
if (listAdapter == null)
|
||||
return;
|
||||
|
||||
int desiredWidth = View.MeasureSpec.makeMeasureSpec(listView.getWidth(), View.MeasureSpec.UNSPECIFIED);
|
||||
int totalHeight = 0;
|
||||
View view = null;
|
||||
for (int i = 0; i < listAdapter.getCount(); i++) {
|
||||
view = listAdapter.getView(i, view, listView);
|
||||
if (i == 0)
|
||||
view.setLayoutParams(new ViewGroup.LayoutParams(desiredWidth, ViewGroup.LayoutParams.WRAP_CONTENT));
|
||||
|
||||
view.measure(View.MeasureSpec.makeMeasureSpec(desiredWidth, View.MeasureSpec.AT_MOST), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
|
||||
totalHeight += view.getMeasuredHeight();
|
||||
}
|
||||
ViewGroup.LayoutParams params = listView.getLayoutParams();
|
||||
params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
|
||||
listView.setLayoutParams(params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
@ -182,15 +160,6 @@ public class TrackSegmentFragment extends OsmAndListFragment {
|
|||
view.findViewById(R.id.header_layout).setVisibility(View.GONE);
|
||||
|
||||
ListView listView = (ListView) view.findViewById(android.R.id.list);
|
||||
listView.setOnTouchListener(new View.OnTouchListener() {
|
||||
// Setting on Touch Listener for handling the touch inside ScrollView
|
||||
@Override
|
||||
public boolean onTouch(View v, MotionEvent event) {
|
||||
// Disallow the touch request for parent scroll on touch of child view
|
||||
v.getParent().requestDisallowInterceptTouchEvent(true);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
listView.setDivider(null);
|
||||
listView.setDividerHeight(0);
|
||||
|
||||
|
@ -850,6 +819,7 @@ public class TrackSegmentFragment extends OsmAndListFragment {
|
|||
private String[] titles;
|
||||
private Map<GPXTabItemType, List<ILineDataSet>> dataSetsMap = new HashMap<>();
|
||||
private TrkSegment segment;
|
||||
private float listViewYPos;
|
||||
|
||||
GPXItemPagerAdapter(PagerSlidingTabStrip tabs, GpxDisplayItem gpxItem) {
|
||||
super();
|
||||
|
@ -995,6 +965,10 @@ public class TrackSegmentFragment extends OsmAndListFragment {
|
|||
return wpt;
|
||||
}
|
||||
|
||||
private void scrollBy(int px) {
|
||||
getListView().setSelectionFromTop(getListView().getFirstVisiblePosition(), getListView().getChildAt(0).getTop() - px);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return tabTypes.length;
|
||||
|
@ -1029,19 +1003,17 @@ public class TrackSegmentFragment extends OsmAndListFragment {
|
|||
chart.setOnTouchListener(new View.OnTouchListener() {
|
||||
@Override
|
||||
public boolean onTouch(View v, MotionEvent event) {
|
||||
switch (event.getAction()) {
|
||||
case MotionEvent.ACTION_DOWN: {
|
||||
chart.getParent().requestDisallowInterceptTouchEvent(true);
|
||||
break;
|
||||
}
|
||||
case MotionEvent.ACTION_CANCEL:
|
||||
case MotionEvent.ACTION_UP: {
|
||||
chart.getParent().requestDisallowInterceptTouchEvent(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
getListView().requestDisallowInterceptTouchEvent(true);
|
||||
switch (event.getAction()) {
|
||||
case android.view.MotionEvent.ACTION_DOWN:
|
||||
listViewYPos = event.getRawY();
|
||||
break;
|
||||
case android.view.MotionEvent.ACTION_MOVE:
|
||||
scrollBy(Math.round(listViewYPos - event.getRawY()));
|
||||
listViewYPos = event.getRawY();
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
chart.setOnChartValueSelectedListener(new OnChartValueSelectedListener() {
|
||||
|
|
Loading…
Reference in a new issue