Search in sources :

Example 6 with ObservableGridView

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

the class FlexibleSpaceWithImageGridViewFragment method setScrollY.

@SuppressWarnings("NewApi")
@Override
public void setScrollY(int scrollY, int threshold) {
    View view = getView();
    if (view == null) {
        return;
    }
    ObservableGridView gridView = (ObservableGridView) view.findViewById(R.id.scroll);
    if (gridView == null) {
        return;
    }
    View firstVisibleChild = gridView.getChildAt(0);
    if (firstVisibleChild != null) {
        int offset = scrollY;
        int position = 0;
        if (threshold < scrollY) {
            int baseHeight = firstVisibleChild.getHeight();
            position = scrollY / baseHeight;
            offset = scrollY % baseHeight;
        }
        setSelectionFromTop(gridView, position, -offset);
    }
}
Also used : ObservableGridView(com.github.ksoichiro.android.observablescrollview.ObservableGridView) ObservableGridView(com.github.ksoichiro.android.observablescrollview.ObservableGridView) View(android.view.View) SuppressLint(android.annotation.SuppressLint)

Example 7 with ObservableGridView

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

the class FlexibleSpaceWithImageGridViewFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_flexiblespacewithimagegridview, container, false);
    final ObservableGridView gridView = (ObservableGridView) view.findViewById(R.id.scroll);
    // Set padding view for GridView. This is the flexible space.
    View paddingView = new View(getActivity());
    final int flexibleSpaceImageHeight = getResources().getDimensionPixelSize(R.dimen.flexible_space_image_height);
    FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, flexibleSpaceImageHeight);
    paddingView.setLayoutParams(lp);
    // This is required to disable header's list selector effect
    paddingView.setClickable(true);
    gridView.addHeaderView(paddingView);
    setDummyData(gridView);
    // 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
    gridView.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(gridView, new Runnable() {

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

Example 8 with ObservableGridView

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

the class ToolbarControlGridViewActivity method createScrollable.

@Override
protected ObservableGridView createScrollable() {
    ObservableGridView gridView = (ObservableGridView) findViewById(R.id.scrollable);
    setDummyData(gridView);
    return gridView;
}
Also used : ObservableGridView(com.github.ksoichiro.android.observablescrollview.ObservableGridView)

Example 9 with ObservableGridView

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

the class ViewPagerTabFragmentGridViewFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_gridview, container, false);
    final ObservableGridView gridView = (ObservableGridView) view.findViewById(R.id.scroll);
    setDummyData(gridView);
    Fragment parentFragment = getParentFragment();
    ViewGroup viewGroup = (ViewGroup) parentFragment.getView();
    if (viewGroup != null) {
        gridView.setTouchInterceptionViewGroup((ViewGroup) viewGroup.findViewById(R.id.container));
        if (parentFragment instanceof ObservableScrollViewCallbacks) {
            gridView.setScrollViewCallbacks((ObservableScrollViewCallbacks) parentFragment);
        }
    }
    return view;
}
Also used : ViewGroup(android.view.ViewGroup) ObservableGridView(com.github.ksoichiro.android.observablescrollview.ObservableGridView) ObservableScrollViewCallbacks(com.github.ksoichiro.android.observablescrollview.ObservableScrollViewCallbacks) ObservableGridView(com.github.ksoichiro.android.observablescrollview.ObservableGridView) View(android.view.View) Fragment(android.support.v4.app.Fragment)

Example 10 with ObservableGridView

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

the class ViewPagerTabGridViewFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_gridview, container, false);
    Activity parentActivity = getActivity();
    final ObservableGridView gridView = (ObservableGridView) view.findViewById(R.id.scroll);
    setDummyDataWithHeader(gridView, inflater.inflate(R.layout.padding, gridView, 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(gridView, new Runnable() {

                @Override
                public void run() {
                    // scrollTo() doesn't work, should use setSelection()
                    gridView.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
        gridView.setTouchInterceptionViewGroup((ViewGroup) parentActivity.findViewById(R.id.root));
        gridView.setScrollViewCallbacks((ObservableScrollViewCallbacks) parentActivity);
    }
    return view;
}
Also used : Bundle(android.os.Bundle) Activity(android.app.Activity) ObservableGridView(com.github.ksoichiro.android.observablescrollview.ObservableGridView) ObservableScrollViewCallbacks(com.github.ksoichiro.android.observablescrollview.ObservableScrollViewCallbacks) ObservableGridView(com.github.ksoichiro.android.observablescrollview.ObservableGridView) View(android.view.View)

Aggregations

ObservableGridView (com.github.ksoichiro.android.observablescrollview.ObservableGridView)16 View (android.view.View)11 AbsListView (android.widget.AbsListView)4 ObservableScrollViewCallbacks (com.github.ksoichiro.android.observablescrollview.ObservableScrollViewCallbacks)4 SuppressLint (android.annotation.SuppressLint)3 Activity (android.app.Activity)3 Bundle (android.os.Bundle)2 FrameLayout (android.widget.FrameLayout)2 Fragment (android.support.v4.app.Fragment)1 ViewGroup (android.view.ViewGroup)1 AdapterView (android.widget.AdapterView)1 TextView (android.widget.TextView)1 ArrayList (java.util.ArrayList)1