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

The following examples show how to use com.github.ksoichiro.android.observablescrollview.ScrollState. 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: ToolbarControlWebViewActivity.java    From UltimateAndroid with Apache License 2.0 6 votes vote down vote up
@Override
public void onUpOrCancelMotionEvent(ScrollState scrollState) {
    mDragging = false;
    mBaseTranslationY = 0;

    float headerTranslationY = ViewHelper.getTranslationY(mHeaderView);
    int toolbarHeight = mToolbarView.getHeight();
    if (scrollState == ScrollState.UP) {
        if (toolbarHeight < mScrollView.getCurrentScrollY()) {
            if (headerTranslationY != -toolbarHeight) {
                ViewPropertyAnimator.animate(mHeaderView).cancel();
                ViewPropertyAnimator.animate(mHeaderView).translationY(-toolbarHeight).setDuration(200).start();
            }
        }
    } else if (scrollState == ScrollState.DOWN) {
        if (toolbarHeight < mScrollView.getCurrentScrollY()) {
            if (headerTranslationY != 0) {
                ViewPropertyAnimator.animate(mHeaderView).cancel();
                ViewPropertyAnimator.animate(mHeaderView).translationY(0).setDuration(200).start();
            }
        }
    }
}
 
Example #2
Source File: ActionBarControlWebViewActivity.java    From Android-ObservableScrollView with Apache License 2.0 6 votes vote down vote up
@Override
public void onUpOrCancelMotionEvent(ScrollState scrollState) {
    ActionBar ab = getSupportActionBar();
    if (ab == null) {
        return;
    }
    if (scrollState == ScrollState.UP) {
        if (ab.isShowing()) {
            ab.hide();
        }
    } else if (scrollState == ScrollState.DOWN) {
        if (!ab.isShowing()) {
            ab.show();
        }
    }
}
 
Example #3
Source File: StickyHeaderScrollViewActivity.java    From Android-ObservableScrollView with Apache License 2.0 6 votes vote down vote up
@Override
public void onUpOrCancelMotionEvent(ScrollState scrollState) {
    mBaseTranslationY = 0;

    if (scrollState == ScrollState.DOWN) {
        showToolbar();
    } else if (scrollState == ScrollState.UP) {
        int toolbarHeight = mToolbarView.getHeight();
        int scrollY = mScrollView.getCurrentScrollY();
        if (toolbarHeight <= scrollY) {
            hideToolbar();
        } else {
            showToolbar();
        }
    } else {
        // Even if onScrollChanged occurs without scrollY changing, toolbar should be adjusted
        if (!toolbarIsShown() && !toolbarIsHidden()) {
            // Toolbar is moving but doesn't know which to move:
            // you can change this to hideToolbar()
            showToolbar();
        }
    }
}
 
Example #4
Source File: ActionBarControlRecyclerViewActivity.java    From Android-ObservableScrollView with Apache License 2.0 6 votes vote down vote up
@Override
public void onUpOrCancelMotionEvent(ScrollState scrollState) {
    ActionBar ab = getSupportActionBar();
    if (ab == null) {
        return;
    }
    if (scrollState == ScrollState.UP) {
        if (ab.isShowing()) {
            ab.hide();
        }
    } else if (scrollState == ScrollState.DOWN) {
        if (!ab.isShowing()) {
            ab.show();
        }
    }
}
 
Example #5
Source File: ViewPagerTabActivity.java    From Android-ObservableScrollView with Apache License 2.0 6 votes vote down vote up
@Override
public void onUpOrCancelMotionEvent(ScrollState scrollState) {
    mBaseTranslationY = 0;

    Fragment fragment = getCurrentFragment();
    if (fragment == null) {
        return;
    }
    View view = fragment.getView();
    if (view == null) {
        return;
    }

    // ObservableXxxViews have same API
    // but currently they don't have any common interfaces.
    adjustToolbar(scrollState, view);
}
 
Example #6
Source File: ActionBarControlGridViewActivity.java    From Android-ObservableScrollView with Apache License 2.0 6 votes vote down vote up
@Override
public void onUpOrCancelMotionEvent(ScrollState scrollState) {
    ActionBar ab = getSupportActionBar();
    if (ab == null) {
        return;
    }
    if (scrollState == ScrollState.UP) {
        if (ab.isShowing()) {
            ab.hide();
        }
    } else if (scrollState == ScrollState.DOWN) {
        if (!ab.isShowing()) {
            ab.show();
        }
    }
}
 
