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;
}
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));
}
});
}
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();
}
});
}
}
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;
}
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);
}
}
Aggregations