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

The following examples show how to use android.support.v4.app.FragmentTransaction#setCustomAnimations() . 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: BluetoothActivity.java    From AndroidDemo with MIT License 6 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        if (currentFragment.getTag().equals(CHAT_FRAGMENT)) {
            FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
            transaction.setCustomAnimations(android.R.anim.slide_in_left, android.R.anim.slide_out_right);
            transaction.hide(chatFragment).show(listFragment).commit();
            currentFragment = getSupportFragmentManager().findFragmentByTag(LIST_FRAGMENT);
            if (imm != null) {
                imm.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
            }
            setSubtitle("");
            return true;
        } else
            return super.onKeyDown(keyCode, event);
    } else
        return super.onKeyDown(keyCode, event);
}
 
Example 2
Source File: CategoryHandler.java    From mobikul-standalone-pos with MIT License 6 votes vote down vote up
public void addCategory(View v) {
    FragmentManager fragmentManager = ((AppCompatActivity) context).getSupportFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    fragmentTransaction.setCustomAnimations(R.anim.enter_from_right, R.anim.exit_to_left);
    Fragment fragment;
    fragment = ((BaseActivity) context).mSupportFragmentManager.findFragmentByTag(AddCategoryFragment.class.getSimpleName());
    if (fragment == null)
        fragment = new AddCategoryFragment();
    if (!fragment.isAdded()) {
        Bundle bundle = new Bundle();
        bundle.putSerializable("category", category);
        fragment.setArguments(bundle);
        Log.d("name", fragment.getClass().getSimpleName() + "");
        fragmentTransaction.add(((CategoryActivity) context).binding.categoryFl.getId(), fragment, fragment.getClass().getSimpleName());
        fragmentTransaction.addToBackStack(fragment.getClass().getSimpleName()).commit();
    }
}
 
Example 3
Source File: BaseFragmentActivity.java    From BigApp_WordPress_Android with Apache License 2.0 6 votes vote down vote up
/***
 * 显示fragment + 动画效果
 *
 * @param layoutId container_id
 * @param fragment fragment
 * @param extras   bundle
 */
protected void showFragmentLeftRight(int layoutId, Fragment fragment, Bundle extras, boolean back,
                                     String fragmentTag) {
    if (fragment != null) {
        if (extras != null) {
            fragment.setArguments(extras);
        }
        FragmentTransaction transaction = getSupportFragmentManager()
                .beginTransaction();

        if (back) {
            transaction.setCustomAnimations(R.anim.v_left_in,
                    R.anim.v_right_out, R.anim.v_right_in, R.anim.v_left_out);
        } else {
            // 定义进入和退出的动画
            transaction.setCustomAnimations(R.anim.v_right_in,
                    R.anim.v_left_out, R.anim.v_left_in, R.anim.v_right_out);
        }
        try {
            transaction.replace(layoutId, fragment, fragmentTag).commit();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
 
Example 4
Source File: WebViewCarFragment.java    From carstream-android-auto with Apache License 2.0 6 votes vote down vote up
private void hideWarningScreen() {
    if (warningScreenOpen) {
        if (isAdded()) {
            webView.setVisibility(View.VISIBLE);
            toolbar.setVisibility(View.VISIBLE);
            FragmentManager childFragmentManager = getChildFragmentManager();
            Fragment oldFragment = childFragmentManager.findFragmentByTag(SAFETY_WARNING_FRAGMENT_TAG);
            if (oldFragment != null) {
                warningScreenOpen = false;
                FragmentTransaction fragmentTransaction = childFragmentManager.beginTransaction();
                fragmentTransaction.remove(oldFragment);
                fragmentTransaction.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out);
                fragmentTransaction.commitAllowingStateLoss();
            }
        }
        webView.requestFocus();
    }
}
 
Example 5
Source File: WebViewCarFragment.java    From carstream-android-auto with Apache License 2.0 6 votes vote down vote up
private void hideNativePlayer() {
    if (isAdded()) {
        nativePlayerActive = false;
        nativePlayerFragment = null;
        webView.setVisibility(View.VISIBLE);
        getView().findViewById(R.id.full_screen_view).setVisibility(View.GONE);
        FragmentManager childFragmentManager = getChildFragmentManager();
        Fragment oldFragment = childFragmentManager.findFragmentByTag(PLAYER_FRAGMENT_TAG);
        if (oldFragment != null) {
            FragmentTransaction fragmentTransaction = childFragmentManager.beginTransaction();
            fragmentTransaction.remove(oldFragment);
            fragmentTransaction.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out);
            fragmentTransaction.commitAllowingStateLoss();
        }
    }
    webView.requestFocus();
}
 
Example 6
Source File: CategoryHandler.java    From mobikul-standalone-pos with MIT License 6 votes vote down vote up
public void onClickCategory(Category category) {
    FragmentManager fragmentManager = ((AppCompatActivity) context).getSupportFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    fragmentTransaction.setCustomAnimations(R.anim.enter_from_right, R.anim.exit_to_left);
    Fragment fragment;
    fragment = ((BaseActivity) context).mSupportFragmentManager.findFragmentByTag(AddCategoryFragment.class.getSimpleName());
    if (fragment == null)
        fragment = new AddCategoryFragment();
    if (!fragment.isAdded()) {
        Bundle bundle = new Bundle();
        bundle.putSerializable("category", category);
        bundle.putBoolean("edit", true);
        fragment.setArguments(bundle);
        Log.d("name", fragment.getClass().getSimpleName() + "");
        fragmentTransaction.add(((CategoryActivity) context).binding.categoryFl.getId(), fragment, fragment.getClass().getSimpleName());
        fragmentTransaction.addToBackStack(fragment.getClass().getSimpleName()).commit();
    }
}
 
Example 7
Source File: FeedManageActivity.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);
    //设置动画
    transaction.setCustomAnimations(
            R.anim.right_in,
            R.anim.right_out);
    //当前的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 8
