mirror of
https://github.com/vanitasvitae/Spherical
synced 2025-12-07 21:01:31 +01:00
Use Butterknife, properly display progressFragment
This commit is contained in:
parent
7932d00cdc
commit
92c84e8281
9 changed files with 177 additions and 139 deletions
76
app/src/main/java/de/trac/spherical/util/LoadImageTask.java
Normal file
76
app/src/main/java/de/trac/spherical/util/LoadImageTask.java
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
package de.trac.spherical.util;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import de.trac.spherical.parser.PhotoSphereMetadata;
|
||||
import de.trac.spherical.parser.PhotoSphereParser;
|
||||
|
||||
/**
|
||||
* Dedicated async tasks to load an image.
|
||||
* Takes a progress reporter and informs it about the changes.
|
||||
*/
|
||||
public class LoadImageTask extends AsyncTask<Void, Void, LoadImageTask.Result> {
|
||||
|
||||
private ContentResolver contentResolver;
|
||||
private Uri uri;
|
||||
|
||||
private Bitmap bitmap;
|
||||
private PhotoSphereMetadata metadata;
|
||||
private final String type;
|
||||
private final FinishedCallback callback;
|
||||
|
||||
public LoadImageTask(ContentResolver contentResolver, Uri uri, String type, FinishedCallback callback) {
|
||||
this.callback = callback;
|
||||
this.contentResolver = contentResolver;
|
||||
this.uri = uri;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Result doInBackground(Void... params) {
|
||||
|
||||
try {
|
||||
bitmap = BitmapFactory.decodeStream(contentResolver.openInputStream(uri));
|
||||
metadata = PhotoSphereParser.parse(contentResolver.openInputStream(uri));
|
||||
return new Result(bitmap, metadata);
|
||||
} catch (IOException | OutOfMemoryError e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Result result) {
|
||||
callback.onImageLoadingFinished(result);
|
||||
}
|
||||
|
||||
public interface FinishedCallback {
|
||||
void onImageLoadingFinished(Result result);
|
||||
}
|
||||
|
||||
public static class Result {
|
||||
|
||||
private Bitmap bitmap;
|
||||
private PhotoSphereMetadata metadata;
|
||||
|
||||
public Result(Bitmap bitmap, PhotoSphereMetadata metadata) {
|
||||
this.bitmap = bitmap;
|
||||
this.metadata = metadata;
|
||||
}
|
||||
|
||||
public Bitmap getBitmap() {
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
public PhotoSphereMetadata getMetadata() {
|
||||
return metadata;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue