Example usage for android.app Activity getFragmentManager

List of usage examples for android.app Activity getFragmentManager

Introduction

In this page you can find the example usage for android.app Activity getFragmentManager.

Prototype

@Deprecated
public FragmentManager getFragmentManager() 

Source Link

Document

Return the FragmentManager for interacting with fragments associated with this activity.

Usage

From source file:com.readystatesoftware.ghostlog.GhostLogSettingsFragment.java

private static void setupOpenSourceInfoPreference(final Activity activity, Preference preference) {
    preference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override//  w w w. j  a va  2 s .c  om
        public boolean onPreferenceClick(Preference preference) {
            FragmentManager fm = activity.getFragmentManager();
            FragmentTransaction ft = fm.beginTransaction();
            Fragment prev = fm.findFragmentByTag("dialog");
            if (prev != null) {
                ft.remove(prev);
            }
            ft.addToBackStack(null);
            new OpenSourceLicensesDialog().show(ft, "dialog");
            return true;
        }
    });
}

From source file:com.readystatesoftware.ghostlog.GhostLogSettingsFragment.java

private static void setupVersionPref(final Activity activity, Preference preference) {
    preference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override// w w w.  j  a v a 2s. c o  m
        public boolean onPreferenceClick(Preference preference) {
            FragmentManager fm = activity.getFragmentManager();
            FragmentTransaction ft = fm.beginTransaction();
            Fragment prev = fm.findFragmentByTag("dialog");
            if (prev != null) {
                ft.remove(prev);
            }
            ft.addToBackStack(null);
            new AboutDialog().show(ft, "dialog");
            return true;
        }
    });
}

From source file:io.digibyte.tools.animation.BRAnimator.java

public static void showReceiveFragment(Activity app, boolean isReceive) {
    if (app == null) {
        Log.e(TAG, "showReceiveFragment: app is null");
        return;/* ww  w. ja  v  a2s. c om*/
    }
    FragmentReceive fragmentReceive = (FragmentReceive) app.getFragmentManager()
            .findFragmentByTag(FragmentReceive.class.getName());
    if (fragmentReceive != null && fragmentReceive.isAdded())
        return;
    fragmentReceive = new FragmentReceive();
    Bundle args = new Bundle();
    args.putBoolean("receive", isReceive);
    fragmentReceive.setArguments(args);

    app.getFragmentManager().beginTransaction().setCustomAnimations(0, 0, 0, R.animator.plain_300)
            .add(android.R.id.content, fragmentReceive, FragmentReceive.class.getName())
            .addToBackStack(FragmentReceive.class.getName()).commit();

}

From source file:io.digibyte.tools.animation.BRAnimator.java

public static void showSendFragment(Activity app, final String bitcoinUrl) {
    if (app == null) {
        Log.e(TAG, "showSendFragment: app is null");
        return;//from  w  w w. j  a  v  a 2 s  . c o m
    }
    FragmentSend fragmentSend = (FragmentSend) app.getFragmentManager()
            .findFragmentByTag(FragmentSend.class.getName());
    if (fragmentSend != null && fragmentSend.isAdded()) {
        fragmentSend.setUrl(bitcoinUrl);
        return;
    }
    try {
        fragmentSend = new FragmentSend();
        if (bitcoinUrl != null && !bitcoinUrl.isEmpty()) {
            Bundle bundle = new Bundle();
            bundle.putString("url", bitcoinUrl);
            fragmentSend.setArguments(bundle);
        }
        app.getFragmentManager().beginTransaction().setCustomAnimations(0, 0, 0, R.animator.plain_300)
                .add(android.R.id.content, fragmentSend, FragmentSend.class.getName())
                .addToBackStack(FragmentSend.class.getName()).commit();
    } finally {

    }

}

From source file:org.onepf.opfiab.opfiab_uitest.tests.ui.UnifiedFragmentHelperTest.java

