Java Code Examples for com.hippo.unifile.UniFile#fromFile()
The following examples show how to use
com.hippo.unifile.UniFile#fromFile() .
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: GalleryActivity.java From MHViewer with Apache License 2.0 | 6 votes |
private void buildProvider() { if (mGalleryProvider != null) { return; } if (ACTION_DIR.equals(mAction)) { if (mFilename != null) { mGalleryProvider = new DirGalleryProvider(UniFile.fromFile(new File(mFilename))); } } else if (ACTION_EH.equals(mAction)) { if (mGalleryInfo != null) { mGalleryProvider = new EhGalleryProvider(this, mGalleryInfo); } } else if (Intent.ACTION_VIEW.equals(mAction)) { if (mUri != null) { // Only support zip now mGalleryProvider = new ArchiveGalleryProvider(this, mUri); } } }
Example 2
Source File: Settings.java From MHViewer with Apache License 2.0 | 6 votes |
@Nullable public static UniFile getDownloadLocation() { UniFile dir = null; try { Uri.Builder builder = new Uri.Builder(); builder.scheme(getString(KEY_DOWNLOAD_SAVE_SCHEME, null)); builder.encodedAuthority(getString(KEY_DOWNLOAD_SAVE_AUTHORITY, null)); builder.encodedPath(getString(KEY_DOWNLOAD_SAVE_PATH, null)); builder.encodedQuery(getString(KEY_DOWNLOAD_SAVE_QUERY, null)); builder.encodedFragment(getString(KEY_DOWNLOAD_SAVE_FRAGMENT, null)); dir = UniFile.fromUri(sContext, builder.build()); } catch (Throwable e) { ExceptionUtils.throwIfFatal(e); // Ignore } return dir != null ? dir : UniFile.fromFile(AppConfig.getDefaultDownloadDir()); }
Example 3
Source File: Settings.java From Nimingban with Apache License 2.0 | 6 votes |
@Nullable public static UniFile getImageSaveLocation() { UniFile dir = null; try { Uri.Builder builder = new Uri.Builder(); builder.scheme(getString(KEY_IMAGE_SAVE_SCHEME, null)); builder.encodedAuthority(getString(KEY_IMAGE_SAVE_AUTHORITY, null)); builder.encodedPath(getString(KEY_IMAGE_SAVE_PATH, null)); builder.encodedQuery(getString(KEY_IMAGE_SAVE_QUERY, null)); builder.encodedFragment(getString(KEY_IMAGE_SAVE_FRAGMENT, null)); dir = UniFile.fromUri(sContext, builder.build()); } catch (Exception e) { e.printStackTrace(); } return dir != null ? dir : UniFile.fromFile(NMBAppConfig.getImageDir()); }
Example 4
Source File: GalleryActivity.java From EhViewer with Apache License 2.0 | 6 votes |
private void buildProvider() { if (mGalleryProvider != null) { return; } if (ACTION_DIR.equals(mAction)) { if (mFilename != null) { mGalleryProvider = new DirGalleryProvider(UniFile.fromFile(new File(mFilename))); } } else if (ACTION_EH.equals(mAction)) { if (mGalleryInfo != null) { mGalleryProvider = new EhGalleryProvider(this, mGalleryInfo); } } else if (Intent.ACTION_VIEW.equals(mAction)) { if (mUri != null) { // Only support zip now mGalleryProvider = new ArchiveGalleryProvider(this, mUri); } } }
Example 5
Source File: Settings.java From EhViewer with Apache License 2.0 | 6 votes |
@Nullable public static UniFile getDownloadLocation() { UniFile dir = null; try { Uri.Builder builder = new Uri.Builder(); builder.scheme(getString(KEY_DOWNLOAD_SAVE_SCHEME, null)); builder.encodedAuthority(getString(KEY_DOWNLOAD_SAVE_AUTHORITY, null)); builder.encodedPath(getString(KEY_DOWNLOAD_SAVE_PATH, null)); builder.encodedQuery(getString(KEY_DOWNLOAD_SAVE_QUERY, null)); builder.encodedFragment(getString(KEY_DOWNLOAD_SAVE_FRAGMENT, null)); dir = UniFile.fromUri(sContext, builder.build()); } catch (Throwable e) { ExceptionUtils.throwIfFatal(e); // Ignore } return dir != null ? dir : UniFile.fromFile(AppConfig.getDefaultDownloadDir()); }
Example 6
Source File: HeaderImageView.java From Nimingban with Apache License 2.0 | 5 votes |
@Override public boolean save(InputStream is, long length, String mediaType, ProgressNotify notify) { OutputStream os = null; try { boolean autoSave = Settings.getSaveImageAuto() && mName != null; if (autoSave) { String extension = MimeTypeMap.getSingleton().getExtensionFromMimeType(mediaType); if (TextUtils.isEmpty(extension)) { extension = "jpg"; } String filename = mName + '.' + extension; UniFile dir = Settings.getImageSaveLocation(); if (dir != null) { mTempFile = dir.createFile(filename); } else { mTempFile = UniFile.fromFile(NMBAppConfig.createTempFileWithFilename(filename)); } } else { mTempFile = UniFile.fromFile(NMBAppConfig.createTempFile()); } if (mTempFile == null) { return false; } os = mTempFile.openOutputStream(); IOUtils.copy(is, os); // Notify media scanner if (autoSave) { mContext.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, mTempFile.getUri())); } return true; } catch (IOException e) { return false; } finally { IOUtils.closeQuietly(os); } }
Example 7
Source File: UniversalProvider.java From Nimingban with Apache License 2.0 | 4 votes |
@Nullable @Override public UniFile getFile(Uri uri) { File file = new File(uri.getPath()); return UniFile.fromFile(file); }