├── box-content-sdk
├── .gitignore
├── gradle.properties
├── src
│ ├── main
│ │ ├── assets
│ │ │ ├── offlinepng.png
│ │ │ └── offline.html
│ │ ├── res
│ │ │ ├── drawable-hdpi
│ │ │ │ ├── boxlogo_white.png
│ │ │ │ ├── boxsdk_dialog_warning.png
│ │ │ │ ├── ic_box_contentsdk_add_grey_24dp.png
│ │ │ │ └── boxsdk_thumb_background.xml
│ │ │ ├── drawable
│ │ │ │ ├── ic_box_contentsdk_add_grey_24dp.png
│ │ │ │ ├── box_circle_mask.xml
│ │ │ │ ├── initials_count_thumb_background.xml
│ │ │ │ ├── teal_rectangle.xml
│ │ │ │ ├── blue_highlight_rectangle.xml
│ │ │ │ └── btn_blue_bordered.xml
│ │ │ ├── drawable-xhdpi
│ │ │ │ └── ic_box_contentsdk_add_grey_24dp.png
│ │ │ ├── drawable-xxhdpi
│ │ │ │ └── ic_box_contentsdk_add_grey_24dp.png
│ │ │ ├── values
│ │ │ │ ├── colors.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ ├── attrs.xml
│ │ │ │ ├── not_localized.xml
│ │ │ │ └── themes.xml
│ │ │ └── layout
│ │ │ │ ├── boxsdk_activity_oauth.xml
│ │ │ │ ├── boxsdk_avatar_item.xml
│ │ │ │ ├── boxsdk_list_item_new_account.xml
│ │ │ │ ├── boxsdk_choose_auth_activity.xml
│ │ │ │ ├── blocked_ip_error.xml
│ │ │ │ ├── boxsdk_list_item_account.xml
│ │ │ │ └── boxsdk_alert_dialog_text_entry.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── box
│ │ │ │ └── androidsdk
│ │ │ │ └── content
│ │ │ │ ├── models
│ │ │ │ ├── BoxVoid.java
│ │ │ │ ├── BoxObject.java
│ │ │ │ ├── BoxIteratorUsers.java
│ │ │ │ ├── BoxIteratorComments.java
│ │ │ │ ├── BoxIteratorCollections.java
│ │ │ │ ├── BoxIteratorCollaborations.java
│ │ │ │ ├── BoxIteratorFileVersions.java
│ │ │ │ ├── BoxIteratorRealTimeServers.java
│ │ │ │ ├── BoxMap.java
│ │ │ │ ├── BoxEmbedLink.java
│ │ │ │ ├── BoxIteratorItems.java
│ │ │ │ ├── BoxOrder.java
│ │ │ │ ├── BoxIteratorRecentItems.java
│ │ │ │ ├── BoxEnterprise.java
│ │ │ │ ├── BoxIteratorUploadSessionParts.java
│ │ │ │ ├── BoxSimpleMessage.java
│ │ │ │ ├── BoxClassification.java
│ │ │ │ ├── BoxGroup.java
│ │ │ │ ├── BoxIteratorRepresentations.java
│ │ │ │ ├── BoxIteratorBoxEntity.java
│ │ │ │ ├── BoxSharedLinkSession.java
│ │ │ │ ├── BoxCollection.java
│ │ │ │ ├── BoxIteratorEvents.java
│ │ │ │ ├── BoxIteratorEnterpriseEvents.java
│ │ │ │ ├── BoxCollaborator.java
│ │ │ │ ├── BoxMetadata.java
│ │ │ │ ├── BoxUploadSessionEndpoints.java
│ │ │ │ ├── BoxMDMData.java
│ │ │ │ ├── BoxUploadSessionPart.java
│ │ │ │ ├── BoxRealTimeServer.java
│ │ │ │ ├── BoxRecentItem.java
│ │ │ │ ├── BoxPermission.java
│ │ │ │ ├── BoxUploadEmail.java
│ │ │ │ ├── BoxBookmark.java
│ │ │ │ ├── BoxExpiringEmbedLinkFile.java
│ │ │ │ └── BoxArray.java
│ │ │ │ ├── utils
│ │ │ │ ├── IStreamPosition.java
│ │ │ │ ├── BoxLogUtils.java
│ │ │ │ ├── BoxContentProvider.java
│ │ │ │ ├── StringMappedThreadPoolExecutor.java
│ │ │ │ ├── BoxLogger.java
│ │ │ │ ├── Logger.java
│ │ │ │ ├── ProgressInputStream.java
│ │ │ │ └── ProgressOutputStream.java
│ │ │ │ ├── listeners
│ │ │ │ ├── DownloadStartListener.java
│ │ │ │ └── ProgressListener.java
│ │ │ │ ├── auth
│ │ │ │ └── BlockedIPErrorActivity.java
│ │ │ │ ├── BoxApiSearch.java
│ │ │ │ ├── requests
│ │ │ │ ├── BoxResponseBatch.java
│ │ │ │ ├── BoxCacheableRequest.java
│ │ │ │ ├── BoxRequestRecentItems.java
│ │ │ │ ├── BoxRequestItemDelete.java
│ │ │ │ ├── BoxResponse.java
│ │ │ │ ├── BoxRequestList.java
│ │ │ │ ├── BoxRequestCollectionUpdate.java
│ │ │ │ ├── MultiputResponseHandler.java
│ │ │ │ ├── BoxRequestsCollections.java
│ │ │ │ ├── BoxHttpRequest.java
│ │ │ │ ├── BoxRequestItemRestoreTrashed.java
│ │ │ │ ├── BoxRequestItemCopy.java
│ │ │ │ └── BoxRequestBatch.java
│ │ │ │ ├── views
│ │ │ │ └── OfflineAvatarController.java
│ │ │ │ ├── BoxApiRecentItems.java
│ │ │ │ ├── BoxCache.java
│ │ │ │ ├── BoxCacheFutureTask.java
│ │ │ │ ├── BoxApi.java
│ │ │ │ ├── BoxConstants.java
│ │ │ │ ├── BoxApiShare.java
│ │ │ │ ├── BoxApiCollection.java
│ │ │ │ ├── BoxApiEvent.java
│ │ │ │ ├── BoxConfig.java
│ │ │ │ ├── BoxApiComment.java
│ │ │ │ └── BoxFutureTask.java
│ │ ├── project.properties
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── box
│ │ │ └── androidsdk
│ │ │ └── content
│ │ │ ├── testUtil
│ │ │ ├── DateUtil.java
│ │ │ ├── SessionUtil.java
│ │ │ └── PowerMock.java
│ │ │ ├── requests
│ │ │ ├── BoxCollaborationRequestTest.java
│ │ │ ├── URLValidationTest.java
│ │ │ └── BoxSearchRequestTest.java
│ │ │ └── models
│ │ │ ├── BoxBookmarkTest.java
│ │ │ └── BoxCommentTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── box
│ │ └── androidsdk
│ │ └── content
│ │ └── models
│ │ └── BoxUploadSessionTest.java
├── proguard-rules.pro
└── build.gradle
├── box-content-sample
├── .gitignore
├── gradle.properties
├── src
│ ├── main
│ │ ├── assets
│ │ │ └── box_logo.png
│ │ ├── res
│ │ │ ├── mipmap-hdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── drawable-hdpi
│ │ │ │ ├── boxsdk_generic.png
│ │ │ │ └── boxsdk_icon_folder_yellow.png
│ │ │ ├── drawable-xhdpi
│ │ │ │ ├── boxsdk_generic.png
│ │ │ │ └── boxsdk_icon_folder_yellow.png
│ │ │ ├── values
│ │ │ │ ├── styles.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ └── strings.xml
│ │ │ ├── drawable
│ │ │ │ └── ic_white_add_24dp.xml
│ │ │ ├── values-w820dp
│ │ │ │ └── dimens.xml
│ │ │ ├── layout
│ │ │ │ ├── activity_main.xml
│ │ │ │ └── boxsdk_list_item.xml
│ │ │ └── menu
│ │ │ │ └── menu_main.xml
│ │ └── AndroidManifest.xml
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── box
│ │ └── androidsdk
│ │ └── sample
│ │ └── ApplicationTest.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── doc
├── Users.md
├── Events.md
├── Search.md
├── Authentication.md
├── Comments.md
├── Folders.md
├── AppUsers.md
└── Collaborations.md
├── CHANGELOG.md
├── .gitignore
├── .utility
└── initiate-publish.sh
├── .github
├── ISSUE_TEMPLATE
│ ├── enhancement.md
│ ├── config.yml
│ ├── bug.md
│ └── question.md
└── workflows
│ └── releases.yml
├── gradle.properties
├── .travis.yml
├── CONTRIBUTING.md
├── gradlew.bat
└── maven_push.gradle
/box-content-sdk/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/box-content-sample/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':box-content-sample', ':box-content-sdk'
2 |
--------------------------------------------------------------------------------
/box-content-sdk/gradle.properties:
--------------------------------------------------------------------------------
1 | POM_NAME=Box Android SDK
2 | POM_ARTIFACT_ID=box-android-sdk
3 | POM_PACKAGING=aar
4 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/box/box-android-sdk/master/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/box-content-sample/gradle.properties:
--------------------------------------------------------------------------------
1 | POM_NAME=Android Box Content SDK SAMPLE
2 | POM_ARTIFACT_ID=androidboxcontentsdksample
3 | POM_PACKAGING=aar
--------------------------------------------------------------------------------
/box-content-sample/src/main/assets/box_logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/box/box-android-sdk/master/box-content-sample/src/main/assets/box_logo.png
--------------------------------------------------------------------------------
/box-content-sdk/src/main/assets/offlinepng.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/box/box-android-sdk/master/box-content-sdk/src/main/assets/offlinepng.png
--------------------------------------------------------------------------------
/box-content-sample/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/box/box-android-sdk/master/box-content-sample/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/box-content-sample/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/box/box-android-sdk/master/box-content-sample/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/box-content-sample/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/box/box-android-sdk/master/box-content-sample/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/box-content-sdk/src/main/res/drawable-hdpi/boxlogo_white.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/box/box-android-sdk/master/box-content-sdk/src/main/res/drawable-hdpi/boxlogo_white.png
--------------------------------------------------------------------------------
/box-content-sample/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/box/box-android-sdk/master/box-content-sample/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/box-content-sample/src/main/res/drawable-hdpi/boxsdk_generic.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/box/box-android-sdk/master/box-content-sample/src/main/res/drawable-hdpi/boxsdk_generic.png
--------------------------------------------------------------------------------
/box-content-sample/src/main/res/drawable-xhdpi/boxsdk_generic.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/box/box-android-sdk/master/box-content-sample/src/main/res/drawable-xhdpi/boxsdk_generic.png
--------------------------------------------------------------------------------
/box-content-sdk/src/main/res/drawable-hdpi/boxsdk_dialog_warning.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/box/box-android-sdk/master/box-content-sdk/src/main/res/drawable-hdpi/boxsdk_dialog_warning.png
--------------------------------------------------------------------------------
/box-content-sdk/src/main/res/drawable/ic_box_contentsdk_add_grey_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/box/box-android-sdk/master/box-content-sdk/src/main/res/drawable/ic_box_contentsdk_add_grey_24dp.png
--------------------------------------------------------------------------------
/box-content-sample/src/main/res/drawable-hdpi/boxsdk_icon_folder_yellow.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/box/box-android-sdk/master/box-content-sample/src/main/res/drawable-hdpi/boxsdk_icon_folder_yellow.png
--------------------------------------------------------------------------------
/box-content-sdk/src/main/res/drawable/box_circle_mask.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
--------------------------------------------------------------------------------
/box-content-sample/src/main/res/drawable-xhdpi/boxsdk_icon_folder_yellow.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/box/box-android-sdk/master/box-content-sample/src/main/res/drawable-xhdpi/boxsdk_icon_folder_yellow.png
--------------------------------------------------------------------------------
/box-content-sdk/src/main/res/drawable-hdpi/ic_box_contentsdk_add_grey_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/box/box-android-sdk/master/box-content-sdk/src/main/res/drawable-hdpi/ic_box_contentsdk_add_grey_24dp.png
--------------------------------------------------------------------------------
/box-content-sdk/src/main/res/drawable-xhdpi/ic_box_contentsdk_add_grey_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/box/box-android-sdk/master/box-content-sdk/src/main/res/drawable-xhdpi/ic_box_contentsdk_add_grey_24dp.png
--------------------------------------------------------------------------------
/box-content-sdk/src/main/res/drawable-xxhdpi/ic_box_contentsdk_add_grey_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/box/box-android-sdk/master/box-content-sdk/src/main/res/drawable-xxhdpi/ic_box_contentsdk_add_grey_24dp.png
--------------------------------------------------------------------------------
/box-content-sdk/src/main/res/drawable/initials_count_thumb_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/doc/Users.md:
--------------------------------------------------------------------------------
1 | Users
2 | =====
3 |
4 | Get the current User
5 | --------------------
6 | ```java
7 | BoxApiUser userApi = new BoxApiUser(session);
8 | BoxUser currentUser = userApi.getCurrentUserInfoRequest().send();
9 | ```
10 |
11 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/assets/offline.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |

