Java Code Examples for androidx.fragment.app.FragmentActivity#getSupportFragmentManager()

The following examples show how to use androidx.fragment.app.FragmentActivity#getSupportFragmentManager() . 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: SimpleDialog.java    From SimpleDialogFragments with Apache License 2.0 6 votes vote down vote up
/**
 * Shows the dialog. Results will be forwarded to the activity supplied.
 * The tag can be used to identify the dialog in {@link OnDialogResultListener#onResult}
 * An optional argument can be used to remove a previously shown dialog with the tag given
 * prior to showing this one.
 *
 * @param activity the hosting activity
 * @param tag the dialogs tag
 * @param replaceTag removes the dialog with the given tag if specified
 */
public void show(FragmentActivity activity, String tag, String replaceTag){
    FragmentManager manager = activity.getSupportFragmentManager();
    Fragment existing = manager.findFragmentByTag(replaceTag);
    if (existing != null) {
        FragmentManager otherManager = existing.getFragmentManager();
        if (otherManager != null) {
            FragmentTransaction ft = otherManager.beginTransaction();
            ft.remove(existing);
            ft.commit();
        }
    }
    try {
        super.show(manager, tag);
    } catch (IllegalStateException ignored) {
    }
}
 
Example 2
Source File: BottomDialogFragment.java    From AndroidQuick with MIT License 6 votes vote down vote up
public static BottomDialogFragment showDialog(FragmentActivity appCompatActivity, String[] itemData) {
    FragmentManager fragmentManager = appCompatActivity.getSupportFragmentManager();
    BottomDialogFragment bottomDialogFragment =
            (BottomDialogFragment) fragmentManager.findFragmentByTag(TAG);
    if (null == bottomDialogFragment) {
        bottomDialogFragment = newInstance(itemData);
    }

    if (!appCompatActivity.isFinishing()
            && null != bottomDialogFragment
            && !bottomDialogFragment.isAdded()) {
        fragmentManager.beginTransaction()
                .add(bottomDialogFragment, TAG)
                .commitAllowingStateLoss();
    }

    return bottomDialogFragment;
}
 
Example 3
Source File: MainActivity.java    From Applozic-Android-SDK with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static void addFragment(FragmentActivity fragmentActivity, Fragment fragmentToAdd, String fragmentTag) {

        FragmentManager supportFragmentManager = fragmentActivity.getSupportFragmentManager();

        //Fragment activeFragment = UIService.getActiveFragment(fragmentActivity);
        FragmentTransaction fragmentTransaction = supportFragmentManager
                .beginTransaction();
        /*if (null != activeFragment) {
            fragmentTransaction.hide(activeFragment);
        }*/

        fragmentTransaction.replace(R.id.container, fragmentToAdd,
                fragmentTag);

        if (supportFragmentManager.getBackStackEntryCount() > 1) {
            supportFragmentManager.popBackStack();
        }
        fragmentTransaction.addToBackStack(fragmentTag);
        fragmentTransaction.commit();
        supportFragmentManager.executePendingTransactions();
        //Log.i(TAG, "BackStackEntryCount: " + supportFragmentManager.getBackStackEntryCount());
    }
 
Example 4
Source File: FragmentInjectHelper.java    From FriendCircle with GNU General Public License v3.0 6 votes vote down vote up
@Nullable
public static <F extends Fragment> F inject(@NonNull FragmentActivity target,
                                            @NonNull Class<F> fragClass,
                                            @Nullable Bundle arguments,
                                            @Nullable String tag) {
    if (!ActivityUtil.isAlive(target)) return null;
    if (TextUtils.isEmpty(tag)) {
        tag = fragClass.getName();
    }
    FragmentManager fragmentManager = target.getSupportFragmentManager();
    F result = (F) fragmentManager.findFragmentByTag(tag);
    if (result == null) {
        result = (F) fragmentManager.getFragmentFactory().instantiate(fragClass.getClassLoader(), fragClass.getName());
        result.setArguments(arguments);
        fragmentManager.beginTransaction()
                .add(result, tag)
                .commitAllowingStateLoss();
        fragmentManager.executePendingTransactions();
    }
    return result;
}
 
Example 5
Source File: PlotterFragment.java    From Bluefruit_LE_Connect_Android_V2 with MIT License 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    FragmentActivity activity = getActivity();

    switch (item.getItemId()) {
        case R.id.action_help:
            if (activity != null) {
                FragmentManager fragmentManager = activity.getSupportFragmentManager();
                if (fragmentManager != null) {
                    CommonHelpFragment helpFragment = CommonHelpFragment.newInstance(getString(R.string.plotter_help_title), getString(R.string.plotter_help_text));
                    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction()
                            .replace(R.id.contentLayout, helpFragment, "Help");
                    fragmentTransaction.addToBackStack(null);
                    fragmentTransaction.commit();
                }
            }
            return true;

        default:
            return super.onOptionsItemSelected(item);
    }
}
 
