androidx.fragment.app.FragmentManager Java Examples
The following examples show how to use
androidx.fragment.app.FragmentManager.
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: AskPermission.java From CommonUtils with Apache License 2.0 | 6 votes |
@Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { if (listener != null && code == requestCode) { for (int i = 0; i < permissions.length; i++) { if (grantResults[i] == PackageManager.PERMISSION_GRANTED) listener.permissionGranted(permissions[i]); else listener.permissionDenied(permissions[i]); } } try { if (getActivity() != null) { FragmentManager manager = getActivity().getSupportFragmentManager(); manager.executePendingTransactions(); manager.beginTransaction() .remove(this) .commitAllowingStateLoss(); } } catch (IllegalStateException ex) { Log.w(TAG, ex); } }
Example #2
Source File: ConversationActivity.java From Applozic-Android-SDK with BSD 3-Clause "New" or "Revised" License | 6 votes |
public void showAudioRecordingDialog() { if (Utils.hasMarshmallow() && PermissionsUtils.checkSelfPermissionForAudioRecording(this)) { new ApplozicPermissions(this, layout).requestAudio(); } else if (PermissionsUtils.isAudioRecordingPermissionGranted(this)) { FragmentManager supportFragmentManager = getSupportFragmentManager(); DialogFragment fragment = AudioMessageFragment.newInstance(); FragmentTransaction fragmentTransaction = supportFragmentManager .beginTransaction().add(fragment, "AudioMessageFragment"); fragmentTransaction.addToBackStack(null); fragmentTransaction.commitAllowingStateLoss(); } else { if (alCustomizationSettings.getAudioPermissionNotFoundMsg() == null) { showSnackBar(R.string.applozic_audio_permission_missing); } else { snackbar = Snackbar.make(layout, alCustomizationSettings.getAudioPermissionNotFoundMsg(), Snackbar.LENGTH_SHORT); snackbar.show(); } } }
Example #3
Source File: SimpleListActivity.java From hipda with GNU General Public License v2.0 | 6 votes |
private void showFragment() { FragmentManager fragmentManager = getSupportFragmentManager(); Bundle arguments = getIntent().getExtras(); BaseFragment fragment; if (arguments.getInt(SimpleListFragment.ARG_TYPE) == SimpleListJob.TYPE_SEARCH) { fragment = new SearchFragment(); } else { updateAppBarScrollFlag(); fragment = new SimpleListFragment(); } fragment.setArguments(arguments); fragmentManager.beginTransaction() .replace(R.id.main_frame_container, fragment).commit(); }
Example #4
Source File: FragmentHelper.java From AndroidNavigation with MIT License | 6 votes |
public static void handleDismissFragment(@NonNull AwesomeFragment target, @NonNull AwesomeFragment presented, @Nullable AwesomeFragment top) { FragmentManager fragmentManager = target.requireFragmentManager(); target.setAnimation(PresentAnimation.Modal); if (top == null) { top = (AwesomeFragment) fragmentManager.findFragmentById(target.getContainerId()); } if (top == null) { return; } top.setAnimation(PresentAnimation.Modal); fragmentManager.beginTransaction().setMaxLifecycle(presented, Lifecycle.State.STARTED).commit(); fragmentManager.popBackStack(presented.getSceneId(), FragmentManager.POP_BACK_STACK_INCLUSIVE); FragmentHelper.executePendingTransactionsSafe(fragmentManager); target.onFragmentResult(top.getRequestCode(), top.getResultCode(), top.getResultData()); }
Example #5
Source File: MainBookListFragment.java From HaoReader with GNU General Public License v3.0 | 6 votes |
@Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { if (savedInstanceState != null) { FragmentManager manager = getChildFragmentManager(); fragments[0] = (BookListFragment) manager.findFragmentByTag(getString(BOOK_GROUPS[0])); fragments[1] = (BookListFragment) manager.findFragmentByTag(getString(BOOK_GROUPS[1])); fragments[2] = (BookListFragment) manager.findFragmentByTag(getString(BOOK_GROUPS[2])); fragments[3] = (BookListFragment) manager.findFragmentByTag(getString(BOOK_GROUPS[3])); for (Fragment fragment : fragments) { if (fragment instanceof BookListFragment) { ((BookListFragment) fragment).setItemClickListenerTwo(getAdapterListener()); } } } else { showFragment(this.group); } }
Example #6
Source File: ImagePickerView.java From ColorPickerDialog with Apache License 2.0 | 6 votes |
@Override protected void onRestoreInstanceState(Parcelable state) { super.onRestoreInstanceState(state); new Handler(Looper.getMainLooper()).post(new Runnable() { @Override public void run() { FragmentManager manager = requestFragmentManager(); if (manager != null) { Fragment fragment = manager.findFragmentByTag(TAG_CHILD_IMAGE_PICKER); if (fragment instanceof ImageColorPickerDialog) ((ImageColorPickerDialog) fragment).withListener(listener); } } }); }
Example #7
Source File: MaterialDatePickerPagesTest.java From material-components-android with Apache License 2.0 | 6 votes |
@Before public void setupDatePickerDialogForSwiping() { CalendarConstraints calendarConstraints = new CalendarConstraints.Builder() .setStart(START.timeInMillis) .setEnd(END.timeInMillis) .setOpenAt(OPEN_AT.timeInMillis) .build(); FragmentManager fragmentManager = activityTestRule.getActivity().getSupportFragmentManager(); String tag = "Date DialogFragment"; dialogFragment = MaterialDatePicker.Builder.datePicker().setCalendarConstraints(calendarConstraints).build(); dialogFragment.show(fragmentManager, tag); InstrumentationRegistry.getInstrumentation().waitForIdleSync(); IdlingRegistry.getInstance() .register( new RecyclerIdlingResource( dialogFragment.getView().findViewWithTag(MaterialCalendar.MONTHS_VIEW_GROUP_TAG))); listenerIdlingResource = new ListenerIdlingResource(); }
Example #8
Source File: MainActivity.java From Passbook with Apache License 2.0 | 6 votes |
@Override public void onBackPressed() { setStatusBarColor(0, 0, true); Fragment edit = getSupportFragmentManager().findFragmentByTag("edit"); if(edit != null) { getSupportFragmentManager().popBackStack("edit", FragmentManager.POP_BACK_STACK_INCLUSIVE); mAds.setVisibility(View.VISIBLE); return; } Fragment detail = getSupportFragmentManager().findFragmentByTag("detail"); if(detail!=null) { getSupportFragmentManager().popBackStack("detail", FragmentManager.POP_BACK_STACK_INCLUSIVE); return; } super.onBackPressed(); }
Example #9
Source File: OpenChannelActivity.java From SendBird-Android with MIT License | 6 votes |
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_open_channel); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_open_channel); setSupportActionBar(toolbar); if (getSupportActionBar() != null) { getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_arrow_left_white_24_dp); } if (savedInstanceState == null) { // Load list of Open Channels Fragment fragment = OpenChannelListFragment.newInstance(); FragmentManager manager = getSupportFragmentManager(); manager.popBackStack(); manager.beginTransaction() .replace(R.id.container_open_channel, fragment) .commit(); } }
Example #10
Source File: ImageLoader.java From tindroid with Apache License 2.0 | 6 votes |
ImageLoader(int imageSize, FragmentManager fm) { // mResources = context.getResources(); mImageSize = imageSize > 0 ? imageSize : DEFAULT_IMAGE_SIZE; final RetainFragment retainFragment = findOrCreateRetainFragment(fm); // See if we already have an ImageCache stored in RetainFragment //noinspection unchecked mBitmapCache = (LruCache<String, Bitmap>) retainFragment.getObject(); // No existing ImageCache, create one and store it in RetainFragment if (mBitmapCache == null) { int maxSize = Math.round(MEMORY_PERCENT * Runtime.getRuntime().maxMemory() / 1024); mBitmapCache = new LruCache<String, Bitmap>(maxSize) { /** * Measure item size in kilobytes rather than units which is more practical * for a bitmap cache */ @Override protected int sizeOf(@NonNull String key, @NonNull Bitmap bitmap) { final int bitmapSize = bitmap.getByteCount() / 1024; return bitmapSize == 0 ? 1 : bitmapSize; } }; retainFragment.saveObject(mBitmapCache); } }
Example #11
Source File: IRKitSettingActivity.java From DeviceConnect-Android with MIT License | 6 votes |
/** * getFragments()とgetViewPager().getCurrentItem()の紐付けを行う。 * 表示していたFragmentを返す。 * @return 表示していたFragment */ private Fragment getCurrentFragment(final int current) { FragmentManager fm = getSupportFragmentManager(); Fragment f = null; List<Fragment> list = fm.getFragments(); if (list.size() == 0) { return f; } String className = PAGES[current].getSimpleName(); for (Fragment fragment : list) { if (fragment.getClass().getSimpleName().equals(className)) { f = fragment; } } return f; }
Example #12
Source File: MainActivity.java From googleads-mobile-android-examples with Apache License 2.0 | 6 votes |
@Override public void onNavigationDrawerItemSelected(int position) { // update the main content by replacing fragments FragmentManager fragmentManager = getSupportFragmentManager(); FragmentTransaction trans = fragmentManager.beginTransaction(); switch (position) { case 0: trans.replace(R.id.container, new AdMobAdListenerFragment()); break; case 1: trans.replace(R.id.container, new AdMobAdTargetingFragment()); break; case 2: trans.replace(R.id.container, new AdMobBannerSizesFragment()); break; case 3: trans.replace(R.id.container, new AdMobCustomMuteThisAdFragment()); break; case 4: trans.replace(R.id.container, new DFPFluidSizeFragment()); break; case 5: trans.replace(R.id.container, new DFPPPIDFragment()); break; case 6: trans.replace(R.id.container, new DFPCustomTargetingFragment()); break; case 7: trans.replace(R.id.container, new DFPCategoryExclusionFragment()); break; case 8: trans.replace(R.id.container, new DFPMultipleAdSizesFragment()); break; case 9: trans.replace(R.id.container, new DFPAppEventsFragment()); break; case 10: trans.replace(R.id.container, new DFPCustomControlsFragment()); break; } trans.commit(); }
Example #13
Source File: SectionsPagerAdapter.java From PHONK with GNU General Public License v3.0 | 5 votes |
public SectionsPagerAdapter(FragmentManager fm, EmptyFragment mEmptyFragment, CombinedFolderAndProjectFragment mCombinedFolderAndProjectFragment) { mFragmentManager = fm; mFragments = new SparseArray<>(); mFragments.put(0, mEmptyFragment); mFragments.put(1, mCombinedFolderAndProjectFragment); }
Example #14
Source File: AwesomeActivity.java From AndroidNavigation with MIT License | 5 votes |
protected void setRootFragmentInternal(AwesomeFragment fragment) { clearFragmentsInternal(); FragmentManager fragmentManager = getSupportFragmentManager(); FragmentTransaction transaction = fragmentManager.beginTransaction(); transaction.setReorderingAllowed(true); transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); fragment.setAnimation(PresentAnimation.None); transaction.add(android.R.id.content, fragment, fragment.getSceneId()); transaction.addToBackStack(fragment.getSceneId()); transaction.commit(); FragmentHelper.executePendingTransactionsSafe(fragmentManager); }
Example #15
Source File: MultiFragmentsActivity.java From AndroidAnimationExercise with Apache License 2.0 | 5 votes |
public SectionsPagerAdapter(FragmentManager fm) { super(fm); mFragments.add(new OneFragment()); mFragments.add(new TwoFragment()); mFragments.add(new ThreeFragment()); mFragments.add(new FourFragment()); mFragments.add(new CommunicationFragment()); mTitles.add("one"); mTitles.add("two"); mTitles.add("three"); mTitles.add("four"); mTitles.add("five"); }
Example #16
Source File: CommCareSetupActivity.java From commcare-android with Apache License 2.0 | 5 votes |
private void persistCommCareAppState() { FragmentManager fm = this.getSupportFragmentManager(); containerFragment = (ContainerFragment<CommCareApp>)fm.findFragmentByTag("cc-app"); if (containerFragment == null) { containerFragment = new ContainerFragment<>(); fm.beginTransaction().add(containerFragment, "cc-app").commit(); } else { ccApp = containerFragment.getData(); } }
Example #17
Source File: ReplaceRuleDialog.java From HaoReader with GNU General Public License v3.0 | 5 votes |
public static void show(FragmentManager fragmentManager, ReplaceRuleBean replaceRuleBean, OnSaveReplaceRule saveReplaceRule) { ReplaceRuleDialog dialog = new ReplaceRuleDialog(); Bundle args = new Bundle(); args.putParcelable("replaceRuleBean", replaceRuleBean); dialog.setArguments(args); dialog.saveReplaceRule = saveReplaceRule; dialog.show(fragmentManager, "replaceRule"); }
Example #18
Source File: ImageGalleryFragment.java From Hentoid with Apache License 2.0 | 5 votes |
private boolean onItemClick(int position) { ImageFileItem imgFile = itemAdapter.getAdapterItem(position); viewModel.setStartingIndex(imgFile.getImage().getDisplayOrder()); if (0 == getParentFragmentManager().getBackStackEntryCount()) { // Gallery mode (Library -> gallery -> pager) getParentFragmentManager() .beginTransaction() .replace(android.R.id.content, new ImagePagerFragment()) .addToBackStack(null) .commit(); } else { // Pager mode (Library -> pager -> gallery -> pager) getParentFragmentManager().popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE); // Leave only the latest element in the back stack } return true; }
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: DemoActivity.java From browser-switch-android with MIT License | 5 votes |
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); FragmentManager fm = getSupportFragmentManager(); if (fm.findFragmentByTag(FRAGMENT_TAG) == null) { fm.beginTransaction() .add(android.R.id.content, new DemoFragment(), FRAGMENT_TAG) .commit(); } }
Example #21
Source File: PrivacyPolicyFragment.java From mimi-reader with Apache License 2.0 | 5 votes |
/** * Builds and displays a licenses fragment for you. Requires "/res/raw/licenses.html" and * "/res/layout/licenses_fragment.xml" to be present. * * @param fm A fragment manager instance used to display this LicensesFragment. */ public static void displayLicensesFragment(FragmentManager fm) { FragmentTransaction ft = fm.beginTransaction(); Fragment prev = fm.findFragmentByTag(FRAGMENT_TAG); if (prev != null) { ft.remove(prev); } ft.addToBackStack(null); // Create and show the dialog. DialogFragment newFragment = PrivacyPolicyFragment.newInstance(); newFragment.show(ft, FRAGMENT_TAG); }
Example #22
Source File: MainActivity.java From Bluefruit_LE_Connect_Android_V2 with MIT License | 5 votes |
private void popFragmentsIfNoPeripheralsConnected() { final int numConnectedPeripherals = BleManager.getInstance().getConnectedDevices().size(); final boolean isLastConnectedPeripheral = numConnectedPeripherals == 0; if (isLastConnectedPeripheral && (!kAvoidPoppingFragmentsWhileOnDfu || !isIsDfuInProgress())) { Log.d(TAG, "No peripherals connected. Pop all fragments"); FragmentManager fragmentManager = getSupportFragmentManager(); fragmentManager.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE); fragmentManager.executePendingTransactions(); } }
Example #23
Source File: SongSection.java From Jockey with Apache License 2.0 | 5 votes |
public SongSection(@NonNull List<Song> data, Context context, PlayerController playerController, MusicStore musicStore, PlaylistStore playlistStore, FragmentManager fragmentManager, @Nullable OnSongSelectedListener songSelectedListener) { super(data); mContext = context; mMusicStore = musicStore; mPlaylistStore = playlistStore; mPlayerController = playerController; mFragmentManager = fragmentManager; mSongListener = songSelectedListener; mCurrentSong = BehaviorSubject.create(); }
Example #24
Source File: BaseActivity.java From prayer-times-android with Apache License 2.0 | 5 votes |
@SuppressLint("RtlHardcoded") @Override public boolean onOptionsItemSelected(@NonNull MenuItem item) { if (item.getItemId() == android.R.id.home) { FragmentManager fm = getSupportFragmentManager(); if (fm.getBackStackEntryCount() > 0) { onBackPressed(); } else { mDrawerLayout.openDrawer(isRTL() ? Gravity.RIGHT : Gravity.LEFT); } return true; } return super.onOptionsItemSelected(item); }
Example #25
Source File: TriggerConnector.java From AndroidAPS with GNU Affero General Public License v3.0 | 5 votes |
@Override public void generateDialog(LinearLayout root, FragmentManager fragmentManager) { final int padding = MainApp.dpToPx(5); root.setPadding(padding, padding, padding, padding); root.setBackgroundResource(R.drawable.border_automation_unit); LinearLayout triggerListLayout = new LinearLayout(root.getContext()); triggerListLayout.setOrientation(LinearLayout.VERTICAL); triggerListLayout.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); root.addView(triggerListLayout); adapter = new TriggerListAdapter(fragmentManager, root.getContext(), triggerListLayout, this); }
Example #26
Source File: AirMapView.java From AirMapView with Apache License 2.0 | 5 votes |
/** * Used for initialization of the underlying map provider. * * @param fragmentManager required for initialization */ public void initialize(FragmentManager fragmentManager) { AirMapInterface mapInterface = (AirMapInterface) fragmentManager.findFragmentById(R.id.map_frame); if (mapInterface != null) { initialize(fragmentManager, mapInterface); } else { initialize(fragmentManager, new DefaultAirMapViewBuilder(getContext()).builder().build()); } }
Example #27
Source File: LoginUINetworkTest.java From adamant-android with GNU General Public License v3.0 | 5 votes |
@Test @LargeTest public void uiNetSuccessLogin() throws Exception { LoginScreen activity = activityRule.getActivity(); FragmentManager supportFragmentManager = activity.getSupportFragmentManager(); FragmentIdlingResource dialogFragmentIdlingResource = new FragmentIdlingResource( LoginScreen.BOTTOM_LOGIN_TAG, supportFragmentManager ); onView(withId(R.id.activity_login_btn_login)).perform(click()); idlingBlock(dialogFragmentIdlingResource, () -> { onView(withId(R.id.fragment_login_et_passphrase)) .check(matches(isDisplayed())); onView(withId(R.id.fragment_login_et_passphrase)) .perform(typeText(InstrumentedTestConstants.PASSPHRASE)) .perform(closeSoftKeyboard()); onView(withId(R.id.fragment_login_btn_enter)).perform(click()); }); String mainActivity = MainScreen.class.getName(); ActivityIdlingResosurce activityIdlingResosurce = new ActivityIdlingResosurce(mainActivity); idlingBlock(activityIdlingResosurce, () -> { intended(hasComponent(MainScreen.class.getName())); }); }
Example #28
Source File: StoryViewPagerAdapter.java From Instagram-Profile-Downloader with MIT License | 5 votes |
public StoryViewPagerAdapter(FragmentManager fm, List<StoryModel> models, Boolean isFromNet, List<String> list,Boolean isDownloadPostImage, boolean isAlreadyDownloaded,boolean isFromDownloadScreen){ super(fm); this.modelList = models; this.isFromNet = isFromNet; this.list = list; this.isDownloadPostImage = isDownloadPostImage; this.isAlreadyDownloaded=isAlreadyDownloaded; this.isFromDownloadScreen =isFromDownloadScreen; }
Example #29
Source File: MainActivity.java From ArchPackages with GNU General Public License v3.0 | 5 votes |
/** * callback from {@link DetailsFragment} * inflate a new {@link FilesFragment} * * @param files: the {@link Files} to bind dirs and files count */ @Override public void onDetailsFragmentCallbackOnFilesClicked(Files files) { FragmentManager fragmentManager = getSupportFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); FilesFragment filesFragment = FilesFragment.newInstance(files); fragmentTransaction.add(R.id.content_main_fragment_container, filesFragment); fragmentTransaction.addToBackStack(null); fragmentTransaction.commit(); }
Example #30
Source File: FragmentUtils.java From hipda with GNU General Public License v2.0 | 5 votes |
public static void showFragment(FragmentManager fragmentManager, Fragment fragment, boolean skipEnterAnim) { FragmentTransaction transaction = fragmentManager.beginTransaction(); if (skipEnterAnim) { transaction.setCustomAnimations(0, 0, 0, R.anim.slide_out_right); } else { transaction.setCustomAnimations(R.anim.slide_in_right, R.anim.slide_out_right, R.anim.slide_in_right, R.anim.slide_out_right); } transaction.add(R.id.main_frame_container, fragment, fragment.getClass().getName()) .addToBackStack(fragment.getClass().getName()) .commitAllowingStateLoss(); }