Java Code Examples for com.github.ksoichiro.android.observablescrollview.ObservableScrollView#setScrollViewCallbacks()

The following examples show how to use com.github.ksoichiro.android.observablescrollview.ObservableScrollView#setScrollViewCallbacks() . 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: 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 2
Source File: DetailsActivity.java    From Material-Design-Example with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.screen_details);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);


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

    mScrollView = (ObservableScrollView) findViewById(R.id.scroll);
    mScrollView.setScrollViewCallbacks(this);

    mParallaxImageHeight = getResources().getDimensionPixelSize(R.dimen.drawer_menu_width);
}
 
Example 3
Source File: StickyHeaderWebViewActivity.java    From Android-ObservableScrollView with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_stickyheaderwebview);

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

    mScrollView = (ObservableScrollView) findViewById(R.id.scroll);
    mScrollView.setScrollViewCallbacks(mScrollViewScrollCallbacks);

    ObservableWebView mWebView = (ObservableWebView) findViewById(R.id.web);
    mWebView.setScrollViewCallbacks(mWebViewScrollCallbacks);
    mWebView.loadUrl("file:///android_asset/lipsum.html");
}
 
Example 4
Source File: ParallaxToolbarScrollViewActivity.java    From Android-ObservableScrollView with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_parallaxtoolbarscrollview);

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

    mScrollView = (ObservableScrollView) findViewById(R.id.scroll);
    mScrollView.setScrollViewCallbacks(this);

    mParallaxImageHeight = getResources().getDimensionPixelSize(R.dimen.parallax_image_height);
}
 
Example 5
Source File: ToolbarControlWebViewActivity.java    From UltimateAndroid with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.observable_scroll_view_activity_toolbarcontrolwebview);

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

    mScrollView = (ObservableScrollView) findViewById(R.id.scroll);
    mScrollView.setScrollViewCallbacks(mScrollViewScrollCallbacks);

    ObservableWebView mWebView = (ObservableWebView) findViewById(R.id.web);
    mWebView.setScrollViewCallbacks(mWebViewScrollCallbacks);
    mWebView.loadUrl("file:///android_asset/lipsum.html");
}
 
Example 6
Source File: StickyHeaderScrollViewActivity.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_stickyheaderscrollview);

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

    mScrollView = (ObservableScrollView) findViewById(R.id.scroll);
    mScrollView.setScrollViewCallbacks(this);
}
 
Example 7
Source File: ViewPagerTab2ScrollViewFragment.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_scrollview_noheader, container, false);

    final ObservableScrollView scrollView = (ObservableScrollView) view.findViewById(R.id.scroll);
    Activity parentActivity = getActivity();
    scrollView.setTouchInterceptionViewGroup((ViewGroup) parentActivity.findViewById(R.id.container));
    if (parentActivity instanceof ObservableScrollViewCallbacks) {
        scrollView.setScrollViewCallbacks((ObservableScrollViewCallbacks) parentActivity);
    }
    return view;
}
 
Example 8
Source File: ViewPagerTab2ScrollViewFragment.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_scrollview_noheader, container, false);

    final ObservableScrollView scrollView = (ObservableScrollView) view.findViewById(R.id.scroll);
    Activity parentActivity = getActivity();
    scrollView.setTouchInterceptionViewGroup((ViewGroup) parentActivity.findViewById(R.id.container));
    if (parentActivity instanceof ObservableScrollViewCallbacks) {
        scrollView.setScrollViewCallbacks((ObservableScrollViewCallbacks) parentActivity);
    }
    return view;
}
 
