mirror of
https://github.com/vanitasvitae/Spherical
synced 2025-09-13 20:29:41 +02:00
Add more logic and metadata object.
This commit is contained in:
parent
68d2695fae
commit
c74c40dc7c
3 changed files with 98 additions and 18 deletions
|
@ -8,7 +8,6 @@ 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;
|
||||
|
@ -18,7 +17,9 @@ import de.trac.spherical.parser.SphereParser;
|
|||
public class MainActivity extends AppCompatActivity {
|
||||
|
||||
public static final String TAG = "Spherical";
|
||||
public static final String INTENT_SPHERE = "application/vnd.google.panorama360+jpg";
|
||||
|
||||
public static final String MIME_PHOTO_SPHERE = "application/vnd.google.panorama360+jpg";
|
||||
public static final String MIME_IMAGE = "image/*";
|
||||
|
||||
private TextView text;
|
||||
|
||||
|
@ -26,41 +27,81 @@ public class MainActivity extends AppCompatActivity {
|
|||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
//TODO: Remove later
|
||||
text = (TextView) findViewById(R.id.hello_world);
|
||||
|
||||
Log.d(TAG, "STARTING");
|
||||
Intent intent = getIntent();
|
||||
Log.d(TAG, "Intent: " + intent.getAction() + " " + intent.getType());
|
||||
|
||||
switch (intent.getAction()) {
|
||||
//Image was sent into the app
|
||||
case Intent.ACTION_SEND:
|
||||
handleSentImage(intent);
|
||||
break;
|
||||
handleSentImageIntent(intent);
|
||||
break;
|
||||
|
||||
//App was launched via launcher icon
|
||||
//TODO: Remove later together with launcher intent filter
|
||||
default:
|
||||
Toast.makeText(this, R.string.prompt_share_image, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
|
||||
private void handleSentImage(Intent intent) {
|
||||
/**
|
||||
* Distinguish type of sent image. Images with the MIME type of a photosphere will be directly
|
||||
* displayed, while images with MIME type image/* are being manually tested using {@link SphereParser}.
|
||||
* @param intent incoming intent.
|
||||
*/
|
||||
private void handleSentImageIntent(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();
|
||||
Uri imageUri = intent.getParcelableExtra(Intent.EXTRA_STREAM);
|
||||
if (imageUri == null) {
|
||||
Toast.makeText(this, R.string.file_not_found, Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
case MIME_PHOTO_SPHERE:
|
||||
displayPhotoSphere(imageUri);
|
||||
break;
|
||||
|
||||
case MIME_IMAGE:
|
||||
displayMaybePhotoSphere(imageUri);
|
||||
break;
|
||||
}
|
||||
|
||||
} else {
|
||||
Toast.makeText(this, "LOL", Toast.LENGTH_SHORT).show();
|
||||
Toast.makeText(this, "TODO: Figure out what to do :D", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
private void showImage(Uri uri) {
|
||||
/**
|
||||
* Check, whether the sent photo is a photo sphere and display either a sphere, or a plain image.
|
||||
* @param uri
|
||||
*/
|
||||
private void displayMaybePhotoSphere(Uri uri) {
|
||||
try {
|
||||
InputStream inputStream = getContentResolver().openInputStream(uri);
|
||||
String xml = SphereParser.getXMLContent(inputStream);
|
||||
|
||||
boolean sphere = true; //TODO: parser.
|
||||
|
||||
if (sphere) {
|
||||
displayPhotoSphere(uri);
|
||||
} else {
|
||||
displayFlatImage(uri);
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a photo sphere.
|
||||
* @param uri
|
||||
*/
|
||||
private void displayPhotoSphere(Uri uri) {
|
||||
try {
|
||||
InputStream inputStream = getContentResolver().openInputStream(uri);
|
||||
String xml = SphereParser.getXMLContent(inputStream);
|
||||
|
@ -79,4 +120,12 @@ public class MainActivity extends AppCompatActivity {
|
|||
Toast.makeText(this, R.string.ioerror, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a flat image.
|
||||
* @param uri
|
||||
*/
|
||||
private void displayFlatImage(Uri uri) {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue