android.app.FragmentTransaction Java Examples

The following examples show how to use android.app.FragmentTransaction. 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: StepCreateFragmentTest.java    From friendly-plans with GNU General Public License v3.0 6 votes vote down vote up
@Before
public void setUp() {
    Context context = activityRule.getActivity().getApplicationContext();
    stepTemplateRepository = new StepTemplateRepository(daoSessionResource.getSession(context));
    taskTemplateRepository = new TaskTemplateRepository(daoSessionResource.getSession(context));
    assetRepository = new AssetRepository(daoSessionResource.getSession(context));

    taskId = taskTemplateRepository.create(TASK_EXPECTED_NAME,
            Integer.valueOf(TASK_EXPECTED_DURATION_TXT),
            null,
            null,
            1);

    StepCreateFragment fragment = new StepCreateFragment();
    Bundle args = new Bundle();
    args.putLong(ActivityProperties.TASK_ID, taskId);
    fragment.setArguments(args);
    FragmentTransaction transaction = activityRule.getActivity().getFragmentManager().beginTransaction();
    transaction.replace(R.id.task_container, fragment);
    transaction.addToBackStack(null);
    transaction.commit();
}
 
Example #2
Source File: SettingsAppearanceFragment.java    From Rey-MusicPlayer with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate(Bundle onSavedInstanceState) {
    super.onCreate(onSavedInstanceState);
    addPreferencesFromResource(R.xml.settings_appearance);
    mPreferenceManager = this.getPreferenceManager();

    mStartUpScreenPreference = (ListPreference) mPreferenceManager.findPreference("preference_key_startup_screen");
    mArrangeTabsPreference = mPreferenceManager.findPreference("preference_key_tab_items");
    mArrangeTabsPreference.setOnPreferenceClickListener(preference -> {
        FragmentTransaction ft = getActivity().getFragmentManager().beginTransaction();
        SettingArrangeTabsFragment dialog = new SettingArrangeTabsFragment();
        dialog.setOnDismissListener(() -> {
            restartActivity();
        });
        dialog.show(ft, "arrangeTabsFragment");
        return false;
    });
    mStartUpScreenPreference.setOnPreferenceChangeListener((preference, o) -> {
        restartActivity();
        return true;
    });
}
 
Example #3
Source File: PaymentActivity.java    From yandex-money-sdk-android with MIT License 6 votes vote down vote up
private void replaceFragment(@Nullable Fragment fragment, boolean clearBackStack) {
    if (fragment == null || isStateSaved) {
        return;
    }

    Fragment currentFragment = getCurrentFragment();
    FragmentManager manager = getFragmentManager();
    if (clearBackStack) {
        manager.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
    }

    @SuppressLint("CommitTransaction")
    FragmentTransaction transaction = manager.beginTransaction()
            .replace(R.id.ym_container, fragment);
    if (!clearBackStack && currentFragment != null) {
        transaction.addToBackStack(fragment.getTag());
    }
    transaction.commit();
    hideKeyboard();
}
 
Example #4
Source File: QuoteViewerActivity.java    From coursera-android with MIT License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	
	// Get the string arrays with the titles and qutoes
	mTitleArray = getResources().getStringArray(R.array.Titles);
	mQuoteArray = getResources().getStringArray(R.array.Quotes);
	
	setContentView(R.layout.main);

	// Get a reference to the FragmentManager
	FragmentManager fragmentManager = getFragmentManager();
	
	// Begin a new FragmentTransaction
	FragmentTransaction fragmentTransaction = fragmentManager
			.beginTransaction();
	
	// Add the TitleFragment
	fragmentTransaction.add(R.id.title_frame, new TitlesFragment());

	// Add the QuoteFragment
	fragmentTransaction.add(R.id.quote_frame, mQuoteFragment);
	
	// Commit the FragmentTransaction
	fragmentTransaction.commit();
}
 