Example 9
Source File: FlexibleSpaceToolbarScrollViewActivity.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_flexiblespacetoolbarscrollview);

    setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
    ActionBar ab = getSupportActionBar();
    if (ab != null) {
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }

    mFlexibleSpaceView = findViewById(R.id.flexible_space);
    mTitleView = (TextView) findViewById(R.id.title);
    mTitleView.setText(getTitle());
    setTitle(null);
    mToolbarView = findViewById(R.id.toolbar);

    final ObservableScrollView scrollView = (ObservableScrollView) findViewById(R.id.scroll);
    scrollView.setScrollViewCallbacks(this);

    mFlexibleSpaceHeight = getResources().getDimensionPixelSize(R.dimen.flexible_space_height);
    int flexibleSpaceAndToolbarHeight = mFlexibleSpaceHeight + getActionBarSize();

    findViewById(R.id.body).setPadding(0, flexibleSpaceAndToolbarHeight, 0, 0);
    mFlexibleSpaceView.getLayoutParams().height = flexibleSpaceAndToolbarHeight;

    ScrollUtils.addOnGlobalLayoutListener(mTitleView, new Runnable() {
        @Override
        public void run() {
            updateFlexibleSpaceText(scrollView.getCurrentScrollY());
        }
    });
}
 
Example 10
Source File: ViewPagerTabScrollViewFragment.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_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;
}
 
Example 11
Source File: FlexibleSpaceToolbarScrollViewActivity.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_flexiblespacetoolbarscrollview);

    setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    mFlexibleSpaceView = findViewById(R.id.flexible_space);
    mTitleView = (TextView) findViewById(R.id.title);
    mTitleView.setText(getTitle());
    setTitle(null);
    mToolbarView = findViewById(R.id.toolbar);

    final ObservableScrollView scrollView = (ObservableScrollView) findViewById(R.id.scroll);
    scrollView.setScrollViewCallbacks(this);

    mFlexibleSpaceHeight = getResources().getDimensionPixelSize(R.dimen.flexible_space_height);
    int flexibleSpaceAndToolbarHeight = mFlexibleSpaceHeight + getActionBarSize();

    findViewById(R.id.body).setPadding(0, flexibleSpaceAndToolbarHeight, 0, 0);
    mFlexibleSpaceView.getLayoutParams().height = flexibleSpaceAndToolbarHeight;

    ViewTreeObserver vto = mTitleView.getViewTreeObserver();
    vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
                mTitleView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
            } else {
                mTitleView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            }
            updateFlexibleSpaceText(scrollView.getCurrentScrollY());
        }
    });
}
 
Example 12
Source File: FlexibleSpaceWithImageScrollViewFragment.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_flexiblespacewithimagescrollview, container, false);

    final ObservableScrollView scrollView = (ObservableScrollView) view.findViewById(R.id.scroll);
    // 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) 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(scrollView, new Runnable() {
            @Override
            public void run() {
                scrollView.scrollTo(0, scrollY);
            }
        });
        updateFlexibleSpace(scrollY, view);
    } else {
        updateFlexibleSpace(0, view);
    }

    scrollView.setScrollViewCallbacks(this);

    return view;
}
 
Example 13
Source File: ActionBarControlScrollViewActivity.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_actionbarcontrolscrollview);

    ObservableScrollView scrollView = (ObservableScrollView) findViewById(R.id.scroll);
    scrollView.setScrollViewCallbacks(this);
}
 
Example 14
Source File: FillGapScrollViewActivity.java    From Android-ObservableScrollView with Apache License 2.0 4 votes vote down vote up
@Override
protected ObservableScrollView createScrollable() {
    ObservableScrollView scrollView = (ObservableScrollView) findViewById(R.id.scroll);
    scrollView.setScrollViewCallbacks(this);
    return scrollView;
}
 
Example 15
Source File: FillGap3ScrollViewActivity.java    From Android-ObservableScrollView with Apache License 2.0 4 votes vote down vote up
@Override
protected ObservableScrollView createScrollable() {
    ObservableScrollView scrollView = (ObservableScrollView) findViewById(R.id.scroll);
    scrollView.setScrollViewCallbacks(this);
    return scrollView;
}
 
