Java Code Examples for android.app.FragmentManager#executePendingTransactions()

The following examples show how to use android.app.FragmentManager#executePendingTransactions() . 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: YoutubeOverlayFragment.java    From AndroidYoutubeOverlay with MIT License 6 votes vote down vote up
/**
 * Builds Fragment and adds it to view hierarchy
 * @return returns YoutubeOverlayFragment instance that was added to hierarchy
 */
public YoutubeOverlayFragment buildAndAdd() {
    Preconditions.checkNotNull(activity);
    Preconditions.checkArgument(!Strings.isNullOrEmpty(ytKey));
    Preconditions.checkArgument(scrollableViewId != 0);

    FragmentManager fragmentManager = activity.getFragmentManager();
    View scrollableView = activity.findViewById(scrollableViewId);
    YoutubeOverlayFragment yt = (YoutubeOverlayFragment) fragmentManager.findFragmentByTag(YoutubeOverlayFragment.class.getName());
    if (yt != null) {
        fragmentManager.beginTransaction().remove(yt).commit();
        fragmentManager.executePendingTransactions();
    }
    yt = new YoutubeOverlayFragment();
    Bundle bundle = new Bundle();
    bundle.putIntArray(YoutubeOverlayFragment.HIDEABLE_VIEWS, Ints.toArray(hideableViews));
    bundle.putString(YoutubeOverlayFragment.YT_DEVELOPER_KEY, ytKey);
    bundle.putInt(SCROLLABLE_VIEW_ID, scrollableViewId);
    yt.setArguments(bundle);
    fragmentManager.beginTransaction().add(((View) scrollableView.getParent()).getId(), yt, YoutubeOverlayFragment.class.getName()).commit();
    return yt;
}
 
Example 2
Source File: DirectoryChooserFragmentTest.java    From droid-stealth with GNU General Public License v2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static void startFragment(@Nonnull Fragment fragment, @Nullable Class activityClass) {
	if (activityClass == null) {
		activityClass = Activity.class;
	}

	Activity activity = Robolectric.buildActivity(activityClass)
			.create()
			.start()
			.resume()
			.get();

	FragmentManager fragmentManager = activity.getFragmentManager();
	FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
	fragmentTransaction.add(R.id.main, fragment);
	fragmentTransaction.commit();

	fragmentManager.executePendingTransactions();
}
 
Example 3
Source File: DirectoryChooserFragmentTest.java    From Android-DirectoryChooser with Apache License 2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static void startFragment(@NonNull final Fragment fragment, @Nullable Class activityClass) {
    final Activity activity = (Activity) Robolectric
            .buildActivity(activityClass == null ? Activity.class : activityClass)
            .create()
            .start()
            .resume()
            .get();

    final FragmentManager fragmentManager = activity.getFragmentManager();
    final FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    fragmentTransaction.add(R.id.main, fragment);
    fragmentTransaction.commit();

    fragmentManager.executePendingTransactions();
}
 
Example 4
Source File: Utility.java    From scene with Apache License 2.0 5 votes vote down vote up
public static void commitFragment(@NonNull FragmentManager fragmentManager, @NonNull FragmentTransaction transaction, boolean commitNow) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        if (commitNow) {
            transaction.commitNowAllowingStateLoss();
        } else {
            transaction.commitAllowingStateLoss();
        }
    } else {
        transaction.commitAllowingStateLoss();
        if (commitNow) {
            fragmentManager.executePendingTransactions();
        }
    }
}
 
Example 5
Source File: WindowCapture.java    From ViewCapture with Apache License 2.0 5 votes vote down vote up
private WindowCaptureFragment getWindowCaptureFragment(@NonNull Activity activity) {
    WindowCaptureFragment windowCaptureFragment = findScreenCaptureFragment(activity);
    boolean isNewInstance = windowCaptureFragment == null;
    if (isNewInstance) {
        windowCaptureFragment = new WindowCaptureFragment();
        FragmentManager fragmentManager = activity.getFragmentManager();
        fragmentManager.beginTransaction().add(windowCaptureFragment, TAG).commitAllowingStateLoss();
        fragmentManager.executePendingTransactions();
    }
    return windowCaptureFragment;
}
 
