Search in sources :

Example 81 with FragmentTransaction

use of androidx.fragment.app.FragmentTransaction in project AmazeFileManager by TeamAmaze.

the class PreferencesActivity method loadPrefFragment.

private void loadPrefFragment(PreferenceFragmentCompat fragment, @StringRes int titleBarName) {
    currentFragment = fragment;
    FragmentTransaction t = getSupportFragmentManager().beginTransaction();
    t.replace(R.id.prefsfragment, fragment);
    t.commit();
    getSupportActionBar().setTitle(titleBarName);
}
Also used : FragmentTransaction(androidx.fragment.app.FragmentTransaction)

Example 82 with FragmentTransaction

use of androidx.fragment.app.FragmentTransaction in project AmazeFileManager by TeamAmaze.

the class MainActivity method goToMain.

public void goToMain(String path) {
    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
    // title.setText(R.string.app_name);
    TabFragment tabFragment = new TabFragment();
    if (intent != null && intent.getAction() != null) {
        if (INTENT_ACTION_OPEN_QUICK_ACCESS.equals(intent.getAction())) {
            path = "5";
        } else if (INTENT_ACTION_OPEN_RECENT.equals(intent.getAction())) {
            path = "6";
        }
    }
    if (path != null && path.length() > 0) {
        Bundle b = new Bundle();
        b.putString("path", path);
        tabFragment.setArguments(b);
    }
    transaction.replace(R.id.content_frame, tabFragment);
    // Commit the transaction
    transaction.addToBackStack("tabt" + 1);
    transaction.commitAllowingStateLoss();
    appbar.setTitle(null);
    floatingActionButton.show();
    if (openzip && zippath != null) {
        openCompressed(zippath);
        zippath = null;
    }
}
Also used : FragmentTransaction(androidx.fragment.app.FragmentTransaction) Bundle(android.os.Bundle) TabFragment(com.amaze.filemanager.ui.fragments.TabFragment)

Example 83 with FragmentTransaction

use of androidx.fragment.app.FragmentTransaction in project AmazeFileManager by TeamAmaze.

the class Drawer method refreshDrawer.

