diff --git a/ShareFileJavaSDK/.classpath b/.classpath similarity index 77% rename from ShareFileJavaSDK/.classpath rename to .classpath index 17af937..db62127 100644 --- a/ShareFileJavaSDK/.classpath +++ b/.classpath @@ -2,7 +2,7 @@ - + diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..00a51af --- /dev/null +++ b/.gitattributes @@ -0,0 +1,6 @@ +# +# https://help.github.com/articles/dealing-with-line-endings/ +# +# These are explicitly windows files and should use crlf +*.bat text eol=crlf + diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml new file mode 100644 index 0000000..9942dd6 --- /dev/null +++ b/.github/workflows/CI.yml @@ -0,0 +1,31 @@ +name: CI + +on: + push: + branches: + - master + pull_request: + branches: + - master + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Set up JDK 11 + uses: actions/setup-java@v3 + with: + java-version: '11' + distribution: 'temurin' + cache: gradle + + - uses: gradle/gradle-build-action@v3 + # env: + # CREDENTIALS: -PGITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} -PGITHUB_USER=${{ github.actor }} -- ${CREDENTIALS} + with: + gradle-version: wrapper + arguments: build -PGITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} -PGITHUB_USER=${{ github.actor }} + diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..1074f62 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,31 @@ +name: Publish package to GitHub Packages +on: + push: + branches: + - master +jobs: + publish: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-java@v3 + with: + java-version: '11' + distribution: 'temurin' + cache: gradle + + # - name: Publish artifact + # env: + # CREDENTIALS: -PGITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} -PGITHUB_USER=${{ github.actor }} + + # run: ./gradlew -Pversion=${{github.ref_name}} publish ${CREDENTIALS} + # - name: Gradle bygg av services + # env: + # CREDENTIALS: -PGITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} -PGITHUB_USER=${{ github.actor }} + # run: ./gradlew build ${CREDENTIALS} + + - name: Publish artifact + uses: gradle/gradle-build-action@v3 + with: + gradle-version: wrapper + arguments: publish -PGITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} -PGITHUB_USER=${{ github.actor }} diff --git a/ShareFileJavaSDK/.project b/.project similarity index 100% rename from ShareFileJavaSDK/.project rename to .project diff --git a/ShareFileJavaSDK/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs similarity index 100% rename from ShareFileJavaSDK/.settings/org.eclipse.jdt.core.prefs rename to .settings/org.eclipse.jdt.core.prefs diff --git a/README.md b/README.md index 14f7d6d..debf4e8 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,39 @@ with an authorization response. ## Building the SDK ## The SDK is a pure Java code and you can build it using the Eclipse IDE (Kepler or higher) or using the Android Studio IDE. Simply point your IDE's import functionality to the SDK folder and it should be able to import the projects correctly. Make sure you have Java-7 JDK atleast. You could either generate `.jar` files from the SDK and use them in your application projects or directly include the SDK Module in your Android application Project or Eclipse Workspace of the application. +Alternatively you can use the SDK without building the SDK code, if you are using Gradle or Maven, you can directly add the dependency as follows: +(Always check for the latest version [here on mavenCentral](http://search.maven.org/#search%7Cga%7C1%7Ca%3A%22sharefile-api%22) since we keep posting enhancements and bug fixes. Alternatively use 3.+ as the version code in dependencies.) + +* Gradle Dependency: + + dependencies { + compile 'com.citrix:sharefile-api:3.1.0' + } + + Gradle on Android might need the addional : + + android { + + //... + packagingOptions { + exclude 'META-INF/DEPENDENCIES' + exclude 'META-INF/LICENSE' + exclude 'META-INF/NOTICE' + } + //... + } + + +* Maven Dependence: + + + com.citrix + sharefile-api + 3.1.0 + + + + The project uses Java-7 source compatibility. So in case you see errors like : * Error:(87, 46) java: diamond operator is not supported in -source 1.6 @@ -40,6 +73,14 @@ To fix these set the follow settings depend on your IDE: * Eclipse : `File->Properties->JavaCompiler->Compiler Compliance level to 1.7` +## Proguard Settings ## + +If you are using pro-guard, make sure to set the following in the configuration file. + + -keepattributes Signature + -keepattributes *Annotation* + -keep class com.citrix.sharefile.api.** { *; } + ## Initialise the SDK ## diff --git a/SDKSample/AndroidStudioProject/app/build.gradle b/SDKSample/AndroidStudioProject/app/build.gradle deleted file mode 100644 index 65dd476..0000000 --- a/SDKSample/AndroidStudioProject/app/build.gradle +++ /dev/null @@ -1,28 +0,0 @@ -apply plugin: 'com.android.application' - -android { - compileSdkVersion 19 - buildToolsVersion "21.1.2" - - defaultConfig { - applicationId "com.sharefile.testv3" - minSdkVersion 14 - targetSdkVersion 19 - compileOptions { - sourceCompatibility JavaVersion.VERSION_1_7 - targetCompatibility JavaVersion.VERSION_1_7 - } - } - - buildTypes { - release { - minifyEnabled true - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard.cfg' - } - } -} - -dependencies { - compile 'com.google.code.gson:gson:2.2.4' - compile('com.sharefile.api:sfsdk:3.0.0') -} diff --git a/SDKSample/AndroidStudioProject/app/libs/sfsdk-3.0.0.jar b/SDKSample/AndroidStudioProject/app/libs/sfsdk-3.0.0.jar deleted file mode 100644 index 0dc7dbc..0000000 Binary files a/SDKSample/AndroidStudioProject/app/libs/sfsdk-3.0.0.jar and /dev/null differ diff --git a/SDKSample/AndroidStudioProject/app/lint.xml b/SDKSample/AndroidStudioProject/app/lint.xml deleted file mode 100644 index 8423c0e..0000000 --- a/SDKSample/AndroidStudioProject/app/lint.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/SDKSample/AndroidStudioProject/app/proguard.cfg b/SDKSample/AndroidStudioProject/app/proguard.cfg deleted file mode 100644 index b05b393..0000000 --- a/SDKSample/AndroidStudioProject/app/proguard.cfg +++ /dev/null @@ -1,39 +0,0 @@ --optimizationpasses 5 --dontusemixedcaseclassnames --dontskipnonpubliclibraryclasses --dontpreverify --verbose --dontwarn org.htmlparser.** --dontwarn jcifs.http.** --dontwarn com.citrix.mdx.** --optimizations !code/simplification/arithmetic,!field/*,!class/merging/* - --keep public class * extends android.app.Activity --keep public class * extends android.app.Application --keep public class * extends android.app.Service --keep public class * extends android.content.BroadcastReceiver --keep public class * extends android.content.ContentProvider --keep public class * extends android.app.backup.BackupAgentHelper --keep public class * extends android.preference.Preference --keep public class com.android.vending.licensing.ILicensingService - --keepclasseswithmembernames class * { - native ; -} - --keepclasseswithmembernames class * { - public (android.content.Context, android.util.AttributeSet); -} - --keepclasseswithmembernames class * { - public (android.content.Context, android.util.AttributeSet, int); -} - --keepclassmembers enum * { - public static **[] values(); - public static ** valueOf(java.lang.String); -} - --keep class * implements android.os.Parcelable { - public static final android.os.Parcelable$Creator *; -} diff --git a/SDKSample/AndroidStudioProject/app/src/main/AndroidManifest.xml b/SDKSample/AndroidStudioProject/app/src/main/AndroidManifest.xml deleted file mode 100644 index 3586791..0000000 --- a/SDKSample/AndroidStudioProject/app/src/main/AndroidManifest.xml +++ /dev/null @@ -1,51 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/SDKSample/AndroidStudioProject/app/src/main/assets/webviewerrors/offline.html b/SDKSample/AndroidStudioProject/app/src/main/assets/webviewerrors/offline.html deleted file mode 100644 index ffc18e7..0000000 --- a/SDKSample/AndroidStudioProject/app/src/main/assets/webviewerrors/offline.html +++ /dev/null @@ -1,42 +0,0 @@ - - - - - - - - -

