android.support.v4.app.Fragment Java Examples
The following examples show how to use
android.support.v4.app.Fragment.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EZ.java From spark-sdk-android with Apache License 2.0 | 6 votes |
/** * Return the callbacks for a fragment or throw an exception. * <p/> * Inspired by: https://gist.github.com/keyboardr/5455206 */ @SuppressWarnings("unchecked") public static <T> T getCallbacksOrThrow(Fragment frag, Class<T> callbacks) { Fragment parent = frag.getParentFragment(); if (parent != null && callbacks.isInstance(parent)) { return (T) parent; } else { FragmentActivity activity = frag.getActivity(); if (activity != null && callbacks.isInstance(activity)) { return (T) activity; } } // We haven't actually failed a class cast thanks to the checks above, but that's the // idiomatic approach for this pattern with fragments. throw new ClassCastException("This fragment's activity or parent fragment must implement " + callbacks.getCanonicalName()); }
Example #2
Source File: MainActivity.java From Cashew with Apache License 2.0 | 6 votes |
@Override public void initView(Bundle savedInstanceState) { SwipeBackHelper.getCurrentPage(this) .setSwipeBackEnable(false); SwipeBackHelper.getCurrentPage(this).setDisallowInterceptTouchEvent(true); getBinding().bnve.enableAnimation(false); getBinding().bnve.enableShiftingMode(false); getBinding().bnve.enableItemShiftingMode(false); List<Fragment> fragments = new ArrayList<>(); fragments.add(new DailyFragment()); fragments.add(new ClassifyFragment()); fragments.add(new GirlFragment()); getBinding().viewpagerMain.setOffscreenPageLimit(fragments.size()); NoTouchNoAnimPagerAdapter noTouchNoAnimPagerAdapter = new NoTouchNoAnimPagerAdapter(getSupportFragmentManager(), fragments); getBinding().viewpagerMain.setAdapter(noTouchNoAnimPagerAdapter); setFrag(R.id.b_i_day); getBinding().bnve.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(@NonNull MenuItem item) { setFrag(item.getItemId()); return true; } }); }
Example #3
Source File: ViewPagerTabFragmentRecyclerViewFragment.java From Android-ObservableScrollView with Apache License 2.0 | 6 votes |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_recyclerview, container, false); final ObservableRecyclerView recyclerView = (ObservableRecyclerView) view.findViewById(R.id.scroll); recyclerView.setLayoutManager(new LinearLayoutManager(getActivity())); recyclerView.setHasFixedSize(false); setDummyData(recyclerView); Fragment parentFragment = getParentFragment(); ViewGroup viewGroup = (ViewGroup) parentFragment.getView(); if (viewGroup != null) { recyclerView.setTouchInterceptionViewGroup((ViewGroup) viewGroup.findViewById(R.id.container)); if (parentFragment instanceof ObservableScrollViewCallbacks) { recyclerView.setScrollViewCallbacks((ObservableScrollViewCallbacks) parentFragment); } } return view; }
Example #4
Source File: MainActivity.java From find-client-android with MIT License | 6 votes |
@SuppressWarnings("StatementWithEmptyBody") @Override public boolean onNavigationItemSelected(MenuItem item) { // Handle navigation view item clicks here. int id = item.getItemId(); Fragment fragment; if (id == R.id.nav_settings) { fragment = new SettingsFragment(); } else if (id == R.id.nav_track) { fragment = new TrackFragment(); } else { // Anything else is home fragment = new LearnFragment(); } // Insert the fragment by replacing any existing fragment FragmentManager fragmentManager = getSupportFragmentManager(); fragmentManager.beginTransaction() .replace(R.id.content, fragment) .commit(); DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); drawer.closeDrawer(GravityCompat.START); return true; }
Example #5
Source File: VideoLoadAsync.java From MediaChooser with Apache License 2.0 | 6 votes |
public VideoLoadAsync(Fragment fragment, ImageView imageView, boolean isScrolling, int width) { mImageView = imageView; this.fragment = fragment; mWidth = width; mIsScrolling = isScrolling; final int memClass = ((ActivityManager) fragment.getActivity().getSystemService(Context.ACTIVITY_SERVICE)) .getMemoryClass(); final int size = 1024 * 1024 * memClass / 8; // Handle orientation change. GalleryRetainCache c = GalleryRetainCache.getOrCreateRetainableCache(); mCache = c.mRetainedCache; if (mCache == null) { // The maximum bitmap pixels allowed in respective direction. // If exceeding, the cache will automatically scale the // bitmaps. /* final int MAX_PIXELS_WIDTH = 100; final int MAX_PIXELS_HEIGHT = 100;*/ mCache = new GalleryCache(size, mWidth, mWidth); c.mRetainedCache = mCache; } }
Example #6
Source File: RxLoaderBackendNestedFragmentCompat.java From rxloader with Apache License 2.0 | 6 votes |
private String getStateId() { if (stateId != null) { return stateId; } Fragment parentFragment = getParentFragment(); stateId = parentFragment.getTag(); if (stateId == null) { int id = parentFragment.getId(); if (id > 0) { stateId = Integer.toString(id); } } if (stateId == null) { throw new IllegalStateException("Fragment dose not have a valid id"); } return stateId; }
Example #7
Source File: NewsFragment.java From xmpp with Apache License 2.0 | 6 votes |
/** * 初始化数据 */ private void initialData() { { childFragments = new ArrayList<Fragment>(); for (int i = 0; i < list.size(); i++) { childFragments.add(titleFragment.newInstance(list.get(i))); } mPageAdapter = new MainFragmentPagerAdapter(getChildFragmentManager(), list, childFragments); mViewpager.setAdapter(mPageAdapter); lauout.setupWithViewPager(mViewpager); lauout.setTabMode(TabLayout.MODE_FIXED); DialogView.dismiss(); } }
Example #8
Source File: OnlyIconsActivity.java From AdvancedMaterialDrawer with Apache License 2.0 | 6 votes |
@Override public void init(Bundle savedInstanceState) { drawer = this; // information text for the fragment Bundle bundle = new Bundle(); bundle.putString("instruction", "The Menu has Only Icons"); Fragment fragmentInstruction = new FragmentInstruction(); fragmentInstruction.setArguments(bundle); // create menu MaterialMenu menu = new MaterialMenu(); menu.add(new MaterialItemSectionFragment(this, this.getResources().getDrawable(R.drawable.app_drawer_icon) , true, new FragmentDummy(), "Fragment Section Icon Banner")); menu.add(new MaterialItemSectionFragment(this, this.getResources().getDrawable(R.drawable.ic_extension_black_36dp) , true, new FragmentDummy(), "Extension")); menu.add(new MaterialItemSectionFragment(this, this.getResources().getDrawable(R.drawable.ic_list_black_36dp) , true, new FragmentDummy(), "List")); menu.add(new MaterialItemSectionFragment(this, this.getResources().getDrawable(R.drawable.ic_favorite_black_36dp) , true, new FragmentDummy(), "Favorite").setSectionColor(Color.parseColor("#ff0858"))); // load menu this.loadMenu(menu); // load the MaterialItemSectionFragment, from the given startIndex this.loadStartFragmentFromMenu(menu); }
Example #9
Source File: WallpaperBoardBrowserActivity.java From wallpaperboard with Apache License 2.0 | 6 votes |
@Override public void onBackPressed() { if (mFragmentId == Extras.ID_WALLPAPER_SEARCH) { Fragment fragment = mFragManager.findFragmentByTag(Extras.TAG_WALLPAPER_SEARCH); if (fragment != null) { WallpaperSearchFragment wallpaperSearchFragment = (WallpaperSearchFragment) fragment; if (!wallpaperSearchFragment.isSearchQueryEmpty()) { wallpaperSearchFragment.filterSearch(""); return; } } super.onBackPressed(); overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out); return; } super.onBackPressed(); }
Example #10
Source File: BaseActivity.java From Android-Pull-To-Refresh with Apache License 2.0 | 5 votes |
public void replaceFragment(Fragment fragment, boolean addToBackStack) { FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction(); fragmentTransaction.setCustomAnimations(R.anim.right_in, R.anim.left_out, R.anim.left_in, R.anim.right_out); fragmentTransaction.replace(R.id.fl_container, fragment); if (addToBackStack) { fragmentTransaction.addToBackStack(null); } fragmentTransaction.commitAllowingStateLoss(); }
Example #11
Source File: SafetyWarningFragment.java From carstream-android-auto with Apache License 2.0 | 5 votes |
@Override public void onAttach(Context context) { super.onAttach(context); Fragment parentFragment = getParentFragment(); if (parentFragment instanceof FragmentInteractionListener) { listener = (FragmentInteractionListener) parentFragment; } }
Example #12
Source File: BusFragment.java From FakeWeather with Apache License 2.0 | 5 votes |
private void setupViewPager(ViewPager viewPager) { ViewPagerAdapter adapter = new ViewPagerAdapter(getChildFragmentManager()); Fragment fragment = new NearbyLineFragment(); adapter.addFrag(fragment, getString(R.string.bus_nearby_line)); fragment = new NearbyStationFragment(); adapter.addFrag(fragment, getString(R.string.bus_nearby_station)); fragment = new FavoritesFragment(); adapter.addFrag(fragment, getString(R.string.bus_favorites)); viewPager.setAdapter(adapter); }
Example #13
Source File: FileListPagerFragment.java From 920-text-editor-v2 with Apache License 2.0 | 5 votes |
public static Fragment newFragment(JecFile path) { FileListPagerFragment f = new FileListPagerFragment(); Bundle b = new Bundle(); b.putParcelable("path", path); f.setArguments(b); return f; }
Example #14
Source File: NovelFragment.java From fingerpoetry-android with Apache License 2.0 | 5 votes |
@Override public Fragment getItem(int position) { if(position == 0){ return new UpdateFragment<Chapter>(); } else { return new SubscribFragment<User2Novel>(); } }
Example #15
Source File: MainActivity.java From AndroidHttpCapture with MIT License | 5 votes |
/** * 修改显示的内容 不会重新加载 **/ public void switchContent(Fragment to) { Boolean isAdded = false; try { FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); if (getSupportFragmentManager().getFragments() != null) { for (Fragment f : getSupportFragmentManager().getFragments()) { if (to.getClass().isAssignableFrom(f.getClass())) { if (!f.isAdded()) { transaction.add(R.id.fl_contain, f, f.getClass().getName()); } else { transaction.show(f); } isAdded = true; } else { transaction.hide(f); f.setUserVisibleHint(false); } } } if (!isAdded) { if (!to.isAdded()) { // 先判断是否被add过 transaction.add(R.id.fl_contain, to, to.getClass().getName()).commitNow(); } else { transaction.show(to).commitNow(); // 隐藏当前的fragment,显示下一个 } } else { transaction.commitNow(); } if (getSupportFragmentManager().findFragmentByTag(to.getClass().getName()) != null) { getSupportFragmentManager().findFragmentByTag(to.getClass().getName()).setUserVisibleHint(true); } // setSelectedFragment((BaseFragment) to); } catch (Exception e) { e.printStackTrace(); } }
Example #16
Source File: ArticleActivity.java From Yuan-WanAndroid with Apache License 2.0 | 5 votes |
/** * 给其他需要传入数据的碎片使用 * * @param activity * @param fragment * @param url * @param title */ public static void startActivityForResultByFragment(Activity activity, Fragment fragment, String url, String title, int id, boolean isCollect, int request) { Intent intent = new Intent(activity, ArticleActivity.class); intent.putExtra(Constant.KEY_ARTICLE_URL, url); intent.putExtra(Constant.KEY_ARTICLE_TITLE, title); intent.putExtra(Constant.KEY_ARTICLE_ID, id); intent.putExtra(Constant.KEY_ARTICLE_COLLECT, isCollect); fragment.startActivityForResult(intent,request); }
Example #17
Source File: AuthAgent.java From letv with Apache License 2.0 | 5 votes |
public int doLogin(Activity activity, String str, IUiListener iUiListener, boolean z, Fragment fragment) { this.b = str; this.c = activity; this.a = iUiListener; if (a(activity, fragment, z)) { f.c(f.d, "OpenUi, showUi, return Constants.UI_ACTIVITY"); d.a().a(this.mToken.getOpenId(), this.mToken.getAppId(), "2", "1", "5", "0", "0", "0"); return 1; } d.a().a(this.mToken.getOpenId(), this.mToken.getAppId(), "2", "1", "5", "1", "0", "0"); f.d(f.d, "startActivity fail show dialog."); this.a = new FeedConfirmListener(this, this.a); return a(z, this.a); }
Example #18
Source File: Flow.java From Flow with Apache License 2.0 | 5 votes |
private void fromFragment() { Fragment fragment = ((Fragment) src); if (forResult) { fragment.startActivityForResult(intent(fragment.getActivity()), requestCode); } else { fragment.startActivity(intent(fragment.getActivity())); } }
Example #19
Source File: MainActivity.java From GeoLog with Apache License 2.0 | 5 votes |
@Override public Fragment getItem(int position) { if (position == 0) { if (tabProfiles == null) tabProfiles = new ProfilesFragment(); return tabProfiles; } else if (position == 1) { if (tabLogs == null) tabLogs = new LogsFragment(); return tabLogs; } else if (position == 2) { if (tabSettings == null) tabSettings = new SettingsFragment(); return tabSettings; } return null; }
Example #20
Source File: HomeActivity.java From alpha-wallet-android with MIT License | 5 votes |
public HomeActivity() { importFileName = null; if (VisibilityFilter.hideDappBrowser()) dappBrowserFragment = new Fragment(); else dappBrowserFragment = new DappBrowserFragment(); transactionsFragment = new TransactionsFragment(); settingsFragment = new NewSettingsFragment(); walletFragment = new WalletFragment(); lifeCycle = new LifecycleObserver() { @OnLifecycleEvent(Lifecycle.Event.ON_START) private void onMoveToForeground() { Log.d("LIFE", "AlphaWallet into foreground"); ((WalletFragment)walletFragment).walletInFocus(); } @OnLifecycleEvent(Lifecycle.Event.ON_STOP) private void onMoveToBackground() { Log.d("LIFE", "AlphaWallet into background"); ((WalletFragment)walletFragment).walletOutOfFocus(); } @Override public int hashCode() { return super.hashCode(); } }; ProcessLifecycleOwner.get().getLifecycle().addObserver(lifeCycle); }
Example #21
Source File: MainActivity.java From LeisureRead with Apache License 2.0 | 5 votes |
private void showFragment(Fragment fragment) { getSupportFragmentManager() .beginTransaction() .replace(R.id.content, fragment) .commit(); }
Example #22
Source File: FragmentUtils.java From Android-UtilCode with Apache License 2.0 | 5 votes |
/** * 隐藏同级别fragment * * @param fragmentManager fragment管理器 */ public static void hideFragments(@NonNull FragmentManager fragmentManager) { List<Fragment> fragments = getFragments(fragmentManager); if (fragments.isEmpty()) return; for (int i = fragments.size() - 1; i >= 0; --i) { Fragment fragment = fragments.get(i); if (fragment != null) hideFragment(fragment); } }
Example #23
Source File: MainTimeLineActivity.java From iBeebo with GNU General Public License v3.0 | 5 votes |
private void initFragments() { Fragment timeLineFragment = getMainTimeLineFragment(); Fragment favFragment = getFavFragment(); Fragment hotWeiboFragment = getHotWeiboViewPagerFragment(); Fragment hotHuatiFragment = getHotHuaTiViewPagerFragment(); FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); if (!timeLineFragment.isAdded()) { fragmentTransaction.add(R.id.center_frame_layout, timeLineFragment, MainTimeLineFragment.class.getName()); fragmentTransaction.hide(timeLineFragment); } if (!favFragment.isAdded()) { fragmentTransaction.add(R.id.center_frame_layout, favFragment, MyFavListFragment.class.getName()); fragmentTransaction.hide(favFragment); } if (!hotWeiboFragment.isAdded()) { fragmentTransaction.add(R.id.center_frame_layout, hotWeiboFragment, HotWeiboViewPagerFragment.class.getName()); fragmentTransaction.hide(hotWeiboFragment); } if (!hotHuatiFragment.isAdded()) { fragmentTransaction.add(R.id.center_frame_layout, hotHuatiFragment, HotHuaTiViewPagerFragment.class.getName()); fragmentTransaction.hide(hotHuatiFragment); } if (!fragmentTransaction.isEmpty()) { fragmentTransaction.commit(); getSupportFragmentManager().executePendingTransactions(); } }
Example #24
Source File: AppViewActivity.java From aptoide-client with GNU General Public License v2.0 | 5 votes |
@Override public void onClick(View v) { reloadButtons = true; Fragment downgrade = new UninstallRetainFragment(); Bundle args = new Bundle(); args.putString("name", name); args.putString("package", package_name); args.putString("version", versionName); args.putString("downgradeVersion", downgradeVersion); args.putString("icon", icon); downgrade.setArguments(args); getFragmentManager().beginTransaction().add(downgrade, "downgrade").commit(); }
Example #25
Source File: RMBTMainActivity.java From open-rmbt with Apache License 2.0 | 5 votes |
public void showMapFromPager() { try { Fragment f = getCurrentFragment(); if (f != null) { ((RMBTResultPagerFragment) f).getPagerAdapter().showMap(); } } catch (Exception e) { e.printStackTrace(); } }
Example #26
Source File: FragmentPagerItemAdapter.java From material-scrolling with Apache License 2.0 | 5 votes |
@Override public ObservableRecyclerView getRecyclerView(int position) { final Fragment f = getFragment(position); if (f == null) { return null; } final View v = f.getView(); return v == null ? null : (ObservableRecyclerView) v.findViewById(R.id.recyclerView); }
Example #27
Source File: DialogFragmentFancyQrCodePager.java From bither-android with Apache License 2.0 | 5 votes |
public Qr.QrCodeTheme getActiveTheme() { Fragment f = getActiveFragment(); if (f != null && f instanceof DialogFragmentFancyQrCodeSinglePage) { DialogFragmentFancyQrCodeSinglePage page = (DialogFragmentFancyQrCodeSinglePage) f; return page.getTheme(); } return null; }
Example #28
Source File: SchedulesFragment.java From timecat with Apache License 2.0 | 5 votes |
private void updateViewPager() { if (fragmentList == null) return; for (Fragment f : fragmentList) { getChildFragmentManager().beginTransaction().remove(f).commitNow(); } fragmentList.clear(); switch(SPHelper.getInt(SCHEDULES_VIEW_TYPE, 1)) { case 0: scheduleListFragment = new ScheduleListFragment(); fragmentList.add(scheduleListFragment); setOnScrollBoundaryDecider(scheduleListFragment); scheduleListFragment.setUserVisibleHint(true); getChildFragmentManager().beginTransaction().add(R.id.fragment_container, scheduleListFragment).commitNow(); break; case 1: scheduleCalendarFragment = new ScheduleCalendarFragment(); if (mDateChangeListener != null) { scheduleCalendarFragment.setOnDateChangeListener(mDateChangeListener); } fragmentList.add(scheduleCalendarFragment); setOnScrollBoundaryDecider(scheduleCalendarFragment); scheduleCalendarFragment.setUserVisibleHint(true); getChildFragmentManager().beginTransaction().add(R.id.fragment_container, scheduleCalendarFragment).commitNow(); break; case 2: break; } }
Example #29
Source File: LifecycleDispatcher.java From AndroidLifecyle with Apache License 2.0 | 5 votes |
public void onFragmentResumed(Fragment fragment) { Object[] callbacks = collectFragmentLifecycleCallbacks(); if (callbacks != null) { for (int i = 0; i < callbacks.length; i++) { ((FragmentLifecycleCallbacks) callbacks[i]).onFragmentResumed(fragment); } } }
Example #30
Source File: MainPagerAdapter.java From InfiniteCycleViewPager with Apache License 2.0 | 5 votes |
@Override public Fragment getItem(final int position) { switch (position) { case TWO_WAY: return new TwoWayPagerFragment(); case HORIZONTAL: default: return new HorizontalPagerFragment(); } }