Search in sources :

Example 51 with AbsListView

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;
}
Also used : AbsListView(android.widget.AbsListView) Intent(android.content.Intent) AbsListView(android.widget.AbsListView) TextView(android.widget.TextView) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) AbsListView(android.widget.AbsListView) ListView(android.widget.ListView) StationActivity(be.brunoparmentier.openbikesharing.app.activities.StationActivity) TextView(android.widget.TextView) AdapterView(android.widget.AdapterView)

Example 52 with AbsListView

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!");
            }
        }
    }
}
Also used : AbsListView(android.widget.AbsListView) View(android.view.View) AdapterView(android.widget.AdapterView) ExpandableListView(android.widget.ExpandableListView) ExpandableListAdapter(android.widget.ExpandableListAdapter) ListAdapter(android.widget.ListAdapter)

Example 53 with AbsListView

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);
}
Also used : AbsListView(android.widget.AbsListView) ListView(android.widget.ListView) AbsListView(android.widget.AbsListView) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 54 with AbsListView

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;
}
Also used : NestedScrollingParent(android.support.v4.view.NestedScrollingParent) NestedScrollView(android.support.v4.widget.NestedScrollView) ScrollView(android.widget.ScrollView) NestedScrollingChild(android.support.v4.view.NestedScrollingChild) ViewGroup(android.view.ViewGroup) ScrollingView(android.support.v4.view.ScrollingView) AbsListView(android.widget.AbsListView) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) WebView(android.webkit.WebView) ScrollingView(android.support.v4.view.ScrollingView) View(android.view.View) NestedScrollView(android.support.v4.widget.NestedScrollView) WebView(android.webkit.WebView) AbsListView(android.widget.AbsListView) RecyclerView(android.support.v7.widget.RecyclerView) ScrollView(android.widget.ScrollView) ViewPager(android.support.v4.view.ViewPager)

Example 55 with AbsListView

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);
        }
    });
}
Also used : Rect(android.graphics.Rect) GestureDetector(android.view.GestureDetector) View(android.view.View) AbsListView(android.widget.AbsListView) MotionEvent(android.view.MotionEvent)

Aggregations

AbsListView (android.widget.AbsListView)223 View (android.view.View)126 ListView (android.widget.ListView)80 AdapterView (android.widget.AdapterView)54 TextView (android.widget.TextView)46 ViewGroup (android.view.ViewGroup)33 ImageView (android.widget.ImageView)29 ScrollView (android.widget.ScrollView)23 RecyclerView (android.support.v7.widget.RecyclerView)21 GridView (android.widget.GridView)21 SuppressLint (android.annotation.SuppressLint)20 OnScrollListener (android.widget.AbsListView.OnScrollListener)19 Intent (android.content.Intent)17 ArrayList (java.util.ArrayList)16 Context (android.content.Context)12 Point (android.graphics.Point)12 Handler (android.os.Handler)12 WebView (android.webkit.WebView)12 ExpandableListView (android.widget.ExpandableListView)12 ArrayListLoader (com.klinker.android.twitter.adapters.ArrayListLoader)10