Java Code Examples for android.support.v4.app.FragmentTransaction#setTransition()

The following examples show how to use android.support.v4.app.FragmentTransaction#setTransition() . 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: RMBTMainActivity.java    From open-rmbt with Apache License 2.0 6 votes vote down vote up
/**
 * 
 * @param popStack
 */
public void showHistory(final boolean popStack)
{
	popBackStackFull();

    FragmentTransaction ft;
    ft = fm.beginTransaction();
    
    ft.replace(R.id.fragment_content, new RMBTHistoryFragment(), AppConstants.PAGE_TITLE_HISTORY);
    ft.addToBackStack(AppConstants.PAGE_TITLE_HISTORY);
    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
    if (popStack) {
    	fm.popBackStack();
    }
    
    ft.commit();
    
    refreshActionBar(AppConstants.PAGE_TITLE_HISTORY);
}
 
Example 2
Source File: ListContentFragment.java    From BatteryFu with GNU General Public License v2.0 6 votes vote down vote up
public void setContent(Fragment content) {
    Fragment last = mCurrentContent;
    mCurrentContent = content;
    FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
    if (last != null)
        ft.replace(R.id.content, mCurrentContent);
    else
        ft.add(R.id.content, mCurrentContent);
    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
    if (mContainer instanceof ViewSwitcher) {
        ViewSwitcher switcher = (ViewSwitcher)mContainer;
        if (mContent != switcher.getCurrentView())
            switcher.showNext();
    }
    ft.commit();
}
 
Example 3
Source File: MainActivity.java    From Focus with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 添加或者显示 fragment
 *
 * @param transaction
 * @param fragment
 */
private void addOrShowFragment(FragmentTransaction transaction, Fragment fragment) {
    transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);

    //当前的fragment就是点击切换的目标fragment,则不用操作
    if (currentFragment == fragment) {
        return;
    }

    Fragment willCloseFragment = currentFragment;//上一个要切换掉的碎片
    currentFragment = fragment;//当前要显示的碎片

    if (willCloseFragment != null) {
        transaction.hide(willCloseFragment);
    }
    if (!fragment.isAdded()) { // 如果当前fragment未被添加,则添加到Fragment管理器中
        transaction.add(R.id.fl_main_body, currentFragment).commitAllowingStateLoss();
    } else {
        transaction.show(currentFragment).commitAllowingStateLoss();
    }
}
 
Example 4
Source File: RMBTMainActivity.java    From open-rmbt with Apache License 2.0 6 votes vote down vote up
public void showHelp(final String url, boolean popBackStack, String titleId)
{
	if (popBackStack) {
		popBackStackFull();
	}
    
	FragmentTransaction ft;
	
    
    ft = fm.beginTransaction();
    
    final Fragment fragment = new RMBTHelpFragment();        
    final Bundle args = new Bundle();
        
    args.putString(RMBTHelpFragment.ARG_URL, url);
    fragment.setArguments(args);
    ft.replace(R.id.fragment_content, fragment, titleId);
    ft.addToBackStack(titleId);
    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);

    ft.commit();
    refreshActionBar(titleId);
}
 
Example 5
Source File: ManageOptionFragmentHandler.java    From mobikul-standalone-pos with MIT License 6 votes vote down vote up
public void saveOptionToProduct(Product product, boolean isEdit) {
    List<Options> optionsList = new ArrayList<>();
    optionsList.addAll(product.getOptions());
    for (Options options : optionsList) {
        for (OptionValues optionValues : options.getOptionValues()) {
            if (optionValues.isSelected()) {
                options.setSelected(optionValues.isSelected());
                break;
            }
            options.setSelected(optionValues.isSelected());
        }
    }

    product.setOptions(optionsList);
    Fragment fragment = ((BaseActivity) context).mSupportFragmentManager.findFragmentByTag(ManageOptionValuesFragment.class.getSimpleName());
    FragmentTransaction ft = ((BaseActivity) context).mSupportFragmentManager.beginTransaction();
    ft.detach(fragment);
    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_CLOSE);
    ft.commit();
    ((BaseActivity) context).mSupportFragmentManager.popBackStackImmediate();
}
 
