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: 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 #2
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 #3
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 #4
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 #5
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 #6
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 #7
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 #8
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 #9
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 #10
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 #11
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 #12
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 #13
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 #14
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 #15
Source File: CertificateManagementActivity.java    From moVirt with Apache License 2.0 5 votes vote down vote up
@Override
public void showDownloadCustomCaDialog(String url, boolean startNewChain) {
    if (getFragmentManager().findFragmentByTag(DOWNLOAD_CA_ISSUER) == null) { // updateViews can call this multiple times
        DownloadCustomCertDialogFragment dialog = new DownloadCustomCertDialogFragment_();
        dialog.setUrl(url);
        dialog.setStartNewChain(startNewChain);
        FragmentTransaction transaction = getFragmentManager().beginTransaction();
        transaction.add(dialog, DOWNLOAD_CA_ISSUER);
        transaction.commitAllowingStateLoss();
    }
}
 
Example #16
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 #17
Source File: FragmentUtil.java    From SmallGdufe-Android with GNU General Public License v3.0 5 votes vote down vote up
/**清空所有fragment*/
public void removeAll(){
    FragmentTransaction ft = fm.beginTransaction();
    for (Fragment f:fs) {
        ft.remove(f);
    }
    ft.commitAllowingStateLoss();
}
 
Example #18
Source File: MainActivity.java    From hex with Apache License 2.0 5 votes vote down vote up
@Override
public void onItemSelectedHandler(HexDrawer.Item item) {
    String collection;

    switch (item) {
        case Settings:
            Intent settingsIntent = new Intent(getApplicationContext(), SettingsActivity.class);
            startActivity(settingsIntent);
            break;
        case About:
            Intent aboutIntent = new Intent(getApplicationContext(), AboutActivity.class);
            startActivity(aboutIntent);
            break;
        default:
            mCurrentItem = item;

            collection = itemToCollection.get(item).toString();
            Bundle bundle = new Bundle();
            bundle.putString(StoryListFragment.CollectionKey, collection);
            StoryListFragment storyListFragment = new StoryListFragment();
            storyListFragment.setArguments(bundle);

            if (getFragmentManager().getBackStackEntryCount() > 0) {
                getFragmentManager().popBackStackImmediate();
            }

            FragmentTransaction transaction = getFragmentManager().beginTransaction();
            transaction.replace(R.id.content_wrapper, storyListFragment);
            transaction.addToBackStack(item.toString());

            transaction.commit();

            break;
    }
}
 
Example #19
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 #20
Source File: DispatcherActivityCallbackTest.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@SuppressLint("CommitTransaction")
private void checkReportFragment(LifecycleDispatcher.DispatcherActivityCallback callback,
        Activity activity) {
    android.app.FragmentManager fm = mock(android.app.FragmentManager.class);
    FragmentTransaction transaction = mock(FragmentTransaction.class);
    when(activity.getFragmentManager()).thenReturn(fm);
    when(fm.beginTransaction()).thenReturn(transaction);
    when(transaction.add(any(Fragment.class), anyString())).thenReturn(transaction);
    callback.onActivityCreated(activity, mock(Bundle.class));
    verify(activity).getFragmentManager();
    verify(fm).beginTransaction();
    verify(transaction).add(any(ReportFragment.class), anyString());
    verify(transaction).commit();
}
 
Example #21
Source File: FragmentUtil.java    From SmallGdufe-Android with GNU General Public License v3.0 5 votes vote down vote up
/**使用本方法前必须先add*/
public void show(Fragment fragment){
    if (currentFragment==fragment) {
        return;//如果是当前fragment,则不重新show一遍了,无意义
    }
    FragmentTransaction ft = fm.beginTransaction();
    for (Fragment f:fs) {
        ft.hide(f);
    }
    ft.show(fragment);
    ft.commit();
    currentFragment = fragment;
}
 
Example #22
Source File: Utils.java    From android-kernel-tweaker with GNU General Public License v3.0 5 votes vote down vote up
public static void showAbout(Activity activity) {

        FragmentManager fm = activity.getFragmentManager();
        FragmentTransaction ft = fm.beginTransaction();
        Fragment prev = fm.findFragmentByTag("dialog_about");
        if (prev != null) {
            ft.remove(prev);
        }
        ft.addToBackStack(null);

        new AboutDialog().show(ft,"dialog_about");
    }
 
