Example usage for android.app FragmentTransaction commit

List of usage examples for android.app FragmentTransaction commit

Introduction

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

Prototype

public abstract int commit();

Source Link

Document

Schedules a commit of this transaction.

Usage

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.
 */// ww w  .j ava 2 s  .  c  om
@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:de.azapps.mirakel.settings.model_settings.generic_list.GenericModelListActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    if (MirakelCommonPreferences.isDark()) {
        setTheme(R.style.AppBaseThemeDARK);
    }/*from   www. j a  va2 s  . co  m*/
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_generic_model_twopane);
    // Show the Up button in the action bar.
    getActionBar().setDisplayHomeAsUpEnabled(true);
    mDetailContainer = (FrameLayout) findViewById(R.id.generic_model_detail_container);

    mTwoPane = MirakelCommonPreferences.isTablet();
    mDetailContainer.setVisibility(mTwoPane ? View.VISIBLE : View.GONE);
    final FragmentTransaction transaction = getFragmentManager().beginTransaction()
            .replace(R.id.generic_model_list_container, new GenericModelListFragment<T>());
    if (mTwoPane) {
        if (!isSupport()) {
            transaction.replace(R.id.generic_model_detail_container, instanceDetail(getDefaultItem()));
        } else {
            getSupportFragmentManager().beginTransaction()
                    .replace(R.id.generic_model_detail_container, instanceSupportDetail(getDefaultItem()))
                    .commit();
        }
    }
    transaction.commit();
}

From source file:org.jp.liteframe.LiteActivity.java

/**
 * Fragment?/*from w w  w  . j a  va  2s . c o m*/
 *
 * @param resView        ??
 * @param targetFragment ??Fragment
 */
public void changeFragment(int resView, LiteFragment targetFragment) {
    if (targetFragment.equals(mCurrentLiteFragment)) {
        return;
    }
    FragmentTransaction transaction = getFragmentManager().beginTransaction();
    if (!targetFragment.isAdded()) {
        transaction.add(resView, targetFragment, targetFragment.getClass().getName());
    }
    if (targetFragment.isHidden()) {
        transaction.show(targetFragment);
        targetFragment.onChange();
    }
    if (mCurrentLiteFragment != null && mCurrentLiteFragment.isVisible()) {
        transaction.hide(mCurrentLiteFragment);
    }
    mCurrentLiteFragment = targetFragment;
    transaction.commit();
}

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  ww  .j av  a2 s.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:net.nakama.duckdroid.ui.Duckdroid.java