Example #5
Source File: FileManagerActivityBase.java    From edslite with GNU General Public License v2.0 6 votes vote down vote up
protected boolean hideSecondaryFragment()
{
    Logger.debug(TAG + ": hideSecondaryFragment");
    FragmentManager fm = getFragmentManager();
    Fragment f = fm.findFragmentById(R.id.fragment2);
    if(f!=null)
    {
        FragmentTransaction trans = fm.beginTransaction();
        trans.remove(f);
        trans.commit();
        View panel = findViewById(R.id.fragment1);
        if(panel!=null)
            panel.setVisibility(View.VISIBLE);
        if(!_isLargeScreenLayout)
        {
            panel = findViewById(R.id.fragment2);
            if(panel!=null)
                panel.setVisibility(View.GONE);
        }
        invalidateOptionsMenu();
        return true;
    }
    return false;
}
 
Example #6
Source File: MainActivity.java    From Android-Basics-Codes with Artistic License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
  //1.����Fragment����
    fragment01 = new Fragment01();
	//2.��ȡFragment������
	FragmentManager fm = getFragmentManager();
	//3.������
	FragmentTransaction ft = fm.beginTransaction();
	//4.������ʾfragment01
	//arg0:������id��Ҳ����֡����
	ft.replace(R.id.fl, fragment01);
	//5.�ύ
	ft.commit();
}
 
Example #7
Source File: MainActivity.java    From privacy-friendly-pin-mnemonic with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    this.securityReset = false;

    doFirstRun();

    final FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
    fragmentTransaction.replace(R.id.main_content, new EnterPinFragment(), "EnterPinFragment");
    fragmentTransaction.addToBackStack(null);
    fragmentTransaction.commit();

    overridePendingTransition(0, 0);
}
 
Example #8
Source File: MainActivity.java    From trekarta with GNU General Public License v3.0 6 votes vote down vote up
private void onTrackProperties(String path) {
    logger.debug("onTrackProperties({})", path);
    //TODO Think of better way to find appropriate track
    for (FileDataSource source : mData) {
        if (source.path.equals(path)) {
            mEditedTrack = source.tracks.get(0);
            break;
        }
    }
    if (mEditedTrack == null)
        return;

    Bundle args = new Bundle(2);
    args.putString(TrackProperties.ARG_NAME, mEditedTrack.name);
    args.putInt(TrackProperties.ARG_COLOR, mEditedTrack.style.color);
    Fragment fragment = Fragment.instantiate(this, TrackProperties.class.getName(), args);
    fragment.setEnterTransition(new Fade());
    FragmentTransaction ft = mFragmentManager.beginTransaction();
    ft.replace(R.id.contentPanel, fragment, "trackProperties");
    ft.addToBackStack("trackProperties");
    ft.commit();
    updateMapViewArea();
}
 
Example #9
Source File: GenresList.java    From moviedb-android with Apache License 2.0 6 votes vote down vote up
/**
 * 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.
 */
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
                        long id) {
    if (movieList.getCurrentList().equals("genre/" + genresList.get(position).getId() + "/movies"))
        movieList.setBackState(1);
    else {
        movieList.setCurrentList("genre/" + genresList.get(position).getId() + "/movies");
        movieList.setBackState(0);
    }
    movieList.setTitle(genresList.get(position).getName());
    FragmentManager manager = getFragmentManager();
    FragmentTransaction transaction = manager.beginTransaction();
    Bundle args = new Bundle();
    args.putString("currentList", "genresList");
    movieList.setArguments(args);
    transaction.replace(R.id.frame_container, movieList);
    // add the current transaction to the back stack:
    transaction.addToBackStack("genresList");
    transaction.commit();
    backState = 1;
}
 
Example #10
Source File: AboutFragment.java    From android-wallet-app with GNU General Public License v3.0 6 votes vote down vote up
@OnClick(R.id.about_donation_iota)
public void onAboutDonationIotaClick() {
    if (IOTA.seed != null) {

        QRCode qrCode = new QRCode();
        qrCode.setAddress(IOTA_DONATION_ADDRESS);
        qrCode.setTag(IOTA_DONATION_TAG);

        Bundle bundle = new Bundle();
        bundle.putParcelable(Constants.QRCODE, qrCode);

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

        getActivity().getFragmentManager().beginTransaction()
                .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
                .replace(R.id.container, fragment, null)
                .addToBackStack(null)
                .commit();
    } else
        Snackbar.make(getActivity().findViewById(R.id.drawer_layout), getString(R.string.messages_iota_donation_require_login), Snackbar.LENGTH_LONG).show();
}
 