Example 6
Source File: ManageCategoriesFragmentHandler.java    From mobikul-standalone-pos with MIT License 6 votes vote down vote up
public void saveCategoryToProduct(Product product, boolean isEdit) {
    if (categoryHashMap != null) {
        Iterator iterator = categoryHashMap.keySet().iterator();
        List<ProductCategoryModel> productCategories = new ArrayList<>();
        while (iterator.hasNext()) {
            String key = (String) iterator.next();
            Category value = categoryHashMap.get(key);
            ProductCategoryModel data = new ProductCategoryModel();
            data.setcId(value.getCId() + "");
            data.setName(value.getCategoryName() + "");
            productCategories.add(data);
        }
        if (product != null)
            product.setProductCategories(productCategories);
        Fragment fragment = ((BaseActivity) context).mSupportFragmentManager.findFragmentByTag(ManageCategoriesFragment.class.getSimpleName());
        FragmentTransaction ft = ((BaseActivity) context).mSupportFragmentManager.beginTransaction();
        ft.detach(fragment);
        ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_CLOSE);
        ft.commit();
        ((BaseActivity) context).mSupportFragmentManager.popBackStackImmediate();
    }
}
 
Example 7
Source File: MainActivity.java    From 4pdaClient-plus with Apache License 2.0 5 votes vote down vote up
public void hideFragments(FragmentTransaction transaction, boolean withAnimation) {
    if (getSupportFragmentManager().getFragments() == null) return;
    if (withAnimation)
        transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_CLOSE);
    else
        transaction.setTransition(FragmentTransaction.TRANSIT_NONE);
    for (Fragment fr : getSupportFragmentManager().getFragments()) {
        if (fr != null) {
            if (fr.isVisible())
                fr.onPause();
            transaction.hide(fr);
        }
    }
}
 
Example 8
Source File: FragmentStackFragmentSupport.java    From V.FlyoutTest with MIT License 5 votes vote down vote up
void addFragmentToStack() {
    mStackLevel++;

    // Instantiate a new fragment.
    Fragment newFragment = FragmentStackSupport.CountingFragment.newInstance(mStackLevel);

    // Add the fragment to the activity, pushing this transaction
    // on to the back stack.
    FragmentTransaction ft = getChildFragmentManager().beginTransaction();
    ft.replace(R.id.simple_fragment, newFragment);
    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
    ft.addToBackStack(null);
    ft.commit();
}
 
Example 9
Source File: RMBTMainActivity.java    From open-rmbt with Apache License 2.0 5 votes vote down vote up
public void showAbout() {
	popBackStackFull();

    FragmentTransaction ft;
    ft = fm.beginTransaction();
    
    ft.replace(R.id.fragment_content, new RMBTAboutFragment(), AppConstants.PAGE_TITLE_ABOUT);
    ft.addToBackStack(AppConstants.PAGE_TITLE_ABOUT);
    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);        	
    
    ft.commit();
    refreshActionBar(AppConstants.PAGE_TITLE_ABOUT);
}
 
Example 10
Source File: EasyIntroCarouselFragment.java    From EasyIntro with Apache License 2.0 5 votes vote down vote up
@Override
public void withOverlaySlide(Fragment slide, @IdRes int container, FragmentManager fragmentManager, @AnimRes int enter, @AnimRes int exit, @AnimRes int popEnter, @AnimRes int popExit, View sharedElement, String transitionName, boolean addToBackStack) {
    FragmentTransaction transaction = fragmentManager.beginTransaction();
    // add to back stack
    if (addToBackStack) {
        transaction.addToBackStack(null);
    }
    transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
    transaction.setCustomAnimations(enter, exit, popEnter, popExit);
    if (sharedElement != null) {
        transaction.addSharedElement(sharedElement, transitionName);
    }
    transaction.replace(container, slide).commit();
}
 
Example 11
Source File: PreferenceActivity.java    From PreferenceFragment with Apache License 2.0 5 votes vote down vote up
private void switchToHeaderInner(String fragmentName, Bundle args, int direction) {
    getSupportFragmentManager().popBackStack(BACK_STACK_PREFS,
            FragmentManager.POP_BACK_STACK_INCLUSIVE);
    if (!isValidFragment(fragmentName)) {
        throw new IllegalArgumentException("Invalid fragment for this activity: "
                + fragmentName);
    }
    Fragment f = Fragment.instantiate(this, fragmentName, args);
    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
    transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
    transaction.replace(R.id.prefs, f);
    transaction.commitAllowingStateLoss();
}
 
