Example usage for android.app FragmentTransaction addToBackStack

List of usage examples for android.app FragmentTransaction addToBackStack

Introduction

In this page you can find the example usage for android.app FragmentTransaction addToBackStack.

Prototype

public abstract FragmentTransaction addToBackStack(@Nullable String name);

Source Link

Document

Add this transaction to the back stack.

Usage

From source file:com.greatspeeches.slides.ScreenSlidePageFragment.java

public void playYutubeVideo() {
    fragmentsLayout.setVisibility(View.VISIBLE);
    videoRel.setVisibility(View.VISIBLE);
    if (mPersonObj.getVideourl().length() > 0) {
        int indexPos = mPersonObj.getVideourl().indexOf("=");
        if (indexPos > 0) {
            videoId = mPersonObj.getVideourl().substring(indexPos + 1, mPersonObj.getVideourl().length());
        }// w  w w. j av  a2 s .  c om

        android.app.FragmentTransaction fts = getChildFragmentManager().beginTransaction();
        YouTubePlayerFragment youTubePlayerFragment = new YouTubePlayerFragment();
        //         YouTubePlayerSupportFragment youTubePlayerFragment = YouTubePlayerSupportFragment.newInstance();
        //         FragmentTransaction fts = myContext.getSupportFragmentManager().beginTransaction();
        fts.add(R.id.video_container, youTubePlayerFragment);
        fts.addToBackStack(null);
        fts.commit();

        myContext.getSupportFragmentManager().executePendingTransactions();

        youTubePlayerFragment.initialize(GreateSpeechesUtil.yOUTUBEdEVELOPERkEY, new OnInitializedListener() {
            @Override
            public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer player,
                    boolean wasRestored) {
                // Play, cue or whatever you want to do with the player
                activePlayer = player;
                activePlayer.setPlayerStyle(YouTubePlayer.PlayerStyle.DEFAULT);
                activePlayer.setPlayerStateChangeListener(videoListener);
                activePlayer.setFullscreen(false);
                activePlayer.setShowFullscreenButton(false);
                if (!wasRestored) {
                    activePlayer.loadVideo(videoId, 0);
                }
            }

            @Override
            public void onInitializationFailure(Provider arg0, YouTubeInitializationResult arg1) {
                // TODO Auto-generated method stub
            }
        });
    }
}

From source file:org.dolphinemu.dolphinemu.gamelist.GameListActivity.java

/**
 * Switches to the {@link Fragment} represented
 * by the given ID number./* ww  w.jav  a 2  s  .co  m*/
 * 
 * @param toPage the number representing the {@link Fragment} to switch to.
 */
public void SwitchPage(int toPage) {
    if (mCurFragmentNum == toPage)
        return;

    switch (toPage) {
    case 0: // Game list
    {
        // We use the title section as the browser directory tracker in the folder browser.
        // Make sure we flip the title back if we're coming from that fragment.
        if (mCurFragmentNum == 1)
            setTitle(R.string.app_name);

        mCurFragmentNum = 0;
        final GameListFragment gameList = new GameListFragment();
        FragmentTransaction ft = getFragmentManager().beginTransaction();
        ft.replace(R.id.content_frame, gameList);
        ft.commit();
        invalidateOptionsMenu();
    }
        break;

    case 1: // Folder Browser
    {
        mCurFragmentNum = 1;
        final FolderBrowser folderBrowser = new FolderBrowser();
        FragmentTransaction ft = getFragmentManager().beginTransaction();
        ft.replace(R.id.content_frame, folderBrowser);
        ft.addToBackStack(null);
        ft.commit();
        invalidateOptionsMenu();
    }
        break;

    case 2: // Settings
    {
        Intent intent = new Intent(this, PrefsActivity.class);
        startActivity(intent);
    }
        break;

    case 3: // About
    {
        Intent intent = new Intent(this, AboutActivity.class);
        startActivity(intent);
    }
        break;

    default:
        break;
    }
}

From source file:ab.util.AbDialogUtil.java

/**
 * ??Fragment.//from w  w w. j av a 2  s .co  m
 * 
 * @param context
 *            the context
 */
public static void removeDialog(Context context) {
    try {
        FragmentActivity activity = (FragmentActivity) context;
        FragmentTransaction ft = activity.getFragmentManager().beginTransaction();
        // 
        ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_CLOSE);
        Fragment prev = activity.getFragmentManager().findFragmentByTag(mDialogTag);
        if (prev != null) {
            ft.remove(prev);
        }
        ft.addToBackStack(null);
        if (context != null) {
            ft.commit();
        }
    } catch (Exception e) {
        // ?Activity??
        e.printStackTrace();
    }
}