public void refreshDrawer() {
    Menu menu = navView.getMenu();
    menu.clear();
    actionViewStateManager.deselectCurrentActionView();
    int order = 0;
    ArrayList<StorageDirectoryParcelable> storageDirectories = mainActivity.getStorageDirectories();
    ArrayList<String> storageDirectoryPaths = new ArrayList<>();
    phoneStorageCount = 0;
    for (StorageDirectoryParcelable storageDirectory : storageDirectories) {
        String file = storageDirectory.path;
        File f = new File(file);
        String name = storageDirectory.name;
        int icon = storageDirectory.iconRes;
        storageDirectoryPaths.add(file);
        if (file.contains(OTGUtil.PREFIX_OTG) || file.startsWith(OTGUtil.PREFIX_MEDIA_REMOVABLE)) {
            addNewItem(menu, STORAGES_GROUP, order++, "OTG", new MenuMetadata(file), R.drawable.ic_usb_white_24dp, R.drawable.ic_show_chart_black_24dp);
            continue;
        }
        if (f.isDirectory() || f.canExecute()) {
            addNewItem(menu, STORAGES_GROUP, order++, name, new MenuMetadata(file), icon, R.drawable.ic_show_chart_black_24dp);
            if (phoneStorageCount == 0)
                firstPath = file;
            else if (phoneStorageCount == 1)
                secondPath = file;
            phoneStorageCount++;
        }
    }
    dataUtils.setStorages(storageDirectoryPaths);
    if (dataUtils.getServers().size() > 0) {
        Collections.sort(dataUtils.getServers(), new BookSorter());
        synchronized (dataUtils.getServers()) {
            for (String[] file : dataUtils.getServers()) {
                addNewItem(menu, SERVERS_GROUP, order++, file[0], new MenuMetadata(file[1]), R.drawable.ic_settings_remote_white_24dp, R.drawable.ic_edit_24dp);
            }
        }
    }
    ArrayList<String[]> accountAuthenticationList = new ArrayList<>();
    if (CloudSheetFragment.isCloudProviderAvailable(mainActivity)) {
        for (CloudStorage cloudStorage : dataUtils.getAccounts()) {
            @DrawableRes int deleteIcon = R.drawable.ic_delete_grey_24dp;
            if (cloudStorage instanceof Dropbox) {
                addNewItem(menu, CLOUDS_GROUP, order++, CloudHandler.CLOUD_NAME_DROPBOX, new MenuMetadata(CloudHandler.CLOUD_PREFIX_DROPBOX + "/"), R.drawable.ic_dropbox_white_24dp, deleteIcon);
                accountAuthenticationList.add(new String[] { CloudHandler.CLOUD_NAME_DROPBOX, CloudHandler.CLOUD_PREFIX_DROPBOX + "/" });
            } else if (cloudStorage instanceof Box) {
                addNewItem(menu, CLOUDS_GROUP, order++, CloudHandler.CLOUD_NAME_BOX, new MenuMetadata(CloudHandler.CLOUD_PREFIX_BOX + "/"), R.drawable.ic_box_white_24dp, deleteIcon);
                accountAuthenticationList.add(new String[] { CloudHandler.CLOUD_NAME_BOX, CloudHandler.CLOUD_PREFIX_BOX + "/" });
            } else if (cloudStorage instanceof OneDrive) {
                addNewItem(menu, CLOUDS_GROUP, order++, CloudHandler.CLOUD_NAME_ONE_DRIVE, new MenuMetadata(CloudHandler.CLOUD_PREFIX_ONE_DRIVE + "/"), R.drawable.ic_onedrive_white_24dp, deleteIcon);
                accountAuthenticationList.add(new String[] { CloudHandler.CLOUD_NAME_ONE_DRIVE, CloudHandler.CLOUD_PREFIX_ONE_DRIVE + "/" });
            } else if (cloudStorage instanceof GoogleDrive) {
                addNewItem(menu, CLOUDS_GROUP, order++, CloudHandler.CLOUD_NAME_GOOGLE_DRIVE, new MenuMetadata(CloudHandler.CLOUD_PREFIX_GOOGLE_DRIVE + "/"), R.drawable.ic_google_drive_white_24dp, deleteIcon);
                accountAuthenticationList.add(new String[] { CloudHandler.CLOUD_NAME_GOOGLE_DRIVE, CloudHandler.CLOUD_PREFIX_GOOGLE_DRIVE + "/" });
            }
        }
        Collections.sort(accountAuthenticationList, new BookSorter());
    }
    if (mainActivity.getBoolean(PREFERENCE_SHOW_SIDEBAR_FOLDERS)) {
        if (dataUtils.getBooks().size() > 0) {
            Collections.sort(dataUtils.getBooks(), new BookSorter());
            synchronized (dataUtils.getBooks()) {
                for (String[] file : dataUtils.getBooks()) {
                    addNewItem(menu, FOLDERS_GROUP, order++, file[0], new MenuMetadata(file[1]), R.drawable.ic_folder_white_24dp, R.drawable.ic_edit_24dp);
                }
            }
        }
    }
    Boolean[] quickAccessPref = TinyDB.getBooleanArray(mainActivity.getPrefs(), QuickAccessPref.KEY, QuickAccessPref.Companion.getDEFAULT());
    if (mainActivity.getBoolean(PREFERENCE_SHOW_SIDEBAR_QUICKACCESSES)) {
        if (quickAccessPref[0]) {
            addNewItem(menu, QUICKACCESSES_GROUP, order++, R.string.quick, new MenuMetadata("5"), R.drawable.ic_star_white_24dp, null);
        }
        if (quickAccessPref[1]) {
            addNewItem(menu, QUICKACCESSES_GROUP, order++, R.string.recent, new MenuMetadata("6"), R.drawable.ic_history_white_24dp, null);
        }
        if (quickAccessPref[2]) {
            addNewItem(menu, QUICKACCESSES_GROUP, order++, R.string.images, new MenuMetadata("0"), R.drawable.ic_photo_library_white_24dp, null);
        }
        if (quickAccessPref[3]) {
            addNewItem(menu, QUICKACCESSES_GROUP, order++, R.string.videos, new MenuMetadata("1"), R.drawable.ic_video_library_white_24dp, null);
        }
        if (quickAccessPref[4]) {
            addNewItem(menu, QUICKACCESSES_GROUP, order++, R.string.audio, new MenuMetadata("2"), R.drawable.ic_library_music_white_24dp, null);
        }
        if (quickAccessPref[5]) {
            addNewItem(menu, QUICKACCESSES_GROUP, order++, R.string.documents, new MenuMetadata("3"), R.drawable.ic_library_books_white_24dp, null);
        }
        if (quickAccessPref[6]) {
            addNewItem(menu, QUICKACCESSES_GROUP, order++, R.string.apks, new MenuMetadata("4"), R.drawable.ic_apk_library_white_24dp, null);
        }
    }
    addNewItem(menu, LASTGROUP, order++, R.string.ftp, new MenuMetadata(() -> {
        FragmentTransaction transaction2 = mainActivity.getSupportFragmentManager().beginTransaction();
        transaction2.replace(R.id.content_frame, new FtpServerFragment());
        mainActivity.getAppbar().getAppbarLayout().animate().translationY(0).setInterpolator(new DecelerateInterpolator(2)).start();
        pending_fragmentTransaction = transaction2;
        if (!isDrawerLocked)
            close();
        else
            onDrawerClosed();
    }), R.drawable.ic_ftp_white_24dp, null);
    addNewItem(menu, LASTGROUP, order++, R.string.apps, new MenuMetadata(() -> {
        FragmentTransaction transaction2 = mainActivity.getSupportFragmentManager().beginTransaction();
        transaction2.replace(R.id.content_frame, new AppsListFragment());
        mainActivity.getAppbar().getAppbarLayout().animate().translationY(0).setInterpolator(new DecelerateInterpolator(2)).start();
        pending_fragmentTransaction = transaction2;
        if (!isDrawerLocked)
            close();
        else
            onDrawerClosed();
    }), R.drawable.ic_android_white_24dp, null);
    addNewItem(menu, LASTGROUP, order++, R.string.setting, new MenuMetadata(() -> {
        Intent in = new Intent(mainActivity, PreferencesActivity.class);
        mainActivity.startActivity(in);
        mainActivity.finish();
    }), R.drawable.ic_settings_white_24dp, null);
    for (int i = 0; i < navView.getMenu().size(); i++) {
        navView.getMenu().getItem(i).setEnabled(true);
    }
    for (int group : GROUPS) {
        menu.setGroupCheckable(group, true, true);
    }
    MenuItem item = navView.getSelected();
    if (item != null) {
        item.setChecked(true);
        actionViewStateManager.selectActionView(item);
    }
}
Also used : DecelerateInterpolator(android.view.animation.DecelerateInterpolator) PreferencesActivity(com.amaze.filemanager.ui.activities.PreferencesActivity) ArrayList(java.util.ArrayList) GoogleDrive(com.cloudrail.si.services.GoogleDrive) FtpServerFragment(com.amaze.filemanager.ui.fragments.FtpServerFragment) CloudStorage(com.cloudrail.si.interfaces.CloudStorage) OneDrive(com.cloudrail.si.services.OneDrive) FragmentTransaction(androidx.fragment.app.FragmentTransaction) BookSorter(com.amaze.filemanager.utils.BookSorter) Menu(android.view.Menu) Dropbox(com.cloudrail.si.services.Dropbox) DrawableRes(androidx.annotation.DrawableRes) Box(com.cloudrail.si.services.Box) Intent(android.content.Intent) MenuItem(android.view.MenuItem) StorageDirectoryParcelable(com.amaze.filemanager.adapters.data.StorageDirectoryParcelable) AppsListFragment(com.amaze.filemanager.ui.fragments.AppsListFragment) HybridFile(com.amaze.filemanager.filesystem.HybridFile) File(java.io.File)

Example 84 with FragmentTransaction

use of androidx.fragment.app.FragmentTransaction in project mopub-android-mediation by mopub.

the class MoPubListFragment method enterAdFragment.

private void enterAdFragment(@NonNull final MoPubSampleAdUnit adConfiguration, @Nullable final String keywords, @Nullable final String userDataKeywords) {
    Preconditions.checkNotNull(adConfiguration);
    final FragmentTransaction fragmentTransaction = getActivity().getSupportFragmentManager().beginTransaction();
    final Class<? extends Fragment> fragmentClass = adConfiguration.getFragmentClass();
    final Fragment fragment;
    try {
        fragment = fragmentClass.newInstance();
    } catch (java.lang.InstantiationException e) {
        MoPubLog.log(ERROR_WITH_THROWABLE, "Error creating fragment for class " + fragmentClass, e);
        return;
    } catch (IllegalAccessException e) {
        MoPubLog.log(ERROR_WITH_THROWABLE, "Error creating fragment for class " + fragmentClass, e);
        return;
    }
    final Bundle bundle = adConfiguration.toBundle();
    if (!TextUtils.isEmpty(keywords)) {
        bundle.putString(KEYWORDS_KEY, keywords);
    }
    if (!TextUtils.isEmpty(userDataKeywords)) {
        bundle.putString(USER_DATA_KEYWORDS_KEY, userDataKeywords);
    }
    fragment.setArguments(bundle);
    if (getFragmentManager().getBackStackEntryCount() > 0) {
        getFragmentManager().popBackStack();
    }
    fragmentTransaction.replace(R.id.fragment_container, fragment).addToBackStack(null).commit();
}
Also used : FragmentTransaction(androidx.fragment.app.FragmentTransaction) Bundle(android.os.Bundle) Fragment(androidx.fragment.app.Fragment) ListFragment(androidx.fragment.app.ListFragment) DialogFragment(androidx.fragment.app.DialogFragment)

