1
0
Fork 0
mirror of https://github.com/vanitasvitae/Spherical synced 2024-11-22 04:12:07 +01:00

Fix NPE, add permission for external storage

This commit is contained in:
vanitasvitae 2017-09-13 14:51:35 +02:00
parent 179d3b7bd2
commit a6f93088df
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
3 changed files with 23 additions and 8 deletions

View file

@ -2,6 +2,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.trac.spherical"> package="de.trac.spherical">
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<application <application
android:allowBackup="true" android:allowBackup="true"
android:icon="@mipmap/ic_launcher" android:icon="@mipmap/ic_launcher"
@ -23,6 +25,12 @@
<action android:name="android.intent.action.SEND" /> <action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.DEFAULT" />
</intent-filter> </intent-filter>
<intent-filter>
<data android:mimeType="image/*" />
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity> </activity>
</application> </application>

View file

@ -72,7 +72,7 @@ public class MainActivity extends AppCompatActivity {
displayPhotoSphere(imageUri); displayPhotoSphere(imageUri);
break; break;
case MIME_IMAGE: default:
displayMaybePhotoSphere(imageUri); displayMaybePhotoSphere(imageUri);
break; break;
} }
@ -92,12 +92,10 @@ public class MainActivity extends AppCompatActivity {
String xml = SphereParser.getXMLContent(inputStream); String xml = SphereParser.getXMLContent(inputStream);
PhotoSphereMetadata metadata = SphereParser.parse(xml); PhotoSphereMetadata metadata = SphereParser.parse(xml);
inputStream = getContentResolver().openInputStream(uri); if (metadata == null || !metadata.isUsePanoramaViewer()) {
displayFlatImage(getContentResolver().openInputStream(uri));
if (metadata.isUsePanoramaViewer()) {
displayPhotoSphere(inputStream, metadata);
} else { } else {
displayFlatImage(inputStream); displayPhotoSphere(getContentResolver().openInputStream(uri), metadata);
} }
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
@ -117,6 +115,11 @@ public class MainActivity extends AppCompatActivity {
String xml = SphereParser.getXMLContent(inputStream); String xml = SphereParser.getXMLContent(inputStream);
PhotoSphereMetadata metadata = SphereParser.parse(xml); PhotoSphereMetadata metadata = SphereParser.parse(xml);
if (metadata == null) {
Log.e(TAG, "Metadata is null. Fall back to flat image.");
displayFlatImage(getContentResolver().openInputStream(uri));
}
displayPhotoSphere(getContentResolver().openInputStream(uri), metadata); displayPhotoSphere(getContentResolver().openInputStream(uri), metadata);
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
@ -130,6 +133,7 @@ public class MainActivity extends AppCompatActivity {
private void displayPhotoSphere(InputStream inputStream, PhotoSphereMetadata metadata) { private void displayPhotoSphere(InputStream inputStream, PhotoSphereMetadata metadata) {
//Please fill me! //Please fill me!
Log.d(TAG, "Display Photo Sphere!");
} }
/** /**
@ -137,6 +141,6 @@ public class MainActivity extends AppCompatActivity {
* @param inputStream * @param inputStream
*/ */
private void displayFlatImage(InputStream inputStream) { private void displayFlatImage(InputStream inputStream) {
Log.d(TAG, "Display Flat Image!");
} }
} }

View file

@ -115,12 +115,15 @@ public class SphereParser {
byte[] xml = new byte[xmlLen - 2]; byte[] xml = new byte[xmlLen - 2];
i = inputStream.read(xml); i = inputStream.read(xml);
throwIfUnexpectedEOF(i, r.length); throwIfUnexpectedEOF(i, xml.length);
return new String(xml); return new String(xml);
} }
public static PhotoSphereMetadata parse(String xmp) { public static PhotoSphereMetadata parse(String xmp) {
if (xmp == null) {
return null;
}
PhotoSphereMetadata meta = new PhotoSphereMetadata(); PhotoSphereMetadata meta = new PhotoSphereMetadata();
meta.setUsePanoramaViewer(parseBoolean(USE_PANORAMA_VIEWER, xmp, true)); meta.setUsePanoramaViewer(parseBoolean(USE_PANORAMA_VIEWER, xmp, true));
meta.setCaptureSoftware(parseString(CAPTURE_SOFTWARE, xmp)); meta.setCaptureSoftware(parseString(CAPTURE_SOFTWARE, xmp));