Search in sources :

Example 86 with Fragment

use of android.support.v4.app.Fragment in project FirebaseUI-Android by firebase.

the class SaveSmartLock method getInstance.

@Nullable
public static SaveSmartLock getInstance(FragmentActivity activity, FlowParameters parameters) {
    SaveSmartLock result;
    FragmentManager fm = activity.getSupportFragmentManager();
    Fragment fragment = fm.findFragmentByTag(TAG);
    if (!(fragment instanceof SaveSmartLock)) {
        result = new SaveSmartLock();
        result.setArguments(FragmentHelper.getFlowParamsBundle(parameters));
        try {
            fm.beginTransaction().add(result, TAG).disallowAddToBackStack().commit();
        } catch (IllegalStateException e) {
            Log.e(TAG, "Cannot add fragment", e);
            return null;
        }
    } else {
        result = (SaveSmartLock) fragment;
    }
    return result;
}
Also used : FragmentManager(android.support.v4.app.FragmentManager) Fragment(android.support.v4.app.Fragment) Nullable(android.support.annotation.Nullable)

Example 87 with Fragment

use of android.support.v4.app.Fragment in project quickstart-android by firebase.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    // Create the adapter that will return a fragment for each section
    mPagerAdapter = new FragmentPagerAdapter(getSupportFragmentManager()) {

        private final Fragment[] mFragments = new Fragment[] { new RecentPostsFragment(), new MyPostsFragment(), new MyTopPostsFragment() };

        private final String[] mFragmentNames = new String[] { getString(R.string.heading_recent), getString(R.string.heading_my_posts), getString(R.string.heading_my_top_posts) };

        @Override
        public Fragment getItem(int position) {
            return mFragments[position];
        }

        @Override
        public int getCount() {
            return mFragments.length;
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return mFragmentNames[position];
        }
    };
    // Set up the ViewPager with the sections adapter.
    mViewPager = (ViewPager) findViewById(R.id.container);
    mViewPager.setAdapter(mPagerAdapter);
    TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
    tabLayout.setupWithViewPager(mViewPager);
    // Button launches NewPostActivity
    findViewById(R.id.fab_new_post).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            startActivity(new Intent(MainActivity.this, NewPostActivity.class));
        }
    });
}
Also used : FragmentPagerAdapter(android.support.v4.app.FragmentPagerAdapter) Intent(android.content.Intent) RecentPostsFragment(com.google.firebase.quickstart.database.fragment.RecentPostsFragment) Fragment(android.support.v4.app.Fragment) MyPostsFragment(com.google.firebase.quickstart.database.fragment.MyPostsFragment) MyTopPostsFragment(com.google.firebase.quickstart.database.fragment.MyTopPostsFragment) View(android.view.View) MyTopPostsFragment(com.google.firebase.quickstart.database.fragment.MyTopPostsFragment) RecentPostsFragment(com.google.firebase.quickstart.database.fragment.RecentPostsFragment) TabLayout(android.support.design.widget.TabLayout) MyPostsFragment(com.google.firebase.quickstart.database.fragment.MyPostsFragment)

Example 88 with Fragment

use of android.support.v4.app.Fragment 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 89 with Fragment

use of android.support.v4.app.Fragment in project Hummingbird-for-Android by xiprox.

the class ProfileTabsPagerAdapter method getItem.

@Override
public Fragment getItem(int position) {
    Bundle args = new Bundle();
    Fragment fragment = null;
    switch(position) {
        case 0:
            fragment = new UserInfoFragment();
            break;
        case 1:
            fragment = new FeedFragment();
            break;
        case 2:
            fragment = new FavoriteAnimeFragment();
    }
    args.putString(ProfileFragment.ARG_USERNAME, username);
    if (fragment != null)
        fragment.setArguments(args);
    return fragment;
}
Also used : Bundle(android.os.Bundle) FavoriteAnimeFragment(tr.bcxip.hummingbird.FavoriteAnimeFragment) UserInfoFragment(tr.bcxip.hummingbird.UserInfoFragment) UserInfoFragment(tr.bcxip.hummingbird.UserInfoFragment) Fragment(android.support.v4.app.Fragment) FavoriteAnimeFragment(tr.bcxip.hummingbird.FavoriteAnimeFragment) FeedFragment(tr.bcxip.hummingbird.FeedFragment) ProfileFragment(tr.bcxip.hummingbird.ProfileFragment) FeedFragment(tr.bcxip.hummingbird.FeedFragment)

Example 90 with Fragment

use of android.support.v4.app.Fragment in project CloudReader by youlookwhat.

the class MainActivity method initContentFragment.

private void initContentFragment() {
    ArrayList<Fragment> mFragmentList = new ArrayList<>();
    mFragmentList.add(new GankFragment());
    mFragmentList.add(new OneFragment());
    mFragmentList.add(new BookFragment());
    // 注意使用的是:getSupportFragmentManager
    MyFragmentPagerAdapter adapter = new MyFragmentPagerAdapter(getSupportFragmentManager(), mFragmentList);
    vpContent.setAdapter(adapter);
    // 设置ViewPager最大缓存的页面个数(cpu消耗少)
    vpContent.setOffscreenPageLimit(2);
    vpContent.addOnPageChangeListener(this);
    mBinding.include.ivTitleGank.setSelected(true);
    vpContent.setCurrentItem(0);
    setSupportActionBar(toolbar);
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        //去除默认Title显示
        actionBar.setDisplayShowTitleEnabled(false);
    }
}
Also used : GankFragment(com.example.jingbin.cloudreader.ui.gank.GankFragment) MyFragmentPagerAdapter(com.example.jingbin.cloudreader.view.MyFragmentPagerAdapter) ArrayList(java.util.ArrayList) OneFragment(com.example.jingbin.cloudreader.ui.one.OneFragment) BookFragment(com.example.jingbin.cloudreader.ui.book.BookFragment) GankFragment(com.example.jingbin.cloudreader.ui.gank.GankFragment) BookFragment(com.example.jingbin.cloudreader.ui.book.BookFragment) Fragment(android.support.v4.app.Fragment) OneFragment(com.example.jingbin.cloudreader.ui.one.OneFragment) ActionBar(android.support.v7.app.ActionBar)

Aggregations

Fragment (android.support.v4.app.Fragment)663 FragmentTransaction (android.support.v4.app.FragmentTransaction)233 Bundle (android.os.Bundle)149 View (android.view.View)140 FragmentManager (android.support.v4.app.FragmentManager)134 DialogFragment (android.support.v4.app.DialogFragment)80 TextView (android.widget.TextView)59 FragmentInstruction (de.madcyph3r.example.example.FragmentInstruction)48 MaterialMenu (de.madcyph3r.materialnavigationdrawer.menu.MaterialMenu)48 MaterialItemSectionFragment (de.madcyph3r.materialnavigationdrawer.menu.item.section.MaterialItemSectionFragment)48 FragmentDummy (de.madcyph3r.example.example.FragmentDummy)43 Intent (android.content.Intent)41 ViewPager (android.support.v4.view.ViewPager)38 FragmentActivity (android.support.v4.app.FragmentActivity)34 ImageView (android.widget.ImageView)32 BaseFragment (com.waz.zclient.pages.BaseFragment)29 ArrayList (java.util.ArrayList)28 FragmentPagerAdapter (android.support.v4.app.FragmentPagerAdapter)25 Button (android.widget.Button)24 ActionBar (android.support.v7.app.ActionBar)23