Java Code Examples for android.app.FragmentTransaction#replace()

The following examples show how to use android.app.FragmentTransaction#replace() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ChatterBoxMainActivity.java    From pubnub-android-chat with MIT License 6 votes vote down vote up
@Override
public void connectedToRoom(String roomTitle, String roomChannelForHereNow) {

    connectedToRoom = true;

    Room r = new Room();
    r.setRoomName(roomChannelForHereNow);
    r.setRoomTitle(roomTitle);
    r.setActive(true);

    currentlyHostedRooms.put(roomChannelForHereNow, r);

    whoIsOnelineFragment = WhoIsOnelineFragment.newInstance(currentUserProfile,roomChannelForHereNow,roomTitle);
    whoIsOnelineFragment.setCurrentUserProfile(currentUserProfile);
    FragmentManager fm = getFragmentManager();
    FragmentTransaction fragmentTransaction = fm.beginTransaction();
    fragmentTransaction.replace(R.id.whos_online_fragment_container, whoIsOnelineFragment);
    fragmentTransaction.commit();

    getSupportActionBar().setTitle(r.getRoomTitle());
}
 
Example 2
Source File: MainActivity.java    From trekarta with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void showMarkerInformation(@NonNull GeoPoint point, @Nullable String name) {
    if (mFragmentManager.getBackStackEntryCount() > 0) {
        popAll();
    }
    Bundle args = new Bundle(3);
    args.putDouble(MarkerInformation.ARG_LATITUDE, point.getLatitude());
    args.putDouble(MarkerInformation.ARG_LONGITUDE, point.getLongitude());
    args.putString(MarkerInformation.ARG_NAME, name);
    Fragment fragment = Fragment.instantiate(this, MarkerInformation.class.getName(), args);
    fragment.setEnterTransition(new Slide());
    FragmentTransaction ft = mFragmentManager.beginTransaction();
    ft.replace(R.id.contentPanel, fragment, "markerInformation");
    ft.addToBackStack("markerInformation");
    ft.commit();
    updateMapViewArea();
}
 
Example 3
Source File: FileManagerActivityBase.java    From edslite with GNU General Public License v2.0 6 votes vote down vote up
protected void showSecondaryFragment(Fragment f, String tag)
{
       FragmentTransaction trans = getFragmentManager().beginTransaction();
       trans.replace(R.id.fragment2, f, tag);
       View panel = findViewById(R.id.fragment2);
       if(panel!=null)
           panel.setVisibility(View.VISIBLE);
       if(!_isLargeScreenLayout)
       {
           panel = findViewById(R.id.fragment1);
           if(panel!=null)
               panel.setVisibility(View.GONE);
       }
       trans.disallowAddToBackStack();
       trans.commit();
   }
 
Example 4
Source File: RssfeedActivity.java    From codeexamples-android with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void onRssItemSelected(String text) {
    stateFragment.lastSelection = text;
    if (getResources().getBoolean(R.bool.twoPaneMode)) {
        DetailFragment fragment = (DetailFragment) getFragmentManager()
                .findFragmentById(R.id.detailFragment);
        fragment.setText(text);
    } else {
        // replace the fragment
        // Create fragment and give it an argument for the selected article
        DetailFragment newFragment = new DetailFragment();
        Bundle args = new Bundle();
        args.putString(DetailFragment.EXTRA_TEXT, text);
        newFragment.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, newFragment);
        transaction.addToBackStack(null);

        // Commit the transaction
        transaction.commit();
    }
}
 
Example 5
Source File: Launcher.java    From TurboLauncher with Apache License 2.0 6 votes vote down vote up
public void onClickTransitionEffectButton(View v, final boolean pageOrDrawer) {
	Bundle bundle = new Bundle();
	bundle.putBoolean(
			TransitionEffectsFragment.PAGE_OR_DRAWER_SCROLL_SELECT,
			pageOrDrawer);
	FragmentManager fragmentManager = getFragmentManager();
	FragmentTransaction fragmentTransaction = fragmentManager
			.beginTransaction();

	mTransitionEffectsFragment = new TransitionEffectsFragment();
	mTransitionEffectsFragment.setArguments(bundle);
	fragmentTransaction.setCustomAnimations(0, 0);
	fragmentTransaction.replace(R.id.launcher, mTransitionEffectsFragment,
			TransitionEffectsFragment.TRANSITION_EFFECTS_FRAGMENT);
	fragmentTransaction.commit();
}
 
