com.dropbox.client2.DropboxAPI Java Examples

The following examples show how to use com.dropbox.client2.DropboxAPI. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UploadFile.java    From BLEConnect with GNU General Public License v2.0 6 votes vote down vote up
public UploadFile(Context context, DropboxAPI<?> api, String dropboxPath,
        File file) {
    // We set the context this way so we don't accidentally leak activities
    mContext = context.getApplicationContext();

    mFileLen = file.length();
    mApi = api;
    mPath = dropboxPath;
    mFile = file;

    mDialog = new ProgressDialog(context);
    mDialog.setMax(100);
    mDialog.setMessage("Uploading " + file.getName());
    mDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    mDialog.setProgress(0);
    mDialog.setButton("Cancel", new OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            // This will cancel the putFile operation
            mRequest.abort();
        }
    });
    mDialog.show();
}
 
Example #2
Source File: UploadFile.java    From BLEConnect with GNU General Public License v2.0 6 votes vote down vote up
public UploadFile(Context context, DropboxAPI<?> api, String dropboxPath,
        File file) {
    // We set the context this way so we don't accidentally leak activities
    mContext = context.getApplicationContext();

    mFileLen = file.length();
    mApi = api;
    mPath = dropboxPath;
    mFile = file;

    mDialog = new ProgressDialog(context);
    mDialog.setMax(100);
    mDialog.setMessage("Uploading " + file.getName());
    mDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    mDialog.setProgress(0);
    mDialog.setButton("Cancel", new OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            // This will cancel the putFile operation
            mRequest.abort();
        }
    });
    mDialog.show();
}
 
Example #3
Source File: DropboxFileDownloaderTest.java    From endpoints-codelab-android with GNU General Public License v3.0 6 votes vote down vote up
public void testBothFilesMissing() {
    DropboxAPI<?> dropboxapi = new DropboxAPIStub() {
        public DropboxAPI.Entry metadata(String arg0, int arg1,
                String arg2, boolean arg3, String arg4)
                throws DropboxException {
            throw notFoundException();
        }
    };

    DropboxFileDownloader downloader = new DropboxFileDownloader(
            dropboxapi, dropboxFiles2);

    downloader.pullFiles();
    assertEquals("Status should be SUCCESS", DropboxFileStatus.SUCCESS,
            downloader.getStatus());
    assertEquals("Should have 2 files", 2, downloader.getFiles().size());
    assertEquals("Status should be NOT_FOUND", DropboxFileStatus.NOT_FOUND,
            dbFile1.getStatus());
    assertEquals("Status should be NOT_FOUND", DropboxFileStatus.NOT_FOUND,
            dbFile2.getStatus());
}
 
Example #4
Source File: DropboxSyncService.java    From narrate-android with Apache License 2.0 6 votes vote down vote up
private void initialize(String token) {
    LogUtil.log(getClass().getSimpleName(), "initialize()");

    AppKeyPair appKeys = new AppKeyPair(APP_KEY, APP_SECRET);
    AndroidAuthSession session = new AndroidAuthSession(appKeys, ACCESS_TYPE);

    mDBApi = new DropboxAPI<>(session);

    if ( token == null )
        token = Settings.getDropboxSyncToken();

    if ( token != null )
        mDBApi.getSession().setOAuth2AccessToken(token);

    if (!doesFolderExist(getBaseFilePath())) {
        try {
            createFileStructure();
        } catch (DropboxException e) {
            e.printStackTrace();
        }
    }
}
 
