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);
}
}
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;
}
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;
}
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;
}
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;
}
Aggregations