Example 12
Source File: ListContactsBirthdayFragment.java    From RememBirthday with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Helper function to showMessage the details of a selected item, either by
 * displaying a fragment in-place in the current UI, or starting a
 * whole new activity in which it is displayed.
 */
private void showDetails(Contact contact, int position) {
    currentContact = contact;
    currentContactPosition = position;
    if (dualPanel) {
        // Assign currentContact to activity and attach dialog
        AbstractBuddyActivity abstractBuddyActivity = (AbstractBuddyActivity) getActivity();
        abstractBuddyActivity.setContactSelected(contact);
        abstractBuddyActivity.attachDialogListener(contact);

        // Checked the position
        contactAdapter.setItemCheckedByPosition(position);

        if(contact == null) {
            removeDetails();
        } else {
            // Make new fragment to showMessage this selection.
            DetailsBuddyFragment detailsFragment = new DetailsBuddyFragment();
            detailsFragment.setBuddy(contact);
            // Execute a transaction, replacing any existing fragment
            // with this one inside the frame.
            FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
            if (getFragmentManager().findFragmentByTag(TAG_DETAILS_FRAGMENT) == null)
                fragmentTransaction.add(R.id.activity_buddy_container_details_fragment, detailsFragment, TAG_DETAILS_FRAGMENT);
            else
                fragmentTransaction.replace(R.id.activity_buddy_container_details_fragment, detailsFragment, TAG_DETAILS_FRAGMENT);
            fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
            fragmentTransaction.commit();
        }
    } else {
        // Otherwise we need to launch a new activity to display
        // the dialog fragment with selected text.
        Intent intent = new Intent();
        intent.setClass(getActivity(), DetailsBuddyActivity.class);
        intent.putExtra(BuddyActivity.EXTRA_BUDDY, contact);
        getActivity().startActivityForResult(intent, DetailsBuddyActivity.UPDATE_BIRTHDAY_RESULT_CODE);
    }
}
 
Example 13
Source File: SelectorActivity.java    From PictureSelector with Apache License 2.0 5 votes vote down vote up
@Override
public void hideFragment(int hidePos, int currPos) {
    if (mCurrPos != -1 && mCurrPos != ConstantData.VALUE_CHANGE_FRAGMENT_SELECTOR) {
        FragmentTransaction transaction = mFragmentManager.beginTransaction();
        transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_CLOSE);
        BaseFragment fragment = mFragments.get(mCurrPos);
        if (fragment != null) {
            transaction.hide(fragment);
        }
        transaction.commitAllowingStateLoss();
    }
    mCurrPos = currPos;
}
 
Example 14
Source File: SipHome.java    From CSipSimple with GNU General Public License v3.0 5 votes vote down vote up
private void clearDetails() {
    if (mDualPane && !hasClearedDetails) {
        FragmentTransaction ft = SipHome.this.getSupportFragmentManager()
                .beginTransaction();
        ft.replace(R.id.details, new Fragment(), null);
        ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
        ft.commit();
    }
}
 
Example 15
Source File: ActivityUtils.java    From incubator-taverna-mobile with Apache License 2.0 5 votes vote down vote up
public static void addFragmentToActivity(FragmentManager fragmentManager, Fragment fragment,
                                         int frameId) {

    for (int i = 0; i < fragmentManager.getBackStackEntryCount(); ++i) {
        fragmentManager.popBackStack();
    }
    FragmentTransaction transaction = fragmentManager.beginTransaction();
    transaction.replace(frameId, fragment);
    transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_CLOSE);
    transaction.commit();
}
 
Example 16
Source File: StartActivity.java    From HomeGenie-Android with GNU General Public License v3.0 5 votes vote down vote up
public void showSettings() {
    SettingsFragment fmWidget = new SettingsFragment();
    FragmentManager fm = getSupportFragmentManager();
    FragmentTransaction fragmentTransaction = fm.beginTransaction();
    fragmentTransaction.add(fmWidget, "SETTINGS");
    fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
    fragmentTransaction.commitAllowingStateLoss();
    //fragmentTransaction.commit();
}
 
