|
|
|
@ -1,12 +1,15 @@
|
|
|
|
|
package de.trac.spherical; |
|
|
|
|
|
|
|
|
|
import android.Manifest; |
|
|
|
|
import android.content.Intent; |
|
|
|
|
import android.content.pm.PackageManager; |
|
|
|
|
import android.graphics.BitmapFactory; |
|
|
|
|
import android.net.Uri; |
|
|
|
|
import android.os.Build; |
|
|
|
|
import android.os.Bundle; |
|
|
|
|
import android.support.design.widget.AppBarLayout; |
|
|
|
|
import android.support.design.widget.FloatingActionButton; |
|
|
|
|
import android.support.v4.app.ActivityCompat; |
|
|
|
|
import android.support.v4.content.ContextCompat; |
|
|
|
|
import android.support.v7.app.AppCompatActivity; |
|
|
|
|
import android.support.v7.widget.Toolbar; |
|
|
|
|
import android.util.Log; |
|
|
|
@ -38,11 +41,15 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
public static final String MIME_PHOTO_SPHERE = "application/vnd.google.panorama360+jpg"; |
|
|
|
|
public static final String MIME_IMAGE = "image/*"; |
|
|
|
|
|
|
|
|
|
private static final int PERMISSION_REQUEST_READ_EXTERNAL_STORAGE = 387; |
|
|
|
|
|
|
|
|
|
private SphereSurfaceView surfaceView; |
|
|
|
|
private Renderer renderer; |
|
|
|
|
private FloatingActionButton fab; |
|
|
|
|
private Toolbar toolbar; |
|
|
|
|
|
|
|
|
|
private Intent cachedIntent; |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
protected void onCreate(Bundle savedInstanceState) { |
|
|
|
|
super.onCreate(savedInstanceState); |
|
|
|
@ -92,11 +99,14 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
Intent intent = getIntent(); |
|
|
|
|
handleIntent(getIntent()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void handleIntent(Intent intent) { |
|
|
|
|
switch (intent.getAction()) { |
|
|
|
|
//Image was sent into the app
|
|
|
|
|
case Intent.ACTION_SEND: |
|
|
|
|
handleSentImageIntent(intent); |
|
|
|
|
checkPermissionAndHandleSentImage(intent); |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
//App was launched via launcher icon
|
|
|
|
@ -106,6 +116,36 @@ 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); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Cache intent and request permission
|
|
|
|
|
this.cachedIntent = intent; |
|
|
|
|
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, |
|
|
|
|
PERMISSION_REQUEST_READ_EXTERNAL_STORAGE); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void onRequestPermissionsResult(int requestCode, |
|
|
|
|
String permissions[], int[] grantResults) { |
|
|
|
|
switch (requestCode) { |
|
|
|
|
case PERMISSION_REQUEST_READ_EXTERNAL_STORAGE: { |
|
|
|
|
// If request is cancelled, the result arrays are empty.
|
|
|
|
|
if (grantResults.length > 0 |
|
|
|
|
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) { |
|
|
|
|
handleSentImageIntent(cachedIntent); |
|
|
|
|
} else { |
|
|
|
|
Toast.makeText(this, R.string.missing_permission, Toast.LENGTH_LONG).show(); |
|
|
|
|
} |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void displayUI(boolean display) { |
|
|
|
|
if (display) { |
|
|
|
|
fab.show(); |
|
|
|
|