Search in sources :

Example 1 with ObservableScrollView

use of com.github.ksoichiro.android.observablescrollview.ObservableScrollView in project UltimateAndroid by cymcsg.

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 (scrollState == ScrollState.UP) {
        if (toolbarHeight < scrollView.getCurrentScrollY()) {
            hideToolbar();
        } else if (scrollView.getCurrentScrollY() < toolbarHeight) {
            showToolbar();
        }
    } else if (scrollState == ScrollState.DOWN) {
        if (toolbarHeight < scrollView.getCurrentScrollY()) {
            showToolbar();
        }
    }
}
Also used : ObservableScrollView(com.github.ksoichiro.android.observablescrollview.ObservableScrollView) Fragment(android.support.v4.app.Fragment) ObservableScrollView(com.github.ksoichiro.android.observablescrollview.ObservableScrollView) View(android.view.View)

Example 2 with ObservableScrollView

use of com.github.ksoichiro.android.observablescrollview.ObservableScrollView in project UltimateAndroid by cymcsg.

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;
        }
        ObservableScrollView scrollView = (ObservableScrollView) f.getView().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);
            }
        }
    }
}
Also used : ObservableScrollView(com.github.ksoichiro.android.observablescrollview.ObservableScrollView) Fragment(android.support.v4.app.Fragment)

Example 3 with ObservableScrollView

use of com.github.ksoichiro.android.observablescrollview.ObservableScrollView in project UltimateAndroid by cymcsg.

the class ViewPagerTabScrollViewFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.observable_scroll_view_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);
            ViewTreeObserver vto = scrollView.getViewTreeObserver();
            vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

                @Override
                public void onGlobalLayout() {
                    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
                        scrollView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                    } else {
                        scrollView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                    }
                    scrollView.scrollTo(0, scrollY);
                }
            });
        }
        scrollView.setScrollViewCallbacks((ObservableScrollViewCallbacks) parentActivity);
    }
    return view;
}
Also used : ObservableScrollView(com.github.ksoichiro.android.observablescrollview.ObservableScrollView) Bundle(android.os.Bundle) Activity(android.app.Activity) ObservableScrollViewCallbacks(com.github.ksoichiro.android.observablescrollview.ObservableScrollViewCallbacks) ObservableScrollView(com.github.ksoichiro.android.observablescrollview.ObservableScrollView) View(android.view.View) ViewTreeObserver(android.view.ViewTreeObserver)

Example 4 with ObservableScrollView

use of com.github.ksoichiro.android.observablescrollview.ObservableScrollView in project UltimateAndroid by cymcsg.

the class ActionBarControlScrollViewActivity method onCreate.

@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);
}
Also used : ObservableScrollView(com.github.ksoichiro.android.observablescrollview.ObservableScrollView)

Example 5 with ObservableScrollView

use of com.github.ksoichiro.android.observablescrollview.ObservableScrollView in project UltimateAndroid by cymcsg.

the class ParallaxToolbarScrollViewActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.observable_scroll_view_activity_parallaxtoolbarscrollview);
    setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
    mImageView = findViewById(R.id.image);
    mToolbarView = findViewById(R.id.toolbar);
    setBackgroundAlpha(mToolbarView, 0, getResources().getColor(R.color.primary));
    ObservableScrollView scrollView = (ObservableScrollView) findViewById(R.id.scroll);
    scrollView.setScrollViewCallbacks(this);
    mParallaxImageHeight = getResources().getDimensionPixelSize(R.dimen.parallax_image_height);
}
Also used : ObservableScrollView(com.github.ksoichiro.android.observablescrollview.ObservableScrollView)

Aggregations

ObservableScrollView (com.github.ksoichiro.android.observablescrollview.ObservableScrollView)28 View (android.view.View)14 ObservableScrollViewCallbacks (com.github.ksoichiro.android.observablescrollview.ObservableScrollViewCallbacks)7 Activity (android.app.Activity)6 Bundle (android.os.Bundle)5 Fragment (android.support.v4.app.Fragment)5 ActionBar (android.support.v7.app.ActionBar)2 ViewTreeObserver (android.view.ViewTreeObserver)2 FrameLayout (android.widget.FrameLayout)2 TextView (android.widget.TextView)2 Toolbar (android.support.v7.widget.Toolbar)1 Editable (android.text.Editable)1 TextWatcher (android.text.TextWatcher)1 ViewGroup (android.view.ViewGroup)1 WebView (android.webkit.WebView)1 ImageButton (android.widget.ImageButton)1 SaveListener (cn.bmob.v3.listener.SaveListener)1 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)1 Feedback (com.nightonke.saver.model.Feedback)1