mirror of
https://github.com/vanitasvitae/Spherical
synced 2024-11-22 12:22:08 +01:00
Read images and display their metadata
This commit is contained in:
parent
57b3068e70
commit
68d2695fae
4 changed files with 70 additions and 6 deletions
|
@ -1,23 +1,82 @@
|
||||||
package de.trac.spherical;
|
package de.trac.spherical;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.net.Uri;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
import de.trac.spherical.parser.SphereParser;
|
||||||
|
|
||||||
public class MainActivity extends AppCompatActivity {
|
public class MainActivity extends AppCompatActivity {
|
||||||
|
|
||||||
public static final String TAG = "Spherical";
|
public static final String TAG = "Spherical";
|
||||||
|
public static final String INTENT_SPHERE = "application/vnd.google.panorama360+jpg";
|
||||||
|
|
||||||
|
private TextView text;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
|
text = (TextView) findViewById(R.id.hello_world);
|
||||||
|
|
||||||
|
Log.d(TAG, "STARTING");
|
||||||
Intent intent = getIntent();
|
Intent intent = getIntent();
|
||||||
String action = intent.getAction();
|
Log.d(TAG, "Intent: " + intent.getAction() + " " + intent.getType());
|
||||||
String type = intent.getType();
|
|
||||||
|
|
||||||
Log.d(TAG, "Intent: " + action + " " + type);
|
switch (intent.getAction()) {
|
||||||
|
case Intent.ACTION_SEND:
|
||||||
|
handleSentImage(intent);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
Toast.makeText(this, R.string.prompt_share_image, Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleSentImage(Intent intent) {
|
||||||
|
String type = intent.getType();
|
||||||
|
if (type != null) {
|
||||||
|
switch (type) {
|
||||||
|
case INTENT_SPHERE:
|
||||||
|
Uri imageUri = intent.getParcelableExtra(Intent.EXTRA_STREAM);
|
||||||
|
if (imageUri != null) {
|
||||||
|
showImage(imageUri);
|
||||||
|
}
|
||||||
|
|
||||||
|
Toast.makeText(this, R.string.wow, Toast.LENGTH_LONG).show();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Toast.makeText(this, "LOL", Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showImage(Uri uri) {
|
||||||
|
try {
|
||||||
|
InputStream inputStream = getContentResolver().openInputStream(uri);
|
||||||
|
String xml = SphereParser.getXMLContent(inputStream);
|
||||||
|
|
||||||
|
if (xml != null) {
|
||||||
|
text.setText(xml);
|
||||||
|
} else {
|
||||||
|
text.setText("null");
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
Log.e(TAG, "File not found.", e);
|
||||||
|
Toast.makeText(this, R.string.file_not_found, Toast.LENGTH_SHORT).show();
|
||||||
|
} catch (IOException e) {
|
||||||
|
Log.e(TAG, "IOException: ", e);
|
||||||
|
Toast.makeText(this, R.string.ioerror, Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -102,7 +102,7 @@ public class SphereParser {
|
||||||
System.out.println(getXMLContent(new FileInputStream(file)));
|
System.out.println(getXMLContent(new FileInputStream(file)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void unread(ArrayList<Byte> list, PushbackInputStream pb) throws IOException {
|
private static void unread(ArrayList<Byte> list, PushbackInputStream pb) throws IOException {
|
||||||
for (int i = list.size() - 1; i >= 0; i--) {
|
for (int i = list.size() - 1; i >= 0; i--) {
|
||||||
pb.unread(list.get(i));
|
pb.unread(list.get(i));
|
||||||
}
|
}
|
||||||
|
@ -114,11 +114,11 @@ public class SphereParser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String hex(byte[] b) {
|
private static String hex(byte[] b) {
|
||||||
return new BigInteger(b).toString(16);
|
return new BigInteger(b).toString(16);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int integer(byte[] b) {
|
private static int integer(byte[] b) {
|
||||||
return new BigInteger(b).intValue();
|
return new BigInteger(b).intValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
tools:context="de.trac.spherical.MainActivity">
|
tools:context="de.trac.spherical.MainActivity">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
|
android:id="@+id/hello_world"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="Hello World!"
|
android:text="Hello World!"
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
<resources>
|
<resources>
|
||||||
<string name="app_name">Spherical</string>
|
<string name="app_name">Spherical</string>
|
||||||
|
<string name="prompt_share_image">Share an image with the app!</string>
|
||||||
|
<string name="file_not_found">File not found.</string>
|
||||||
|
<string name="ioerror">An Error has occurred: IOError.</string>
|
||||||
|
<string name="wow">WOW! SUCH 3D!!!</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Reference in a new issue