Search in sources :

Example 6 with SlidingTabLayout

use of com.google.samples.apps.iosched.ui.widget.SlidingTabLayout in project Android-ObservableScrollView by ksoichiro.

the class FlexibleSpaceWithImageWithViewPagerTab2Activity method onCreate.

@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();
        }
    });
}
Also used : ViewConfiguration(android.view.ViewConfiguration) FrameLayout(android.widget.FrameLayout) TouchInterceptionFrameLayout(com.github.ksoichiro.android.observablescrollview.TouchInterceptionFrameLayout) SlidingTabLayout(com.google.samples.apps.iosched.ui.widget.SlidingTabLayout) OverScroller(android.widget.OverScroller)

Example 7 with SlidingTabLayout

use of com.google.samples.apps.iosched.ui.widget.SlidingTabLayout in project Android-ObservableScrollView by ksoichiro.

the class ViewPagerTabActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_viewpagertab);
    setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
    mHeaderView = findViewById(R.id.header);
    mToolbarView = findViewById(R.id.toolbar);
    mPagerAdapter = new NavigationAdapter(getSupportFragmentManager());
    mPager = (ViewPager) findViewById(R.id.pager);
    mPager.setAdapter(mPagerAdapter);
    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);
    // When the page is selected, other fragments' scrollY should be adjusted
    // according to the toolbar status(shown/hidden)
    slidingTabLayout.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageScrolled(int i, float v, int i2) {
        }

        @Override
        public void onPageSelected(int i) {
            propagateToolbarState(toolbarIsShown());
        }

        @Override
        public void onPageScrollStateChanged(int i) {
        }
    });
    propagateToolbarState(toolbarIsShown());
}
Also used : SlidingTabLayout(com.google.samples.apps.iosched.ui.widget.SlidingTabLayout) ViewPager(android.support.v4.view.ViewPager)

Example 8 with SlidingTabLayout

use of com.google.samples.apps.iosched.ui.widget.SlidingTabLayout in project Android-ObservableScrollView by ksoichiro.

the class ViewPagerTab2Activity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_viewpagertab2);
    setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
    mToolbarView = findViewById(R.id.toolbar);
    mPagerAdapter = new NavigationAdapter(getSupportFragmentManager());
    mPager = (ViewPager) findViewById(R.id.pager);
    mPager.setAdapter(mPagerAdapter);
    // Padding for ViewPager must be set outside the ViewPager itself
    // because with padding, EdgeEffect of ViewPager become strange.
    final int tabHeight = getResources().getDimensionPixelSize(R.dimen.tab_height);
    findViewById(R.id.pager_wrapper).setPadding(0, getActionBarSize() + tabHeight, 0, 0);
    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);
    ViewConfiguration vc = ViewConfiguration.get(this);
    mSlop = vc.getScaledTouchSlop();
    mInterceptionLayout = (TouchInterceptionFrameLayout) findViewById(R.id.container);
    mInterceptionLayout.setScrollInterceptionListener(mInterceptionListener);
}
Also used : ViewConfiguration(android.view.ViewConfiguration) SlidingTabLayout(com.google.samples.apps.iosched.ui.widget.SlidingTabLayout)

Aggregations

SlidingTabLayout (com.google.samples.apps.iosched.ui.widget.SlidingTabLayout)8 ViewPager (android.support.v4.view.ViewPager)4 ViewConfiguration (android.view.ViewConfiguration)4 AppCompatActivity (android.support.v7.app.AppCompatActivity)1 View (android.view.View)1 FrameLayout (android.widget.FrameLayout)1 OverScroller (android.widget.OverScroller)1 TouchInterceptionFrameLayout (com.github.ksoichiro.android.observablescrollview.TouchInterceptionFrameLayout)1