Example usage for android.support.v4.app FragmentTransaction replace

List of usage examples for android.support.v4.app FragmentTransaction replace

Introduction

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

Prototype

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

Source Link

Document

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

Usage

From source file:com.esri.android.ecologicalmarineunitexplorer.map.MapActivity.java

public void showSummary(WaterColumn waterColumn) {
    final FragmentManager fm = getSupportFragmentManager();
    SummaryFragment summaryFragment = (SummaryFragment) fm.findFragmentById(R.id.summary_container);
    if (summaryFragment == null) {
        summaryFragment = SummaryFragment.newInstance();
        mSummaryPresenter = new SummaryPresenter(summaryFragment);
    }/*from w w w  . j a va  2 s  .co  m*/
    mSummaryPresenter.setWaterColumn(waterColumn);

    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();

    // Adjust the map's layout
    FrameLayout mapLayout = (FrameLayout) findViewById(R.id.map_container);
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            0, 7);
    layoutParams.setMargins(0, 0, 36, 0);
    mapLayout.setLayoutParams(layoutParams);
    mapLayout.requestLayout();

    FrameLayout summaryLayout = (FrameLayout) findViewById(R.id.summary_container);
    summaryLayout.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0, 9));
    summaryLayout.requestLayout();

    // Replace whatever is in the summary_container view with this fragment,
    // and add the transaction to the back stack so the user can navigate back
    transaction.replace(R.id.summary_container, summaryFragment);
    transaction.addToBackStack("summary fragment");

    // Commit the transaction
    transaction.commit();

    WaterColumnFragment waterColumnFragment = (WaterColumnFragment) fm
            .findFragmentById(R.id.water_column_linear_layout_top);
    if (waterColumnFragment == null) {
        waterColumnFragment = WaterColumnFragment.newInstance();
    }
    waterColumnFragment.setWaterColumn(waterColumn);
    FragmentTransaction wcTransaction = getSupportFragmentManager().beginTransaction();
    wcTransaction.replace(R.id.column_container, waterColumnFragment);
    wcTransaction.commit();
}

From source file:com.emergencyskills.doe.aed.UI.activity.TabsActivity.java

public void showdrill() {
    ll2.setBackgroundColor(getResources().getColor(R.color.White));
    ll1.setBackgroundColor(getResources().getColor(R.color.FullTransparent));
    ll3.setBackgroundColor(getResources().getColor(R.color.FullTransparent));
    ll4.setBackgroundColor(getResources().getColor(R.color.FullTransparent));
    ll5.setBackgroundColor(getResources().getColor(R.color.FullTransparent));

    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
    DrillsFragment myf = new DrillsFragment();
    transaction.setCustomAnimations(android.R.anim.slide_in_left, android.R.anim.slide_out_right);
    transaction.replace(R.id.frame, myf);

    transaction.commit();/*  ww  w  .  j  a  v a  2  s . c  o  m*/
}

From source file:com.emergencyskills.doe.aed.UI.activity.TabsActivity.java

public void showinstall() {
    ll4.setBackgroundColor(getResources().getColor(R.color.White));
    ll2.setBackgroundColor(getResources().getColor(R.color.FullTransparent));
    ll3.setBackgroundColor(getResources().getColor(R.color.FullTransparent));
    ll1.setBackgroundColor(getResources().getColor(R.color.FullTransparent));
    ll5.setBackgroundColor(getResources().getColor(R.color.FullTransparent));
    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
    NewInstallsFragment myf = new NewInstallsFragment();
    transaction.setCustomAnimations(android.R.anim.slide_in_left, android.R.anim.slide_out_right);
    transaction.replace(R.id.frame, myf);
    transaction.commit();/*from w  w  w.j ava  2s .c  o  m*/
}

From source file:com.emergencyskills.doe.aed.UI.activity.TabsActivity.java

public void showpickupschool() {
    ll1.setBackgroundColor(getResources().getColor(R.color.White));
    ll2.setBackgroundColor(getResources().getColor(R.color.FullTransparent));
    ll3.setBackgroundColor(getResources().getColor(R.color.FullTransparent));
    ll4.setBackgroundColor(getResources().getColor(R.color.FullTransparent));
    ll5.setBackgroundColor(getResources().getColor(R.color.FullTransparent));

    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
    PickSchoolsFragment myf = new PickSchoolsFragment();
    transaction.setCustomAnimations(android.R.anim.slide_in_left, android.R.anim.slide_out_right);
    transaction.replace(R.id.frame, myf);
    transaction.commit();/*w  w w .j a va 2s.  co m*/
}

