Example usage for android.app FragmentTransaction commit

List of usage examples for android.app FragmentTransaction commit

Introduction

In this page you can find the example usage for android.app FragmentTransaction commit.

Prototype

public abstract int commit();

Source Link

Document

Schedules a commit of this transaction.

Usage

From source file:com.aoppp.gatewaymaster.dialogs.DialogUtil.java

/**
 * ??Fragment./*from   w ww .  ja v  a 2s . co  m*/
 * 
 * @param context
 *            the context
 */
public static void removeDialog(Context context) {
    try {
        FragmentActivity activity = (FragmentActivity) context;
        FragmentTransaction ft = activity.getFragmentManager().beginTransaction();
        // 
        ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_CLOSE);
        Fragment prev = activity.getFragmentManager().findFragmentByTag(mDialogTag);
        if (prev != null) {
            ft.remove(prev);
        }
        ft.addToBackStack(null);
        ft.commit();
    } catch (Exception e) {
        // ?Activity??
        e.printStackTrace();
    }
}

From source file:com.poloure.simplerss.Utilities.java

private static void switchToFragment(Fragment fragment, boolean addToBackStack) {
    if (fragment.isHidden()) {
        Fragment[] fragments = { s_fragmentFavourites, s_fragmentManage, s_fragmentFeeds, s_fragmentSettings };
        FragmentTransaction transaction = s_fragmentManager.beginTransaction();

        for (Fragment frag : fragments) {
            if (frag.isVisible()) {
                transaction.hide(frag);/*from w  w  w . j  a  v a2 s  .c  o  m*/
            }
        }
        transaction.show(fragment);
        if (addToBackStack) {
            transaction.addToBackStack(null);

            // Set the default transition for adding to the stack.
            transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
        }
        transaction.commit();
        s_fragmentManager.executePendingTransactions();
        fragment.getActivity().invalidateOptionsMenu();
    }
}

From source file:com.google.games.bridge.TokenFragment.java

/**
 * External entry point for getting tokens and email address.  This
 * creates the fragment if needed and queues up the request.  The fragment, once
 * active processes the list of requests.
 *
 * @param parentActivity   - the activity to attach the fragment to.
 * @param rationale        - the rationale to display when requesting permission.
 * @param fetchEmail       - true indicates get the email.
 * @param fetchAccessToken - true indicates get the access token.
 * @param fetchIdToken     - true indicates get the id token.
 * @param scope            - the scope for getting the id token.
 * @return PendingResult for retrieving the results when ready.
 *//*from  w w  w .j ava 2s.  co  m*/
public static PendingResult fetchToken(Activity parentActivity, String rationale, boolean fetchEmail,
        boolean fetchAccessToken, boolean fetchIdToken, String scope) {
    TokenRequest request = new TokenRequest(fetchEmail, fetchAccessToken, fetchIdToken, scope);
    request.setRationale(rationale);
    synchronized (pendingTokenRequests) {
        pendingTokenRequests.add(request);
    }

    TokenFragment fragment = (TokenFragment) parentActivity.getFragmentManager()
            .findFragmentByTag(FRAGMENT_TAG);

    if (fragment == null) {
        try {
            Log.d(TAG, "Creating fragment");
            fragment = new TokenFragment();
            FragmentTransaction trans = parentActivity.getFragmentManager().beginTransaction();
            trans.add(fragment, FRAGMENT_TAG);
            trans.commit();
        } catch (Throwable th) {
            Log.e(TAG, "Cannot launch token fragment:" + th.getMessage(), th);
            request.setResult(CommonStatusCodes.ERROR);
            synchronized (pendingTokenRequests) {
                pendingTokenRequests.remove(request);
            }
        }
    } else {
        Log.d(TAG, "Fragment exists.. calling processRequests");
        fragment.processRequests(CommonStatusCodes.SUCCESS);
    }

    return request.getPendingResponse();
}

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

public static void showMenuFragment(Activity app) {
    if (app == null) {
        Log.e(TAG, "showReceiveFragment: app is null");
        return;/*from  w  w  w  .  j  a va2  s.c o  m*/
    }
    FragmentTransaction transaction = app.getFragmentManager().beginTransaction();
    transaction.setCustomAnimations(0, 0, 0, R.animator.plain_300);
    transaction.add(android.R.id.content, new FragmentMenu(), FragmentMenu.class.getName());
    transaction.addToBackStack(FragmentMenu.class.getName());
    transaction.commit();

}

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

public static void showGreetingsMessage(Activity app) {
    if (app == null) {
        Log.e(TAG, "showGreetingsMessage: app is null");
        return;// www  . j  a  va 2  s. co  m
    }
    FragmentTransaction transaction = app.getFragmentManager().beginTransaction();
    transaction.setCustomAnimations(0, 0, 0, R.animator.plain_300);
    transaction.add(android.R.id.content, new FragmentGreetings(), FragmentGreetings.class.getName());
    transaction.addToBackStack(FragmentGreetings.class.getName());
    transaction.commit();

}

From source file:com.breadwallet.tools.animation.BRAnimator.java

public static void animateSlideToRight(final MainActivity context) {
    try {//from  w  w  w  .j a v  a2 s .  c o m
        if (!checkTheHorizontalSlideAvailability())
            return;
        final Fragment tmp = previous.pop();
        level--;
        if (level < 1)
            context.setBurgerButtonImage(BRConstants.BURGER);
        if (level == 1)
            context.setBurgerButtonImage(BRConstants.CLOSE);
        FragmentTransaction fragmentTransaction = context.getFragmentManager().beginTransaction();
        fragmentTransaction.replace(R.id.main_layout, tmp, tmp.getClass().getName());
        fragmentTransaction.commit();
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                TranslateAnimation trans = new TranslateAnimation(-MainActivity.screenParametersPoint.x, 0, 0,
                        0);
                trans.setDuration(horizontalSlideDuration);
                trans.setInterpolator(new DecelerateOvershootInterpolator(1f, 0.5f));
                View view = tmp.getView();
                if (view != null)
                    view.startAnimation(trans);
            }
        }, 1);
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:com.breadwallet.tools.animation.BRAnimator.java

/**
 * Animate the transition on wipe wallet fragment
 *//*from  w w  w.  j  a va2s  . c  om*/

public static void pressWipeWallet(final MainActivity context, final Fragment to) {
    try {
        if (!wipeWalletOpen) {
            wipeWalletOpen = true;
            FragmentTransaction fragmentTransaction = context.getFragmentManager().beginTransaction();
            fragmentTransaction.replace(R.id.main_layout, to, to.getClass().getName());
            fragmentTransaction.commit();
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    TranslateAnimation trans = new TranslateAnimation(0, 0, 1920, 0);
                    trans.setDuration(500);
                    trans.setInterpolator(new DecelerateOvershootInterpolator(3f, 0.5f));
                    View view = to.getView();
                    if (view != null)
                        view.startAnimation(trans);
                }
            }, 1);

        } else {
            wipeWalletOpen = false;
            FragmentTransaction fragmentTransaction = context.getFragmentManager().beginTransaction();
            fragmentTransaction.setCustomAnimations(R.animator.from_top, R.animator.to_bottom);
            fragmentTransaction.replace(R.id.main_layout, new FragmentSettings(),
                    FragmentSettings.class.getName());
            fragmentTransaction.commit();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

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

public static void showBreadSignal(Activity activity, String title, String iconDescription, int drawableId,
        BROnSignalCompletion completion) {
    fragmentSignal = new FragmentSignal();
    Bundle bundle = new Bundle();
    bundle.putString(FragmentSignal.TITLE, title);
    bundle.putString(FragmentSignal.ICON_DESCRIPTION, iconDescription);
    fragmentSignal.setCompletion(completion);
    bundle.putInt(FragmentSignal.RES_ID, drawableId);
    fragmentSignal.setArguments(bundle);
    FragmentTransaction transaction = activity.getFragmentManager().beginTransaction();
    transaction.setCustomAnimations(R.animator.from_bottom, R.animator.to_bottom, R.animator.from_bottom,
            R.animator.to_bottom);/*from  w w w  . j  av  a2s  .  c  om*/
    transaction.add(android.R.id.content, fragmentSignal, fragmentSignal.getClass().getName());
    transaction.addToBackStack(null);
    if (!activity.isDestroyed())
        transaction.commit();
}

From source file:com.breadwallet.tools.animation.BRAnimator.java

/**
 * Animates the fragment transition on button_regular_blue "Settings" pressed
 *///from w  ww . j av a2  s . c o m
public static void animateSlideToLeft(final MainActivity context, final Fragment to,
        Fragment previousFragment) {
    try {
        if (!checkTheHorizontalSlideAvailability())
            return;
        level++;
        if (level > 1)
            context.setBurgerButtonImage(BRConstants.BACK);
        FragmentTransaction fragmentTransaction = context.getFragmentManager().beginTransaction();
        fragmentTransaction.replace(R.id.main_layout, to, to.getClass().getName());
        if (previousFragment != null)
            previous.add(previousFragment);
        fragmentTransaction.commit();
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                TranslateAnimation trans = new TranslateAnimation(MainActivity.screenParametersPoint.x, 0, 0,
                        0);
                trans.setDuration(horizontalSlideDuration);
                trans.setInterpolator(new DecelerateOvershootInterpolator(1f, 0.5f));
                View view = to.getView();
                if (view != null)
                    view.startAnimation(trans);
            }
        }, 1);
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:com.breadwallet.tools.animation.BRAnimator.java

public static void animateScanResultFragment() {
    try {//from   ww  w .  j  ava2  s . c o  m
        final MainActivity app = MainActivity.app;
        if (app == null || scanResultFragmentOn)
            return;
        CustomPagerAdapter.adapter.showFragments(false, app);
        scanResultFragmentOn = true;
        InputMethodManager keyboard = (InputMethodManager) app.getSystemService(Context.INPUT_METHOD_SERVICE);

        try {
            keyboard.hideSoftInputFromWindow(
                    CustomPagerAdapter.adapter.mainFragment.addressEditText.getWindowToken(), 0);
        } catch (Exception e) {
            e.printStackTrace();
        }
        app.setBurgerButtonImage(BRConstants.BACK);
        //Disabled inspection: <Expected resource type anim>
        final FragmentManager fragmentManager = app.getFragmentManager();
        final FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

        final FragmentScanResult scanResult = new FragmentScanResult();
        fragmentTransaction.replace(R.id.main_layout, scanResult, FragmentScanResult.class.getName());
        fragmentTransaction.commit();
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                TranslateAnimation trans = new TranslateAnimation(MainActivity.screenParametersPoint.x, 0, 0,
                        0);
                trans.setDuration(500);
                trans.setInterpolator(new DecelerateOvershootInterpolator(3f, 0.5f));
                View view = scanResult.getView();
                if (view != null)
                    view.startAnimation(trans);
            }
        }, 1);
    } catch (Exception e) {
        e.printStackTrace();
    }
}