androidx.fragment.app.Fragment Java Examples
The following examples show how to use
androidx.fragment.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: EnterGalleryDetailTransaction.java From MHViewer with Apache License 2.0 | 6 votes |
@Override public boolean onTransition(Context context, FragmentTransaction transaction, Fragment exit, Fragment enter) { if (mThumb == null || !(enter instanceof GalleryDetailScene)) { return false; } String transitionName = ViewCompat.getTransitionName(mThumb); if (transitionName != null) { exit.setSharedElementReturnTransition( TransitionInflater.from(context).inflateTransition(R.transition.trans_move)); exit.setExitTransition( TransitionInflater.from(context).inflateTransition(R.transition.trans_fade)); enter.setSharedElementEnterTransition( TransitionInflater.from(context).inflateTransition(R.transition.trans_move)); enter.setEnterTransition( TransitionInflater.from(context).inflateTransition(R.transition.trans_fade)); transaction.addSharedElement(mThumb, transitionName); } return true; }
Example #2
Source File: AddBeaconChoicePreferenceDummy.java From PresencePublisher with MIT License | 6 votes |
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2) public AddBeaconChoicePreferenceDummy(Context context, Fragment fragment) { super(context); setKey(DUMMY); setIcon(android.R.drawable.ic_menu_add); setTitle(R.string.add_beacon_title); setSummary(R.string.add_beacon_summary); setOnPreferenceClickListener(prefs -> { BluetoothManager bluetoothManager = (BluetoothManager) getContext().getSystemService(Context.BLUETOOTH_SERVICE); if (bluetoothManager == null) { HyperLog.w(TAG, "Unable to get bluetooth manager"); } else { BluetoothAdapter bluetoothAdapter = bluetoothManager.getAdapter(); if (bluetoothAdapter == null || !bluetoothAdapter.isEnabled()) { Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); fragment.startActivityForResult(enableBtIntent, ON_DEMAND_BLUETOOTH_REQUEST_CODE); return true; } } BeaconScanDialogFragment instance = getInstance(getContext(), this::onScanResult, getSharedPreferences().getStringSet(BEACON_LIST, Collections.emptySet())); instance.show(fragment.requireFragmentManager(), null); return true; }); }
Example #3
Source File: FragmentStack.java From cathode with Apache License 2.0 | 6 votes |
/** Removes all added fragments and clears the stack. */ public void destroy() { if (!allowTransactions()) { return; } commit(); ensureTransaction(); fragmentTransaction.setCustomAnimations(enterAnimation, exitAnimation); final Fragment topFragment = stack.peekFirst(); for (Fragment f : stack) { if (f != topFragment) removeFragment(f); } stack.clear(); for (String tag : topLevelTags) { removeFragment(fragmentManager.findFragmentByTag(tag)); } fragmentTransaction.commitNow(); fragmentTransaction = null; }
Example #4
Source File: MainActivity.java From simple-stack with Apache License 2.0 | 6 votes |
public void setupViewsForKey(BaseKey key) { if(key.shouldShowUp()) { drawerLayout.setDrawerLockMode(LOCK_MODE_LOCKED_CLOSED, GravityCompat.START); drawerToggle.setDrawerIndicatorEnabled(false); getSupportActionBar().setDisplayHomeAsUpEnabled(true); } else { drawerLayout.setDrawerLockMode(LOCK_MODE_UNLOCKED, GravityCompat.START); getSupportActionBar().setDisplayHomeAsUpEnabled(false); drawerToggle.setDrawerIndicatorEnabled(true); } drawerToggle.syncState(); setCheckedItem(key.navigationViewId()); supportInvalidateOptionsMenu(); if(key.isFabVisible()) { fab.show(); } else { fab.hide(); } Fragment fragment = getSupportFragmentManager().findFragmentByTag(key.getFragmentTag()); key.setupFab(fragment, fab); }
Example #5
Source File: ConfirmationDialogFragment.java From DeviceConnect-Android with MIT License | 6 votes |
public static ConfirmationDialogFragment newInstance( final String title, final String message, final String positive, final String negative, final Fragment fragment) { Bundle args = new Bundle(); args.putString(EXTRA_TITLE, title); args.putString(EXTRA_MESSAGE, message); if (positive != null) { args.putString(EXTRA_POSITIVE, positive); } if (negative != null) { args.putString(EXTRA_NEGATIVE, negative); } ConfirmationDialogFragment f = new ConfirmationDialogFragment(); f.setArguments(args); if (fragment != null) { f.setTargetFragment(fragment, 0); } return f; }
Example #6
Source File: EasyPermissions.java From AndroidQuick with MIT License | 6 votes |
private static void checkCallingObjectSuitability(Object object) { // Make sure Object is an Activity or Fragment boolean isActivity = object instanceof Activity; boolean isSupportFragment = object instanceof Fragment; boolean isAppFragment = object instanceof android.app.Fragment; boolean isMinSdkM = Build.VERSION.SDK_INT >= Build.VERSION_CODES.M; if (!(isSupportFragment || isActivity || (isAppFragment && isMinSdkM))) { if (isAppFragment) { throw new IllegalArgumentException( "Target SDK needs to be greater than 23 if caller is android.app.Fragment"); } else { throw new IllegalArgumentException("Caller must be an Activity or a Fragment."); } } }
Example #7
Source File: AwesomeFragment.java From AndroidNavigation with MIT License | 6 votes |
private void handleHideBottomBarWhenPushed(int transit, boolean enter, PresentAnimation animation) { // handle hidesBottomBarWhenPushed Fragment parent = getParentFragment(); if (parent instanceof NavigationFragment) { NavigationFragment navigationFragment = (NavigationFragment) parent; TabBarFragment tabBarFragment = navigationFragment.getTabBarFragment(); if (tabBarFragment == null || !enter) { return; } int index = getIndexAtBackStack(); if (transit == FragmentTransaction.TRANSIT_FRAGMENT_OPEN) { if (index == 0) { if (tabBarFragment.getTabBar() != null) { tabBarFragment.showTabBarWhenPop(R.anim.nav_none); } } else if (index == 1 && shouldHideTabBarWhenPushed()) { tabBarFragment.hideTabBarWhenPush(animation.exit); } } else if (transit == FragmentTransaction.TRANSIT_FRAGMENT_CLOSE) { if (index == 0 && shouldHideTabBarWhenPushed()) { tabBarFragment.showTabBarWhenPop(animation.popEnter); } } } }
Example #8
Source File: WelcomeActivity.java From EdXposedManager with GNU General Public License v3.0 | 6 votes |
private void notifyDataSetChanged() { View parentLayout = findViewById(R.id.content_frame); String frameworkUpdateVersion = mRepoLoader.getFrameworkUpdateVersion(); boolean moduleUpdateAvailable = mRepoLoader.hasModuleUpdates(); Fragment currentFragment = getSupportFragmentManager() .findFragmentById(R.id.content_frame); if (currentFragment instanceof DownloadDetailsFragment) { if (frameworkUpdateVersion != null) { Snackbar.make(parentLayout, R.string.welcome_framework_update_available + " " + frameworkUpdateVersion, Snackbar.LENGTH_LONG).show(); } } boolean snackBar = getSharedPreferences( getPackageName() + "_preferences", MODE_PRIVATE).getBoolean("snack_bar", true); if (moduleUpdateAvailable && snackBar) { Snackbar.make(parentLayout, R.string.modules_updates_available, Snackbar.LENGTH_LONG).setAction(getString(R.string.view), view -> switchFragment(4)).show(); } }
Example #9
Source File: ConfirmDialogV4.java From libcommon with Apache License 2.0 | 6 votes |
/** * ダイアログ表示のためのヘルパーメソッド * こっちはCharSequenceとしてメッセージ内容を指定 * @param parent * @param requestCode * @param id_title * @param message * @param canceledOnTouchOutside * @param userArgs * @return * @throws IllegalStateException */ public static ConfirmDialogV4 showDialog( @NonNull final Fragment parent, final int requestCode, @StringRes final int id_title, @NonNull final CharSequence message, final boolean canceledOnTouchOutside, @Nullable final Bundle userArgs) throws IllegalStateException { final ConfirmDialogV4 dialog = newInstance(requestCode, id_title, 0, message, canceledOnTouchOutside, userArgs); dialog.setTargetFragment(parent, parent.getId()); dialog.show(parent.getParentFragmentManager(), TAG); return dialog; }
Example #10
Source File: MessageDialogFragmentV4.java From libcommon with Apache License 2.0 | 6 votes |
@Override public void onAttach(@NonNull final Context context) { super.onAttach(context); // コールバックインターフェースを取得 if (context instanceof MessageDialogListener) { mDialogListener = (MessageDialogListener)context; } if (mDialogListener == null) { final Fragment fragment = getTargetFragment(); if (fragment instanceof MessageDialogListener) { mDialogListener = (MessageDialogListener)fragment; } } if (mDialogListener == null) { if (BuildCheck.isAndroid4_2()) { final Fragment target = getParentFragment(); if (target instanceof MessageDialogListener) { mDialogListener = (MessageDialogListener)target; } } } if (mDialogListener == null) { // Log.w(TAG, "caller activity/fragment must implement PermissionDetailDialogFragmentListener"); throw new ClassCastException(context.toString()); } }
Example #11
Source File: WelcomeFragment.java From Notepad with Apache License 2.0 | 6 votes |
public void dispatchKeyShortcutEvent(int keyCode) { switch(keyCode) { // CTRL+N: New Note case KeyEvent.KEYCODE_N: Bundle bundle = new Bundle(); bundle.putString("filename", "new"); Fragment fragment = new NoteEditFragment(); fragment.setArguments(bundle); // Add NoteEditFragment getFragmentManager() .beginTransaction() .replace(R.id.noteViewEdit, fragment, "NoteEditFragment") .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_CLOSE) .commit(); break; } }
Example #12
Source File: MainActivity.java From Moneycim with MIT License | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); unbinder = ButterKnife.bind(this); setSupportActionBar(toolbar); if(savedInstanceState == null){ showRootFragment(SpendingListFragment.newInstance()); } fragmentManager.addOnBackStackChangedListener(() -> { List<Fragment> fragments = fragmentManager.getFragments(); Fragment lastFragment = fragments.get(fragments.size() - 1); if(lastFragment instanceof SpendingListFragment){ appBarLayout.setExpanded(true); fab.show(); } else { appBarLayout.setExpanded(false); fab.hide(); } }); }
Example #13
Source File: PreferencesActivity.java From Field-Book with GNU General Public License v2.0 | 6 votes |
@Override public boolean onPreferenceStartFragment(PreferenceFragmentCompat caller, androidx.preference.Preference pref) { // Instantiate the new Fragment final Bundle args = pref.getExtras(); final Fragment fragment = getSupportFragmentManager().getFragmentFactory().instantiate( getClassLoader(), pref.getFragment()); fragment.setArguments(args); fragment.setTargetFragment(caller, 0); // Replace the existing Fragment with the new Fragment getSupportFragmentManager().beginTransaction() .replace(android.R.id.content, fragment) .addToBackStack(null) .commit(); return true; }
Example #14
Source File: SettingsPlaceFragment.java From arcusandroid with Apache License 2.0 | 6 votes |
@Override public boolean onOptionsItemSelected(@NonNull MenuItem item) { // If we're currently saving data - don't do anything. if (isSaving.get()) { return true; } // Don't do anything if we're showing the tz fragment. Fragment tzFragment = BackstackManager.getInstance().getFragmentOnStack(TimezonePickerPopup.class); if (tzFragment != null && tzFragment instanceof TimezonePickerPopup && tzFragment.isVisible()) { return true; } // If for some reason we clicked on something that shouldn't be there.... if (item.getItemId() != R.id.menu_edit_contact) { return super.onOptionsItemSelected(item); } // Else update the editing/not editing mode. String menuTitle = String.valueOf(item.getTitle()); boolean editing = edit.equalsIgnoreCase(menuTitle); item.setTitle(editing ? done : edit); enableInput(editing); return true; }
Example #15
Source File: CustomActionPickerBottomSheet.java From bottomsheets with Apache License 2.0 | 6 votes |
/** * Creates a new instance of the {@link CustomActionPickerBottomSheet} for the specified custom items. * * @param fragment the host fragment * @param items the custom action items * @param config the sheet configuration * @return the created {@link CustomActionPickerBottomSheet} */ @NonNull public static <IT extends BaseActionItem> CustomActionPickerBottomSheet<IT> init(@NonNull Fragment fragment, @NonNull List<IT> items, @NonNull ActionPickerConfig config) { Preconditions.nonNull(fragment); Preconditions.nonNull(fragment.getActivity()); Preconditions.nonNull(items); Preconditions.nonNull(config); return init( fragment.getActivity(), items, new ActionPickerItemResources(), config ); }
Example #16
Source File: FragmentAdapter.java From CalendarView with Apache License 2.0 | 6 votes |
@NonNull @Override public Object instantiateItem(@NonNull ViewGroup container, int position) { if (mUpdateFlag) { Fragment fragment = (Fragment) super.instantiateItem(container, position); String tag = fragment.getTag(); FragmentTransaction transaction = mFragmentManager.beginTransaction(); transaction.remove(fragment); fragment = getItem(position); if (!fragment.isAdded()) { transaction.add(container.getId(), fragment, tag) .attach(fragment) .commitAllowingStateLoss(); } return fragment; } return super.instantiateItem(container, position); }
Example #17
Source File: RxPreferenceFragmentLifecycleTest.java From RxLifecycle with Apache License 2.0 | 6 votes |
private void testBindUntilEvent(LifecycleProvider<FragmentEvent> provider) { Fragment fragment = (Fragment) provider; startFragment(fragment); TestObserver<Object> testObserver = observable.compose(provider.bindUntilEvent(STOP)).test(); fragment.onAttach(null); testObserver.assertNotComplete(); fragment.onCreate(null); testObserver.assertNotComplete(); fragment.onViewCreated(null, null); testObserver.assertNotComplete(); fragment.onStart(); testObserver.assertNotComplete(); fragment.onResume(); testObserver.assertNotComplete(); fragment.onPause(); testObserver.assertNotComplete(); fragment.onStop(); testObserver.assertComplete(); }
Example #18
Source File: ItemPagerAdapter.java From materialistic with Apache License 2.0 | 6 votes |
@Override public Fragment getItem(int position) { if (mFragments[position] != null) { return mFragments[position]; } String fragmentName; Bundle args = new Bundle(); args.putBoolean(LazyLoadFragment.EXTRA_EAGER_LOAD, mDefaultItem == position); if (position == 0) { args.putParcelable(ItemFragment.EXTRA_ITEM, mItem); args.putInt(ItemFragment.EXTRA_CACHE_MODE, mCacheMode); args.putBoolean(ItemFragment.EXTRA_RETAIN_INSTANCE, mRetainInstance); fragmentName = ItemFragment.class.getName(); } else { args.putParcelable(WebFragment.EXTRA_ITEM, mItem); args.putBoolean(WebFragment.EXTRA_RETAIN_INSTANCE, mRetainInstance); fragmentName = WebFragment.class.getName(); } return Fragment.instantiate(mContext, fragmentName, args); }
Example #19
Source File: DialogUtils.java From CommonUtils with Apache License 2.0 | 5 votes |
public static void showDialog(@Nullable Fragment fragment, @NonNull DialogFragment dialog, @Nullable String tag) { if (fragment == null) return; FragmentManager manager = fragment.getChildFragmentManager(); try { dialog.show(manager, tag); } catch (IllegalStateException ex) { Log.e(TAG, "Failed showing dialog.", ex); // We can't do nothing } }
Example #20
Source File: BaseActivity.java From android-drag-FlowLayout with Apache License 2.0 | 5 votes |
protected void replaceFragment(int containerViewId, Fragment fragment, boolean addToback) { FragmentTransaction ft = getSupportFragmentManager().beginTransaction().replace(containerViewId, fragment); if (addToback) { ft.addToBackStack(fragment.getClass().getName()); } ft.commit(); }
Example #21
Source File: ProfileEditActivity.java From SmartPack-Kernel-Manager with GNU General Public License v3.0 | 5 votes |
private Fragment getFragment() { Fragment fragment = getSupportFragmentManager().findFragmentByTag("fragment"); if (fragment == null) { fragment = ProfileEditFragment.newInstance(mPosition); } return fragment; }
Example #22
Source File: SettingsActivity.java From MetalDetector with GNU General Public License v3.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_settings); Fragment preferenceFragment = new SettingsFragment(); FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); ft.add(R.id.pref_container, preferenceFragment); ft.commit(); }
Example #23
Source File: FileSelectorPresenterImpl.java From HaoReader with GNU General Public License v3.0 | 5 votes |
@Override public void init(Fragment fragment) { Bundle bundle = fragment.getArguments(); assert bundle != null; title = bundle.getString("title"); isSingleChoice = bundle.getBoolean("isSingleChoice"); checkBookAdded = bundle.getBoolean("checkBookAdded"); isImage = bundle.getBoolean("isImage"); ArrayList<String> list = bundle.getStringArrayList("suffixes"); assert list != null; suffixes = new String[list.size()]; list.toArray(suffixes); key = StringUtils.join(",", list); }
Example #24
Source File: HealthFragmentChild1.java From DoraemonKit with Apache License 2.0 | 5 votes |
@Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); mLlBackTop = findViewById(R.id.ll_back_top); mLlBackTop.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Fragment parentFragment = getParentFragment(); if (parentFragment instanceof HealthFragment) { ((HealthFragment) parentFragment).scroll2theTop(); } } }); }
Example #25
Source File: Util.java From MaxLock with GNU General Public License v3.0 | 5 votes |
public static void checkForStoragePermission(final Fragment fragment, final int code, @StringRes int description) { if (ContextCompat.checkSelfPermission(fragment.getActivity(), WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { new AlertDialog.Builder(fragment.getActivity()) .setMessage(description) .setPositiveButton(android.R.string.ok, (dialog, which) -> fragment.requestPermissions(new String[]{WRITE_EXTERNAL_STORAGE}, code)) .setNegativeButton(android.R.string.cancel, null) .create().show(); } else { fragment.onRequestPermissionsResult(code, new String[]{WRITE_EXTERNAL_STORAGE}, new int[]{PackageManager.PERMISSION_GRANTED}); } }
Example #26
Source File: WelcomeFragment.java From live-app-android with MIT License | 5 votes |
public static Fragment newInstance(String pubKey) { WelcomeFragment fragment = new WelcomeFragment(); Bundle bundle = new Bundle(); bundle.putString(MainActivity.PUBLISHABLE_KEY, pubKey); fragment.setArguments(bundle); return fragment; }
Example #27
Source File: MainActivity.java From guanggoo-android with Apache License 2.0 | 5 votes |
public static void addFragmentToStack(FragmentManager fm, Fragment fragment) { FragmentTransaction ft = fm.beginTransaction(); ft.replace(R.id.fragment_container, fragment); ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); ft.addToBackStack(sStackName); ft.commit(); }
Example #28
Source File: MainActivity.java From ui with Apache License 2.0 | 5 votes |
@Override public Fragment getItem(int position) { switch (position) { case 0: return leftfrag; case 1: return midfrag; case 2: return rightfrag; default: return null; } }
Example #29
Source File: HomePagerAdapter.java From guanggoo-android with Apache License 2.0 | 5 votes |
@Override public Fragment getItem(int position) { BaseFragment fragment = null; String url = null; switch (position) { case 0: url = ConstantUtil.BASE_URL; break; case 1: url = ConstantUtil.LATEST_URL; break; case 2: url = ConstantUtil.ELITE_URL; break; case 3: url = ConstantUtil.FOLLOWS_URL; break; default: break; } if (!TextUtils.isEmpty(url)) { fragment = FragmentFactory.getFragmentByUrl(url); Bundle bundle = new Bundle(); bundle.putString(BaseFragment.KEY_URL, url); bundle.putString(BaseFragment.KEY_TITLE, getPageTitle(position).toString()); fragment.setArguments(bundle); } return fragment; }
Example #30
Source File: ApplicationPreferencesActivity.java From deltachat-android with GNU General Public License v3.0 | 5 votes |
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); Fragment fragment = getSupportFragmentManager().findFragmentById(android.R.id.content); fragment.onActivityResult(requestCode, resultCode, data); }