com.github.ksoichiro.android.observablescrollview.ObservableGridView Java Examples

The following examples show how to use com.github.ksoichiro.android.observablescrollview.ObservableGridView. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ViewPagerTabFragmentGridViewFragment.java    From Android-ObservableScrollView with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #2
Source File: FlexibleSpaceWithImageGridViewFragment.java    From Android-ObservableScrollView with Apache License 2.0 6 votes vote down vote up
@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);
    }
}
 
Example #3
Source File: FlexibleSpaceWithImageGridViewFragment.java    From Android-ObservableScrollView with Apache License 2.0 6 votes vote down vote up
@Override
protected void updateFlexibleSpace(int scrollY, View view) {
    int flexibleSpaceImageHeight = getResources().getDimensionPixelSize(R.dimen.flexible_space_image_height);

    View listBackgroundView = view.findViewById(R.id.list_background);

    // Translate list background
    ViewHelper.setTranslationY(listBackgroundView, Math.max(0, -scrollY + flexibleSpaceImageHeight));

    // Also pass this event to parent Activity
    FlexibleSpaceWithImageWithViewPagerTabActivity parentActivity =
            (FlexibleSpaceWithImageWithViewPagerTabActivity) getActivity();
    if (parentActivity != null) {
        parentActivity.onScrollChanged(scrollY, (ObservableGridView) view.findViewById(R.id.scroll));
    }
}
 
Example #4
Source File: ViewPagerTab2GridViewFragment.java    From Android-ObservableScrollView with Apache License 2.0 5 votes vote down vote up
@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);
    UiTestUtils.setDummyData(getActivity(), gridView);
    gridView.setTouchInterceptionViewGroup((ViewGroup) parentActivity.findViewById(R.id.container));

    if (parentActivity instanceof ObservableScrollViewCallbacks) {
        gridView.setScrollViewCallbacks((ObservableScrollViewCallbacks) parentActivity);
    }
    return view;
}
 
Example #5
Source File: ActionBarControlGridViewActivity.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.observable_scroll_view_activity_actionbarcontrolgridview);

    ObservableGridView gridView = (ObservableGridView) findViewById(R.id.grid);
    gridView.setScrollViewCallbacks(this);
    List<String> items = new ArrayList<String>();
    for (int i = 1; i <= 100; i++) {
        items.add("Item " + i);
    }
    gridView.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, items));
}
 
Example #6
Source File: TouchInterceptionGridViewActivity.java    From Android-ObservableScrollView with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_touchinterception_gridview);
    ((TextView) findViewById(R.id.title)).setText(getClass().getSimpleName());
    mScrollable = (Scrollable) findViewById(R.id.scrollable);
    mScrollable.setScrollViewCallbacks(this);
    UiTestUtils.setDummyData(this, (ObservableGridView) mScrollable);

    mIntersectionHeight = getResources().getDimensionPixelSize(R.dimen.intersection_height);
    mHeaderBarHeight = getResources().getDimensionPixelSize(R.dimen.header_bar_height);

    mInterceptionLayout = (TouchInterceptionFrameLayout) findViewById(R.id.scroll_wrapper);
    mInterceptionLayout.setScrollInterceptionListener(mInterceptionListener);
}
 
Example #7
Source File: HeaderGridViewActivityTest.java    From Android-ObservableScrollView with Apache License 2.0 5 votes vote down vote up
@Override
protected void setUp() throws Exception {
    super.setUp();
    setActivityInitialTouchMode(true);
    activity = getActivity();
    scrollable = (ObservableGridView) activity.findViewById(R.id.scrollable);
}
 
Example #8
Source File: TouchInterceptionGridViewActivityTest.java    From Android-ObservableScrollView with Apache License 2.0 5 votes vote down vote up
@Override
protected void setUp() throws Exception {
    super.setUp();
    setActivityInitialTouchMode(true);
    activity = getActivity();
    scrollable = (ObservableGridView) activity.findViewById(R.id.scrollable);
}
 
Example #9
Source File: GridViewActivityTest.java    From Android-ObservableScrollView with Apache License 2.0 5 votes vote down vote up
public void testNoCallbacks() throws Throwable {
    runTestOnUiThread(new Runnable() {
        @Override
        public void run() {
            scrollable = (ObservableGridView) activity.findViewById(R.id.scrollable);
            scrollable.setScrollViewCallbacks(null);
        }
    });
    testScroll();
}
 
Example #10
Source File: GridViewActivityTest.java    From Android-ObservableScrollView with Apache License 2.0 5 votes vote down vote up
public void testInitialize() throws Throwable {
    runTestOnUiThread(new Runnable() {
        @Override
        public void run() {
            new ObservableGridView(activity);
            new ObservableGridView(activity, null, 0);
        }
    });
}
 
Example #11
Source File: GridViewActivityTest.java    From Android-ObservableScrollView with Apache License 2.0 5 votes vote down vote up
@Override
protected void setUp() throws Exception {
    super.setUp();
    setActivityInitialTouchMode(true);
    activity = getActivity();
    scrollable = (ObservableGridView) activity.findViewById(R.id.scrollable);
    callbackCounter = new int[2];
}
 
