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:org.symptomcheck.capstone.ui.SettingsActivity.java

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

    mUser = DAOManager.get().getUser();//  w  w  w .  j ava  2 s .c om

    setContentView(R.layout.activity_settings);

    toolbar = (Toolbar) findViewById(R.id.app_bar);
    setSupportActionBar(toolbar);
    toolbarTitle = (TextView) findViewById(R.id.txt_toolbar_title);
    mToolBarImageView = (ImageView) findViewById(R.id.imageToolBar);
    // enable ActionBar app icon to behave as action to toggle nav drawer
    if (getSupportActionBar() != null) {
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setHomeButtonEnabled(true);
        getSupportActionBar().setDisplayShowTitleEnabled(false);
    }

    if (toolbarTitle != null)
        toolbarTitle.setText(getString(R.string.action_settings));
    // Display the fragment as the main content.
    if (mToolBarImageView != null) {
        mToolBarImageView.setVisibility(View.GONE);
        //mToolBarImageView.setOval(false);
        Picasso.with(this).load(R.drawable.ic_action_settings)
                //.resize(96, 96)
                //.centerCrop()
                //.transform(transformation)
                .into(mToolBarImageView);
    }
    // here we would customize Settings Screen according to User type (PATIENT, DOCTOR, ADMIN)
    FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
    if (mUser != null) {
        //TODO#BPR_1
        switch (mUser.getUserType()) {
        case PATIENT:
            fragmentTransaction
                    .replace(R.id.content_settings_checkin_reminder, new CheckInReminderPreferenceFragment()) //TODO#FDAR_2
                    .replace(R.id.content_settings_data_sync, new DataSyncPreferenceFragment())
                    .replace(R.id.content_settings_notification, new NotificationPreferenceFragment());
            break;
        case DOCTOR:
            fragmentTransaction.replace(R.id.content_settings_data_sync, new DataSyncPreferenceFragment())
                    .replace(R.id.content_settings_notification, new NotificationPreferenceFragment());
            break;
        case ADMIN:
            fragmentTransaction
                    .replace(R.id.content_settings_checkin_reminder, new CheckInReminderPreferenceFragment())
                    .replace(R.id.content_settings_data_sync, new DataSyncPreferenceFragment())
                    .replace(R.id.content_settings_notification, new NotificationPreferenceFragment());
            break;
        case UNKNOWN:
            fragmentTransaction.replace(R.id.content_settings_notification,
                    new NotificationPreferenceFragment());
            break;
        }
    } else {
        fragmentTransaction.replace(R.id.content_settings_notification, new NotificationPreferenceFragment());
    }
    fragmentTransaction.commit();
}

From source file:produvia.com.scanner.DevicesActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mErrorOccurred = false;//from  ww w .  j  av a2 s.  co m
    mErrorMessage = "";
    setContentView(R.layout.activity_devices);

    listFragment = new DevicesFragment();
    FragmentTransaction transaction = getFragmentManager().beginTransaction();
    transaction.replace(R.id.main_fragment, listFragment);
    transaction.addToBackStack(null);

    // Commit the transaction
    transaction.commit();
    //Start running the discovery service in the background
    //any discovered services will be reported on the onTaskUpdate callback:
    boolean run_discovery = true;
    Calendar time_now = Calendar.getInstance();
    if (mScanCycleCounter > 0 && mLastScanStartedAt != null) {

        if (time_now.getTimeInMillis()
                - mLastScanStartedAt.getTimeInMillis() < MINIMUM_TIME_BETWEEN_SCANS_MILLIS)
            run_discovery = false;
    }
    if (run_discovery) {

        mLastScanStartedAt = time_now;
        showScanProgress(true);
        WeaverSdkApi.discoveryService(this, true);
    }
    //fetch the services that have already been discovered in previous scans
    //these services will be returned in the onTaskCompleted callback:
    WeaverSdkApi.servicesGet(this, null);
}

From source file:com.luorrak.ouroboros.thread.ThreadFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.action_refresh: {
        getThread(resto, boardName);/* www .  j  a  v a  2 s . c  o  m*/
        break;
    }
    case R.id.action_scroll_bottom: {
        recyclerView.scrollToPosition(threadAdapter.getItemCount() - 1);
        break;
    }
    case R.id.action_scroll_top: {
        recyclerView.scrollToPosition(0);
        break;
    }
    case R.id.action_reply: {
        Intent intent = new Intent(getActivity(), ReplyCommentActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.putExtra(Util.INTENT_THREAD_NO, resto);
        intent.putExtra(Util.INTENT_BOARD_NAME, boardName);
        getActivity().startActivity(intent);
        break;
    }
    case R.id.action_gallery: {
        GalleryFragment galleryFragment = new GalleryFragment().newInstance(boardName, resto);
        FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
        fragmentTransaction.replace(R.id.placeholder_card, galleryFragment).addToBackStack("galleryfragment")
                .commit();
        break;
    }
    case R.id.action_save_all_images: {
        if (ContextCompat.checkSelfPermission(getActivity(),
                Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED
                || ContextCompat.checkSelfPermission(getActivity(),
                        Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
            ActivityCompat
                    .requestPermissions(getActivity(),
                            new String[] { Manifest.permission.READ_EXTERNAL_STORAGE,
                                    Manifest.permission.WRITE_EXTERNAL_STORAGE },
                            Util.REQUEST_STORAGE_PERMISSION);
        } else {
            showDownloadAllDialog();
        }
        break;
    }
    case R.id.action_external_browser: {
        Intent browserIntent = new Intent(Intent.ACTION_VIEW,
                Uri.parse(ChanUrls.getThreadUrlExternal(boardName, resto)));
        startActivity(browserIntent);
        break;
    }
    case R.id.menu_item_share: {
        Intent shareIntent = new Intent(Intent.ACTION_SEND);
        shareIntent.setType("text/plain");
        String shareBody = ChanUrls.getThreadUrlExternal(boardName, resto);
        shareIntent.putExtra(Intent.EXTRA_TEXT, shareBody);
        startActivity(Intent.createChooser(shareIntent, "Share via"));
        break;
    }
    case R.id.action_add_watchlist: {
        Cursor cursor = infiniteDbHelper.getWatchlistCursor();
        int count = cursor.getCount();
        byte[] serializedMediaList;
        cursor.close();

        Cursor threadcursor = infiniteDbHelper.getThreadCursor(resto);
        serializedMediaList = (threadcursor.getCount() > 0) ? threadcursor
                .getBlob(threadcursor.getColumnIndex(DbContract.ThreadEntry.COLUMN_THREAD_MEDIA_FILES)) : null;

        infiniteDbHelper.insertWatchlistEntry(String.valueOf(getActivity().getTitle()), boardName, resto,
                serializedMediaList, count);
        ((ThreadActivity) getActivity()).updateWatchlist();
        Snackbar.make(getView(), "Thread Added To Watchlist", Snackbar.LENGTH_LONG).show();
        threadcursor.close();

        break;
    }
    case R.id.action_layout_vertical: {
        SettingsHelper.setThreadView(getActivity(), Util.THREAD_LAYOUT_VERTICAL);
        ThreadFragment threadFragment = new ThreadFragment().newInstance(resto, boardName);
        FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
        fragmentTransaction.replace(R.id.placeholder_card, threadFragment).commit();
        break;
    }
    case R.id.action_layout_horizontal: {
        SettingsHelper.setThreadView(getActivity(), Util.THREAD_LAYOUT_HORIZONTAL);
        ThreadFragment threadFragment = new ThreadFragment().newInstance(resto, boardName);
        FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
        fragmentTransaction.replace(R.id.placeholder_card, threadFragment).commit();
        break;
    }
    }
    return true;
}

From source file:com.battlelancer.seriesguide.ui.SeriesGuidePreferences.java

public void switchToSettings(String settingsId) {
    Bundle args = new Bundle();
    args.putString("settings", settingsId);
    Fragment f = new SettingsFragment();
    f.setArguments(args);/*from  w ww  .j a v  a  2s . c om*/
    FragmentTransaction ft = getFragmentManager().beginTransaction();
    ft.replace(R.id.content_frame, f);
    ft.addToBackStack(null);
    ft.commit();
}

From source file:org.floens.chan.ui.activity.BoardActivity.java

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

    boardFragment = ThreadFragment.newInstance(this);
    threadFragment = ThreadFragment.newInstance(this);

    FragmentTransaction ft = getFragmentManager().beginTransaction();
    ft.replace(R.id.left_pane, boardFragment);
    ft.replace(R.id.right_pane, threadFragment);
    ft.commitAllowingStateLoss();/*  w ww  .j  a  v  a 2s .c o  m*/

    final ActionBar actionBar = getActionBar();
    actionBar.setListNavigationCallbacks(
            new ArrayAdapter<String>(actionBar.getThemedContext(), R.layout.board_select_spinner,
                    android.R.id.text1, ChanApplication.getBoardManager().getSavedKeys()),
            this);

    updatePaneState();
    updateActionBarState();

    Intent startIntent = getIntent();
    Uri startUri = startIntent.getData();

    if (savedInstanceState != null) {
        threadLoadable.readFromBundle(this, "thread", savedInstanceState);
        startLoadingThread(threadLoadable);

        // Reset page etc.
        Loadable tmp = new Loadable();
        tmp.readFromBundle(this, "board", savedInstanceState);
        loadBoard(tmp.board);
    } else {
        if (startUri != null) {
            handleIntentURI(startUri);
        }

        if (boardLoadable.mode == Loadable.Mode.INVALID) {
            List<String> savedValues = ChanApplication.getBoardManager().getSavedValues();
            if (savedValues.size() > 0) {
                loadBoard(savedValues.get(0));
            }
        }
    }
}

From source file:com.luorrak.ouroboros.thread.ThreadActivity.java

public void doPositiveClickInternal(String threadNo, String boardName) {
    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

    //clear dialog fragments
    fragmentManager.popBackStack("threadDialog", FragmentManager.POP_BACK_STACK_INCLUSIVE);
    if (!threadNo.equals("0")) {
        threadDepth = threadDepth + 1;/*  www.  j  a  v  a  2 s  .  co m*/
        threadFragment = new ThreadFragment().newInstance(threadNo, boardName);
        fragmentTransaction.replace(R.id.placeholder_card, threadFragment)
                .addToBackStack("threadDepth" + String.valueOf(threadDepth)).commit();
    } else {
        Intent intent = new Intent(this, CatalogActivity.class);
        intent.putExtra(Util.INTENT_BOARD_NAME, boardName);
        startActivity(intent);

    }

}

From source file:tw.example.robert.myapplication.bluetoothchat.BluetoothChatFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setHasOptionsMenu(true);/* w  w w. ja v a 2 s. c o m*/

    FragmentManager ft = getFragmentManager();
    FragmentTransaction transaction = ft.beginTransaction();

    MapsActivity fragment = new MapsActivity();
    transaction.replace(R.id.googleMaps, fragment);
    transaction.commit();

    startTime = System.currentTimeMillis();
    handler.removeCallbacks(updateTimer);
    //Delay
    handler.postDelayed(updateTimer, 1000);
    handler.removeCallbacks(ahead);
    //Delay
    handler.postDelayed(ahead, 1000);

    // Get local Bluetooth adapter
    mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

    // If the adapter is null, then Bluetooth is not supported
    if (mBluetoothAdapter == null) {
        FragmentActivity activity = (FragmentActivity) getActivity();
        Toast.makeText(activity, "Bluetooth is not available", Toast.LENGTH_LONG).show();
        activity.finish();
    } // No bluetooth service

    registerBrocast();

    sensorManager = (SensorManager) getActivity().getSystemService(SENSOR_SERVICE);
}

From source file:es.rgmf.libresportgps.MainActivity.java

/**
 * This method is called when you chose an option in Navigation Drawer.
 *///from w w  w  . ja  v a2 s. c o  m
@Override
public void onNavigationDrawerItemSelected(int position) {
    // update the main content by replacing fragments
    FragmentTransaction transaction = mFragmentManager.beginTransaction();
    switch (position) {
    case 0:
        transaction.replace(R.id.container, TrackListFragment.newInstance());
        break;
    case 1:
        transaction.replace(R.id.container, DataViewFragment.newInstance());
        break;
    case 2:
        transaction.replace(R.id.container, SettingsFragment.newInstance());
    default:
        break;
    }
    // If it selects an item from menu we need to pop the stack of fragments
    // to
    // remove the possible stacked fragment.
    mFragmentManager.popBackStack();
    transaction.commitAllowingStateLoss();
}

From source file:xyz.sahildave.widget.SearchViewLayout.java

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

From source file:de.sourcestream.movieDB.controller.MovieDetailsInfo.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  ww . ja  v  a 2  s .  c  o m*/
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

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

    activity.setLastVisitedSimMovie(similarList.get(position).getId());
    activity.getMovieDetailsFragment().setAddToBackStack(true);
    activity.getMovieDetailsFragment().onSaveInstanceState(new Bundle());
    if (activity.getSearchViewCount())
        activity.incSearchMovieDetails();

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

}