Search in sources :

Example 16 with ObservableListView

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

the class ViewPagerTabListViewActivity method onUpOrCancelMotionEvent.

@Override
public void onUpOrCancelMotionEvent(ScrollState scrollState) {
    mBaseTranslationY = 0;
    Fragment fragment = getCurrentFragment();
    if (fragment == null) {
        return;
    }
    View view = fragment.getView();
    if (view == null) {
        return;
    }
    int toolbarHeight = mToolbarView.getHeight();
    final ObservableListView listView = (ObservableListView) view.findViewById(R.id.scroll);
    if (listView == null) {
        return;
    }
    int scrollY = listView.getCurrentScrollY();
    if (scrollState == ScrollState.DOWN) {
        showToolbar();
    } else if (scrollState == ScrollState.UP) {
        if (toolbarHeight <= scrollY) {
            hideToolbar();
        } else {
            showToolbar();
        }
    } else {
        // Even if onScrollChanged occurs without scrollY changing, toolbar should be adjusted
        if (toolbarIsShown() || toolbarIsHidden()) {
            // Toolbar is completely moved, so just keep its state
            // and propagate it to other pages
            propagateToolbarState(toolbarIsShown());
        } else {
            // Toolbar is moving but doesn't know which to move:
            // you can change this to hideToolbar()
            showToolbar();
        }
    }
}
Also used : ObservableListView(com.github.ksoichiro.android.observablescrollview.ObservableListView) Fragment(android.support.v4.app.Fragment) View(android.view.View) ObservableListView(com.github.ksoichiro.android.observablescrollview.ObservableListView)

Example 17 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);
    setDummyDataWithHeader(listView, inflater.inflate(R.layout.padding, listView, false));
    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);
                }
            });
        }
        // TouchInterceptionViewGroup should be a parent view other than ViewPager.
        // This is a workaround for the issue #117:
        // https://github.com/ksoichiro/Android-ObservableScrollView/issues/117
        listView.setTouchInterceptionViewGroup((ViewGroup) parentActivity.findViewById(R.id.root));
        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)

Example 18 with ObservableListView

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

the class FlexibleSpaceWithImageListViewFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_flexiblespacewithimagelistview, container, false);
    final ObservableListView listView = (ObservableListView) view.findViewById(R.id.scroll);
    // Set padding view for ListView. This is the flexible space.
    View paddingView = new View(getActivity());
    final int flexibleSpaceImageHeight = getResources().getDimensionPixelSize(R.dimen.flexible_space_image_height);
    AbsListView.LayoutParams lp = new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT, flexibleSpaceImageHeight);
    paddingView.setLayoutParams(lp);
    // This is required to disable header's list selector effect
    paddingView.setClickable(true);
    listView.addHeaderView(paddingView);
    setDummyData(listView);
    // TouchInterceptionViewGroup should be a parent view other than ViewPager.
    // This is a workaround for the issue #117:
    // https://github.com/ksoichiro/Android-ObservableScrollView/issues/117
    listView.setTouchInterceptionViewGroup((ViewGroup) view.findViewById(R.id.fragment_root));
    // Scroll to the specified offset after layout
    Bundle args = getArguments();
    if (args != null && args.containsKey(ARG_SCROLL_Y)) {
        final int scrollY = args.getInt(ARG_SCROLL_Y, 0);
        ScrollUtils.addOnGlobalLayoutListener(listView, new Runnable() {

            @SuppressLint("NewApi")
            @Override
            public void run() {
                int offset = scrollY % flexibleSpaceImageHeight;
                listView.setSelectionFromTop(0, -offset);
            }
        });
        updateFlexibleSpace(scrollY, view);
    } else {
        updateFlexibleSpace(0, view);
    }
    listView.setScrollViewCallbacks(this);
    updateFlexibleSpace(0, view);
    return view;
}
Also used : ObservableListView(com.github.ksoichiro.android.observablescrollview.ObservableListView) Bundle(android.os.Bundle) AbsListView(android.widget.AbsListView) SuppressLint(android.annotation.SuppressLint) View(android.view.View) AbsListView(android.widget.AbsListView) ObservableListView(com.github.ksoichiro.android.observablescrollview.ObservableListView) SuppressLint(android.annotation.SuppressLint)

Example 19 with ObservableListView

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

the class FragmentActionBarControlListViewFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_actionbarcontrollistview, container, false);
    ObservableListView listView = (ObservableListView) view.findViewById(R.id.list);
    listView.setScrollViewCallbacks(this);
    setDummyData(listView);
    return view;
}
Also used : ObservableListView(com.github.ksoichiro.android.observablescrollview.ObservableListView) View(android.view.View) ObservableListView(com.github.ksoichiro.android.observablescrollview.ObservableListView)

Example 20 with ObservableListView

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

the class ToolbarControlListViewActivity method createScrollable.

@Override
protected ObservableListView createScrollable() {
    ObservableListView listView = (ObservableListView) findViewById(R.id.scrollable);
    setDummyData(listView);
    // 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);
        }
    });
    return listView;
}
Also used : ObservableListView(com.github.ksoichiro.android.observablescrollview.ObservableListView) AbsListView(android.widget.AbsListView)

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