Example #12
Source File: FlexibleSpaceWithImageGridViewFragment.java    From Android-ObservableScrollView with Apache License 2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void setSelectionFromTop(ObservableGridView gridView, int position, int offset) {
    if (Build.VERSION_CODES.LOLLIPOP <= Build.VERSION.SDK_INT) {
        gridView.setSelectionFromTop(position, offset);
    } else if (Build.VERSION_CODES.HONEYCOMB <= Build.VERSION.SDK_INT) {
        gridView.smoothScrollToPositionFromTop(position, offset, 0);
    }
}
 
Example #13
Source File: ViewPagerTab2GridViewFragment.java    From Android-ObservableScrollView with Apache License 2.0 5 votes vote down vote up
@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);
    setDummyData(gridView);
    gridView.setTouchInterceptionViewGroup((ViewGroup) parentActivity.findViewById(R.id.container));

    if (parentActivity instanceof ObservableScrollViewCallbacks) {
        gridView.setScrollViewCallbacks((ObservableScrollViewCallbacks) parentActivity);
    }
    return view;
}
 
Example #14
Source File: HandleTouchGridViewActivity.java    From Android-ObservableScrollView with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_handletouchgridview);

    ObservableGridView gridView = (ObservableGridView) findViewById(R.id.scroll);
    gridView.setScrollViewCallbacks(this);
    gridView.setAdapter(new CustomAdapter(this, getDummyData()));
}
 
Example #15
Source File: ParallaxToolbarGridViewActivity.java    From Android-ObservableScrollView with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_parallaxtoolbargridview) ;

    setSupportActionBar((Toolbar) findViewById(R.id.toolbar));

    mImageView = findViewById(R.id.image);
    mToolbarView = findViewById(R.id.toolbar);
    mToolbarView.setBackgroundColor(ScrollUtils.getColorWithAlpha(0, getResources().getColor(R.color.primary)));

    mParallaxImageHeight = getResources().getDimensionPixelSize(R.dimen.parallax_image_height);

    mGridView = (ObservableGridView) findViewById(R.id.list);
    mGridView.setScrollViewCallbacks(this);
    // Set padding view for ListView. This is the flexible space.
    View paddingView = new View(this);
    AbsListView.LayoutParams lp = new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT,
            mParallaxImageHeight);
    paddingView.setLayoutParams(lp);

    // This is required to disable header's list selector effect
    paddingView.setClickable(true);

    mGridView.addHeaderView(paddingView);
    setDummyData(mGridView);

    // mListBackgroundView makes ListView's background except header view.
    mListBackgroundView = findViewById(R.id.list_background);
}
 
Example #16
Source File: ViewPagerTabGridViewFragment.java    From Android-ObservableScrollView with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #17
Source File: ActionBarControlGridViewActivity.java    From Android-ObservableScrollView with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_actionbarcontrolgridview);

    ObservableGridView gridView = (ObservableGridView) findViewById(R.id.grid);
    gridView.setScrollViewCallbacks(this);
    setDummyData(gridView);
}
 
Example #18
Source File: FlexibleSpaceWithImageGridViewFragment.java    From Android-ObservableScrollView with Apache License 2.0 4 votes vote down vote up
@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;
}
 
Example #19
Source File: BaseFragment.java    From Android-ObservableScrollView with Apache License 2.0 4 votes vote down vote up
protected void setDummyDataWithHeader(ObservableGridView gridView, View headerView) {
    gridView.addHeaderView(headerView);
    setDummyData(gridView);
}
 
Example #20
Source File: FlexibleSpaceWithImageGridViewActivity.java    From Android-ObservableScrollView with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_flexiblespacewithimagegridview);

    mFlexibleSpaceImageHeight = getResources().getDimensionPixelSize(R.dimen.flexible_space_image_height);
    mFlexibleSpaceShowFabOffset = getResources().getDimensionPixelSize(R.dimen.flexible_space_show_fab_offset);
    mActionBarSize = getActionBarSize();
    mImageView = findViewById(R.id.image);
    mOverlayView = findViewById(R.id.overlay);
    ObservableGridView gridView = (ObservableGridView) findViewById(R.id.list);
    gridView.setScrollViewCallbacks(this);

    // Set padding view for ListView. This is the flexible space.
    View paddingView = new View(this);
    AbsListView.LayoutParams lp = new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT,
            mFlexibleSpaceImageHeight);
    paddingView.setLayoutParams(lp);

    // This is required to disable header's list selector effect
    paddingView.setClickable(true);

    gridView.addHeaderView(paddingView);
    setDummyData(gridView);
    mTitleView = (TextView) findViewById(R.id.title);
    mTitleView.setText(getTitle());
    setTitle(null);
    mFab = findViewById(R.id.fab);
    mFab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Toast.makeText(FlexibleSpaceWithImageGridViewActivity.this, "FAB is clicked", Toast.LENGTH_SHORT).show();
        }
    });
    mFabMargin = getResources().getDimensionPixelSize(R.dimen.margin_standard);
    ViewHelper.setScaleX(mFab, 0);
    ViewHelper.setScaleY(mFab, 0);

    // mListBackgroundView makes ListView's background except header view.
    mListBackgroundView = findViewById(R.id.list_background);
}
 
Example #21
Source File: ToolbarControlGridViewActivity.java    From Android-ObservableScrollView with Apache License 2.0 4 votes vote down vote up
@Override
protected ObservableGridView createScrollable() {
    ObservableGridView gridView = (ObservableGridView) findViewById(R.id.scrollable);
    setDummyData(gridView);
    return gridView;
}