From source file:com.antew.redditinpictures.library.ui.RedditFragmentActivity.java

private void loadSubreddit(String subreddit, Category category, Age age) {
    if (subreddit.equals(Constants.Reddit.REDDIT_FRONTPAGE)
            || subreddit.equals(Constants.Reddit.REDDIT_FRONTPAGE_DISPLAY_NAME)) {
        mSelectedSubreddit = Constants.Reddit.REDDIT_FRONTPAGE;
    } else {//  ww  w .  j  a v a2s .c om
        mSelectedSubreddit = subreddit;
    }

    mCategory = category;
    mAge = age;

    switch (mActiveViewType) {
    case GRID:
        FragmentTransaction gridTrans = getFragmentManager().beginTransaction();
        gridTrans.replace(R.id.content_fragment, getNewImageGridFragment(mSelectedSubreddit, mCategory, mAge));
        gridTrans.addToBackStack(null);
        gridTrans.commit();
        break;
    case LIST:
        FragmentTransaction listTrans = getFragmentManager().beginTransaction();
        listTrans.replace(R.id.content_fragment, getNewImageListFragment(mSelectedSubreddit, mCategory, mAge));
        listTrans.addToBackStack(null);
        listTrans.commit();
        break;
    }

    setActionBarTitle(mSelectedSubreddit, RedditUtil.getSortDisplayString(mCategory, mAge));
}

From source file:it.scoppelletti.mobilepower.app.FragmentLayoutController.java

/**
 * Ricostruisce la successione dei frammenti nell’unico pannello.
 * /*from  ww w.  jav a  2s .c  o  m*/
 * @param  fragmentMgr   Gestore dei frammenti.
 * @param  fragmentQueue Frammenti.
 * @return               Identificatore dell’ultimo elemento inserito
 *                       nel back stack. 
 */
private int arrangePanel(FragmentManager fragmentMgr,
        Queue<FragmentLayoutController.FragmentEntry> fragmentQueue) {
    int tnId, lastTnId;
    FragmentLayoutController.FragmentEntry entry;
    FragmentTransaction fragmentTn = null;

    lastTnId = -1;
    while (!fragmentQueue.isEmpty()) {
        tnId = -1;
        entry = fragmentQueue.remove();

        try {
            fragmentTn = fragmentMgr.beginTransaction();

            fragmentTn.replace(myFrameIds[0], entry.getFragment().asFragment(), entry.getTag());

            fragmentTn.addToBackStack(null);
        } finally {
            if (fragmentTn != null) {
                tnId = fragmentTn.commit();
                fragmentTn = null;
            }
        }

        if (tnId >= 0) {
            lastTnId = tnId;
        }
    }

    return lastTnId;
}

From source file:com.example.koppa.driverlicensev2.MainActivity.java

public void addAdminFragment() {
    Fragment frag = null;//ww w .  j  a  v a  2 s.  c  o m
    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    NavigationView navigationView;
    navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.inflateMenu(R.menu.nav_menu_admin);
    frag = new AdminFragment();
    toolbar.setVisibility(View.VISIBLE);

    fragmentTransaction.replace(R.id.fragment_container, frag);
    fragmentTransaction.addToBackStack(null);
    fragmentTransaction.commit();
}

From source file:itcr.gitsnes.MainActivity.java

/**
 *  Methods inflate menu options panel/*from ww  w  .ja  v  a 2s  .c o  m*/
 *  Params:
 *      - [menu]
 *  Returns:
 *      - State of building [true]
 */
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    /* Inflate the menu; this adds items to the action bar if it is present. */
    getMenuInflater().inflate(R.menu.main, menu);

    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView();
    if (null != searchView) {
        searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
        searchView.setIconifiedByDefault(false);
    }

    SearchView.OnQueryTextListener queryTextListener = new SearchView.OnQueryTextListener() {
        public boolean onQueryTextChange(String newText) {
            // this is your adapter that will be filtered
            // Log.i("log_tag",newText);

            return true;
        }

        public boolean onQueryTextSubmit(String query) {
            Log.i("log_tag", query);

            MasterGames new_fragment = new MasterGames(json_arr);
            new_fragment.setQname(query);

            RelativeLayout rl = (RelativeLayout) findViewById(R.id.mainback);
            rl.setBackgroundColor(Color.parseColor("#009f28"));
            authButton.setVisibility(View.INVISIBLE);

            FragmentTransaction transaction = getFragmentManager().beginTransaction();
            transaction.replace(R.id.placeholder, new_fragment);
            transaction.addToBackStack(null);
            transaction.commit();

            return true;

        }
    };

    searchView.setOnQueryTextListener(queryTextListener);

    return super.onCreateOptionsMenu(menu);
}

From source file:net.nakama.duckdroid.ui.Duckdroid.java

/**
 * //from   w  w  w .j  a v  a 2  s  .c  o  m
 * @param result
 */
private void manageResult(ZeroClickResponse result) {

    if (result.isBang() && result.getRedirect() != null && !result.getRedirect().equals("")) {
        startBrowserIntent(result.getRedirect());

    } else if (result.getFlatResults().size() == 0) {

        TextView nt = new TextView(this);
        nt.setText("^_^ No result...");
        LinearLayout ll = (LinearLayout) findViewById(R.id.lt_main);
        ll.removeAllViews();
        ll.addView(nt);

    } else {

        FragmentManager manager = getFragmentManager();
        FragmentTransaction trx = manager.beginTransaction();
        ResultFragment resultFragment = new ResultFragment(result);
        trx.replace(R.id.lt_main, resultFragment);
        //trx.add(R.id.lt_main, resultFragment);
        trx.addToBackStack(null);
        trx.commit();
    }
}

From source file:ml.puredark.hviewer.ui.fragments.SettingFragment.java

@Override
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
    if (preference.getKey().equals(KEY_PREF_ABOUT_UPGRADE)) {
        ///*from  w w  w.ja va  2  s  .  c  o m*/
        if (!checking)
            UpdateManager.checkUpdate(activity);
    } else if (preference.getKey().equals(KEY_PREF_BKRS_BACKUP)) {
        //
        new AlertDialog.Builder(activity).setTitle("?").setMessage("?")
                .setPositiveButton(getString(R.string.ok), (dialog, which) -> {
                    String backup = new DataBackup().DoBackup();
                    activity.showSnackBar(backup);
                }).setNegativeButton(getString(R.string.cancel), null).show();

    } else if (preference.getKey().equals(KEY_PREF_BKRS_RESTORE)) {
        //
        new AlertDialog.Builder(activity).setTitle("???")
                .setMessage("????")
                .setPositiveButton(getString(R.string.ok), (dialog, which) -> {
                    String restore = new DataRestore().DoRestore();
                    Intent intent = new Intent();
                    activity.setResult(RESULT_OK, intent);
                    Toast.makeText(activity, restore, Toast.LENGTH_LONG).show();
                    activity.finish();
                }).setNegativeButton(getString(R.string.cancel), null).show();

    } else if (preference.getKey().equals(KEY_PREF_ABOUT_LICENSE)) {
        //???
        Intent intent = new Intent(activity, LicenseActivity.class);
        startActivity(intent);
    } else if (preference.getKey().equals(KEY_PREF_ABOUT_PRIVACY)) {
        //???
        Intent intent = new Intent(activity, PrivacyActivity.class);
        startActivity(intent);
    } else if (preference.getKey().equals(KEY_PREF_ABOUT_H_VIEWER)) {
        //
        FragmentTransaction transaction = getFragmentManager().beginTransaction();
        transaction.replace(R.id.setting_content, new AboutFragment(activity));
        transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
        transaction.addToBackStack(null);
        transaction.commit();
    } else if (preference.getKey().equals(KEY_PREF_DOWNLOAD_PATH)) {
        //
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
            intent.addFlags(Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION);
            try {
                startActivityForResult(intent, RESULT_CHOOSE_DIRECTORY);
            } catch (ActivityNotFoundException e) {
                e.printStackTrace();
                mDialog.show(getFragmentManager(), null);
            }
            new Handler().postDelayed(() -> {
                if (!opened)
                    activity.showSnackBar("?");
            }, 1000);
        } else {
            mDialog.show(getFragmentManager(), null);
        }
    } else if (preference.getKey().equals(KEY_PREF_DOWNLOAD_IMPORT)) {
        //
        new AlertDialog.Builder(activity).setTitle("?")
                .setMessage("??")
                .setPositiveButton(getString(R.string.ok), (dialog, which) -> {
                    DownloadedImport();
                }).setNegativeButton(getString(R.string.cancel), null).show();
    } else if (preference.getKey().equals(KEY_PREF_FAVOURITE_EXPORT)) {
        //?
        new AlertDialog.Builder(activity).setTitle("??")
                .setMessage("?")
                .setPositiveButton("", (dialog, which) -> {
                    DocumentFile file = FileHelper.createFileIfNotExist(Names.favouritesname,
                            DownloadManager.getDownloadPath(), Names.backupdirname);
                    if (file != null) {
                        FavouriteHolder holder = new FavouriteHolder(activity);
                        String json = new Gson().toJson(holder.getFavourites());
                        FileHelper.writeString(json, file);
                        holder.onDestroy();
                        activity.showSnackBar("??");
                    } else
                        activity.showSnackBar("");
                }).setNegativeButton(getString(R.string.cancel), null).show();
    } else if (preference.getKey().equals(KEY_PREF_FAVOURITE_IMPORT)) {
        //?
        new AlertDialog.Builder(activity).setTitle("??")
                .setMessage("???")
                .setPositiveButton(getString(R.string.ok), (dialog, which) -> {
                    String json = FileHelper.readString(Names.favouritesname, DownloadManager.getDownloadPath(),
                            Names.backupdirname);
                    if (json == null) {
                        activity.showSnackBar("?");
                    } else {
                        try {
                            List<Pair<CollectionGroup, List<LocalCollection>>> favGroups = new Gson().fromJson(
                                    json,
                                    new TypeToken<ArrayList<Pair<CollectionGroup, ArrayList<LocalCollection>>>>() {
                                    }.getType());
                            FavouriteHolder holder = new FavouriteHolder(activity);
                            for (Pair<CollectionGroup, List<LocalCollection>> pair : favGroups) {
                                Logger.d("DataStore", "" + pair.first);
                                CollectionGroup group = holder.getGroupByTitle(pair.first.title);
                                if (group == null) {
                                    group = pair.first;
                                    group.gid = holder.addFavGroup(group);
                                }
                                for (LocalCollection collection : pair.second) {
                                    collection.gid = group.gid;
                                    holder.addFavourite(collection);
                                }
                            }
                            holder.onDestroy();
                            activity.showSnackBar("??");
                        } catch (Exception e) {
                            e.printStackTrace();
                            activity.showSnackBar("?");
                        }
                    }
                }).setNegativeButton(getString(R.string.cancel), null).show();
    } else if (preference.getKey().equals(KEY_PREF_CACHE_CLEAN)) {
        //
        new AlertDialog.Builder(activity).setTitle("?")
                .setMessage("??")
                .setPositiveButton(getString(R.string.ok), (dialog, which) -> {
                    ImagePipeline imagePipeline = Fresco.getImagePipeline();
                    imagePipeline.clearDiskCaches();
                    activity.showSnackBar("??");
                    preference.setSummary(" 0.00 MB");
                }).setNegativeButton(getString(R.string.cancel), null).show();
    } else if (preference.getKey().equals(KEY_PREF_PROXY_DETAIL)) {
        //PROXY?
        FragmentTransaction transaction = getFragmentManager().beginTransaction();
        transaction.replace(R.id.setting_content, new ProxyFragment(activity));
        transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
        transaction.addToBackStack(null);
        transaction.commit();
    } else if (preference.getKey().equals(KEY_PREF_LOCK_METHODS_DETAIL)) {
        //??
        FragmentTransaction transaction = getFragmentManager().beginTransaction();
        transaction.replace(R.id.setting_content, new LockMethodFragment(activity));
        transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
        transaction.addToBackStack(null);
        transaction.commit();
    }
    return super.onPreferenceTreeClick(preferenceScreen, preference);
}

From source file:com.murati.oszk.audiobook.ui.MusicPlayerActivity.java

private void navigateToBrowser(String mediaId) {
    //TODO: maybe place navigate block here

    LogHelper.d(TAG, "navigateToBrowser, mediaId=" + mediaId);
    MediaBrowserFragment fragment = getBrowseFragment();
    updateBookButtons(mediaId);//from   w w w .j a v a2  s  . c  o  m

    if (fragment == null || !TextUtils.equals(fragment.getMediaId(), mediaId)) {
        // Create Transaction
        FragmentTransaction transaction = getFragmentManager().beginTransaction();
        transaction.setCustomAnimations(R.animator.slide_in_from_right, R.animator.slide_out_to_left,
                R.animator.slide_in_from_left, R.animator.slide_out_to_right);

        // Create Backstack
        // Not an empty, root or the same where we are currently, for refresh retries
        if (fragment != null && mediaId != null && mediaId != getMediaId()) {
            transaction.addToBackStack(null);
        }

        //Create new fragment and navigate
        fragment = new MediaBrowserFragment();
        fragment.setMediaId(mediaId);
        transaction.replace(R.id.container, fragment, FRAGMENT_TAG);

        //Do it
        transaction.commit();
    }
}