Skip to content

Instantly share code, notes, and snippets.

@bradtheappguy
Created April 26, 2013 18:10
Show Gist options
  • Save bradtheappguy/5469209 to your computer and use it in GitHub Desktop.
Save bradtheappguy/5469209 to your computer and use it in GitHub Desktop.
R1 Effects SDK Android Integration Guidw

Introduction


The Android R1 Photo Effects SDK allows developers to include a suite of image effects to their applications.

Installation


1. Download and Install the Photo Effects SDK

  • 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.

2. Create a New Project.

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)

Alt text

  • Select Next on the following screens and finish when possible

3. Add the SDK as a Dependency.

[ In Eclipse ]

  • Select File
  • Select Import
  • Select Existing Android Code into Workspace
  • Select Next
  • Add the root directory for the unzipped SDK
  • Select Finish

Alt text

  • Right click your Application folder in the Package Explorer
  • Select Properties

Alt text

  • Select Java Build Path
  • Select Projects
  • Select Add
  • Select Check Project
  • Select OK
  • Select OK

Alt text

  • Right click your Application folder in the Package Explorer
  • Select Properties
  • Select Android
  • Select Add
  • Select the R1 Effects Project
  • Select OK
  • Select OK

Alt text

4. Configure the AndroidManifest.xml.

[ In Eclipse ]

  • Double click the AndroidManifest.xml file in the Package Explorer
  • Select the farthest tab to the right below the open window

Alt text

   // 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" />

Alt text

   // 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"/>  

Alt text

   // Inside of the application tag, add the following name
   android:name=".PhotoAccess"  

Alt text

5. Create a user interface.

[ 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

Alt text

// 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" />

Alt text

6. Create an application subclass for photo access.

[ In Eclipse ]

  • In package manager right click “com”
  • Select New
  • Select Class

Alt text

  • Name the Class PhotoAccess
  • Select Finish

Alt text

  • 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);
	}
}

7. Update the Main Activity Class to Communicate with the Photo Effects SDK.

[ 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);

					}
				}
			}
		}
	}
}

8. Include Assets in your Project.

  • Copy the Effects and fonts folders from the assets directory of the demo app to the assets directory in your project

9. Update the Subproject for Ant Builds.

  • On the command line, insert the following from the subproject root
android update project --target target_ID --path ~/path/to/subproject/root

10. Update the Project for Ant Builds.

  • 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

11. Build the 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment