Search in sources :

Example 16 with ObservableScrollView

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();
        }
    }
}
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 17 with ObservableScrollView

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);
            }
        }
    }
}
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 18 with ObservableScrollView

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

Example 19 with ObservableScrollView

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)));
}
Also used : ImageButton(android.widget.ImageButton) ObservableScrollView(com.github.ksoichiro.android.observablescrollview.ObservableScrollView) TextView(android.widget.TextView) TextView(android.widget.TextView) ObservableScrollView(com.github.ksoichiro.android.observablescrollview.ObservableScrollView) View(android.view.View) Toolbar(android.support.v7.widget.Toolbar)

Example 20 with ObservableScrollView

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