Example #11
Source File: MemberListActivity.java    From tapchat-android with Apache License 2.0 6 votes vote down vote up
@Subscribe public void onServiceStateChanged(ServiceStateChangedEvent event) {
    TapchatService service = event.getService();
    if (service.getConnectionState() != TapchatService.STATE_LOADED) {
        return;
    }

    long connectionId = getIntent().getLongExtra(BufferFragment.ARG_CONNECTION_ID, -1);
    long bufferId = getIntent().getLongExtra(BufferFragment.ARG_BUFFER_ID, -1);

    mChannel = (ChannelBuffer) service.getConnection(connectionId).getBuffer(bufferId);

    setTitle(getString(R.string.members_title_format, mChannel.getDisplayName()));

    Bundle args = new Bundle();
    args.putLong(BufferFragment.ARG_CONNECTION_ID, mChannel.getConnection().getId());
    args.putLong(BufferFragment.ARG_BUFFER_ID, mChannel.getId());

    MemberListFragment fragment = (MemberListFragment) getFragmentManager().findFragmentByTag("members");
    if (fragment == null) {
        fragment = new MemberListFragment();
        fragment.setArguments(args);
        FragmentTransaction transaction = getFragmentManager().beginTransaction();
        transaction.add(R.id.content, fragment, "members");
        transaction.commit();
    }
}
 
Example #12
Source File: HtmlDialog.java    From HtmlDialog with Apache License 2.0 6 votes vote down vote up
/**
 * The sole constructor for {@code HtmlDialog}.
 *
 * @param fm  The {@code FragmentManager} from the calling activity that is used
 *            internally to show the {@code DialogFragment}.
 */
public HtmlDialog(FragmentManager fm)
{
    // See if there are any DialogFragments from the FragmentManager
    FragmentTransaction ft = fm.beginTransaction();
    Fragment prev = fm.findFragmentByTag(HtmlDialogFragment.TAG_HTML_DIALOG_FRAGMENT);

    // Remove if found
    if (prev != null)
    {
        ft.remove(prev);
        ft.commit();
    }

    mFragmentManager = fm;
}
 
Example #13
Source File: ConfigActivity.java    From Dainty with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    overridePendingTransition(R.anim.left_in, 0);
    super.onCreate(savedInstanceState);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Window window = getWindow();
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
                | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        window.getDecorView().setSystemUiVisibility(
                View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                        | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
        );
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.setStatusBarColor(Color.TRANSPARENT);
    }
    mSwipeBackLayout = new SwipeBackLayout(this);
    FragmentTransaction ft = getFragmentManager().beginTransaction();
    ft.add(android.R.id.content, new SettingsFragment());
    ft.commit();
    PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this);
}
 
Example #14
Source File: MainActivity.java    From QuickLyric with GNU General Public License v3.0 6 votes vote down vote up
private LyricsViewFragment init(FragmentManager fragmentManager, boolean startEmpty) {
    LyricsViewFragment lyricsViewFragment = (LyricsViewFragment) fragmentManager.findFragmentByTag(LYRICS_FRAGMENT_TAG);
    if (lyricsViewFragment == null || lyricsViewFragment.isDetached())
        lyricsViewFragment = new LyricsViewFragment();
    lyricsViewFragment.startEmpty(startEmpty);
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    fragmentTransaction.setCustomAnimations(R.animator.slide_in_end, R.animator.slide_out_start, R.animator.slide_in_start, R.animator.slide_out_end);
    if (!lyricsViewFragment.isAdded()) {
        fragmentTransaction.add(id.main_fragment_container, lyricsViewFragment, LYRICS_FRAGMENT_TAG);
    }

    Fragment[] activeFragments = getActiveFragments();
    displayedFragment = getDisplayedFragment(activeFragments);

    for (Fragment fragment : activeFragments)
        if (fragment != null) {
            if (fragment != displayedFragment && !fragment.isHidden()) {
                fragmentTransaction.hide(fragment);
                fragment.onHiddenChanged(true);
            } else if (fragment == displayedFragment)
                fragmentTransaction.show(fragment);
        }
    fragmentTransaction.commit();
    return lyricsViewFragment;
}
 
