Merge "Always save long screenshot temp file to the same place" into sc-dev
This commit is contained in:
@@ -111,30 +111,21 @@ class ImageExporter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stores the given Bitmap to a temp file.
|
* Writes the given Bitmap to outputFile.
|
||||||
*/
|
*/
|
||||||
ListenableFuture<File> exportAsTempFile(Executor executor, Bitmap bitmap) {
|
ListenableFuture<File> exportToRawFile(Executor executor, Bitmap bitmap,
|
||||||
|
final File outputFile) {
|
||||||
return CallbackToFutureAdapter.getFuture(
|
return CallbackToFutureAdapter.getFuture(
|
||||||
(completer) -> {
|
(completer) -> {
|
||||||
executor.execute(() -> {
|
executor.execute(() -> {
|
||||||
File cachePath;
|
try (FileOutputStream stream = new FileOutputStream(outputFile)) {
|
||||||
try {
|
bitmap.compress(mCompressFormat, mQuality, stream);
|
||||||
cachePath = File.createTempFile("long_screenshot_cache_", ".tmp");
|
completer.set(outputFile);
|
||||||
try (FileOutputStream stream = new FileOutputStream(cachePath)) {
|
|
||||||
bitmap.compress(mCompressFormat, mQuality, stream);
|
|
||||||
} catch (IOException e) {
|
|
||||||
if (cachePath.exists()) {
|
|
||||||
//noinspection ResultOfMethodCallIgnored
|
|
||||||
cachePath.delete();
|
|
||||||
cachePath = null;
|
|
||||||
}
|
|
||||||
completer.setException(e);
|
|
||||||
}
|
|
||||||
if (cachePath != null) {
|
|
||||||
completer.set(cachePath);
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// Failed to create a new file
|
if (outputFile.exists()) {
|
||||||
|
//noinspection ResultOfMethodCallIgnored
|
||||||
|
outputFile.delete();
|
||||||
|
}
|
||||||
completer.setException(e);
|
completer.setException(e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -228,8 +228,8 @@ public class LongScreenshotActivity extends Activity {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Immediately export to temp image file for saved state
|
// Immediately export to temp image file for saved state
|
||||||
mCacheSaveFuture = mImageExporter.exportAsTempFile(mBackgroundExecutor,
|
mCacheSaveFuture = mImageExporter.exportToRawFile(mBackgroundExecutor,
|
||||||
mLongScreenshot.toBitmap());
|
mLongScreenshot.toBitmap(), new File(getCacheDir(), "long_screenshot_cache.png"));
|
||||||
mCacheSaveFuture.addListener(() -> {
|
mCacheSaveFuture.addListener(() -> {
|
||||||
try {
|
try {
|
||||||
// Get the temp file path to persist, used in onSavedInstanceState
|
// Get the temp file path to persist, used in onSavedInstanceState
|
||||||
|
|||||||
Reference in New Issue
Block a user