Example 85 with FragmentTransaction

use of androidx.fragment.app.FragmentTransaction in project FlycoTabLayout by H07000223.

the class FragmentChangeManager method setFragments.

/**
 * 界面切换控制
 */
public void setFragments(int index) {
    for (int i = 0; i < mFragments.size(); i++) {
        FragmentTransaction ft = mFragmentManager.beginTransaction();
        Fragment fragment = mFragments.get(i);
        if (i == index) {
            ft.show(fragment);
        } else {
            ft.hide(fragment);
        }
        ft.commit();
    }
    mCurrentTab = index;
}
Also used : FragmentTransaction(androidx.fragment.app.FragmentTransaction) Fragment(androidx.fragment.app.Fragment)

Aggregations

FragmentTransaction (androidx.fragment.app.FragmentTransaction)186 Fragment (androidx.fragment.app.Fragment)58 FragmentManager (androidx.fragment.app.FragmentManager)53 Bundle (android.os.Bundle)28 Test (org.junit.Test)14 DialogFragment (androidx.fragment.app.DialogFragment)10 OCFileListFragment (com.owncloud.android.ui.fragment.OCFileListFragment)6 Intent (android.content.Intent)5 View (android.view.View)5 ActionBar (androidx.appcompat.app.ActionBar)4 Toolbar (androidx.appcompat.widget.Toolbar)4 SwipeRefreshListFragment (eu.siacs.conversations.ui.widget.SwipeRefreshListFragment)4 File (java.io.File)4 MediaGalleryFragment (org.thoughtcrime.securesms.mediasend.v2.gallery.MediaGalleryFragment)4 SuppressLint (android.annotation.SuppressLint)3 Activity (android.app.Activity)3 DecelerateInterpolator (android.view.animation.DecelerateInterpolator)3 ProcessViewerFragment (com.amaze.filemanager.ui.fragments.ProcessViewerFragment)3 SslUntrustedCertDialog (com.owncloud.android.ui.dialog.SslUntrustedCertDialog)3 TargetApi (android.annotation.TargetApi)2