Search in sources :

Example 6 with FragmentStatePagerAdapter

use of android.support.v4.app.FragmentStatePagerAdapter in project MaterialViewPager by florent37.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    setTitle("");
    ButterKnife.bind(this);
    final Toolbar toolbar = mViewPager.getToolbar();
    if (toolbar != null) {
        setSupportActionBar(toolbar);
    }
    mViewPager.getViewPager().setAdapter(new FragmentStatePagerAdapter(getSupportFragmentManager()) {

        @Override
        public Fragment getItem(int position) {
            switch(position % 4) {
                //    return WebViewFragment.newInstance();
                default:
                    return RecyclerViewFragment.newInstance();
            }
        }

        @Override
        public int getCount() {
            return 4;
        }

        @Override
        public CharSequence getPageTitle(int position) {
            switch(position % 4) {
                case 0:
                    return "Selection";
                case 1:
                    return "Actualités";
                case 2:
                    return "Professionnel";
                case 3:
                    return "Divertissement";
            }
            return "";
        }
    });
    mViewPager.setMaterialViewPagerListener(new MaterialViewPager.Listener() {

        @Override
        public HeaderDesign getHeaderDesign(int page) {
            switch(page) {
                case 0:
                    return HeaderDesign.fromColorResAndUrl(R.color.green, "http://phandroid.s3.amazonaws.com/wp-content/uploads/2014/06/android_google_moutain_google_now_1920x1080_wallpaper_Wallpaper-HD_2560x1600_www.paperhi.com_-640x400.jpg");
                case 1:
                    return HeaderDesign.fromColorResAndUrl(R.color.blue, "http://www.hdiphonewallpapers.us/phone-wallpapers/540x960-1/540x960-mobile-wallpapers-hd-2218x5ox3.jpg");
                case 2:
                    return HeaderDesign.fromColorResAndUrl(R.color.cyan, "http://www.droid-life.com/wp-content/uploads/2014/10/lollipop-wallpapers10.jpg");
                case 3:
                    return HeaderDesign.fromColorResAndUrl(R.color.red, "http://www.tothemobile.com/wp-content/uploads/2014/07/original.jpg");
            }
            return null;
        }
    });
    mViewPager.getViewPager().setOffscreenPageLimit(mViewPager.getViewPager().getAdapter().getCount());
    mViewPager.getPagerTitleStrip().setViewPager(mViewPager.getViewPager());
    final View logo = findViewById(R.id.logo_white);
    if (logo != null) {
        logo.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                mViewPager.notifyHeaderChanged();
                Toast.makeText(getApplicationContext(), "Yes, the title is clickable", Toast.LENGTH_SHORT).show();
            }
        });
    }
}
Also used : FragmentStatePagerAdapter(android.support.v4.app.FragmentStatePagerAdapter) MaterialViewPager(com.github.florent37.materialviewpager.MaterialViewPager) HeaderDesign(com.github.florent37.materialviewpager.header.HeaderDesign) Fragment(android.support.v4.app.Fragment) RecyclerViewFragment(com.github.florent37.materialviewpager.sample.fragment.RecyclerViewFragment) BindView(butterknife.BindView) View(android.view.View) Toolbar(android.support.v7.widget.Toolbar)

Example 7 with FragmentStatePagerAdapter