5 |
%s
%s
%s
6 |
7 |
8 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/java/com/box/androidsdk/content/models/BoxVoid.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content.models;
2 |
3 | /**
4 | * Class that represents a void response from the Box API.
5 | */
6 | public class BoxVoid extends BoxObject {
7 |
8 | }
9 |
--------------------------------------------------------------------------------
/box-content-sample/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/java/com/box/androidsdk/content/models/BoxObject.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content.models;
2 |
3 | import java.io.Serializable;
4 |
5 | /**
6 | * Base class for all Box objects.
7 | */
8 | public class BoxObject implements Serializable { }
9 |
--------------------------------------------------------------------------------
/box-content-sample/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Apr 10 15:27:10 PDT 2013
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
7 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/java/com/box/androidsdk/content/utils/IStreamPosition.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content.utils;
2 |
3 |
4 | /**
5 | * Interface used by APIs that use stream positions.
6 | */
7 | public interface IStreamPosition{
8 | public Long getNextStreamPosition();
9 | }
10 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/res/drawable-hdpi/boxsdk_thumb_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/res/drawable/teal_rectangle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/java/com/box/androidsdk/content/models/BoxIteratorUsers.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content.models;
2 |
3 | /**
4 | * Class representing a list of Box users.
5 | */
6 | public class BoxIteratorUsers extends BoxIteratorBoxEntity {
7 | private static final long serialVersionUID = -6123959160296884824L;
8 | }
9 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/java/com/box/androidsdk/content/models/BoxIteratorComments.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content.models;
2 |
3 | /**
4 | * Class representing a list of comments.
5 | */
6 | public class BoxIteratorComments extends BoxIteratorBoxEntity {
7 | private static final long serialVersionUID = 2614335107470674624L;
8 | }
9 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/java/com/box/androidsdk/content/models/BoxIteratorCollections.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content.models;
2 |
3 | /**
4 | * Class representing a list of item collections.
5 | */
6 | public class BoxIteratorCollections extends BoxIteratorBoxEntity {
7 | private static final long serialVersionUID = -4334289842796989974L;
8 | }
9 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/java/com/box/androidsdk/content/models/BoxIteratorCollaborations.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content.models;
2 |
3 | /**
4 | * Class representing a list of collaborations.
5 | */
6 | public class BoxIteratorCollaborations extends BoxIteratorBoxEntity {
7 | private static final long serialVersionUID = -7915638707645944101L;
8 | }
9 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/java/com/box/androidsdk/content/models/BoxIteratorFileVersions.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content.models;
2 |
3 | /**
4 | * Class representing a list of versions of a {@link BoxFile}.
5 | */
6 | public class BoxIteratorFileVersions extends BoxIteratorBoxEntity {
7 | private static final long serialVersionUID = -5641060152622694049L;
8 | }
9 |
--------------------------------------------------------------------------------
/box-content-sample/src/main/res/drawable/ic_white_add_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/box-content-sample/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/res/drawable/blue_highlight_rectangle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/java/com/box/androidsdk/content/models/BoxIteratorRealTimeServers.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content.models;
2 |
3 | /**
4 | * Class representing a list of real time servers.
5 | */
6 | public class BoxIteratorRealTimeServers extends BoxIteratorBoxEntity {
7 |
8 | private static final long serialVersionUID = -4986489348666966126L;
9 | public static final String FIELD_CHUNK_SIZE = "chunk_size";
10 |
11 | }
12 |
--------------------------------------------------------------------------------
/box-content-sample/src/androidTest/java/com/box/androidsdk/sample/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.sample;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/box-content-sdk/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #de000000
4 | #80000000
5 | #00adef
6 | #ffeeeeee
7 |
8 |
9 | #195eae
10 | #80afd2
11 |
12 |
13 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 72dp
5 | 40dp
6 | 16sp
7 | 20sp
8 | 16sp
9 |
10 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | Changelog
2 | =========
3 |
4 | ## Next Release
5 |
6 | __Breaking Changes:__
7 | - Fix cross-app scripting vulnerability by removing Activity export of OAuthActivity ([#440](https://github.com/box/box-android-sdk/pull/440))
8 |
9 | __New Features and Enhancements:__
10 |
11 | - Add support for the uploader display name field for Files and File Versions ([#424](https://github.com/box/box-android-sdk/pull/424))
12 | - Add path parameter sanitization ([#428](https://github.com/box/box-android-sdk/pull/428))
13 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/java/com/box/androidsdk/content/listeners/DownloadStartListener.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content.listeners;
2 |
3 | import com.box.androidsdk.content.models.BoxDownload;
4 |
5 | /**
6 | * Listener that provides information on a download once the download starts.
7 | */
8 | public interface DownloadStartListener {
9 |
10 | /**
11 | * Callback when download has started
12 | * @param downloadInfo
13 | */
14 | public void onStart(BoxDownload downloadInfo);
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/box-content-sdk/src/test/java/com/box/androidsdk/content/testUtil/DateUtil.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content.testUtil;
2 |
3 |
4 | import org.junit.Assert;
5 |
6 | import java.util.Date;
7 |
8 | public class DateUtil {
9 | public static void assertSameDateSecondPrecision(Date expectedDate, Date date) {
10 | long expectedDateTruncated = expectedDate.getTime() / 1000;
11 | long dateTruncated = date.getTime() / 1000;
12 | Assert.assertEquals(expectedDateTruncated, dateTruncated);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/box-content-sample/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/java/com/box/androidsdk/content/listeners/ProgressListener.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content.listeners;
2 |
3 | /**
4 | * The listener interface for monitoring the progress of a long-running API call.
5 | */
6 | public interface ProgressListener {
7 |
8 | /**
9 | * Invoked when the progress of the API call changes.
10 | * @param numBytes the number of bytes completed.
11 | * @param totalBytes the total number of bytes.
12 | */
13 | void onProgressChanged(long numBytes, long totalBytes);
14 | }
15 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/java/com/box/androidsdk/content/models/BoxMap.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content.models;
2 |
3 | import com.eclipsesource.json.JsonObject;
4 |
5 | /**
6 | * Class representing a map of arbitrary keys and values.
7 | */
8 | public class BoxMap extends BoxJsonObject {
9 |
10 | private static final long serialVersionUID = 162879893465214004L;
11 |
12 | /**
13 | * Constructs an empty map object.
14 | */
15 | public BoxMap() {
16 |
17 | }
18 |
19 | public BoxMap(JsonObject jsonObject){
20 | super(jsonObject);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | #built application files
2 | *.apk
3 | *.ap_
4 |
5 | # files for the dex VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # generated files
12 | bin/
13 | gen/
14 |
15 | # Local configuration file (sdk path, etc)
16 | local.properties
17 |
18 | # Windows thumbnail db
19 | Thumbs.db
20 |
21 | # OSX files
22 | .DS_Store
23 |
24 | # Eclipse project files
25 | .classpath
26 | .project
27 |
28 | # Android Studio
29 | .idea/
30 | *.iml
31 | #.idea/workspace.xml - remove # and delete .idea if it better suit your needs.
32 | .gradle
33 | build/
34 |
--------------------------------------------------------------------------------
/doc/Events.md:
--------------------------------------------------------------------------------
1 | Events
2 | ======
3 |
4 | Get Events for the Current User
5 | -------------------------------
6 | ```java
7 | BoxApiEvent eventApi = new BoxApiEvent(session);
8 | BoxRequestsEvent.GetUserEvents eventRequest = eventApi.getUserEventsRequest();
9 |
10 | // See API documentation for configuring stream position and stream type:
11 | // https://developers.box.com/docs/#events
12 | eventRequest.setStreamType("all").setStreamPosition("0");
13 |
14 | BoxIteratorEvents events = eventRequest.send();
15 | // You will likely want to use events.getNextStreamPosition() for your next request.
16 | ```
17 |
--------------------------------------------------------------------------------
/box-content-sample/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Box Content SDK Sample
3 |
4 | Hello world!
5 | Settings
6 | Accounts
7 | Add account
8 | Upload
9 | Switch Accounts
10 | Log out
11 | Log out all
12 | Log in
13 |
14 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/res/layout/boxsdk_activity_oauth.xml:
--------------------------------------------------------------------------------
1 |
7 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/java/com/box/androidsdk/content/models/BoxEmbedLink.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content.models;
2 |
3 | import com.eclipsesource.json.JsonArray;
4 |
5 | import java.util.ArrayList;
6 | import java.util.Collection;
7 | import java.util.Iterator;
8 | import java.util.List;
9 |
10 | /**
11 | * An object representing a url link.
12 | */
13 | public class BoxEmbedLink extends BoxJsonObject {
14 |
15 | private static final String FIELD_URL = "url";
16 |
17 |
18 | public BoxEmbedLink() {
19 | super();
20 | }
21 |
22 | public String getUrl(){
23 | return getPropertyAsString(FIELD_URL);
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system edit
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 | #
10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12 |
13 | # Project target.
14 | target=android-19
15 | android.library=true
16 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/java/com/box/androidsdk/content/models/BoxIteratorItems.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content.models;
2 |
3 | import com.eclipsesource.json.JsonObject;
4 |
5 | import org.json.JSONArray;
6 |
7 | /**
8 | * Class representing a list of items in Box (of types {@link BoxFolder}, {@link BoxFile}, and {@link BoxBookmark}).
9 | */
10 | public class BoxIteratorItems extends BoxIteratorBoxEntity {
11 | private static final long serialVersionUID = 1378358978076482578L;
12 |
13 | public BoxIteratorItems() {super();}
14 |
15 | public BoxIteratorItems(JsonObject object) {
16 | super(object);
17 | }
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/box-content-sdk/src/test/java/com/box/androidsdk/content/testUtil/SessionUtil.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content.testUtil;
2 |
3 | import android.content.Context;
4 |
5 | import com.box.androidsdk.content.auth.BoxAuthentication;
6 | import com.box.androidsdk.content.models.BoxSession;
7 |
8 | /**
9 | * Utils for mocking the BoxSession
10 | */
11 |
12 | public class SessionUtil {
13 | public static BoxSession newMockBoxSession(Context context) {
14 | BoxAuthentication.BoxAuthenticationInfo authenticationInfo = new BoxAuthentication.BoxAuthenticationInfo();
15 | authenticationInfo.setAccessToken("accessTokenMock");
16 | return new BoxSession(context, authenticationInfo, null);
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/box-content-sample/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/hkuo/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 | #}
18 |
--------------------------------------------------------------------------------
/doc/Search.md:
--------------------------------------------------------------------------------
1 | Search
2 | ======
3 |
4 | Search for files and folders
5 | ----------------------------
6 |
7 | ```java
8 | BoxApiSearch searchApi = new BoxApiSearch(session);
9 | BoxIteratorItems searchResults = searchApi.getSearchRequest("search string")
10 | .setOffset(0) // default is 0
11 | .setLimit(100) // default is 30, max is 200
12 | // Optional: Specify advanced search parameters. See BoxRequestsSearch.Search for the full list of parameters supported.
13 | .limitAncestorFolderIds(new String[]{"folderId1", "folderId2"}) // only items in these folders will be returned.
14 | .limitFileExtensions(new String[]{"jpg", "png"}) // only files with these extensions will be returned.
15 | .send();
16 | ```
17 |
--------------------------------------------------------------------------------
/box-content-sdk/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in C:/Program Files (x86)/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 | #}
18 |
--------------------------------------------------------------------------------
/.utility/initiate-publish.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # This script initiates the Gradle publishing task when pushes to master occur.
3 | # NOTE: Travis-CI can only publish SNAPSHOT versions. To release a version, you need
4 | # to use the internal Jenkins job.
5 |
6 | echo Repo: $TRAVIS_REPO_SLUG Pull Request: $TRAVIS_PULL_REQUEST Branch: $TRAVIS_BRANCH
7 | if [ "$TRAVIS_REPO_SLUG" == "box/box-android-sdk" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$TRAVIS_BRANCH" == "master" ]; then
8 | export GIT_COUNT=`git rev-list HEAD --count`
9 | echo "Starting publish to Sonatype... $GIT_COUNT"
10 |
11 | ./gradlew uploadArchives
12 | RETVAL=$?
13 |
14 | if [ $RETVAL -eq 0 ]; then
15 | echo 'Completed publish!'
16 | else
17 | echo 'Publish failed.'
18 | return 1
19 | fi
20 |
21 | fi
22 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/enhancement.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Enhancement
3 | about: Suggest a new feature or change
4 | title: ''
5 | labels: enhancement
6 | assignees: mwwoda, mhagmajer, antusus, arjankowski, lukaszsocha2, bartlomiejleszczynski
7 |
8 | ---
9 |
10 | ### Is your feature request related to a problem? Please describe.
11 |
12 |
13 | ### Describe the solution you'd like
14 |
15 |
16 | ### Describe alternatives you've considered
17 |
18 |
19 | ### Additional context
20 |
21 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/java/com/box/androidsdk/content/auth/BlockedIPErrorActivity.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content.auth;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 | import android.view.View;
6 |
7 | import com.box.sdk.android.R;
8 |
9 | /**
10 | * Activity to notify the user that their ip was blocked by the admin
11 | */
12 | public class BlockedIPErrorActivity extends Activity {
13 | @Override
14 | protected void onCreate(Bundle savedInstanceState) {
15 | super.onCreate(savedInstanceState);
16 | setContentView(R.layout.blocked_ip_error);
17 | findViewById(R.id.ok).setOnClickListener(new View.OnClickListener() {
18 |
19 | @Override
20 | public void onClick(final View view) {
21 | finish();
22 | }
23 | });
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/box-content-sample/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 28
5 |
6 | defaultConfig {
7 | applicationId "com.box.androidsdk.sample"
8 |
9 | minSdkVersion 16
10 | targetSdkVersion 28
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | compileOptions {
21 | sourceCompatibility JavaVersion.VERSION_1_8
22 | targetCompatibility JavaVersion.VERSION_1_8
23 | }
24 | }
25 |
26 | dependencies {
27 | implementation 'androidx.appcompat:appcompat:1.0.2'
28 | implementation project(':box-content-sdk')
29 | }
30 |
31 | //apply from: '../maven_push.gradle'
32 |
--------------------------------------------------------------------------------
/box-content-sample/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
12 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/box-content-sample/src/main/res/menu/menu_main.xml:
--------------------------------------------------------------------------------
1 |
23 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/config.yml:
--------------------------------------------------------------------------------
1 | blank_issues_enabled: false
2 | contact_links:
3 | - name: SDK documentation
4 | url: https://github.com/box/box-android-sdk/tree/master/doc
5 | about: Before creating an issue, I have checked that the SDK documentation doesn't solve my issue.
6 | - name: API documentation
7 | url: https://developer.box.com/docs
8 | about: Before creating an issue, I have checked that the API documentation doesn't solve my issue.
9 | - name: Box Developer Forums
10 | url: https://community.box.com/t5/Platform-and-Development-Forum/bd-p/DeveloperForum
11 | about: Before creating an issue, I have searched the Box Developer Forums and my issue isn't already reported there.
12 | - name: Issues in this repo
13 | url: https://github.com/box/box-android-sdk/search?type=Issues
14 | about: Before creating an issue, I have searched Issues in this repo and my issue isn't already reported.
15 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/res/drawable/btn_blue_bordered.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
19 |
20 | android.enableJetifier=true
21 | android.useAndroidX=true
--------------------------------------------------------------------------------
/.github/workflows/releases.yml:
--------------------------------------------------------------------------------
1 | # A GitHub action that notifies the developer
2 | # changelog repository of any new releases.
3 |
4 | name: Notify changelog
5 |
6 | on:
7 | # Only trigger for a full release,
8 | # ignoring pre-releases and drafts
9 | release:
10 | types:
11 | - released
12 |
13 | jobs:
14 | notify:
15 | # This job can run on the latest Ubuntu
16 | # and it should not take more than 3 minutes
17 | runs-on: ubuntu-latest
18 | timeout-minutes: 3
19 |
20 | steps:
21 | # There's really only 1 step, and i
22 | - name: Notify changelog of new release
23 | uses: peter-evans/repository-dispatch@v1
24 | with:
25 | token: ${{ secrets.DISPATCH_ACCESS_TOKEN }}
26 | repository: box/box-developer-changelog
27 | event-type: new-release-note
28 | client-payload: '{"ref": "${{ github.ref }}", "repository": "${{github.repository}}", "labels": "sdks,android,mobile", "repo_display_name": "Box Android SDK"}'
29 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/java/com/box/androidsdk/content/BoxApiSearch.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content;
2 |
3 | import com.box.androidsdk.content.models.BoxSession;
4 | import com.box.androidsdk.content.requests.BoxRequestsSearch;
5 |
6 | /**
7 | * Represents the API of the search endpoint on Box. This class can be used to generate request objects
8 | * for each of the APIs exposed endpoints
9 | */
10 | public class BoxApiSearch extends BoxApi {
11 |
12 | public BoxApiSearch(BoxSession session) {
13 | super(session);
14 | }
15 |
16 | /**
17 | * Gets a request to search
18 | *
19 | * @param query query to use for search
20 | * @return request to search
21 | */
22 | public BoxRequestsSearch.Search getSearchRequest(String query) {
23 | BoxRequestsSearch.Search request = new BoxRequestsSearch.Search(query, getSearchUrl(), mSession);
24 | return request;
25 | }
26 |
27 | protected String getSearchUrl() { return String.format("%s/search", getBaseUri()); }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/java/com/box/androidsdk/content/models/BoxOrder.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content.models;
2 |
3 | import com.eclipsesource.json.JsonObject;
4 | import com.eclipsesource.json.JsonValue;
5 |
6 | /**
7 | * Class representing an order for a list of objects.
8 | */
9 | public class BoxOrder extends BoxJsonObject {
10 |
11 | public static final String FIELD_BY = "by";
12 | public static final String FIELD_DIRECTION = "direction";
13 |
14 | public static final String DIRECTION_ASCENDING = "ASC";
15 | public static final String DIRECTION_DESCENDING = "DESC";
16 |
17 | public static final String SORT_ID = "id";
18 | public static final String SORT_NAME = "name";
19 | public static final String SORT_DATE = "date";
20 | public static final String SORT_SIZE = "size";
21 |
22 |
23 | public String getBy() {
24 | return getPropertyAsString(FIELD_BY);
25 | }
26 |
27 | public String getDirection() {
28 | return getPropertyAsString(FIELD_DIRECTION);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
15 |
16 |
19 |
20 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/java/com/box/androidsdk/content/models/BoxIteratorRecentItems.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content.models;
2 |
3 | import com.eclipsesource.json.JsonObject;
4 |
5 | /**
6 | * A class representing list of BoxRecentItem's
7 | */
8 | public class BoxIteratorRecentItems extends BoxIterator {
9 | private static final long serialVersionUID = -2642748896882484555L;
10 |
11 | private transient BoxJsonObjectCreator representationCreator;
12 |
13 | public BoxIteratorRecentItems() {
14 | super();
15 | }
16 |
17 | public BoxIteratorRecentItems(JsonObject jsonObject) {
18 | super(jsonObject);
19 | }
20 |
21 | @Override
22 | protected BoxJsonObjectCreator getObjectCreator() {
23 | if (representationCreator != null){
24 | return representationCreator;
25 | }
26 | representationCreator = BoxJsonObject.getBoxJsonObjectCreator(BoxRecentItem.class);
27 | return representationCreator;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/java/com/box/androidsdk/content/models/BoxEnterprise.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content.models;
2 |
3 | import com.eclipsesource.json.JsonObject;
4 | import com.eclipsesource.json.JsonValue;
5 |
6 | import java.util.Map;
7 |
8 | /**
9 | * Class that represents an enterprise in Box.
10 | */
11 | public class BoxEnterprise extends BoxEntity {
12 |
13 | private static final long serialVersionUID = -3453999549970888942L;
14 |
15 | public static final String TYPE = "enterprise";
16 |
17 | public static final String FIELD_NAME = "name";
18 |
19 | /**
20 | * Constructs an empty BoxEnterprise object.
21 | */
22 | public BoxEnterprise() {
23 | super();
24 | }
25 |
26 | public BoxEnterprise(JsonObject jsonObject){
27 | super(jsonObject);
28 | }
29 |
30 | /**
31 | * Gets the name of the item.
32 | *
33 | * @return the name of the item.
34 | */
35 | public String getName() {
36 | return getPropertyAsString(FIELD_NAME);
37 | }
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/java/com/box/androidsdk/content/models/BoxIteratorUploadSessionParts.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content.models;
2 |
3 | import com.eclipsesource.json.JsonObject;
4 |
5 | /**
6 | * Class representing a list of BoxUploadSessionPart
7 | */
8 | public class BoxIteratorUploadSessionParts extends BoxIterator{
9 |
10 | private static final long serialVersionUID = -4986339348447936122L;
11 | private transient BoxJsonObjectCreator partsCreator;
12 |
13 | public BoxIteratorUploadSessionParts() {
14 | super();
15 | }
16 |
17 | public BoxIteratorUploadSessionParts(JsonObject jsonObject) {
18 | super(jsonObject);
19 | }
20 |
21 | @Override
22 | protected BoxJsonObjectCreator getObjectCreator() {
23 | if (partsCreator != null){
24 | return partsCreator;
25 | }
26 | partsCreator = BoxJsonObject.getBoxJsonObjectCreator(BoxUploadSessionPart.class);
27 | return partsCreator;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/java/com/box/androidsdk/content/requests/BoxResponseBatch.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content.requests;
2 |
3 | import com.box.androidsdk.content.models.BoxObject;
4 |
5 | import java.util.ArrayList;
6 |
7 | /**
8 | * Batch response class that contains all the response information for a completed BoxRequestBatch
9 | */
10 | public class BoxResponseBatch extends BoxObject {
11 |
12 | /**
13 | * Collection of the response objects
14 | */
15 | protected ArrayList mResponses = new ArrayList();
16 |
17 | /**
18 | * Returns the collection of response objects
19 | *
20 | * @return collection of response objects
21 | */
22 | public ArrayList getResponses() {
23 | return mResponses;
24 | }
25 |
26 | /**
27 | * Adds a response to the collection
28 | *
29 | * @param response the response to add
30 | */
31 | public void addResponse(BoxResponse response) {
32 | mResponses.add(response);
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/java/com/box/androidsdk/content/models/BoxSimpleMessage.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content.models;
2 |
3 | import com.eclipsesource.json.JsonObject;
4 | import com.eclipsesource.json.JsonValue;
5 |
6 | /**
7 | * Class representing a response from a real time server.
8 | */
9 | public class BoxSimpleMessage extends BoxJsonObject {
10 |
11 | private static final long serialVersionUID = 1626798809346520004L;
12 | public static final String FIELD_MESSAGE = "message";
13 |
14 | public static final String MESSAGE_NEW_CHANGE = "new_change";
15 | public static final String MESSAGE_RECONNECT = "reconnect";
16 |
17 | /**
18 | * Returns the message from the server.
19 | *
20 | * @return message from the server.
21 | */
22 | public String getMessage() {
23 | return getPropertyAsString(FIELD_MESSAGE);
24 | }
25 |
26 | /**
27 | * Constructs an empty BoxSimpleMessage object.
28 | */
29 | public BoxSimpleMessage() {
30 |
31 | }
32 |
33 | public BoxSimpleMessage(JsonObject jsonObject){
34 | super(jsonObject);
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/box-content-sample/src/main/res/layout/boxsdk_list_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
10 |
11 |
19 |
20 |
30 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: android
2 | sudo: required
3 | jdk: oraclejdk8
4 |
5 | env:
6 | global:
7 | - secure: kAObSZVQ6SGgIJsh++UYDWyF8AqvYI5xnAaL2CJRq2NUxAMsOwiJdM9Ey/HiOoSyzzII7Ve7Cyji1YE+YfHYOfs5x9iNMIwSRqQv9l8nry7GlzxLXt4OhFpM0EIeaNokzzwXYjiZ7TTLOtLuYCr7ssGTRGUrFCsBHI/+4dKS68k=
8 | - secure: hLpLbEi5ThL/+qHuEmJvvJkzfBrXbyOjDbd9fSSYESSQuGUoEGH3UM7Ws6eJynv/G0w+xmJIQ4vlDbSBa53vaYwHB2l0Rhcoj3XHHvpMwlckIh/TGA+o4Bd5DHN61Jatm6ja8PFRAhNF4adsLUwObrE6Z9ydepKFYBWSjP4xEws=
9 |
10 | android:
11 | components:
12 | - tools
13 | - platform-tools
14 |
15 | before_install:
16 | - touch $HOME/.android/repositories.cfg
17 | - yes | sdkmanager "platforms;android-28"
18 | - yes | sdkmanager "build-tools;28.0.3"
19 | - sdkmanager "tools" > /dev/null
20 | - sdkmanager "platform-tools" > /dev/null
21 |
22 | before_cache:
23 | - rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
24 | - rm -fr $HOME/.gradle/caches/*/plugin-resolution/
25 |
26 | cache:
27 | directories:
28 | - $HOME/.m2
29 | - $HOME/.gradle/caches/
30 | - $HOME/.gradle/wrapper/
31 | - $HOME/.android/build-cache
32 |
33 | script: "./gradlew clean build"
34 |
35 | after_success: .utility/initiate-publish.sh
36 |
37 | git:
38 | depth: 9999999
--------------------------------------------------------------------------------
/box-content-sdk/src/main/res/values/not_localized.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 308201fd30820166a00302010202044c8a3289300d06092a864886f70d01010505003043310b3009060355040613024341310b3009060355040813024f6e310f300d060355040713064f747461776131163014060355040a130d426974686561647320496e632e301e170d3130303931303133323834315a170d3335303930343133323834315a3043310b3009060355040613024341310b3009060355040813024f6e310f300d060355040713064f747461776131163014060355040a130d426974686561647320496e632e30819f300d06092a864886f70d010101050003818d0030818902818100926a2f83b01d88c31614e8b398b40606aa098949d97922332cee24e7362b77bc8dfd3b3556f0f787042cf1d17ff5fb0dd8672d5d2bfc903a2b1ef330d7323a00b8b6187e000a0d1a34fe0e6dcfdd1bbd021718a5fed5249348f24626b7b2c5d35d70b8c6a1436be8006c8843bcf1b5dea829c9d48aa77d06ebc0eeac294388b70203010001300d06092a864886f70d0101050500038181009170b46b82a7e5529d7e8c9ce45d1ad6ba539a0808c278923e5d8740686f1069f744d2bf18ce239f1f082a3c3c810947c42f972464f1cc9c4e5f39b7eee4282d6a617d4cea94677154d5f58629dcad04fae7540936838d466cd0c08831dba6b4989459a460cccc741f5fe2affffb42ef47943cc2fa7017fecfbf3dfd6cfb07d0
5 |
6 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/java/com/box/androidsdk/content/views/OfflineAvatarController.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content.views;
2 |
3 | import android.content.Context;
4 |
5 | import com.box.androidsdk.content.BoxFutureTask;
6 | import com.box.androidsdk.content.models.BoxDownload;
7 |
8 | import java.io.File;
9 |
10 | /**
11 | * This is a special avatar controller that never makes network calls, and should be able to show avatars
12 | * for other accounts if available.
13 | */
14 | public class OfflineAvatarController extends DefaultAvatarController {
15 |
16 |
17 | final Context mContext;
18 |
19 | public OfflineAvatarController(Context context){
20 | super(null);
21 | mContext = context.getApplicationContext();
22 | }
23 |
24 | @Override
25 | protected File getAvatarDir(String userId) {
26 | File directory = new File(mContext.getFilesDir().getAbsolutePath()+ File.separator + userId + File.separator + "avatar");
27 | cleanOutOldAvatars(directory, DEFAULT_MAX_AGE);
28 | return directory;
29 | }
30 |
31 | @Override
32 | public BoxFutureTask executeAvatarDownloadRequest(String userId, BoxAvatarView avatarView) {
33 | return null;
34 | }
35 | }
--------------------------------------------------------------------------------
/box-content-sdk/src/main/java/com/box/androidsdk/content/models/BoxClassification.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content.models;
2 |
3 | public class BoxClassification extends BoxJsonObject {
4 | public static final String FIELD_NAME = "name";
5 | public static final String FIELD_COLOR = "color";
6 | public static final String FIELD_DEFINITION= "definition";
7 |
8 | /**
9 | * Gets the name of the classification.
10 | *
11 | * @return the name of the classification.
12 | */
13 | public String getName() {
14 | return getPropertyAsString(FIELD_NAME);
15 | }
16 |
17 | /**
18 | * Gets the hexcode color of the classification.
19 | *
20 | * @return the hexcode color of the classification.
21 | */
22 | public String getColor() {
23 | return getPropertyAsString(FIELD_COLOR);
24 | }
25 |
26 | /**
27 | * Gets the definition of the classification.
28 | *
29 | * @return the definition of the classification.
30 | */
31 | public String getDefinition() {
32 | return getPropertyAsString(FIELD_DEFINITION);
33 | }
34 |
35 | public String toString() {
36 | return "Classification " + getName() + " " + getColor() + " " + getDefinition();
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/res/layout/boxsdk_avatar_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
19 |
29 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/java/com/box/androidsdk/content/requests/BoxCacheableRequest.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content.requests;
2 |
3 | import com.box.androidsdk.content.BoxException;
4 | import com.box.androidsdk.content.BoxFutureTask;
5 | import com.box.androidsdk.content.models.BoxObject;
6 |
7 | /**
8 | * Interface that adds the ability for requests to retrieve data from the cache instead of over the
9 | * network.
10 | *
11 | * @param The results of the request
12 | */
13 | public interface BoxCacheableRequest {
14 |
15 | /**
16 | * Sends the request to fetch results from cache synchronously.
17 | *
18 | * @return the cached results of the request
19 | * @throws BoxException thrown if there is no implementation of BoxCache set in BoxConfig, or if
20 | * there was another issue getting cached results.
21 | */
22 | T sendForCachedResult() throws BoxException;
23 |
24 | /**
25 | * Converts the request to a BoxCacheFutureTask that can be used to execute the request
26 | * asynchronously.
27 | *
28 | * @return a task that will fetch the results from the cache
29 | * @throws BoxException thrown if there is no implementation of BoxCache set in BoxConfig.
30 | */
31 | BoxFutureTask toTaskForCachedResult() throws BoxException;
32 | }
--------------------------------------------------------------------------------
/box-content-sdk/src/main/java/com/box/androidsdk/content/utils/BoxLogUtils.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content.utils;
2 |
3 | import java.util.Map;
4 |
5 | public class BoxLogUtils {
6 |
7 | private static Logger sLogger = new BoxLogger();
8 |
9 | public static void setLogger(Logger logger) {
10 | sLogger = logger;
11 | }
12 |
13 | public static Logger getLogger(Logger logger) {
14 | return sLogger;
15 | }
16 |
17 | public static boolean getIsLoggingEnabled() {
18 | return sLogger.getIsLoggingEnabled();
19 | }
20 |
21 | public static void i(String tag, String msg) {
22 | sLogger.i(tag, msg);
23 | }
24 |
25 | public static void i(String tag, String msg, Map map) {
26 | sLogger.i(tag, msg, map);
27 | }
28 |
29 | public static void d(String tag, String msg) {
30 | sLogger.d(tag, msg);
31 | }
32 |
33 | public static void e(String tag, String msg) {
34 | sLogger.e(tag, msg);
35 | }
36 |
37 | public static void e(String tag, Throwable t) {
38 | sLogger.e(tag, t);
39 | }
40 |
41 | public static void e(String tag, String msg, Throwable t) {
42 | sLogger.e(tag, msg, t);
43 | }
44 |
45 | public static void nonFatalE(String tag, String msg, Throwable t) {
46 | sLogger.nonFatalE(tag, msg, t);
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/doc/Authentication.md:
--------------------------------------------------------------------------------
1 | Authentication
2 | ==============
3 |
4 | Single User Mode
5 | ---------------------
6 | The SDK can take care of all UI interaction for authenticating a user. If necessary, a WebView will be presented from your app's activity to collect credentials from the user.
7 | ```java
8 | BoxSession session = new BoxSession(context);
9 | session.authenticate();
10 | ```
11 |
12 | When you no longer need the session, it is a good practice to logout.
13 | ```java
14 | session.logout();
15 | ```
16 |
17 | Multi-Account Mode
18 | ------------------------
19 | To support account switching, create a session with the userId explicitly set to null. This will launch an account chooser to select an authenticated account or log in to a different account.
20 | ```java
21 | BoxSession session = new BoxSession(context, null);
22 | session.authenticate();
23 | ```
24 |
25 | Log all users out.
26 |
27 | ```java
28 | BoxAuthentication.getInstance().logoutAllUsers(context);
29 | ```
30 |
31 | Security
32 | ------------------------
33 | The SDK stores authentication information in shared preferences by default. It is recommended that you create your own implementation of `BoxAuthentication.AuthStorage` to provide additional security as needed. You can set the authentication storage as follows:
34 | ```java
35 | BoxAuthentication.getInstance().setAuthStorage(new CustomAuthStorage());
36 | ```
37 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/java/com/box/androidsdk/content/BoxApiRecentItems.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content;
2 |
3 | import com.box.androidsdk.content.models.BoxSession;
4 | import com.box.androidsdk.content.requests.BoxRequestRecentItems;
5 |
6 | /**
7 | * Represents the API of the Recent Items endpoint on Box.
8 | */
9 | public class BoxApiRecentItems extends BoxApi {
10 | private static final String ENDPOINT_NAME = "recent_items";
11 |
12 | /**
13 | * Constructs a BoxApi with the provided BoxSession.
14 | *
15 | * @param session authenticated session to use with the BoxApi.
16 | */
17 | public BoxApiRecentItems(BoxSession session) {
18 | super(session);
19 | }
20 |
21 | /**
22 | * Gets the URL for getting the recent items
23 | *
24 | * @return the URL string for getting the recent items
25 | */
26 | protected String getRecentItemsUrl() {
27 | return String.format("%s/" + ENDPOINT_NAME, getBaseUri());
28 | }
29 |
30 | /**
31 | * Gets a request that gets users recent items
32 | *
33 | * @return request to get users recent items
34 | */
35 | public BoxRequestRecentItems.GetRecentItems getRecentItemsRequest() {
36 | BoxRequestRecentItems.GetRecentItems request = new BoxRequestRecentItems.GetRecentItems(getRecentItemsUrl(), mSession);
37 | return request;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/res/layout/boxsdk_list_item_new_account.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
15 |
20 |
27 |
28 |
--------------------------------------------------------------------------------
/doc/Comments.md:
--------------------------------------------------------------------------------
1 | Comments
2 | ========
3 |
4 | Get the existing Comments of a Box File
5 | ---------------------------------------
6 | ```java
7 | BoxApiFile fileApi = new BoxApiFile(session);
8 | BoxIteratorComments comments = fileApi.getCommentsRequest("fileId").send();
9 | ```
10 |
11 | Get the info of an existing Comment
12 | -----------------------------------
13 | ```java
14 | BoxApiComment commentApi = new BoxApiComment(session);
15 | BoxComment comment = commentApi.getInfoRequest("commentId").send();
16 | ```
17 |
18 | Add a new Comment to a Box File
19 | -------------------------------
20 | ```java
21 | BoxApiFile fileApi = new BoxApiFile(session);
22 | BoxComment newComment = fileApi.getAddCommentRequest("fileId", "Comment message").send();
23 | ```
24 |
25 | Reply to an Existing Comment
26 | ----------------------------
27 | ```java
28 | BoxApiComment commentApi = new BoxApiComment(session);
29 | BoxComment replyComment = commentApi.getAddCommentReplyRequest("commentId", "Comment message").send();
30 | ```
31 |
32 | Update an existing Comment
33 | --------------------------
34 | ```java
35 | BoxApiComment commentApi = new BoxApiComment(session);
36 | BoxComment updatedComment = commentApi.getUpdateRequest("commentId", "Updated message").send();
37 | ```
38 |
39 | Delete a Comment
40 | ----------------
41 | ```java
42 | BoxApiComment commentApi = new BoxApiComment(session);
43 | commentApi.getDeleteRequest("commentId").send();
44 | ```
45 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/java/com/box/androidsdk/content/models/BoxGroup.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content.models;
2 |
3 | import com.eclipsesource.json.JsonObject;
4 |
5 | import java.util.LinkedHashMap;
6 | import java.util.Map;
7 |
8 | /**
9 | * Class that represents a group of Box users.
10 | */
11 | public class BoxGroup extends BoxCollaborator {
12 |
13 | private static final long serialVersionUID = 5872741782856508553L;
14 | public static final String TYPE = "group";
15 |
16 | /**
17 | * Constructs an empty BoxGroup.
18 | */
19 | public BoxGroup() {
20 | super();
21 | }
22 |
23 | /**
24 | * Constructs a BoxGroup with the provided map values.
25 | * @param object json object representing this object
26 | */
27 | public BoxGroup(JsonObject object) {
28 | super(object);
29 | }
30 |
31 | /**
32 | * A convenience method to create an empty group with just the id and type fields set. This allows
33 | * the ability to interact with the content sdk in a more descriptive and type safe manner
34 | *
35 | * @param groupId the id of group to create
36 | * @return an empty BoxGroup object that only contains id and type information
37 | */
38 | public static BoxGroup createFromId(String groupId) {
39 | JsonObject object = new JsonObject();
40 | object.add(BoxCollaborator.FIELD_ID, groupId);
41 | object.add(BoxCollaborator.FIELD_TYPE, BoxUser.TYPE);
42 | return new BoxGroup(object);
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/java/com/box/androidsdk/content/BoxCache.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content;
2 |
3 | import com.box.androidsdk.content.models.BoxObject;
4 | import com.box.androidsdk.content.requests.BoxCacheableRequest;
5 | import com.box.androidsdk.content.requests.BoxRequest;
6 | import com.box.androidsdk.content.requests.BoxResponse;
7 |
8 | /**
9 | * Interface providing local storage to save fetched remote data.
10 | */
11 |
12 | public interface BoxCache {
13 |
14 | /**
15 | * Returns the last cached BoxObject for this BoxRequest.
16 | * @param request - The BoxRequest object that can be used for fetching remote data.
17 | * @param A child of BoxObject
18 | * @param A child of BoxRequest that implements BoxCacheableRequest
19 | * @return a BoxObject associated with the request type.
20 | * @throws BoxException thrown if the request fails.
21 | */
22 | T get(R request) throws BoxException;
23 |
24 | /**
25 | * Stores the BoxResponse object in the local store. The original request should included in the
26 | * response object.
27 | *
28 | * @param response - BoxResponse object obtained from a BoxRequest sent using the Box Android SDK.
29 | * @param A child of BoxObject
30 | * @throws BoxException - Exception that should be thrown if there is an issue with storing response.
31 | */
32 | void put(BoxResponse response) throws BoxException;
33 | }
34 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/java/com/box/androidsdk/content/models/BoxIteratorRepresentations.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content.models;
2 |
3 | import com.eclipsesource.json.JsonObject;
4 |
5 | import java.util.ArrayList;
6 |
7 | /**
8 | * Class representing a list of representations.
9 | */
10 | public class BoxIteratorRepresentations extends BoxIterator {
11 |
12 | private static final long serialVersionUID = -4986439348667936122L;
13 |
14 | private transient BoxJsonObjectCreator representationCreator;
15 |
16 | public BoxIteratorRepresentations() {
17 | }
18 |
19 | public BoxIteratorRepresentations(JsonObject jsonObject) {
20 | super(jsonObject);
21 | }
22 |
23 | @Override
24 | protected BoxJsonObjectCreator getObjectCreator() {
25 | if (representationCreator != null){
26 | return representationCreator;
27 | }
28 | representationCreator = BoxJsonObject.getBoxJsonObjectCreator(BoxRepresentation.class);
29 | return representationCreator;
30 | }
31 |
32 | @Deprecated
33 | public Long offset() {
34 | return null;
35 | }
36 |
37 | @Deprecated
38 | public Long limit() {
39 | return null;
40 | }
41 |
42 | @Deprecated
43 | public Long fullSize() {
44 | return null;
45 | }
46 |
47 | @Deprecated
48 | public ArrayList getSortOrders() {
49 | return null;
50 | }
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/res/values/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
10 |
11 |
15 |
16 |
21 |
22 |
26 |
27 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/box-content-sdk/src/test/java/com/box/androidsdk/content/requests/BoxCollaborationRequestTest.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content.requests;
2 |
3 | import com.box.androidsdk.content.BoxApiCollaboration;
4 | import com.box.androidsdk.content.BoxException;
5 | import com.box.androidsdk.content.models.BoxCollaboration;
6 | import com.box.androidsdk.content.models.BoxFile;
7 | import com.box.androidsdk.content.models.BoxUser;
8 | import com.box.androidsdk.content.testUtil.PowerMock;
9 |
10 | import junit.framework.Assert;
11 |
12 | import org.junit.Test;
13 |
14 | import java.io.UnsupportedEncodingException;
15 | import java.lang.reflect.InvocationTargetException;
16 | import java.text.ParseException;
17 |
18 | public class BoxCollaborationRequestTest extends PowerMock {
19 |
20 | @Test
21 | public void testAddCollaborationRequestTest() throws NoSuchMethodException, BoxException, InvocationTargetException, IllegalAccessException, UnsupportedEncodingException, ParseException {
22 |
23 | String expected = "{\"item\":{\"id\":\"testFileId\",\"type\":\"file\"},\"accessible_by\":{\"id\":\"testUserId\",\"type\":\"user\"},\"role\":\"editor\"}";
24 | BoxApiCollaboration apiCollaboration = new BoxApiCollaboration(null);
25 | BoxUser user = BoxUser.createFromId("testUserId");
26 | BoxRequestsShare.AddCollaboration collabRequest = apiCollaboration.getAddRequest(BoxFile.createFromId("testFileId"), BoxCollaboration.Role.EDITOR, user);
27 | String actual = collabRequest.getStringBody();
28 | Assert.assertEquals(expected, actual);
29 | }
30 | }
--------------------------------------------------------------------------------
/box-content-sdk/src/main/java/com/box/androidsdk/content/utils/BoxContentProvider.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content.utils;
2 |
3 | import android.content.ContentProvider;
4 | import android.content.ContentValues;
5 | import android.database.Cursor;
6 | import android.net.Uri;
7 |
8 | import androidx.annotation.NonNull;
9 | import androidx.annotation.Nullable;
10 |
11 | import com.box.androidsdk.content.BoxConfig;
12 |
13 |
14 | public class BoxContentProvider extends ContentProvider {
15 |
16 | @Override
17 | public boolean onCreate() {
18 | BoxConfig.APPLICATION_CONTEXT = getContext();
19 | return true;
20 | }
21 |
22 | @Nullable
23 | @Override
24 | public Cursor query(@NonNull Uri uri, @Nullable String[] projection, @Nullable String selection,
25 | @Nullable String[] selectionArgs, @Nullable String sortOrder) {
26 | return null;
27 | }
28 |
29 | @Nullable
30 | @Override
31 | public String getType(@NonNull Uri uri) {
32 | return null;
33 | }
34 |
35 | @Nullable
36 | @Override
37 | public Uri insert(@NonNull Uri uri, @Nullable ContentValues values) {
38 | return null;
39 | }
40 |
41 | @Override
42 | public int delete(@NonNull Uri uri, @Nullable String selection, @Nullable String[] selectionArgs) {
43 | return 0;
44 | }
45 |
46 | @Override
47 | public int update(@NonNull Uri uri, @Nullable ContentValues values, @Nullable String selection,
48 | @Nullable String[] selectionArgs) {
49 | return 0;
50 | }
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/box-content-sdk/src/androidTest/java/com/box/androidsdk/content/models/BoxUploadSessionTest.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content.models;
2 |
3 | import junit.framework.TestCase;
4 |
5 |
6 | public class BoxUploadSessionTest extends TestCase {
7 |
8 | public void testParseJson() {
9 | String sessionJson = "{\"total_parts\":2," +
10 | "\"part_size\":8388608," +
11 | "\"session_endpoints\":{" +
12 | "\"list_parts\":\"https://upload.box.com/api/2.0/files/upload_sessions/F971964745A5CD0C001BBE4E58196BFD/parts\"," +
13 | "\"commit\":\"https://upload.box.com/api/2.0/files/upload_sessions/F971964745A5CD0C001BBE4E58196BFD/commit\"," +
14 | "\"upload_part\":\"https://upload.box.com/api/2.0/files/upload_sessions/F971964745A5CD0C001BBE4E58196BFD\"," +
15 | "\"status\":\"https://upload.box.com/api/2.0/files/upload_sessions/F971964745A5CD0C001BBE4E58196BFD\"," +
16 | "\"abort\":\"https://upload.box.com/api/2.0/files/upload_sessions/F971964745A5CD0C001BBE4E58196BFD\"" +
17 | "}," +
18 | "\"session_expires_at\":\"2017-04-18T01:45:15Z\"," +
19 | "\"id\":\"F971964745A5CD0C001BBE4E58196BFD\"," +
20 | "\"type\":\"upload_session\"," +
21 | "\"num_parts_processed\":0" +
22 | "}";
23 | BoxUploadSession session = new BoxUploadSession();
24 | session.createFromJson(sessionJson);
25 | String json = session.toJson();
26 | System.out.println(json);
27 | assertEquals(sessionJson, json);
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/java/com/box/androidsdk/content/BoxCacheFutureTask.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content;
2 |
3 | import com.box.androidsdk.content.models.BoxObject;
4 | import com.box.androidsdk.content.requests.BoxCacheableRequest;
5 | import com.box.androidsdk.content.requests.BoxRequest;
6 | import com.box.androidsdk.content.requests.BoxResponse;
7 |
8 | import java.util.concurrent.Callable;
9 |
10 | /**
11 | * A {@link BoxFutureTask} that indicates the results will be fetched from the cache instead of the
12 | * server
13 | */
14 | public class BoxCacheFutureTask extends BoxFutureTask {
15 |
16 |
17 | /**
18 | * Creates a new instance of a task that will fetch results from the cache
19 | *
20 | * @param clazz the class of the return type
21 | * @param request the request to execute against the cache
22 | * @param cache The implementation of BoxCache to be used to store results of this task.
23 | */
24 | public BoxCacheFutureTask(final Class clazz, final R request, final BoxCache cache) {
25 | super(new Callable>() {
26 | @Override
27 | public BoxResponse call() throws Exception {
28 | T result = null;
29 | Exception ex = null;
30 | try {
31 | result = cache.get(request);
32 | } catch (Exception e) {
33 | ex = e;
34 | }
35 |
36 | return new BoxResponse(result, ex, request);
37 | }
38 | }, request);
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/java/com/box/androidsdk/content/BoxApi.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content;
2 |
3 | import com.box.androidsdk.content.models.BoxSession;
4 |
5 | /**
6 | * Base class for the Box API endpoint classes.
7 | */
8 | public class BoxApi {
9 |
10 | protected BoxSession mSession;
11 |
12 | protected String mBaseUri = BoxConstants.BASE_URI;
13 | protected String mBaseUploadUri = BoxConstants.BASE_UPLOAD_URI;
14 |
15 | /**
16 | * Constructs a BoxApi with the provided BoxSession.
17 | *
18 | * @param session authenticated session to use with the BoxApi.
19 | */
20 | public BoxApi(BoxSession session) {
21 | this.mSession = session;
22 | }
23 |
24 | /**
25 | * Returns the base URI for the API.
26 | *
27 | * @return base URI for the API.
28 | */
29 | protected String getBaseUri() {
30 | if (mSession != null && mSession.getAuthInfo() != null && mSession.getAuthInfo().getBaseDomain() != null){
31 | return String.format(BoxConstants.BASE_URI_TEMPLATE,mSession.getAuthInfo().getBaseDomain());
32 | }
33 | return mBaseUri;
34 | }
35 |
36 | /**
37 | * Returns the base URI for uploads for the API.
38 | *
39 | * @return base upload URI.
40 | */
41 | protected String getBaseUploadUri() {
42 | if (mSession != null && mSession.getAuthInfo() != null && mSession.getAuthInfo().getBaseDomain() != null){
43 | return String.format(BoxConstants.BASE_UPLOAD_URI_TEMPLATE, mSession.getAuthInfo().getBaseDomain());
44 | }
45 | return mBaseUploadUri;
46 | }
47 |
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/res/layout/boxsdk_choose_auth_activity.xml:
--------------------------------------------------------------------------------
1 |
7 |
15 |
16 |
23 |
24 |
32 |
33 |
34 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/java/com/box/androidsdk/content/models/BoxIteratorBoxEntity.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content.models;
2 |
3 | import com.eclipsesource.json.JsonObject;
4 |
5 | import java.util.ArrayList;
6 | import java.util.Iterator;
7 |
8 | /**
9 | * A collection that contains a subset of items that are a part of a larger collection. The items within a partial collection begin at an offset within the full
10 | * collection and end at a specified limit. Note that the actual size of a partial collection may be less than its limit since the limit only specifies the
11 | * maximum size. For example, if there's a full collection with a size of 3, then a partial collection with offset 0 and limit 3 would be equal to a partial
12 | * collection with offset 0 and limit 100.
13 | *
14 | * @param the type of elements in this partial collection.
15 | */
16 | public class BoxIteratorBoxEntity extends BoxIterator{
17 |
18 | private static final long serialVersionUID = 8036181424029520417L;
19 |
20 |
21 |
22 | public BoxIteratorBoxEntity() {
23 | super();
24 | }
25 |
26 | public BoxIteratorBoxEntity(JsonObject jsonObject) {
27 | super(jsonObject);
28 | }
29 |
30 | private transient BoxJsonObjectCreator representationCreator;
31 |
32 | @Override
33 | protected BoxJsonObjectCreator getObjectCreator() {
34 | if (representationCreator != null){
35 | return representationCreator;
36 | }
37 | representationCreator = (BoxJsonObjectCreator)BoxEntity.getBoxJsonObjectCreator();
38 | return representationCreator;
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/res/layout/blocked_ip_error.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
19 |
27 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/java/com/box/androidsdk/content/models/BoxSharedLinkSession.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content.models;
2 |
3 | import android.content.Context;
4 |
5 | import java.util.ArrayList;
6 |
7 | /**
8 | * Session created from a shared link.
9 | */
10 | public class BoxSharedLinkSession extends BoxSession {
11 |
12 | String mSharedLink;
13 | String mPassword;
14 |
15 | public BoxSharedLinkSession(BoxSession session) {
16 | super(session);
17 |
18 | if (session instanceof BoxSharedLinkSession) {
19 | BoxSharedLinkSession sharedLinkSession = (BoxSharedLinkSession) session;
20 | setSharedLink(sharedLinkSession.getSharedLink());
21 | setPassword(sharedLinkSession.getPassword());
22 | }
23 | }
24 |
25 | public BoxSharedLinkSession(Context context) {
26 | super(context);
27 | }
28 |
29 | public BoxSharedLinkSession(Context context, String userId ) {
30 | super(context, userId);
31 | }
32 |
33 | public BoxSharedLinkSession(Context context, String userId, String clientId, String clientSecret, String redirectUrl) {
34 | super(context, userId, clientId, clientSecret, redirectUrl);
35 | }
36 |
37 | public String getSharedLink() {
38 | return mSharedLink;
39 | }
40 |
41 | public BoxSharedLinkSession setSharedLink(String sharedLink) {
42 | mSharedLink = sharedLink;
43 | return this;
44 | }
45 |
46 | public String getPassword() {
47 | return mPassword;
48 | }
49 |
50 | public BoxSharedLinkSession setPassword(String password) {
51 | mPassword = password;
52 | return this;
53 | }
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/doc/Folders.md:
--------------------------------------------------------------------------------
1 | Folders
2 | =======
3 |
4 | Get Info about a Box Folder
5 | ---------------------------
6 | ```java
7 | BoxApiFolder folderApi = new BoxApiFolder(session);
8 | BoxFolder folder = folderApi.getInfoRequest("folderId").send();
9 | ```
10 |
11 | Get the items in a Box Folder
12 | --------------------------------
13 | ```java
14 | BoxApiFolder folderApi = new BoxApiFolder(session);
15 | BoxIteratorItems items = folderApi.getItemsRequest("folderId").send();
16 | ```
17 | or the following convenience method
18 |
19 | ```java
20 | BoxFolder folder = folderApi.getFolderWithAllItems("folderId").send();
21 | BoxIteratorItems items = folder.getItemCollection();
22 | ```
23 |
24 | Update Properties of a Box Folder
25 | ---------------------------------
26 | ```java
27 | BoxApiFolder folderApi = new BoxApiFolder(session);
28 | BoxFolder updatedFolder = folderApi.getUpdateRequest("folderId")
29 | // Update properties.
30 | .setName("new file name")
31 | .setDescription("new file description")
32 | .send();
33 | ```
34 |
35 | Delete a Box Folder
36 | -------------------
37 | ```java
38 | BoxApiFolder folderApi = new BoxApiFolder(session);
39 | folderApi.getDeleteRequest("folderId")
40 | // Optional: By default the folder will be deleted including all the files/folders within.
41 | // Set 'recursive' to false to only allow for the deletion if the folder is empty.
42 | .setRecursive(false)
43 | .send();
44 | ```
45 |
46 | Create a new Box Folder
47 | -----------------------
48 | ```java
49 | BoxApiFolder folderApi = new BoxApiFolder(session);
50 | BoxFolder newFolder = folderApi.getCreateRequest("parentFolderId", "New Folder Name").send();
51 | ```
52 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/java/com/box/androidsdk/content/models/BoxCollection.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content.models;
2 |
3 | import com.eclipsesource.json.JsonObject;
4 | import com.eclipsesource.json.JsonValue;
5 |
6 | import java.util.Map;
7 |
8 | /**
9 | * Class that represents a collection on Box.
10 | */
11 | public class BoxCollection extends BoxEntity {
12 |
13 | public static final String TYPE = "collection";
14 |
15 | public static final String FIELD_NAME = "name";
16 | public static final String FIELD_COLLECTION_TYPE = "collection_type";
17 |
18 | /**
19 | * Constructs an empty BoxCollection object.
20 | */
21 | public BoxCollection() {
22 | super();
23 | }
24 |
25 | /**
26 | * Constructs a BoxCollection with the provided map values
27 | *
28 | * @param object JsonObject representing this class
29 | */
30 | public BoxCollection(JsonObject object) {
31 | super(object);
32 | }
33 |
34 | public static BoxCollection createFromId(String id) {
35 | JsonObject object = new JsonObject();
36 | object.add(FIELD_ID, id);
37 | return new BoxCollection(object);
38 | }
39 |
40 | /**
41 | * Gets the name of the collection.
42 | *
43 | * @return the name of the collection.
44 | */
45 | public String getName() {
46 | return getPropertyAsString(FIELD_NAME);
47 | }
48 |
49 | /**
50 | * Gets the type of the collection. Currently only "favorites" is supported.
51 | *
52 | * @return type of collection.
53 | */
54 | public String getCollectionType() {
55 | return getPropertyAsString(FIELD_COLLECTION_TYPE);
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/java/com/box/androidsdk/content/models/BoxIteratorEvents.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content.models;
2 |
3 | import com.box.androidsdk.content.utils.IStreamPosition;
4 |
5 | import java.util.ArrayList;
6 | import java.util.HashSet;
7 |
8 | /**
9 | * Class representing a list of events fired off by the Box events API.
10 | */
11 | public class BoxIteratorEvents extends BoxIteratorBoxEntity implements IStreamPosition {
12 |
13 | private static final long serialVersionUID = 2397451459829964208L;
14 | public static final String FIELD_CHUNK_SIZE = "chunk_size";
15 | public static final String FIELD_NEXT_STREAM_POSITION = "next_stream_position";
16 |
17 | /**
18 | * Gets the number of event records returned in this chunk.
19 | *
20 | * @return number of event records returned.
21 | */
22 | public Long getChunkSize() {
23 | return getPropertyAsLong(FIELD_CHUNK_SIZE);
24 | }
25 |
26 | /**
27 | * Gets the next position in the event stream that you should request in order to get the next events.
28 | *
29 | * @return next position in the event stream to request in order to get the next events.
30 | */
31 | public Long getNextStreamPosition() {
32 | return getPropertyAsLong(FIELD_NEXT_STREAM_POSITION);
33 | }
34 |
35 | public ArrayList getWithoutDuplicates(){
36 | HashSet mEventIds = new HashSet(this.size());
37 | ArrayList events = new ArrayList(this.size());
38 | for(BoxEvent event : this){
39 | if (!mEventIds.contains(event.getId())){
40 | events.add(event);
41 | }
42 | }
43 | return events;
44 | }
45 |
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/box-content-sdk/src/test/java/com/box/androidsdk/content/requests/URLValidationTest.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content.requests;
2 |
3 | import android.content.Context;
4 |
5 | import com.box.androidsdk.content.BoxApiFile;
6 | import com.box.androidsdk.content.BoxException;
7 | import com.box.androidsdk.content.models.BoxExpiringEmbedLinkFile;
8 | import com.box.androidsdk.content.testUtil.PowerMock;
9 | import com.box.androidsdk.content.testUtil.SessionUtil;
10 |
11 | import junit.framework.Assert;
12 |
13 | import org.junit.Test;
14 | import org.mockito.Mock;
15 | import org.powermock.core.classloader.annotations.PrepareForTest;
16 |
17 | @PrepareForTest({ BoxHttpResponse.class, BoxHttpRequest.class, BoxRequestsFile.class})
18 | public class URLValidationTest extends PowerMock {
19 |
20 | @Mock
21 | Context mMockContext;
22 |
23 | @Test
24 | public void failForInvalidURL() throws Exception {
25 | {
26 | final String invalidPathParameter = "/../";
27 | final String expectedRequestUrl = "https://api.box.com/2.0/files/" + invalidPathParameter;
28 | BoxApiFile fileApi = new BoxApiFile(SessionUtil.newMockBoxSession(mMockContext));
29 | BoxRequestsFile.GetEmbedLinkFileInfo embedLinkRequest = fileApi.getEmbedLinkRequest(invalidPathParameter);
30 | Assert.assertEquals(expectedRequestUrl, embedLinkRequest.mRequestUrlString);
31 | try {
32 | BoxExpiringEmbedLinkFile embedLinkFile = embedLinkRequest.send();
33 | } catch (BoxException e) {
34 | Assert.assertEquals("An invalid path parameter passed. Relative path parameters cannot be passed.", e.getMessage());
35 | return;
36 | }
37 | Assert.fail("Never threw a BoxException");
38 | }
39 | }
40 | }
--------------------------------------------------------------------------------
/box-content-sdk/src/main/java/com/box/androidsdk/content/BoxConstants.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content;
2 |
3 | public class BoxConstants {
4 |
5 | public static final String TAG = "BoxContentSdk";
6 |
7 | public static final String BASE_URI = "https://api.box.com/2.0";
8 | public static final String BASE_UPLOAD_URI = "https://upload.box.com/api/2.0";
9 | public static final String OAUTH_BASE_URI = "https://api.box.com";
10 |
11 | public static final String OAUTH_BASE_URI_TEMPLATE = "https://api.%s";
12 | public static final String BASE_URI_TEMPLATE = "https://api.%s/2.0";
13 | public static final String BASE_UPLOAD_URI_TEMPLATE = "https://upload.%s/api/2.0";
14 |
15 |
16 | public static final String FIELD_SIZE = "size";
17 | public static final String FIELD_CONTENT_CREATED_AT = "content_created_at";
18 | public static final String FIELD_CONTENT_MODIFIED_AT = "content_modified_at";
19 | public static final String FIELD_COMMENT_COUNT = "comment_count";
20 |
21 | public static final String ROOT_FOLDER_ID = "0";
22 |
23 | public static final String KEY_CLIENT_ID = "client_id";
24 | public static final String KEY_REDIRECT_URL = "redirect_uri";
25 | public static final String KEY_CLIENT_SECRET = "client_secret";
26 | public static final String KEY_BOX_DEVICE_ID = "box_device_id";
27 | public static final String KEY_BOX_DEVICE_NAME = "box_device_name";
28 | public static final String KEY_BOX_USERS = "boxusers";
29 | public static final String KEY_BOX_REFRESH_TOKEN_EXPIRES_AT = "box_refresh_token_expires_at";
30 | public static final String KEY_TOKEN = "token";
31 |
32 | public static final int HTTP_STATUS_TOO_MANY_REQUESTS = 429;
33 |
34 | public static final String REQUEST_BOX_APP_FOR_AUTH_INTENT_ACTION = "com.box.android.action.AUTHENTICATE_VIA_BOX_APP";
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/java/com/box/androidsdk/content/requests/BoxRequestRecentItems.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content.requests;
2 |
3 | import com.box.androidsdk.content.BoxException;
4 | import com.box.androidsdk.content.BoxFutureTask;
5 | import com.box.androidsdk.content.models.BoxIteratorRecentItems;
6 | import com.box.androidsdk.content.models.BoxSession;
7 |
8 | /**
9 | * BoxRequest to perform operations on the global recents endpoint
10 | */
11 | public class BoxRequestRecentItems {
12 |
13 | /**
14 | * Request to get the Recent Items
15 | */
16 | public static class GetRecentItems extends BoxRequestList implements BoxCacheableRequest {
17 | private static final long serialVersionUID = 8123965031279971506L;
18 | private static final String LIMIT = "limit";
19 | private static final String DEFAULT_LIMIT = "100";
20 |
21 | /**
22 | * Creates a get recent items request
23 | *
24 | * @param recentItemsUrl URL of the recents items endpoint.
25 | * @param session the authenticated session that will be used to make the request with.
26 | */
27 | public GetRecentItems(String recentItemsUrl, BoxSession session) {
28 | super(BoxIteratorRecentItems.class, null, recentItemsUrl, session);
29 | mQueryMap.put(LIMIT, DEFAULT_LIMIT);
30 | }
31 |
32 | @Override
33 | public BoxIteratorRecentItems sendForCachedResult() throws BoxException {
34 | return super.handleSendForCachedResult();
35 | }
36 |
37 | @Override
38 | public BoxFutureTask toTaskForCachedResult() throws BoxException {
39 | return super.handleToTaskForCachedResult();
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/res/layout/boxsdk_list_item_account.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
17 |
22 |
29 |
37 |
38 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/java/com/box/androidsdk/content/utils/StringMappedThreadPoolExecutor.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content.utils;
2 |
3 | import java.lang.ref.WeakReference;
4 | import java.util.concurrent.BlockingQueue;
5 | import java.util.concurrent.ConcurrentHashMap;
6 | import java.util.concurrent.ThreadFactory;
7 | import java.util.concurrent.ThreadPoolExecutor;
8 | import java.util.concurrent.TimeUnit;
9 |
10 | /**
11 | *
12 | * A thread pool executor that lets callers access a runnable by its toString method.
13 | */
14 | public final class StringMappedThreadPoolExecutor extends ThreadPoolExecutor {
15 |
16 | private final ConcurrentHashMap> mRunningTasks = new ConcurrentHashMap>();
17 |
18 | public StringMappedThreadPoolExecutor(int corePoolSize,
19 | int maximumPoolSize,
20 | long keepAliveTime,
21 | TimeUnit unit,
22 | BlockingQueue workQueue,
23 | ThreadFactory threadFactory){
24 | super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, threadFactory);
25 | }
26 |
27 | @Override
28 | protected void beforeExecute(Thread t, Runnable r) {
29 | super.beforeExecute(t, r);
30 | mRunningTasks.put(r.toString(), new WeakReference(r));
31 | }
32 |
33 | @Override
34 | protected void afterExecute(Runnable r, Throwable t) {
35 | super.afterExecute(r, t);
36 | mRunningTasks.remove(r.toString());
37 | }
38 |
39 | public Runnable getTaskFor(String runnableString){
40 | WeakReference ref = mRunningTasks.get(runnableString);
41 | if (ref == null){
42 | return null;
43 | }
44 | return ref.get();
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/box-content-sdk/src/test/java/com/box/androidsdk/content/models/BoxBookmarkTest.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content.models;
2 |
3 | import com.eclipsesource.json.JsonObject;
4 |
5 | import org.junit.Assert;
6 | import org.junit.Test;
7 |
8 | public class BoxBookmarkTest {
9 |
10 | @Test
11 | public void testConstructorNoParameter() {
12 | // given
13 |
14 | // when
15 | BoxBookmark bookmark = new BoxBookmark();
16 | Long size = bookmark.getSize();
17 | String url = bookmark.getUrl();
18 |
19 | // then
20 | Assert.assertNull(size);
21 | Assert.assertNull(url);
22 | }
23 |
24 | @Test
25 | public void testConstructorWithJsonObjectParameter() {
26 | // given
27 | String expectedType = "my_type";
28 | String expectedUrl = "http://box.com";
29 | String bookmarkJson = "{\"type\":\"" + expectedType + "\",\"size\":\"6381527\",\"url\":\"" + expectedUrl + "\"}";
30 | JsonObject jsonObj = JsonObject.readFrom(bookmarkJson);
31 |
32 | // when
33 | BoxBookmark bookmark = new BoxBookmark(jsonObj);
34 | String type = bookmark.getType();
35 | Long size = bookmark.getSize();
36 | String url = bookmark.getUrl();
37 |
38 | // then
39 | Assert.assertEquals(expectedType, type);
40 | Assert.assertNull(size);
41 | Assert.assertEquals(expectedUrl, url);
42 | }
43 |
44 | @Test
45 | public void testCreateFromId() {
46 | // given
47 | String expectedId = "5";
48 | String expectedType = BoxBookmark.TYPE;
49 |
50 | // when
51 | BoxBookmark bookmark = BoxBookmark.createFromId(expectedId);
52 | String id = bookmark.getId();
53 | String type = bookmark.getType();
54 |
55 | // then
56 | Assert.assertEquals(expectedId, id);
57 | Assert.assertEquals(expectedType, type);
58 | }
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/box-content-sdk/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 28
5 |
6 | defaultConfig {
7 | minSdkVersion 16
8 | targetSdkVersion 28
9 | versionCode 50000
10 | versionName "5.0.0" /* Update in BoxConfig.SDK_VERSION as well */
11 | version "5.0.0"
12 | group "com.box"
13 |
14 | // Set version code and name
15 | def env = System.getenv()
16 | def git_count = env['GIT_COUNT'] as Integer
17 | if (git_count != null) {
18 | /* Update in BoxConfig.SDK_VERSION as well */
19 | versionCode git_count + 50000
20 | versionName "5.99." + git_count + "-SNAPSHOT"
21 | version "5.99." + git_count + "-SNAPSHOT"
22 | }
23 | }
24 |
25 | buildTypes {
26 | release {
27 | minifyEnabled false
28 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
29 | }
30 | }
31 |
32 | compileOptions {
33 | sourceCompatibility JavaVersion.VERSION_1_8
34 | targetCompatibility JavaVersion.VERSION_1_8
35 | }
36 |
37 | lintOptions {
38 | abortOnError false
39 | }
40 |
41 | dexOptions {
42 | jumboMode = true
43 | javaMaxHeapSize = "4g"
44 | }
45 | }
46 |
47 | dependencies {
48 | implementation 'com.eclipsesource.minimal-json:minimal-json:0.9.1'
49 | implementation 'androidx.annotation:annotation:1.0.2'
50 | testImplementation 'junit:junit:4.12'
51 | testImplementation "org.powermock:powermock-module-junit4:1.6.2"
52 | testImplementation "org.powermock:powermock-module-junit4-rule:1.6.2"
53 | testImplementation "org.powermock:powermock-api-mockito:1.6.2"
54 | testImplementation "org.powermock:powermock-classloading-xstream:1.6.2"
55 | }
56 |
57 | apply from: '../maven_push.gradle'
58 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/java/com/box/androidsdk/content/models/BoxIteratorEnterpriseEvents.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content.models;
2 |
3 | import com.box.androidsdk.content.utils.IStreamPosition;
4 |
5 | import java.util.ArrayList;
6 | import java.util.HashSet;
7 |
8 | /**
9 | * Class representing a list of enterprise events fired off by the Box events API.
10 | */
11 | public class BoxIteratorEnterpriseEvents extends BoxIteratorBoxEntity implements IStreamPosition {
12 |
13 | private static final long serialVersionUID = 940295540206254689L;
14 | public static final String FIELD_CHUNK_SIZE = "chunk_size";
15 | public static final String FIELD_NEXT_STREAM_POSITION = "next_stream_position";
16 |
17 | /**
18 | * Gets the number of event records returned in this chunk.
19 | *
20 | * @return number of event records returned.
21 | */
22 | public Long getChunkSize() {
23 | return getPropertyAsLong(FIELD_CHUNK_SIZE);
24 | }
25 |
26 | /**
27 | * Gets the next position in the event stream that you should request in order to get the next events.
28 | *
29 | * @return next position in the event stream to request in order to get the next events.
30 | */
31 | public Long getNextStreamPosition() {
32 | String longValue = getPropertyAsString(FIELD_NEXT_STREAM_POSITION);
33 | return Long.parseLong(longValue.replace("\"", ""));
34 | }
35 |
36 | public ArrayList getWithoutDuplicates(){
37 | HashSet mEventIds = new HashSet(this.size());
38 | ArrayList events = new ArrayList(this.size());
39 | for(BoxEnterpriseEvent event : this){
40 | if (!mEventIds.contains(event.getId())){
41 | events.add(event);
42 | }
43 | }
44 | return events;
45 | }
46 |
47 |
48 | }
49 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/java/com/box/androidsdk/content/models/BoxCollaborator.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content.models;
2 |
3 | import java.text.ParseException;
4 | import java.util.Date;
5 |
6 | import com.box.androidsdk.content.utils.BoxDateFormat;
7 | import com.eclipsesource.json.JsonObject;
8 | import com.eclipsesource.json.JsonValue;
9 |
10 | import java.util.Map;
11 |
12 | /**
13 | * Contains information about a BoxCollaborator.
14 | */
15 | public abstract class BoxCollaborator extends BoxEntity {
16 |
17 | private static final long serialVersionUID = 4995483369186543255L;
18 | public static final String FIELD_NAME = "name";
19 | public static final String FIELD_CREATED_AT = "created_at";
20 | public static final String FIELD_MODIFIED_AT = "modified_at";
21 |
22 | /**
23 | * Constructs an empty BoxCollaborator object.
24 | */
25 | public BoxCollaborator() {
26 | super();
27 | }
28 |
29 | /**
30 | * Constructs an empty BoxCollaborator object.
31 | * @param object jsonObject to use to create an instance of this class.
32 | */
33 | public BoxCollaborator(JsonObject object) {
34 | super(object);
35 | }
36 |
37 | /**
38 | * Gets the name of the collaborator.
39 | *
40 | * @return the name of the collaborator.
41 | */
42 | public String getName() {
43 | return getPropertyAsString(FIELD_NAME);
44 | }
45 |
46 | /**
47 | * Gets the date that the collaborator was created.
48 | *
49 | * @return the date that the collaborator was created.
50 | */
51 | public Date getCreatedAt() {
52 | return getPropertyAsDate(FIELD_CREATED_AT);
53 | }
54 |
55 | /**
56 | * Gets the date that the collaborator was modified.
57 | *
58 | * @return the date that the collaborator was modified.
59 | */
60 | public Date getModifiedAt() {
61 | return getPropertyAsDate(FIELD_MODIFIED_AT);
62 | }
63 |
64 | }
--------------------------------------------------------------------------------
/box-content-sdk/src/main/java/com/box/androidsdk/content/models/BoxMetadata.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content.models;
2 |
3 | import com.eclipsesource.json.JsonObject;
4 | import com.eclipsesource.json.JsonValue;
5 |
6 | import java.util.List;
7 | import java.util.Map;
8 |
9 | /**
10 | * Represents metadata information from a template.
11 | */
12 | public class BoxMetadata extends BoxJsonObject {
13 |
14 | /**
15 | * The file ID that metadata belongs to.
16 | */
17 | public static final String FIELD_PARENT = "parent";
18 |
19 | /**
20 | * The template that the metadata information belongs to.
21 | */
22 | public static final String FIELD_TEMPLATE = "template";
23 |
24 | /**
25 | * The scope that the metadata's template belongs to.
26 | */
27 | public static final String FIELD_SCOPE = "scope";
28 |
29 | private List mMetadataKeys;
30 |
31 | /**
32 | * Constructs an empty BoxMetadata object.
33 | */
34 | public BoxMetadata() {
35 | super();
36 | }
37 |
38 | /**
39 | * Initialize with a Map from Box API response JSON.
40 | *
41 | * @param object from Box API response JSON.
42 | *
43 | */
44 | public BoxMetadata(JsonObject object) {
45 | super(object);
46 | }
47 |
48 | /**
49 | * Gets the metadata's parent.
50 | *
51 | * @return the metadata's parent.
52 | */
53 | public String getParent() {
54 | return getPropertyAsString(FIELD_PARENT);
55 | }
56 |
57 | /**
58 | * Gets the metadata's template.
59 | *
60 | * @return the metadata's template.
61 | */
62 | public String getTemplate() {
63 | return getPropertyAsString(FIELD_TEMPLATE);
64 | }
65 |
66 | /**
67 | * Gets the metadata's scope.
68 | *
69 | * @return the metadata's scope.
70 | */
71 | public String getScope() {
72 | return getPropertyAsString(FIELD_SCOPE);
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/java/com/box/androidsdk/content/requests/BoxRequestItemDelete.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content.requests;
2 |
3 | import com.box.androidsdk.content.models.BoxSession;
4 | import com.box.androidsdk.content.models.BoxVoid;
5 |
6 | /**
7 | * Abstract class that represents a request to delete a BoxItem.
8 | *
9 | * @param type of BoxRequest that is being created.
10 | */
11 | public abstract class BoxRequestItemDelete> extends BoxRequest {
12 | protected String mId;
13 |
14 | /**
15 | * Constructs an item delete request with the default parameters.
16 | *
17 | * @param id id of the Box item to delete.
18 | * @param requestUrl URL of the delete endpoint.
19 | * @param session the authenticated session that will be used to make the request with.
20 | */
21 | public BoxRequestItemDelete(String id, String requestUrl, BoxSession session) {
22 | super(BoxVoid.class, requestUrl, session);
23 | mId = id;
24 | mRequestMethod = Methods.DELETE;
25 | }
26 |
27 | /**
28 | * Gets the id of the item to delete.
29 | *
30 | * @return id of the item to delete.
31 | */
32 | public String getId() {
33 | return mId;
34 | }
35 |
36 | /**
37 | * Sets the if-match header for the request.
38 | * The item will only be deleted if the specified etag matches the most current etag for the item.
39 | *
40 | * @param etag etag to set in the if-match header.
41 | * @return the request with the updated if-match header.
42 | */
43 | @Override
44 | public R setIfMatchEtag(String etag) {
45 | return super.setIfMatchEtag(etag);
46 | }
47 |
48 | /**
49 | * Returns the currently set etag for the if-match header of the request.
50 | *
51 | * @return etag currently set in the if-match header.
52 | */
53 | @Override
54 | public String getIfMatchEtag() {
55 | return super.getIfMatchEtag();
56 | }
57 |
58 | }
59 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/java/com/box/androidsdk/content/utils/BoxLogger.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content.utils;
2 |
3 | import android.util.Log;
4 |
5 | import com.box.androidsdk.content.BoxConfig;
6 |
7 | import java.io.PrintWriter;
8 | import java.io.StringWriter;
9 | import java.util.Locale;
10 | import java.util.Map;
11 |
12 | /**
13 | * Implementation for Logger.
14 | */
15 | public class BoxLogger implements Logger {
16 | public boolean getIsLoggingEnabled() {
17 | return (BoxConfig.IS_LOG_ENABLED && BoxConfig.IS_DEBUG);
18 | }
19 |
20 | public void i(String tag, String msg) {
21 | if (getIsLoggingEnabled()) {
22 | Log.i(tag, msg);
23 | }
24 | }
25 |
26 | public void i(String tag, String msg, Map map) {
27 | if (getIsLoggingEnabled() && map != null) {
28 | for (Map.Entry e : map.entrySet()) {
29 | Log.i(tag, String.format(Locale.ENGLISH, "%s: %s:%s", msg, e.getKey(), e.getValue()));
30 | }
31 | }
32 | }
33 |
34 | public void d(String tag, String msg) {
35 | if (getIsLoggingEnabled()) {
36 | Log.d(tag, msg);
37 | }
38 | }
39 |
40 | public void e(String tag, String msg) {
41 | if (getIsLoggingEnabled()) {
42 | Log.e(tag, msg);
43 | }
44 | }
45 |
46 | public void e(String tag, Throwable t) {
47 | if (getIsLoggingEnabled() && t != null) {
48 | StringWriter sw = new StringWriter();
49 | PrintWriter pw = new PrintWriter(sw);
50 | t.printStackTrace(pw);
51 | Log.e(tag, sw.toString());
52 | }
53 | }
54 |
55 | public void e(String tag, String msg, Throwable t) {
56 | if (getIsLoggingEnabled()) {
57 | Log.e(tag, msg, t);
58 | }
59 | }
60 |
61 | @Override
62 | public void nonFatalE(String tag, String msg, Throwable t) {
63 | if (getIsLoggingEnabled()) {
64 | Log.e("NON_FATAL" + tag, msg, t);
65 | }
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/java/com/box/androidsdk/content/requests/BoxResponse.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content.requests;
2 |
3 | import com.box.androidsdk.content.models.BoxObject;
4 |
5 | import java.io.Serializable;
6 |
7 | /**
8 | * This class acts as a wrapper for holding onto the response or exceptions returned from the result of a BoxRequest.
9 | * @param The BoxObject that was generated from a response to a BoxRequest.
10 | */
11 | public class BoxResponse implements Serializable {
12 |
13 | protected final E mResult;
14 | protected final Exception mException;
15 | protected final BoxRequest mRequest;
16 |
17 | // BoxResponse should never be instantiated by themselves and instead should be created from a BoxHttpResponse
18 |
19 | /**
20 | *
21 | * @param result the BoxObject generated from handling BoxHttpResponse if any.
22 | * @param ex the exception thrown from a handling a BoxHttpResponse if any.
23 | * @param request the original request that generated the BoxHttpResponse sourcing the result or exception.
24 | */
25 | public BoxResponse(E result, Exception ex, BoxRequest request) {
26 | mResult = result;
27 | mException = ex;
28 | mRequest = request;
29 | }
30 |
31 | /**
32 | *
33 | * @return the BoxObject parsed from a given server response.
34 | */
35 | public E getResult() {
36 | return mResult;
37 | }
38 |
39 | /**
40 | *
41 | * @return the exception thrown from a given server response.
42 | */
43 | public Exception getException() {
44 | return mException;
45 | }
46 |
47 | /**
48 | *
49 | * @return the request used to generate the response or exception backing this object.
50 | */
51 | public BoxRequest getRequest() {
52 | return mRequest;
53 | }
54 |
55 | /**
56 | *
57 | * @return true if this object was not created from an exception, false otherwise.
58 | */
59 | public boolean isSuccess() {
60 | return mException == null;
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/java/com/box/androidsdk/content/requests/BoxRequestList.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content.requests;
2 |
3 | import com.box.androidsdk.content.models.BoxSession;
4 | import com.box.androidsdk.content.models.BoxIterator;
5 |
6 | /**
7 | * Request for getting a list of items.
8 | */
9 | public abstract class BoxRequestList> extends BoxRequestItem {
10 | private static final String LIMIT = "limit";
11 | private static final String OFFSET = "offset";
12 |
13 | // 1000 is the current max that the API supports
14 | private static final String DEFAULT_LIMIT = "1000";
15 | private static final String DEFAULT_OFFSET = "0";
16 |
17 |
18 | /**
19 | * Creates a list request with the default parameters
20 | *
21 | * @param clazz class of the object returned in the response.
22 | * @param id id of the list to get the items of
23 | * @param requestUrl URL of the list items endpoint
24 | * @param session the authenticated session that will be used to make the request with
25 | */
26 | public BoxRequestList(Class clazz, String id, String requestUrl, BoxSession session) {
27 | super(clazz, id, requestUrl, session);
28 | mRequestMethod = Methods.GET;
29 | mQueryMap.put(LIMIT, DEFAULT_LIMIT);
30 | mQueryMap.put(OFFSET, DEFAULT_OFFSET);
31 | }
32 |
33 | /**
34 | * Sets the limit of items that should be returned
35 | *
36 | * @param limit limit of items to return
37 | * @return the get folder items request
38 | */
39 | public R setLimit(int limit) {
40 | mQueryMap.put(LIMIT, String.valueOf(limit));
41 | return (R) this;
42 | }
43 |
44 | /**
45 | * Sets the offset of the items that should be returned
46 | *
47 | * @param offset offset of items to return
48 | * @return the offset of the items to return
49 | */
50 | public R setOffset(int offset) {
51 | mQueryMap.put(OFFSET, String.valueOf(offset));
52 | return (R) this;
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/java/com/box/androidsdk/content/models/BoxUploadSessionEndpoints.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content.models;
2 |
3 | import java.util.HashMap;
4 | import java.util.List;
5 | import java.util.Map;
6 |
7 | /**
8 | * JsonObject representing the endpoints of a box upload session for multiput uploads
9 | */
10 |
11 | public class BoxUploadSessionEndpoints extends BoxJsonObject {
12 |
13 | public static final String FIELD_LIST_PARTS = "list_parts";
14 | public static final String FIELD_COMMIT = "commit";
15 | public static final String FIELD_UPLOAD_PART = "upload_part";
16 | public static final String FIELD_STATUS = "status";
17 | public static final String FIELD_ABORT = "abort";
18 |
19 | /**
20 | * Get end point for listing parts
21 | * @return
22 | */
23 | public String getListPartsEndpoint() {
24 | return getPropertyAsString(FIELD_LIST_PARTS);
25 | }
26 |
27 | /**
28 | * Get commit endpoint
29 | * @return
30 | */
31 | public String getCommitEndpoint() {
32 | return getPropertyAsString(FIELD_COMMIT);
33 | }
34 |
35 | /**
36 | * Get upload endpoint
37 | * @return
38 | */
39 | public String getUploadPartEndpoint() {
40 | return getPropertyAsString(FIELD_UPLOAD_PART);
41 | }
42 |
43 | /**
44 | * Get status endpoint
45 | * @return
46 | */
47 | public String getStatusEndpoint() {
48 | return getPropertyAsString(FIELD_STATUS);
49 | }
50 |
51 | /**
52 | * Get abort endpoint
53 | * @return
54 | */
55 | public String getAbortEndpoint() {
56 | return getPropertyAsString(FIELD_ABORT);
57 | }
58 |
59 | /**
60 | * Get a map of all end points
61 | * @return
62 | */
63 | public Map getEndpointsMap () {
64 | List keys = getPropertiesKeySet();
65 | HashMap endpoints = new HashMap<>(keys.size());
66 | for (String key : keys) {
67 | endpoints.put(key, getPropertyAsString(key));
68 | }
69 | return endpoints;
70 | }
71 |
72 |
73 | }
74 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/java/com/box/androidsdk/content/models/BoxMDMData.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content.models;
2 |
3 | import com.eclipsesource.json.JsonObject;
4 |
5 |
6 | /**
7 | * An object containing Mobile Device Management data that may be required to login with certain enterprise and api key combinations.
8 | */
9 | public class BoxMDMData extends BoxJsonObject {
10 |
11 | public static final String BOX_MDM_DATA = "box_mdm_data";
12 | public static final String BUNDLE_ID = "bundle_id";
13 | public static final String MANAGEMENT_ID = "management_id";
14 | public static final String PUBLIC_ID = "public_id";
15 | public static final String BILLING_ID = "billing_id";
16 | public static final String EMAIL_ID = "email_id";
17 |
18 |
19 | public BoxMDMData() {
20 | super();
21 | }
22 |
23 | public BoxMDMData(JsonObject jsonObject) {
24 | super(jsonObject);
25 | }
26 |
27 | public void setValue(final String key, final String value){
28 | set(key, value);
29 | }
30 |
31 | public void setBundleId(final String bundleId){
32 | setValue(BUNDLE_ID, bundleId);
33 | }
34 |
35 | public void setPublicId(final String publicId){
36 | setValue(PUBLIC_ID, publicId);
37 | }
38 |
39 | public void setManagementId(final String managementId){
40 | setValue(MANAGEMENT_ID, managementId);
41 | }
42 |
43 | public void setEmailId(final String emailId){
44 | setValue(EMAIL_ID, emailId);
45 | }
46 |
47 | public void setBillingId(final String billingId){
48 | setValue(BILLING_ID, billingId);
49 | }
50 |
51 | public String getBundleId(){
52 | return getPropertyAsString(PUBLIC_ID);
53 | }
54 |
55 | public String getPublicId(){
56 | return getPropertyAsString(PUBLIC_ID);
57 | }
58 |
59 | public String getManagementId(){
60 | return getPropertyAsString(MANAGEMENT_ID);
61 | }
62 |
63 | public String getEmailId(){
64 | return getPropertyAsString(EMAIL_ID);
65 | }
66 |
67 | public String getBillingIdId(){
68 | return getPropertyAsString(BILLING_ID);
69 | }
70 |
71 |
72 | }
73 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/java/com/box/androidsdk/content/utils/Logger.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content.utils;
2 |
3 | import java.util.Map;
4 |
5 | /**
6 | * Interface supporting logging for box sdks
7 | */
8 |
9 | public interface Logger {
10 |
11 | /**
12 | * @return true if logging is currently enabled.
13 | */
14 | public boolean getIsLoggingEnabled();
15 |
16 | /**
17 | * Info logs.
18 | * @param tag tag to provide category information
19 | * @param msg detailed message for debugging
20 | */
21 | public void i(String tag, String msg);
22 |
23 | /**
24 | * Info logs with key-value pairs
25 | * @param tag tag to provide category information
26 | * @param msg detailed message for debugging
27 | * @param map map of keys and values to log.
28 | */
29 | public void i(String tag, String msg, Map map);
30 |
31 | /**
32 | * Debug logs
33 | * @param tag tag to provide category information
34 | * @param msg detailed message for debugging
35 | */
36 | public void d(String tag, String msg);
37 |
38 | /**
39 | * Error logs
40 | * @param tag tag to provide category information
41 | * @param msg detailed message for debugging
42 | */
43 | public void e(String tag, String msg);
44 |
45 | /**
46 | * Error log with throwable
47 | * @param tag tag to provide category information
48 | * @param t the exception to log
49 | */
50 | public void e(String tag, Throwable t);
51 |
52 | /**
53 | * Error log with throwable and message.
54 | * @param tag tag to provide category information
55 | * @param msg detailed message for debugging
56 | * @param t the exception to log
57 | */
58 | public void e(String tag, String msg, Throwable t);
59 |
60 | /**
61 | * Use for logging non fatal errors
62 | * May be used for debugging with stack traces.
63 | * @param tag tag to provide category information
64 | * @param msg detailed message for debugging
65 | * @param t the exception if applicable
66 | */
67 | public void nonFatalE(String tag, String msg, Throwable t);
68 | }
69 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/java/com/box/androidsdk/content/BoxApiShare.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content;
2 |
3 | import android.text.TextUtils;
4 |
5 | import com.box.androidsdk.content.models.BoxSession;
6 | import com.box.androidsdk.content.models.BoxSharedLinkSession;
7 | import com.box.androidsdk.content.requests.BoxRequestsShare;
8 |
9 | /**
10 | * Represents the API of the share endpoint on Box. This class can be used to generate request objects
11 | * for each of the APIs exposed endpoints
12 | */
13 | public class BoxApiShare extends BoxApi {
14 |
15 | protected String getSharedItemsUrl() { return String.format("%s/shared_items", getBaseUri()); }
16 |
17 | /**
18 | * Constructs a BoxApiShare with the provided BoxSession
19 | *
20 | * @param session authenticated session to use with the BoxApiShare
21 | */
22 | public BoxApiShare(BoxSession session) {
23 | super(session);
24 | }
25 |
26 | /**
27 | * Returns a request to get a BoxItem from a shared link.
28 | *
29 | * @param sharedLink shared link of the item to retrieve.
30 | * @return request to get a BoxItem from a shared link.
31 | */
32 | public BoxRequestsShare.GetSharedLink getSharedLinkRequest(String sharedLink) {
33 | return getSharedLinkRequest(sharedLink, null);
34 | }
35 |
36 | /**
37 | * Returns a request to get a BoxItem from a shared link.
38 | *
39 | * @param sharedLink shared link of the item to retrieve.
40 | * @param password password for shared link
41 | * @return request to get a BoxItem from a shared link.
42 | */
43 | public BoxRequestsShare.GetSharedLink getSharedLinkRequest(String sharedLink, String password) {
44 | BoxSharedLinkSession session = null;
45 | if (mSession instanceof BoxSharedLinkSession) {
46 | session = (BoxSharedLinkSession)mSession;
47 | } else {
48 | session = new BoxSharedLinkSession(mSession);
49 | }
50 |
51 | session.setSharedLink(sharedLink);
52 | session.setPassword(password);
53 | BoxRequestsShare.GetSharedLink request = new BoxRequestsShare.GetSharedLink(getSharedItemsUrl(), session);
54 | return request;
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/java/com/box/androidsdk/content/models/BoxUploadSessionPart.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content.models;
2 |
3 | import com.eclipsesource.json.JsonObject;
4 |
5 | /**
6 | * Represents a part of the file that is uploaded.
7 | */
8 | public class BoxUploadSessionPart extends BoxJsonObject {
9 |
10 | private String partId;
11 | private long offset;
12 | private long size;
13 | private String sha1;
14 |
15 | public static final String FIELD_PART_ID = "part_id";
16 | public static final String FIELD_SIZE = "size";
17 | public static final String FIELD_OFFSET = "offset";
18 | public static final String FIELD_SHA1 = "sha1";
19 |
20 | public static final String FIELD_PART = "part";
21 |
22 |
23 | /**
24 | * Constructs a BoxUploadSessionPart object.
25 | *
26 | * @param object jsonObject to use to create an instance of this class.
27 | */
28 | public BoxUploadSessionPart(JsonObject object) {
29 | super(object);
30 | }
31 |
32 | @Override
33 | public void createFromJson(JsonObject object) {
34 | super.createFromJson(object.get(FIELD_PART) == null ? object : object.get(FIELD_PART).asObject());
35 | }
36 |
37 | /**
38 | * Constructs an empty BoxUploadSessionPart object.
39 | */
40 | public BoxUploadSessionPart() {
41 | super();
42 | }
43 |
44 | /**
45 | * Gets the sha1 digest of the part.
46 | *
47 | * @return the sh1 digest
48 | */
49 | public String getSha1() {
50 | return getPropertyAsString(FIELD_SHA1);
51 | }
52 |
53 |
54 | /**
55 | * Gets the part id.
56 | *
57 | * @return the id of the part.
58 | */
59 | public String getPartId() {
60 | return getPropertyAsString(FIELD_PART_ID);
61 | }
62 |
63 | /**
64 | * Gets the offset byte.
65 | *
66 | * @return the offset of the part.
67 | */
68 | public long getOffset() {
69 | return getPropertyAsLong(FIELD_OFFSET);
70 | }
71 |
72 | /**
73 | * Gets the size of the part.
74 | *
75 | * @return the size of the part.
76 | */
77 | public long getSize() {
78 | return getPropertyAsLong(FIELD_SIZE);
79 | }
80 |
81 | }
--------------------------------------------------------------------------------
/box-content-sdk/src/main/java/com/box/androidsdk/content/models/BoxRealTimeServer.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content.models;
2 |
3 | import com.box.androidsdk.content.utils.SdkUtils;
4 | import com.eclipsesource.json.JsonObject;
5 | import com.eclipsesource.json.JsonValue;
6 |
7 | import java.util.Map;
8 |
9 | /**
10 | * Contains information about a RealTimeServer.
11 | */
12 | public class BoxRealTimeServer extends BoxEntity {
13 |
14 | private static final long serialVersionUID = -6591493101188395748L;
15 |
16 | public static final String TYPE = "realtime_server";
17 |
18 | public static final String FIELD_TYPE = "type";
19 | public static final String FIELD_URL = "url";
20 | public static final String FIELD_TTL = "ttl";
21 | public static final String FIELD_MAX_RETRIES = "max_retries";
22 | public static final String FIELD_RETRY_TIMEOUT = "retry_timeout";
23 |
24 | /**
25 | * The realtime_server type, 'realtime_server'
26 | *
27 | * @return The realtime_server type, 'realtime_server'
28 | */
29 | public String getType() {
30 | return getPropertyAsString(TYPE);
31 | }
32 |
33 | /**
34 | * Returns the URL for connecting to this server.
35 | *
36 | * @return the URL for connecting to this server.
37 | */
38 | public String getUrl() {
39 | return getPropertyAsString(FIELD_URL);
40 | }
41 |
42 | /**
43 | * Returns the time to live for connections to this server.
44 | *
45 | * @return The time to live for connections to this server.
46 | */
47 | public Long getTTL() {
48 | return getPropertyAsLong(FIELD_TTL);
49 | }
50 |
51 | /**
52 | * Returns the maximum number of retries connections to this server should make.
53 | *
54 | * @return The maximum number of retries connections to this server should make.
55 | */
56 | public Long getMaxRetries() {
57 | return getPropertyAsLong(FIELD_MAX_RETRIES);
58 | }
59 |
60 | public Long getFieldRetryTimeout() {
61 | return getPropertyAsLong(FIELD_RETRY_TIMEOUT);
62 | }
63 |
64 | /**
65 | * Constructs an empty object.
66 | */
67 | public BoxRealTimeServer() {
68 | super();
69 | }
70 |
71 |
72 | }
--------------------------------------------------------------------------------
/box-content-sdk/src/main/java/com/box/androidsdk/content/BoxApiCollection.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content;
2 |
3 | import com.box.androidsdk.content.models.BoxSession;
4 | import com.box.androidsdk.content.requests.BoxRequestsCollections;
5 |
6 | /**
7 | * Represents the API of the collections endpoint on Box. This class can be used to generate request objects
8 | * for each of the APIs exposed endpoints
9 | */
10 | public class BoxApiCollection extends BoxApi {
11 |
12 | /**
13 | * Constructs a BoxApiCollection with the provided BoxSession
14 | *
15 | * @param session authenticated session to use with the BoxApiCollection
16 | */
17 | public BoxApiCollection(BoxSession session) {
18 | super(session);
19 | }
20 |
21 | /**
22 | * Gets the URL for getting the available collections
23 | *
24 | * @return the URL string for getting the available collections
25 | */
26 | protected String getCollectionsUrl() {
27 | return String.format("%s/collections", getBaseUri());
28 | }
29 |
30 | /**
31 | * Gets the URL for getting the items of a collection
32 | * @param id the unique id associated with the item.
33 | * @return the URL string for getting a collections items
34 | */
35 | protected String getCollectionItemsUrl(String id) {
36 | return String.format("%s/%s/items", getCollectionsUrl(), id);
37 | }
38 |
39 | /**
40 | * Gets a request that gets the collections belonging to the user
41 | *
42 | * @return request to get collections belonging to the user
43 | */
44 | public BoxRequestsCollections.GetCollections getCollectionsRequest() {
45 | BoxRequestsCollections.GetCollections request = new BoxRequestsCollections.GetCollections(getCollectionsUrl(), mSession);
46 | return request;
47 | }
48 |
49 | /**
50 | * Gets a request that gets the items of a collection
51 | *
52 | * @param id id of collection to retrieve items of
53 | * @return request to get a collections items
54 | */
55 | public BoxRequestsCollections.GetCollectionItems getItemsRequest(String id) {
56 | BoxRequestsCollections.GetCollectionItems request = new BoxRequestsCollections.GetCollectionItems(id, getCollectionItemsUrl(id), mSession);
57 | return request;
58 | }
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/java/com/box/androidsdk/content/requests/BoxRequestCollectionUpdate.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content.requests;
2 |
3 | import android.text.TextUtils;
4 |
5 | import com.box.androidsdk.content.models.BoxSession;
6 | import com.box.androidsdk.content.models.BoxCollection;
7 | import com.box.androidsdk.content.models.BoxItem;
8 | import com.box.androidsdk.content.models.BoxIteratorCollections;
9 | import com.box.androidsdk.content.utils.SdkUtils;
10 | import com.eclipsesource.json.JsonArray;
11 | import com.eclipsesource.json.JsonObject;
12 | import com.eclipsesource.json.JsonValue;
13 |
14 | import java.util.LinkedHashMap;
15 | import java.util.Map;
16 |
17 | /**
18 | * Abstract class that represents a request to update a collection's contents by adding or removing an item.
19 | * @param type of BoxItem that is returned in the response.
20 | * @param type of BoxRequest that is being created.
21 | */
22 | public abstract class BoxRequestCollectionUpdate> extends BoxRequestItem {
23 |
24 | protected static final String FIELD_COLLECTIONS = "collections";
25 |
26 | /**
27 | * Constructs an update collection request with the default parameters.
28 | *
29 | * @param clazz class of the BoxItem returned in the response.
30 | * @param id id of the item to add to/remove from a collection.
31 | * @param requestUrl URL of the update collection endpoint.
32 | * @param session the authenticated session that will be used to make the request with.
33 | */
34 | public BoxRequestCollectionUpdate(Class clazz, String id, String requestUrl, BoxSession session) {
35 | super(clazz, id, requestUrl, session);
36 | mRequestMethod = Methods.PUT;
37 | }
38 |
39 | /**
40 | * Sets the id of the collection to update.
41 | *
42 | * @param id id of the collection to update.
43 | * @return request with the updated collection id.
44 | */
45 | protected R setCollectionId(String id) {
46 | JsonArray jsonArray = new JsonArray();
47 | if (!TextUtils.isEmpty(id)) {
48 | BoxCollection col = BoxCollection.createFromId(id);
49 | jsonArray.add(col.toJsonObject());
50 | }
51 | mBodyMap.put(FIELD_COLLECTIONS, jsonArray);
52 | return (R) this;
53 | }
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/bug.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Bug
3 | about: Report a bug found in the SDK
4 | title: ''
5 | labels: bug
6 | assignees: mwwoda, mhagmajer, antusus, arjankowski, lukaszsocha2, bartlomiejleszczynski
7 |
8 | ---
9 |
10 | - [ ] I have checked that the [SDK documentation][sdk-docs] doesn't solve my issue.
11 | - [ ] I have checked that the [API documentation][api-docs] doesn't solve my issue.
12 | - [ ] I have searched the [Box Developer Forums][dev-forums] and my issue isn't already reported (or if it has been reported, I have attached a link to it, for reference).
13 | - [ ] I have searched [Issues in this repo][github-repo] and my issue isn't already reported.
14 |
15 | ### Description of the Issue
16 |
17 |
18 |
19 |
20 |
21 | ### Steps to Reproduce
22 |
23 |
24 |
25 |
26 | 1. Go to '...'
27 | 2. Click on '....'
28 | 3. Scroll down to '....'
29 | 4. See error
30 |
31 | ### Expected Behavior
32 |
33 |
34 | ### Error Message, Including Stack Trace
35 |
36 |
37 |
38 | ### Screenshots
39 |
40 |
41 | ### Versions Used
42 | Android SDK:
43 | Android:
44 |
45 | [sdk-docs]: ./doc
46 | [api-docs]: https://developer.box.com/docs
47 | [dev-forums]: https://community.box.com/t5/Platform-and-Development-Forum/bd-p/DeveloperForum
48 | [github-repo]: https://github.com/box/box-android-sdk/search?type=Issues
49 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/question.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Question
3 | about: Request for Assistance
4 | title: ''
5 | labels: question
6 | assignees: mwwoda, mhagmajer, antusus, arjankowski, lukaszsocha2, bartlomiejleszczynski
7 |
8 | ---
9 |
10 | - [ ] I have checked that the [SDK documentation][sdk-docs] doesn't solve my issue.
11 | - [ ] I have checked that the [API documentation][api-docs] doesn't solve my issue.
12 | - [ ] I have searched the [Box Developer Forums][dev-forums] and my issue isn't already reported (or if it has been reported, I have attached a link to it, for reference).
13 | - [ ] I have searched [Issues in this repo][github-repo] and my issue isn't already reported.
14 |
15 | ### Description of the Issue
16 |
17 |
18 |
19 |
20 |
21 | ### Steps to Reproduce
22 |
23 |
24 |
25 |
26 | 1. Go to '...'
27 | 2. Click on '....'
28 | 3. Scroll down to '....'
29 | 4. See error
30 |
31 | ### Expected Behavior
32 |
33 |
34 | ### Error Message, Including Stack Trace
35 |
36 |
37 |
38 | ### Screenshots
39 |
40 |
41 | ### Versions Used
42 | Android SDK:
43 | Android:
44 |
45 | [sdk-docs]: ./doc
46 | [api-docs]: https://developer.box.com/docs
47 | [dev-forums]: https://community.box.com/t5/Platform-and-Development-Forum/bd-p/DeveloperForum
48 | [github-repo]: https://github.com/box/box-android-sdk/search?type=Issues
49 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/java/com/box/androidsdk/content/utils/ProgressInputStream.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content.utils;
2 |
3 | import com.box.androidsdk.content.listeners.ProgressListener;
4 |
5 | import java.io.IOException;
6 | import java.io.InputStream;
7 |
8 | /**
9 | * An {@link java.io.InputStream} that can report the progress of reading from another InputStream to a
10 | * {@link com.box.androidsdk.content.listeners.ProgressListener}.
11 | */
12 | public class ProgressInputStream extends InputStream {
13 | private final InputStream stream;
14 | private final ProgressListener listener;
15 |
16 | private long total;
17 | private long totalRead;
18 | private int progress;
19 |
20 | /**
21 | * Constructs a ProgressInputStream that wraps another InputStream.
22 | * @param stream the stream whose progress will be monitored.
23 | * @param listener the listener that will receive progress updates.
24 | * @param total the total number of bytes that are expected to be read from the stream.
25 | */
26 | public ProgressInputStream(InputStream stream, ProgressListener listener, long total) {
27 | this.stream = stream;
28 | this.listener = listener;
29 | this.total = total;
30 | }
31 |
32 | /**
33 | * Gets the total number of bytes that are expected to be read from the stream.
34 | * @return the total number of bytes.
35 | */
36 | public long getTotal() {
37 | return this.total;
38 | }
39 |
40 | /**
41 | * Sets the total number of bytes that are expected to be read from the stream.
42 | * @param total the total number of bytes
43 | */
44 | public void setTotal(long total) {
45 | this.total = total;
46 | }
47 |
48 | @Override
49 | public void close() throws IOException {
50 | this.stream.close();
51 | }
52 |
53 | @Override
54 | public int read() throws IOException {
55 | int read = this.stream.read();
56 | this.totalRead++;
57 | this.listener.onProgressChanged(this.totalRead, this.total);
58 |
59 | return read;
60 | }
61 |
62 | @Override
63 | public int read(byte[] b, int off, int len) throws IOException {
64 | int read = this.stream.read(b, off, len);
65 | this.totalRead += read;
66 | this.listener.onProgressChanged(this.totalRead, this.total);
67 |
68 | return read;
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/java/com/box/androidsdk/content/models/BoxRecentItem.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content.models;
2 |
3 | import com.eclipsesource.json.JsonObject;
4 |
5 | import java.util.Date;
6 |
7 | /**
8 | * A class representing Box recent item
9 | */
10 | public class BoxRecentItem extends BoxJsonObject {
11 | private static final long serialVersionUID = -2642748896882484887L;
12 |
13 | private static final String TYPE = "recent_item";
14 |
15 | protected static final String FIELD_INTERACTION_TYPE = "interaction_type";
16 | protected static final String FIELD_INTERACTED_AT = "interacted_at";
17 | protected static final String FIELD_ITEM = "item";
18 | protected static final String FIELD_ITERACTION_SHARED_LINK = "interaction_shared_link";
19 |
20 | public BoxRecentItem() {
21 | super();
22 | }
23 |
24 | /**
25 | * Constructs a BoxRecentItem with the provided map values
26 | *
27 | * @param object JsonObject representing this class
28 | */
29 | public BoxRecentItem (JsonObject object) {
30 | super(object);
31 | }
32 |
33 | /**
34 | * Gets the Type of object
35 | *
36 | * @return Returns the type of object i.e recent_item
37 | */
38 | public String getType() {
39 | return getPropertyAsString(TYPE);
40 | }
41 |
42 | /**
43 | * Gets the recent item
44 | *
45 | * @return Returns BoxItem object from the BoxRecentItem object
46 | */
47 | public BoxItem getItem(){
48 | return (BoxItem) getPropertyAsJsonObject(BoxEntity.getBoxJsonObjectCreator(), FIELD_ITEM);
49 | }
50 |
51 | /**
52 | * Gets the interaction type of the item eg. item_preview, item_open etc.
53 | *
54 | * @return Interaction type of the item
55 | */
56 | public String getInteractionType()
57 | {
58 | return getPropertyAsString(FIELD_INTERACTION_TYPE);
59 | }
60 |
61 | /**
62 | * Gets the timestamp of last interaction with the item
63 | *
64 | * @return Date object representing interaction timestamp
65 | */
66 | public Date getInteractedAt()
67 | {
68 | return getPropertyAsDate(FIELD_INTERACTED_AT);
69 | }
70 |
71 | /**
72 | * Gets the shared link used for accessing the item
73 | *
74 | * @return shared link URL
75 | */
76 | public String getInteractionSharedLink()
77 | {
78 | return getPropertyAsString(FIELD_ITERACTION_SHARED_LINK);
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/java/com/box/androidsdk/content/models/BoxPermission.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content.models;
2 |
3 | import com.eclipsesource.json.JsonObject;
4 |
5 | import java.util.EnumSet;
6 | import java.util.Map;
7 |
8 | /**
9 | * Holds the API representation of a permission set for a {@link BoxItem} which is a string to
10 | * boolean mapping. Convenience methods are provided ({@link BoxFolder#getPermissions()} and
11 | * {@link BoxFile#getPermissions()}) to make permission comparison easier
12 | */
13 | public class BoxPermission extends BoxJsonObject {
14 |
15 | public BoxPermission() {
16 | super();
17 | }
18 |
19 | public BoxPermission(JsonObject object) {
20 | super(object);
21 | }
22 |
23 | EnumSet getPermissions() {
24 | EnumSet permissions = EnumSet.noneOf(BoxItem.Permission.class);
25 |
26 | for (String key : getPropertiesKeySet()){
27 | Boolean value = getPropertyAsBoolean(key);
28 | if (value == null || value == false) {
29 | continue;
30 | }
31 |
32 | if (key.equals(BoxItem.Permission.CAN_DOWNLOAD.toString())) {
33 | permissions.add(BoxItem.Permission.CAN_DOWNLOAD);
34 | } else if (key.equals(BoxItem.Permission.CAN_UPLOAD.toString())) {
35 | permissions.add(BoxItem.Permission.CAN_UPLOAD);
36 | } else if (key.equals(BoxItem.Permission.CAN_RENAME.toString())) {
37 | permissions.add(BoxItem.Permission.CAN_RENAME);
38 | } else if (key.equals(BoxItem.Permission.CAN_DELETE.toString())) {
39 | permissions.add(BoxItem.Permission.CAN_DELETE);
40 | } else if (key.equals(BoxItem.Permission.CAN_SHARE.toString())) {
41 | permissions.add(BoxItem.Permission.CAN_SHARE);
42 | } else if (key.equals(BoxItem.Permission.CAN_SET_SHARE_ACCESS.toString())) {
43 | permissions.add(BoxItem.Permission.CAN_SET_SHARE_ACCESS);
44 | } else if (key.equals(BoxItem.Permission.CAN_PREVIEW.toString())) {
45 | permissions.add(BoxItem.Permission.CAN_PREVIEW);
46 | } else if (key.equals(BoxItem.Permission.CAN_COMMENT.toString())) {
47 | permissions.add(BoxItem.Permission.CAN_COMMENT);
48 | } else if (key.equals(BoxItem.Permission.CAN_INVITE_COLLABORATOR.toString())) {
49 | permissions.add(BoxItem.Permission.CAN_INVITE_COLLABORATOR);
50 | }
51 | }
52 |
53 | return permissions;
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/java/com/box/androidsdk/content/BoxApiEvent.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content;
2 |
3 | import com.box.androidsdk.content.models.BoxSession;
4 | import com.box.androidsdk.content.utils.RealTimeServerConnection;
5 | import com.box.androidsdk.content.requests.BoxRequestsEvent;
6 |
7 | /**
8 | * Represents the API of the event endpoint on Box. This class can be used to generate request objects
9 | * for each of the APIs exposed endpoints
10 | */
11 | public class BoxApiEvent extends BoxApi {
12 |
13 | public static final String EVENTS_ENDPOINT = "/events";
14 |
15 | /**
16 | * Constructs a BoxApiEvent with the provided BoxSession
17 | *
18 | * @param session authenticated session to use with the BoxApiEvent
19 | */
20 | public BoxApiEvent(BoxSession session) {
21 | super(session);
22 | }
23 |
24 | protected String getEventsUrl() { return getBaseUri() + EVENTS_ENDPOINT; }
25 |
26 |
27 | /**
28 | * Gets a request that retrieves user events
29 | *
30 | * @return request to get user events
31 | */
32 | public BoxRequestsEvent.GetUserEvents getUserEventsRequest() {
33 | BoxRequestsEvent.GetUserEvents request = new BoxRequestsEvent.GetUserEvents( getEventsUrl(), mSession);
34 | return request;
35 | }
36 |
37 | /**
38 | * Gets a request that retrieves enterprise events
39 | *
40 | * @return request to retrieve enterprise events
41 | */
42 | public BoxRequestsEvent.GetEnterpriseEvents getEnterpriseEventsRequest() {
43 | BoxRequestsEvent.GetEnterpriseEvents request = new BoxRequestsEvent.GetEnterpriseEvents(getEventsUrl(), mSession);
44 | return request;
45 | }
46 |
47 | /**
48 | * Gets a request that retrieves a RealTimeServerConnection, which is used to create a long poll to check for some generic change
49 | * to the user's account. This can be combined with syncing logic using getUserEventsRequest or getEnterpriseEventsRequest to discover what has changed.
50 | *
51 | * @param changeListener A listener that will get triggered when a change has been made to the user's account or an exception has occurred.
52 | * @return A RealTimeServerConnection that checks for a change to a user's account.
53 | */
54 | public RealTimeServerConnection getLongPollServerConnection(RealTimeServerConnection.OnChangeListener changeListener) {
55 | BoxRequestsEvent.EventRealTimeServerRequest request = new BoxRequestsEvent.EventRealTimeServerRequest(getEventsUrl(), mSession);
56 | return new RealTimeServerConnection(request,changeListener, mSession );
57 | }
58 |
59 |
60 |
61 | }
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | Contributing
2 | ============
3 |
4 | All contributions are welcome to this project.
5 |
6 | Contributor License Agreement
7 | -----------------------------
8 |
9 | Before a contribution can be merged into this project, please fill out
10 | the [Contributor License Agreement (CLA)](http://box.github.io/cla).
11 |
12 | How to contribute
13 | -----------------
14 |
15 | - **File an issue** - if you found a bug, want to request an
16 | enhancement, or want to implement something (bug fix or feature).
17 | - **Send a pull request** - if you want to contribute code. Please be
18 | sure to file an issue first.
19 |
20 | Pull request best practices
21 | ============
22 |
23 | We want to accept your pull requests. Please follow these steps:
24 |
25 | Step 1: File an issue
26 | ---------------------
27 |
28 | Before writing any code, please file an issue stating the problem you
29 | want to solve or the feature you want to implement. This allows us to
30 | give you feedback before you spend any time writing code. There may be a
31 | known limitation that can't be addressed, or a bug that has already been
32 | fixed in a different way. The issue allows us to communicate and figure
33 | out if it's worth your time to write a bunch of code for the project.
34 |
35 | Step 2: Fork this repository on GitHub
36 | -------------------------------------
37 |
38 | This will create your own copy of our repository.
39 |
40 | Step 3: Set the remote fetch origin
41 | -------------------------------
42 |
43 | The remote fetch origin is the project under the Box organization.
44 | Setting this will ensure you're pulling in the latest changes from the main repository.
45 |
46 | ```
47 | git remote set-url origin https://github.com/box/box-android-content-sdk.git
48 | ```
49 |
50 | ```
51 | git remote set-url origin --push https://github.com//box-android-content-sdk.git
52 | ```
53 |
54 |
55 | Step 4: Rebase
56 | --------------
57 |
58 | Before sending a pull request, rebase against origin, like thus:
59 |
60 | ```
61 | git fetch origin
62 | ```
63 | ```
64 | git pull --rebase
65 | ```
66 |
67 |
68 | This will add your changes on top of what's already in origin.
69 |
70 | Step 5: Run the tests
71 | ---------------------
72 |
73 | Make sure that all tests are passing before submitting a pull request.
74 |
75 | Step 6: Send the pull request
76 | -----------------------------
77 |
78 | Send the pull request from your fork to us. Be sure to include
79 | a description that lets us know what work you did.
80 |
81 | Keep in mind that we like to see one issue addressed per pull request,
82 | as this helps keep our git history clean so we can more easily track
83 | down issues.
84 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/java/com/box/androidsdk/content/models/BoxUploadEmail.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content.models;
2 |
3 | import android.text.TextUtils;
4 |
5 | import com.eclipsesource.json.JsonObject;
6 | import com.eclipsesource.json.JsonValue;
7 |
8 | import java.util.Locale;
9 | import java.util.Map;
10 |
11 | /**
12 | * Represents an email address that can be used to upload files to a folder on Box.
13 | */
14 | public class BoxUploadEmail extends BoxJsonObject {
15 |
16 | private static final long serialVersionUID = -1707312180661448119L;
17 | public static final String FIELD_ACCESS = "access";
18 | public static final String FIELD_EMAIL = "email";
19 |
20 | /**
21 | * Constructs a BoxUploadEmail with default settings.
22 | */
23 | public BoxUploadEmail() {
24 | }
25 |
26 | public BoxUploadEmail(JsonObject jsonObject) {
27 | super(jsonObject);
28 | }
29 |
30 | public static BoxUploadEmail createFromAccess(Access access) {
31 | JsonObject object = new JsonObject();
32 | if (access == null){
33 | object.add(FIELD_ACCESS, JsonValue.NULL);
34 | } else {
35 | object.add(FIELD_ACCESS, access.toString());
36 | }
37 | return new BoxUploadEmail(object);
38 | }
39 |
40 | /**
41 | * Gets the access level of this upload email.
42 | *
43 | * @return the access level of this upload email.
44 | */
45 | public Access getAccess() {
46 | return Access.fromString(getPropertyAsString(FIELD_ACCESS));
47 | }
48 |
49 | /**
50 | * Enumerates the possible access levels that can be set on an upload email.
51 | */
52 | public enum Access {
53 | /**
54 | * Anyone can send an upload to this email address.
55 | */
56 | OPEN("open"),
57 |
58 | /**
59 | * Only collaborators can send an upload to this email address.
60 | */
61 | COLLABORATORS("collaborators");
62 |
63 | private final String mValue;
64 |
65 | public static Access fromString(String text) {
66 | if (!TextUtils.isEmpty(text)) {
67 | for (Access e : Access.values()) {
68 | if (text.equalsIgnoreCase(e.toString())) {
69 | return e;
70 | }
71 | }
72 | }
73 | throw new IllegalArgumentException(String.format(Locale.ENGLISH, "No enum with text %s found", text));
74 | }
75 |
76 | private Access(String value) {
77 | this.mValue = value;
78 | }
79 |
80 | @Override
81 | public String toString() {
82 | return this.mValue;
83 | }
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/doc/AppUsers.md:
--------------------------------------------------------------------------------
1 | Developer's Edition (App Users)
2 | ==============
3 |
4 | Authentication
5 | ---------------------
6 | When using Developer's Edition (App Users), developers must implement AuthenticationRefreshProvider. It is recommended this implementation be set in the first line of the BoxAuthentication class in order to handle all sessions.
7 | ```java
8 | private final refreshProvider = new BoxAuthentication.AuthenticationRefreshProvider() {
9 | @Override
10 | public BoxAuthentication.BoxAuthenticationInfo refreshAuthenticationInfo(BoxAuthentication.BoxAuthenticationInfo info) throws BoxException {
11 | // Do things to retrieve updated access token from the previous info.
12 | return refreshedInfo;
13 | }
14 |
15 | @Override
16 | public boolean launchAuthUi(String userId, BoxSession session) {
17 | // return true if developer wishes to launch their own activity to interact with user for login.
18 | // Activity should call BoxAuthentication. BoxAuthentication.getInstance().onAuthenticated() or onAuthenticationFailure() as appropriate.
19 | // Make sure to use an application context here when starting your activity to avoid memory leaks.
20 |
21 | return true;
22 | }
23 | };
24 | BoxAuthentication.getInstance().setRefreshProvider(refreshProvider);
25 |
26 | ```
27 |
28 | Once set, sessions can be used normally. The first time launching your auth UI provided from the launchAuthUi method.
29 | When using App Users with our other SDKs, currently you MUST use this approach currently.
30 |
31 |
32 |
33 | ```java
34 |
35 | BoxSession session = new BoxSession(context);
36 | session.authenticate();
37 | ```
38 |
39 | Single-Session
40 | ------------------------
41 | You can also manage sessions without changing BoxAuthentication by using the following session constructor.
42 |
43 | ```java
44 | BoxAuthentication.BoxAuthenticationInfo info = new BoxAuthentication.BoxAuthenticationInfo();
45 | // Populate info with as much information known as possible. If the access token is not provided the refresh provider implementation's launchAuthUi method will be invoked.
46 | info.setAccessToken("the first access token");
47 |
48 | BoxSession session = new BoxSession(context, info, REFRESH_PROVIDER_IMPL);
49 | session.authenticate();
50 | ```
51 |
52 | Log all users out.
53 |
54 | ```java
55 | BoxAuthentication.getInstance().logoutAllUsers(context);
56 | ```
57 |
58 | Security
59 | ------------------------
60 | The SDK stores authentication information in shared preferences by default. It is recommended that you create your own implementation of `BoxAuthentication.AuthStorage` to provide additional security as needed. You can set the authentication storage as follows:
61 | ```java
62 | BoxAuthentication.getInstance().setAuthStorage(new CustomAuthStorage());
63 | ```
64 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/box-content-sdk/src/test/java/com/box/androidsdk/content/testUtil/PowerMock.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content.testUtil;
2 |
3 | import android.text.TextUtils;
4 |
5 | import com.box.androidsdk.content.requests.BoxHttpResponse;
6 | import com.box.androidsdk.content.requests.BoxRequest;
7 |
8 | import org.junit.Before;
9 | import org.junit.runner.RunWith;
10 | import org.mockito.invocation.InvocationOnMock;
11 | import org.mockito.stubbing.Answer;
12 | import org.powermock.api.mockito.PowerMockito;
13 | import org.powermock.core.classloader.annotations.PrepareForTest;
14 | import org.powermock.modules.junit4.PowerMockRunner;
15 |
16 | import java.io.ByteArrayInputStream;
17 | import java.io.ByteArrayOutputStream;
18 | import java.net.HttpURLConnection;
19 | import java.net.URL;
20 |
21 | import static org.mockito.Matchers.any;
22 |
23 | /**
24 | * Created by jholzer on 11/22/17.
25 | */
26 |
27 | @RunWith(PowerMockRunner.class)
28 | @PrepareForTest(TextUtils.class)
29 | public abstract class PowerMock {
30 |
31 | /**
32 | * Method to simplify mocking a 200 response with a sample json body
33 | * @param sampleJson
34 | * @throws Exception
35 | */
36 | protected static void mockSuccessResponseWithJson(String sampleJson) throws Exception {
37 | //Byte stream to capture the outputstream to the server
38 | ByteArrayOutputStream outputStream = new ByteArrayOutputStream(1024);
39 | URL u = PowerMockito.mock(URL.class);
40 | PowerMockito.whenNew(URL.class).withAnyArguments().thenReturn(u);
41 | HttpURLConnection huc = PowerMockito.mock(HttpURLConnection.class);
42 | PowerMockito.when(u.openConnection()).thenReturn(huc);
43 | PowerMockito.when(huc.getOutputStream()).thenReturn(outputStream);
44 | PowerMockito.when(huc.getContentType()).thenReturn(BoxRequest.ContentTypes.JSON.toString());
45 | PowerMockito.when(huc.getResponseCode()).thenReturn(200);
46 |
47 |
48 | //Mock Response with sample json
49 | BoxHttpResponse response = new BoxHttpResponse(huc);
50 | PowerMockito.when(response.getBody()).thenReturn(new ByteArrayInputStream(sampleJson.getBytes()));
51 | PowerMockito.whenNew(BoxHttpResponse.class).withAnyArguments().thenReturn(response);
52 | }
53 |
54 | @Before
55 | public void setup() {
56 | PowerMockito.mockStatic(TextUtils.class);
57 | PowerMockito.when(TextUtils.isEmpty(any(CharSequence.class))).thenAnswer(new Answer() {
58 | @Override
59 | public Boolean answer(InvocationOnMock invocation) throws Throwable {
60 | CharSequence a = (CharSequence) invocation.getArguments()[0];
61 | return !(a != null && a.length() > 0);
62 | }
63 | });
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/doc/Collaborations.md:
--------------------------------------------------------------------------------
1 | Collaborations
2 | ==============
3 |
4 | ###### Collaborations is a sophisticated mechanism for managing access to to folders. If you would like to give your users the ability to manage collaborations, we recommend using the Share SDK rather than trying to call these methods yourself. The Share SDK contains activities that allow users to manage folder collaborations.
5 |
6 | View Collaborators in a Folder
7 | ------------------------------
8 | ```java
9 | BoxApiFolder folderApi = new BoxApiFolder(session);
10 | BoxListCollaborations collaborations = folderApi.getCollaborationsRequest("folderId").send();
11 | ```
12 |
13 | Add a Collaborator to a Folder
14 | ------------------------------
15 | Add a collaborator by email address:
16 | ```java
17 | BoxApiCollaboration collabApi = new BoxApiCollaboration(session);
18 | BoxCollaboration collaboration = collabApi.getAddRequest("folderId", BoxCollaboration.Role.VIEWER, "test@user.com").send();
19 | ```
20 | Add a user:
21 | ```java
22 | BoxApiCollaboration collabApi = new BoxApiCollaboration(session);
23 | // You can either use an existing BoxUser object or create one from the user ID
24 | BoxUser user = BoxUser.createFromId("userId");
25 | BoxCollaboration collaboration = collabApi.getAddRequest("folderId", BoxCollaboration.Role.VIEWER, user).send();
26 | ```
27 | Add a group:
28 | ```java
29 | BoxApiCollaboration collabApi = new BoxApiCollaboration(session);
30 | // You can either use an existing BoxGroup object or create one from the group ID
31 | BoxGroup group = BoxGroup.createFromId("groupId");
32 | BoxCollaboration collaboration = collabApi.getAddRequest("folderId", BoxCollaboration.Role.VIEWER, group).send();
33 | ```
34 |
35 | Remove a Collaborator from a Folder
36 | ------------------------------
37 | ```java
38 | BoxApiCollaboration collabApi = new BoxApiCollaboration(session);
39 | collabApi.getDeleteRequest("collaborationId").send();
40 | ```
41 |
42 | Update an existing Collaboration
43 | --------------------------------
44 | ```java
45 | BoxApiCollaboration collabApi = new BoxApiCollaboration(session);
46 | BoxCollaboration updatedCollaboration = collabApi.getUpdateRequest("collaborationId").setNewRole(BoxCollaboration.Role.EDITOR).send();
47 | ```
48 |
49 | View Pending Collaborations for the Current User
50 | ---------------------------------------
51 | A "Pending Collaboration" represents a user who has not yet accepted the invitation to join a folder as a collaborator. Most users auto-accept invitations, but some do not. This method retrieves the collaboration invitations that the current user has not yet accepted.
52 | ```java
53 | BoxApiCollaboration collabApi = new BoxApiCollaboration(session);
54 | BoxIteratorCollaborations pendingCollabs = collabApi.getPendingCollaborationsRequest().send();
55 | ```
56 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/java/com/box/androidsdk/content/requests/MultiputResponseHandler.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content.requests;
2 |
3 | import com.box.androidsdk.content.BoxException;
4 | import com.box.androidsdk.content.models.BoxFile;
5 | import com.box.androidsdk.content.models.BoxIterator;
6 | import com.box.androidsdk.content.models.BoxIteratorBoxEntity;
7 | import com.box.androidsdk.content.models.BoxIteratorItems;
8 | import com.box.androidsdk.content.models.BoxObject;
9 |
10 | import java.net.HttpURLConnection;
11 |
12 | /**
13 | * A request handler that is designed to handle retry logic for a CommitUploadSession to give server
14 | * time to process all the parts.
15 | */
16 |
17 | public class MultiputResponseHandler extends BoxRequest.BoxRequestHandler {
18 |
19 | protected static final int DEFAULT_NUM_RETRIES = 2;
20 | protected static final int DEFAULT_MAX_WAIT_MILLIS = 90 * 1000;
21 |
22 | protected int mNumAcceptedRetries = 0;
23 | protected int mRetryAfterMillis = 1000;
24 |
25 | public MultiputResponseHandler(BoxRequestsFile.CommitUploadSession request) {
26 | super(request);
27 | }
28 |
29 |
30 | @Override
31 | public T onResponse(Class clazz, BoxHttpResponse response) throws IllegalAccessException, InstantiationException, BoxException {
32 | if (response.getResponseCode() == HttpURLConnection.HTTP_ACCEPTED) {
33 | try {
34 | // First attempt to use Retry-After header, all failures will eventually fall back to exponential backoff
35 | if (mNumAcceptedRetries < DEFAULT_NUM_RETRIES) {
36 | mNumAcceptedRetries++;
37 | mRetryAfterMillis = getRetryAfterFromResponse(response, 1);
38 | } else if (mRetryAfterMillis < DEFAULT_MAX_WAIT_MILLIS) {
39 | // Exponential back off with some randomness to avoid traffic spikes to server
40 | mRetryAfterMillis *= (1.5 + Math.random());
41 | } else {
42 | // Give up after the maximum retry time is exceeded.
43 | throw new BoxException.MaxAttemptsExceeded("Max wait time exceeded.", mNumAcceptedRetries);
44 | }
45 | Thread.sleep(mRetryAfterMillis);
46 | return (T) mRequest.send();
47 | } catch (InterruptedException e) {
48 | throw new BoxException(e.getMessage(), response);
49 | }
50 | } else {
51 | BoxIterator list = super.onResponse(BoxIteratorBoxEntity.class, response);
52 | return (T)list.get(0);
53 | }
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/java/com/box/androidsdk/content/models/BoxBookmark.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content.models;
2 |
3 | import com.box.androidsdk.content.BoxConstants;
4 | import com.eclipsesource.json.JsonObject;
5 |
6 | /**
7 | * Class that represents a bookmark on Box.
8 | */
9 | public class BoxBookmark extends BoxItem {
10 |
11 | private static final long serialVersionUID = 2628881847260043250L;
12 |
13 | public static final String TYPE = "web_link";
14 | public static final String FIELD_URL = "url";
15 | public static final String FIELD_COMMENT_COUNT = BoxConstants.FIELD_COMMENT_COUNT;
16 |
17 | public static final String[] ALL_FIELDS = new String[]{
18 | FIELD_TYPE,
19 | FIELD_ID,
20 | FIELD_SEQUENCE_ID,
21 | FIELD_ETAG,
22 | FIELD_NAME,
23 | FIELD_URL,
24 | FIELD_CREATED_AT,
25 | FIELD_MODIFIED_AT,
26 | FIELD_DESCRIPTION,
27 | FIELD_PATH_COLLECTION,
28 | FIELD_CREATED_BY,
29 | FIELD_MODIFIED_BY,
30 | FIELD_TRASHED_AT,
31 | FIELD_PURGED_AT,
32 | FIELD_OWNED_BY,
33 | FIELD_SHARED_LINK,
34 | FIELD_PARENT,
35 | FIELD_ITEM_STATUS,
36 | FIELD_PERMISSIONS,
37 | FIELD_COMMENT_COUNT,
38 | };
39 |
40 | /**
41 | * Constructs an empty BoxBookmark object.
42 | */
43 | public BoxBookmark() {
44 | super();
45 | }
46 |
47 | /**
48 | * Constructs a BoxBookmark with the provided map values.
49 | *
50 | * @param object JsonObject representing this class
51 | */
52 | public BoxBookmark(JsonObject object) {
53 | super(object);
54 | }
55 |
56 | /**
57 | * A convenience method to create an empty bookmark with just the id and type fields set. This allows
58 | * the ability to interact with the content sdk in a more descriptive and type safe manner
59 | *
60 | * @param bookmarkId the id of folder to create
61 | * @return an empty BoxBookmark object that only contains id and type information
62 | */
63 | public static BoxBookmark createFromId(String bookmarkId) {
64 | JsonObject object = new JsonObject();
65 | object.add(FIELD_ID, bookmarkId);
66 | object.add(FIELD_TYPE, TYPE);
67 | return new BoxBookmark(object);
68 | }
69 |
70 | /**
71 | * Gets the URL of the bookmark.
72 | *
73 | * @return the URL of the bookmark.
74 | */
75 | public String getUrl() {
76 | return getPropertyAsString(FIELD_URL);
77 | }
78 |
79 | /**
80 | * This always returns null as size doesn't make sense for bookmarks.
81 | *
82 | * @return null.
83 | */
84 | public Long getSize() {
85 | return null;
86 | }
87 |
88 | }
89 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/java/com/box/androidsdk/content/requests/BoxRequestsCollections.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content.requests;
2 |
3 | import com.box.androidsdk.content.BoxException;
4 | import com.box.androidsdk.content.BoxFutureTask;
5 | import com.box.androidsdk.content.models.BoxIteratorCollections;
6 | import com.box.androidsdk.content.models.BoxIteratorItems;
7 | import com.box.androidsdk.content.models.BoxSession;
8 |
9 | public class BoxRequestsCollections {
10 |
11 | /**
12 | * Request to get the available collections.
13 | */
14 | public static class GetCollections extends BoxRequestList implements BoxCacheableRequest {
15 | private static final long serialVersionUID = 8123965031279971506L;
16 |
17 | /**
18 | * Creates a get collections request with the default parameters.
19 | *
20 | * @param collectionsUrl URL of the collections endpoint.
21 | * @param session the authenticated session that will be used to make the request with.
22 | */
23 | public GetCollections(String collectionsUrl, BoxSession session) {
24 | super(BoxIteratorCollections.class, null, collectionsUrl, session);
25 | }
26 |
27 | @Override
28 | public BoxIteratorCollections sendForCachedResult() throws BoxException {
29 | return super.handleSendForCachedResult();
30 | }
31 |
32 | @Override
33 | public BoxFutureTask toTaskForCachedResult() throws BoxException {
34 | return super.handleToTaskForCachedResult();
35 | }
36 | }
37 |
38 | /**
39 | * Request to get a collection's items.
40 | */
41 | public static class GetCollectionItems extends BoxRequestList implements BoxCacheableRequest {
42 | private static final long serialVersionUID = 8123965031279971507L;
43 |
44 | /**
45 | * Creates a get collection items with the default parameters.
46 | *
47 | * @param id id of the collection
48 | * @param collectionItemsUrl URL of the collection items endpoint.
49 | * @param session the authenticated session that will be used to make the request with.
50 | */
51 | public GetCollectionItems(String id, String collectionItemsUrl, BoxSession session) {
52 | super(BoxIteratorItems.class, id, collectionItemsUrl, session);
53 | }
54 |
55 | @Override
56 | public BoxIteratorItems sendForCachedResult() throws BoxException {
57 | return handleSendForCachedResult();
58 | }
59 |
60 | @Override
61 | public BoxFutureTask toTaskForCachedResult() throws BoxException {
62 | return handleToTaskForCachedResult();
63 | }
64 | }
65 |
66 | }
67 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/java/com/box/androidsdk/content/requests/BoxHttpRequest.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content.requests;
2 |
3 | import com.box.androidsdk.content.BoxConfig;
4 | import com.box.androidsdk.content.listeners.ProgressListener;
5 |
6 | import java.io.IOException;
7 | import java.io.InputStream;
8 | import java.io.OutputStream;
9 | import java.net.HttpURLConnection;
10 | import java.net.URL;
11 |
12 | import javax.net.ssl.HttpsURLConnection;
13 |
14 | /**
15 | * Class that represents an HTTP request.
16 | */
17 | class BoxHttpRequest {
18 |
19 | protected final HttpURLConnection mUrlConnection;
20 | protected final ProgressListener mListener;
21 |
22 | /**
23 | * Constructs an HTTP request with the default parameters.
24 | *
25 | * @param url URL to connect to.
26 | * @param method method type for the HTTP request.
27 | * @param listener progress listener for a long-running API call.
28 | * @throws IOException
29 | */
30 | public BoxHttpRequest(URL url, BoxRequest.Methods method, ProgressListener listener) throws IOException {
31 | mUrlConnection = (HttpURLConnection) url.openConnection();
32 | mUrlConnection.setRequestMethod(method.toString());
33 | mListener = listener;
34 | // enables TLS 1.1 and 1.2 which is disabled by default on kitkat and below
35 | if (BoxConfig.ENABLE_TLS_FOR_PRE_20 && mUrlConnection instanceof HttpsURLConnection) {
36 | ((HttpsURLConnection) mUrlConnection).setSSLSocketFactory(new BoxRequest.TLSSSLSocketFactory());
37 | }
38 |
39 | }
40 |
41 |
42 | /**
43 | * Adds an HTTP header to the request.
44 | *
45 | * @param key the header key.
46 | * @param value the header value.
47 | * @return request with the updated header.
48 | */
49 | public BoxHttpRequest addHeader(String key, String value) {
50 | mUrlConnection.addRequestProperty(key, value);
51 | return this;
52 | }
53 |
54 | /**
55 | * Sets the body for the HTTP request to the contents of an InputStream.
56 | *
57 | * @param body InputStream to use for the contents of the body.
58 | * @return request with the updated body input stream.
59 | * @throws IOException
60 | */
61 | public BoxHttpRequest setBody(InputStream body) throws IOException {
62 | mUrlConnection.setDoOutput(true);
63 | OutputStream output = mUrlConnection.getOutputStream();
64 | int b = body.read();
65 | while (b != -1) {
66 | output.write(b);
67 | b = body.read();
68 | }
69 | output.close();
70 | return this;
71 | }
72 |
73 | /**
74 | * Returns the URL connection for the request.
75 | *
76 | * @return URL connection for the request.
77 | */
78 | public HttpURLConnection getUrlConnection() {
79 | return mUrlConnection;
80 | }
81 |
82 | }
83 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/res/layout/boxsdk_alert_dialog_text_entry.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
23 |
24 |
33 |
34 |
45 |
46 |
55 |
56 |
67 |
68 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/java/com/box/androidsdk/content/utils/ProgressOutputStream.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content.utils;
2 |
3 | import com.box.androidsdk.content.listeners.ProgressListener;
4 |
5 | import java.io.IOException;
6 | import java.io.OutputStream;
7 |
8 | /**
9 | * An {@link java.io.OutputStream} that can report the progress of writing to another OutputStream to a
10 | * {@link com.box.androidsdk.content.listeners.ProgressListener}.
11 | */
12 | public class ProgressOutputStream extends OutputStream {
13 | private final OutputStream stream;
14 | private final ProgressListener listener;
15 |
16 | private long total;
17 | private long totalWritten;
18 | private int progress;
19 |
20 | /**
21 | * Constructs a ProgressOutputStream that wraps another OutputStream.
22 | * @param stream the stream whose progress will be monitored.
23 | * @param listener the listener that will receive progress updates.
24 | * @param total the total number of bytes that are expected to be read from the stream.
25 | */
26 | public ProgressOutputStream(OutputStream stream, ProgressListener listener, long total) {
27 | this.stream = stream;
28 | this.listener = listener;
29 | this.total = total;
30 | }
31 |
32 | /**
33 | * Returns the total number of bytes expected to be read from the stream.
34 | *
35 | * @return the total number of bytes expected to be read from the stream.
36 | */
37 | public long getTotal() {
38 | return this.total;
39 | }
40 |
41 | /**
42 | * Sets the total number of bytes expected to be read from the stream.
43 | *
44 | * @param total the total number of bytes that are expected to be read from the stream.
45 | */
46 | public void setTotal(long total) {
47 | this.total = total;
48 | }
49 |
50 | @Override
51 | public void close() throws IOException {
52 | this.stream.close();
53 | super.close();
54 | }
55 |
56 | @Override
57 | public void flush() throws IOException {
58 | this.stream.flush();
59 | super.flush();
60 | }
61 |
62 | @Override
63 | public void write(byte[] b) throws IOException {
64 | this.stream.write(b);
65 | this.totalWritten += b.length;
66 | this.listener.onProgressChanged(this.totalWritten, this.total);
67 | }
68 |
69 | @Override
70 | public void write(byte[] b, int off, int len) throws IOException {
71 | this.stream.write(b, off, len);
72 | if (len < b.length) {
73 | this.totalWritten += len;
74 | } else {
75 | this.totalWritten += b.length;
76 | }
77 | this.listener.onProgressChanged(this.totalWritten, this.total);
78 | }
79 |
80 | @Override
81 | public void write(int b) throws IOException {
82 | this.stream.write(b);
83 | this.totalWritten++;
84 | this.listener.onProgressChanged(this.totalWritten, this.total);
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/java/com/box/androidsdk/content/BoxConfig.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content;
2 |
3 | import android.content.Context;
4 | import android.os.Build;
5 |
6 | public class BoxConfig {
7 |
8 | private static BoxCache mCache = null;
9 |
10 | /**
11 | * Flag for whether logging is enabled. This will log all requests and responses made by the SDK
12 | */
13 | public static boolean IS_LOG_ENABLED = false;
14 |
15 | /**
16 | * Flag for whether the app is currently run in debug mode. This is set by the {@link com.box.androidsdk.content.models.BoxSession}
17 | * object and is determined from the {@link android.content.pm.ApplicationInfo#FLAG_DEBUGGABLE}
18 | */
19 | public static boolean IS_DEBUG = false;
20 |
21 | /**
22 | * Client id used for the OAuth flow
23 | */
24 | public static String CLIENT_ID = null;
25 |
26 | /**
27 | * Client secret used for the OAuth flow
28 | */
29 | public static String CLIENT_SECRET = null;
30 |
31 | /**
32 | * Sets whether sessions should authentivate with the Box Application if available.
33 | */
34 | public static boolean ENABLE_BOX_APP_AUTHENTICATION = false;
35 |
36 | /**
37 | * The redirect url used with OAuth flow
38 | */
39 | public static String REDIRECT_URL = "https://app.box.com/static/sync_redirect.html";
40 |
41 | /**
42 | * Device name used for the OAuth flow and refreshing
43 | */
44 | public static String DEVICE_NAME = null;
45 |
46 | /**
47 | * Device id used for the OAuth flow and refreshing
48 | */
49 | public static String DEVICE_ID = null;
50 |
51 | /**
52 | * Application context to be used by box sessions when necessary to show ui.
53 | */
54 | public static Context APPLICATION_CONTEXT = null;
55 |
56 | /**
57 | * Sets the cache implementation that BoxRequests that implement {@link com.box.androidsdk.content.requests.BoxCacheableRequest}
58 | * will use when the fromCache flag is enabled
59 | *
60 | * @param cache the cache implementation to use
61 | */
62 | public static void setCache(BoxCache cache) {
63 | mCache = cache;
64 | }
65 |
66 | /**
67 | * Returns the cache implementation that has been set for the SDK
68 | *
69 | * @return the cache implementation
70 | */
71 | public static BoxCache getCache() {
72 | return mCache;
73 | }
74 |
75 | /**
76 | * Version string
77 | */
78 | public static String SDK_VERSION = "5.0.0";
79 |
80 | /**
81 | * Optional paramater for whether authentication should use
82 | * WindowManager.LayoutParams.FLAG_SECURE before loading UI.
83 | */
84 | public static boolean IS_FLAG_SECURE = false;
85 |
86 | /**
87 | * This config enables TLS 1.1 and 1.2 on kitkat and below versions which are disabled by default.
88 | */
89 | public static boolean ENABLE_TLS_FOR_PRE_20 = Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT_WATCH;
90 | }
91 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/java/com/box/androidsdk/content/requests/BoxRequestItemRestoreTrashed.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content.requests;
2 |
3 | import com.box.androidsdk.content.models.BoxSession;
4 | import com.box.androidsdk.content.models.BoxFolder;
5 | import com.box.androidsdk.content.models.BoxItem;
6 | import com.eclipsesource.json.JsonObject;
7 |
8 | import java.util.LinkedHashMap;
9 | import java.util.Map;
10 |
11 | /**
12 | * Abstract class that represents a request to restore a trashed item.
13 | *
14 | * @param type of BoxItem to restore from the trash.
15 | * @param type of BoxRequest that is being created.
16 | */
17 | abstract class BoxRequestItemRestoreTrashed> extends BoxRequestItem {
18 | public BoxRequestItemRestoreTrashed(Class clazz, String id, String requestUrl, BoxSession session) {
19 | super(clazz, id, requestUrl, session);
20 | mRequestMethod = Methods.POST;
21 | }
22 |
23 | /**
24 | * Returns the name currently set for the restored item, or null if not set.
25 | *
26 | * @return new name for the restored item.
27 | */
28 | public String getName() {
29 | return mBodyMap.containsKey(BoxItem.FIELD_NAME) ?
30 | (String) mBodyMap.get(BoxItem.FIELD_NAME) :
31 | null;
32 | }
33 |
34 | /**
35 | * Sets the new name for the restored item. If null, the restored item will keep its original name.
36 | *
37 | * @param name name for the restored item.
38 | * @return request with the updated name for the restored item.
39 | */
40 | public R setName(String name) {
41 | mBodyMap.put(BoxItem.FIELD_NAME, name);
42 | return (R) this;
43 | }
44 |
45 | /**
46 | * Returns the parent id currently set for the restored item, or null if not set.
47 | *
48 | * @return parent id for the restored item.
49 | */
50 | public String getParentId() {
51 | return mBodyMap.containsKey(BoxItem.FIELD_PARENT) ?
52 | ((BoxFolder) mBodyMap.get(BoxItem.FIELD_PARENT)).getId() :
53 | null;
54 | }
55 |
56 | /**
57 | * Sets the id of the parent folder for the restored item. If null, the restored item will be restored to its original parent folder.
58 | *
59 | * @param parentId id of the parent folder for the restored item.
60 | * @return request with the updated parent folder id.
61 | */
62 | public R setParentId(String parentId) {
63 | BoxFolder parentFolder = BoxFolder.createFromId(parentId);
64 | mBodyMap.put(BoxItem.FIELD_PARENT, parentFolder);
65 | return (R) this;
66 | }
67 |
68 | @Override
69 | protected void parseHashMapEntry(JsonObject jsonBody, Map.Entry entry) {
70 | if (entry.getKey().equals(BoxItem.FIELD_PARENT)) {
71 | jsonBody.add(entry.getKey(), parseJsonObject(entry.getValue()));
72 | return;
73 | }
74 | super.parseHashMapEntry(jsonBody, entry);
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/java/com/box/androidsdk/content/BoxApiComment.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content;
2 |
3 | import com.box.androidsdk.content.models.BoxSession;
4 | import com.box.androidsdk.content.requests.BoxRequestsComment;
5 |
6 | /**
7 | * Represents the API of the comment endpoint on Box. This class can be used to generate request objects
8 | * for each of the APIs exposed endpoints
9 | */
10 | public class BoxApiComment extends BoxApi {
11 |
12 | /**
13 | * Constructs a BoxApiComment with the provided BoxSession
14 | *
15 | * @param session authenticated session to use with the BoxApiComment
16 | */
17 | public BoxApiComment(BoxSession session) {
18 | super(session);
19 | }
20 |
21 | public static final String COMMENTS_ENDPOINT = "/comments";
22 |
23 | protected String getCommentsUrl() { return getBaseUri() + COMMENTS_ENDPOINT; }
24 | protected String getCommentInfoUrl(String id) { return String.format("%s/%s", getCommentsUrl(), id); }
25 |
26 | /**
27 | * Gets a request that retrieves information on a comment
28 | *
29 | * @param id id of comment to retrieve info on
30 | * @return request to get a comment's information
31 | */
32 | public BoxRequestsComment.GetCommentInfo getInfoRequest(String id) {
33 | BoxRequestsComment.GetCommentInfo request = new BoxRequestsComment.GetCommentInfo(id, getCommentInfoUrl(id), mSession);
34 | return request;
35 | }
36 |
37 | /**
38 | * Gets a request that adds a reply comment to a comment
39 | *
40 | * @param commentId id of the comment to reply to
41 | * @param message message for the comment that will be added
42 | * @return request to add a reply comment to a comment
43 | */
44 | public BoxRequestsComment.AddReplyComment getAddCommentReplyRequest(String commentId, String message) {
45 | BoxRequestsComment.AddReplyComment request = new BoxRequestsComment.AddReplyComment(commentId, message, getCommentsUrl(), mSession);
46 | return request;
47 | }
48 |
49 | /**
50 | * Gets a request that updates a comment's information
51 | *
52 | * @param id id of comment to update information on
53 | * @param newMessage new message for the comment
54 | * @return request to update a comment's information
55 | */
56 | public BoxRequestsComment.UpdateComment getUpdateRequest(String id, String newMessage) {
57 | BoxRequestsComment.UpdateComment request = new BoxRequestsComment.UpdateComment(id, newMessage, getCommentInfoUrl(id), mSession);
58 | return request;
59 | }
60 |
61 | /**
62 | * Gets a request that deletes a comment
63 | *
64 | * @param id id of comment to delete
65 | * @return request to delete a comment
66 | */
67 | public BoxRequestsComment.DeleteComment getDeleteRequest(String id) {
68 | BoxRequestsComment.DeleteComment request = new BoxRequestsComment.DeleteComment(id, getCommentInfoUrl(id), mSession);
69 | return request;
70 | }
71 |
72 |
73 | }
--------------------------------------------------------------------------------
/box-content-sdk/src/test/java/com/box/androidsdk/content/requests/BoxSearchRequestTest.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content.requests;
2 |
3 | import android.content.Context;
4 |
5 | import com.box.androidsdk.content.BoxApiSearch;
6 | import com.box.androidsdk.content.models.BoxIteratorItems;
7 | import com.box.androidsdk.content.testUtil.PowerMock;
8 | import com.box.androidsdk.content.testUtil.SessionUtil;
9 | import com.eclipsesource.json.JsonObject;
10 |
11 | import junit.framework.Assert;
12 |
13 | import org.junit.Test;
14 | import org.mockito.Mock;
15 | import org.powermock.core.classloader.annotations.PrepareForTest;
16 |
17 | /**
18 | * Tests for search requests
19 | */
20 |
21 |
22 |
23 | @PrepareForTest({ BoxHttpResponse.class, BoxHttpRequest.class, BoxRequest.class, BoxRequestsSearch.class})
24 | public class BoxSearchRequestTest extends PowerMock {
25 |
26 | @Mock
27 | Context mMockContext;
28 |
29 | @Test
30 | public void testSearch() throws Exception {
31 | final String expectedRequestUrl = "https://api.box.com/2.0/search";
32 | final String sampleSearchResultsJson = "{ \"total_count\": 1, \"entries\": [ { \"type\": \"file\", \"id\": \"172245607\", \"sequence_id\": \"1\", \"etag\": \"1\", \"sha1\": \"f89d97c5eea0a68e2cec911s932eca34a52355d2\", \"name\": \"Box for Sales - Empowering Your Mobile Worker White paper 2pg (External).pdf\", \"description\": \"This is old and needs to be updated - but general themes still apply\", \"size\": 408979, \"path_collection\": { \"total_count\": 2, \"entries\": [ { \"type\": \"folder\", \"id\": \"0\", \"sequence_id\": null, \"etag\": null, \"name\": \"All Files\" }, { \"type\": \"folder\", \"id\": \"2150506\", \"sequence_id\": \"1\", \"etag\": \"1\", \"name\": \"Marketing Active Work\" } ] }, \"created_at\": \"2014-05-17T12:59:45-07:00\", \"modified_at\": \"2014-05-17T13:00:20-07:00\", \"trashed_at\": null, \"purged_at\": null, \"content_created_at\": \"2014-05-17T12:58:58-07:00\", \"content_modified_at\": \"2014-05-17T12:58:58-07:00\", \"created_by\": { \"type\": \"user\", \"id\": \"19551097\", \"name\": \"Ted Blosser\", \"login\": \"ted@box.com\" }, \"modified_by\": { \"type\": \"user\", \"id\": \"19551097\", \"name\": \"Ted Blosser\", \"login\": \"ted@box.com\" }, \"owned_by\": { \"type\": \"user\", \"id\": \"19551097\", \"name\": \"Ted Blosser\", \"login\": \"ted@box.com\" }, \"shared_link\": null, \"parent\": { \"type\": \"folder\", \"id\": \"2150506\", \"sequence_id\": \"1\", \"etag\": \"1\", \"name\": \"Marketing Active Work\" }, \"item_status\": \"active\" } ], \"limit\": 30, \"offset\": 0 }";
33 | BoxApiSearch searchApi = new BoxApiSearch(SessionUtil.newMockBoxSession(mMockContext));
34 | BoxRequestsSearch.Search searchRequest = searchApi.getSearchRequest("query");
35 |
36 | mockSuccessResponseWithJson(sampleSearchResultsJson);
37 | BoxIteratorItems searchResults = searchRequest.send();
38 |
39 | Assert.assertEquals(expectedRequestUrl, searchRequest.mRequestUrlString);
40 | Assert.assertEquals(JsonObject.readFrom(sampleSearchResultsJson), searchResults.toJsonObject());
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/java/com/box/androidsdk/content/models/BoxExpiringEmbedLinkFile.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content.models;
2 |
3 | import android.text.TextUtils;
4 |
5 | import com.box.androidsdk.content.BoxConstants;
6 | import com.eclipsesource.json.JsonObject;
7 |
8 | import java.util.Date;
9 |
10 | /**
11 | * Class that represents a file on Box that has an expiring embed link.
12 | */
13 | public class BoxExpiringEmbedLinkFile extends BoxFile {
14 |
15 | private static final long serialVersionUID = -4732748896287486795L;
16 |
17 | public static final String FIELD_EMBED_LINK = "expiring_embed_link";
18 | protected static final String FIELD_EMBED_LINK_CREATION_TIME = "expiring_embed_link_creation_time";
19 |
20 |
21 | /**
22 | * Constructs an empty BoxExpiringEmbedLinkFile object.
23 | */
24 | public BoxExpiringEmbedLinkFile() {
25 | super();
26 | }
27 |
28 |
29 | /**
30 | * Constructs a BoxExpiringEmbedLinkFile with the provided map values
31 | *
32 | * @param object JsonObject representing this class
33 | */
34 | public BoxExpiringEmbedLinkFile(JsonObject object) {
35 | super(object);
36 | }
37 |
38 | @Override
39 | public void createFromJson(String json) {
40 | super.createFromJson(json);
41 | setUrlCreationTime();
42 | }
43 |
44 | /**
45 | * Gets the expiring embed link of the file. The URL will expire after 60 seconds and the preview session will expire after 60 minutes
46 | *
47 | * @return the expiring embed link of the file.
48 | */
49 | public BoxEmbedLink getEmbedLink() {
50 | return getPropertyAsJsonObject(BoxJsonObject.getBoxJsonObjectCreator(BoxEmbedLink.class), FIELD_EMBED_LINK);
51 | }
52 |
53 | /**
54 | * This is the System.currentTimeMillis from the device when the server response was first parsed.
55 | * @return the System.currentTimeMillis from the device when the server response was first parsed
56 | */
57 | public Long getUrlCreationTime(){
58 | return getPropertyAsLong(FIELD_EMBED_LINK_CREATION_TIME);
59 | }
60 |
61 | private void setUrlCreationTime(){
62 | set(FIELD_EMBED_LINK_CREATION_TIME, System.currentTimeMillis());
63 | }
64 |
65 | /**
66 | * Convenience method to check if 60 seconds has passed since the time this link was created.
67 | * @return false if creation time is less than 60 seconds, true otherwise.
68 | */
69 | public boolean isEmbedLinkUrlExpired(){
70 | Long urlCreationTime = getUrlCreationTime();
71 | if (urlCreationTime == null){
72 | return true;
73 | }
74 | return (System.currentTimeMillis() - urlCreationTime) < (60 * 1000);
75 | }
76 |
77 | /**
78 | * Convenience method to check if 60 minutes has passed since the time this link was created.
79 | * @return false if creation time is less than 60 minutes, true otherwise.
80 | */
81 | public boolean isPreviewSessionExpired(){
82 | Long urlCreationTime = getUrlCreationTime();
83 | if (urlCreationTime == null){
84 | return true;
85 | }
86 | return (System.currentTimeMillis() - urlCreationTime) < (60 * 60 * 1000);
87 | }
88 |
89 |
90 | }
--------------------------------------------------------------------------------
/box-content-sdk/src/main/java/com/box/androidsdk/content/requests/BoxRequestItemCopy.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content.requests;
2 |
3 | import com.box.androidsdk.content.models.BoxSession;
4 | import com.box.androidsdk.content.models.BoxFolder;
5 | import com.box.androidsdk.content.models.BoxItem;
6 | import com.eclipsesource.json.JsonObject;
7 |
8 | import java.util.LinkedHashMap;
9 | import java.util.Map;
10 |
11 | /**
12 | * Abstract class that represents a request to copy a BoxItem.
13 | *
14 | * @param type of BoxItem that will be returned in the response.
15 | * @param type of BoxRequest that is being created.
16 | */
17 | abstract class BoxRequestItemCopy> extends BoxRequestItem {
18 |
19 | /**
20 | * Constructs a box item copy request with the default parameters.
21 | *
22 | * @param clazz class of the response object.
23 | * @param id id of the item to copy.
24 | * @param parentId id of the parent folder for the copy of the item.
25 | * @param requestUrl URL for the copy endpoint to use.
26 | * @param session the authenticated session that will be used to make the request with.
27 | */
28 | public BoxRequestItemCopy(Class clazz, String id, String parentId, String requestUrl, BoxSession session) {
29 | super(clazz, id, requestUrl, session);
30 | mRequestMethod = Methods.POST;
31 | setParentId(parentId);
32 | }
33 |
34 | /**
35 | * Returns the name currently set for the item copy.
36 | * @return name for the item copy, or null if not set
37 | */
38 | public String getName() {
39 | return mBodyMap.containsKey(BoxItem.FIELD_NAME) ?
40 | (String) mBodyMap.get(BoxItem.FIELD_NAME) :
41 | null;
42 | }
43 |
44 | /**
45 | * Sets the name used in the request for the item copy.
46 | *
47 | * @param name name for the copy of the item.
48 | * @return request with the updated name.
49 | */
50 | public R setName(String name) {
51 | mBodyMap.put(BoxItem.FIELD_NAME, name);
52 | return (R) this;
53 | }
54 |
55 | /**
56 | * Returns the parent id currently set for the item copy.
57 | *
58 | * @return id of the parent folder for the item copy.
59 | */
60 | public String getParentId() {
61 | return mBodyMap.containsKey(BoxItem.FIELD_PARENT) ?
62 | ((BoxFolder) mBodyMap.get(BoxItem.FIELD_PARENT)).getId() :
63 | null;
64 | }
65 |
66 | /**
67 | * Sets the parent id used in the request for the item copy.
68 | *
69 | * @param parentId id of the parent folder for the item copy.
70 | * @return request with the updated parent id.
71 | */
72 | public R setParentId(String parentId) {
73 | BoxFolder parentFolder = BoxFolder.createFromId(parentId);
74 | mBodyMap.put(BoxItem.FIELD_PARENT, parentFolder);
75 | return (R) this;
76 | }
77 |
78 | @Override
79 | protected void parseHashMapEntry(JsonObject jsonBody, Map.Entry entry) {
80 | if (entry.getKey().equals(BoxItem.FIELD_PARENT)) {
81 | jsonBody.add(entry.getKey(), parseJsonObject(entry.getValue()));
82 | return;
83 | }
84 | super.parseHashMapEntry(jsonBody, entry);
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/java/com/box/androidsdk/content/models/BoxArray.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content.models;
2 |
3 | import com.eclipsesource.json.JsonArray;
4 |
5 | import java.util.ArrayList;
6 | import java.util.Collection;
7 | import java.util.Iterator;
8 | import java.util.List;
9 |
10 | /**
11 | * A collection that contains BoxJsonObject items
12 | *
13 | * @param the type of elements in this partial collection.
14 | */
15 | public class BoxArray implements Collection {
16 |
17 | protected final Collection collection = new ArrayList();
18 |
19 | public BoxArray() {
20 | super();
21 | }
22 |
23 | public String toJson() {
24 | JsonArray array = new JsonArray();
25 | for (int i = 0; i < size(); i++) {
26 | array.add(get(i).toJsonObject());
27 | }
28 | return array.toString();
29 | }
30 |
31 | @Override
32 | public boolean add(E e) {
33 | return this.collection.add(e);
34 | }
35 |
36 | @Override
37 | public boolean addAll(Collection extends E> c) {
38 | return this.collection.addAll(c);
39 | }
40 |
41 | @Override
42 | public void clear() {
43 | this.collection.clear();
44 | }
45 |
46 | @Override
47 | public boolean contains(Object o) {
48 | return this.collection.contains(o);
49 | }
50 |
51 | @Override
52 | public boolean containsAll(Collection> c) {
53 | return this.collection.containsAll(c);
54 | }
55 |
56 | @Override
57 | public boolean equals(Object o) {
58 | return this.collection.equals(o);
59 | }
60 |
61 | @Override
62 | public int hashCode() {
63 | return this.collection.hashCode();
64 | }
65 |
66 | @Override
67 | public boolean isEmpty() {
68 | return this.collection.isEmpty();
69 | }
70 |
71 | @Override
72 | public Iterator iterator() {
73 | return this.collection.iterator();
74 | }
75 |
76 | @Override
77 | public boolean remove(Object o) {
78 | return this.collection.remove(o);
79 | }
80 |
81 | @Override
82 | public boolean removeAll(Collection> c) {
83 | return this.collection.removeAll(c);
84 | }
85 |
86 | @Override
87 | public boolean retainAll(Collection> c) {
88 | return this.collection.retainAll(c);
89 | }
90 |
91 | @Override
92 | public int size() {
93 | return this.collection.size();
94 | }
95 |
96 | @Override
97 | public Object[] toArray() {
98 | return this.collection.toArray();
99 | }
100 |
101 | @Override
102 | public T[] toArray(T[] a) {
103 | return this.collection.toArray(a);
104 | }
105 |
106 | public E get(int index) {
107 | if (collection instanceof List) {
108 | return (E) ((List) collection).get(index);
109 | }
110 | if (index < 0) {
111 | throw new IndexOutOfBoundsException();
112 | }
113 | Iterator iterator = iterator();
114 | int i = 0;
115 | while (iterator.hasNext()) {
116 | if (index == i) {
117 | return iterator.next();
118 | }
119 | iterator.next();
120 | }
121 | throw new IndexOutOfBoundsException();
122 | }
123 | }
124 |
--------------------------------------------------------------------------------
/maven_push.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'maven'
2 | apply plugin: 'signing'
3 |
4 | def isReleaseBuild() {
5 | return project.version.contains("SNAPSHOT") == false
6 | }
7 |
8 | def sonatypeRepositoryUrl
9 | if (isReleaseBuild()) {
10 | sonatypeRepositoryUrl = hasProperty('RELEASE_REPOSITORY_URL') ? RELEASE_REPOSITORY_URL
11 | : "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
12 | } else {
13 | sonatypeRepositoryUrl = hasProperty('SNAPSHOT_REPOSITORY_URL') ? SNAPSHOT_REPOSITORY_URL
14 | : "https://oss.sonatype.org/content/repositories/snapshots"
15 |
16 | }
17 |
18 | def repositoryUsername = hasProperty('SONATYPE_USER') ? SONATYPE_USER : System.getenv('SONATYPE_USER');
19 | def repositoryPassword = hasProperty('SONATYPE_PASS') ? SONATYPE_PASS : System.getenv('SONATYPE_PASS');
20 |
21 | afterEvaluate { project ->
22 | uploadArchives {
23 | repositories {
24 | mavenDeployer {
25 | beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
26 |
27 | pom.artifactId = POM_ARTIFACT_ID
28 |
29 | repository(url: sonatypeRepositoryUrl) {
30 | authentication(userName: repositoryUsername, password: repositoryPassword)
31 | }
32 |
33 | pom.project {
34 | name POM_NAME
35 | packaging POM_PACKAGING
36 | description "Box Android SDK"
37 | url "https://github.com/box/box-android-sdk"
38 |
39 | scm {
40 | url "https://github.com/box/box-android-sdk"
41 | connection "scm:git@github.com:box/box-android-sdk.git"
42 | }
43 |
44 | licenses {
45 | license {
46 | name "The Apache Software License, Version 2.0"
47 | url "http://www.apache.org/licenses/LICENSE-2.0.txt"
48 | distribution "repo"
49 | }
50 | }
51 |
52 | developers {
53 | developer {
54 | id repositoryUsername
55 | name "Box Android Team"
56 | }
57 | }
58 | }
59 | }
60 | }
61 | }
62 |
63 | signing {
64 | required { isReleaseBuild() && gradle.taskGraph.hasTask("uploadArchives") }
65 | sign configurations.archives
66 | }
67 |
68 | task androidJavadocs(type: Javadoc) {
69 | source = android.sourceSets.main.java.srcDirs
70 | classpath += project.files(android.getBootClasspath())
71 | classpath += files(android.libraryVariants.collect { variant ->
72 | variant.javaCompile.classpath.files
73 | })
74 | }
75 |
76 | task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {
77 | classifier = 'javadoc'
78 | //basename = artifact_id
79 | from androidJavadocs.destinationDir
80 | }
81 |
82 | task androidSourcesJar(type: Jar) {
83 | classifier = 'sources'
84 | //basename = artifact_id
85 | from android.sourceSets.main.java.srcDirs
86 | }
87 |
88 | artifacts {
89 | //archives packageReleaseJar
90 | archives androidSourcesJar
91 | archives androidJavadocsJar
92 | }
93 | }
94 |
--------------------------------------------------------------------------------
/box-content-sdk/src/test/java/com/box/androidsdk/content/models/BoxCommentTest.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content.models;
2 |
3 | import com.box.androidsdk.content.testUtil.DateUtil;
4 | import com.box.androidsdk.content.testUtil.PowerMock;
5 | import com.box.androidsdk.content.utils.BoxDateFormat;
6 | import com.eclipsesource.json.JsonObject;
7 |
8 | import org.junit.Assert;
9 | import org.junit.Test;
10 |
11 | import java.util.Date;
12 |
13 |
14 | /**
15 | * Test BoxComment model
16 | */
17 |
18 | public class BoxCommentTest extends PowerMock {
19 |
20 | @Test
21 | public void testConstructorNoParameter() {
22 | // given
23 |
24 | // when
25 | BoxComment comment = new BoxComment();
26 | Date createdAt = comment.getCreatedAt();
27 | BoxUser createdBy = comment.getCreatedBy();
28 | Boolean isReply = comment.getIsReplyComment();
29 | BoxItem item = comment.getItem();
30 | String message = comment.getMessage();
31 | Date modifiedAt = comment.getModifiedAt();
32 | String taggedMessage = comment.getTaggedMessage();
33 |
34 | // then
35 | Assert.assertNull(createdAt);
36 | Assert.assertNull(createdBy);
37 | Assert.assertNull(isReply);
38 | Assert.assertNull(item);
39 | Assert.assertNull(message);
40 | Assert.assertNull(modifiedAt);
41 | Assert.assertNull(taggedMessage);
42 | }
43 |
44 | @Test
45 | public void testConstructorWithJsonObjectParameter() {
46 | // given
47 | String expectedType = "comment";
48 | Date expectedCreatedAt = new Date();
49 | Date expectedModifiedAt = new Date();
50 | Boolean expectedIsReplyComment = false;
51 | String expectedMessage = "These tigers are cool!";
52 | String expectedTaggedMessage = "These tigers are cool!";
53 | BoxUser expectedCreatedBy = BoxUser.createFromId("1");
54 | BoxItem expectedItem = BoxFile.createFromId("1");
55 |
56 | String commentJson = "{" +
57 | "\"type\":\"" + expectedType + "\"," +
58 | "\"is_reply_comment\":" + expectedIsReplyComment + "," +
59 | "\"message\":\"" + expectedMessage + "\"," +
60 | "\"tagged_message\":\"" + expectedTaggedMessage + "\"," +
61 | "\"created_by\":" + expectedCreatedBy.toJson() + "," +
62 | "\"created_at\":\"" + BoxDateFormat.format(expectedCreatedAt) + "\"," +
63 | "\"modified_at\":\"" + BoxDateFormat.format(expectedModifiedAt) + "\"," +
64 | "\"item\":" + expectedItem.toJson() + "}";
65 |
66 | JsonObject jsonObj = JsonObject.readFrom(commentJson);
67 |
68 | // when
69 | BoxComment comment = new BoxComment(jsonObj);
70 |
71 | // then
72 | Assert.assertEquals(expectedType, comment.getType());
73 | DateUtil.assertSameDateSecondPrecision(expectedCreatedAt, comment.getCreatedAt());
74 | DateUtil.assertSameDateSecondPrecision(expectedModifiedAt, comment.getModifiedAt());
75 | Assert.assertEquals(expectedMessage, comment.getMessage());
76 | Assert.assertEquals(expectedCreatedBy, comment.getCreatedBy());
77 | Assert.assertEquals(expectedTaggedMessage, comment.getTaggedMessage());
78 | Assert.assertEquals(expectedItem, comment.getItem());
79 | Assert.assertEquals(expectedIsReplyComment, comment.getIsReplyComment());
80 | }
81 |
82 |
83 | }
84 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/java/com/box/androidsdk/content/BoxFutureTask.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content;
2 |
3 | import java.util.ArrayList;
4 | import java.util.concurrent.Callable;
5 | import java.util.concurrent.CancellationException;
6 | import java.util.concurrent.ExecutionException;
7 | import java.util.concurrent.FutureTask;
8 |
9 | import com.box.androidsdk.content.models.BoxObject;
10 | import com.box.androidsdk.content.requests.BoxRequest;
11 | import com.box.androidsdk.content.requests.BoxResponse;
12 |
13 | /**
14 | * A task that can be executed asynchronously to fetch results. This is generally created using
15 | * {@link BoxRequest#toTask()}
16 | *
17 | * @param the BoxObject result of the request
18 | */
19 | public class BoxFutureTask extends FutureTask> {
20 |
21 | protected final BoxRequest mRequest;
22 | protected ArrayList> mCompletedListeners = new ArrayList>();
23 |
24 | /**
25 | * Creates an instance of a task that can be executed asynchronously
26 | *
27 | * @param clazz the class of the return type
28 | * @param request the original request that was used to create the future task
29 | */
30 | public BoxFutureTask(final Class clazz, final BoxRequest request) {
31 | super(new Callable>() {
32 |
33 | @Override
34 | public BoxResponse call() throws Exception {
35 | E ret = null;
36 | Exception ex = null;
37 | try {
38 | ret = (E) request.send();
39 | } catch (Exception e) {
40 | ex = e;
41 | }
42 | return new BoxResponse(ret, ex, request);
43 | }
44 | });
45 | mRequest = request;
46 | }
47 |
48 | /**
49 | * Protected constructor for BoxFutureTask so that child classes can provide their own callable
50 | * implementation
51 | *
52 | * @param callable what will be executed when the future task is run
53 | * @param request the original request that the future task was created from
54 | */
55 | protected BoxFutureTask(final Callable> callable, final BoxRequest request) {
56 | super(callable);
57 | mRequest = request;
58 | }
59 |
60 | @Override
61 | protected synchronized void done() {
62 | BoxResponse response = null;
63 | Exception ex = null;
64 | try {
65 | response = this.get();
66 | } catch (InterruptedException e) {
67 | ex = e;
68 | } catch (ExecutionException e) {
69 | ex = e;
70 | } catch (CancellationException e) {
71 | ex = e;
72 | }
73 |
74 | if (ex != null) {
75 | response = new BoxResponse(null, new BoxException("Unable to retrieve response from FutureTask.", ex), mRequest);
76 | }
77 |
78 | ArrayList> listener = mCompletedListeners;
79 | for (OnCompletedListener l : listener) {
80 | l.onCompleted(response);
81 | }
82 | }
83 |
84 | @SuppressWarnings("unchecked")
85 | public synchronized BoxFutureTask addOnCompletedListener(OnCompletedListener listener) {
86 | mCompletedListeners.add(listener);
87 | return this;
88 | }
89 |
90 | public interface OnCompletedListener {
91 |
92 | void onCompleted(BoxResponse response);
93 | }
94 |
95 | }
96 |
--------------------------------------------------------------------------------
/box-content-sdk/src/main/java/com/box/androidsdk/content/requests/BoxRequestBatch.java:
--------------------------------------------------------------------------------
1 | package com.box.androidsdk.content.requests;
2 |
3 | import com.box.androidsdk.content.BoxException;
4 | import com.box.androidsdk.content.BoxFutureTask;
5 | import com.box.androidsdk.content.models.BoxObject;
6 |
7 | import java.util.ArrayList;
8 | import java.util.concurrent.ExecutionException;
9 | import java.util.concurrent.ExecutorService;
10 | import java.util.concurrent.ThreadPoolExecutor;
11 |
12 | /**
13 | * Batch request class that allows the ability to send multiple BoxRequests through an executor and
14 | * return a batch response object that contains all of the response information for each individual request
15 | *
16 | * Requests will run in parallel if Executor is set by caller otherwise requests will run sequentially.
17 | */
18 | public class BoxRequestBatch extends BoxRequest {
19 | private static final long serialVersionUID = 8123965031279971500L;
20 | private ExecutorService mExecutor;
21 |
22 | protected ArrayList mRequests = new ArrayList();
23 |
24 | /**
25 | * Initializes a new BoxRequestBatch
26 | */
27 | public BoxRequestBatch() {
28 | super(BoxResponseBatch.class, null, null);
29 | mExecutor = null;
30 | }
31 |
32 | /**
33 | * Requests will run in parallel if Executor is set by caller otherwise requests will run sequentially.
34 | * @param executor executor used to execute this request in parallel
35 | * @return current request
36 | */
37 | public BoxRequestBatch setExecutor(ExecutorService executor) {
38 | mExecutor = executor;
39 | return this;
40 | }
41 |
42 | /**
43 | * Adds a BoxRequest to the batch
44 | *
45 | * @param request the BoxRequest to add
46 | * @return the batch request
47 | */
48 | public BoxRequestBatch addRequest(BoxRequest request) {
49 | mRequests.add(request);
50 | return this;
51 | }
52 |
53 | @Override
54 | public BoxResponseBatch onSend() throws BoxException {
55 | BoxResponseBatch responses = new BoxResponseBatch();
56 |
57 | if (mExecutor != null) {
58 | ArrayList> tasks = new ArrayList>();
59 | for (BoxRequest req : mRequests) {
60 | BoxFutureTask task = req.toTask();
61 | mExecutor.submit(task);
62 | tasks.add(task);
63 | }
64 |
65 | for (BoxFutureTask task : tasks) {
66 | try {
67 | BoxResponse response = task.get();
68 | responses.addResponse(response);
69 | } catch (InterruptedException e) {
70 | throw new BoxException(e.getMessage(), e);
71 | } catch (ExecutionException e) {
72 | throw new BoxException(e.getMessage(), e);
73 | }
74 | }
75 | }
76 | else {
77 | for (BoxRequest req : mRequests) {
78 | BoxObject value = null;
79 | Exception ex = null;
80 | try {
81 | value = req.send();
82 | } catch (Exception e) {
83 | ex = e;
84 | }
85 |
86 | BoxResponse response = new BoxResponse(value, ex, req);
87 | responses.addResponse(response);
88 | }
89 | }
90 |
91 | return responses;
92 | }
93 | }
94 |
--------------------------------------------------------------------------------