Example 6
Source File: LinphoneActivity.java    From Linphone4Android with GNU General Public License v3.0 5 votes vote down vote up
private void changeFragment(Fragment newFragment, FragmentsAvailable newFragmentType, boolean withoutAnimation) {
	FragmentManager fm = getFragmentManager();
	FragmentTransaction transaction = fm.beginTransaction();

	/*if (!withoutAnimation && !isAnimationDisabled && currentFragment.shouldAnimate()) {
		if (newFragmentType.isRightOf(currentFragment)) {
			transaction.setCustomAnimations(R.anim.slide_in_right_to_left,
					R.anim.slide_out_right_to_left,
					R.anim.slide_in_left_to_right,
					R.anim.slide_out_left_to_right);
		} else {
			transaction.setCustomAnimations(R.anim.slide_in_left_to_right,
					R.anim.slide_out_left_to_right,
					R.anim.slide_in_right_to_left,
					R.anim.slide_out_right_to_left);
		}
	}*/

	if (newFragmentType != FragmentsAvailable.DIALER
			&& newFragmentType != FragmentsAvailable.CONTACTS_LIST
			&& newFragmentType != FragmentsAvailable.CHAT_LIST
			&& newFragmentType != FragmentsAvailable.HISTORY_LIST) {
		transaction.addToBackStack(newFragmentType.toString());
	} else {
		while (fm.getBackStackEntryCount() > 0) {
			fm.popBackStackImmediate(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
		}
	}

	transaction.replace(R.id.fragmentContainer, newFragment, newFragmentType.toString());
	transaction.commitAllowingStateLoss();
	fm.executePendingTransactions();

	currentFragment = newFragmentType;
}
 
Example 7
Source File: AvoidOnResult.java    From AvoidOnResult with Apache License 2.0 5 votes vote down vote up
private AvoidOnResultFragment getAvoidOnResultFragment(Activity activity) {
    AvoidOnResultFragment avoidOnResultFragment = findAvoidOnResultFragment(activity);
    if (avoidOnResultFragment == null) {
        avoidOnResultFragment = new AvoidOnResultFragment();
        FragmentManager fragmentManager = activity.getFragmentManager();
        fragmentManager
                .beginTransaction()
                .add(avoidOnResultFragment, TAG)
                .commitAllowingStateLoss();
        fragmentManager.executePendingTransactions();
    }
    return avoidOnResultFragment;
}
 
Example 8
Source File: RxPermissions.java    From AndroidProjects with MIT License 5 votes vote down vote up
private RxPermissionsFragment getRxPermissionsFragment(Activity activity) {
    RxPermissionsFragment rxPermissionsFragment = findRxPermissionsFragment(activity);
    boolean isNewInstance = rxPermissionsFragment == null;
    if (isNewInstance) {
        rxPermissionsFragment = new RxPermissionsFragment();
        FragmentManager fragmentManager = activity.getFragmentManager();
        fragmentManager
                .beginTransaction()
                .add(rxPermissionsFragment, TAG)
                .commitAllowingStateLoss();
        fragmentManager.executePendingTransactions();
    }
    return rxPermissionsFragment;
}
 
Example 9
Source File: RxPermissions.java    From GankGirl with GNU Lesser General Public License v2.1 5 votes vote down vote up
private RxPermissionsFragment getRxPermissionsFragment(Activity activity) {
    RxPermissionsFragment rxPermissionsFragment = findRxPermissionsFragment(activity);
    boolean isNewInstance = rxPermissionsFragment == null;
    if (isNewInstance) {
        rxPermissionsFragment = new RxPermissionsFragment();
        FragmentManager fragmentManager = activity.getFragmentManager();
        fragmentManager
                .beginTransaction()
                .add(rxPermissionsFragment, TAG)
                .commit();
        fragmentManager.executePendingTransactions();
    }
    return rxPermissionsFragment;
}
 
Example 10
Source File: ActResultRequest.java    From MNUpdateAPK with GNU General Public License v3.0 5 votes vote down vote up
private OnActResultEventDispatcherFragment getEventDispatchFragment(Activity activity) {
    final FragmentManager fragmentManager = activity.getFragmentManager();

    OnActResultEventDispatcherFragment fragment = findEventDispatchFragment(fragmentManager);
    if (fragment == null) {
        fragment = new OnActResultEventDispatcherFragment();
        fragmentManager
                .beginTransaction()
                .add(fragment, OnActResultEventDispatcherFragment.TAG)
                .commitAllowingStateLoss();
        fragmentManager.executePendingTransactions();
    }
    return fragment;
}
 
Example 11
Source File: BaseRestoreInstanceFragment.java    From Material-SearchView with Apache License 2.0 5 votes vote down vote up
public void show(@NonNull final FragmentManager manager) {
    FragmentTransaction transaction = manager.beginTransaction();
    Fragment prev = manager.findFragmentByTag(DIALOG_TAG);
    if (prev != null) {
        transaction.remove(prev);
    }

    transaction.add(this, DIALOG_TAG);
    transaction.commitAllowingStateLoss();
    manager.executePendingTransactions();
}
 
Example 12
Source File: MainUIActivity.java    From MiBandDecompiled with Apache License 2.0 5 votes vote down vote up
private void b()
{
    FragmentManager fragmentmanager = getFragmentManager();
    FragmentTransaction fragmenttransaction = fragmentmanager.beginTransaction();
    a = (DynamicFragment)Fragment.instantiate(this, cn/com/smartdevices/bracelet/ui/DynamicFragment.getName());
    fragmenttransaction.add(0x7f0a01bf, a, "DynamicFragment");
    fragmenttransaction.commit();
    fragmentmanager.executePendingTransactions();
    p();
    r();
    I = LuaEvent.getInstance(this);
    c();
    aa = findViewById(0x7f0a01b9);
    k = findViewById(0x7f0a01ba);
}
 
Example 13
Source File: EnvelopesActivity.java    From budget-envelopes with GNU General Public License v3.0 5 votes vote down vote up
public void topFragment(Class<?> cls, int transition, Bundle args) {
    Fragment frag = Fragment.instantiate(
        this,
        cls.getName(),
        args
    );
    FragmentManager fragmentManager = getFragmentManager();
    fragmentManager.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
    fragmentManager.beginTransaction()
     .replace(R.id.content_frame, frag)
     .setTransition(transition)
     .commit();
    fragmentManager.executePendingTransactions();
    configureFragment(frag);
}
 
Example 14
Source File: EnvelopesActivity.java    From budget-envelopes with GNU General Public License v3.0 5 votes vote down vote up
public void switchFragment(Class<?> cls, String name, Bundle args) {
    Fragment frag = Fragment.instantiate(
        this,
        cls.getName(),
        args
    );
    FragmentManager fragmentManager = getFragmentManager();
    fragmentManager.beginTransaction()
     .replace(R.id.content_frame, frag)
     .addToBackStack(name)
     .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
     .commit();
    fragmentManager.executePendingTransactions();
    configureFragment(frag);
}
 
Example 15
Source File: MainActivity.java    From linphone-android with GNU General Public License v3.0 4 votes vote down vote up
protected void changeFragment(Fragment fragment, String name, boolean isChild) {
    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction transaction = fragmentManager.beginTransaction();

    if (transaction.isAddToBackStackAllowed()) {
        int count = fragmentManager.getBackStackEntryCount();
        if (count > 0) {
            FragmentManager.BackStackEntry entry =
                    fragmentManager.getBackStackEntryAt(count - 1);

            if (entry != null && name.equals(entry.getName())) {
                fragmentManager.popBackStack();
                if (!isChild) {
                    // We just removed it's duplicate from the back stack
                    // And we want at least one in it
                    transaction.addToBackStack(name);
                }
            }
        }

        if (isChild) {
            transaction.addToBackStack(name);
        }
    }

    if (getResources().getBoolean(R.bool.hide_bottom_bar_on_second_level_views)) {
        if (isChild) {
            if (!isTablet()) {
                hideTabBar();
            }
        } else {
            showTabBar();
        }
    }

    Compatibility.setFragmentTransactionReorderingAllowed(transaction, false);
    if (isChild && isTablet()) {
        transaction.replace(R.id.fragmentContainer2, fragment, name);
        findViewById(R.id.fragmentContainer2).setVisibility(View.VISIBLE);
    } else {
        transaction.replace(R.id.fragmentContainer, fragment, name);
    }
    transaction.commitAllowingStateLoss();
    fragmentManager.executePendingTransactions();
}
 
Example 16
Source File: RssfeedActivity.java    From codeexamples-android with Eclipse Public License 1.0 3 votes vote down vote up
private void showDetailFragment(int containerId, String rssItemUrl, boolean addToBackStack) {
	
	// find detail fragment first
	FragmentManager fm = getFragmentManager();
	RssfeedDetailFragment detailFragment =
			(RssfeedDetailFragment) fm.findFragmentByTag(TAG_DETAIL);

	if (detailFragment == null) {
		// create new detail fragment
		detailFragment = RssfeedDetailFragment.instantiate(rssItemUrl);
		
		// add fragment to the layout
		addDetailFragment(detailFragment, containerId, addToBackStack, fm);
		
	} else if (detailFragment.getId() != containerId) {
			
		// remove fragment from old container
		fm.beginTransaction().remove(detailFragment).commit();
		fm.executePendingTransactions();
		
		// add fragment to the new container
		addDetailFragment(detailFragment, containerId, addToBackStack, fm);
		
	} // else, fragment is already at the right place
	
	detailFragment.setUrl(rssItemUrl);
	
}