Source File: OptionHandler.java    From mobikul-standalone-pos with MIT License 6 votes vote down vote up
public void onClickOption(Options options) {
    FragmentManager fragmentManager = ((AppCompatActivity) context).getSupportFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    fragmentTransaction.setCustomAnimations(R.anim.enter_from_right, R.anim.exit_to_left);
    Fragment fragment;
    fragment = ((BaseActivity) context).mSupportFragmentManager.findFragmentByTag(AddOptionFragment.class.getSimpleName());
    if (fragment == null)
        fragment = new AddOptionFragment();
    if (!fragment.isAdded()) {
        Bundle bundle = new Bundle();
        bundle.putSerializable("options", options);
        bundle.putBoolean("edit", true);
        fragment.setArguments(bundle);
        Log.d("name", fragment.getClass().getSimpleName() + "");
        fragmentTransaction.add(((OptionsActivity) context).binding.optionFl.getId(), fragment, fragment.getClass().getSimpleName());
        fragmentTransaction.addToBackStack(fragment.getClass().getSimpleName()).commit();
    }
}
 
Example 9
Source File: AddProductFragmentHandler.java    From mobikul-standalone-pos with MIT License 6 votes vote down vote up
public void selectCategories(Product product, boolean edit) {
    FragmentManager fragmentManager = ((AppCompatActivity) context).getSupportFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    fragmentTransaction.setCustomAnimations(R.anim.enter_from_right, R.anim.exit_to_left);
    Fragment fragment;
    fragment = ((BaseActivity) context).mSupportFragmentManager.findFragmentByTag(ManageCategoriesFragment.class.getSimpleName());
    if (fragment == null)
        fragment = new ManageCategoriesFragment();
    Bundle bundle = new Bundle();
    bundle.putSerializable("product", product);
    bundle.putSerializable("edit", edit);
    fragment.setArguments(bundle);
    fragmentTransaction.add(((ProductActivity) context).binding.productFl.getId(), fragment, fragment.getClass().getSimpleName());
    fragmentTransaction.addToBackStack(fragment.getClass().getSimpleName()).commit();

}
 
Example 10
Source File: OpmlActivity.java    From SimpleNews with Apache License 2.0 5 votes vote down vote up
@Override
public void assignFeeds(List<Feed> feeds) {
    FragmentTransaction t = getSupportFragmentManager().beginTransaction();
    t.setCustomAnimations(R.anim.slide_in_left, R.anim.slide_out_left, R.anim.slide_in_right, R.anim.slide_out_right);
    t.replace(R.id.container, OpmlAssignFragment.newInstance(feeds), OPML_ASSIGN_TAG);
    t.addToBackStack(null);
    t.commit();
    supportInvalidateOptionsMenu();
}
 
Example 11
Source File: LocalVideoActivity.java    From YCAudioPlayer with Apache License 2.0 5 votes vote down vote up
private void showPlayingFragment(VideoBean videoBean) {
    if (isPlayFragmentShow) {
        return;
    }
    FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
    ft.setCustomAnimations(R.anim.fragment_slide_up, 0);
    if (mLocalVideoFragment == null) {
        mLocalVideoFragment = LocalVideoFragment.newInstance(videoBean);
        ft.replace(android.R.id.content, mLocalVideoFragment);
    } else {
        ft.show(mLocalVideoFragment);
    }
    ft.commitAllowingStateLoss();
    isPlayFragmentShow = true;
}
 
Example 12
Source File: MainActivity.java    From YTPlayer with GNU General Public License v3.0 5 votes vote down vote up
public static boolean loadFragment(Fragment fragment) {
    if (fragment != null) {
        Log.e("LoadingFragment", "");

        FragmentTransaction ft = fragmentManager.beginTransaction();
        ft.setCustomAnimations(R.anim.fade_in, R.anim.fade_out);
        ft.replace(R.id.fragment_container, fragment)
                .commit();
        return true;
    }
    return false;
}
 