Example 6
Source File: MqttSettingsCodeReaderFragment.java    From Bluefruit_LE_Connect_Android_V2 with MIT License 6 votes vote down vote up
@Override
public void onCodeScanned(String contents) {
    Log.d(TAG, "Code Scanned: " + contents);
    if (isCodeAlreadyScanned) {
        return;
    }       // To avoid double scans and pop 2 times the fragment
    isCodeAlreadyScanned = true;

    // Beep
    final ToneGenerator tg = new ToneGenerator(AudioManager.STREAM_NOTIFICATION, 100);
    tg.startTone(ToneGenerator.TONE_PROP_BEEP);

    //
    mListener.onPasswordUpdated(contents);

    // Pop current fragment
    FragmentActivity activity = getActivity();
    if (activity != null) {
        FragmentManager fragmentManager = activity.getSupportFragmentManager();
        fragmentManager.popBackStack();
    }
}
 
Example 7
Source File: ControllerFragment.java    From Bluefruit_LE_Connect_Android_V2 with MIT License 6 votes vote down vote up
@SuppressWarnings("SwitchStatementWithTooFewBranches")
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    FragmentActivity activity = getActivity();

    switch (item.getItemId()) {
        case R.id.action_help:
            if (activity != null) {
                FragmentManager fragmentManager = activity.getSupportFragmentManager();
                CommonHelpFragment helpFragment = CommonHelpFragment.newInstance(getString(R.string.controller_help_title), getString(R.string.controller_help_text_ios_android));
                FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction()
                        .setCustomAnimations(R.anim.slide_in_left, R.anim.slide_out_right, R.anim.slide_in_right, R.anim.slide_out_left)
                        .replace(R.id.contentLayout, helpFragment, "Help");
                fragmentTransaction.addToBackStack(null);
                fragmentTransaction.commit();
            }
            return true;

        default:
            return super.onOptionsItemSelected(item);
    }
}
 
Example 8
Source File: FastMainTabDelegate.java    From FastLib with Apache License 2.0 5 votes vote down vote up
public FastMainTabDelegate(View rootView, FragmentActivity activity, IFastMainView iFastMainView) {
    if (iFastMainView == null || rootView == null || activity == null) {
        return;
    }
    this.mContext = activity;
    this.mObject = activity;
    this.mIFastMainView = iFastMainView;
    mFragmentManager = activity.getSupportFragmentManager();
    mSavedInstanceState = iFastMainView.getSavedInstanceState();
    getTabLayout(rootView);
    getViewPager(rootView);
    initTabLayout();
}
 
Example 9
Source File: SpyglassRobolectricRunner.java    From Spyglass with Apache License 2.0 5 votes vote down vote up
public static void startFragment(Fragment fragment, FragmentActivity activity, String tag) {
    FragmentManager fragmentManager = activity.getSupportFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    fragmentTransaction.add(fragment, tag);
    fragmentTransaction.commit();
    fragmentManager.executePendingTransactions();
    activity.invalidateOptionsMenu();
}
 
Example 10
Source File: DialogUtils.java    From CommonUtils with Apache License 2.0 5 votes vote down vote up
public static void showDialog(@Nullable FragmentActivity activity, @NonNull DialogFragment dialog, @Nullable String tag) {
    if (activity == null) return;

    FragmentManager manager = activity.getSupportFragmentManager();
    try {
        dialog.show(manager, tag);
    } catch (IllegalStateException ex) {
        Log.e(TAG, "Failed showing dialog.", ex); // We can't do nothing
    }
}
 
Example 11
Source File: UIService.java    From Applozic-Android-SDK with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static Fragment getFragmentByTag(FragmentActivity activity, String tag) {
    if (activity == null) {
        return null;
    }
    FragmentManager supportFragmentManager = activity.getSupportFragmentManager();

    if (supportFragmentManager.getBackStackEntryCount() == 0) {
        return null;
    }
    return supportFragmentManager.findFragmentByTag(tag);
}
 
