Skip to content

Commit

Permalink
update.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sunzxyong committed Oct 24, 2018
1 parent 14aff4e commit 315a3eb
Showing 1 changed file with 58 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.zxy.tiny.callback.BitmapBatchCallback;
import com.zxy.tiny.callback.Callback;
import com.zxy.tiny.callback.DefaultCallbackDispatcher;
import com.zxy.tiny.common.BitmapBatchResult;

import java.io.File;

Expand All @@ -28,6 +29,63 @@ public void batchCompress(BitmapBatchCallback callback) {
impl(callback);
}

public BitmapBatchResult batchCompressSync() {
return implSync();
}

public BitmapBatchResult implSync() {
BitmapBatchResult result = new BitmapBatchResult();

if (mSource == null) {
result.success = false;
result.throwable = new RuntimeException("the source is null!");
return result;
}

if (mCompressOptions == null)
mCompressOptions = new Tiny.BitmapCompressOptions();

if (mSourceType == SourceType.FILE_ARRAY) {
File[] file = (File[]) mSource;
try {
result.bitmaps = new BitmapCompressCallableTasks.FileArrayAsBitmapCallable(mCompressOptions, file).call();
result.success = true;
} catch (Exception e) {
result.success = false;
result.throwable = e;
}
} else if (mSourceType == SourceType.BITMAP_ARRAY) {
Bitmap[] bitmaps = (Bitmap[]) mSource;
try {
result.bitmaps = new BitmapCompressCallableTasks.BitmapArrayAsBitmapCallable(mCompressOptions, bitmaps).call();
result.success = true;
} catch (Exception e) {
result.success = false;
result.throwable = e;
}
} else if (mSourceType == SourceType.URI_ARRAY) {
Uri[] uris = (Uri[]) mSource;
try {
result.bitmaps = new BitmapCompressCallableTasks.UriArrayAsBitmapCallable(mCompressOptions, uris).call();
result.success = true;
} catch (Exception e) {
result.success = false;
result.throwable = e;
}
} else if (mSourceType == SourceType.RES_ID_ARRAY) {
int[] resIds = (int[]) mSource;
try {
result.bitmaps = new BitmapCompressCallableTasks.ResourceArrayAsBitmapCallable(mCompressOptions, resIds).call();
result.success = true;
} catch (Exception e) {
result.success = false;
result.throwable = e;
}
}

return result;
}

private void impl(Callback callback) {
if (mSource == null) {
if (callback instanceof BitmapBatchCallback) {
Expand Down

0 comments on commit 315a3eb

Please sign in to comment.