本文整理汇总了Java中com.hippo.unifile.UniFile类的典型用法代码示例。如果您正苦于以下问题:Java UniFile类的具体用法?Java UniFile怎么用?Java UniFile使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
UniFile类属于com.hippo.unifile包,在下文中一共展示了UniFile类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getFile
import com.hippo.unifile.UniFile; //导入依赖的package包/类
@Override
public UniFile getFile(Uri uri) {
// Get dir
UniFile dir = Settings.getImageSaveLocation();
if (dir == null) {
return null;
}
// Get filename
List<String> path = uri.getPathSegments();
if (path == null || path.size() != 1) {
return null;
}
return dir.findFile(path.get(0));
}
示例2: getType
import com.hippo.unifile.UniFile; //导入依赖的package包/类
@Nullable
@Override
public String getType(@NonNull Uri uri) {
final UniFile file = getFileForUri(uri);
if (file != null) {
final String name = file.getUri().getPath();
if (name != null) {
final int lastDot = name.lastIndexOf('.');
if (lastDot >= 0) {
final String extension = name.substring(lastDot + 1);
final String mime = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
if (mime != null) {
return mime;
}
}
}
}
return "application/octet-stream";
}
示例3: downloadApk
import com.hippo.unifile.UniFile; //导入依赖的package包/类
public static void downloadApk(Context context, String url, List<DiscUrl> discUrls, String failedUrl, String filename) {
if (sUpdating) {
return;
}
sUpdating = true;
context = context.getApplicationContext();
File dir = NMBAppConfig.getExternalAppDir();
if (dir == null) {
Toast.makeText(context, R.string.download_update_failde, Toast.LENGTH_SHORT).show();
return;
}
DownloadRequest request = new DownloadRequest();
request.setUrl(url);
request.setFilename(filename);
request.setDir(UniFile.fromFile(dir));
request.setOkHttpClient(NMBApplication.getOkHttpClient(context));
new DownloadApkTask(context, request, Uri.fromFile(new File(dir, filename)), failedUrl).execute();
}
示例4: handlerIntent
import com.hippo.unifile.UniFile; //导入依赖的package包/类
private boolean handlerIntent(Intent intent) {
if (intent == null) {
return false;
}
String action = intent.getAction();
if (ACTION_SINGLE_IMAGE.equals(action)) {
int site = intent.getIntExtra(KEY_SITE, -1);
String id = intent.getStringExtra(KEY_ID);
String key = intent.getStringExtra(KEY_KEY);
String image = intent.getStringExtra(KEY_IMAGE);
if (Site.isValid(site) && id != null && key != null && image != null) {
mGalleryAdapter = new SingleImageAdapter(Site.fromId(site), id, key, image);
return true;
}
} else if (ACTION_IMAGE_FILE.equals(action)) {
Uri fileUri = intent.getParcelableExtra(KEY_UNI_FILE_URI);
UniFile file = UniFile.fromUri(this, fileUri);
if (file != null) {
mGalleryAdapter = new ImageFileAdapter(file);
return true;
}
}
return false;
}
示例5: bindPagerHolder
import com.hippo.unifile.UniFile; //导入依赖的package包/类
@Override
public void bindPagerHolder(GalleryHolder holder, int position) {
String key;
DataContainer container;
UniFile dir = Settings.getImageSaveLocation();
if (Settings.getSaveImageAuto() && dir != null) {
key = null;
container = new UniFileDataContain(GalleryActivity2.this, dir,
mSite.getReadableName(GalleryActivity2.this) + "-" + mId);
} else {
key = mKey;
container = null;
}
holder.galleryPage.load(key, mImage, container);
}
示例6: getImageSaveLocation
import com.hippo.unifile.UniFile; //导入依赖的package包/类
@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());
}
示例7: setImageFile
import com.hippo.unifile.UniFile; //导入依赖的package包/类
private void setImageFile(UniFile file) {
if (file == null) {
return;
}
Object object = NMBApplication.getImageWrapperHelper(getContext())
.decode(new UniFileInputStreamPipe(file));
if (object != null) {
ImageWrapper imageWrapper = (ImageWrapper) object;
imageWrapper.start();
Drawable drawable = new ImageDrawable(imageWrapper);
removeDrawableAndHolder();
setImageDrawable(drawable);
mImageFile = file;
mContainer = null;
}
}
示例8: listFiles
import com.hippo.unifile.UniFile; //导入依赖的package包/类
private void listFiles() {
UniFile[] files = mFile.listFiles();
if (files == null) {
Toast.makeText(this, "null", Toast.LENGTH_SHORT).show();
} else if (files.length == 0) {
Toast.makeText(this, "empty", Toast.LENGTH_SHORT).show();
} else {
ArrayList<Uri> uris = new ArrayList<>();
for (UniFile f : files) {
uris.add(f.getUri());
}
Intent intent = new Intent(this, FileListActivity.class);
intent.putParcelableArrayListExtra(FileListActivity.KEY_URIS, uris);
startActivity(intent);
}
}
示例9: listFilesFilenameFilter
import com.hippo.unifile.UniFile; //导入依赖的package包/类
private void listFilesFilenameFilter() {
UniFile[] files = mFile.listFiles(new FilenameFilter() {
@Override
public boolean accept(UniFile dir, String filename) {
return filename.startsWith("a");
}
});
if (files == null) {
Toast.makeText(this, "null", Toast.LENGTH_SHORT).show();
} else if (files.length == 0) {
Toast.makeText(this, "empty", Toast.LENGTH_SHORT).show();
} else {
ArrayList<Uri> uris = new ArrayList<>();
for (UniFile f : files) {
uris.add(f.getUri());
}
Intent intent = new Intent(this, FileListActivity.class);
intent.putParcelableArrayListExtra(FileListActivity.KEY_URIS, uris);
startActivity(intent);
}
}
示例10: save
import com.hippo.unifile.UniFile; //导入依赖的package包/类
public boolean save(int index, @NonNull UniFile file) {
int state = getPageState(index);
if (STATE_FINISHED != state) {
return false;
}
InputStreamPipe pipe = mSpiderDen.openInputStreamPipe(index);
if (null == pipe) {
return false;
}
OutputStream os = null;
try {
os = file.openOutputStream();
pipe.obtain();
IOUtils.copy(pipe.open(), os);
return true;
} catch (IOException e) {
return false;
} finally {
pipe.close();
pipe.release();
IOUtils.closeQuietly(os);
}
}
示例11: removeFromDownloadDir
import com.hippo.unifile.UniFile; //导入依赖的package包/类
private boolean removeFromDownloadDir(int index) {
UniFile dir = getDownloadDir();
if (dir == null) {
return false;
}
boolean result = false;
for (int i = 0, n = GalleryProvider2.SUPPORT_IMAGE_EXTENSIONS.length; i < n; i++) {
String filename = generateImageFilename(index, GalleryProvider2.SUPPORT_IMAGE_EXTENSIONS[i]);
UniFile file = dir.subFile(filename);
if (file != null) {
result |= file.delete();
}
}
return result;
}
示例12: openDownloadOutputStreamPipe
import com.hippo.unifile.UniFile; //导入依赖的package包/类
/**
* @param extension without dot
*/
@Nullable
private OutputStreamPipe openDownloadOutputStreamPipe(int index, @Nullable String extension) {
UniFile dir = getDownloadDir();
if (dir == null) {
return null;
}
extension = fixExtension('.' + extension);
UniFile file = dir.createFile(generateImageFilename(index, extension));
if (file != null) {
return new UniFileOutputStreamPipe(file);
} else {
return null;
}
}
示例13: openDownloadInputStreamPipe
import com.hippo.unifile.UniFile; //导入依赖的package包/类
@Nullable
public InputStreamPipe openDownloadInputStreamPipe(int index) {
UniFile dir = getDownloadDir();
if (dir == null) {
return null;
}
for (int i = 0; i < 2; i++) {
UniFile file = findImageFile(dir, index);
if (file != null) {
return new UniFileInputStreamPipe(file);
} else if (!copyFromCacheToDownloadDir(index)) {
return null;
}
}
return null;
}
示例14: save
import com.hippo.unifile.UniFile; //导入依赖的package包/类
@Override
public boolean save(int index, @NonNull UniFile file) {
UniFile[] fileList = mFileList.get();
if (null == fileList || index < 0 || index >= fileList.length) {
return false;
}
InputStream is = null;
OutputStream os = null;
try {
is = fileList[index].openInputStream();
os = file.openOutputStream();
IOUtils.copy(is, os);
return true;
} catch (IOException e) {
return false;
} finally {
IOUtils.closeQuietly(is);
IOUtils.closeQuietly(os);
}
}
示例15: onPreferenceChange
import com.hippo.unifile.UniFile; //导入依赖的package包/类
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
String key = preference.getKey();
if (Settings.KEY_MEDIA_SCAN.equals(key)) {
if (newValue instanceof Boolean) {
UniFile downloadLocation = Settings.getDownloadLocation();
if ((Boolean) newValue) {
CommonOperations.removeNoMediaFile(downloadLocation);
} else {
CommonOperations.ensureNoMediaFile(downloadLocation);
}
}
return true;
} else if (Settings.KEY_IMAGE_RESOLUTION.equals(key)) {
if (newValue instanceof String) {
Settings.putImageResolution((String) newValue);
}
return true;
}
return false;
}