Example 17
Source File: RMBTMainActivity.java    From open-rmbt with Apache License 2.0 5 votes vote down vote up
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults)
{
    switch (requestCode)
    {
    case PermissionHelper.REQUEST_AT_INIT:
        if (geoLocation == null)
            geoLocation = new MainGeoLocation(getApplicationContext());
        geoLocation.start();
        checkSettings(true, null);
        
        
        // reinit main menu fragment mainly to update location info
        final FragmentTransaction ft;
        ft = fm.beginTransaction();
        ft.replace(R.id.fragment_content, new RMBTMainMenuFragment(), AppConstants.PAGE_TITLE_MAIN);
        ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
        //hack for v4 support library bug:
        ft.commitAllowingStateLoss();
        //ft.commit();
        
        return;
    
    case PermissionHelper.REQUEST_AT_TEST_START:
        startTest();
        return;
    }
}
 
Example 18
Source File: MainActivity.java    From WiFiProxySwitcher with Apache License 2.0 5 votes vote down vote up
@Override
public void onWiFiSetSuccess() {
    FragmentManager fm = getSupportFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();
    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
    ft.remove(wifiConnectionFragment);
    ft.show(proxySettingsFragment);
    ft.commit();
}
 
Example 19
Source File: RMBTMainActivity.java    From open-rmbt with Apache License 2.0 5 votes vote down vote up
public void showFilter() {
    final FragmentManager fm = getSupportFragmentManager();
    FragmentTransaction ft;
    
    final Fragment fragment = new RMBTFilterFragment();
    
    ft = fm.beginTransaction();
    ft.replace(R.id.fragment_content, fragment, AppConstants.PAGE_TITLE_HISTORY_FILTER);
    ft.addToBackStack(AppConstants.PAGE_TITLE_HISTORY_FILTER);
    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
    ft.commit();
    
    refreshActionBar(AppConstants.PAGE_TITLE_HISTORY_FILTER);
}
 
Example 20
Source File: IBaseActivity.java    From Collection-Android with MIT License 4 votes vote down vote up
/**
 * Show a fragment.
 *
 * @param thisFragment Now show fragment, can be null.
 * @param thatFragment fragment to display.
 * @param stickyStack  sticky back stack.
 * @param requestCode  requestCode.
</T> */
public  <T extends IBaseFragment> void startFragment(
		T thisFragment, T thatFragment,
		boolean stickyStack, int requestCode,
		boolean isSkipAnimation
) {
	FragmentTransaction fragmentTransaction = mFManager.beginTransaction();
	if (thisFragment != null) {
		FragmentStackEntity thisStackEntity = (FragmentStackEntity) mFragmentEntityMap.get(thisFragment);
		if (thisStackEntity != null) {
			if (thisStackEntity.isSticky) {
				thisFragment.onPause();
				thisFragment.onStop();
				fragmentTransaction.hide(thisFragment);
				if(isSkipAnimation){
					fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_CLOSE);
				}

			} else {
				fragmentTransaction.remove(thisFragment).commit();
				if(isSkipAnimation){
					fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_CLOSE);
				}
				fragmentTransaction.commitNow();
				fragmentTransaction = mFManager.beginTransaction();
				mFragmentEntityMap.remove(thisFragment);
				mFragmentStack.remove(thisFragment);
				fragmentStack.remove(thisFragment.getClass().getSimpleName());
			}
		}
	}
	String fragmentTag =
			thatFragment.getClass().getSimpleName();
	fragmentTransaction.add(fragmentLayoutId(), thatFragment, fragmentTag);
	if(isSkipAnimation){
		fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
	}
	fragmentTransaction.addToBackStack(fragmentTag);
	fragmentTransaction.commit();
	mFManager.executePendingTransactions();
	FragmentStackEntity fragmentStackEntity = new FragmentStackEntity();
	fragmentStackEntity.isSticky = stickyStack;
	fragmentStackEntity.requestCode = requestCode;
	thatFragment.setStackEntity(fragmentStackEntity);
	mFragmentEntityMap.put(thatFragment,fragmentStackEntity);
	mFragmentStack.add(thatFragment);
	fragmentStack.put(fragmentTag,thatFragment);
}