Example #5
Source File: DropboxFileDownloaderTest.java    From endpoints-codelab-android with GNU General Public License v3.0 6 votes vote down vote up
public void testRemoteFileDeleted() {
    DropboxAPI<?> dropboxapi = new DropboxAPIStub() {
        public DropboxAPI.Entry metadata(String arg0, int arg1,
                String arg2, boolean arg3, String arg4)
                throws DropboxException {
            return create_metadata(remoterev1, true);
        }
    };

    DropboxFileDownloader downloader = new DropboxFileDownloader(
            dropboxapi, dropboxFiles1);

    downloader.pullFiles();
    assertEquals("Status should be SUCCESS", DropboxFileStatus.SUCCESS,
            downloader.getStatus());
    assertEquals("Should have 1 file", 1, downloader.getFiles().size());
    assertEquals("Status should be NOT_FOUND", DropboxFileStatus.NOT_FOUND,
            dbFile1.getStatus());
}
 
Example #6
Source File: DropboxFileDownloaderTest.java    From endpoints-codelab-android with GNU General Public License v3.0 6 votes vote down vote up
public void testRemoteFileMissing() {
    DropboxAPI<?> dropboxapi = new DropboxAPIStub() {
        public DropboxAPI.Entry metadata(String arg0, int arg1,
                String arg2, boolean arg3, String arg4)
                throws DropboxException {
            throw notFoundException();
        }
    };

    DropboxFileDownloader downloader = new DropboxFileDownloader(
            dropboxapi, dropboxFiles1);

    downloader.pullFiles();
    assertEquals("Status should be SUCCESS", DropboxFileStatus.SUCCESS,
            downloader.getStatus());
    assertEquals("Should have 1 file", 1, downloader.getFiles().size());
    assertEquals("Status should be NOT_FOUND", DropboxFileStatus.NOT_FOUND,
            dbFile1.getStatus());
}
 
Example #7
Source File: DropboxAPIStub.java    From endpoints-codelab-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public com.dropbox.client2.DropboxAPI.DropboxFileInfo getThumbnail(
        String arg0, OutputStream arg1,
        com.dropbox.client2.DropboxAPI.ThumbSize arg2,
        com.dropbox.client2.DropboxAPI.ThumbFormat arg3, ProgressListener arg4)
        throws DropboxException {
    return null;
}
 
Example #8
Source File: DropboxSyncService.java    From narrate-android with Apache License 2.0 5 votes vote down vote up
/**
 * Returns 1 if it does exist
 * Returns 0 if it does not exist
 * Returns -1 if there is any other error
 *
 * @param path
 * @return
 */
private int doesFileExist(String path) {
    try {
        DropboxAPI.Entry metadata = getFileInfo(path);
        return 1;
    } catch (DropboxException e) {
        e.printStackTrace();
        if (e.toString().contains("404"))
            return 0;
        else
            return -1;
    }
}
 
Example #9
Source File: DropboxSyncService.java    From narrate-android with Apache License 2.0 5 votes vote down vote up
private boolean doesFolderExist(String path) {
    try {
        DropboxAPI.Entry metadata = getFileInfo(path);
        return metadata.isDir;
    } catch (DropboxException e) {
        e.printStackTrace();
        return false;
    }
}
 
Example #10
Source File: DropboxSyncService.java    From narrate-android with Apache License 2.0 5 votes vote down vote up
@Override
public List<RemoteDataInfo> getRemoteEntries() throws SyncFailedException {
    StringBuilder sb = new StringBuilder();
    sb.append(getBaseFilePath());
    sb.append(ENTRIES);

    List<RemoteDataInfo> dataInfoObjects = new ArrayList<>();

    try {
        List<DropboxAPI.Entry> dropboxEntries = getFileInfo(sb.toString()).contents;

        for (DropboxAPI.Entry entry : dropboxEntries) {
            if ( !entry.isDir ) {
                RemoteDataInfo infoObject = new RemoteDataInfo();
                infoObject.isDirectory = entry.isDir;
                infoObject.isDeleted = entry.isDeleted;
                infoObject.name = entry.fileName().toUpperCase();
                infoObject.modifiedDate = RESTUtility.parseDate(entry.modified).getTime();
                infoObject.revision = entry.rev;
                dataInfoObjects.add(infoObject);
            }
        }

    } catch (Exception e) {
        if (!BuildConfig.DEBUG) Crashlytics.logException(e);
        e.printStackTrace();
        throw new SyncFailedException(e.getMessage());
    }

    return dataInfoObjects;
}
 