Example 12
Source File: MqttSettingsCodeReaderFragment.java    From Bluefruit_LE_Connect_Android_V2 with MIT License 5 votes vote down vote up
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);

    if (requestCode != RC_HANDLE_CAMERA_PERM) {
        Log.d(TAG, "Got unexpected permission result: " + requestCode);
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        return;
    }

    if (grantResults.length != 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
        Log.d(TAG, "Camera permission granted - initialize the camera source");
        // we have permission, so create the camerasource
        createCameraSource(kAutoFocus, kUseFlash);
        return;
    }

    Log.e(TAG, "Permission not granted: results len = " + grantResults.length +
            " Result code = " + (grantResults.length > 0 ? grantResults[0] : "(empty)"));

    DialogInterface.OnClickListener listener = (dialog, id) -> {
        FragmentActivity activity = getActivity();
        if (activity != null) {
            FragmentManager fragmentManager = activity.getSupportFragmentManager();
            fragmentManager.popBackStack();
        }
    };

    AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
    builder.setMessage(R.string.mqttcodereader_nocamerapermission)
            .setPositiveButton(android.R.string.ok, listener)
            .show();
}
 
Example 13
Source File: ActivityUtils.java    From NGA-CLIENT-VER-OPEN-SOURCE with GNU General Public License v2.0 5 votes vote down vote up
private void notice(String title, String content, Context c) {

        if (c == null)
            return;
        NLog.d(TAG, "saying dialog");
        Bundle b = new Bundle();
        b.putString("title", title);
        b.putString("content", content);
        synchronized (lock) {
            try {

                DialogFragment df = new SayingDialogFragment();
                df.setArguments(b);

                FragmentActivity fa = (FragmentActivity) c;
                FragmentManager fm = fa.getSupportFragmentManager();
                FragmentTransaction ft = fm.beginTransaction();

                Fragment prev = fm.findFragmentByTag(dialogTag);
                if (prev != null) {
                    ft.remove(prev);
                }

                ft.commit();
                df.show(fm, dialogTag);
                this.df = df;
            } catch (Exception e) {
                NLog.e(this.getClass().getSimpleName(), NLog.getStackTraceString(e));

            }

        }

    }
 
Example 14
Source File: MobiComKitPeopleActivity.java    From Applozic-Android-SDK with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static void addFragment(FragmentActivity fragmentActivity, Fragment fragmentToAdd, String fragmentTag) {
    FragmentManager supportFragmentManager = fragmentActivity.getSupportFragmentManager();

    FragmentTransaction fragmentTransaction = supportFragmentManager
            .beginTransaction();
    fragmentTransaction.replace(R.id.layout_child_activity, fragmentToAdd,
            fragmentTag);

    if (supportFragmentManager.getBackStackEntryCount() > 1) {
        supportFragmentManager.popBackStack();
    }
    fragmentTransaction.addToBackStack(fragmentTag);
    fragmentTransaction.commitAllowingStateLoss();
    supportFragmentManager.executePendingTransactions();
}
 
Example 15
Source File: StickerKeyboardProvider.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
public StickerKeyboardProvider(@NonNull FragmentActivity activity,
                               @NonNull StickerEventListener eventListener)
{
  this.context          = activity;
  this.eventListener    = eventListener;
  this.pagerAdapter     = new StickerPagerAdapter(activity.getSupportFragmentManager(), this);
  this.stickerThrottler = new Throttler(100);

  initViewModel(activity);
}
 
Example 16
Source File: BucketDialog.java    From CrazyDaily with Apache License 2.0 4 votes vote down vote up
public void show(FragmentActivity activity) {
    super.show(activity.getSupportFragmentManager(), TAG);
}
 
Example 17
Source File: NoteEditDialog.java    From CrazyDaily with Apache License 2.0 4 votes vote down vote up
public void show(FragmentActivity activity) {
    super.show(activity.getSupportFragmentManager(), TAG);
}
 
Example 18
Source File: FragmentStack.java    From cathode with Apache License 2.0 4 votes vote down vote up
private FragmentStack(FragmentActivity activity, int containerId, Callback callback) {
  this.activity = activity;
  fragmentManager = activity.getSupportFragmentManager();
  this.containerId = containerId;
  this.callback = callback;
}
 
Example 19
Source File: FragmentMaster.java    From FragmentMaster with Apache License 2.0 4 votes vote down vote up
FragmentMaster(FragmentActivity activity) {
    mActivity = activity;
    mFragmentManager = activity.getSupportFragmentManager();
    mEventDispatcher = new MasterEventDispatcher(activity);
}
 
Example 20
Source File: CrazyDailyAlertDialog.java    From CrazyDaily with Apache License 2.0 4 votes vote down vote up
public void show(FragmentActivity activity) {
    super.show(activity.getSupportFragmentManager(), TAG);
}