The Android R1 Photo Effects SDK allows developers to include a suite of image effects to their applications.
- Download the R1Effects ZIP file to your local machine from https://r1sdk.com/download
- Unzip this file to a location on your machine. Make sure that this location is not in the literal workspace for your project. It includes the R1 Photo Effects SDK and an SDK demo app for installation reference.
If you already have a project, skip to step 3.
[ In Eclipse ]
- Select File
- Select New
- Select Android Application Project
- Create an application name (“MyPhotoEffects” for example) and set the Minimum Required SDK to 2.3 (Gingerbread)
- Select Next on the following screens and finish when possible
[ In Eclipse ]
- Select File
- Select Import
- Select Existing Android Code into Workspace
- Select Next
- Add the root directory for the unzipped SDK
- Select Finish
- Right click your Application folder in the Package Explorer
- Select Properties
- Select Java Build Path
- Select Projects
- Select Add
- Select Check Project
- Select OK
- Select OK
- Right click your Application folder in the Package Explorer
- Select Properties
- Select Android
- Select Add
- Select the R1 Effects Project
- Select OK
- Select OK
[ In Eclipse ]
- Double click the AndroidManifest.xml file in the Package Explorer
- Select the farthest tab to the right below the open window
// Inside of the manifest tag, add the following permissions
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
// Inside of the manifest tag, add the following features
<uses-feature android:glEsVersion="0x00020000" android:required="true"/>
<uses-feature android:name="android.hardware.camera" />
// Inside of the application tag, add the following activities
<activity android:name="com.radiumone.viame_android.activities.CropImage"
android:configChanges="orientation|keyboardHidden"
android:screenOrientation="portrait" />
<activity android:name="com.radiumone.viame_android.activities.ApplyFilterActivity"
android:configChanges="orientation|keyboardHidden"
android:launchMode="singleTop"
android:screenOrientation="portrait" />
// Inside of the application tag, add the following service
<service android:name="com.radiumone.viame_android.filters.FilterDownloadManager"/>
// Inside of the application tag, add the following name
android:name=".PhotoAccess"
[ In Eclipse ]
- In the package explorer select the “res” folder triangle
- Select the “layout” folder triangle
- Double click activity_main.xml
- Select the farthest tab to the right below the open window
// Remove the TextView tag inside the RelativeLayout
// Inside the RelativeLayout tag add the following button
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:text="Launch SDK" />
// Inside the RelativeLayout tag add the following image view
<ImageView
android:id="@+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:src="@drawable/ic_launcher" />
[ In Eclipse ]
- In package manager right click “com”
- Select New
- Select Class
- Name the Class PhotoAccess
- Select Finish
- Modify the code so that PhotoAccess extends Application.
// Before the class, reference your app package
package com.example.myphotoeffects;
// Before the class, import the following
import android.app.Application;
import android.content.Intent;
import android.provider.MediaStore;
// Before the class, import the following from the SDK
import com.radiumone.viame_android.admin.Registration;
import com.radiumone.viame_android.filters.FilterDownloadManager;
// Extend Application with PhotoAccess
public class PhotoAccess extends Application {
@Override
public void onCreate() {
super.onCreate();
// Start download process for stickers and scenes
// Replace YOUR_APP_TOKEN with your unique SDK ID
Registration.getRegistration().setAppToken(this, "YOUR_APP_TOKEN");
Intent filterIntent = new Intent(this, FilterDownloadManager.class);
startService(filterIntent);
}
}
[ In Eclipse ]
- In the package explorer Select “src”
- Select “com”
- Double Click "MainActivity.java"
// Before the class, reference your app package
package com.example.myphotoeffects;
// Before the class, import the following
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.util.DisplayMetrics;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
// Before the class, import the following from the SDK
import com.radiumone.viame_android.activities.ApplyFilterActivity;
import com.radiumone.viame_android.activities.CropImage;
import com.radiumone.viame_android.util.ImageUtils;
import com.radiumone.viame_android.util.MediaHelper;
public class MainActivity extends Activity {
// Declare and assign arbitrary values to the following variables for activity results
public static final int REQUEST_CROP_IMAGE = 100;
public static final int REQUEST_GALLERY_SELECT = 500;
// Declare an image view for final image
private ImageView imageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Declare a button and add an event listener
Button button1 = (Button) findViewById(R.id.button1);
button1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// Open device gallery
startSelectPicture();
}
});
// Assign image view
imageView = (ImageView) findViewById(R.id.imageView1);
}
// Create method that sends user to the device media gallery
// You could also send the user to the camera
protected void startSelectPicture() {
// Declare and assign and intent for the media gallery
Intent intent;
intent = new Intent(Intent.ACTION_PICK,
MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
intent.setType("image/*");
// Send the user to the device media gallery
// REQUEST_GALLERY_SELECT specifies the activity result
startActivityForResult(intent, REQUEST_GALLERY_SELECT);
}
// Create method that handles activity results
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// Handle activities accordingly
switch (requestCode) {
// Handle the image returned from the device media gallery
case REQUEST_GALLERY_SELECT:
// Check for error
if (resultCode == RESULT_OK) {
// Declare and assign URI to selected device media gallery image
Uri selectedImageUri = data.getData();
// Declare intent and assign to Photo Effects SDK
Intent intent = new Intent(this, CropImage.class);
// Pass image URI to SDK
intent.setData(selectedImageUri);
// Send the user to the SDK
// REQUEST_CROP_IMAGE specified the activity result
startActivityForResult(intent, REQUEST_CROP_IMAGE);
}
break;
// Handle the image returned from the Photo SDK
case REQUEST_CROP_IMAGE:
if (resultCode == RESULT_OK) {
// Declare a string and assign it to the SDK photo path
String photoPath = data.getStringExtra(ApplyFilterActivity.EXTRA_PHOTO_FILE_PATH);
// Check for failure
if (photoPath != null) {
// Declare and assign display metrics variable for screen info
DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
// Declare and assign bitmap to display SDK photo
Bitmap bitmap = ImageUtils.loadBitmapImage(photoPath,displayMetrics.widthPixels,displayMetrics.widthPixels);
// Display bitmap in the image view if it exists
if (bitmap != null) {
imageView.setImageBitmap(bitmap);
}
}
}
}
}
}
- Copy the Effects and fonts folders from the assets directory of the demo app to the assets directory in your project
- On the command line, insert the following from the subproject root
android update project --target target_ID --path ~/path/to/subproject/root
- On the command line, insert the following from the project root if the subproject is not displayed in project.properties of your project root
android update project --target target_ID --path path/to/your/project --library relative/path/to/library_project
- On the command line, in the root directory of your project, enter the following
ant clean debug
- To build the app to a device, enter the following
adb install -r bin/APK_NAME.apk