mirror of
https://github.com/vanitasvitae/Spherical
synced 2024-12-22 02:48:00 +01:00
Load images in AsyncTask. Fixes #10.
This commit is contained in:
parent
bd921bfc1b
commit
0fe9bb7ce7
2 changed files with 26 additions and 3 deletions
23
app/src/main/java/de/trac/spherical/HandleImageTask.java
Normal file
23
app/src/main/java/de/trac/spherical/HandleImageTask.java
Normal file
|
@ -0,0 +1,23 @@
|
|||
package de.trac.spherical;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.AsyncTask;
|
||||
|
||||
/**
|
||||
* Created by vanitas on 15.09.17.
|
||||
*/
|
||||
|
||||
public class HandleImageTask extends AsyncTask<Intent, Void, Void> {
|
||||
|
||||
private MainActivity mainActivity;
|
||||
|
||||
public HandleImageTask(MainActivity mainActivity) {
|
||||
this.mainActivity = mainActivity;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Intent... params) {
|
||||
mainActivity.handleSentImageIntent(params[0]);
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -119,7 +119,7 @@ public class MainActivity extends AppCompatActivity {
|
|||
private void checkPermissionAndHandleSentImage(Intent intent) {
|
||||
int status = ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE);
|
||||
if (status == PackageManager.PERMISSION_GRANTED) {
|
||||
handleSentImageIntent(intent);
|
||||
new HandleImageTask(this).doInBackground(intent);
|
||||
}
|
||||
|
||||
// Cache intent and request permission
|
||||
|
@ -137,7 +137,7 @@ public class MainActivity extends AppCompatActivity {
|
|||
// If request is cancelled, the result arrays are empty.
|
||||
if (grantResults.length > 0
|
||||
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||
handleSentImageIntent(cachedIntent);
|
||||
new HandleImageTask(this).doInBackground(cachedIntent);
|
||||
} else {
|
||||
Toast.makeText(this, R.string.toast_missing_permission, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
@ -184,7 +184,7 @@ public class MainActivity extends AppCompatActivity {
|
|||
* displayed, while images with MIME type image/* are being manually tested using {@link PhotoSphereParser}.
|
||||
* @param intent incoming intent.
|
||||
*/
|
||||
private void handleSentImageIntent(Intent intent) {
|
||||
void handleSentImageIntent(Intent intent) {
|
||||
String type = intent.getType();
|
||||
if (type != null) {
|
||||
|
||||
|
|
Loading…
Reference in a new issue