Example #23
Source File: FaBoServiceListActivity.java    From DeviceConnect-Android with MIT License 5 votes vote down vote up
/**
 * FaBoが持っているサービスを削除するフラグメントを表示します.
 */
private void showRemoverFragment() {
    FragmentManager mgr = getFragmentManager();
    FragmentTransaction transaction = mgr.beginTransaction();
    RemoverFragment fragment = new RemoverFragment();
    transaction.replace(R.id.fragment_container, fragment);
    transaction.commit();
}
 
Example #24
Source File: FragmentCreatorMock.java    From react-native-navigation with MIT License 5 votes vote down vote up
private ExternalComponent createContent(Activity activity) {
    FrameLayout content = new FrameLayout(activity) {
        @Override
        protected void onAttachedToWindow() {
            super.onAttachedToWindow();
            FragmentManager fm = activity.getFragmentManager();
            FragmentTransaction ft = fm.beginTransaction();
            ft.add(R.id.fragment_screen_content, new SomeFragment());
            ft.commitAllowingStateLoss();
        }
    };
    content.setId(R.id.fragment_screen_content);
    return () -> content;
}
 
Example #25
Source File: MainActivity.java    From hex with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ThemeHelper.applyTheme(this);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = setupToolbar();

    getFragmentManager().addOnBackStackChangedListener(this);

    mCurrentItem = FrontPage;

    if (savedInstanceState != null) {
        mCurrentItem = HexDrawer.Item.valueOf(savedInstanceState.getString(ITEM_KEY));
    }

    mDrawer = new HexDrawer(this, toolbar, mCurrentItem, this);
    mDrawer.build();

    Bundle bundle = new Bundle();
    bundle.putString(StoryListFragment.CollectionKey, itemToCollection.get(mCurrentItem).toString());
    StoryListFragment storyListFragment = new StoryListFragment();
    storyListFragment.setArguments(bundle);

    FragmentTransaction transaction = getFragmentManager().beginTransaction();
    transaction.replace(R.id.content_wrapper, storyListFragment);

    transaction.commit();

    updateDrawer();
    updateToolbarTitle();
}
 
Example #26
Source File: RTProxyImpl.java    From Android-RTEditor with Apache License 2.0 5 votes vote down vote up
@Override
/* @inheritDoc */
public void openDialogFragment(String fragmentTag, DialogFragment fragment) {
    Activity activity = getActivity();
    if (activity != null) {
        FragmentManager fragmentMgr = activity.getFragmentManager();
        FragmentTransaction ft = fragmentMgr.beginTransaction();
        DialogFragment oldFragment = (DialogFragment) fragmentMgr
                .findFragmentByTag(fragmentTag);
        if (oldFragment == null) {
            fragment.show(ft, fragmentTag);
        }
    }
}
 
Example #27
Source File: Constants.java    From rss with GNU General Public License v3.0 5 votes vote down vote up
static
void hideFragments(Fragment... fragments)
{
    FragmentTransaction transaction = s_fragmentManager.beginTransaction();
    for(Fragment fragment : fragments)
    {
        transaction.hide(fragment);
    }
    transaction.commit();
}
 
Example #28
Source File: SyncCustomizationFragment.java    From delion with Apache License 2.0 5 votes vote down vote up
private void displayPassphraseTypeDialog() {
    FragmentTransaction ft = getFragmentManager().beginTransaction();
    PassphraseTypeDialogFragment dialog = PassphraseTypeDialogFragment.create(
            mProfileSyncService.getPassphraseType(),
            mProfileSyncService.getExplicitPassphraseTime(),
            mProfileSyncService.isEncryptEverythingAllowed());
    dialog.show(ft, FRAGMENT_PASSPHRASE_TYPE);
    dialog.setTargetFragment(this, -1);
}
 
Example #29
Source File: MainActivity.java    From driveimageview with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main_fragment);

    FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
    MainFragment mainFragment = new MainFragment();
    fragmentTransaction.replace(ch.haclyon.driveimageview.example.R.id.fragment_container, mainFragment);
    fragmentTransaction.commit();

    getActionBar().setDisplayHomeAsUpEnabled(false);
}
 
Example #30
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();
}