com.github.ksoichiro.android.observablescrollview.ObservableListView Java Examples
The following examples show how to use
com.github.ksoichiro.android.observablescrollview.ObservableListView.
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: ViewPagerTabActivity.java From UltimateAndroid with Apache License 2.0 | 6 votes |
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(); } } }
Example #2
Source File: ViewPagerTabActivity.java From UltimateAndroid with Apache License 2.0 | 6 votes |
private void propagateToolbarStateForListView(boolean isShown, View view, int toolbarHeight) { ObservableListView listView = (ObservableListView) view.findViewById(R.id.list); if (listView == null) { return; } if (isShown) { // Scroll up if (0 < listView.getCurrentScrollY()) { listView.setSelection(0); } } else { // Scroll down (to hide padding) if (listView.getCurrentScrollY() < toolbarHeight) { listView.setSelection(1); } } }
Example #3
Source File: ViewPagerTabListViewFragment.java From Android-ObservableScrollView with Apache License 2.0 | 6 votes |
@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; }
Example #4
Source File: ViewPagerTabFragmentListViewFragment.java From Android-ObservableScrollView with Apache License 2.0 | 6 votes |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_listview, container, false); final ObservableListView listView = (ObservableListView) view.findViewById(R.id.scroll); setDummyData(listView); Fragment parentFragment = getParentFragment(); ViewGroup viewGroup = (ViewGroup) parentFragment.getView(); if (viewGroup != null) { listView.setTouchInterceptionViewGroup((ViewGroup) viewGroup.findViewById(R.id.container)); if (parentFragment instanceof ObservableScrollViewCallbacks) { listView.setScrollViewCallbacks((ObservableScrollViewCallbacks) parentFragment); } } return view; }
Example #5
Source File: FlexibleSpaceWithImageListViewFragment.java From Android-ObservableScrollView with Apache License 2.0 | 6 votes |
@SuppressWarnings("NewApi") @Override public void setScrollY(int scrollY, int threshold) { View view = getView(); if (view == null) { return; } ObservableListView listView = (ObservableListView) view.findViewById(R.id.scroll); if (listView == null) { return; } View firstVisibleChild = listView.getChildAt(0); if (firstVisibleChild != null) { int offset = scrollY; int position = 0; if (threshold < scrollY) { int baseHeight = firstVisibleChild.getHeight(); position = scrollY / baseHeight; offset = scrollY % baseHeight; } listView.setSelectionFromTop(position, -offset); } }
Example #6
Source File: FlexibleSpaceWithImageListViewFragment.java From Android-ObservableScrollView with Apache License 2.0 | 6 votes |
@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, (ObservableListView) view.findViewById(R.id.scroll)); } }
Example #7
Source File: ViewPagerTabListViewActivity.java From Android-ObservableScrollView with Apache License 2.0 | 5 votes |
@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(); } } }
Example #8
Source File: ViewPagerTabListViewFragment.java From UltimateAndroid with Apache License 2.0 | 5 votes |
@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; }
Example #9
Source File: ViewPagerTabListViewActivity.java From Android-ObservableScrollView with Apache License 2.0 | 5 votes |
private void propagateToolbarState(boolean isShown) { int toolbarHeight = mToolbarView.getHeight(); // Set scrollY for the fragments that are not created yet mPagerAdapter.setScrollY(isShown ? 0 : toolbarHeight); // Set scrollY for the active fragments for (int i = 0; i < mPagerAdapter.getCount(); i++) { // Skip current item if (i == mPager.getCurrentItem()) { continue; } // Skip destroyed or not created item Fragment f = mPagerAdapter.getItemAt(i); if (f == null) { continue; } View view = f.getView(); if (view == null) { continue; } ObservableListView listView = (ObservableListView) view.findViewById(R.id.scroll); if (isShown) { // Scroll up if (0 < listView.getCurrentScrollY()) { listView.setSelection(0); } } else { // Scroll down (to hide padding) if (listView.getCurrentScrollY() < toolbarHeight) { listView.setSelection(1); } } } }
Example #10
Source File: HandleTouchListViewActivity.java From Android-ObservableScrollView with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_handletouchlistview); ObservableListView listView = (ObservableListView) findViewById(R.id.scroll); listView.setScrollViewCallbacks(this); listView.setAdapter(new CustomAdapter(this, getDummyData())); }
Example #11
Source File: ViewPagerTab2ListViewFragment.java From Android-ObservableScrollView with Apache License 2.0 | 5 votes |
@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); setDummyData(listView); listView.setTouchInterceptionViewGroup((ViewGroup) parentActivity.findViewById(R.id.container)); if (parentActivity instanceof ObservableScrollViewCallbacks) { listView.setScrollViewCallbacks((ObservableScrollViewCallbacks) parentActivity); } return view; }
Example #12
Source File: TouchInterceptionListViewActivityTest.java From Android-ObservableScrollView with Apache License 2.0 | 5 votes |
@Override protected void setUp() throws Exception { super.setUp(); setActivityInitialTouchMode(true); activity = getActivity(); scrollable = (ObservableListView) activity.findViewById(R.id.scrollable); }
Example #13
Source File: TouchInterceptionListViewActivity.java From Android-ObservableScrollView with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_touchinterception_listview); ((TextView) findViewById(R.id.title)).setText(getClass().getSimpleName()); mScrollable = (Scrollable) findViewById(R.id.scrollable); mScrollable.setScrollViewCallbacks(this); UiTestUtils.setDummyData(this, (ObservableListView) 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 #14
Source File: ListViewScrollFromBottomActivityTest.java From Android-ObservableScrollView with Apache License 2.0 | 5 votes |
@Override protected void setUp() throws Exception { super.setUp(); setActivityInitialTouchMode(true); activity = getActivity(); scrollable = (ObservableListView) activity.findViewById(R.id.scrollable); }
Example #15
Source File: ListViewScrollFromBottomActivity.java From Android-ObservableScrollView with Apache License 2.0 | 5 votes |
@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); } }); }
Example #16
Source File: ListViewActivityTest.java From Android-ObservableScrollView with Apache License 2.0 | 5 votes |
@Override protected void setUp() throws Exception { super.setUp(); setActivityInitialTouchMode(true); activity = getActivity(); scrollable = (ObservableListView) activity.findViewById(R.id.scrollable); callbackCounter = new int[2]; }
Example #17
Source File: ListViewActivityTest.java From Android-ObservableScrollView with Apache License 2.0 | 5 votes |
public void testInitialize() throws Throwable { runTestOnUiThread(new Runnable() { @Override public void run() { new ObservableListView(activity); new ObservableListView(activity, null, 0); } }); }
Example #18
Source File: ListViewActivityTest.java From Android-ObservableScrollView with Apache License 2.0 | 5 votes |
public void testNoCallbacks() throws Throwable { runTestOnUiThread(new Runnable() { @Override public void run() { scrollable = (ObservableListView) activity.findViewById(R.id.scrollable); scrollable.setScrollViewCallbacks(null); } }); testScroll(); }
Example #19
Source File: ViewPagerTab2ListViewFragment.java From Android-ObservableScrollView with Apache License 2.0 | 5 votes |
@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.setDummyData(getActivity(), listView); listView.setTouchInterceptionViewGroup((ViewGroup) parentActivity.findViewById(R.id.container)); if (parentActivity instanceof ObservableScrollViewCallbacks) { listView.setScrollViewCallbacks((ObservableScrollViewCallbacks) parentActivity); } return view; }
Example #20
Source File: FillGap3ListViewActivity.java From Android-ObservableScrollView with Apache License 2.0 | 5 votes |
@Override protected ObservableListView createScrollable() { ObservableListView listView = (ObservableListView) findViewById(R.id.scroll); listView.setScrollViewCallbacks(this); setDummyDataFew(listView); return listView; }
Example #21
Source File: FillGap2ListViewActivity.java From Android-ObservableScrollView with Apache License 2.0 | 5 votes |
@Override protected ObservableListView createScrollable() { ObservableListView listView = (ObservableListView) findViewById(R.id.scroll); listView.setScrollViewCallbacks(this); setDummyDataWithHeader(listView, mFlexibleSpaceImageHeight); return listView; }
Example #22
Source File: ParallaxToolbarListViewActivity.java From Android-ObservableScrollView with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_parallaxtoolbarlistview) ; 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); mListView = (ObservableListView) findViewById(R.id.list); mListView.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); mListView.addHeaderView(paddingView); setDummyData(mListView); // mListBackgroundView makes ListView's background except header view. mListBackgroundView = findViewById(R.id.list_background); }
Example #23
Source File: ViewPagerTabListViewFragment.java From Android-ObservableScrollView with Apache License 2.0 | 5 votes |
@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; }
Example #24
Source File: FillGapListViewActivity.java From Android-ObservableScrollView with Apache License 2.0 | 5 votes |
@Override protected ObservableListView createScrollable() { ObservableListView listView = (ObservableListView) findViewById(R.id.scroll); listView.setScrollViewCallbacks(this); setDummyDataWithHeader(listView, mFlexibleSpaceImageHeight); return listView; }
Example #25
Source File: ScrollFromBottomListViewActivity.java From Android-ObservableScrollView with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_stickyheaderlistview); setSupportActionBar((Toolbar) findViewById(R.id.toolbar)); mHeaderView = findViewById(R.id.header); ViewCompat.setElevation(mHeaderView, getResources().getDimension(R.dimen.toolbar_elevation)); mToolbarView = findViewById(R.id.toolbar); mListView = (ObservableListView) findViewById(R.id.list); mListView.setScrollViewCallbacks(this); LayoutInflater inflater = LayoutInflater.from(this); mListView.addHeaderView(inflater.inflate(R.layout.padding, mListView, false)); // toolbar mListView.addHeaderView(inflater.inflate(R.layout.padding, mListView, false)); // sticky view setDummyData(mListView); ScrollUtils.addOnGlobalLayoutListener(mListView, new Runnable() { @Override public void run() { int count = mListView.getAdapter().getCount() - 1; int position = count == 0 ? 1 : count > 0 ? count : 0; mListView.smoothScrollToPosition(position); mListView.setSelection(position); } }); }
Example #26
Source File: FragmentActionBarControlListViewFragment.java From Android-ObservableScrollView with Apache License 2.0 | 5 votes |
@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; }
Example #27
Source File: ViewPagerTabListViewActivity.java From UltimateAndroid with Apache License 2.0 | 5 votes |
private void propagateToolbarState(boolean isShown) { int toolbarHeight = mToolbarView.getHeight(); // Set scrollY for the fragments that are not created yet mPagerAdapter.setScrollY(isShown ? 0 : toolbarHeight); // Set scrollY for the active fragments for (int i = 0; i < mPagerAdapter.getCount(); i++) { // Skip current item if (i == mPager.getCurrentItem()) { continue; } // Skip destroyed or not created item Fragment f = mPagerAdapter.getItemAt(i); if (f == null) { continue; } ObservableListView listView = (ObservableListView) f.getView().findViewById(R.id.list); if (isShown) { // Scroll up if (0 < listView.getCurrentScrollY()) { listView.setSelection(0); } } else { // Scroll down (to hide padding) if (listView.getCurrentScrollY() < toolbarHeight) { listView.setSelection(1); } } } }
Example #28
Source File: ViewPagerTabListViewActivity.java From UltimateAndroid with Apache License 2.0 | 5 votes |
@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.list); 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(); } } }
Example #29
Source File: ScrollFromBottomListViewActivity.java From UltimateAndroid with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.observable_scroll_view_activity_toolbarcontrollistview); setSupportActionBar((Toolbar) findViewById(R.id.toolbar)); mHeaderView = findViewById(R.id.header); ViewCompat.setElevation(mHeaderView, getResources().getDimension(R.dimen.toolbar_elevation)); mToolbarView = findViewById(R.id.toolbar); mListView = (ObservableListView) findViewById(R.id.list); mListView.setScrollViewCallbacks(this); LayoutInflater inflater = LayoutInflater.from(this); mListView.addHeaderView(inflater.inflate(R.layout.observable_scroll_view_padding, null)); // toolbar mListView.addHeaderView(inflater.inflate(R.layout.observable_scroll_view_padding, null)); // sticky view List<String> items = new ArrayList<String>(); for (int i = 1; i <= 100; i++) { items.add("Item " + i); } mListView.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, items)); ViewTreeObserver vto = mListView.getViewTreeObserver(); vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { mListView.getViewTreeObserver().removeGlobalOnLayoutListener(this); } else { mListView.getViewTreeObserver().removeOnGlobalLayoutListener(this); } int count = mListView.getAdapter().getCount() - 1; int position = count == 0 ? 1 : count > 0 ? count : 0; mListView.smoothScrollToPosition(position); mListView.setSelection(position); } }); }
Example #30
Source File: FlexibleSpaceWithImageListViewActivity.java From Android-ObservableScrollView with Apache License 2.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_flexiblespacewithimagelistview); 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); ObservableListView listView = (ObservableListView) findViewById(R.id.list); listView.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); listView.addHeaderView(paddingView); setDummyData(listView); 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(FlexibleSpaceWithImageListViewActivity.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); }