Example usage for android.app FragmentTransaction replace

List of usage examples for android.app FragmentTransaction replace

Introduction

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

Prototype

public abstract FragmentTransaction replace(@IdRes int containerViewId, Fragment fragment);

Source Link

Document

Calls #replace(int,Fragment,String) with a null tag.

Usage

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 ww. j  a  v  a2  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:de.sourcestream.movieDB.controller.TVDetailsInfo.java

/**
 * Callback method to be invoked when an item in this AdapterView has been clicked.
 *
 * @param parent   The AdapterView where the click happened.
 * @param view     The view within the AdapterView that was clicked (this will be a view provided by the adapter)
 * @param position The position of the view in the adapter.
 * @param id       The row id of the item that was clicked.
 *///from w  w  w  . jav  a  2 s. co  m
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

    activity.setRestoreMovieDetailsAdapterState(true);
    activity.setRestoreMovieDetailsState(false);
    if (activity.getTvDetailsSimFragment() != null
            && activity.getLastVisitedSimTV() == similarList.get(position).getId()
            && activity.getTvDetailsSimFragment().getTimeOut() == 0) {
        // Old tv details retrieve info and re-init component else crash
        activity.getTvDetailsSimFragment().onSaveInstanceState(new Bundle());
        Bundle bundle = new Bundle();
        bundle.putInt("id", similarList.get(position).getId());
        Bundle save = activity.getTvDetailsSimFragment().getSave();
        // Re-init movie details and set save information
        tvDetails = new TVDetails();
        tvDetails.setTimeOut(0);
        tvDetails.setSave(save);
        tvDetails.setArguments(bundle);
    } else
        tvDetails = new TVDetails();

    activity.setLastVisitedSimTV(similarList.get(position).getId());
    activity.getTvDetailsFragment().setAddToBackStack(true);
    activity.getTvDetailsFragment().onSaveInstanceState(new Bundle());
    if (activity.getSearchViewCount())
        activity.incSearchTvDetails();

    activity.setTvDetailsFragment(null);
    activity.setSaveInTVDetailsSimFragment(true);
    tvDetails.setTitle(similarList.get(position).getTitle());
    FragmentManager manager = getActivity().getFragmentManager();
    FragmentTransaction transaction = manager.beginTransaction();
    Bundle bundle = new Bundle();
    bundle.putInt("id", similarList.get(position).getId());
    tvDetails.setArguments(bundle);
    transaction.replace(R.id.frame_container, tvDetails);
    // add the current transaction to the back stack:
    transaction.addToBackStack("similarDetails");
    transaction.commit();

}

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

private void changeViewType(ViewType viewType) {
    if (viewType != null) {
        mActiveViewType = viewType;//from   ww w. j ava2  s  . com
        switch (mActiveViewType) {
        case GRID:
            FragmentTransaction gridTrans = getFragmentManager().beginTransaction();
            gridTrans.replace(R.id.content_fragment, getNewImageGridFragment());
            gridTrans.commit();
            invalidateOptionsMenu();
            break;
        case LIST:
            FragmentTransaction listTrans = getFragmentManager().beginTransaction();
            listTrans.replace(R.id.content_fragment, getNewImageListFragment());
            listTrans.commit();
            invalidateOptionsMenu();
            break;
        }
    }
}

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

private void initializeActiveView() {
    switch (mActiveViewType) {
    case GRID://from  www  .  ja  v  a2s  .c o  m
        EasyTracker.getInstance(this)
                .send(MapBuilder
                        .createEvent(Constants.Analytics.Category.INITIALIZE,
                                Constants.Analytics.Action.IMAGE_VIEW, Constants.Analytics.Label.GRID, null)
                        .build());
        FragmentTransaction gridTrans = getFragmentManager().beginTransaction();
        gridTrans.replace(R.id.content_fragment, getNewImageGridFragment());
        gridTrans.commit();
        break;
    case LIST:
        EasyTracker.getInstance(this)
                .send(MapBuilder
                        .createEvent(Constants.Analytics.Category.INITIALIZE,
                                Constants.Analytics.Action.IMAGE_VIEW, Constants.Analytics.Label.LIST, null)
                        .build());
        FragmentTransaction listTrans = getFragmentManager().beginTransaction();
        listTrans.replace(R.id.content_fragment, getNewImageListFragment());
        listTrans.commit();
        break;
    }
}

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 {/*from w  w  w .j a  v  a 2s .  com*/
        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:com.ysy.classpower_utils.search_view.OwnSearchViewLayout.java

private void showContentFragment() {
    final FragmentTransaction transaction = mFragmentManager.beginTransaction();
    transaction.setCustomAnimations(xyz.sahildave.widget.R.animator.fade_in,
            xyz.sahildave.widget.R.animator.fade_out);
    transaction.replace(xyz.sahildave.widget.R.id.search_expanded_content, mExpandedContentFragment);
    mExpandedContentFragment.setHasOptionsMenu(false);
    transaction.commit();/*from  w  w  w  .jav a 2  s. c o  m*/
}

From source file:itcr.gitsnes.MainActivity.java

public void add_games(MenuItem item) {
    AddGame new_fragment = new AddGame();
    FragmentTransaction transaction = getFragmentManager().beginTransaction();
    transaction.replace(R.id.placeholder, new_fragment);
    transaction.addToBackStack(null);/*w  w  w .  j  a  v a2s.  c o m*/
    transaction.commit();

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

}

From source file:us.cboyd.android.dicom.DcmBrowser.java

public void onFileSelected(int position, ArrayList<String> fileList, File currDir) {
    // The user selected a DICOM file from the DcmListFragment
    position -= 1;/*w  w  w  . jav a2s  .co  m*/
    if ((position < 0) || (position > fileList.size())) {
        // TODO: Error
        return;
    }

    if (mFragmented && mListFragment.isVisible()) {
        // If we're in the one-pane layout and need to swap fragments

        // Enable the Home/Up button to allow the user to go back to 
        ActionBar actionBar = getActionBar();
        actionBar.setHomeButtonEnabled(true);
        actionBar.setDisplayHomeAsUpEnabled(true);

        // Create fragment and give it an argument for the selected article
        Bundle args = new Bundle();
        args.putInt(DcmVar.POSITION, position);
        args.putStringArrayList(DcmVar.FILELIST, fileList);
        args.putString(DcmVar.CURRDIR, currDir.getPath());
        mInfoFragment.setArguments(args);
        FragmentTransaction transaction = getFragmentManager().beginTransaction();

        // Replace whatever is in the fragment_container view with this fragment,
        // and add the transaction to the back stack so the user can navigate back
        transaction.replace(R.id.fragment_container, mInfoFragment);
        transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
        transaction.addToBackStack(null).commit();

        // set up the drawer's list view with items and click listener
        mDrawerList.setAdapter(mListFragment.getListAdapter());
    } else {
        // If we're in the two-pane layout or already displaying the DcmInfoFragment

        // Call a method in the DcmInfoFragment to update its content
        mInfoFragment.updateDicomInfo(position, fileList, currDir.getPath());
    }
    setTitle(fileList.get(position));
}

From source file:itcr.gitsnes.MainActivity.java

public void advanced_query(MenuItem item) {

    SearchFrame new_fragment = new SearchFrame();
    FragmentTransaction transaction = getFragmentManager().beginTransaction();
    transaction.replace(R.id.placeholder, new_fragment);
    transaction.addToBackStack(null);/* ww  w .j a  v  a  2s .  co m*/
    transaction.commit();

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

}

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

/**
 * //from  w  ww.  j a v a2  s  .com
 * @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();
    }
}