Search in sources :

Example 21 with FragmentStatePagerAdapter

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

the class UserActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    setTitle("");
    ButterKnife.bind(this);
    Intent i = new Intent(this, RegistrationIntentService.class);
    i.putExtra("DEVICE_ID", "saloh");
    i.putExtra("DEVICE_NAME", "bokota");
    startService(i);
    registerReceiver();
    final Toolbar toolbar = mViewPager.getToolbar();
    if (toolbar != null) {
        setSupportActionBar(toolbar);
    }
    Intent intent = getIntent();
    String jsonString = intent.getStringExtra("user");
    try {
        user = new JSONObject(jsonString);
        SessionManager sessionManager = new SessionManager(this);
        sessionManager.createLoginSession(user.getString("name"), user.getString("mail"), user.getString("_id"));
        sessionManager.setUser(jsonString);
        String text = user.getString("lastname") + " " + user.getString("name");
        ((TextView) findViewById(R.id.logo_white)).setText(text);
    } catch (JSONException e) {
        e.printStackTrace();
    }
    mViewPager.getViewPager().setAdapter(new FragmentStatePagerAdapter(getSupportFragmentManager()) {

        @Override
        public Fragment getItem(int position) {
            switch(position % 3) {
                case 0:
                    return ModuleFragment.newInstance(user);
                case 1:
                    return RendezVousStatesFragment.newInstance(user);
                case 2:
                    return TimeTableFragment.newInstance(user);
                default:
                    return ModuleFragment.newInstance(user);
            }
        }

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

        @Override
        public CharSequence getPageTitle(int position) {
            switch(position % 3) {
                case 0:
                    return getResources().getString(R.string.NoteManager);
                case 1:
                    return getResources().getString(R.string.RdvManager);
                case 2:
                    return getResources().getString(R.string.TimetableManager);
                case 3:
                    return "Gestion .. ";
            }
            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) SessionManager(dz.easy.androidclient.Util.SessionManager) HeaderDesign(com.github.florent37.materialviewpager.header.HeaderDesign) JSONException(org.json.JSONException) Intent(android.content.Intent) RendezVousStatesFragment(dz.easy.androidclient.fragment.RendezVousStatesFragment) ModuleFragment(dz.easy.androidclient.fragment.ModuleFragment) Fragment(android.support.v4.app.Fragment) TimeTableFragment(dz.easy.androidclient.fragment.TimeTableFragment) BindView(butterknife.BindView) TextView(android.widget.TextView) View(android.view.View) JSONObject(org.json.JSONObject) TextView(android.widget.TextView) Toolbar(android.support.v7.widget.Toolbar)

Example 22 with FragmentStatePagerAdapter

use of android.support.v4.app.FragmentStatePagerAdapter in project android-page-transition by xmuSistone.

the class MainActivity method fillViewPager.

/**
     * 填充ViewPager
     */
private void fillViewPager() {
    indicatorTv = (TextView) findViewById(R.id.indicator_tv);
    viewPager = (ViewPager) findViewById(R.id.viewpager);
    // 1. viewPager添加parallax效果,使用PageTransformer就足够了
    viewPager.setPageTransformer(false, new CustPagerTransformer(this));
    // 2. viewPager添加adapter
    for (int i = 0; i < 10; i++) {
        // 预先准备10个fragment
        fragments.add(new CommonFragment());
    }
    viewPager.setAdapter(new FragmentStatePagerAdapter(getSupportFragmentManager()) {

        @Override
        public Fragment getItem(int position) {
            CommonFragment fragment = fragments.get(position % 10);
            fragment.bindData(imageArray[position % imageArray.length]);
            return fragment;
        }

        @Override
        public int getCount() {
            return 666;
        }
    });
    // 3. viewPager滑动时,调整指示器
    viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
        }

        @Override
        public void onPageSelected(int position) {
            updateIndicatorTv();
        }

        @Override
        public void onPageScrollStateChanged(int state) {
        }
    });
    updateIndicatorTv();
}
Also used : FragmentStatePagerAdapter(android.support.v4.app.FragmentStatePagerAdapter) Fragment(android.support.v4.app.Fragment) ViewPager(android.support.v4.view.ViewPager)

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