Example #15
Source File: FragmentPaymentCart.java    From Ecommerce-Retronight-Android with Creative Commons Zero v1.0 Universal 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
		Bundle savedInstanceState) {
	// TODO Auto-generated method stub

	v =  inflater.inflate(R.layout.fragment_payment_cart, container, false);

	if(activity.IS_CONNECTED) {
		storeClassVariables();
		initUIHandles();
		initUIListeners();
		formatUI();
		activity.removeAppliedCouponToCart();
		loadCart();
		if(isBackFromLogin) {
			FragmentTransaction fragmentTransaction = activity.fragMgr.beginTransaction();
			FragmentPaymentCheckout fragment = new FragmentPaymentCheckout();
			fragmentTransaction.add(R.id.ll_body, fragment, MainActivity.SCREEN_CHECKOUT)
			.addToBackStack(MainActivity.SCREEN_CHECKOUT)
			.commit();
		}
	} else {
		AlertDialog.Builder alert  = new AlertDialog.Builder(v.getContext());
		alert.setMessage(MainActivity.MSG_CART_DISCONNECTED);
		alert.setTitle("Error");
		alert.setPositiveButton(MainActivity.MSG_OK, new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog, int which) {
				//dismiss the dialog
				activity.loadShop();
			}
		});
		alert.create().show();
	}

	return v;

}
 
Example #16
Source File: MainActivity.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void onTabSelected(ActionBar.Tab tab,
		FragmentTransaction fragmentTransaction) {
	// When the given tab is selected, show the tab contents in the
	// container view.
	Fragment fragment = new DummySectionFragment();
	Bundle args = new Bundle();
	args.putInt(DummySectionFragment.ARG_SECTION_NUMBER,
			tab.getPosition() + 1);
	fragment.setArguments(args);
	getFragmentManager().beginTransaction()
			.replace(R.id.container, fragment).commit();
}
 
Example #17
Source File: Activity_Main.java    From Pedometer with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(final Bundle b) {
    super.onCreate(b);
    if (Build.VERSION.SDK_INT >= 26) {
        API26Wrapper.startForegroundService(this, new Intent(this, SensorListener.class));
    } else {
        startService(new Intent(this, SensorListener.class));
    }
    if (b == null) {
        // Create new fragment and transaction
        Fragment newFragment = new Fragment_Overview();
        FragmentTransaction transaction = getFragmentManager().beginTransaction();

        // Replace whatever is in the fragment_container view with this
        // fragment,
        // and add the transaction to the back stack
        transaction.replace(android.R.id.content, newFragment);

        // Commit the transaction
        transaction.commit();
    }


    GoogleApiClient.Builder builder = new GoogleApiClient.Builder(this, this, this);
    builder.addApi(Games.API, Games.GamesOptions.builder().build());
    builder.addScope(Games.SCOPE_GAMES);
    builder.addApi(Fitness.HISTORY_API);
    builder.addApi(Fitness.RECORDING_API);
    builder.addScope(new Scope(Scopes.FITNESS_ACTIVITY_READ_WRITE));

    mGoogleApiClient = builder.build();

    if (BuildConfig.DEBUG && Build.VERSION.SDK_INT >= 23 && PermissionChecker
            .checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) !=
            PermissionChecker.PERMISSION_GRANTED) {
        requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 0);
    }
}
 
Example #18
Source File: FragmentTabHost.java    From V.FlyoutTest with MIT License 5 votes vote down vote up
@Override
public void onTabChanged(String tabId) {
    if (mAttached) {
        FragmentTransaction ft = doTabChanged(tabId, null);
        if (ft != null) {
            ft.commit();
        }
    }
    if (mOnTabChangeListener != null) {
        mOnTabChangeListener.onTabChanged(tabId);
    }
}
 
Example #19
Source File: NetworksActivity.java    From tapchat-android with Apache License 2.0 5 votes vote down vote up
@Override protected void loadFragments() {
    NetworksFragment fragment = (NetworksFragment) getFragmentManager().findFragmentByTag("networks");
    if (fragment == null) {
        FragmentTransaction transaction = getFragmentManager().beginTransaction();
        transaction.add(R.id.content, new NetworksFragment(), "networks");
        transaction.commit();
    }
}
 
Example #20
Source File: MainActivity.java    From AndroidBottomSheet with Apache License 2.0 5 votes vote down vote up
@Override
protected final void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    if (getFragmentManager().findFragmentByTag(FRAGMENT_TAG) == null) {
        Fragment fragment = Fragment.instantiate(this, PreferenceFragment.class.getName());
        FragmentTransaction transaction = getFragmentManager().beginTransaction();
        transaction.replace(R.id.fragment, fragment, FRAGMENT_TAG);
        transaction.commit();
    }
}
 
Example #21
Source File: MoveFragment.java    From FireFiles with Apache License 2.0 5 votes vote down vote up
public static void show(FragmentManager fm, ArrayList<DocumentInfo> docs, boolean deleteAfter) {
	final Bundle args = new Bundle();
	args.putParcelableArrayList(EXTRA_DOC_LIST, docs);
	args.putBoolean(EXTRA_DELETE_AFTER, deleteAfter);
	
	final MoveFragment fragment = new MoveFragment();
	fragment.setArguments(args);

	final FragmentTransaction ft = fm.beginTransaction();
	ft.replace(R.id.container_save, fragment, TAG);
	ft.commitAllowingStateLoss();
}
 
Example #22
Source File: MainActivity.java    From QuickLyric with GNU General Public License v3.0 5 votes vote down vote up
public void updateLyricsFragment(int outAnim, int inAnim, boolean transition, boolean lock, Lyrics lyrics) {
    LyricsViewFragment lyricsViewFragment = (LyricsViewFragment) getFragmentManager().findFragmentByTag(LYRICS_FRAGMENT_TAG);
    FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
    fragmentTransaction.setCustomAnimations(inAnim, outAnim, inAnim, outAnim);
    Fragment activeFragment = getDisplayedFragment(getActiveFragments());
    if (lyricsViewFragment != null && lyricsViewFragment.getView() != null) {
        SharedPreferences preferences = getSharedPreferences("current_music", Context.MODE_PRIVATE);
        String artist = preferences.getString("artist", null);
        String track = preferences.getString("track", null);
        if (lyrics.isLRC() && !(lyrics.getOriginalArtist().equals(artist) && lyrics.getOriginalTitle().equals(track))) {
            LrcView parser = new LrcView(this, null);
            parser.setOriginalLyrics(lyrics);
            parser.setSourceLrc(lyrics.getText());
            lyrics = parser.getStaticLyrics();
        }
        lyricsViewFragment.manualUpdateLock = lock;
        lyricsViewFragment.update(lyrics, lyricsViewFragment.getView(), true);
        if (transition) {
            fragmentTransaction.hide(activeFragment).show(lyricsViewFragment);
            prepareAnimations(activeFragment);
            prepareAnimations(lyricsViewFragment);
        }
        showRefreshFab(true);
        lyricsViewFragment.expandToolbar();
    } else {
        Bundle lyricsBundle = new Bundle();
        try {
            lyricsBundle.putByteArray("lyrics", lyrics.toBytes());
        } catch (IOException e) {
            e.printStackTrace();
        }
        lyricsViewFragment = new LyricsViewFragment();
        lyricsViewFragment.setArguments(lyricsBundle);
        if (!(activeFragment instanceof LyricsViewFragment) && activeFragment != null)
            fragmentTransaction.hide(activeFragment).add(id.main_fragment_container, lyricsViewFragment, LYRICS_FRAGMENT_TAG);
        else
            fragmentTransaction.replace(id.main_fragment_container, lyricsViewFragment, LYRICS_FRAGMENT_TAG);
    }
    fragmentTransaction.commitAllowingStateLoss();
}
 
Example #23
Source File: MapPrefActivity.java    From AIMSICDL with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    MapPrefFragment settingsFragment = new MapPrefFragment();
    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    fragmentTransaction.replace(android.R.id.content, settingsFragment);
    fragmentTransaction.commit();
}
 
Example #24
Source File: SettingsActivity.java    From AIMSICDL with GNU General Public License v3.0 5 votes vote down vote up
private void loadFragment() {
    SettingsFragment settingsFragment = new SettingsFragment();
    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    fragmentTransaction.replace(android.R.id.content, settingsFragment);
    fragmentTransaction.commit();
}
 
