Search in sources :

Example 26 with DocumentFile

use of androidx.documentfile.provider.DocumentFile in project AntennaPod by AntennaPod.

the class LocalFeedUpdaterTest method testGetImageUrl_EmptyFolder.

@Test
public void testGetImageUrl_EmptyFolder() {
    DocumentFile documentFolder = mockDocumentFolder();
    String imageUrl = LocalFeedUpdater.getImageUrl(context, documentFolder);
    String defaultImageName = context.getResources().getResourceEntryName(R.raw.local_feed_default_icon);
    assertThat(imageUrl, endsWith(defaultImageName));
}
Also used : DocumentFile(androidx.documentfile.provider.DocumentFile) AssetsDocumentFile(androidx.documentfile.provider.AssetsDocumentFile) Test(org.junit.Test)

Example 27 with DocumentFile

use of androidx.documentfile.provider.DocumentFile in project orgzly-android by orgzly.

the class SavedSearchesFragmentTest method testExportSavedSearches.

@Test
public void testExportSavedSearches() throws IOException {
    Intents.init();
    // Uri to get back after sending Intent.ACTION_CREATE_DOCUMENT
    DocumentFile file = DocumentFile.fromFile(new LocalStorage(context).downloadsDirectory("searches.json"));
    Instrumentation.ActivityResult result = new Instrumentation.ActivityResult(Activity.RESULT_OK, new Intent().setData(file.getUri()));
    intending(hasAction(Intent.ACTION_CREATE_DOCUMENT)).respondWith(result);
    onActionItemClick(R.id.saved_searches_export, R.string.export);
    onSnackbar().check(matches(withText(context.getResources().getQuantityString(R.plurals.exported_searches, 4, 4))));
    Intents.release();
    file.delete();
}
Also used : DocumentFile(androidx.documentfile.provider.DocumentFile) LocalStorage(com.orgzly.android.LocalStorage) Instrumentation(android.app.Instrumentation) Intent(android.content.Intent) OrgzlyTest(com.orgzly.android.OrgzlyTest) Test(org.junit.Test)

Example 28 with DocumentFile

use of androidx.documentfile.provider.DocumentFile in project RSAndroidApp by RailwayStations.

the class MapsActivity method onCreateOptionsMenu.

