Back to project page android-component-location.
The source code is released under:
MIT License
If you think the Android project android-component-location listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.yingchn.android.util; /*w ww. j av a 2 s . c o m*/ import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentTransaction; import com.yingchn.android.activity.ArbitraryFragmentActivity; import com.yingchn.android.location.R; public class FragmentUtil { public static final String ARGUMENTS_KEY_NO_BACK_STACK = "noBackStack"; public static void removeAndAddSelf(FragmentManager fragmentManager, int layoutId, Fragment paramFragment1, Bundle paramBundle) { FragmentTransaction transaction = fragmentManager.beginTransaction(); transaction.remove(paramFragment1); transaction.commit(); fragmentManager.executePendingTransactions(); transaction = fragmentManager.beginTransaction(); paramFragment1.setArguments(paramBundle); transaction.add(layoutId, paramFragment1); transaction.commit(); fragmentManager.executePendingTransactions(); } public static void detachAndAdd(FragmentManager fragmentManager, int layoutId, Fragment paramFragment1, Fragment paramFragment2, Bundle paramBundle) { FragmentTransaction transaction = fragmentManager.beginTransaction(); paramFragment2.setArguments(paramBundle); transaction.detach(paramFragment1); transaction.add(layoutId, paramFragment2); transaction.commit(); fragmentManager.executePendingTransactions(); } public static void navigateTo(FragmentManager fragmentManager, int layoutId, Fragment paramFragment, Bundle paramBundle) { FragmentTransaction transaction = fragmentManager.beginTransaction(); if ((paramBundle != null) && (paramBundle.getBoolean(ARGUMENTS_KEY_NO_BACK_STACK))) paramBundle.remove(ARGUMENTS_KEY_NO_BACK_STACK); transaction.setCustomAnimations(R.anim.push_left_in, R.anim.push_left_out, R.anim.push_right_in, R.anim.right_out); paramFragment.setArguments(paramBundle); transaction.replace(layoutId, paramFragment); transaction.addToBackStack(null); transaction.commit(); fragmentManager.executePendingTransactions(); } public static void navigateTo(FragmentManager fragmentManager, int layoutId, Fragment paramFragment, String paramString, Bundle paramBundle) { FragmentTransaction transaction = fragmentManager.beginTransaction(); transaction.setCustomAnimations(R.anim.push_left_in, R.anim.push_left_out, R.anim.push_right_in, R.anim.right_out); paramFragment.setArguments(paramBundle); transaction.replace(layoutId, paramFragment); transaction.addToBackStack(paramString); transaction.commit(); fragmentManager.executePendingTransactions(); } public static void navigateToInNewActivity(Activity activity, Fragment paramFragment, Bundle paramBundle) { Intent localIntent = new Intent(activity, ArbitraryFragmentActivity.class); localIntent.putExtra( ArbitraryFragmentActivity.INTENT_PARAMS_FRAGMENT_NAME, paramFragment.getClass().getName()); localIntent.putExtra(ArbitraryFragmentActivity.INTENT_PARAMS_BUNDLE, paramBundle); activity.startActivity(localIntent); } public static void navigateToInNewActivityForResult(Fragment fragment, int requestCode, Fragment paramFragment, Bundle paramBundle) { Intent localIntent = new Intent(fragment.getActivity(), ArbitraryFragmentActivity.class); localIntent.putExtra( ArbitraryFragmentActivity.INTENT_PARAMS_FRAGMENT_NAME, paramFragment.getClass().getName()); localIntent.putExtra(ArbitraryFragmentActivity.INTENT_PARAMS_BUNDLE, paramBundle); fragment.startActivityForResult(localIntent, requestCode); } public static void removeAndAdd(FragmentManager fragmentManager, int layoutId, Fragment paramFragment1, Fragment paramFragment2, Bundle paramBundle) { FragmentTransaction transaction = fragmentManager.beginTransaction(); paramFragment2.setArguments(paramBundle); transaction.remove(paramFragment1); transaction.add(layoutId, paramFragment2); transaction.commit(); fragmentManager.executePendingTransactions(); } public static void replaceFragment(FragmentManager fragmentManager, int layoutId, Fragment paramFragment, Bundle paramBundle) { FragmentTransaction transaction = fragmentManager.beginTransaction(); paramFragment.setArguments(paramBundle); transaction.replace(layoutId, paramFragment); transaction.commit(); fragmentManager.executePendingTransactions(); } }