Example 13
Source File: MainActivity.java    From notSABS with MIT License 5 votes vote down vote up
public void blacklistLayout(View view) {
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    fragmentTransaction.setCustomAnimations(R.anim.enter, R.anim.exit, R.anim.pop_enter, R.anim.pop_exit);
    fragmentTransaction.replace(R.id.fragmentContainer, new BlockCustomUrlFragment());
    fragmentTransaction.addToBackStack("manage_url_to_add_custom");
    fragmentTransaction.commit();
}
 
Example 14
Source File: MainActivity.java    From Prodigal with Apache License 2.0 5 votes vote down vote up
private void switchFragmentTo(Fragment fragment, boolean slide){
    fragmentStack.push(currentFragment);
    FragmentTransaction ft = fragmentManager.beginTransaction();
    if (slide) {
        ft.setCustomAnimations(R.anim.slide_in_right, R.anim.slide_out_left);
    }
    ft.hide(currentFragment).show(fragment).commit();
    currentFragment = fragment;
    this.currentTickObject = (OnTickListener) fragment;
    wheelView.setOnTickListener((OnTickListener) fragment);
}
 
Example 15
Source File: CheckoutHandler.java    From mobikul-standalone-pos with MIT License 5 votes vote down vote up
public void cashPayment(TotalModel totalModel) {
    FragmentManager fragmentManager = ((AppCompatActivity) context).getSupportFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    fragmentTransaction.setCustomAnimations(R.anim.enter_from_right, R.anim.exit_to_left);
    Fragment fragment;
    fragment = fragmentManager.findFragmentByTag(CashFragment.class.getSimpleName());
    if (fragment == null)
        fragment = new CashFragment();
    Bundle bundle = new Bundle();
    bundle.putSerializable("total", totalModel);
    fragment.setArguments(bundle);
    fragmentTransaction.add(((Checkout) context).checkoutBinding.frameLayout.getId(), fragment, fragment.getClass().getSimpleName());
    fragmentTransaction.addToBackStack(fragment.getClass().getSimpleName()).commit();
}
 
Example 16
Source File: DetailVideoActivity.java    From YCAudioPlayer with Apache License 2.0 5 votes vote down vote up
/**
 * 隐藏页面
 */
private void hidePlayingFragment() {
    FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
    ft.setCustomAnimations(0, R.anim.fragment_slide_down);
    ft.hide(mDetailAudioFragment);
    ft.commitAllowingStateLoss();
    isPlayFragmentShow = false;
}
 
Example 17
Source File: MainActivity.java    From SABS with MIT License 5 votes vote down vote up
public void whitelistLayout(View view) {
   Log.d(TAG, "Edit button click in Fragment1");
   FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    fragmentTransaction.setCustomAnimations(R.anim.enter, R.anim.exit, R.anim.pop_enter, R.anim.pop_exit);
   fragmentTransaction.replace(R.id.fragmentContainer, new WhitelistFragment());
   fragmentTransaction.addToBackStack("manage_url_to_manage_standard");
   fragmentTransaction.commit();
}
 
Example 18
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 19
Source File: PhotoViewerActivity.java    From glimmr with Apache License 2.0 5 votes vote down vote up
private void setPhotoInfoFragmentVisibility(Photo photo, boolean show, boolean animate) {
    if (photo == null) {
        Log.e(TAG, "setPhotoInfoFragmentVisibility: photo is null");
        return;
    }
    if (getResources().getBoolean(R.bool.sw600dp)) {
        FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
        if (show) {
            if (animate) {
                ft.setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out);
            }
            mPhotoInfoFragment = PhotoInfoFragment.newInstance(photo);
            ft.replace(R.id.sideFragment, mPhotoInfoFragment);
            ft.addToBackStack(null);
            ft.commit();
        } else if (mPhotoInfoFragment != null) {
            ft.hide(mPhotoInfoFragment);
            getSupportFragmentManager().popBackStack();
            ft.commit();
        }
    } else {
        if (show) {
            PhotoInfoFragment photoInfoFrag = PhotoInfoFragment.newInstance(photo);
            photoInfoFrag.show(getSupportFragmentManager(), "PhotoInfoFragment");
        }
    }
}
 
Example 20
Source File: BaseActivity.java    From Android-Pull-To-Refresh with Apache License 2.0 5 votes vote down vote up
public void replaceFragment(Fragment fragment, boolean addToBackStack) {
    FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();
    fragmentTransaction.setCustomAnimations(R.anim.right_in, R.anim.left_out, R.anim.left_in, R.anim.right_out);
    fragmentTransaction.replace(R.id.fl_container, fragment);
    if (addToBackStack) {
        fragmentTransaction.addToBackStack(null);
    }
    fragmentTransaction.commitAllowingStateLoss();
}