Example 16
Source File: SlidingUpScrollViewActivity.java    From Android-ObservableScrollView with Apache License 2.0 4 votes vote down vote up
@Override
protected ObservableScrollView createScrollable() {
    ObservableScrollView scrollView = (ObservableScrollView) findViewById(R.id.scroll);
    scrollView.setScrollViewCallbacks(this);
    return scrollView;
}
 
Example 17
Source File: FlexibleSpaceWithImageScrollViewActivity.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_flexiblespacewithimagescrollview);

    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);
    mScrollView = (ObservableScrollView) findViewById(R.id.scroll);
    mScrollView.setScrollViewCallbacks(this);
    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(FlexibleSpaceWithImageScrollViewActivity.this, "FAB is clicked", Toast.LENGTH_SHORT).show();
        }
    });
    mFabMargin = getResources().getDimensionPixelSize(R.dimen.margin_standard);
    ViewHelper.setScaleX(mFab, 0);
    ViewHelper.setScaleY(mFab, 0);

    ScrollUtils.addOnGlobalLayoutListener(mScrollView, new Runnable() {
        @Override
        public void run() {
            mScrollView.scrollTo(0, mFlexibleSpaceImageHeight - mActionBarSize);

            // If you'd like to start from scrollY == 0, don't write like this:
            //mScrollView.scrollTo(0, 0);
            // The initial scrollY is 0, so it won't invoke onScrollChanged().
            // To do this, use the following:
            //onScrollChanged(0, false, false);

            // You can also achieve it with the following codes.
            // This causes scroll change from 1 to 0.
            //mScrollView.scrollTo(0, 1);
            //mScrollView.scrollTo(0, 0);
        }
    });
}
 
Example 18
Source File: FlexibleSpaceToolbarWebViewActivity.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_flexiblespacetoolbarwebview);

    setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
    ActionBar ab = getSupportActionBar();
    if (ab != null) {
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }

    mFlexibleSpaceView = findViewById(R.id.flexible_space);
    mTitleView = (TextView) findViewById(R.id.title);
    mTitleView.setText(getTitle());
    setTitle(null);
    mToolbarView = findViewById(R.id.toolbar);

    mWebViewContainer = findViewById(R.id.webViewContainer);

    final ObservableScrollView scrollView = (ObservableScrollView) findViewById(R.id.scroll);
    scrollView.setScrollViewCallbacks(this);

    WebView webView = (WebView) findViewById(R.id.webView);
    webView.loadUrl("file:///android_asset/lipsum.html");

    mFlexibleSpaceHeight = getResources().getDimensionPixelSize(R.dimen.flexible_space_height);
    int flexibleSpaceAndToolbarHeight = mFlexibleSpaceHeight + getActionBarSize();

    final FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) webView.getLayoutParams();
    layoutParams.topMargin = flexibleSpaceAndToolbarHeight;
    webView.setLayoutParams(layoutParams);

    mFlexibleSpaceView.getLayoutParams().height = flexibleSpaceAndToolbarHeight;

    ScrollUtils.addOnGlobalLayoutListener(mTitleView, new Runnable() {
        @Override
        public void run() {
            updateFlexibleSpaceText(scrollView.getCurrentScrollY());
        }
    });
}
 
Example 19
Source File: FillGap2ScrollViewActivity.java    From Android-ObservableScrollView with Apache License 2.0 4 votes vote down vote up
@Override
protected ObservableScrollView createScrollable() {
    ObservableScrollView scrollView = (ObservableScrollView) findViewById(R.id.scroll);
    scrollView.setScrollViewCallbacks(this);
    return scrollView;
}
 
Example 20
Source File: AboutActivity.java    From sharelock-android with MIT License 4 votes vote down vote up
protected ObservableScrollView createScrollable() {
    ObservableScrollView scrollView = (ObservableScrollView) findViewById(R.id.scroll);
    scrollView.setScrollViewCallbacks(this);
    return scrollView;
}