Example usage for android.support.v4.app FragmentTransaction detach

List of usage examples for android.support.v4.app FragmentTransaction detach

Introduction

In this page you can find the example usage for android.support.v4.app FragmentTransaction detach.

Prototype

public abstract FragmentTransaction detach(Fragment fragment);

Source Link

Document

Detach the given fragment from the UI.

Usage

From source file:com.shalzz.attendance.activity.MainActivity.java

/**
 * Push the installed fragment into our custom back stack (or optionally
 * {@link FragmentTransaction#remove} it) and {@link FragmentTransaction#add} {@code fragment}.
 *
 * @param fragment {@link Fragment} to be added.
 *
 *//*from   ww w  .j  a  v  a 2 s .  c  om*/
private void showFragment(Fragment fragment) {
    final FragmentTransaction ft = mFragmentManager.beginTransaction();
    final Fragment installed = getInstalledFragment();

    // return if the fragment is already installed
    if (isAttendanceListInstalled() && fragment instanceof AttendanceListFragment
            || isTimeTablePagerInstalled() && fragment instanceof TimeTablePagerFragment
            || isSettingsInstalled() && fragment instanceof SettingsFragment) {
        return;
    }

    if (mPreviousFragment != null) {
        Timber.d("showFragment: destroying previous fragment %s", mPreviousFragment.getClass().getSimpleName());
        ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
        ft.remove(mPreviousFragment);
        mPreviousFragment = null;
    }

    // Remove the current fragment and push it into the backstack.
    if (installed != null) {
        mPreviousFragment = installed;
        ft.detach(mPreviousFragment);
    }

    // Show the new one
    ft.add(R.id.frame_container, fragment, FRAGMENT_TAG);
    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
    ft.commit();
}

From source file:github.popeen.dsub.fragments.SelectDirectoryFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.menu_remove_playlist:
        removeFromPlaylist(playlistId, playlistName, getSelectedIndexes());
        return true;
    case R.id.menu_download_all:
        downloadAllPodcastEpisodes();/*from www.  j  a va2s  .  c om*/
        return true;
    case R.id.menu_show_all:
        setShowAll();
        return true;
    case R.id.menu_top_tracks:
        showTopTracks();
        return true;
    case R.id.menu_similar_artists:
        showSimilarArtists(id);
        return true;
    case R.id.menu_radio:
        startArtistRadio(id);
        return true;
    case R.id.reverse:
        FragmentTransaction ft = getFragmentManager().beginTransaction();
        ft.detach(this).attach(this).commit();
        return true;
    }

    return super.onOptionsItemSelected(item);

}

From source file:com.sonymobile.dronecontrol.activity.MainActivity.java

private void initDevice() {
    ARDiscoveryDeviceService selectedService = null;

    if (mDeviceToConnect != null && mScreenFragment.isAdded()) {
        for (ARDiscoveryDeviceService service : mDeviceList) {

            // check available devices
            if (service.getDevice() instanceof ARDiscoveryDeviceBLEService) {
                if (EnumDevices.MINIDRONE.equals(mDeviceToConnect)) {
                    selectedService = service;
                    break;
                }//  w  w  w . j ava2  s .  c o  m
            } else if (ardiscoveryService.getProductFromProductID(service.getProductID())
                    .toString() == ARDISCOVERY_PRODUCT_ENUM.ARDISCOVERY_PRODUCT_ARDRONE.toString()) {
                if (EnumDevices.BEBOP.equals(mDeviceToConnect)) {
                    selectedService = service;
                    break;
                }

            } else if (ardiscoveryService.getProductFromProductID(service.getProductID())
                    .toString() == ARDISCOVERY_PRODUCT_ENUM.ARDISCOVERY_PRODUCT_JS.toString()) {
                if (EnumDevices.JUMPINGSUMO.equals(mDeviceToConnect)) {
                    selectedService = service;
                    break;
                }
            }
        }

        // if selected device was found
        if (selectedService != null) {
            final FragmentManager manager = getSupportFragmentManager();
            final FragmentTransaction fragmentTransaction = manager.beginTransaction();

            ((TextView) findViewById(R.id.tv_connecting))
                    .setText(getResources().getString(R.string.device_found));
            ((ProgressBar) findViewById(R.id.progress)).setVisibility(View.INVISIBLE);

            if (Utils.DEBUG || (!Utils.DEBUG && mBtListener.isGamepadConnected())) {
                if (mDeviceToConnect != null) {
                    mHandler.removeCallbacks(mListRefresh);
                    final Intent intent = new Intent(MainActivity.this, mDeviceToConnect.className);
                    intent.putExtra(Constants.EXTRA_DEVICE_SERVICE, selectedService);
                    startActivity(intent);
                }
            } else {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        Toast.makeText(getApplicationContext(), R.string.gamepad_needed, Toast.LENGTH_SHORT)
                                .show();
                    }
                });
                fragmentTransaction.detach(mScreenFragment);
                manager.popBackStack();
                manager.popBackStack();
            }

        }
    }
}