From source file:com.example.android.imaginarium.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    slidingTabsColorsFragment = new SlidingTabsColorsFragment();
    loginFragment = new LoginFragment();

    mSignInButton = (SignInButton) findViewById(R.id.sign_in_button);

    separation_bar = findViewById(R.id.separation_bar);

    mSignInButton.setOnClickListener(this);
    parentView = (ViewGroup) mSignInButton.getParent();
    parentView.removeView(separation_bar);

    mGoogleApiClient = buildGoogleApiClient();

    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
    loginDisplayed = true;// w  ww . j av a2s  . c om
    notifyServer = false;

    if (savedInstanceState == null) {

        if (mGoogleApiClient != null && mGoogleApiClient.isConnected()) {
            signInUpdateLayout();

            Bundle args = new Bundle();
            args.putString("gid", gid);
            args.putString("friends", friendList);
            slidingTabsColorsFragment.setArguments(args);
            transaction.replace(R.id.sample_content_fragment, slidingTabsColorsFragment);

        } else {
            signOutUpdateLayout();
            transaction.replace(R.id.sample_content_fragment, loginFragment);
        }
        transaction.commit();
    }

}

From source file:com.emergencyskills.doe.aed.UI.activity.TabsActivity.java

public void showpending() {
    ll5.setBackgroundColor(getResources().getColor(R.color.White));
    ll2.setBackgroundColor(getResources().getColor(R.color.FullTransparent));
    ll3.setBackgroundColor(getResources().getColor(R.color.FullTransparent));
    ll4.setBackgroundColor(getResources().getColor(R.color.FullTransparent));
    ll1.setBackgroundColor(getResources().getColor(R.color.FullTransparent));
    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
    PendingUploadsFragment myf = new PendingUploadsFragment();
    transaction.setCustomAnimations(android.R.anim.slide_in_left, android.R.anim.slide_out_right);
    transaction.replace(R.id.frame, myf);
    transaction.commit();//from www  .  j  av a2s  .  com
}

From source file:com.example.angel.parkpanda.MainActivity.java

public void initGoogleMap() {
    supportMapFragment = supportMapFragment.newInstance();
    FragmentManager fragmentManager = getSupportFragmentManager();
    FragmentTransaction FT = fragmentManager.beginTransaction();
    FT.replace(R.id.flContent, supportMapFragment).commit();
    supportMapFragment.getMapAsync(this);
}

From source file:com.dwdesign.tweetings.fragment.StatusFragment.java

@Override
public void onActivityCreated(final Bundle savedInstanceState) {
    mPreferences = getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
    final TweetingsApplication application = getApplication();
    mService = application.getServiceInterface();
    mLazyImageLoader = application.getImageLoaderWrapper();
    mImagesPreviewFragment = (ImagesPreviewFragment) Fragment.instantiate(getActivity(),
            ImagesPreviewFragment.class.getName());
    super.onActivityCreated(savedInstanceState);
    setRetainInstance(true);/*  w w w.ja  v  a2 s .c  om*/
    mLoadMoreAutomatically = mPreferences.getBoolean(PREFERENCE_KEY_LOAD_MORE_AUTOMATICALLY, true);
    final Bundle bundle = getArguments();
    if (bundle != null) {
        mAccountId = bundle.getLong(INTENT_KEY_ACCOUNT_ID);
        mStatusId = bundle.getLong(INTENT_KEY_STATUS_ID);
        bundle.setClassLoader(ParcelableStatus.class.getClassLoader());
        mStatus = bundle.getParcelable(INTENT_KEY_STATUS);
        mImagesPreviewFragment.setStatus(mStatus);
    }
    mInReplyToView.setOnClickListener(this);
    mFollowButton.setOnClickListener(this);
    mProfileView.setOnClickListener(this);
    mLocationView.setOnClickListener(this);
    mRetweetedStatusView.setOnClickListener(this);
    mMenuBar.setOnMenuItemClickListener(this);
    final FragmentManager fm = getFragmentManager();
    final FragmentTransaction ft = fm.beginTransaction();
    ft.replace(R.id.images_preview, mImagesPreviewFragment);
    ft.commit();
    //if (mStatus != null) {
    //displayStatus(mStatus);
    //} else {
    //getStatus(false);
    //}

}

From source file:com.cattle.PhotoSelectionActivity.java

private void replacePrimaryFragment(int id, FragmentTransaction ft) {
    Fragment fragment;/* w w  w. j a  va  2s  .co  m*/

    switch (id) {
    case TAB_SELECTED:
        fragment = new SelectedPhotosFragment();
        break;
    case TAB_UPLOADS:
        fragment = new UploadsFragment();
        break;
    case TAB_PHOTOS:
    default:
        fragment = new UserPhotosFragment();
        break;
    }

    if (null != mPreviouslySelectedTab) {
        final int oldId = (Integer) mPreviouslySelectedTab.getTag();
        final int enterAnim = id > oldId ? R.anim.slide_in_right : R.anim.slide_in_left;
        final int exitAnim = id > oldId ? R.anim.slide_out_left : R.anim.slide_out_right;
        ft.setCustomAnimations(enterAnim, exitAnim);
    }

    ft.replace(R.id.frag_primary, fragment);
}

From source file:androidx.navigation.fragment.FragmentNavigator.java

@SuppressWarnings("deprecation")
@Override/*from w  w  w.  j  a va 2  s.  c o m*/
public void navigate(@NonNull Destination destination, @Nullable Bundle args, @Nullable NavOptions navOptions) {
    final Fragment frag = destination.createFragment(args);
    final FragmentTransaction ft = mFragmentManager.beginTransaction();

    int enterAnim = navOptions != null ? navOptions.getEnterAnim() : -1;
    int exitAnim = navOptions != null ? navOptions.getExitAnim() : -1;
    int popEnterAnim = navOptions != null ? navOptions.getPopEnterAnim() : -1;
    int popExitAnim = navOptions != null ? navOptions.getPopExitAnim() : -1;
    if (enterAnim != -1 || exitAnim != -1 || popEnterAnim != -1 || popExitAnim != -1) {
        enterAnim = enterAnim != -1 ? enterAnim : 0;
        exitAnim = exitAnim != -1 ? exitAnim : 0;
        popEnterAnim = popEnterAnim != -1 ? popEnterAnim : 0;
        popExitAnim = popExitAnim != -1 ? popExitAnim : 0;
        ft.setCustomAnimations(enterAnim, exitAnim, popEnterAnim, popExitAnim);
    }

    ft.replace(mContainerId, frag);

    final @IdRes int destId = destination.getId();
    final boolean initialNavigation = mBackStack.isEmpty();
    final boolean isClearTask = navOptions != null && navOptions.shouldClearTask();
    // TODO Build first class singleTop behavior for fragments
    final boolean isSingleTopReplacement = navOptions != null && !initialNavigation
            && navOptions.shouldLaunchSingleTop() && mBackStack.peekLast() == destId;

    int backStackEffect;
    if (!initialNavigation && !isClearTask && !isSingleTopReplacement) {
        ft.addToBackStack(getBackStackName(destId));
        backStackEffect = BACK_STACK_DESTINATION_ADDED;
    } else if (isSingleTopReplacement) {
        // Single Top means we only want one instance on the back stack
        if (mBackStack.size() > 1) {
            // If the Fragment to be replaced is on the FragmentManager's
            // back stack, a simple replace() isn't enough so we
            // remove it from the back stack and put our replacement
            // on the back stack in its place
            mFragmentManager.popBackStack();
            ft.addToBackStack(getBackStackName(destId));
        }
        backStackEffect = BACK_STACK_UNCHANGED;
    } else {
        backStackEffect = BACK_STACK_DESTINATION_ADDED;
    }
    ft.setReorderingAllowed(true);
    ft.commit();
    // The commit succeeded, update our view of the world
    if (initialNavigation || !isSingleTopReplacement) {
        mBackStack.add(destId);
    }
    dispatchOnNavigatorNavigated(destId, backStackEffect);
}