Example #7
Source File: ScrollFromBottomListViewActivity.java    From Android-ObservableScrollView with Apache License 2.0 6 votes vote down vote up
@Override
public void onUpOrCancelMotionEvent(ScrollState scrollState) {
    mBaseTranslationY = 0;

    float headerTranslationY = ViewHelper.getTranslationY(mHeaderView);
    int toolbarHeight = mToolbarView.getHeight();
    if (scrollState == ScrollState.UP) {
        if (toolbarHeight < mListView.getCurrentScrollY()) {
            if (headerTranslationY != -toolbarHeight) {
                ViewPropertyAnimator.animate(mHeaderView).cancel();
                ViewPropertyAnimator.animate(mHeaderView).translationY(-toolbarHeight).setDuration(200).start();
            }
        }
    } else if (scrollState == ScrollState.DOWN) {
        if (toolbarHeight < mListView.getCurrentScrollY()) {
            if (headerTranslationY != 0) {
                ViewPropertyAnimator.animate(mHeaderView).cancel();
                ViewPropertyAnimator.animate(mHeaderView).translationY(0).setDuration(200).start();
            }
        }
    }
}
 
Example #8
Source File: MainActivity.java    From ExpressHelper with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onUpOrCancelMotionEvent(ScrollState scrollState) {
	mBaseTranslationY = 0;

	Fragment fragment = getCurrentFragment();
	if (fragment == null) {
		return;
	}
	View view = fragment.getView();
	if (view == null) {
		return;
	}

	// ObservableXxxViews have same API
	// but currently they don't have any common interfaces.
	adjustToolbar(scrollState, view);
}
 
Example #9
Source File: FragmentActionBarControlListViewFragment.java    From Android-ObservableScrollView with Apache License 2.0 6 votes vote down vote up
@Override
public void onUpOrCancelMotionEvent(ScrollState scrollState) {
    AppCompatActivity activity = (AppCompatActivity) getActivity();
    if (activity == null) {
        return;
    }
    ActionBar ab = activity.getSupportActionBar();
    if (ab == null) {
        return;
    }
    if (scrollState == ScrollState.UP) {
        if (ab.isShowing()) {
            ab.hide();
        }
    } else if (scrollState == ScrollState.DOWN) {
        if (!ab.isShowing()) {
            ab.show();
        }
    }
}
 
Example #10
Source File: ViewPagerTab2Activity.java    From Android-ObservableScrollView with Apache License 2.0 6 votes vote down vote up
private void adjustToolbar(ScrollState scrollState) {
    int toolbarHeight = mToolbarView.getHeight();
    final Scrollable scrollable = getCurrentScrollable();
    if (scrollable == null) {
        return;
    }
    int scrollY = scrollable.getCurrentScrollY();
    if (scrollState == ScrollState.DOWN) {
        showToolbar();
    } else if (scrollState == ScrollState.UP) {
        if (toolbarHeight <= scrollY) {
            hideToolbar();
        } else {
            showToolbar();
        }
    } else if (!toolbarIsShown() && !toolbarIsHidden()) {
        // Toolbar is moving but doesn't know which to move:
        // you can change this to hideToolbar()
        showToolbar();
    }
}
 
Example #11
Source File: HollyViewPagerAnimator.java    From HollyViewPager with Apache License 2.0 6 votes vote down vote up
public void registerScrollView(final ObservableScrollView scrollView) {
    scrolls.add(scrollView);

    if (scrollView.getParent() != null && scrollView.getParent().getParent() != null && scrollView.getParent().getParent() instanceof ViewGroup)
        scrollView.setTouchInterceptionViewGroup((ViewGroup) scrollView.getParent().getParent());

    scrollView.setScrollViewCallbacks(new ObservableScrollViewCallbacks() {
        @Override
        public void onScrollChanged(int i, boolean b, boolean b1) {
            onScroll(scrollView, i);
        }

        @Override
        public void onDownMotionEvent() {

        }

        @Override
        public void onUpOrCancelMotionEvent(ScrollState scrollState) {

        }
    });
}
 
