Use the Photoshop Express editor in your own Android application
// code inside an Activity method
Uri imageToEditUri = … // uri of image to edit
String imageToEditMimeType = … // must be of type “image/*”
Intent launchEditor = new Intent();
launchEditor.setAction(Intent.ACTION_EDIT);
launchEditor.setDataAndType(imageToEditUri, imageToEditMimeType);
try
{
// start the editor activity
startActivityForResult(launchEditor, LAUNCH_EDITOR);
}
catch (ActivityNotFoundException e)
{
// Handle error condition. Correct version of
// Photoshop Express not installed?
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == LAUNCH_EDITOR)
{
if (resultCode == Activity.RESULT_OK)
{
Uri savedImage = data.getData();
// savedImage is the Uri for the newly created
// edited version of the original image.
}
else
{
// Edit Operation canceled by user
}
}
}
package com.adobe.psmobile.editor.launcherappone;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.widget.Toast;
// LauncherOneMain: Main activity for sample application that uses Photoshop Express Editor
public class LauncherOneMain extends Activity
{
private static final int SELECT_IMAGE = 0; // selector for image gallery call
private static final int LAUNCH_EDITOR = 1; // selector for editor launch call
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// launch the image picker
launchImagePicker();
}
// Launches the image picker.
public void launchImagePicker()
{
try
{
// This opens the Android Gallery or a similar activity
// that displays the images on the Android devices's SD card.
// The selected image is returned with a call to onActivityResult
// with the request code SELECT_IMAGE
startActivityForResult(new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI),
SELECT_IMAGE);
}
catch (ActivityNotFoundException e)
{
// No activity found that handles Intent.ACTION_PICK
}
}
/**
* onActivityResult: Called when an activity you launched exits,
* giving you the requestCode you started it with along with
* the resultCode it returned, and any additional returned data.
* The resultCode will be RESULT_CANCELED if the activity explicitly
* returned that, didn't return any result, or
* abnormally terminated during its operation.
*/
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == SELECT_IMAGE)
{
if (resultCode == Activity.RESULT_OK)
{
// get the Uri for the selected image
Uri selectedImage = data.getData();
// create an Intent to launch activity that
// supports ACTION_EDIT for
// the selected image. Photoshop Express Editor
// handles such intent
Intent launchEditor = new Intent();
launchEditor.setAction(Intent.ACTION_EDIT);
launchEditor.setDataAndType(selectedImage, data.getType());
try
{
// start the activity. Result will be returned in
// onActivityResult call with
// requestCode LAUNCH_EDITOR
startActivityForResult(launchEditor, LAUNCH_EDITOR);
}
catch (ActivityNotFoundException e)
{
// No activity found. Correct version of Photoshop Express
// Editor not installed.
Toast myToast = Toast.makeText(this,
new String("Failed to Launch Editor. Please make sure
Photoshop Express 1.1 or above is installed."),
Toast.LENGTH_SHORT);
myToast.show();
}
}
}
else if (requestCode == LAUNCH_EDITOR)
{
// returned from editor
String resultStr = null;
if (resultCode == Activity.RESULT_OK)
{
// Editor operation returned after saving the image.
// Get the Uri for the newly edited image that was saved.
Uri savedImage = data.getData();
resultStr = new String("Editor saved image to Uri: ") +
savedImage.toString();
}
else
{
// Editor operation canceled by user
resultStr = new String("Edit operation canceled.");
}
// display Toast with message
Toast myToast = Toast.makeText(this, resultStr, Toast.LENGTH_SHORT);
myToast.show();
// now that the editing operation has completed,
// launch the image picker again
launchImagePicker();
}
}
}