Java Code Examples for com.github.ksoichiro.android.observablescrollview.ScrollUtils#addOnGlobalLayoutListener()

The following examples show how to use com.github.ksoichiro.android.observablescrollview.ScrollUtils#addOnGlobalLayoutListener() . 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: ViewPagerTabListViewFragment.java    From Android-ObservableScrollView with Apache License 2.0 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_listview, container, false);

    Activity parentActivity = getActivity();
    final ObservableListView listView = (ObservableListView) view.findViewById(R.id.scroll);
    UiTestUtils.setDummyDataWithHeader(getActivity(), listView, inflater.inflate(R.layout.padding, null));

    if (parentActivity instanceof ObservableScrollViewCallbacks) {
        // Scroll to the specified position after layout
        Bundle args = getArguments();
        if (args != null && args.containsKey(ARG_INITIAL_POSITION)) {
            final int initialPosition = args.getInt(ARG_INITIAL_POSITION, 0);
            ScrollUtils.addOnGlobalLayoutListener(listView, new Runnable() {
                @Override
                public void run() {
                    // scrollTo() doesn't work, should use setSelection()
                    listView.setSelection(initialPosition);
                }
            });
        }
        listView.setScrollViewCallbacks((ObservableScrollViewCallbacks) parentActivity);
    }
    return view;
}
 
Example 2
Source File: ViewPagerTabScrollViewFragment.java    From Android-ObservableScrollView with Apache License 2.0 6 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);
                }
            });
        }
        scrollView.setScrollViewCallbacks((ObservableScrollViewCallbacks) parentActivity);
    }
    return view;
}
 
Example 3
Source File: ViewPagerTabGridViewFragment.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_gridview, container, false);

    Activity parentActivity = getActivity();
    final ObservableGridView gridView = (ObservableGridView) view.findViewById(R.id.scroll);
    setDummyDataWithHeader(gridView, inflater.inflate(R.layout.padding, gridView, false));

    if (parentActivity instanceof ObservableScrollViewCallbacks) {
        // Scroll to the specified position after layout
        Bundle args = getArguments();
        if (args != null && args.containsKey(ARG_INITIAL_POSITION)) {
            final int initialPosition = args.getInt(ARG_INITIAL_POSITION, 0);
            ScrollUtils.addOnGlobalLayoutListener(gridView, new Runnable() {
                @Override
                public void run() {
                    // scrollTo() doesn't work, should use setSelection()
                    gridView.setSelection(initialPosition);
                }
            });
        }

        // 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
        gridView.setTouchInterceptionViewGroup((ViewGroup) parentActivity.findViewById(R.id.root));

        gridView.setScrollViewCallbacks((ObservableScrollViewCallbacks) parentActivity);
    }
    return view;
}
 
Example 4
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 5
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 6
Source File: FlexibleSpaceWithImageRecyclerViewFragment.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_flexiblespacewithimagerecyclerview, container, false);

    final ObservableRecyclerView recyclerView = (ObservableRecyclerView) view.findViewById(R.id.scroll);
    recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
    recyclerView.setHasFixedSize(false);
    final View headerView = LayoutInflater.from(getActivity()).inflate(R.layout.recycler_header, null);
    final int flexibleSpaceImageHeight = getResources().getDimensionPixelSize(R.dimen.flexible_space_image_height);
    headerView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, flexibleSpaceImageHeight));
    setDummyDataWithHeader(recyclerView, headerView);

    // 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
    recyclerView.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(recyclerView, new Runnable() {
            @Override
            public void run() {
                int offset = scrollY % flexibleSpaceImageHeight;
                RecyclerView.LayoutManager lm = recyclerView.getLayoutManager();
                if (lm != null && lm instanceof LinearLayoutManager) {
                    ((LinearLayoutManager) lm).scrollToPositionWithOffset(0, -offset);
                }
            }
        });
        updateFlexibleSpace(scrollY, view);
    } else {
        updateFlexibleSpace(0, view);
    }

    recyclerView.setScrollViewCallbacks(this);

    return view;
}
 
Example 7
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 8
Source File: RecyclerViewScrollFromBottomActivity.java    From Android-ObservableScrollView with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    final ObservableRecyclerView scrollable = (ObservableRecyclerView) findViewById(R.id.scrollable);
    ScrollUtils.addOnGlobalLayoutListener(scrollable, new Runnable() {
        @Override
        public void run() {
            int count = scrollable.getAdapter().getItemCount() - 1;
            int position = count == 0 ? 1 : count > 0 ? count : 0;
            scrollable.scrollToPosition(position);
        }
    });
}
 
Example 9
Source File: ViewPagerTabRecyclerViewFragment.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_recyclerview, container, false);

    Activity parentActivity = getActivity();
    final ObservableRecyclerView recyclerView = (ObservableRecyclerView) view.findViewById(R.id.scroll);
    recyclerView.setLayoutManager(new LinearLayoutManager(parentActivity));
    recyclerView.setHasFixedSize(false);
    View headerView = LayoutInflater.from(parentActivity).inflate(R.layout.padding, null);
    setDummyDataWithHeader(recyclerView, headerView);

    if (parentActivity instanceof ObservableScrollViewCallbacks) {
        // Scroll to the specified offset after layout
        Bundle args = getArguments();
        if (args != null && args.containsKey(ARG_INITIAL_POSITION)) {
            final int initialPosition = args.getInt(ARG_INITIAL_POSITION, 0);
            ScrollUtils.addOnGlobalLayoutListener(recyclerView, new Runnable() {
                @Override
                public void run() {
                    recyclerView.scrollVerticallyToPosition(initialPosition);
                }
            });
        }

        // 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
        recyclerView.setTouchInterceptionViewGroup((ViewGroup) parentActivity.findViewById(R.id.root));

        recyclerView.setScrollViewCallbacks((ObservableScrollViewCallbacks) parentActivity);
    }
    return view;
}
 
Example 10
Source File: ViewPagerTabRecyclerViewFragment.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_recyclerview, container, false);

    Activity parentActivity = getActivity();
    final ObservableRecyclerView recyclerView = (ObservableRecyclerView) view.findViewById(R.id.scroll);
    recyclerView.setLayoutManager(new LinearLayoutManager(parentActivity));
    recyclerView.setHasFixedSize(false);
    View headerView = LayoutInflater.from(parentActivity).inflate(R.layout.padding, null);
    UiTestUtils.setDummyDataWithHeader(getActivity(), recyclerView, headerView);

    if (parentActivity instanceof ObservableScrollViewCallbacks) {
        // Scroll to the specified offset after layout
        Bundle args = getArguments();
        if (args != null && args.containsKey(ARG_INITIAL_POSITION)) {
            final int initialPosition = args.getInt(ARG_INITIAL_POSITION, 0);
            ScrollUtils.addOnGlobalLayoutListener(recyclerView, new Runnable() {
                @Override
                public void run() {
                    recyclerView.scrollVerticallyToPosition(initialPosition);
                }
            });
        }
        recyclerView.setScrollViewCallbacks((ObservableScrollViewCallbacks) parentActivity);
    }
    return view;
}
 
Example 11
Source File: ListViewScrollFromBottomActivity.java    From Android-ObservableScrollView with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    final ObservableListView scrollable = (ObservableListView) findViewById(R.id.scrollable);
    ScrollUtils.addOnGlobalLayoutListener(scrollable, new Runnable() {
        @Override
        public void run() {
            int count = scrollable.getAdapter().getCount() - 1;
            int position = count == 0 ? 1 : count > 0 ? count : 0;
            scrollable.smoothScrollToPosition(position);
            scrollable.setSelection(position);
        }
    });
}
 
Example 12
Source File: FillGapBaseActivity.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(getLayoutResId());

    mFlexibleSpaceImageHeight = getResources().getDimensionPixelSize(R.dimen.flexible_space_image_height);
    mActionBarSize = getActionBarSize();

    // Even when the top gap has began to change, header bar still can move
    // within mIntersectionHeight.
    mIntersectionHeight = getResources().getDimensionPixelSize(R.dimen.intersection_height);

    mImage = findViewById(R.id.image);
    mHeader = findViewById(R.id.header);
    mHeaderBar = findViewById(R.id.header_bar);
    mHeaderBackground = findViewById(R.id.header_background);
    mListBackgroundView = findViewById(R.id.list_background);

    final S scrollable = createScrollable();

    ((TextView) findViewById(R.id.title)).setText(getTitle());
    setTitle(null);

    ScrollUtils.addOnGlobalLayoutListener((View) scrollable, new Runnable() {
        @Override
        public void run() {
            mReady = true;
            updateViews(scrollable.getCurrentScrollY(), false);
        }
    });
}
 
Example 13
Source File: ScrollFromBottomListViewActivity.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_stickyheaderlistview);

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

    mListView = (ObservableListView) findViewById(R.id.list);
    mListView.setScrollViewCallbacks(this);

    LayoutInflater inflater = LayoutInflater.from(this);
    mListView.addHeaderView(inflater.inflate(R.layout.padding, mListView, false)); // toolbar
    mListView.addHeaderView(inflater.inflate(R.layout.padding, mListView, false)); // sticky view
    setDummyData(mListView);

    ScrollUtils.addOnGlobalLayoutListener(mListView, new Runnable() {
        @Override
        public void run() {
            int count = mListView.getAdapter().getCount() - 1;
            int position = count == 0 ? 1 : count > 0 ? count : 0;
            mListView.smoothScrollToPosition(position);
            mListView.setSelection(position);
        }
    });
}
 
Example 14
Source File: ScrollFromBottomRecyclerViewActivity.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_stickyheaderrecyclerview);

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

    mRecyclerView = (ObservableRecyclerView) findViewById(R.id.recycler);
    mRecyclerView.setScrollViewCallbacks(this);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
    mRecyclerView.setHasFixedSize(false);
    View headerView = LayoutInflater.from(this).inflate(R.layout.recycler_header, null);
    setDummyDataWithHeader(mRecyclerView, headerView);

    ScrollUtils.addOnGlobalLayoutListener(mRecyclerView, new Runnable() {
        @Override
        public void run() {
            int count = mRecyclerView.getAdapter().getItemCount() - 1;
            int position = count == 0 ? 1 : count > 0 ? count : 0;
            mRecyclerView.scrollToPosition(position);
        }
    });
}
 
Example 15
Source File: FillGap3BaseActivity.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(getLayoutResId());

    setSupportActionBar((Toolbar) findViewById(R.id.toolbar));

    mFlexibleSpaceImageHeight = getResources().getDimensionPixelSize(R.dimen.flexible_space_image_height);
    mActionBarSize = getActionBarSize();
    mHeaderBarHeight = getResources().getDimensionPixelSize(R.dimen.header_bar_height);

    // Even when the top gap has began to change, header bar still can move
    // within mIntersectionHeight.
    mIntersectionHeight = getResources().getDimensionPixelSize(R.dimen.intersection_height);

    mImageView = findViewById(R.id.image);
    mHeader = findViewById(R.id.header);
    mHeaderBar = findViewById(R.id.header_bar);
    mHeaderBackground = findViewById(R.id.header_background);

    mScrollable = createScrollable();

    mInterceptionLayout = (TouchInterceptionFrameLayout) findViewById(R.id.scroll_wrapper);
    mInterceptionLayout.setScrollInterceptionListener(mInterceptionListener);
    mTitle = (TextView) findViewById(R.id.title);
    mTitle.setText(getTitle());
    ViewHelper.setTranslationY(mTitle, (mHeaderBarHeight - mActionBarSize) / 2);
    setTitle(null);

    if (savedInstanceState == null) {
        mInitialTranslationY = mFlexibleSpaceImageHeight - mHeaderBarHeight;
    }

    ScrollUtils.addOnGlobalLayoutListener(mInterceptionLayout, new Runnable() {
        @Override
        public void run() {
            mReady = true;
            updateViews(mInitialTranslationY, false);
        }
    });
}
 
Example 16
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 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: FlexibleSpaceWithImageWithViewPagerTab2Activity.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_flexiblespacewithimagewithviewpagertab2);

    setSupportActionBar((Toolbar) findViewById(R.id.toolbar));

    ViewCompat.setElevation(findViewById(R.id.header), getResources().getDimension(R.dimen.toolbar_elevation));
    mPagerAdapter = new NavigationAdapter(getSupportFragmentManager());
    mPager = (ViewPager) findViewById(R.id.pager);
    mPager.setAdapter(mPagerAdapter);
    mImageView = findViewById(R.id.image);
    mOverlayView = findViewById(R.id.overlay);
    // Padding for ViewPager must be set outside the ViewPager itself
    // because with padding, EdgeEffect of ViewPager become strange.
    mFlexibleSpaceHeight = getResources().getDimensionPixelSize(R.dimen.flexible_space_image_height);
    mTabHeight = getResources().getDimensionPixelSize(R.dimen.tab_height);
    findViewById(R.id.pager_wrapper).setPadding(0, mFlexibleSpaceHeight, 0, 0);
    mTitleView = (TextView) findViewById(R.id.title);
    mTitleView.setText(getTitle());
    setTitle(null);

    SlidingTabLayout slidingTabLayout = (SlidingTabLayout) findViewById(R.id.sliding_tabs);
    slidingTabLayout.setCustomTabView(R.layout.tab_indicator, android.R.id.text1);
    slidingTabLayout.setSelectedIndicatorColors(getResources().getColor(R.color.accent));
    slidingTabLayout.setDistributeEvenly(true);
    slidingTabLayout.setViewPager(mPager);
    ((FrameLayout.LayoutParams) slidingTabLayout.getLayoutParams()).topMargin = mFlexibleSpaceHeight - mTabHeight;

    ViewConfiguration vc = ViewConfiguration.get(this);
    mSlop = vc.getScaledTouchSlop();
    mMaximumVelocity = vc.getScaledMaximumFlingVelocity();
    mInterceptionLayout = (TouchInterceptionFrameLayout) findViewById(R.id.container);
    mInterceptionLayout.setScrollInterceptionListener(mInterceptionListener);
    mScroller = new OverScroller(getApplicationContext());
    ScrollUtils.addOnGlobalLayoutListener(mInterceptionLayout, new Runnable() {
        @Override
        public void run() {
            // Extra space is required to move mInterceptionLayout when it's scrolled.
            // It's better to adjust its height when it's laid out
            // than to adjust the height when scroll events (onMoveMotionEvent) occur
            // because it causes lagging.
            // See #87: https://github.com/ksoichiro/Android-ObservableScrollView/issues/87
            FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mInterceptionLayout.getLayoutParams();
            lp.height = getScreenHeight() + mFlexibleSpaceHeight;
            mInterceptionLayout.requestLayout();

            updateFlexibleSpace();
        }
    });
}
 
Example 19
Source File: BaseHomeFragment.java    From ExpressHelper with GNU General Public License v3.0 4 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
	View rootView = inflater.inflate(R.layout.fragment_home, container, false);

	if (mSets == null) {
		mSets = Settings.getInstance(getActivity().getApplicationContext());
	}

	refreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.swipeRefreshLayout);

	mRecyclerView = (ObservableRecyclerView) rootView.findViewById(R.id.scroll);
	mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
	mRecyclerView.setHasFixedSize(true);
	headerView = inflater.inflate(R.layout.padding, null);

	Activity parentActivity = getActivity();
	context = parentActivity.getApplicationContext();
	if (parentActivity instanceof ObservableScrollViewCallbacks) {
		// Scroll to the specified position after layout
		Bundle args = getArguments();
		if (args != null && args.containsKey(ARG_INITIAL_POSITION)) {
			final int initialPosition = args.getInt(ARG_INITIAL_POSITION, 0);
			ScrollUtils.addOnGlobalLayoutListener(mRecyclerView, new Runnable() {
				@Override
				public void run() {
					mRecyclerView.scrollVerticallyToPosition(initialPosition);
				}
			});
		}
		mRecyclerView.setScrollViewCallbacks((ObservableScrollViewCallbacks) parentActivity);
	}

	refreshLayout.setProgressViewEndTarget(
			true,
			getResources().getDimensionPixelOffset(R.dimen.abc_action_bar_default_height_material) +
					getResources().getDimensionPixelOffset(R.dimen.tab_height)
	);
	refreshLayout.setColorSchemeResources(R.color.blue_500);
	refreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
		@Override
		public void onRefresh() {
			mHandler.sendEmptyMessage(FLAG_REFRESH_LIST);
		}
	});

	mDB = ((MainActivity) getActivity()).mExpressDB;
	setUpAdapter();

	return rootView;
}
 
Example 20
Source File: AboutActivity.java    From sharelock-android with MIT License 4 votes vote down vote up
@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)));
}