Skip to content
This repository was archived by the owner on Jul 27, 2019. It is now read-only.

Commit ad086ee

Browse files
committed
Merge pull request #17 from CreativeSDK/ash/send-to-desktop-api
Ash/send to desktop api
2 parents c204c33 + 7e53ff9 commit ad086ee

File tree

31 files changed

+861
-0
lines changed

31 files changed

+861
-0
lines changed

send-to-desktop-api/.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea
5+
.DS_Store
6+
/build
7+
/captures
8+
9+
/app/src/main/java/com/adobe/sendtodesktopapi/Keys.java

send-to-desktop-api/app/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

send-to-desktop-api/app/build.gradle

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
apply plugin: 'com.android.application'
2+
3+
/* 1) Apply the Gradle Retrolambda Plugin */
4+
apply plugin: 'me.tatarka.retrolambda'
5+
6+
android {
7+
compileSdkVersion 23
8+
buildToolsVersion "23.0.2"
9+
10+
defaultConfig {
11+
applicationId "com.adobe.sendtodesktopapi"
12+
minSdkVersion 16 // Minimum is 16
13+
targetSdkVersion 23
14+
versionCode 1
15+
versionName "1.0"
16+
}
17+
buildTypes {
18+
release {
19+
minifyEnabled false
20+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
21+
}
22+
}
23+
24+
/* 2) Compile for Java 1.8 or greater */
25+
compileOptions {
26+
sourceCompatibility JavaVersion.VERSION_1_8
27+
targetCompatibility JavaVersion.VERSION_1_8
28+
}
29+
30+
/* 3) Exclude duplicate licenses */
31+
packagingOptions {
32+
exclude 'META-INF/LICENSE.txt'
33+
exclude 'META-INF/LICENSE'
34+
exclude 'META-INF/NOTICE.txt'
35+
exclude 'META-INF/NOTICE'
36+
exclude 'META-INF/DEPENDENCIES'
37+
pickFirst 'AndroidManifest.xml'
38+
}
39+
}
40+
41+
dependencies {
42+
compile fileTree(dir: 'libs', include: ['*.jar'])
43+
testCompile 'junit:junit:4.12'
44+
compile 'com.android.support:appcompat-v7:23.1.1'
45+
compile 'com.android.support:design:23.1.1'
46+
47+
/* 4) Add the CSDK framework dependencies (Make sure these version numbers are correct) */
48+
compile 'com.adobe.creativesdk.foundation:auth:0.9.7'
49+
compile 'com.adobe.creativesdk.foundation:assetcore:0.9.7'
50+
51+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Add project specific ProGuard rules here.
2+
# By default, the flags in this file are appended to flags specified
3+
# in /Users/arnwine/Library/Android/sdk/tools/proguard/proguard-android.txt
4+
# You can edit the include path and order by changing the proguardFiles
5+
# directive in build.gradle.
6+
#
7+
# For more details, see
8+
# http://developer.android.com/guide/developing/tools/proguard.html
9+
10+
# Add any project specific keep options here:
11+
12+
# If your project uses WebView with JS, uncomment the following
13+
# and specify the fully qualified class name to the JavaScript interface
14+
# class:
15+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16+
# public *;
17+
#}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.adobe.sendtodesktopapi;
2+
3+
import android.app.Application;
4+
import android.test.ApplicationTestCase;
5+
6+
/**
7+
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
8+
*/
9+
public class ApplicationTest extends ApplicationTestCase<Application> {
10+
public ApplicationTest() {
11+
super(Application.class);
12+
}
13+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.adobe.sendtodesktopapi">
4+
5+
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
6+
7+
<application
8+
android:allowBackup="true"
9+
android:icon="@mipmap/ic_launcher"
10+
android:label="@string/app_name"
11+
android:supportsRtl="true"
12+
android:theme="@style/AppTheme"
13+
android:name=".MainApplication">
14+
<activity
15+
android:name=".MainActivity"
16+
android:label="@string/app_name"
17+
android:theme="@style/AppTheme.NoActionBar">
18+
<intent-filter>
19+
<action android:name="android.intent.action.MAIN" />
20+
21+
<category android:name="android.intent.category.LAUNCHER" />
22+
</intent-filter>
23+
</activity>
24+
</application>
25+
26+
</manifest>
Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
package com.adobe.sendtodesktopapi;
2+
3+
import android.content.Intent;
4+
import android.graphics.Bitmap;
5+
import android.net.Uri;
6+
import android.os.Bundle;
7+
import android.provider.MediaStore;
8+
import android.support.design.widget.FloatingActionButton;
9+
import android.support.design.widget.Snackbar;
10+
import android.support.v7.app.AppCompatActivity;
11+
import android.support.v7.widget.Toolbar;
12+
import android.util.Log;
13+
import android.view.Menu;
14+
import android.view.MenuItem;
15+
import android.view.View;
16+
import android.widget.Button;
17+
import android.widget.ImageView;
18+
import android.widget.Toast;
19+
20+
import com.adobe.creativesdk.foundation.auth.AdobeAuthException;
21+
import com.adobe.creativesdk.foundation.auth.AdobeAuthSessionHelper;
22+
import com.adobe.creativesdk.foundation.auth.AdobeAuthSessionLauncher;
23+
import com.adobe.creativesdk.foundation.auth.AdobeUXAuthManager;
24+
import com.adobe.creativesdk.foundation.sendtodesktop.AdobeCreativeCloudApplication;
25+
import com.adobe.creativesdk.foundation.sendtodesktop.AdobeSendToDesktopApplication;
26+
import com.adobe.creativesdk.foundation.sendtodesktop.AdobeSendToDesktopException;
27+
import com.adobe.creativesdk.foundation.sendtodesktop.IAdobeSendToDesktopCallBack;
28+
29+
import java.io.IOException;
30+
31+
public class MainActivity extends AppCompatActivity {
32+
33+
private AdobeUXAuthManager mUXAuthManager = AdobeUXAuthManager.getSharedAuthManager();
34+
private AdobeAuthSessionHelper mAuthSessionHelper;
35+
36+
private Button mOpenGalleryButton;
37+
private Button mSendToPhotoshopButton;
38+
private ImageView mSelectedImageView;
39+
40+
private Uri mSelectedImageUri;
41+
42+
@Override
43+
protected void onCreate(Bundle savedInstanceState) {
44+
super.onCreate(savedInstanceState);
45+
setContentView(R.layout.activity_main);
46+
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
47+
setSupportActionBar(toolbar);
48+
49+
mAuthSessionHelper = new AdobeAuthSessionHelper(mStatusCallback);
50+
mAuthSessionHelper.onCreate(savedInstanceState);
51+
52+
mOpenGalleryButton = (Button) findViewById(R.id.openGalleryButton);
53+
mSendToPhotoshopButton = (Button) findViewById(R.id.sendToPhotoshopButton);
54+
mSelectedImageView = (ImageView) findViewById(R.id.selectedImageView);
55+
56+
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
57+
fab.setOnClickListener(new View.OnClickListener() {
58+
@Override
59+
public void onClick(View view) {
60+
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
61+
.setAction("Action", null).show();
62+
}
63+
});
64+
}
65+
66+
private AdobeAuthSessionHelper.IAdobeAuthStatusCallback mStatusCallback;
67+
{
68+
mStatusCallback = new AdobeAuthSessionHelper.IAdobeAuthStatusCallback() {
69+
@Override
70+
public void call(AdobeAuthSessionHelper.AdobeAuthStatus adobeAuthStatus, AdobeAuthException e) {
71+
if (AdobeAuthSessionHelper.AdobeAuthStatus.AdobeAuthLoggedIn == adobeAuthStatus) {
72+
73+
showAuthenticatedUI();
74+
75+
} else {
76+
77+
showAdobeLoginUI();
78+
79+
}
80+
}
81+
};
82+
}
83+
84+
private void showAdobeLoginUI() {
85+
mUXAuthManager.login(new AdobeAuthSessionLauncher.Builder()
86+
.withActivity(this)
87+
.withRequestCode(200) // Can be any int
88+
.build()
89+
);
90+
}
91+
92+
private void showAuthenticatedUI() {
93+
94+
Log.i(MainActivity.class.getSimpleName(), "User is logged in!");
95+
96+
View.OnClickListener openGalleryButtonListener = new View.OnClickListener() {
97+
@Override
98+
public void onClick(View v) {
99+
Intent galleryPickerIntent = new Intent();
100+
galleryPickerIntent.setType("image/*");
101+
galleryPickerIntent.setAction(Intent.ACTION_GET_CONTENT);
102+
103+
startActivityForResult(Intent.createChooser(galleryPickerIntent, "Select an Image"), 203); // Can be any int
104+
}
105+
};
106+
mOpenGalleryButton.setOnClickListener(openGalleryButtonListener);
107+
108+
View.OnClickListener sendToPhotoshopButtonListener = new View.OnClickListener() {
109+
@Override
110+
public void onClick(View v) {
111+
try {
112+
sendToDesktop();
113+
} catch (IOException e) {
114+
e.printStackTrace();
115+
}
116+
}
117+
};
118+
mSendToPhotoshopButton.setOnClickListener(sendToPhotoshopButtonListener);
119+
120+
}
121+
122+
private void sendToDesktop() throws IOException {
123+
/* 1) Get the image Bitmap */
124+
Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), mSelectedImageUri);
125+
126+
/* 2) Specify the Adobe desktop app to send to */
127+
AdobeCreativeCloudApplication creativeCloudApplication = AdobeCreativeCloudApplication.AdobePhotoshopCreativeCloud;
128+
129+
/* 3) Make a callback to handle success and error */
130+
final IAdobeSendToDesktopCallBack sendToDesktopCallBack = new IAdobeSendToDesktopCallBack() {
131+
@Override
132+
public void onSuccess() {
133+
// Success case example
134+
Toast.makeText(MainActivity.this, "Opening in Photoshop on your desktop!", Toast.LENGTH_LONG).show();
135+
}
136+
137+
@Override
138+
public void onError(AdobeSendToDesktopException e) {
139+
// Error case example
140+
Toast.makeText(MainActivity.this, "Failed!", Toast.LENGTH_LONG).show();
141+
142+
e.printStackTrace();
143+
}
144+
};
145+
146+
/* 4) Send the image to the desktop! */
147+
AdobeSendToDesktopApplication.sendImage(bitmap, creativeCloudApplication, "My image title", sendToDesktopCallBack);
148+
}
149+
150+
@Override
151+
protected void onResume() {
152+
super.onResume();
153+
mAuthSessionHelper.onResume();
154+
}
155+
156+
@Override
157+
protected void onPause() {
158+
super.onPause();
159+
mAuthSessionHelper.onPause();
160+
}
161+
162+
@Override
163+
protected void onStart() {
164+
super.onStart();
165+
mAuthSessionHelper.onStart();
166+
}
167+
168+
@Override
169+
protected void onStop() {
170+
super.onStop();
171+
mAuthSessionHelper.onStop();
172+
}
173+
174+
@Override
175+
protected void onDestroy() {
176+
super.onDestroy();
177+
mAuthSessionHelper.onDestroy();
178+
}
179+
180+
@Override
181+
public void onActivityResult(int requestCode, int resultCode, Intent data) {
182+
super.onActivityResult(requestCode, resultCode, data);
183+
mAuthSessionHelper.onActivityResult(requestCode, resultCode, data);
184+
185+
if (resultCode == RESULT_OK && requestCode == 203) { // the int we used for startActivityForResult()
186+
187+
mSelectedImageUri = data.getData();
188+
mSelectedImageView.setImageURI(mSelectedImageUri);
189+
190+
}
191+
}
192+
193+
@Override
194+
public boolean onCreateOptionsMenu(Menu menu) {
195+
// Inflate the menu; this adds items to the action bar if it is present.
196+
getMenuInflater().inflate(R.menu.menu_main, menu);
197+
return true;
198+
}
199+
200+
@Override
201+
public boolean onOptionsItemSelected(MenuItem item) {
202+
// Handle action bar item clicks here. The action bar will
203+
// automatically handle clicks on the Home/Up button, so long
204+
// as you specify a parent activity in AndroidManifest.xml.
205+
int id = item.getItemId();
206+
207+
//noinspection SimplifiableIfStatement
208+
if (id == R.id.action_logout) {
209+
mUXAuthManager.logout();
210+
return true;
211+
}
212+
213+
return super.onOptionsItemSelected(item);
214+
}
215+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.adobe.sendtodesktopapi;
2+
3+
import android.app.Application;
4+
5+
import com.adobe.creativesdk.foundation.AdobeCSDKFoundation;
6+
import com.adobe.creativesdk.foundation.auth.IAdobeAuthClientCredentials;
7+
8+
/**
9+
* Created by ash on 3/12/16.
10+
*/
11+
public class MainApplication extends Application implements IAdobeAuthClientCredentials {
12+
13+
/* Be sure to fill in the two strings below. */
14+
private static final String CREATIVE_SDK_CLIENT_ID = Keys.CSDK_CLIENT_ID;
15+
private static final String CREATIVE_SDK_CLIENT_SECRET = Keys.CSDK_CLIENT_SECRET;
16+
17+
@Override
18+
public void onCreate() {
19+
super.onCreate();
20+
AdobeCSDKFoundation.initializeCSDKFoundation(getApplicationContext());
21+
}
22+
23+
@Override
24+
public String getClientID() {
25+
return CREATIVE_SDK_CLIENT_ID;
26+
}
27+
28+
@Override
29+
public String getClientSecret() {
30+
return CREATIVE_SDK_CLIENT_SECRET;
31+
}
32+
}
33+

0 commit comments

Comments
 (0)