Example #25
Source File: FragmentTabHost.java    From V.FlyoutTest with MIT License 5 votes vote down vote up
@Override
protected void onAttachedToWindow() {
    super.onAttachedToWindow();

    String currentTab = getCurrentTabTag();

    // Go through all tabs and make sure their fragments match
    // the correct state.
    FragmentTransaction ft = null;
    for (int i=0; i<mTabs.size(); i++) {
        TabInfo tab = mTabs.get(i);
        tab.fragment = mFragmentManager.findFragmentByTag(tab.tag);
        if (tab.fragment != null && !tab.fragment.isDetached()) {
            if (tab.tag.equals(currentTab)) {
                // The fragment for this tab is already there and
                // active, and it is what we really want to have
                // as the current tab.  Nothing to do.
                mLastTab = tab;
            } else {
                // This fragment was restored in the active state,
                // but is not the current tab.  Deactivate it.
                if (ft == null) {
                    ft = mFragmentManager.beginTransaction();
                }
                ft.detach(tab.fragment);
            }
        }
    }

    // We are now ready to go.  Make sure we are switched to the
    // correct tab.
    mAttached = true;
    ft = doTabChanged(currentTab, ft);
    if (ft != null) {
        ft.commit();
        mFragmentManager.executePendingTransactions();
    }
}
 
Example #26
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 #27
Source File: MainActivity.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
void showDialog(String text) {
    // DialogFragment.show() will take care of adding the fragment
    // in a transaction.  We also want to remove any currently showing
    // dialog, so make our own transaction and take care of that here.
    FragmentTransaction ft = getFragmentManager().beginTransaction();

    DialogFragment newFragment = MyDialogFragment.newInstance(text);

    // Show the dialog.
    newFragment.show(ft, "dialog");
}
 
Example #28
Source File: MainActivity.java    From HeadFirstAndroid with MIT License 5 votes vote down vote up
private void selectItem(int position) {
    // update the main content by replacing fragments
    currentPosition = position;
    Fragment fragment;
    switch(position) {
    case 1:
        fragment = new PizzaMaterialFragment();
        break;
    case 2:
        fragment = new PastaFragment();
        break;
    case 3:
        fragment = new StoresFragment();
        break;
    default:
        fragment = new TopFragment();
    }
    FragmentTransaction ft = getFragmentManager().beginTransaction();
    ft.replace(R.id.content_frame, fragment, "visible_fragment");
    ft.addToBackStack(null);
    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
    ft.commit();
    //Set the action bar title
    setActionBarTitle(position);
    //Close drawer
    drawerLayout.closeDrawer(drawerList);
}
 
Example #29
Source File: OverviewFragment.java    From kolabnotes-android with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void replaceDetailFragment(DetailFragment detail, String noteUID, String notebookUID, ActiveAccount account) {
    FragmentTransaction ft = getFragmentManager(). beginTransaction();
    ft.replace(R.id.details_fragment, detail);
    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        ft.commitNow();
        detail.updateFragmentDataWithNewNoteSelection(noteUID, notebookUID, account);
    }else{
        ft.commit();
        getFragmentManager().executePendingTransactions();
        detail.updateFragmentDataWithNewNoteSelection(noteUID, notebookUID, account);
    }
}
 
Example #30
Source File: OAuthManagerFragmentController.java    From react-native-oauth with MIT License 5 votes vote down vote up
public void requestAuth(HashMap<String,Object> cfg, OAuthManagerOnAccessTokenListener listener) {
  mListener = listener;
  mCfg = cfg;

  runOnMainThread(new Runnable() {
    @Override
    public void run() {
      Log.d(TAG, "fragment manager checking...");
      if (fragmentManager.isDestroyed()) {
        return;
      }

      FragmentTransaction ft = fragmentManager.beginTransaction();
      Fragment prevDialog =
        fragmentManager.findFragmentByTag(TAG);
      
      Log.d(TAG, "previous() Dialog?");
      
      if (prevDialog != null) {
        ft.remove(prevDialog);
      }

      Log.d(TAG, "Creating new Fragment");
      OAuthManagerDialogFragment frag = 
        OAuthManagerDialogFragment.newInstance(context, OAuthManagerFragmentController.this);

      ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
      ft.add(frag, TAG);
      Log.d(TAG, "Committing with State Loss");
      // ft.commit();
      ft.commitAllowingStateLoss();
    }
  });
}