Example #11
Source File: DropboxSyncService.java    From narrate-android with Apache License 2.0 5 votes vote down vote up
@Override
public List<RemoteDataInfo> getRemotePhotos() throws SyncFailedException {
    StringBuilder sb = new StringBuilder();
    sb.append(getBaseFilePath());
    sb.append(PHOTOS);

    List<RemoteDataInfo> dataInfoObjects = new ArrayList<>();

    try {
        List<DropboxAPI.Entry> dropboxEntries = getFileInfo(sb.toString()).contents;

        for (DropboxAPI.Entry file : dropboxEntries) {
            if ( !file.isDir ) {
                RemoteDataInfo infoObject = new RemoteDataInfo();
                infoObject.isDirectory = file.isDir;
                infoObject.isDeleted = file.isDeleted;
                infoObject.name = file.fileName().toLowerCase();
                infoObject.modifiedDate = RESTUtility.parseDate(file.modified).getTime();
                infoObject.revision = file.rev;
                dataInfoObjects.add(infoObject);
            }
        }

    } catch (Exception e) {
        if (!BuildConfig.DEBUG) Crashlytics.logException(e);
        e.printStackTrace();
        throw new SyncFailedException(e.getMessage());
    }

    return dataInfoObjects;
}
 
Example #12
Source File: UploadAudioFile.java    From android-auto-call-recorder with MIT License 5 votes vote down vote up
public UploadAudioFile(Context context, DropboxAPI dropboxApi, String dropbox_path, String filePath, String fileName) {
    super();
    this.dropboxApi = dropboxApi;
    this.dropbox_path = dropbox_path;
    this.context = context;
    this.filePath = filePath;
    this.fileName = fileName;
}
 
Example #13
Source File: DropboxFileUploaderTest.java    From endpoints-codelab-android with GNU General Public License v3.0 5 votes vote down vote up
private DropboxAPI.Entry create_metadata(String path, String rev, boolean isDeleted) {
    DropboxAPI.Entry metadata = new DropboxAPI.Entry();
    metadata.path = path;
    metadata.rev = rev;
    metadata.isDeleted = isDeleted;
    return metadata;
}
 
Example #14
Source File: DropboxAPIStub.java    From endpoints-codelab-android with GNU General Public License v3.0 4 votes vote down vote up
@Override
public com.dropbox.client2.DropboxAPI.Account accountInfo()
        throws DropboxException {
    return null;
}
 
Example #15
Source File: DropboxAPIStub.java    From endpoints-codelab-android with GNU General Public License v3.0 4 votes vote down vote up
@Override
public com.dropbox.client2.DropboxAPI.DropboxInputStream getThumbnailStream(
        String arg0, com.dropbox.client2.DropboxAPI.ThumbSize arg1,
        com.dropbox.client2.DropboxAPI.ThumbFormat arg2) throws DropboxException {
    return null;
}
 
Example #16
Source File: DropboxAPIStub.java    From endpoints-codelab-android with GNU General Public License v3.0 4 votes vote down vote up
@Override
public com.dropbox.client2.DropboxAPI.DropboxLink media(String arg0,
        boolean arg1) throws DropboxException {
    return null;
}
 
Example #17
Source File: DropboxAPIStub.java    From endpoints-codelab-android with GNU General Public License v3.0 4 votes vote down vote up
@Override
public com.dropbox.client2.DropboxAPI.Entry metadata(String arg0, int arg1,
        String arg2, boolean arg3, String arg4) throws DropboxException {
    return null;
}
 
Example #18
Source File: DropboxAPIStub.java    From endpoints-codelab-android with GNU General Public License v3.0 4 votes vote down vote up
@Override
public com.dropbox.client2.DropboxAPI.Entry move(String arg0, String arg1)
        throws DropboxException {
    return null;
}
 
