use of android.widget.AbsListView in project OpenBikeSharing by bparmentier.
the class StationsListFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_stations_list, container, false);
ListView listView = (ListView) view.findViewById(R.id.stationsListView);
listView.setAdapter(stationsListAdapter);
TextView emptyView = (TextView) view.findViewById(R.id.emptyList);
emptyView.setText(emptyListResourceId);
listView.setEmptyView(view.findViewById(R.id.emptyList));
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent = new Intent(getActivity(), StationActivity.class);
intent.putExtra(KEY_STATION, stations.get(position));
startActivity(intent);
}
});
listView.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
SwipeRefreshLayout refreshLayout = (SwipeRefreshLayout) getActivity().findViewById(R.id.swipe_container);
if (firstVisibleItem == 0)
refreshLayout.setEnabled(true);
else
refreshLayout.setEnabled(false);
}
});
return view;
}
use of android.widget.AbsListView in project androidquery by androidquery.
the class Common method onScrollStateChanged2.
private void onScrollStateChanged2(AbsListView lv, int scrollState) {
lv.setTag(AQuery.TAG_NUM, scrollState);
if (scrollState == SCROLL_STATE_IDLE) {
int first = lv.getFirstVisiblePosition();
int last = lv.getLastVisiblePosition();
int count = last - first;
ListAdapter la = lv.getAdapter();
for (int i = 0; i <= count; i++) {
long packed = i + first;
View convertView = lv.getChildAt(i);
Number targetPacked = (Number) convertView.getTag(AQuery.TAG_NUM);
if (targetPacked != null) {
la.getView((int) packed, convertView, lv);
convertView.setTag(AQuery.TAG_NUM, null);
} else {
// AQUtility.debug("skip!");
}
}
}
}
use of android.widget.AbsListView in project RoboBinding by RoboBinding.
the class AbsListViewAddOnTest method shouldSupportMultipleOnOnScrollListeners.
/**
* TODO: Not supported by Robolectric 2.x yet.
*/
@Test
@Ignore
public void shouldSupportMultipleOnOnScrollListeners() {
AbsListView view = new ListView(RuntimeEnvironment.application);
AbsListViewAddOn viewAddOn = new AbsListViewAddOn(view, null);
MockOnScrollListener listener1 = new MockOnScrollListener();
MockOnScrollListener listener2 = new MockOnScrollListener();
viewAddOn.addOnScrollListener(listener1);
viewAddOn.addOnScrollListener(listener2);
view.smoothScrollToPositionFromTop(1, 0, 500);
assertTrue(listener1.scrollEventFired);
assertTrue(listener1.scrollStateChangedEventFired);
assertTrue(listener2.scrollEventFired);
assertTrue(listener2.scrollStateChangedEventFired);
}
use of android.widget.AbsListView in project CollapsingRefresh by ckrgithub.
the class RefreshContentWrapper method findScrollableViewInternal.
private View findScrollableViewInternal(View content, boolean selfable) {
View scrollableView = null;
Queue<View> views = new LinkedBlockingQueue<>(Collections.singletonList(content));
while (!views.isEmpty() && scrollableView == null) {
View view = views.poll();
if (view != null) {
if ((selfable || view != content) && (view instanceof AbsListView || view instanceof ScrollView || view instanceof ScrollingView || view instanceof NestedScrollingChild || view instanceof NestedScrollingParent || view instanceof WebView || view instanceof ViewPager)) {
scrollableView = view;
} else if (view instanceof ViewGroup) {
ViewGroup group = (ViewGroup) view;
for (int j = 0; j < group.getChildCount(); j++) {
views.add(group.getChildAt(j));
}
}
}
}
return scrollableView;
}
use of android.widget.AbsListView in project keepass2android by PhilippC.
the class GestureUtils method setupGestureDetector.
// SimpleOnGestureListener
/**
* Adds a gesture listener to {@code listView}.
*
* @param listView
* {@link AbsListView}.
* @param listener
* {@link OnGestureListener}.
*/
public static void setupGestureDetector(final AbsListView listView, final OnGestureListener listener) {
final GestureDetector _gestureDetector = new GestureDetector(listView.getContext(), new GestureDetector.SimpleOnGestureListener() {
private Object getData(float x, float y) {
int i = getSubViewId(x, y);
if (i >= 0)
return listView.getItemAtPosition(listView.getFirstVisiblePosition() + i);
return null;
}
// getSubView()
private View getSubView(float x, float y) {
int i = getSubViewId(x, y);
if (i >= 0)
return listView.getChildAt(i);
return null;
}
// getSubView()
private int getSubViewId(float x, float y) {
Rect r = new Rect();
for (int i = 0; i < listView.getChildCount(); i++) {
listView.getChildAt(i).getHitRect(r);
if (r.contains((int) x, (int) y)) {
if (BuildConfig.DEBUG)
Log.d(CLASSNAME, String.format("getSubViewId() -- left-top-right-bottom = %d-%d-%d-%d", r.left, r.top, r.right, r.bottom));
return i;
}
}
return -1;
}
// getSubViewId()
@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
if (BuildConfig.DEBUG)
Log.d(CLASSNAME, String.format("onSingleTapConfirmed() -- x = %.2f -- y = %.2f", e.getX(), e.getY()));
return listener == null ? false : listener.onSingleTapConfirmed(getSubView(e.getX(), e.getY()), getData(e.getX(), e.getY()));
}
// onSingleTapConfirmed()
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
if (listener == null || e1 == null || e2 == null)
return false;
FlingDirection fd = calcFlingDirection(e1, e2, velocityX, velocityY);
if (!FlingDirection.UNKNOWN.equals(fd)) {
if (listener.onFling(getSubView(e1.getX(), e1.getY()), getData(e1.getX(), e1.getY()), fd)) {
MotionEvent cancelEvent = MotionEvent.obtain(e1);
cancelEvent.setAction(MotionEvent.ACTION_CANCEL);
listView.onTouchEvent(cancelEvent);
}
}
/*
* Always return false to let the default handler draw
* the item properly.
*/
return false;
}
});
// _gestureDetector
listView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return _gestureDetector.onTouchEvent(event);
}
});
}
Aggregations