Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -280,33 +280,38 @@ private double getStepValue() {
private BitmapDrawable getBitmapDrawable(final String uri) {
BitmapDrawable bitmapDrawable = null;
ExecutorService executorService = Executors.newSingleThreadExecutor();
Future<BitmapDrawable> future = executorService.submit(new Callable<BitmapDrawable>() {
@Override
public BitmapDrawable call() {
BitmapDrawable bitmapDrawable = null;
try {
Bitmap bitmap = null;
if (uri.startsWith("http://") || uri.startsWith("https://") ||
uri.startsWith("file://") || uri.startsWith("asset://") || uri.startsWith("data:")) {
bitmap = BitmapFactory.decodeStream(new URL(uri).openStream());
} else {
int drawableId = getResources()
.getIdentifier(uri, "drawable", getContext()
.getPackageName());
bitmap = BitmapFactory.decodeResource(getResources(), drawableId);
try {
Future<BitmapDrawable> future = executorService.submit(new Callable<BitmapDrawable>() {
@Override
public BitmapDrawable call() {
BitmapDrawable bitmapDrawable = null;
try {
Bitmap bitmap = null;
if (uri.startsWith("http://") || uri.startsWith("https://") ||
uri.startsWith("file://") || uri.startsWith("asset://") || uri.startsWith("data:")) {
bitmap = BitmapFactory.decodeStream(new URL(uri).openStream());
} else {
int drawableId = getResources()
.getIdentifier(uri, "drawable", getContext()
.getPackageName());
bitmap = BitmapFactory.decodeResource(getResources(), drawableId);
}

bitmapDrawable = new BitmapDrawable(getResources(), bitmap);
} catch (Exception e) {
e.printStackTrace();
}

bitmapDrawable = new BitmapDrawable(getResources(), bitmap);
} catch (Exception e) {
e.printStackTrace();
return bitmapDrawable;
}
return bitmapDrawable;
});
try {
bitmapDrawable = future.get();
} catch (Exception e) {
e.printStackTrace();
}
});
try {
bitmapDrawable = future.get();
} catch (Exception e) {
e.printStackTrace();
} finally {
// Without this, every call leaks the worker thread for the lifetime of the process.
executorService.shutdown();
}
return bitmapDrawable;
}
Expand Down