use of com.github.ksoichiro.android.observablescrollview.ObservableScrollView in project Android-ObservableScrollView by ksoichiro.
the class ViewPagerTabScrollViewActivity method onUpOrCancelMotionEvent.
@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 (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();
}
}
}
use of com.github.ksoichiro.android.observablescrollview.ObservableScrollView in project Android-ObservableScrollView by ksoichiro.
the class ViewPagerTabScrollViewActivity method propagateToolbarState.
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;
}
ObservableScrollView scrollView = (ObservableScrollView) view.findViewById(R.id.scroll);
if (isShown) {
// Scroll up
if (0 < scrollView.getCurrentScrollY()) {
scrollView.scrollTo(0, 0);
}
} else {
// Scroll down (to hide padding)
if (scrollView.getCurrentScrollY() < toolbarHeight) {
scrollView.scrollTo(0, toolbarHeight);
}
}
}
}
use of com.github.ksoichiro.android.observablescrollview.ObservableScrollView in project Android-ObservableScrollView by ksoichiro.
the class ViewPagerTabScrollViewFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_scrollview, container, false);
final ObservableScrollView scrollView = (ObservableScrollView) view.findViewById(R.id.scroll);
Activity parentActivity = getActivity();
if (parentActivity instanceof ObservableScrollViewCallbacks) {
// 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(scrollView, new Runnable() {
@Override
public void run() {
scrollView.scrollTo(0, scrollY);
}
});
}
// 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
scrollView.setTouchInterceptionViewGroup((ViewGroup) parentActivity.findViewById(R.id.root));
scrollView.setScrollViewCallbacks((ObservableScrollViewCallbacks) parentActivity);
}
return view;
}
use of com.github.ksoichiro.android.observablescrollview.ObservableScrollView in project sharelock-android by auth0.
the class AboutActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_about);
ImageButton newButton = (ImageButton) findViewById(R.id.about_new_button);
newButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startNewSecretActivity();
}
});
final Toolbar toolbar = (Toolbar) findViewById(R.id.about_toolbar);
setSupportActionBar(toolbar);
mFlexibleSpaceImageHeight = getResources().getDimensionPixelSize(R.dimen.about_flexible_space_height);
mActionBarSize = getActionBarSize();
// Even when the top gap has began to change, header bar still can move
// within mIntersectionHeight.
mIntersectionHeight = getResources().getDimensionPixelSize(R.dimen.about_intersection_height);
mHeader = findViewById(R.id.about_header);
mHeaderBar = findViewById(R.id.about_header_bar);
mHeaderBackground = findViewById(R.id.about_header_background);
final ObservableScrollView scrollable = createScrollable();
final TextView subtitleText = (TextView) findViewById(R.id.about_subtitle);
subtitleText.setText(getString(R.string.about_subtitle));
setTitle(null);
ScrollUtils.addOnGlobalLayoutListener((View) scrollable, new Runnable() {
@Override
public void run() {
mReady = true;
updateViews(scrollable.getCurrentScrollY(), false);
}
});
TextView aboutText = (TextView) findViewById(R.id.container);
aboutText.setText(Html.fromHtml(getString(R.string.sharelock_about)));
}
use of com.github.ksoichiro.android.observablescrollview.ObservableScrollView in project Android-ObservableScrollView by ksoichiro.
the class FillGapScrollViewActivity method createScrollable.
@Override
protected ObservableScrollView createScrollable() {
ObservableScrollView scrollView = (ObservableScrollView) findViewById(R.id.scroll);
scrollView.setScrollViewCallbacks(this);
return scrollView;
}
Aggregations