@Override
public boolean onCreateOptionsMenu(final Menu menu) {
    super.onCreateOptionsMenu(menu);
    getMenuInflater().inflate(R.menu.maps, menu);
    final MenuItem item = menu.findItem(R.id.menu_toggle_mypos);
    myLocSwitch = new CheckBox(this);
    myLocSwitch.setButtonDrawable(R.drawable.ic_gps_fix_selector);
    myLocSwitch.setChecked(baseApplication.isLocationUpdates());
    item.setActionView(myLocSwitch);
    myLocSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
        baseApplication.setLocationUpdates(isChecked);
        if (isChecked) {
            askedForPermission = false;
            registerLocationManager();
        } else {
            unregisterLocationManager();
        }
    });
    final String map = baseApplication.getMap();
    final MenuItem osmMapnick = menu.findItem(R.id.osm_mapnik);
    osmMapnick.setChecked(map == null);
    osmMapnick.setOnMenuItemClickListener(new MapMenuListener(this, baseApplication, null));
    final SubMenu mapSubmenu = menu.findItem(R.id.maps_submenu).getSubMenu();
    for (final OnlineTileSource tileSource : onlineTileSources.values()) {
        final MenuItem mapItem = mapSubmenu.add(R.id.maps_group, NONE, NONE, tileSource.getName());
        mapItem.setChecked(tileSource.getName().equals(map));
        mapItem.setOnMenuItemClickListener(new MapMenuListener(this, baseApplication, tileSource.getName()));
    }
    final Uri mapDirectory = baseApplication.getMapDirectoryUri();
    if (mapDirectory != null) {
        final DocumentFile documentsTree = getDocumentFileFromTreeUri(mapDirectory);
        if (documentsTree != null) {
            for (final DocumentFile file : documentsTree.listFiles()) {
                if (file.isFile() && file.getName().endsWith(".map")) {
                    final MenuItem mapItem = mapSubmenu.add(R.id.maps_group, NONE, NONE, file.getName());
                    mapItem.setChecked(file.getUri().equals(baseApplication.toUri(map)));
                    mapItem.setOnMenuItemClickListener(new MapMenuListener(this, baseApplication, file.getUri().toString()));
                }
            }
        }
    }
    mapSubmenu.setGroupCheckable(R.id.maps_group, true, true);
    final MenuItem mapFolder = mapSubmenu.add(R.string.map_folder);
    mapFolder.setOnMenuItemClickListener(item1 -> {
        openMapDirectoryChooser();
        return false;
    });
    final Uri mapTheme = baseApplication.getMapThemeUri();
    final Uri mapThemeDirectory = baseApplication.getMapThemeDirectoryUri();
    final MenuItem defaultTheme = menu.findItem(R.id.default_theme);
    defaultTheme.setChecked(mapTheme == null);
    defaultTheme.setOnMenuItemClickListener(new MapThemeMenuListener(this, baseApplication, null));
    final SubMenu themeSubmenu = menu.findItem(R.id.themes_submenu).getSubMenu();
    if (mapThemeDirectory != null) {
        final DocumentFile documentsTree = getDocumentFileFromTreeUri(mapThemeDirectory);
        if (documentsTree != null) {
            for (final DocumentFile file : documentsTree.listFiles()) {
                if (file.isFile() && file.getName().endsWith(".xml")) {
                    final String themeName = file.getName();
                    final MenuItem themeItem = themeSubmenu.add(R.id.themes_group, NONE, NONE, themeName);
                    themeItem.setChecked(file.getUri().equals(mapTheme));
                    themeItem.setOnMenuItemClickListener(new MapThemeMenuListener(this, baseApplication, file.getUri()));
                } else if (file.isDirectory()) {
                    final DocumentFile childFile = file.findFile(file.getName() + ".xml");
                    if (childFile != null) {
                        final String themeName = file.getName();
                        final MenuItem themeItem = themeSubmenu.add(R.id.themes_group, NONE, NONE, themeName);
                        themeItem.setChecked(childFile.getUri().equals(mapTheme));
                        themeItem.setOnMenuItemClickListener(new MapThemeMenuListener(this, baseApplication, childFile.getUri()));
                    }
                }
            }
        }
    }
    themeSubmenu.setGroupCheckable(R.id.themes_group, true, true);
    final MenuItem themeFolder = themeSubmenu.add(R.string.theme_folder);
    themeFolder.setOnMenuItemClickListener(item12 -> {
        openThemeDirectoryChooser();
        return false;
    });
    return true;
}
Also used : OnlineTileSource(org.mapsforge.map.layer.download.tilesource.OnlineTileSource) DocumentFile(androidx.documentfile.provider.DocumentFile) CheckBox(android.widget.CheckBox) MenuItem(android.view.MenuItem) SubMenu(android.view.SubMenu) Uri(android.net.Uri)

Example 29 with DocumentFile

use of androidx.documentfile.provider.DocumentFile in project syncthing-android by syncthing.

the class FolderActivity method onOptionsItemSelected.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch(item.getItemId()) {
        case R.id.create:
            if (TextUtils.isEmpty(mFolder.id)) {
                Toast.makeText(this, R.string.folder_id_required, Toast.LENGTH_LONG).show();
                return true;
            }
            if (TextUtils.isEmpty(mFolder.path)) {
                Toast.makeText(this, R.string.folder_path_required, Toast.LENGTH_LONG).show();
                return true;
            }
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && mFolderUri != null) {
                /**
                 * Normally, syncthing takes care of creating the ".stfolder" marker.
                 * This fails on newer android versions if the syncthing binary only has
                 * readonly access on the path and the user tries to configure a
                 * sendonly folder. To fix this, we'll precreate the marker using java code.
                 * We also create an empty file in the marker directory, to hopefully keep
                 * it alive in the face of overzealous disk cleaner apps.
                 */
                DocumentFile dfFolder = DocumentFile.fromTreeUri(this, mFolderUri);
                if (dfFolder != null) {
                    Log.v(TAG, "Creating new directory " + mFolder.path + File.separator + FOLDER_MARKER_NAME);
                    DocumentFile marker = dfFolder.createDirectory(FOLDER_MARKER_NAME);
                    marker.createFile("text/plain", "empty");
                }
            }
            getApi().createFolder(mFolder);
            finish();
            return true;
        case R.id.remove:
            showDeleteDialog();
            return true;
        case android.R.id.home:
            onBackPressed();
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}
Also used : DocumentFile(androidx.documentfile.provider.DocumentFile)

Example 30 with DocumentFile

use of androidx.documentfile.provider.DocumentFile in project kdeconnect-android by KDE.

the class CompositeReceiveFileJob method getDocumentFileFor.

private DocumentFile getDocumentFileFor(final String filename, final boolean open) throws RuntimeException {
    final DocumentFile destinationFolderDocument;
    String filenameToUse = filename;
    // If the file should be opened immediately store it in the standard location to avoid the FileProvider trouble (See ReceiveNotification::setURI)
    if (open || !ShareSettingsFragment.isCustomDestinationEnabled(getDevice().getContext())) {
        final String defaultPath = ShareSettingsFragment.getDefaultDestinationDirectory().getAbsolutePath();
        filenameToUse = FilesHelper.findNonExistingNameForNewFile(defaultPath, filenameToUse);
        destinationFolderDocument = DocumentFile.fromFile(new File(defaultPath));
    } else {
        destinationFolderDocument = ShareSettingsFragment.getDestinationDirectory(getDevice().getContext());
    }
    String displayName = FilenameUtils.getBaseName(filenameToUse);
    String mimeType = FilesHelper.getMimeTypeFromFile(filenameToUse);
    if ("*/*".equals(mimeType)) {
        displayName = filenameToUse;
    }
    DocumentFile fileDocument = destinationFolderDocument.createFile(mimeType, displayName);
    if (fileDocument == null) {
        throw new RuntimeException(getDevice().getContext().getString(R.string.cannot_create_file, filenameToUse));
    }
    return fileDocument;
}
Also used : DocumentFile(androidx.documentfile.provider.DocumentFile) File(java.io.File) DocumentFile(androidx.documentfile.provider.DocumentFile)

Aggregations

DocumentFile (androidx.documentfile.provider.DocumentFile)42 IOException (java.io.IOException)16 Uri (android.net.Uri)13 AssetsDocumentFile (androidx.documentfile.provider.AssetsDocumentFile)10 OutputStream (java.io.OutputStream)10 ArrayList (java.util.ArrayList)9 File (java.io.File)8 Test (org.junit.Test)8 Intent (android.content.Intent)5 NonNull (androidx.annotation.NonNull)5 ShellNotRunningException (com.amaze.filemanager.file_operations.exceptions.ShellNotRunningException)5 CloudStorage (com.cloudrail.si.interfaces.CloudStorage)5 SmbFile (jcifs.smb.SmbFile)5 SFTPClient (net.schmizz.sshj.sftp.SFTPClient)5 Context (android.content.Context)4 OpenMode (com.amaze.filemanager.file_operations.filesystem.OpenMode)4 SFtpClientTemplate (com.amaze.filemanager.filesystem.ssh.SFtpClientTemplate)4 DataUtils (com.amaze.filemanager.utils.DataUtils)4 SmbException (jcifs.smb.SmbException)4 AsyncTask (android.os.AsyncTask)3