Example #12
Source File: ActionBarControlScrollViewActivity.java    From Android-ObservableScrollView with Apache License 2.0 6 votes vote down vote up
@Override
public void onUpOrCancelMotionEvent(ScrollState scrollState) {
    ActionBar ab = getSupportActionBar();
    if (ab == null) {
        return;
    }
    if (scrollState == ScrollState.UP) {
        if (ab.isShowing()) {
            ab.hide();
        }
    } else if (scrollState == ScrollState.DOWN) {
        if (!ab.isShowing()) {
            ab.show();
        }
    }
}
 
Example #13
Source File: ActionBarControlListViewActivity.java    From Android-ObservableScrollView with Apache License 2.0 6 votes vote down vote up
@Override
public void onUpOrCancelMotionEvent(ScrollState scrollState) {
    ActionBar ab = getSupportActionBar();
    if (ab == null) {
        return;
    }
    if (scrollState == ScrollState.UP) {
        if (ab.isShowing()) {
            ab.hide();
        }
    } else if (scrollState == ScrollState.DOWN) {
        if (!ab.isShowing()) {
            ab.show();
        }
    }
}
 
Example #14
Source File: ViewPagerTabActivity.java    From Android-ObservableScrollView with Apache License 2.0 6 votes vote down vote up
@Override
public void onUpOrCancelMotionEvent(ScrollState scrollState) {
    mBaseTranslationY = 0;

    Fragment fragment = getCurrentFragment();
    if (fragment == null) {
        return;
    }
    View view = fragment.getView();
    if (view == null) {
        return;
    }

    // ObservableXxxViews have same API
    // but currently they don't have any common interfaces.
    adjustToolbar(scrollState, view);
}
 
Example #15
Source File: ToolbarControlScrollViewActivity.java    From UltimateAndroid with Apache License 2.0 6 votes vote down vote up
@Override
public void onUpOrCancelMotionEvent(ScrollState scrollState) {
    mBaseTranslationY = 0;

    float headerTranslationY = ViewHelper.getTranslationY(mHeaderView);
    int toolbarHeight = mToolbarView.getHeight();
    if (scrollState == ScrollState.UP) {
        if (toolbarHeight < mScrollView.getCurrentScrollY()) {
            if (headerTranslationY != -toolbarHeight) {
                ViewPropertyAnimator.animate(mHeaderView).cancel();
                ViewPropertyAnimator.animate(mHeaderView).translationY(-toolbarHeight).setDuration(200).start();
            }
        }
    } else if (scrollState == ScrollState.DOWN) {
        if (toolbarHeight < mScrollView.getCurrentScrollY()) {
            if (headerTranslationY != 0) {
                ViewPropertyAnimator.animate(mHeaderView).cancel();
                ViewPropertyAnimator.animate(mHeaderView).translationY(0).setDuration(200).start();
            }
        }
    }
}
 
Example #16
Source File: ViewPagerTabActivity.java    From UltimateAndroid with Apache License 2.0 6 votes vote down vote up
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 #17
Source File: ScrollFromBottomListViewActivity.java    From UltimateAndroid with Apache License 2.0 6 votes vote down vote up
@Override
public void onUpOrCancelMotionEvent(ScrollState scrollState) {
    mBaseTranslationY = 0;

    float headerTranslationY = ViewHelper.getTranslationY(mHeaderView);
    int toolbarHeight = mToolbarView.getHeight();
    if (scrollState == ScrollState.UP) {
        if (toolbarHeight < mListView.getCurrentScrollY()) {
            if (headerTranslationY != -toolbarHeight) {
                ViewPropertyAnimator.animate(mHeaderView).cancel();
                ViewPropertyAnimator.animate(mHeaderView).translationY(-toolbarHeight).setDuration(200).start();
            }
        }
    } else if (scrollState == ScrollState.DOWN) {
        if (toolbarHeight < mListView.getCurrentScrollY()) {
            if (headerTranslationY != 0) {
                ViewPropertyAnimator.animate(mHeaderView).cancel();
                ViewPropertyAnimator.animate(mHeaderView).translationY(0).setDuration(200).start();
            }
        }
    }
}
 