private static void replaceFragment(Activity activity) throws InterruptedException {
    if (activity instanceof FragmentActivity) {
        ((FragmentActivity) activity).getSupportFragmentManager().beginTransaction()
                .replace(R.id.content, SupportTestFragment.getInstance(R.color.red)).addToBackStack(null)
                .commit();//  www. ja va2  s .c o  m

    } else {
        activity.getFragmentManager().beginTransaction()
                .replace(R.id.content, TestFragment.getInstance(R.color.red)).addToBackStack(null).commit();
    }
    Thread.sleep(WAIT_REOPEN_ACTIVITY);
}

From source file:io.digibyte.tools.animation.BRAnimator.java

public static void showTransactionPager(Activity app, List<TxItem> items, int position) {
    if (app == null) {
        Log.e(TAG, "showSendFragment: app is null");
        return;//  w w w  . j  av a  2 s .c  o m
    }
    FragmentTransactionDetails fragmentTransactionDetails = (FragmentTransactionDetails) app
            .getFragmentManager().findFragmentByTag(FragmentTransactionDetails.class.getName());
    if (fragmentTransactionDetails != null && fragmentTransactionDetails.isAdded()) {
        fragmentTransactionDetails.setItems(items);
        Log.e(TAG, "showTransactionPager: Already showing");
        return;
    }
    fragmentTransactionDetails = new FragmentTransactionDetails();
    fragmentTransactionDetails.setItems(items);
    Bundle bundle = new Bundle();
    bundle.putInt("pos", position);
    fragmentTransactionDetails.setArguments(bundle);

    app.getFragmentManager().beginTransaction().setCustomAnimations(0, 0, 0, R.animator.plain_300)
            .add(android.R.id.content, fragmentTransactionDetails, FragmentTransactionDetails.class.getName())
            .addToBackStack(FragmentTransactionDetails.class.getName()).commit();

}

From source file:io.digibyte.tools.animation.BRAnimator.java

public static void showSupportFragment(Activity app, String articleId) {
    if (supportIsShowing)
        return;// w w w.  j a va2s .c om
    supportIsShowing = true;
    if (app == null) {
        Log.e(TAG, "showSupportFragment: app is null");
        return;
    }
    FragmentSupport fragmentSupport = (FragmentSupport) app.getFragmentManager()
            .findFragmentByTag(FragmentSupport.class.getName());
    if (fragmentSupport != null && fragmentSupport.isAdded()) {
        app.getFragmentManager().popBackStack();
        return;
    }
    try {
        fragmentSupport = new FragmentSupport();
        if (articleId != null && !articleId.isEmpty()) {
            Bundle bundle = new Bundle();
            bundle.putString("articleId", articleId);
            fragmentSupport.setArguments(bundle);
        }
        app.getFragmentManager().beginTransaction().setCustomAnimations(0, 0, 0, R.animator.plain_300)
                .add(android.R.id.content, fragmentSupport, FragmentSend.class.getName())
                .addToBackStack(FragmentSend.class.getName()).commit();

    } finally {

    }

}

From source file:io.digibyte.tools.animation.BRAnimator.java

public static void showRequestFragment(Activity app, String address) {
    if (app == null) {
        Log.e(TAG, "showRequestFragment: app is null");
        return;/*ww w . ja  va2s.c  o  m*/
    }
    if (Utils.isNullOrEmpty(address)) {
        Log.e(TAG, "showRequestFragment: address is empty: " + address);
        return;
    }

    FragmentRequestAmount fragmentRequestAmount = (FragmentRequestAmount) app.getFragmentManager()
            .findFragmentByTag(FragmentRequestAmount.class.getName());
    if (fragmentRequestAmount != null && fragmentRequestAmount.isAdded())
        return;

    fragmentRequestAmount = new FragmentRequestAmount();
    Bundle bundle = new Bundle();
    bundle.putString("address", address);
    fragmentRequestAmount.setArguments(bundle);
    app.getFragmentManager().beginTransaction().setCustomAnimations(0, 0, 0, R.animator.plain_300)
            .add(android.R.id.content, fragmentRequestAmount, FragmentRequestAmount.class.getName())
            .addToBackStack(FragmentRequestAmount.class.getName()).commit();

}

