Search in sources :

Example 1 with ObservableListView

use of com.github.ksoichiro.android.observablescrollview.ObservableListView in project UltimateAndroid by cymcsg.

the class ViewPagerTabActivity method adjustToolbarForListViews.

private void adjustToolbarForListViews(ScrollState scrollState, View view) {
    int toolbarHeight = mToolbarView.getHeight();
    final ObservableListView listView = (ObservableListView) view.findViewById(R.id.list);
    if (listView == null) {
        return;
    }
    if (scrollState == ScrollState.UP) {
        if (toolbarHeight < listView.getCurrentScrollY()) {
            hideToolbar();
        } else if (listView.getCurrentScrollY() < toolbarHeight) {
            showToolbar();
        }
    } else if (scrollState == ScrollState.DOWN) {
        if (toolbarHeight < listView.getCurrentScrollY()) {
            showToolbar();
        }
    }
}
Also used : ObservableListView(com.github.ksoichiro.android.observablescrollview.ObservableListView)

Example 2 with ObservableListView

use of com.github.ksoichiro.android.observablescrollview.ObservableListView in project UltimateAndroid by cymcsg.

the class ViewPagerTabListViewFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.observable_scroll_view_fragment_listview, container, false);
    Activity parentActivity = getActivity();
    final ObservableListView listView = (ObservableListView) view.findViewById(R.id.list);
    listView.addHeaderView(inflater.inflate(R.layout.observable_scroll_view_padding, null));
    List<String> items = new ArrayList<String>();
    for (int i = 1; i <= 100; i++) {
        items.add("Item " + i);
    }
    listView.setAdapter(new ArrayAdapter<String>(parentActivity, android.R.layout.simple_list_item_1, items));
    if (parentActivity instanceof ObservableScrollViewCallbacks) {
        // Scroll to the specified position after layout
        Bundle args = getArguments();
        if (args != null && args.containsKey(ARG_INITIAL_POSITION)) {
            final int initialPosition = args.getInt(ARG_INITIAL_POSITION, 0);
            ViewTreeObserver vto = listView.getViewTreeObserver();
            vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

                @Override
                public void onGlobalLayout() {
                    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
                        listView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                    } else {
                        listView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                    }
                    // scrollTo() doesn't work, should use setSelection()
                    listView.setSelection(initialPosition);
                }
            });
        }
        listView.setScrollViewCallbacks((ObservableScrollViewCallbacks) parentActivity);
    }
    return view;
}
Also used : Bundle(android.os.Bundle) ArrayList(java.util.ArrayList) Activity(android.app.Activity) ObservableScrollViewCallbacks(com.github.ksoichiro.android.observablescrollview.ObservableScrollViewCallbacks) View(android.view.View) ObservableListView(com.github.ksoichiro.android.observablescrollview.ObservableListView) ObservableListView(com.github.ksoichiro.android.observablescrollview.ObservableListView) ViewTreeObserver(android.view.ViewTreeObserver)

Example 3 with ObservableListView

use of com.github.ksoichiro.android.observablescrollview.ObservableListView in project UltimateAndroid by cymcsg.

the class ActionBarControlListViewActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.observable_scroll_view_activity_actionbarcontrollistview);
    ObservableListView listView = (ObservableListView) findViewById(R.id.list);
    listView.setScrollViewCallbacks(this);
    List<String> items = new ArrayList<String>();
    for (int i = 1; i <= 100; i++) {
        items.add("Item " + i);
    }
    listView.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, items));
    // ObservableListView uses setOnScrollListener, but it still works.
    listView.setOnScrollListener(new AbsListView.OnScrollListener() {

        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
            Log.v(TAG, "onScrollStateChanged: " + scrollState);
        }

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            Log.v(TAG, "onScroll: firstVisibleItem: " + firstVisibleItem + " visibleItemCount: " + visibleItemCount + " totalItemCount: " + totalItemCount);
        }
    });
}
Also used : ObservableListView(com.github.ksoichiro.android.observablescrollview.ObservableListView) ArrayList(java.util.ArrayList) AbsListView(android.widget.AbsListView)

Example 4 with ObservableListView

use of com.github.ksoichiro.android.observablescrollview.ObservableListView in project Android-ObservableScrollView by ksoichiro.

the class ListViewScrollFromBottomActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    final ObservableListView scrollable = (ObservableListView) findViewById(R.id.scrollable);
    ScrollUtils.addOnGlobalLayoutListener(scrollable, new Runnable() {

        @Override
        public void run() {
            int count = scrollable.getAdapter().getCount() - 1;
            int position = count == 0 ? 1 : count > 0 ? count : 0;
            scrollable.smoothScrollToPosition(position);
            scrollable.setSelection(position);
        }
    });
}
Also used : ObservableListView(com.github.ksoichiro.android.observablescrollview.ObservableListView)

Example 5 with ObservableListView

use of com.github.ksoichiro.android.observablescrollview.ObservableListView in project Android-ObservableScrollView by ksoichiro.

the class ViewPagerTabListViewFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_listview, container, false);
    Activity parentActivity = getActivity();
    final ObservableListView listView = (ObservableListView) view.findViewById(R.id.scroll);
    UiTestUtils.setDummyDataWithHeader(getActivity(), listView, inflater.inflate(R.layout.padding, null));
    if (parentActivity instanceof ObservableScrollViewCallbacks) {
        // Scroll to the specified position after layout
        Bundle args = getArguments();
        if (args != null && args.containsKey(ARG_INITIAL_POSITION)) {
            final int initialPosition = args.getInt(ARG_INITIAL_POSITION, 0);
            ScrollUtils.addOnGlobalLayoutListener(listView, new Runnable() {

                @Override
                public void run() {
                    // scrollTo() doesn't work, should use setSelection()
                    listView.setSelection(initialPosition);
                }
            });
        }
        listView.setScrollViewCallbacks((ObservableScrollViewCallbacks) parentActivity);
    }
    return view;
}
Also used : ObservableListView(com.github.ksoichiro.android.observablescrollview.ObservableListView) Bundle(android.os.Bundle) Activity(android.app.Activity) ObservableScrollViewCallbacks(com.github.ksoichiro.android.observablescrollview.ObservableScrollViewCallbacks) View(android.view.View) ObservableListView(com.github.ksoichiro.android.observablescrollview.ObservableListView)

Aggregations

ObservableListView (com.github.ksoichiro.android.observablescrollview.ObservableListView)29 View (android.view.View)18 AbsListView (android.widget.AbsListView)11 ObservableScrollViewCallbacks (com.github.ksoichiro.android.observablescrollview.ObservableScrollViewCallbacks)7 Activity (android.app.Activity)5 Fragment (android.support.v4.app.Fragment)5 Bundle (android.os.Bundle)4 SuppressLint (android.annotation.SuppressLint)3 TextView (android.widget.TextView)3 ArrayList (java.util.ArrayList)3 ViewTreeObserver (android.view.ViewTreeObserver)2 Context (android.content.Context)1 Nullable (android.support.annotation.Nullable)1 ViewGroup (android.view.ViewGroup)1 AdapterView (android.widget.AdapterView)1 FrameLayout (android.widget.FrameLayout)1 ImageView (android.widget.ImageView)1 ListView (android.widget.ListView)1 ScrollState (com.github.ksoichiro.android.observablescrollview.ScrollState)1 MapActivity (net.osmand.plus.activities.MapActivity)1