Example #18
Source File: ViewPagerTabActivity.java    From UltimateAndroid with Apache License 2.0 6 votes vote down vote up
private void adjustToolbarForScrollViews(ScrollState scrollState, View view) {
    int toolbarHeight = mToolbarView.getHeight();
    final ObservableScrollView scrollView = (ObservableScrollView) view.findViewById(R.id.scroll);
    if (scrollView == null) {
        return;
    }
    if (scrollState == ScrollState.UP) {
        if (toolbarHeight < scrollView.getCurrentScrollY()) {
            hideToolbar();
        } else if (scrollView.getCurrentScrollY() < toolbarHeight) {
            showToolbar();
        }
    } else if (scrollState == ScrollState.DOWN) {
        if (toolbarHeight < scrollView.getCurrentScrollY()) {
            showToolbar();
        }
    }
}
 
Example #19
Source File: ViewPagerTabActivity.java    From UltimateAndroid with Apache License 2.0 6 votes vote down vote up
@Override
public void onUpOrCancelMotionEvent(ScrollState scrollState) {
    mBaseTranslationY = 0;

    Fragment fragment = getCurrentFragment();
    if (fragment == null) {
        return;
    }
    View view = fragment.getView();
    if (view == null) {
        return;
    }

    // ObservableXxxViews have same API
    // but currently they don't have any common interfaces.
    adjustToolbarForScrollViews(scrollState, view);
    adjustToolbarForListViews(scrollState, view);
}
 
Example #20
Source File: ToolbarControlListViewActivity.java    From UltimateAndroid with Apache License 2.0 6 votes vote down vote up
@Override
public void onUpOrCancelMotionEvent(ScrollState scrollState) {
    mBaseTranslationY = 0;

    float headerTranslationY = ViewHelper.getTranslationY(mHeaderView);
    int toolbarHeight = mToolbarView.getHeight();
    if (scrollState == ScrollState.UP) {
        if (toolbarHeight < mListView.getCurrentScrollY()) {
            if (headerTranslationY != -toolbarHeight) {
                ViewPropertyAnimator.animate(mHeaderView).cancel();
                ViewPropertyAnimator.animate(mHeaderView).translationY(-toolbarHeight).setDuration(200).start();
            }
        }
    } else if (scrollState == ScrollState.DOWN) {
        if (toolbarHeight < mListView.getCurrentScrollY()) {
            if (headerTranslationY != 0) {
                ViewPropertyAnimator.animate(mHeaderView).cancel();
                ViewPropertyAnimator.animate(mHeaderView).translationY(0).setDuration(200).start();
            }
        }
    }
}
 
Example #21
Source File: ScrollFromBottomRecyclerViewActivity.java    From Android-ObservableScrollView with Apache License 2.0 6 votes vote down vote up
@Override
public void onUpOrCancelMotionEvent(ScrollState scrollState) {
    mBaseTranslationY = 0;

    float headerTranslationY = ViewHelper.getTranslationY(mHeaderView);
    int toolbarHeight = mToolbarView.getHeight();
    if (scrollState == ScrollState.UP) {
        if (toolbarHeight < mRecyclerView.getCurrentScrollY()) {
            if (headerTranslationY != -toolbarHeight) {
                ViewPropertyAnimator.animate(mHeaderView).cancel();
                ViewPropertyAnimator.animate(mHeaderView).translationY(-toolbarHeight).setDuration(200).start();
            }
        }
    } else if (scrollState == ScrollState.DOWN) {
        if (toolbarHeight < mRecyclerView.getCurrentScrollY()) {
            if (headerTranslationY != 0) {
                ViewPropertyAnimator.animate(mHeaderView).cancel();
                ViewPropertyAnimator.animate(mHeaderView).translationY(0).setDuration(200).start();
            }
        }
    }
}
 
Example #22
Source File: ViewPagerTabScrollViewWithFabFragment.java    From Android-ObservableScrollView with Apache License 2.0 5 votes vote down vote up
@Override
public void onUpOrCancelMotionEvent(ScrollState scrollState) {
    if (getActivity() != null && getActivity() instanceof ObservableScrollViewCallbacks) {
        ((ObservableScrollViewCallbacks) getActivity()).onUpOrCancelMotionEvent(scrollState);
    }

    if (scrollState == ScrollState.UP) {
        hideFab();
    } else if (scrollState == ScrollState.DOWN) {
        showFab();
    }
}
 
