Example usage for android.support.v4.app FragmentManager beginTransaction

List of usage examples for android.support.v4.app FragmentManager beginTransaction

Introduction

In this page you can find the example usage for android.support.v4.app FragmentManager beginTransaction.

Prototype

public abstract FragmentTransaction beginTransaction();

Source Link

Document

Start a series of edit operations on the Fragments associated with this FragmentManager.

Usage

From source file:at.alladin.rmbt.android.about.RMBTAboutFragment.java

private View createView(View view, LayoutInflater inflater) {
    activity = getActivity();/*www .  j a v a 2s  . c  o m*/

    getAppInfo(activity);

    final String clientUUID = String.format("U%s", ConfigHelper.getUUID(activity.getApplicationContext()));

    final String controlServerVersion = ConfigHelper.getControlServerVersion(activity);

    final ListView listView = (ListView) view.findViewById(R.id.aboutList);

    final ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();

    HashMap<String, String> item;
    item = new HashMap<String, String>();
    item.put("title", clientName);
    item.put("text1", this.getString(R.string.about_rtr_line1));
    list.add(item);
    item = new HashMap<String, String>();
    item.put("title", this.getString(R.string.about_version_title));
    item.put("text1", clientVersion);
    item.put("text2", "");
    list.add(item);
    item = new HashMap<String, String>();
    item.put("title", getString(R.string.about_clientid_title));
    item.put("text1", clientUUID);
    item.put("text2", "");
    list.add(item);
    item = new HashMap<String, String>();
    item.put("title", getString(R.string.about_web_title));
    item.put("text1", getString(R.string.about_web_line1));
    item.put("text2", "");
    list.add(item);
    item = new HashMap<String, String>();
    item.put("title", getString(R.string.about_email_title));
    item.put("text1", getString(R.string.about_email_line1));
    item.put("text2", "");
    list.add(item);
    item = new HashMap<String, String>();
    item.put("title", getString(R.string.about_terms_title));
    item.put("text1", getString(R.string.about_terms_line1));
    item.put("text2", "");
    list.add(item);
    item = new HashMap<String, String>();
    item.put("title", getString(R.string.about_git_title));
    item.put("text1", getString(R.string.about_git_line1));
    item.put("text2", "");
    list.add(item);
    item = new HashMap<String, String>();
    item.put("title", getString(R.string.about_dev_title));
    item.put("text1", getString(R.string.about_dev_line1));
    item.put("text2", getString(R.string.about_dev_line2));
    list.add(item);

    final String openSourceSoftwareLicenseInfo = GooglePlayServicesUtil
            .getOpenSourceSoftwareLicenseInfo(getActivity());

    if (openSourceSoftwareLicenseInfo != null) {
        item = new HashMap<String, String>();
        item.put("title", getString(R.string.about_gms_legal_title));
        item.put("text1", getString(R.string.about_gms_legal_line1));
        item.put("text2", "");
        list.add(item);
    }

    if (ConfigHelper.isDevEnabled(getActivity())) {
        item = new HashMap<String, String>();
        item.put("title", getString(R.string.about_test_counter_title));
        item.put("text1", Integer.toString(ConfigHelper.getTestCounter(getActivity())));
        item.put("text2", "");
        list.add(item);
    }

    item = new HashMap<String, String>();
    item.put("title", getString(R.string.about_control_server_version));
    item.put("text1", controlServerVersion != null ? controlServerVersion : "---");
    item.put("text2", "");
    list.add(item);

    sa = new RMBTAboutAdapter(getActivity(), list, R.layout.about_item,
            new String[] { "title", "text1", "text2" }, new int[] { R.id.title, R.id.text1, R.id.text2 });

    listView.setAdapter(sa);

    listView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(final AdapterView<?> l, final View v, final int position, final long id) {

            switch (position) {

            case 1:
                handleHiddenCode();
                break;

            case 2:
                final android.content.ClipboardManager clipBoard = (android.content.ClipboardManager) getActivity()
                        .getSystemService(Context.CLIPBOARD_SERVICE);
                ClipData clip = ClipData.newPlainText("client_uuid", clientUUID);
                clipBoard.setPrimaryClip(clip);
                final Toast toast = Toast.makeText(getActivity(), R.string.about_clientid_toast,
                        Toast.LENGTH_LONG);
                toast.show();
                break;

            case 3:
                startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.about_web_link))));
                break;

            case 4:
                /* Create the Intent */
                final Intent emailIntent = new Intent(Intent.ACTION_SEND);

                /* Fill it with Data */
                emailIntent.setType("plain/text");
                emailIntent.putExtra(Intent.EXTRA_EMAIL,
                        new String[] { getString(R.string.about_email_email) });
                emailIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.about_email_subject));
                emailIntent.putExtra(Intent.EXTRA_TEXT, "");

                /* Send it off to the Activity-Chooser */
                startActivity(Intent.createChooser(emailIntent, getString(R.string.about_email_sending)));

                break;

            case 5:
                final FragmentManager fm = activity.getSupportFragmentManager();
                FragmentTransaction ft;
                ft = fm.beginTransaction();
                ft.replace(R.id.fragment_content, new RMBTTermsFragment(), "terms");
                ft.addToBackStack("terms");
                ft.commit();
                break;

            case 6:
                startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.about_git_link))));
                break;

            case 7:
                startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.about_dev_link))));
                break;

            case 8:
                final String licenseInfo = GooglePlayServicesUtil
                        .getOpenSourceSoftwareLicenseInfo(getActivity());
                AlertDialog.Builder licenseDialog = new AlertDialog.Builder(getActivity());
                licenseDialog.setMessage(licenseInfo);
                licenseDialog.show();
                break;

            default:
                break;
            }
        }

    });

    return view;
}

From source file:com.aosijia.dragonbutler.ui.widget.ActionSheet.java

public void show(FragmentManager manager, String tag) {
    if (!mDismissed || manager.isDestroyed()) {
        return;/*from   w  w  w  .j  ava 2  s  .  co m*/
    }
    mDismissed = false;
    FragmentTransaction ft = manager.beginTransaction();
    ft.add(this, tag);
    ft.addToBackStack(null);
    ft.commitAllowingStateLoss();
}

From source file:com.actionbarsherlock.sample.demos.app.LoaderCustomSupport.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    FragmentManager fm = getSupportFragmentManager();

    // Create the list fragment and add it as our sole content.
    if (fm.findFragmentById(android.R.id.content) == null) {
        AppListFragment list = new AppListFragment();
        fm.beginTransaction().add(android.R.id.content, list).commit();
    }/*  w w  w  . j av  a  2s. co  m*/
}

From source file:com.actionbarsherlock.plus.SherlockDialogPlusFragment.java

/**
 * Display the dialog, adding the fragment to the given FragmentManager.  This
 * is a convenience for explicitly creating a transaction, adding the
 * fragment to it with the given tag, and committing it.  This does
 * <em>not</em> add the transaction to the back stack.  When the fragment
 * is dismissed, a new transaction will be executed to remove it from
 * the activity./*w ww . ja va  2  s.  c om*/
 * @param manager The FragmentManager this fragment will be added to.
 * @param tag The tag for this fragment, as per
 * {@link FragmentTransaction#add(Fragment, String) FragmentTransaction.add}.
 */
public void show(FragmentManager manager, String tag) {
    mDismissed = false;
    mShownByMe = true;
    FragmentTransaction ft = manager.beginTransaction();
    ft.add(this, tag);
    ft.commit();
}

From source file:cn.newgxu.android.bbs.activity.ViewTopicActivity.java

@Override
public void onClick(View v) {
    switch (v.getId()) {
    case R.id.send_reply_icon:
        Toast.makeText(this, "send click!", Toast.LENGTH_SHORT).show();
        break;/*from  w  w  w.j a v a2  s  .  c o m*/
    default:
        Toast.makeText(this, "user click!", Toast.LENGTH_SHORT).show();
        FragmentManager fm = getSupportFragmentManager();
        if (fm.findFragmentByTag(Consts.USER) == null) {
            UserFragment fragment = new UserFragment();
            Bundle args = new Bundle();
            final String str = v.getTag().toString();
            Log.d(TAG, str);
            args.putInt(Consts.UID, Integer.parseInt(str));
            fragment.setArguments(args);
            getSupportActionBar().setTitle(R.string.user_info);
            getSupportActionBar().setSubtitle(null);
            fm.beginTransaction().replace(R.id.fragment_container, fragment, Consts.USER).addToBackStack(null)
                    .commit();
        }
        break;
    }
}

From source file:cf.obsessiveorange.rhcareerfairlayout.ui.activities.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    instance = this;
    //        Pull using: adb pull /sdcard/RHCareerFairLayoutTrace.trace "D:\1. Work\Workspaces\Java Workspace\RHCareerFairLayout\android\RHCareerFairLayout"
    //        Debug.startMethodTracing("RHCareerFairLayoutTrace");

    setContentView(R.layout.activity_main);

    DBManager.setupDBAdapterIfNeeded(this);

    // Setup search, without suggestions, and defaulting to last searched string.
    search = (SearchBox) findViewById(R.id.searchbox);
    search.enableVoiceRecognition(this);
    search.setSearchWithoutSuggestions(true);
    search.setSearchString(getSearchString());

    // Setup toolbar
    toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);/*from  w ww  . ja  va  2  s .  c  o  m*/

    // Setup title
    Term term = DBManager.getTerm();
    if (term == null) {
        reloadData();
        return;
    } else {
        ((TextView) findViewById(R.id.main_txt_title))
                .setText(getString(R.string.career_fair_format, term.getQuarter(), term.getYear()));
    }

    // Setup parent fragment with tabPager
    FragmentManager fm = getSupportFragmentManager();
    if (fm.findFragmentByTag(RHCareerFairLayout.PARENT_FRAGMENT_TAG) == null) {
        FragmentTransaction ft = fm.beginTransaction();
        ft.add(R.id.main_frg_body, new VPParentFragment(), RHCareerFairLayout.PARENT_FRAGMENT_TAG);
        ft.commit();
        fm.executePendingTransactions();
    }
}

From source file:com.app.blockydemo.ui.fragment.FormulaEditorFragment.java

private void onUserDismiss() {
    formulaEditorEditText.endEdit();// w  w w.  ja  v  a 2  s.  c  om
    currentFormula.prepareToRemove();

    FragmentActivity activity = getActivity();
    FragmentManager fragmentManager = activity.getSupportFragmentManager();
    FragmentTransaction fragTransaction = fragmentManager.beginTransaction();
    fragTransaction.hide(this);
    fragTransaction.show(fragmentManager.findFragmentByTag(ScriptFragment.TAG));
    fragTransaction.commit();

    resetActionBar();

    BottomBar.showBottomBar(activity);
    BottomBar.showPlayButton(activity);

}

From source file:ch.corten.aha.worldclock.WorldClockActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    FragmentManager fm = getSupportFragmentManager();
    // Create the list fragment and add it as our sole content.
    if (fm.findFragmentById(android.R.id.content) == null) {
        ClockListFragment list = new ClockListFragment();
        fm.beginTransaction().add(android.R.id.content, list).commit();
    }//  w  w  w . j a v  a  2 s  .co m
}

From source file:android.support.v17.leanback.app.GuidedStepSupportFragment.java

/**
 * Adds the specified GuidedStepSupportFragment as content of Activity; no backstack entry is added so
 * the activity will be dismissed when BACK key is pressed.  The method is typically called in
 * Activity.onCreate() when savedInstanceState is null.  When savedInstanceState is not null,
 * the Activity is being restored,  do not call addAsRoot() to duplicate the Fragment restored
 * by FragmentManager./*  w  w  w.ja  v  a  2 s.c  o m*/
 * {@link #UI_STYLE_ACTIVITY_ROOT} is assigned.
 *
 * Note: currently fragments added using this method must be created programmatically rather
 * than via XML.
 * @param activity The Activity to be used to insert GuidedstepFragment.
 * @param fragment The GuidedStepSupportFragment to be inserted into the fragment stack.
 * @param id The id of container to add GuidedStepSupportFragment, can be android.R.id.content.
 * @return The ID returned by the call FragmentTransaction.commit, or -1 there is already
 *         GuidedStepSupportFragment.
 */
public static int addAsRoot(FragmentActivity activity, GuidedStepSupportFragment fragment, int id) {
    // Workaround b/23764120: call getDecorView() to force requestFeature of ActivityTransition.
    activity.getWindow().getDecorView();
    FragmentManager fragmentManager = activity.getSupportFragmentManager();
    if (fragmentManager.findFragmentByTag(TAG_LEAN_BACK_ACTIONS_FRAGMENT) != null) {
        Log.w(TAG, "Fragment is already exists, likely calling "
                + "addAsRoot() when savedInstanceState is not null in Activity.onCreate().");
        return -1;
    }
    FragmentTransaction ft = fragmentManager.beginTransaction();
    fragment.setUiStyle(UI_STYLE_ACTIVITY_ROOT);
    return ft.replace(id, fragment, TAG_LEAN_BACK_ACTIONS_FRAGMENT).commit();
}

From source file:br.com.split.activities.PickFriendsActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_escolher_amigos_facebook);

    FragmentManager fm = getSupportFragmentManager();

    if (savedInstanceState == null) {
        // First time through, we create our fragment programmatically.
        final Bundle args = getIntent().getExtras();
        friendPickerFragment = new FriendPickerFragment(args);
        friendPickerFragment.setFriendPickerType(FriendPickerType.TAGGABLE_FRIENDS);
        friendPickerFragment.setDoneButtonText(getResources().getString(R.string.acao_feito));
        friendPickerFragment.setTitleText(getResources().getString(R.string.title_activity_facebook_amigos));
        fm.beginTransaction().add(R.id.friend_picker_fragment, friendPickerFragment).commit();
    } else {/*from ww w.j  a  va  2 s  .c o m*/
        // Subsequent times, our fragment is recreated by the framework and already has saved and
        // restored its state, so we don't need to specify args again. (In fact, this might be
        // incorrect if the fragment was modified programmatically since it was created.)
        friendPickerFragment = (FriendPickerFragment) fm.findFragmentById(R.id.friend_picker_fragment);
    }

    friendPickerFragment.setOnErrorListener(new PickerFragment.OnErrorListener() {
        @Override
        public void onError(PickerFragment<?> fragment, FacebookException error) {
            PickFriendsActivity.this.onError(error);
        }
    });

    friendPickerFragment.setOnDoneButtonClickedListener(new PickerFragment.OnDoneButtonClickedListener() {
        @Override
        public void onDoneButtonClicked(PickerFragment<?> fragment) {
            if (friendPickerFragment.getSelection().size() != 0) {
                SplitApplication application = (SplitApplication) getApplication();
                // TODO: Aqui nao devemos desmarcar os amigos ja adicionados ao evento.
                application.setSelectedUsers(friendPickerFragment.getSelection());
                setResult(RESULT_OK);
                finish();
            } else {
                setResult(RESULT_CANCELED);
                finish();
            }

        }
    });
}