From source file:com.hippo.scene.StageActivity.java

public void startScene(Announcer announcer) {
    Class<?> clazz = announcer.clazz;
    Bundle args = announcer.args;/*from www  .  ja  v  a2  s . c o m*/
    TransitionHelper tranHelper = announcer.tranHelper;
    FragmentManager fragmentManager = getSupportFragmentManager();
    int launchMode = getSceneLaunchMode(clazz);

    // Check LAUNCH_MODE_SINGLE_TASK
    if (launchMode == SceneFragment.LAUNCH_MODE_SINGLE_TASK) {
        for (int i = 0, n = mSceneTagList.size(); i < n; i++) {
            String tag = mSceneTagList.get(i);
            Fragment fragment = fragmentManager.findFragmentByTag(tag);
            if (fragment == null) {
                Log.e(TAG, "Can't find fragment with tag: " + tag);
                continue;
            }

            if (clazz.isInstance(fragment)) { // Get it
                FragmentTransaction transaction = fragmentManager.beginTransaction();

                // Use default animation
                transaction.setCustomAnimations(R.anim.scene_open_enter, R.anim.scene_open_exit);

                // Remove top fragments
                for (int j = i + 1; j < n; j++) {
                    String topTag = mSceneTagList.get(j);
                    Fragment topFragment = fragmentManager.findFragmentByTag(topTag);
                    if (null == topFragment) {
                        Log.e(TAG, "Can't find fragment with tag: " + topTag);
                        continue;
                    }
                    // Clear shared element
                    topFragment.setSharedElementEnterTransition(null);
                    topFragment.setSharedElementReturnTransition(null);
                    topFragment.setEnterTransition(null);
                    topFragment.setExitTransition(null);
                    // Remove it
                    transaction.remove(topFragment);
                }

                // Remove tag from index i+1
                mSceneTagList.subList(i + 1, mSceneTagList.size()).clear();

                // Attach fragment
                if (fragment.isDetached()) {
                    transaction.attach(fragment);
                }

                // Commit
                transaction.commitAllowingStateLoss();

                // New arguments
                if (args != null && fragment instanceof SceneFragment) {
                    // TODO Call onNewArguments when view created ?
                    ((SceneFragment) fragment).onNewArguments(args);
                }

                return;
            }
        }
    }

    // Get current fragment
    SceneFragment currentScene = null;
    if (mSceneTagList.size() > 0) {
        // Get last tag
        String tag = mSceneTagList.get(mSceneTagList.size() - 1);
        Fragment fragment = fragmentManager.findFragmentByTag(tag);
        if (fragment != null) {
            Assert.assertTrue(SceneFragment.class.isInstance(fragment));
            currentScene = (SceneFragment) fragment;
        }
    }

    // Check LAUNCH_MODE_SINGLE_TASK
    if (clazz.isInstance(currentScene) && launchMode == SceneFragment.LAUNCH_MODE_SINGLE_TOP) {
        if (args != null) {
            currentScene.onNewArguments(args);
        }
        return;
    }

    // Create new scene
    SceneFragment newScene = newSceneInstance(clazz);
    newScene.setArguments(args);

    // Create new scene tag
    String newTag = Integer.toString(mIdGenerator.getAndIncrement());

    // Add new tag to list
    mSceneTagList.add(newTag);
    mDelaySceneTagList.add(newTag);

    FragmentTransaction transaction = fragmentManager.beginTransaction();
    // Animation
    if (currentScene != null) {
        if (tranHelper == null || !tranHelper.onTransition(this, transaction, currentScene, newScene)) {
            // Clear shared item
            currentScene.setSharedElementEnterTransition(null);
            currentScene.setSharedElementReturnTransition(null);
            currentScene.setEnterTransition(null);
            currentScene.setExitTransition(null);
            newScene.setSharedElementEnterTransition(null);
            newScene.setSharedElementReturnTransition(null);
            newScene.setEnterTransition(null);
            newScene.setExitTransition(null);
            // Set default animation
            transaction.setCustomAnimations(R.anim.scene_open_enter, R.anim.scene_open_exit);
        }
        // Detach current scene
        if (!currentScene.isDetached()) {
            transaction.detach(currentScene);
        } else {
            Log.e(TAG, "Current scene is detached");
        }
    }

    // Add new scene
    transaction.add(getContainerViewId(), newScene, newTag);

    // Commit
    transaction.commitAllowingStateLoss();

    // Check request
    if (announcer.requestFrom != null) {
        newScene.addRequest(announcer.requestFrom.getTag(), announcer.requestCode);
    }
}

From source file:com.zoffcc.applications.zanavi.Navit.java

static void animate_bottom_bar_down() {
    final FrameLayout a = (FrameLayout) Global_Navit_Object.findViewById(R.id.bottom_bar_slide);

    // System.out.println("FRAG:animate_bottom_bar_down:014");

    // set bottom end positon correctly??
    bottom_y_margin_bottom_bar_touch = Navit.map_view_height + Navit.actionBarHeight + bottom_bar_px
            - Navit.bottom_bar_slider_shadow_px;

    final int move_by = (int) (bottom_y_margin_bottom_bar_touch - cur_y_margin_bottom_bar_touch);
    TranslateAnimation animation = new TranslateAnimation(0, 0, 0, move_by); //  new TranslateAnimation(xFrom,xTo, yFrom,yTo)
    animation.setDuration(bottom_bar_snap_duration); // animation duration
    animation.setFillAfter(true);/*from w w  w .j a v a2 s . c  o m*/
    animation.setFillEnabled(true);
    animation.setRepeatCount(0); // animation repeat count
    animation.setAnimationListener(new AnimationListener() {

        @Override
        public void onAnimationStart(Animation animation) {
        }

        @Override
        public void onAnimationRepeat(Animation animation) {
        }

        @Override
        public void onAnimationEnd(Animation animation) {
            // set bottom end positon correctly??
            bottom_y_margin_bottom_bar_touch = Navit.map_view_height + Navit.actionBarHeight + bottom_bar_px
                    - Navit.bottom_bar_slider_shadow_px;

            cur_y_margin_bottom_bar_touch = bottom_y_margin_bottom_bar_touch;
            RelativeLayout.LayoutParams relativeParams = (RelativeLayout.LayoutParams) a.getLayoutParams();
            relativeParams.setMargins(0, (int) bottom_y_margin_bottom_bar_touch, 0, 0); // left, top, right, bottom
            a.setLayoutParams(relativeParams);
            a.requestLayout();

            TranslateAnimation anim = new TranslateAnimation(0, 0, 0, 0);
            anim.setFillAfter(true);
            anim.setFillEnabled(true);
            anim.setDuration(1);
            a.startAnimation(anim);

            // remove roadbook fragment -----------
            try {
                if (road_book != null) {
                    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
                    // System.out.println("FRAG:dettach:002");
                    fragmentTransaction.detach(road_book);
                    fragmentTransaction.remove(road_book).commit();
                    road_book = null;
                }
            } catch (Exception ef) {
            }
            // remove roadbook fragment -----------

        }
    });
    a.startAnimation(animation);
}