- -

- - \ No newline at end of file diff --git a/SDKSample/AndroidStudioProject/app/src/main/java/com/sharefile/testv3/Core/Core.java b/SDKSample/AndroidStudioProject/app/src/main/java/com/sharefile/testv3/Core/Core.java deleted file mode 100644 index 047ac45..0000000 --- a/SDKSample/AndroidStudioProject/app/src/main/java/com/sharefile/testv3/Core/Core.java +++ /dev/null @@ -1,108 +0,0 @@ -package com.sharefile.testv3.Core; - - -import android.content.Context; -import android.util.Log; - -import com.citrix.sharefile.api.SFSdk; -import com.citrix.sharefile.api.async.SFAsyncTaskFactory; -import com.citrix.sharefile.api.authentication.SFOAuth2Token; -import com.citrix.sharefile.api.authentication.SFOAuthService; -import com.citrix.sharefile.api.exceptions.SFInvalidStateException; -import com.citrix.sharefile.api.interfaces.IOAuthTokenCallback; -import com.citrix.sharefile.api.interfaces.ISFApiClient; -import com.citrix.sharefile.api.interfaces.ISFAsyncTask; -import com.citrix.sharefile.api.interfaces.ISFAsyncTaskFactory; -import com.citrix.sharefile.api.interfaces.ISFOAuthService; -import com.sharefile.testv3.PersistantToken; -import com.sharefile.testv3.SFLogger; - -public class Core -{ - private static final String TAG = "Core"; - - private static boolean isInitialised = false; - - public static boolean isIsInitialised() - { - return isInitialised; - } - - /* - * Please hard-code the following two strings with appropriate values you get from ShareFile API page. - * Dont disclose them to anyone. - * WEB_LOGIN_CLIENT_ID_SHAREFILE, - * WEB_LOGIN_CLIENT_SECRET_SHAREFILE - */ - public static final String WEB_LOGIN_CLIENT_ID_SHAREFILE = null; - public static final String WEB_LOGIN_CLIENT_SECRET_SHAREFILE = null; - - public static final String WEB_LOGIN_REDIRECT_URL = "https://secure.sharefile.com/oauthcomplete.aspx"; - public static final String CONTROL_PLANE = "sharefile.com"; - private static ISFApiClient apiClient; - - public static void setApiClient(ISFApiClient client) - { - apiClient = client; - } - - public static ISFApiClient getApiClient() - { - return apiClient; - } - - private static ISFAsyncTaskFactory asyncTaskFactory = new ISFAsyncTaskFactory() - { - @Override - public ISFAsyncTask createNewTask() - { - return new SampleAsyncTask(); - } - }; - - public static void initShareFileSDK() throws SFInvalidStateException - { - if(WEB_LOGIN_CLIENT_ID_SHAREFILE==null || WEB_LOGIN_CLIENT_SECRET_SHAREFILE == null) - { - throw new SFInvalidStateException("Please define clientid/client secret in code"); - } - - SFSdk.init(WEB_LOGIN_CLIENT_ID_SHAREFILE,WEB_LOGIN_CLIENT_SECRET_SHAREFILE,WEB_LOGIN_REDIRECT_URL); - - //optional. makes life easy for Android apps. - SFSdk.setLogger(new SFLogger()); - SFSdk.setAsyncTaskFactory(asyncTaskFactory); - - isInitialised = true; - } - - - public static void getOAuthToken(Context appContext, - String userName, - String password, - String subdomain, - IOAuthTokenCallback callback) - { - SFOAuth2Token token = null; - - try - { - token = PersistantToken.readToken(appContext); - } - catch (Exception e) - { - Log.e(TAG,"",e); - } - - if(token == null) - { - ISFOAuthService oAuthService = new SFOAuthService(); - - oAuthService.authenticateAsync(subdomain, CONTROL_PLANE, userName, password, callback); - - return; - } - - callback.onSuccess(token); - } -} diff --git a/SDKSample/AndroidStudioProject/app/src/main/java/com/sharefile/testv3/Core/SampleAsyncTask.java b/SDKSample/AndroidStudioProject/app/src/main/java/com/sharefile/testv3/Core/SampleAsyncTask.java deleted file mode 100644 index a827280..0000000 --- a/SDKSample/AndroidStudioProject/app/src/main/java/com/sharefile/testv3/Core/SampleAsyncTask.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.sharefile.testv3.Core; - -import android.os.AsyncTask; - -import com.citrix.sharefile.api.interfaces.ISFAsyncHelper; -import com.citrix.sharefile.api.interfaces.ISFAsyncTask; - -public class SampleAsyncTask extends AsyncTask implements ISFAsyncTask -{ - ISFAsyncHelper asyncHelper; - - @Override - protected Object doInBackground(Object[] objects) - { - asyncHelper.execute(); - return null; - } - - @Override - protected void onPostExecute(Object o) - { - super.onPostExecute(o); - asyncHelper.onPostExecute(); - } - - @Override - public void start(ISFAsyncHelper asyncHelper) - { - this.asyncHelper = asyncHelper; - executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } -} \ No newline at end of file diff --git a/SDKSample/AndroidStudioProject/app/src/main/java/com/sharefile/testv3/FoldersActivity.java b/SDKSample/AndroidStudioProject/app/src/main/java/com/sharefile/testv3/FoldersActivity.java deleted file mode 100644 index 56a6b64..0000000 --- a/SDKSample/AndroidStudioProject/app/src/main/java/com/sharefile/testv3/FoldersActivity.java +++ /dev/null @@ -1,693 +0,0 @@ -package com.sharefile.testv3; - -import android.app.Activity; -import android.app.Dialog; -import android.content.Context; -import android.content.Intent; -import android.net.Uri; -import android.os.Bundle; -import android.util.Log; -import android.view.View; -import android.view.View.OnClickListener; -import android.view.WindowManager; -import android.widget.AdapterView; -import android.widget.AdapterView.OnItemClickListener; -import android.widget.Button; -import android.widget.EditText; -import android.widget.ListView; -import android.widget.ProgressBar; -import android.widget.Toast; - -import com.citrix.sharefile.api.constants.SFKeywords; -import com.citrix.sharefile.api.enumerations.SFV3ElementType; -import com.citrix.sharefile.api.exceptions.SFInvalidStateException; -import com.citrix.sharefile.api.exceptions.SFNotAuthorizedException; -import com.citrix.sharefile.api.exceptions.SFOtherException; -import com.citrix.sharefile.api.exceptions.SFSDKException; -import com.citrix.sharefile.api.exceptions.SFServerException; -import com.citrix.sharefile.api.https.SFDownloadRunnable; -import com.citrix.sharefile.api.https.SFUploadRunnable; -import com.citrix.sharefile.api.https.TransferRunnable; -import com.citrix.sharefile.api.interfaces.ISFApiClient; -import com.citrix.sharefile.api.interfaces.ISFApiResultCallback; -import com.citrix.sharefile.api.interfaces.ISFQuery; -import com.citrix.sharefile.api.interfaces.ISFReAuthHandler; -import com.citrix.sharefile.api.interfaces.ISFReExecuteQuery; -import com.citrix.sharefile.api.models.SFAccessControl; -import com.citrix.sharefile.api.models.SFFile; -import com.citrix.sharefile.api.models.SFFolder; -import com.citrix.sharefile.api.models.SFItem; -import com.citrix.sharefile.api.models.SFODataFeed; -import com.citrix.sharefile.api.models.SFSymbolicLink; -import com.sharefile.testv3.Core.Core; -import com.sharefile.testv3.upload.UploadInfo; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.HashMap; -import java.util.Map; -import java.util.Stack; - -public class FoldersActivity extends Activity implements ISFReExecuteQuery -{ - private static final SFLogger SLog = new SFLogger(); - private static final String TAG = "FolderActivity"; - private static final int SFREQUEST_CODE_PHOTO_PICKER = 0x1234; - private ListView mSFItemListView = null; - private Activity thisActivity = null; - private ProgressBar mThrobber = null; - private String TOP = "top"; - - private Map mapFolderContents = new HashMap(); - private Stack mFolderIdStack = new Stack(); - - private void navigateForward(String link) throws URISyntaxException - { - SLog.d("GET", "Nav to: " + link); - confirmExit = false; - mFolderIdStack.push(link); - getContents(link); - } - - private void storeToCache(String folderId,SFFolder object) - { - mapFolderContents.put(folderId, object); - } - - private void navigateBack() throws URISyntaxException - { - String link = mFolderIdStack.peek(); - - if(!link.contains(TOP)) - { - link = mFolderIdStack.pop(); - link = mFolderIdStack.peek(); - getContents(link); - } - else - { - if(confirmExit) - { - finish(); - } - else - { - confirmExit = true; - showToast("Press back again to exit"); - getContents(link); - } - } - } - - - private void showBusy(boolean busy) - { - if(mThrobber!=null) - { - if(busy) - { - mThrobber.setVisibility(View.VISIBLE); - } - else - { - mThrobber.setVisibility(View.INVISIBLE); - } - } - } - - private void callCreateFolderApi(String folderName,String folderDescription) - throws URISyntaxException, SFInvalidStateException - { - String parenturl = mFolderIdStack.peek(); - SFFolder folder = new SFFolder(); - folder.setName(folderName); - folder.setDescription(folderDescription); - - Core.getApiClient() - .items() - .createFolder(new URI(parenturl), folder,false) - .executeAsync(new ISFApiResultCallback() - { - - @Override - public void onSuccess(SFFolder object) - { - showToast("success"); - } - - @Override - public void onError(SFSDKException error,ISFQuery sfapiApiqueri) - { - showToast(error.getLocalizedMessage()); - } - }) ; - - } - - private void callGetAccessControlApi() throws URISyntaxException, SFInvalidStateException - { - String parenturl = mFolderIdStack.peek(); - - Core.getApiClient() - .accessControls() - .getByItem(new URI(parenturl)) - .executeAsync(new ISFApiResultCallback>() { - @Override - public void onSuccess(SFODataFeed object) { - showToast("success"); - } - - @Override - public void onError(SFSDKException v3error, ISFQuery> asApiqueri) { - showToast(v3error.getLocalizedMessage()); - } - }); - - } - - private void callUploadApi(final UploadInfo uploadInfo) throws IOException, SFInvalidStateException, SFServerException - { - String parentid = mFolderIdStack.peek(); - SFFolder currentFolder = mapFolderContents.get(parentid); - if(currentFolder==null) - { - showToast("Current Folder NULL"); - return; - } - - InputStream is = UploadInfo.getInputStreamFromPath(uploadInfo.getFullPathToFile(),getApplicationContext()); - - SFUploadRunnable uploader = Core.getApiClient().getUploader( - currentFolder, - uploadInfo.getFilename(), - "", - is.available(), - is,new TransferRunnable.IProgress() { - @Override - public void bytesTransfered(long l) - { - SLog.d(TAG,"uploaded: " + l + " bytes of " + uploadInfo.getFilename()); - } - - @Override - public void onError(SFSDKException e, long l) - { - showToast(e.getLocalizedMessage()); - } - - @Override - public void onComplete(long l) - { - SLog.d(TAG, "Upload complete" + uploadInfo.getFilename()); - showToast("Upload complete: " + uploadInfo.getFilename()); - } - }); - - uploader.start(); - } - - private void showCreateFolderDialog() - { - final Dialog dialog = new Dialog(this); - dialog.setContentView(R.layout.dlg_create_folder); - dialog.setTitle("Create Folder"); - - // set the custom dialog components - text, image and button - final EditText edxfolderName = (EditText) dialog.findViewById(R.id.create_folder_name); - final EditText edxfolderDetails = (EditText) dialog.findViewById(R.id.create_folder_details); - - Button okButton = (Button) dialog.findViewById(R.id.ok); - - okButton.setOnClickListener(new OnClickListener() - { - @Override - public void onClick(View v) - { - String folderName = edxfolderName.getText().toString().trim(); - String folderDetails = edxfolderDetails.getText().toString().trim(); - - try - { - callCreateFolderApi(folderName, folderDetails); - } - catch (Exception e) - { - Log.e(TAG,"",e); - } - - dialog.dismiss(); - } - }); - - - Button cancelButton = (Button) dialog.findViewById(R.id.cancel); - - cancelButton.setOnClickListener(new OnClickListener() - { - @Override - public void onClick(View v) - { - dialog.dismiss(); - } - }); - - WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); - lp.copyFrom(dialog.getWindow().getAttributes()); - lp.width = WindowManager.LayoutParams.MATCH_PARENT; - lp.height = WindowManager.LayoutParams.WRAP_CONTENT; - dialog.show(); - dialog.getWindow().setAttributes(lp); - - - } - - @Override - public void execute(ISFApiClient sfApiClient, - ISFQuery query, - ISFApiResultCallback listener, - ISFReAuthHandler reauthHandler) - { - try - { - query.executeAsync(listener); - } - catch (SFInvalidStateException e) - { - Log.e(TAG,"",e); - } - } - - - private interface GetCredsCallback - { - public void doneGetCreds(String userName,String password); - } - - private void showGetCredsDialog(final GetCredsCallback callback) - { - final Dialog dialog = new Dialog(this); - dialog.setContentView(R.layout.dlg_get_creds); - dialog.setTitle("Enter Credentials"); - - // set the custom dialog components - text, image and button - final EditText edxUserName = (EditText) dialog.findViewById(R.id.getcreds_username); - final EditText edxPassword = (EditText) dialog.findViewById(R.id.getcreds_password); - - Button okButton = (Button) dialog.findViewById(R.id.ok); - - okButton.setOnClickListener(new OnClickListener() - { - @Override - public void onClick(View v) - { - String userName = edxUserName.getText().toString().trim(); - String password = edxPassword.getText().toString().trim(); - - callback.doneGetCreds(userName, password); - - dialog.dismiss(); - } - }); - - - Button cancelButton = (Button) dialog.findViewById(R.id.cancel); - - cancelButton.setOnClickListener(new OnClickListener() - { - @Override - public void onClick(View v) - { - dialog.dismiss(); - } - }); - - WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); - lp.copyFrom(dialog.getWindow().getAttributes()); - lp.width = WindowManager.LayoutParams.MATCH_PARENT; - lp.height = WindowManager.LayoutParams.WRAP_CONTENT; - dialog.show(); - dialog.getWindow().setAttributes(lp); - } - - public void showToast(final String msg) - { - runOnUiThread(new Runnable() - { - @Override - public void run() - { - Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_LONG).show();; - } - }); - } - - private void showContentsList(SFFolder object) - { - SFFolder folderItem = (SFFolder) object; - SFItemListViewAdapter adapter = new SFItemListViewAdapter(thisActivity, R.layout.sf_item, folderItem.getChildren()); - - try - { - mSFItemListView.setAdapter(adapter); - mSFItemListView.invalidate(); - } - catch(Exception e) - { - SLog.d("Act", "Exception: "+ Log.getStackTraceString(e)); - } - - showBusy(false); - } - - boolean confirmExit = false; - - @Override - public void onBackPressed() - { - //super.onBackPressed(); - - try - { - navigateBack(); - } - catch (Exception e) - { - if(confirmExit) - { - finish(); - } - else - { - confirmExit = true; - showToast("Press back again to exit"); - return; - } - } - - } - - private SFFolder getFromCache(String folderid) - { - return mapFolderContents.get(folderid); - } - - private URI getUriFromLink(String link) throws URISyntaxException - { - URI uri = null; - - SLog.d("GET", "build link for = " + link); - - uri = new URI(link); - - SLog.d("GET", "ret URI = " + uri.toString()); - - return uri; - } - - - private synchronized void getContents(final String link) throws URISyntaxException - { - SFFolder folder = getFromCache(link); - - if(folder!=null) - { - showContentsList(folder); - return; - } - - showBusy(true); - - try - { - Core.getApiClient() - .items() - .get(getUriFromLink(link),false) - .expand(SFKeywords.CHILDREN) - .expand(SFKeywords.REDIRECTION).executeAsync(getContentsListener); - } - catch (SFInvalidStateException e) - { - showBusy(false); - showToast("Exception "+ e.getLocalizedMessage()); - } - } - - ISFApiResultCallback getContentsListener = new ISFApiResultCallback() - { - @Override - public void onSuccess(final SFItem object) - { - if(SFV3ElementType.isFolderType(object)) - { - storeToCache(object.geturl().toString(), (SFFolder) object); - showContentsList((SFFolder) object); - } - } - - @Override - public void onError(final SFSDKException v3error,final ISFQuery asApiqueri) - { - SLog.e(TAG,"",v3error); - - showToast("Failed Get Item: " + v3error.getLocalizedMessage()); - - showBusy(false); - - if(v3error instanceof SFNotAuthorizedException) - { - showGetCredsDialog(new GetCredsCallback() - { - @Override - public void doneGetCreds(final String userName, final String password) - { - showBusy(true); - - try - { - ((SFNotAuthorizedException) v3error).getReAuthContext(). - reExecuteQueryWithCredentials(userName, - password, - FoldersActivity.this); - } - catch (SFInvalidStateException e) - { - Log.e(TAG,"",e); - } - } - }); - - } - else - { - showToast(v3error.getLocalizedMessage()); - } - } - }; - - private void startMediaPicker(String type, int requestCode) - { - Activity activity = this; - - Intent intent = createMediaPickerIntent(activity, type); - - startActivityForResult(intent,requestCode); - } - - public static Intent createMediaPickerIntent(Context context, String type) // , int requestCode - { - - final Intent photoPickerIntent = new Intent(Intent.ACTION_GET_CONTENT); - photoPickerIntent.setType(type); - photoPickerIntent.addCategory(Intent.CATEGORY_OPENABLE);//only content that we can open with [ContentResolver].openInputStream(); - - return Intent.createChooser(photoPickerIntent, context.getString(R.string.strUploadFrom)); - } - - private void initUIControls() - { - Button createFolder = (Button) findViewById(R.id.folderActions_buttonCreateFolder); - - createFolder.setOnClickListener(new OnClickListener() - { - @Override - public void onClick(View v) - { - showCreateFolderDialog(); - } - }); - - - Button getAccessControlList = (Button) findViewById(R.id.folderActions_buttonPreferences); - - getAccessControlList.setOnClickListener(new OnClickListener() - { - @Override - public void onClick(View v) - { - try - { - callGetAccessControlApi(); - } - catch (Exception e) - { - Log.e(TAG,"",e); - } - } - }); - - - Button upload = (Button) findViewById(R.id.folderActions_buttonUpload); - - upload.setOnClickListener(new OnClickListener() - { - @Override - public void onClick(View v) - { - startMediaPicker("image/* , video/*", SFREQUEST_CODE_PHOTO_PICKER); - } - }); - - ////////////////// List View/////////////////////// - mSFItemListView = (ListView) findViewById(R.id.Folder_listview); - mThrobber = (ProgressBar)findViewById(R.id.Folder_throbber); - - mSFItemListView.setOnItemClickListener(new OnItemClickListener() - { - @Override - public void onItemClick(AdapterView parent, View view,int position, long id) - { - //SFItem item = (SFItem) view.getTag(); - SwipeListItemState state = (SwipeListItemState) view.getTag(); - SFItem item = state.mSFItem; - - if(item!=null) - { - if(SFV3ElementType.isFolderType(item)) - { - String fid = item.getId(); - String link = null; - - if(item instanceof SFSymbolicLink) - { - link = ((SFSymbolicLink)item).getLink().toString(); - } - else - { - link = item.geturl().toString(); - } - - //getContents(fid,link); - try - { - navigateForward(item.geturl().toString()); - } - catch (URISyntaxException e) - { - e.printStackTrace(); - } - } - else if(SFV3ElementType.isFileType(item)) - { - showToast("Starting download for: " + item.getName()); - - try - { - callDownloadApi((SFFile)item); - } - catch (Exception e) - { - showToast(e.getLocalizedMessage()); - } - } - } - } - }); - } - - private File getOutputFile(SFFile file) - { - File fileonInternalStorage = new File(getFilesDir() , file.getFileName()); - return fileonInternalStorage; - } - - private void callDownloadApi(SFFile item ) throws FileNotFoundException, SFOtherException - { - OutputStream os = new FileOutputStream(getOutputFile(item)); - - SFDownloadRunnable downloader = Core.getApiClient(). - getDownloader(item, os, - new TransferRunnable.IProgress() - { - @Override - public void bytesTransfered(long l) - { - Log.d(TAG,"bytes transfered " + l); - } - - @Override - public void onError(SFSDKException e, long l) - { - showToast(e.getLocalizedMessage()); - } - - @Override - public void onComplete(long l) - { - SLog.d(TAG,"Download completed with bytes: " + l); - showToast("Download completed"); - } - }); - - downloader.start(); - } - - - @Override - protected void onCreate(Bundle savedInstanceState) - { - thisActivity = this; - - super.onCreate(savedInstanceState); - - setContentView(R.layout.folder); - - initUIControls(); - - try - { - mFolderIdStack.clear(); - navigateForward(Core.getApiClient().getTopUrl().toString()); - } - catch (URISyntaxException e) - { - Log.e(TAG,"",e); - } - } - - @Override - protected void onActivityResult(int requestCode, int resultCode, Intent data) - { - super.onActivityResult(requestCode, resultCode, data); - - if(requestCode == SFREQUEST_CODE_PHOTO_PICKER && data!=null) - { - try - { - final Uri mediaUri = data.getData(); - UploadInfo uploadInfo = UploadInfo.getUploadInfoFromContentProvider(getApplicationContext(), mediaUri); - callUploadApi(uploadInfo); - } - catch (Exception e) - { - showToast(e.getLocalizedMessage()); - } - } - } -} \ No newline at end of file diff --git a/SDKSample/AndroidStudioProject/app/src/main/java/com/sharefile/testv3/FullscreenActivity.java b/SDKSample/AndroidStudioProject/app/src/main/java/com/sharefile/testv3/FullscreenActivity.java deleted file mode 100644 index 9379215..0000000 --- a/SDKSample/AndroidStudioProject/app/src/main/java/com/sharefile/testv3/FullscreenActivity.java +++ /dev/null @@ -1,255 +0,0 @@ -package com.sharefile.testv3; - -import android.app.Activity; -import android.content.Intent; -import android.os.Bundle; -import android.util.Log; -import android.view.View; -import android.view.View.OnClickListener; -import android.widget.Button; -import android.widget.EditText; -import android.widget.LinearLayout; -import android.widget.ProgressBar; -import android.widget.Toast; - -import com.citrix.sharefile.api.SFApiClient; -import com.citrix.sharefile.api.authentication.SFOAuth2Token; -import com.citrix.sharefile.api.exceptions.SFInvalidStateException; -import com.citrix.sharefile.api.exceptions.SFJsonException; -import com.citrix.sharefile.api.exceptions.SFSDKException; -import com.citrix.sharefile.api.interfaces.IOAuthTokenCallback; -import com.citrix.sharefile.api.interfaces.ISFApiClient; -import com.sharefile.testv3.Core.Core; - -import java.io.IOException; -import java.util.ArrayList; - -/** - * An example full-screen activity that shows and hides the system UI (i.e. - * status bar and navigation/system bar) with user interaction. - * - */ -public class FullscreenActivity extends Activity -{ - private static final String TAG = "FullscreenActivity"; - private static final SFLogger SLog = new SFLogger(); - private ProgressBar progressBar; - - public FullscreenActivity() - { - } - - public void showToast(final String msg) - { - runOnUiThread(new Runnable() - { - @Override - public void run() - { - Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_LONG).show();; - } - }); - } - - - private ArrayList