Example 6
Source File: FragmentStack.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
void addFragmentToStack() {
    mStackLevel++;

    // Instantiate a new fragment.
    Fragment newFragment = CountingFragment.newInstance(mStackLevel);

    // Add the fragment to the activity, pushing this transaction
    // on to the back stack.
    FragmentTransaction ft = getFragmentManager().beginTransaction();
    ft.replace(R.id.simple_fragment, newFragment);
    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
    ft.addToBackStack(null);
    ft.commit();
}
 
Example 7
Source File: FragmentStack.java    From android-test with Apache License 2.0 5 votes vote down vote up
void addFragmentToStack() {
  stackLevel++;

  // Instantiate a new fragment.
  Fragment newFragment = CountingFragment.newInstance(stackLevel);

  // Add the fragment to the activity, pushing this transaction
  // on to the back stack.
  FragmentTransaction ft = getFragmentManager().beginTransaction();
  ft.replace(R.id.simple_fragment, newFragment);
  ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
  ft.addToBackStack(null);
  ft.commit();
}
 
Example 8
Source File: PreferencesActivity.java    From external-nfc-api with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    prefs.registerOnSharedPreferenceChangeListener(this);

    // Display the fragment as the main content.
    FragmentManager mFragmentManager = getFragmentManager();
    FragmentTransaction mFragmentTransaction = mFragmentManager.beginTransaction();
    PrefsFragment mPrefsFragment = new PrefsFragment();
    mFragmentTransaction.replace(android.R.id.content, mPrefsFragment);
    mFragmentTransaction.commit();

}
 
Example 9
Source File: ConversationsActivity.java    From Conversations with GNU General Public License v3.0 5 votes vote down vote up
private void initializeFragments() {
    FragmentTransaction transaction = getFragmentManager().beginTransaction();
    Fragment mainFragment = getFragmentManager().findFragmentById(R.id.main_fragment);
    Fragment secondaryFragment = getFragmentManager().findFragmentById(R.id.secondary_fragment);
    if (mainFragment != null) {
        if (binding.secondaryFragment != null) {
            if (mainFragment instanceof ConversationFragment) {
                getFragmentManager().popBackStack();
                transaction.remove(mainFragment);
                transaction.commit();
                getFragmentManager().executePendingTransactions();
                transaction = getFragmentManager().beginTransaction();
                transaction.replace(R.id.secondary_fragment, mainFragment);
                transaction.replace(R.id.main_fragment, new ConversationsOverviewFragment());
                transaction.commit();
                return;
            }
        } else {
            if (secondaryFragment instanceof ConversationFragment) {
                transaction.remove(secondaryFragment);
                transaction.commit();
                getFragmentManager().executePendingTransactions();
                transaction = getFragmentManager().beginTransaction();
                transaction.replace(R.id.main_fragment, secondaryFragment);
                transaction.addToBackStack(null);
                transaction.commit();
                return;
            }
        }
    } else {
        transaction.replace(R.id.main_fragment, new ConversationsOverviewFragment());
    }
    if (binding.secondaryFragment != null && secondaryFragment == null) {
        transaction.replace(R.id.secondary_fragment, new ConversationFragment());
    }
    transaction.commit();
}
 