Example #23
Source File: ActionBarControlListViewActivity.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
@Override
public void onUpOrCancelMotionEvent(ScrollState scrollState) {
    ActionBar ab = getSupportActionBar();
    if (scrollState == ScrollState.UP) {
        if (ab.isShowing()) {
            ab.hide();
        }
    } else if (scrollState == ScrollState.DOWN) {
        if (!ab.isShowing()) {
            ab.show();
        }
    }
}
 
Example #24
Source File: ViewPagerTabFragmentParentFragment.java    From Android-ObservableScrollView with Apache License 2.0 5 votes vote down vote up
@Override
public void onUpOrCancelMotionEvent(ScrollState scrollState) {
    if (!mScrolled) {
        // This event can be used only when TouchInterceptionFrameLayout
        // doesn't handle the consecutive events.
        adjustToolbar(scrollState);
    }
}
 
Example #25
Source File: ToolbarControlBaseActivity.java    From Android-ObservableScrollView with Apache License 2.0 5 votes vote down vote up
@Override
public void onUpOrCancelMotionEvent(ScrollState scrollState) {
    Log.e("DEBUG", "onUpOrCancelMotionEvent: " + scrollState);
    if (scrollState == ScrollState.UP) {
        if (toolbarIsShown()) {
            hideToolbar();
        }
    } else if (scrollState == ScrollState.DOWN) {
        if (toolbarIsHidden()) {
            showToolbar();
        }
    }
}
 
Example #26
Source File: ViewPagerTabScrollViewActivity.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
@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 ObservableScrollView scrollView = (ObservableScrollView) view.findViewById(R.id.scroll);
    if (scrollState == ScrollState.UP) {
        if (toolbarHeight < scrollView.getCurrentScrollY()) {
            hideToolbar();
        } else if (scrollView.getCurrentScrollY() < toolbarHeight) {
            showToolbar();
        }
    } else if (scrollState == ScrollState.DOWN) {
        if (toolbarHeight < scrollView.getCurrentScrollY()) {
            showToolbar();
        }
    }
}
 
Example #27
Source File: ViewPagerTab2Activity.java    From Android-ObservableScrollView with Apache License 2.0 5 votes vote down vote up
@Override
public void onUpOrCancelMotionEvent(ScrollState scrollState) {
    if (!mScrolled) {
        // This event can be used only when TouchInterceptionFrameLayout
        // doesn't handle the consecutive events.
        adjustToolbar(scrollState);
    }
}
 
Example #28
Source File: ViewPagerTab2Activity.java    From Android-ObservableScrollView with Apache License 2.0 5 votes vote down vote up
@Override
public boolean shouldInterceptTouchEvent(MotionEvent ev, boolean moving, float diffX, float diffY) {
    if (!mScrolled && mSlop < Math.abs(diffX) && Math.abs(diffY) < Math.abs(diffX)) {
        // Horizontal scroll is maybe handled by ViewPager
        return false;
    }

    Scrollable scrollable = getCurrentScrollable();
    if (scrollable == null) {
        mScrolled = false;
        return false;
    }

    // If interceptionLayout can move, it should intercept.
    // And once it begins to move, horizontal scroll shouldn't work any longer.
    int toolbarHeight = mToolbarView.getHeight();
    int translationY = (int) ViewHelper.getTranslationY(mInterceptionLayout);
    boolean scrollingUp = 0 < diffY;
    boolean scrollingDown = diffY < 0;
    if (scrollingUp) {
        if (translationY < 0) {
            mScrolled = true;
            mLastScrollState = ScrollState.UP;
            return true;
        }
    } else if (scrollingDown) {
        if (-toolbarHeight < translationY) {
            mScrolled = true;
            mLastScrollState = ScrollState.DOWN;
            return true;
        }
    }
    mScrolled = false;
    return false;
}
 
Example #29
Source File: ViewPagerTabListViewActivity.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
@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 #30
Source File: ViewPagerTabActivity.java    From Android-ObservableScrollView with Apache License 2.0 5 votes vote down vote up
private void adjustToolbar(ScrollState scrollState, View view) {
    int toolbarHeight = mToolbarView.getHeight();
    final Scrollable scrollView = (Scrollable) view.findViewById(R.id.scroll);
    if (scrollView == null) {
        return;
    }
    int scrollY = scrollView.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();
        }
    }
}