2017-09-12 14:54:41 +02:00
|
|
|
package de.trac.spherical;
|
|
|
|
|
2017-09-12 18:11:58 +02:00
|
|
|
import android.content.Intent;
|
2017-09-12 19:50:59 +02:00
|
|
|
import android.net.Uri;
|
2017-09-12 14:54:41 +02:00
|
|
|
import android.support.v7.app.AppCompatActivity;
|
|
|
|
import android.os.Bundle;
|
2017-09-12 18:11:58 +02:00
|
|
|
import android.util.Log;
|
2017-09-12 19:50:59 +02:00
|
|
|
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;
|
2017-09-12 14:54:41 +02:00
|
|
|
|
|
|
|
public class MainActivity extends AppCompatActivity {
|
|
|
|
|
2017-09-12 18:11:58 +02:00
|
|
|
public static final String TAG = "Spherical";
|
2017-09-12 19:50:59 +02:00
|
|
|
public static final String INTENT_SPHERE = "application/vnd.google.panorama360+jpg";
|
|
|
|
|
|
|
|
private TextView text;
|
2017-09-12 18:11:58 +02:00
|
|
|
|
2017-09-12 14:54:41 +02:00
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
setContentView(R.layout.activity_main);
|
2017-09-12 19:50:59 +02:00
|
|
|
text = (TextView) findViewById(R.id.hello_world);
|
2017-09-12 18:11:58 +02:00
|
|
|
|
2017-09-12 19:50:59 +02:00
|
|
|
Log.d(TAG, "STARTING");
|
2017-09-12 18:11:58 +02:00
|
|
|
Intent intent = getIntent();
|
2017-09-12 19:50:59 +02:00
|
|
|
Log.d(TAG, "Intent: " + intent.getAction() + " " + intent.getType());
|
|
|
|
|
|
|
|
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) {
|
2017-09-12 18:11:58 +02:00
|
|
|
String type = intent.getType();
|
2017-09-12 19:50:59 +02:00
|
|
|
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");
|
|
|
|
}
|
2017-09-12 18:11:58 +02:00
|
|
|
|
2017-09-12 19:50:59 +02:00
|
|
|
} 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();
|
|
|
|
}
|
2017-09-12 14:54:41 +02:00
|
|
|
}
|
|
|
|
}
|