Example 10
Source File: OAuthActivity.java    From box-android-sdk with Apache License 2.0 5 votes vote down vote up
protected void startOAuth() {
    // Use already logged in accounts if not disabled in this activity and not already showing this fragment.
    if (authType != AUTH_TYPE_APP && !getIntent().getBooleanExtra(EXTRA_DISABLE_ACCOUNT_CHOOSING, false) && getFragmentManager().findFragmentByTag(CHOOSE_AUTH_TAG) == null){
        Map<String, BoxAuthenticationInfo> map = BoxAuthentication.getInstance().getStoredAuthInfo(this);
        if (SdkUtils.isEmptyString(getIntent().getStringExtra(EXTRA_USER_ID_RESTRICTION)) && map != null && map.size() > 0) {
            FragmentTransaction transaction = getFragmentManager().beginTransaction();
            transaction.replace(R.id.oauth_container,ChooseAuthenticationFragment.createAuthenticationActivity(this), CHOOSE_AUTH_TAG);
            transaction.addToBackStack(CHOOSE_AUTH_TAG);
            transaction.commit();
        }
    }
    switch (authType) {
        case AUTH_TYPE_APP:
            Intent intent = getBoxAuthApp();
            if (intent != null) {
                intent.putExtra(BoxConstants.KEY_CLIENT_ID, mClientId);
                intent.putExtra(BoxConstants.KEY_REDIRECT_URL, mRedirectUrl);
                if (!SdkUtils.isEmptyString(getIntent().getStringExtra(EXTRA_USER_ID_RESTRICTION))) {
                    intent.putExtra(EXTRA_USER_ID_RESTRICTION, getIntent().getStringExtra(EXTRA_USER_ID_RESTRICTION));
                }
                mIsLoggingInViaBoxApp = true;
                startActivityForResult(intent, REQUEST_BOX_APP_FOR_AUTH_CODE);
                break;
            }
        case AUTH_TYPE_WEBVIEW:
            showSpinner();
            this.oauthView = createOAuthView();
            this.oauthClient = createOAuthWebViewClient();
            oauthClient.setOnPageFinishedListener(this);
            oauthView.setWebViewClient(oauthClient);
            if (mSession.getBoxAccountEmail() != null){
                oauthView.setBoxAccountEmail(mSession.getBoxAccountEmail());
            }
            oauthView.authenticate(mClientId, mRedirectUrl);
            break;
        default:
    }
}
 
Example 11
Source File: DonateActivity.java    From Klyph with MIT License 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState)
{
	super.onCreate(savedInstanceState);

	setTitle(R.string.donate_activity_title);

	FragmentTransaction ft = getFragmentManager().beginTransaction();

	DonateFragment donationsFragment = DonateFragment.newInstance(false, GOOGLE_PUBKEY, GOOGLE_CATALOG,
			getResources().getStringArray(R.array.donate_google_catalog_values));
	ft.replace(R.id.fragment_container, donationsFragment, "donationsFragment");

	ft.commit();
}
 
Example 12
Source File: MainActivity.java    From SecondScreen with Apache License 2.0 5 votes vote down vote up
private void createFragments() {
    // Begin a new FragmentTransaction
    FragmentTransaction transaction = getFragmentManager().beginTransaction();

    // This fragment shows ProfileListFragment as a sidebar (only seen in tablet mode landscape)
    if(!(getFragmentManager().findFragmentById(R.id.profileList) instanceof ProfileListFragment))
        transaction.replace(R.id.profileList, new ProfileListFragment(), "ProfileListFragment");

    // This fragment shows ProfileListFragment in the main screen area (only seen on phones and tablet mode portrait),
    // but only if it doesn't already contain ProfileViewFragment or ProfileEditFragment.
    // If ProfileListFragment is already showing in the sidebar, use WelcomeFragment instead
    if(!((getFragmentManager().findFragmentById(R.id.profileViewEdit) instanceof ProfileEditFragment)
            || (getFragmentManager().findFragmentById(R.id.profileViewEdit) instanceof ProfileViewFragment))) {
        SharedPreferences prefMain = U.getPrefMain(this);
        if(prefMain.getBoolean("show-welcome-message", false)
                || (getFragmentManager().findFragmentById(R.id.profileViewEdit) == null
                && findViewById(R.id.layoutMain).getTag().equals("main-layout-large"))
                || ((getFragmentManager().findFragmentById(R.id.profileViewEdit) instanceof ProfileListFragment)
                && findViewById(R.id.layoutMain).getTag().equals("main-layout-large"))) {
            // Show welcome message
            Bundle bundle = new Bundle();
            bundle.putBoolean("show-welcome-message", prefMain.getBoolean("show-welcome-message", false));

            Fragment fragment = new WelcomeFragment();
            fragment.setArguments(bundle);

            transaction.replace(R.id.profileViewEdit, fragment, "NoteListFragment");
        } else if(findViewById(R.id.layoutMain).getTag().equals("main-layout-normal"))
            transaction.replace(R.id.profileViewEdit, new ProfileListFragment(), "NoteListFragment");
    }

    // Commit fragment transaction
    transaction.commit();
}
 
Example 13
Source File: MainActivity.java    From Android-Basics-Codes with Artistic License 2.0 5 votes vote down vote up
public void click2(View v){
	//��ʾfragment02
	//1.����Fragment����
	Fragment02 fragment02 = new Fragment02();
	//2.��ȡFragment������
	FragmentManager fm = getFragmentManager();
	//3.������
	FragmentTransaction ft = fm.beginTransaction();
	//4.������ʾfragment02
	//arg0:������id��Ҳ����֡����
	ft.replace(R.id.fl, fragment02);
	//5.�ύ
	ft.commit();
}
 
Example 14
Source File: ServerFragment.java    From FireFiles with Apache License 2.0 5 votes vote down vote up
public static void show(FragmentManager fm, RootInfo root) {
    final ServerFragment fragment = new ServerFragment();
    final Bundle args = new Bundle();
    args.putParcelable(EXTRA_ROOT, root);
    fragment.setArguments(args);
    final FragmentTransaction ft = fm.beginTransaction();
    ft.replace(R.id.container_directory, fragment);
    ft.commitAllowingStateLoss();
}
 
Example 15
Source File: MainActivity.java    From ShoppingList with Apache License 2.0 5 votes vote down vote up
private void displayCached() {
    CacheListFragment cacheFR = new CacheListFragment();
    android.app.FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction transaction = fragmentManager.beginTransaction();
    transaction.replace(R.id.fragment_container, cacheFR);
    transaction.addToBackStack(null);
    transaction.commit();
}
 
Example 16
Source File: TaskCreateFragment.java    From friendly-plans with GNU General Public License v3.0 5 votes vote down vote up
private void showStepsList(final long taskId) {
    StepListFragment fragment = new StepListFragment();
    Bundle args = new Bundle();
    args.putLong(ActivityProperties.TASK_ID, taskId);
    fragment.setArguments(args);

    FragmentTransaction transaction = getFragmentManager()
            .beginTransaction();
    transaction.replace(R.id.task_container, fragment);
    transaction.addToBackStack(null);
    transaction.commit();
}
 
Example 17
Source File: HiddenSettingsActivity.java    From United4 with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Switches to the passed fragment
 * If the currently shown fragment has the same type as the argument, does nothing. Otherwise,
 * removes the current fragment and makes a new fragment of the passed in type and shows it
 * @param type the fragment to switch to
 * @param arguments arguments to give to the fragment
 */
private void swapScreens(FragmentType type, @Nullable Bundle arguments) {
    FragmentManager manager = getFragmentManager();
    FragmentTransaction transaction = manager.beginTransaction();
    // if we already have a fragment and that fragment is not the fragment we want to show, remove it
    // otherwise, it is the fragment we want to show, so we're done, just return and abort the transaction
    if (manager.findFragmentByTag("fragment") != null) {
        if (((HiddenSettingsFragment) manager.findFragmentByTag("fragment")).getType() != type) {
            transaction.remove(manager.findFragmentByTag("fragment"));
        } else {
            return;
        }
    }
    // Make a new fragment
    Fragment newFragment = null;
    switch (type) {
        case SETTINGS_LIST:
            newFragment = new SettingsListFragment();
            break;
        case JANITOR_LOGIN:
            newFragment = new JanitorLoginFragment();
            break;
        case THREAD_WATCHER:
            newFragment = new ThreadWatcherFragment();
            break;
        case AWOO_ENDPOINT:
            newFragment = new AwooEndpointFragment();
            break;
        case DEBUG_SETTINGS_LIST:
            newFragment = new DebugSettingsListFragment();
            break;
        case COLOR_LIST:
            newFragment = new ColorListFragment();
            break;
        case PROPERTY_EDITOR:
            newFragment = new PropertyEditorFragment();
            break;
        case PROPERTY_EDITOR_NEW:
            newFragment = new NewPropertyFragment();
            break;
        case PROPERTIES_LIST:
            newFragment = new PropertiesListFragment();
            break;
        case HIDDEN_LIST:
            newFragment = new HiddenThreadListFragment();
            break;
        case NOTIFICATION_SETTINGS:
            newFragment = new NotificationSettingsFragment();
            break;
        case COLOR_PICKER:
            newFragment = new ColorPickerFragment();
            break;
    }
    newFragment.setArguments(arguments);
    // Put the fragment in our layout
    //transaction.add(newFragment, "fragment");
    transaction.replace(R.id.userscript_activity_main_fragment, newFragment, "fragment");
    transaction.addToBackStack("fragment"); // TODO is this needed?
    transaction.commit();
}
 
Example 18
Source File: RecentsCreateFragment.java    From FireFiles with Apache License 2.0 4 votes vote down vote up
public static void show(FragmentManager fm) {
    final RecentsCreateFragment fragment = new RecentsCreateFragment();
    final FragmentTransaction ft = fm.beginTransaction();
    ft.replace(R.id.container_directory, fragment);
    ft.commitAllowingStateLoss();
}
 
Example 19
Source File: MainUI.java    From AnLinux-App with Apache License 2.0 4 votes vote down vote up
protected void newFragment(int position){

        Fragment fragment;
        FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();

        switch(position){

            case 0:
                fragment = new DashBoard();
                fragmentTransaction.replace(R.id.fragmentHolder, fragment);
                fragmentTransaction.addToBackStack(null);
                fragmentTransaction.commit();
                break;

            case 1:
                fragment = new About();
                fragmentTransaction.replace(R.id.fragmentHolder, fragment);
                fragmentTransaction.addToBackStack(null);
                fragmentTransaction.commit();
                break;

            case 2:
                fragment = new DesktopEnvironment();
                fragmentTransaction.replace(R.id.fragmentHolder, fragment);
                fragmentTransaction.addToBackStack(null);
                fragmentTransaction.commit();
                break;

            case 3:
                fragment = new WindowManager();
                fragmentTransaction.replace(R.id.fragmentHolder, fragment);
                fragmentTransaction.addToBackStack(null);
                fragmentTransaction.commit();
                break;

            case 4:
                fragment = new Uninstaller();
                fragmentTransaction.replace(R.id.fragmentHolder, fragment);
                fragmentTransaction.addToBackStack(null);
                fragmentTransaction.commit();
                break;

            case 5:
                fragment = new SSH();
                fragmentTransaction.replace(R.id.fragmentHolder, fragment);
                fragmentTransaction.addToBackStack(null);
                fragmentTransaction.commit();
                break;

            case 6:
                fragment = new Patches();
                fragmentTransaction.replace(R.id.fragmentHolder, fragment);
                fragmentTransaction.addToBackStack(null);
                fragmentTransaction.commit();
                break;

            case 7:
                fragment = new SU();
                fragmentTransaction.replace(R.id.fragmentHolder, fragment);
                fragmentTransaction.addToBackStack(null);
                fragmentTransaction.commit();
                break;

            case 8:
                fragment = new RootfsDownload();
                fragmentTransaction.replace(R.id.fragmentHolder, fragment);
                fragmentTransaction.addToBackStack(null);
                fragmentTransaction.commit();
                break;
        }
    }
 
Example 20
Source File: WorldActivity.java    From blocktopograph with GNU Affero General Public License v3.0 4 votes vote down vote up
/** Open NBT editor fragment for the given editableNBT */
public void openNBTEditor(EditableNBT editableNBT){

    // see changeContentFragment(callback)
    this.confirmContentClose = getString(R.string.confirm_close_nbt_editor);

    EditorFragment editorFragment = new EditorFragment();
    editorFragment.setEditableNBT(editableNBT);

    FragmentTransaction transaction = getFragmentManager().beginTransaction();
    transaction.replace(R.id.world_content, editorFragment);
    transaction.addToBackStack(null);

    transaction.commit();

}