use of android.support.v4.app.FragmentStatePagerAdapter in project easy by MehdiBenmesa.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    setTitle("");
    ButterKnife.bind(this);
    final Toolbar toolbar = mViewPager.getToolbar();
    if (toolbar != null) {
        setSupportActionBar(toolbar);
    }
    mViewPager.getViewPager().setAdapter(new FragmentStatePagerAdapter(getSupportFragmentManager()) {

        @Override
        public Fragment getItem(int position) {
            switch(position % 4) {
                //    return WebViewFragment.newInstance();
                default:
                    return RecyclerViewFragment.newInstance();
            }
        }

        @Override
        public int getCount() {
            return 4;
        }

        @Override
        public CharSequence getPageTitle(int position) {
            switch(position % 4) {
                case 0:
                    return "Selection";
                case 1:
                    return "Actualités";
                case 2:
                    return "Professionnel";
                case 3:
                    return "Divertissement";
            }
            return "";
        }
    });
    mViewPager.setMaterialViewPagerListener(new MaterialViewPager.Listener() {

        @Override
        public HeaderDesign getHeaderDesign(int page) {
            switch(page) {
                case 0:
                    return HeaderDesign.fromColorResAndUrl(R.color.green, "http://phandroid.s3.amazonaws.com/wp-content/uploads/2014/06/android_google_moutain_google_now_1920x1080_wallpaper_Wallpaper-HD_2560x1600_www.paperhi.com_-640x400.jpg");
                case 1:
                    return HeaderDesign.fromColorResAndUrl(R.color.blue, "http://www.hdiphonewallpapers.us/phone-wallpapers/540x960-1/540x960-mobile-wallpapers-hd-2218x5ox3.jpg");
                case 2:
                    return HeaderDesign.fromColorResAndUrl(R.color.cyan, "http://www.droid-life.com/wp-content/uploads/2014/10/lollipop-wallpapers10.jpg");
                case 3:
                    return HeaderDesign.fromColorResAndUrl(R.color.red, "http://www.tothemobile.com/wp-content/uploads/2014/07/original.jpg");
            }
            return null;
        }
    });
    mViewPager.getViewPager().setOffscreenPageLimit(mViewPager.getViewPager().getAdapter().getCount());
    mViewPager.getPagerTitleStrip().setViewPager(mViewPager.getViewPager());
    final View logo = findViewById(R.id.logo_white);
    if (logo != null) {
        logo.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                mViewPager.notifyHeaderChanged();
                Toast.makeText(getApplicationContext(), "Yes, the title is clickable", Toast.LENGTH_SHORT).show();
            }
        });
    }
}
Also used : FragmentStatePagerAdapter(android.support.v4.app.FragmentStatePagerAdapter) MaterialViewPager(com.github.florent37.materialviewpager.MaterialViewPager) HeaderDesign(com.github.florent37.materialviewpager.header.HeaderDesign) Fragment(android.support.v4.app.Fragment) RecyclerViewFragment(com.github.florent37.materialviewpager.sample.fragment.RecyclerViewFragment) BindView(butterknife.BindView) View(android.view.View) Toolbar(android.support.v7.widget.Toolbar)

Example 8 with FragmentStatePagerAdapter

use of android.support.v4.app.FragmentStatePagerAdapter in project UltimateAndroid by cymcsg.

the class QuickReturnListViewActivity method onCreate.

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.quick_return_listview_activity_main);
    PagerAdapter adapter = new FragmentStatePagerAdapter(getSupportFragmentManager()) {

        @Override
        public Fragment getItem(int position) {
            switch(position) {
                case 0:
                    return new DefaultFragment();
                case 1:
                    return new AnimationFragment();
                case 2:
                    return new BottomFragment();
            }
            return null;
        }

        @Override
        public int getCount() {
            return 3;
        }

        @Override
        public CharSequence getPageTitle(int position) {
            switch(position) {
                case 0:
                    return "default_fragment";
                case 1:
                    return "animation_fragment";
                case 2:
                    return "footer_fragment";
            }
            return null;
        }
    };
    mPager = (ViewPager) findViewById(R.id.pager);
    mPager.setAdapter(adapter);
    mPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {

        @Override
        public void onPageSelected(int position) {
            getActionBar().setSelectedNavigationItem(position);
        }
    });
    mPager.setPageMargin(20);
    getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    for (int position = 0; position < adapter.getCount(); position++) {
        getActionBar().addTab(getActionBar().newTab().setText(adapter.getPageTitle(position)).setTabListener(this));
    }
    getActionBar().setDisplayShowHomeEnabled(false);
    getActionBar().setDisplayShowTitleEnabled(false);
}
Also used : FragmentStatePagerAdapter(android.support.v4.app.FragmentStatePagerAdapter) ViewPager(android.support.v4.view.ViewPager) FragmentStatePagerAdapter(android.support.v4.app.FragmentStatePagerAdapter) PagerAdapter(android.support.v4.view.PagerAdapter)

Example 9 with FragmentStatePagerAdapter

use of android.support.v4.app.FragmentStatePagerAdapter in project BGARefreshLayout-Android by bingoogolapple.

the class BGAStickyNavLayout method regetNestedContentView.

/**
     * 重新获取嵌套的内容视图
     */
private void regetNestedContentView() {
    int currentItem = mDirectViewPager.getCurrentItem();
    PagerAdapter adapter = mDirectViewPager.getAdapter();
    if (adapter instanceof FragmentPagerAdapter || adapter instanceof FragmentStatePagerAdapter) {
        Fragment item = (Fragment) adapter.instantiateItem(mDirectViewPager, currentItem);
        mNestedContentView = item.getView();
        // 清空之前的
        mNestedNormalView = null;
        mNestedAbsListView = null;
        mNestedRecyclerView = null;
        mNestedScrollView = null;
        mNestedWebView = null;
        if (mNestedContentView instanceof AbsListView) {
            mNestedAbsListView = (AbsListView) mNestedContentView;
            mNestedAbsListView.setOnScrollListener(mLvOnScrollListener);
            if (!isHeaderViewCompleteInvisible()) {
                mNestedAbsListView.setSelection(0);
            }
        } else if (mNestedContentView instanceof RecyclerView) {
            mNestedRecyclerView = (RecyclerView) mNestedContentView;
            mNestedRecyclerView.removeOnScrollListener(mRvOnScrollListener);
            mNestedRecyclerView.addOnScrollListener(mRvOnScrollListener);
            if (!isHeaderViewCompleteInvisible()) {
                mNestedRecyclerView.scrollToPosition(0);
            }
        } else if (mNestedContentView instanceof ScrollView) {
            mNestedScrollView = (ScrollView) mNestedContentView;
            if (!isHeaderViewCompleteInvisible()) {
                mNestedScrollView.scrollTo(mNestedScrollView.getScrollX(), 0);
            }
        } else if (mNestedContentView instanceof WebView) {
            mNestedWebView = (WebView) mNestedContentView;
            if (!isHeaderViewCompleteInvisible()) {
                mNestedWebView.scrollTo(mNestedWebView.getScrollX(), 0);
            }
        } else {
            mNestedNormalView = mNestedContentView;
        }
    } else {
        throw new IllegalStateException(BGAStickyNavLayout.class.getSimpleName() + "的第三个子控件为ViewPager时,其adapter必须是FragmentPagerAdapter或者FragmentStatePagerAdapter");
    }
}
Also used : FragmentStatePagerAdapter(android.support.v4.app.FragmentStatePagerAdapter) ScrollView(android.widget.ScrollView) FragmentPagerAdapter(android.support.v4.app.FragmentPagerAdapter) AbsListView(android.widget.AbsListView) RecyclerView(android.support.v7.widget.RecyclerView) WebView(android.webkit.WebView) Fragment(android.support.v4.app.Fragment) PagerAdapter(android.support.v4.view.PagerAdapter) FragmentPagerAdapter(android.support.v4.app.FragmentPagerAdapter) FragmentStatePagerAdapter(android.support.v4.app.FragmentStatePagerAdapter)

Example 10 with FragmentStatePagerAdapter

use of android.support.v4.app.FragmentStatePagerAdapter in project making-apps-beautiful by ankurkotwal.

the class ArticleDetailActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_article_detail);
    ViewPager pager = (ViewPager) findViewById(R.id.pager);
    pager.setAdapter(new FragmentStatePagerAdapter(getSupportFragmentManager()) {

        @Override
        public Fragment getItem(int i) {
            Bundle arguments = new Bundle();
            arguments.putString(ArticleDetailFragment.ARG_ITEM_ID, DummyContent.ITEMS.get(i).id);
            ArticleDetailFragment fragment = new ArticleDetailFragment();
            fragment.setArguments(arguments);
            return fragment;
        }

        @Override
        public int getCount() {
            return DummyContent.ITEMS.size();
        }
    });
    pager.setPageMarginDrawable(getResources().getDrawable(R.drawable.list_divider_holo_light));
    pager.setPageMargin((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, getResources().getDisplayMetrics()));
    String startId = getIntent().getStringExtra(ArticleDetailFragment.ARG_ITEM_ID);
    for (int i = 0; i < DummyContent.ITEMS.size(); i++) {
        if (DummyContent.ITEMS.get(i).id.equals(startId)) {
            pager.setCurrentItem(i);
            return;
        }
    }
}
Also used : FragmentStatePagerAdapter(android.support.v4.app.FragmentStatePagerAdapter) Bundle(android.os.Bundle) ViewPager(android.support.v4.view.ViewPager) Fragment(android.support.v4.app.Fragment)

Aggregations

FragmentStatePagerAdapter (android.support.v4.app.FragmentStatePagerAdapter)21 Fragment (android.support.v4.app.Fragment)20 ViewPager (android.support.v4.view.ViewPager)13 Bundle (android.os.Bundle)11 View (android.view.View)6 Toolbar (android.support.v7.widget.Toolbar)3 BindView (butterknife.BindView)3 MaterialViewPager (com.github.florent37.materialviewpager.MaterialViewPager)3 HeaderDesign (com.github.florent37.materialviewpager.header.HeaderDesign)3 PagerAdapter (android.support.v4.view.PagerAdapter)2 TextView (android.widget.TextView)2 RecyclerViewFragment (com.github.florent37.materialviewpager.sample.fragment.RecyclerViewFragment)2 Intent (android.content.Intent)1 StateListDrawable (android.graphics.drawable.StateListDrawable)1 FragmentManager (android.support.v4.app.FragmentManager)1 FragmentPagerAdapter (android.support.v4.app.FragmentPagerAdapter)1 RecyclerView (android.support.v7.widget.RecyclerView)1 AccelerateDecelerateInterpolator (android.view.animation.AccelerateDecelerateInterpolator)1 WebView (android.webkit.WebView)1 AbsListView (android.widget.AbsListView)1