use of com.hippo.unifile.UniFile in project EhViewer by seven332.
the class SpiderDen method copyFromCacheToDownloadDir.
private boolean copyFromCacheToDownloadDir(int index) {
if (sCache == null) {
return false;
}
UniFile dir = getDownloadDir();
if (dir == null) {
return false;
}
// Find image file in cache
String key = EhCacheKeyFactory.getImageKey(mGid, index);
InputStreamPipe pipe = sCache.getInputStreamPipe(key);
if (pipe == null) {
return false;
}
OutputStream os = null;
try {
// Get extension
String extension;
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
pipe.obtain();
BitmapFactory.decodeStream(pipe.open(), null, options);
pipe.close();
extension = MimeTypeMap.getSingleton().getExtensionFromMimeType(options.outMimeType);
if (extension != null) {
extension = '.' + extension;
} else {
return false;
}
// Fix extension
extension = fixExtension(extension);
// Copy from cache to download dir
UniFile file = dir.createFile(generateImageFilename(index, extension));
if (file == null) {
return false;
}
os = file.openOutputStream();
IOUtils.copy(pipe.open(), os);
return true;
} catch (IOException e) {
return false;
} finally {
IOUtils.closeQuietly(os);
pipe.close();
pipe.release();
}
}
use of com.hippo.unifile.UniFile in project EhViewer by seven332.
the class Settings method getDownloadLocation.
@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());
}
use of com.hippo.unifile.UniFile in project EhViewer by seven332.
the class ImageSearchLayout method setImageUri.
public void setImageUri(@Nullable Uri imageUri) {
if (null == imageUri) {
return;
}
Context context = getContext();
UniFile file = UniFile.fromUri(context, imageUri);
if (null == file) {
return;
}
try {
int maxSize = context.getResources().getDimensionPixelOffset(R.dimen.image_search_max_size);
Bitmap bitmap = BitmapUtils.decodeStream(new UniFileInputStreamPipe(file), maxSize, maxSize);
if (null == bitmap) {
return;
}
File temp = AppConfig.createTempFile();
if (null == temp) {
return;
}
// TODO ehentai image search is bad when I'm writing this line.
// Re-compress image will make image search failed.
OutputStream os = null;
try {
os = new FileOutputStream(temp);
bitmap.compress(Bitmap.CompressFormat.JPEG, 90, os);
mImagePath = temp.getPath();
mPreview.setImageBitmap(bitmap);
mPreview.setVisibility(VISIBLE);
} catch (FileNotFoundException e) {
e.printStackTrace();
} finally {
IOUtils.closeQuietly(os);
}
} catch (OutOfMemoryError e) {
Log.e(TAG, "Out of memory");
}
}
Aggregations