From source file:com.aftabsikander.permissionassist.PermissionAssistant.java

/**
 * Request a set of permissions, showing rationale if the system requests it.
 *
 * @param activity       {@link Activity} requesting permissions. Should implement {@link
 *                       ActivityCompat.OnRequestPermissionsResultCallback} or override {@link
 *                       FragmentActivity#onRequestPermissionsResult(int, String[], int[])} if
 *                       it extends from {@link FragmentActivity}.
 * @param rationale      a message explaining why the application needs this set of permissions,
 *                       will be displayed if the user rejects the request the first time.
 * @param positiveButton custom text for positive button
 * @param negativeButton custom text for negative button
 * @param requestCode    request code to track this request, must be < 256.
 * @param perms          a set of permissions to be requested.
 * @see Manifest.permission//from  w  ww.  j a  va 2s  . c o m
 */
@SuppressLint("NewApi")
public static void requestPermissions(@NonNull Activity activity, @NonNull String rationale,
        @StringRes int positiveButton, @StringRes int negativeButton, int requestCode,
        @NonNull String... perms) {
    if (hasPermissions(activity, perms)) {
        notifyAlreadyHasPermissions(activity, requestCode, perms);
        return;
    }

    if (shouldShowRationale(activity, perms)) {
        showRationaleDialogFragment(activity.getFragmentManager(), rationale, positiveButton, negativeButton,
                requestCode, perms);
    } else {
        ActivityCompat.requestPermissions(activity, perms, requestCode);
    }
}

From source file:com.androidexperiments.sprayscape.androidutils.PermissionRequester.java

public static void requestPermission(final String permission, final String objectName,
        final String methodName) {
    Log.i(TAG, "requestPermission() called for permission: " + permission);

    final Activity currentActivity = UnityPlayer.currentActivity;
    boolean granted = ActivityCompat.checkSelfPermission(currentActivity,
            permission) == PackageManager.PERMISSION_GRANTED;

    if (granted) {
        Log.i(TAG, "Permission already granted: " + permission);
        SendPermissionResult(permission, true, objectName, methodName);
        return;//from   w  w w .  ja va2  s. com
    }

    try {
        // use a fragment here because we wouldn't be able to capture onRequestPermissionsResult() on the main activity unless we sub-classed it...
        // final values so the fragment inner-class can access them
        final FragmentManager fragmentManager = currentActivity.getFragmentManager();
        final Fragment request = new Fragment() {

            @Override
            public void onStart() {
                super.onStart();
                Log.i(TAG, "Permission fragment onStart()");
                FragmentCompat.requestPermissions(this, new String[] { permission }, 0);
            }

            @SuppressLint("Override")
            @SuppressWarnings("unused")
            public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
                Log.i(TAG, "onRequestPermissionsResult(" + requestCode + ", " + permissions.toString() + ", "
                        + grantResults.toString() + ")");

                if (grantResults.length > 0) {
                    for (int i = 0; i < grantResults.length; i++) {
                        if (grantResults[i] == PackageManager.PERMISSION_GRANTED) {
                            Log.i(TAG, "Permission granted: " + permissions[i]);
                            SendPermissionResult(permissions[i], true, objectName, methodName);
                        } else {
                            Log.i(TAG, "Permission denied: " + permissions[i]);
                            SendPermissionResult(permissions[i], false, objectName, methodName);
                        }
                    }
                } else {
                    Log.i(TAG, "Permission denied: " + permission);
                    SendPermissionResult(permission, false, objectName, methodName);
                }

                FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
                fragmentTransaction.remove(this);
                fragmentTransaction.commit();
            }
        };

        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.add(0, request);
        fragmentTransaction.commit();
    } catch (Exception error) {
        Log.e(TAG, "Permission request failed: '" + permission + "'", error);
        SendPermissionResult(permission, false, objectName, methodName);
    }
}