Java Code Examples for androidx.fragment.app.FragmentManager#isStateSaved()

The following examples show how to use androidx.fragment.app.FragmentManager#isStateSaved() . 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: GDPR.java    From GDPRDialog with Apache License 2.0 6 votes vote down vote up
/**
 * shows the consent dialog
 *
 * @param activity the parent activity of the dialog
 * @param setup the setup for the dialog
 * @param location the request location
 */
public void showDialog(AppCompatActivity activity, GDPRSetup setup, GDPRLocation location) {
    FragmentManager fm = activity.getSupportFragmentManager();
    if (fm.findFragmentByTag(GDPRDialog.class.getName()) != null) {
        // dialog already exists, it either is already shown or will be shown automatically if activity is recreated
        return;
    }
    try {
        if (fm.isStateSaved()) {
            // in this case, activity will be destroyed, we ignore this call
            return;
        }
        showDialog(fm, activity, setup, location);
    } catch (NoSuchMethodError e) {
        // Support Library Version < 26.1.0 is used, isStateSaved is not yet existing...
        // we just catch the exception and ignore it
        try {
            showDialog(fm, activity, setup, location);
        } catch (IllegalStateException e2) {
            // ignored, activity is probably just being destroyed...
        }
    }
}
 
Example 2
Source File: RationaleDialogFragmentCompat.java    From easypermissions with Apache License 2.0 5 votes vote down vote up
/**
 * Version of {@link #show(FragmentManager, String)} that no-ops when an IllegalStateException
 * would otherwise occur.
 */
public void showAllowingStateLoss(FragmentManager manager, String tag) {
    if (manager.isStateSaved()) {
        return;
    }

    show(manager, tag);
}
 
Example 3
Source File: FragmentItem.java    From WiFiAnalyzer with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void activate(@NonNull MainActivity mainActivity, @NonNull MenuItem menuItem, @NonNull NavigationMenu navigationMenu) {
    FragmentManager fragmentManager = mainActivity.getSupportFragmentManager();
    if (fragmentManager.isStateSaved()) {
        return;
    }
    updateMainActivity(mainActivity, menuItem, navigationMenu);
    startFragment(fragmentManager);
}
 
Example 4
Source File: TaskListActivity.java    From opentasks with Apache License 2.0 5 votes vote down vote up
private void replaceTaskDetailsFragment(@NonNull Fragment fragment)
{
    FragmentManager fragmentManager = getSupportFragmentManager();
    // only change state if the state has not been saved yet, otherwise just drop it
    if (!fragmentManager.isStateSaved())
    {
        fragmentManager.beginTransaction()
                .setCustomAnimations(0, R.anim.openttasks_fade_exit, 0, 0)
                .replace(R.id.task_detail_container, fragment, DETAILS_FRAGMENT_TAG).commit();
    }
}
 
Example 5
Source File: ConfigIntroFragment.java    From prayer-times-android with Apache License 2.0 4 votes vote down vote up
@Override
public void run() {
    mView.postDelayed(mDoTask, 2000);
    if (mFragment == null || mFragment.getTopSlider() == null || isDetached() || !isAdded()) {
        return;
    }

    FragmentManager fm = getChildFragmentManager();
    if (fm.isStateSaved()) return;

    switch (mTask % 6) {
        case 0:
            mFragment.getTopSlider().animateOpen();
            break;
        case 1:
            mFragment.getTopSlider().animateClose();
            break;
        case 2:
            mFragment.getBottomSlider().animateOpen();
            break;
        case 3:
            mFragment.getBottomSlider().animateClose();
            break;
        case 4:
            mMenuItem.getIcon().setAlpha(100);
            mMenuItem.getIcon().invalidateSelf();

            mFragment.setFooterText("", false);
            fm.beginTransaction()
                    .replace(R.id.basecontent,
                            mPrefsFrag).addToBackStack("").commit();
            break;
        case 5:
            mMenuItem.getIcon().setAlpha(255);
            mMenuItem.getIcon().invalidateSelf();
            mFragment.setFooterText(getString(R.string.monthly), false);
            getChildFragmentManager().popBackStack();
            break;

    }
    mTask++;
}
 
Example 6
Source File: TreatmentsBolusFragment.java    From AndroidAPS with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void onClick(View v) {
    final Treatment treatment = (Treatment) v.getTag();
    if (treatment == null)
        return;
    switch (v.getId()) {
        case R.id.treatments_remove:
            OKDialog.showConfirmation(getContext(), MainApp.gs(R.string.removerecord),
                    MainApp.gs(R.string.configbuilder_insulin) + ": " + MainApp.gs(R.string.formatinsulinunits, treatment.insulin) +
                            "\n" + MainApp.gs(R.string.carbs) + ": " + MainApp.gs(R.string.format_carbs, (int) treatment.carbs) +
                            "\n" + MainApp.gs(R.string.date) + ": " + DateUtil.dateAndTimeString(treatment.date),
                    (dialog, id) -> {
                        final String _id = treatment._id;
                        if (treatment.source == Source.PUMP) {
                            treatment.isValid = false;
                            TreatmentsPlugin.getPlugin().getService().update(treatment);
                        } else {
                            if (NSUpload.isIdValid(_id)) {
                                NSUpload.removeCareportalEntryFromNS(_id);
                            } else {
                                UploadQueue.removeID("dbAdd", _id);
                            }
                            TreatmentsPlugin.getPlugin().getService().delete(treatment);
                        }
                        updateGui();
                    }, null);
            break;
        case R.id.treatments_calculation:
            FragmentManager manager = getFragmentManager();
            // try to fix  https://fabric.io/nightscout3/android/apps/info.nightscout.androidaps/issues/5aca7a1536c7b23527eb4be7?time=last-seven-days
            // https://stackoverflow.com/questions/14860239/checking-if-state-is-saved-before-committing-a-fragmenttransaction
            if (manager.isStateSaved())
                return;
            if (treatment.getBoluscalc() != null) {
                WizardInfoDialog wizardDialog = new WizardInfoDialog();
                wizardDialog.setData(treatment.getBoluscalc());
                wizardDialog.show(manager, "WizardInfoDialog");
            }
            break;
    }
}
 
Example 7
Source File: ConfigIntroFragment.java    From prayer-times-android with Apache License 2.0 4 votes vote down vote up
@Override
public void run() {
    mView.postDelayed(mDoTask, 2000);
    if (mFragment == null || mFragment.getTopSlider() == null || isDetached() || !isAdded()) {
        return;
    }

    FragmentManager fm = getChildFragmentManager();
    if (fm.isStateSaved()) return;

    switch (mTask % 6) {
        case 0:
            mFragment.getTopSlider().animateOpen();
            break;
        case 1:
            mFragment.getTopSlider().animateClose();
            break;
        case 2:
            mFragment.getBottomSlider().animateOpen();
            break;
        case 3:
            mFragment.getBottomSlider().animateClose();
            break;
        case 4:
            mMenuItem.getIcon().setAlpha(100);
            mMenuItem.getIcon().invalidateSelf();

            mFragment.setFooterText("", false);
            fm.beginTransaction()
                    .replace(R.id.basecontent,
                            mPrefsFrag).addToBackStack("").commit();
            break;
        case 5:
            mMenuItem.getIcon().setAlpha(255);
            mMenuItem.getIcon().invalidateSelf();
            mFragment.setFooterText(getString(R.string.monthly), false);
            getChildFragmentManager().popBackStack();
            break;

    }
    mTask++;
}