Example #19
Source File: DropboxAPIStub.java    From endpoints-codelab-android with GNU General Public License v3.0 4 votes vote down vote up
@Override
public com.dropbox.client2.DropboxAPI.Entry putFile(String arg0,
        InputStream arg1, long arg2, String arg3, ProgressListener arg4)
        throws DropboxException {
    return null;
}
 
Example #20
Source File: DropboxFileUploaderTest.java    From endpoints-codelab-android with GNU General Public License v3.0 4 votes vote down vote up
private DropboxAPI.Entry create_metadata(String path, String rev) {
    return create_metadata(path, rev, false);
}
 
Example #21
Source File: DropboxAPIStub.java    From endpoints-codelab-android with GNU General Public License v3.0 4 votes vote down vote up
@Override
public com.dropbox.client2.DropboxAPI.Entry putFileOverwrite(String arg0,
        InputStream arg1, long arg2, ProgressListener arg3)
        throws DropboxException {
    return null;
}
 
Example #22
Source File: DropboxAPIStub.java    From endpoints-codelab-android with GNU General Public License v3.0 4 votes vote down vote up
@Override
public com.dropbox.client2.DropboxAPI.UploadRequest putFileOverwriteRequest(
        String arg0, InputStream arg1, long arg2, ProgressListener arg3)
        throws DropboxException {
    return null;
}
 
Example #23
Source File: DropboxAPIStub.java    From endpoints-codelab-android with GNU General Public License v3.0 4 votes vote down vote up
@Override
public com.dropbox.client2.DropboxAPI.UploadRequest putFileRequest(
        String arg0, InputStream arg1, long arg2, String arg3,
        ProgressListener arg4) throws DropboxException {
    return null;
}
 
Example #24
Source File: DropboxAPIStub.java    From endpoints-codelab-android with GNU General Public License v3.0 4 votes vote down vote up
@Override
public com.dropbox.client2.DropboxAPI.Entry restore(String arg0, String arg1)
        throws DropboxException {
    return null;
}
 
Example #25
Source File: DropboxAPIStub.java    From endpoints-codelab-android with GNU General Public License v3.0 4 votes vote down vote up
@Override
public List<com.dropbox.client2.DropboxAPI.Entry> revisions(String arg0,
        int arg1) throws DropboxException {
    return null;
}
 
Example #26
Source File: DropboxAPIStub.java    From endpoints-codelab-android with GNU General Public License v3.0 4 votes vote down vote up
@Override
public List<com.dropbox.client2.DropboxAPI.Entry> search(String arg0,
        String arg1, int arg2, boolean arg3) throws DropboxException {
    return null;
}
 
Example #27
Source File: DropboxAPIStub.java    From endpoints-codelab-android with GNU General Public License v3.0 4 votes vote down vote up
@Override
public com.dropbox.client2.DropboxAPI.DropboxLink share(String arg0)
        throws DropboxException {
    return null;
}
 
Example #28
Source File: DropboxAPIStub.java    From endpoints-codelab-android with GNU General Public License v3.0 4 votes vote down vote up
@Override
public com.dropbox.client2.DropboxAPI.DropboxInputStream getFileStream(
        String arg0, String arg1) throws DropboxException {
    return null;
}
 
Example #29
Source File: DropboxAPIStub.java    From endpoints-codelab-android with GNU General Public License v3.0 4 votes vote down vote up
@Override
public com.dropbox.client2.DropboxAPI.DropboxFileInfo getFile(String arg0,
        String arg1, OutputStream arg2, ProgressListener arg3)
        throws DropboxException {
    return null;
}
 
Example #30
Source File: DropboxAPIStub.java    From endpoints-codelab-android with GNU General Public License v3.0 4 votes vote down vote up
@Override
public com.dropbox.client2.DropboxAPI.Entry createFolder(String arg0)
        throws DropboxException {
    return null;
}