/**
 * /*w w  w.  j  av a2  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:us.shandian.blacklight.ui.main.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    if (hasSmartBar()) {
        getWindow().setUiOptions(ActivityInfo.UIOPTION_SPLIT_ACTION_BAR_WHEN_NARROW);
    }/*from  w  w w  .  j a  v a  2 s.  com*/

    Utility.initDarkMode(this);

    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    // Tint
    Utility.enableTint(this);

    // Detect if the user chose to use right-handed mode
    boolean rightHanded = Settings.getInstance(this).getBoolean(Settings.RIGHT_HANDED, false);
    mDrawerGravity = rightHanded ? Gravity.RIGHT : Gravity.LEFT;

    // Set gravity
    View nav = findViewById(R.id.nav);
    DrawerLayout.LayoutParams p = (DrawerLayout.LayoutParams) nav.getLayoutParams();
    p.gravity = mDrawerGravity;
    nav.setLayoutParams(p);

    // Initialize naviagtion drawer
    mDrawer = (DrawerLayout) findViewById(R.id.drawer);
    mToggle = new ActionBarDrawerToggle(this, mDrawer, R.drawable.ic_drawer_l, 0, 0) {
        @Override
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            getActionBar().show();
            invalidateOptionsMenu();
            if (mLastChoice == null) {
                mLastChoice = (TextView) mMy.getChildAt(0);
                mLastChoice.getPaint().setFakeBoldText(true);
                mLastChoice.invalidate();
            }

            ((HomeTimeLineFragment) mFragments[0]).hideFAB();
        }

        @Override
        public void onDrawerClosed(View drawerView) {
            invalidateOptionsMenu();

            if (mNext == 0) {
                ((HomeTimeLineFragment) mFragments[0]).showFAB();
            }
        }
    };
    mDrawer.setDrawerListener(mToggle);

    if (mDrawerGravity == Gravity.LEFT) {
        mDrawer.setDrawerShadow(R.drawable.drawer_shadow, Gravity.LEFT);
    }

    mMy = (ListView) findViewById(R.id.list_my);
    mAtMe = (ListView) findViewById(R.id.list_at_me);
    mOther = (ListView) findViewById(R.id.list_other);
    mMy.setVerticalScrollBarEnabled(false);
    mMy.setChoiceMode(ListView.CHOICE_MODE_NONE);
    mAtMe.setVerticalScrollBarEnabled(false);
    mAtMe.setChoiceMode(ListView.CHOICE_MODE_NONE);
    mOther.setVerticalScrollBarEnabled(false);
    mOther.setChoiceMode(ListView.CHOICE_MODE_NONE);

    mMy.setOnItemClickListener(this);
    mAtMe.setOnItemClickListener(this);
    mOther.setOnItemClickListener(this);

    // My account
    mName = (TextView) findViewById(R.id.my_name);
    mName.getPaint().setFakeBoldText(true);
    mAvatar = (ImageView) findViewById(R.id.my_avatar);
    mLoginCache = new LoginApiCache(this);
    mUserCache = new UserApiCache(this);
    initList();
    new InitializerTask().execute();
    new GroupsTask().execute();

    findViewById(R.id.my_account).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (mUser != null) {
                Intent i = new Intent();
                i.setAction(Intent.ACTION_MAIN);
                i.setClass(MainActivity.this, UserTimeLineActivity.class);
                i.putExtra("user", mUser);
                startActivity(i);
            }
        }

    });

    // Initialize ActionBar Style
    getActionBar().setHomeButtonEnabled(true);

    // Ignore first spinner event
    mIgnore = true;

    // Fragments
    mFragments[0] = new HomeTimeLineFragment();
    mFragments[1] = new CommentTimeLineFragment();
    mFragments[2] = new FavListFragment();
    mFragments[3] = new DirectMessageUserFragment();
    mFragments[4] = new MentionsTimeLineFragment();
    mFragments[5] = new CommentMentionsTimeLineFragment();
    mFragments[6] = new SearchFragment();
    mManager = getFragmentManager();

    FragmentTransaction ft = mManager.beginTransaction();
    for (Fragment f : mFragments) {
        ft.add(R.id.container, f);
        ft.hide(f);
    }
    ft.commit();
    switchTo(0);
}

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

public void addAdminFragment() {
    Fragment frag = null;/*from  ww  w  .j a  va2 s  .com*/
    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: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 source file:cz.zcu.kiv.eeg.mobile.base.ui.NavigationActivity.java

public boolean openSection(int itemPosition) {
    Intent intent;/* w  w  w  . j  a  v  a 2 s  .  c  o  m*/

    if (itemPosition != previousFragment) {
        FragmentManager fragmentManager = getFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
        switch (itemPosition) {
        // dashboard
        case 0:
            DashboardFragment dashboardFrag;
            dashboardFrag = new DashboardFragment();
            fragmentTransaction.replace(R.id.content, dashboardFrag, DashboardFragment.TAG);
            fragmentTransaction.commit();
            previousFragment = itemPosition;
            break;

        // scenarios
        case 1:
            intent = new Intent();
            intent.setClass(this, ScenarioActivity.class);
            startActivity(intent);
            break;

        // experiments
        case 2:
            intent = new Intent();
            intent.setClass(this, ExperimentActivity.class);
            startActivity(intent);
            break;

        // datafile upload
        case 3:
            DataFileUploadFragment dataFileFrag;
            dataFileFrag = new DataFileUploadFragment();

            fragmentTransaction.replace(R.id.content, dataFileFrag, DataFileUploadFragment.TAG);
            fragmentTransaction.commit();
            previousFragment = itemPosition;
            break;

        // reservations
        case 4:
            ReservationFragment agendaFrag;
            agendaFrag = new ReservationFragment();

            fragmentTransaction.replace(R.id.content, agendaFrag, ReservationFragment.TAG);
            fragmentTransaction.commit();
            previousFragment = itemPosition;
            break;

        // application settings
        case 5:
            intent = new Intent();
            intent.setClass(this, SettingsActivity.class);
            startActivity(intent);
            break;
        default:
            return false;
        }
    }
    drawerLayout.closeDrawer(drawerList);
    return true;
}

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  .  j  a v a 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);
}