Skip to content

Commit

Permalink
Merge pull request aliyun#236 from wushuai1415/master
Browse files Browse the repository at this point in the history
- release 2.9.5
  • Loading branch information
luozhang002 authored Oct 19, 2020
2 parents d070304 + 0e00c14 commit 7805bc6
Show file tree
Hide file tree
Showing 46 changed files with 1,192 additions and 242 deletions.
31 changes: 20 additions & 11 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 25
buildToolsVersion '25.0.2'
compileSdkVersion 29
buildToolsVersion '29.0.2'

defaultConfig {
applicationId "com.alibaba.sdk.android.oss.app"
minSdkVersion 14
targetSdkVersion 22
targetSdkVersion 26
versionCode 1
versionName "1.0"
}
Expand All @@ -25,16 +25,25 @@ android {

}

allprojects {
repositories {
jcenter()
// maven { url "https://jitpack.io" }
maven { url "https://maven.google.com" }
}
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:design:25.0.1'
compile 'com.google.code.gson:gson:2.8.1'
implementation fileTree(include: ['*.jar'], dir: 'libs')
testImplementation 'junit:junit:4.12'
implementation 'com.squareup.okhttp3:okhttp:3.11.0'
implementation 'com.android.support:appcompat-v7:25.3.1'
implementation 'com.android.support:design:25.3.1'
implementation 'com.google.code.gson:gson:2.8.1'
// compile 'com.aliyun.dpa:oss-android-sdk:+'
compile project(':oss-android-sdk')
implementation project(':oss-android-sdk')
//本地照片库
compile 'com.library.tangxiaolv:telegramgallery:1.0.3'
implementation 'com.library.tangxiaolv:telegramgallery:1.0.3'
//material dialog
compile 'com.afollestad.material-dialogs:core:0.9.4.4'
implementation 'com.afollestad.material-dialogs:core:0.9.4.4'
}
1 change: 1 addition & 0 deletions app/src/main/java/com/alibaba/oss/app/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@ public class Config {
public static final int FAIL = 9999;
public static final int REQUESTCODE_AUTH = 10111;
public static final int REQUESTCODE_LOCALPHOTOS = 10112;
public static final int REQUESTCODE_OPEN_DOCUMENT = 10113;
}
19 changes: 18 additions & 1 deletion app/src/main/java/com/alibaba/oss/app/service/OssService.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import android.content.Context;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Environment;
import android.util.Log;

import com.alibaba.oss.app.Config;
Expand All @@ -12,9 +14,11 @@
import com.alibaba.sdk.android.oss.ServiceException;
import com.alibaba.sdk.android.oss.callback.OSSCompletedCallback;
import com.alibaba.sdk.android.oss.callback.OSSProgressCallback;
import com.alibaba.sdk.android.oss.common.OSSConstants;
import com.alibaba.sdk.android.oss.common.OSSLog;
import com.alibaba.sdk.android.oss.common.auth.OSSCustomSignerCredentialProvider;
import com.alibaba.sdk.android.oss.common.auth.OSSPlainTextAKSKCredentialProvider;
import com.alibaba.sdk.android.oss.common.utils.BinaryUtil;
import com.alibaba.sdk.android.oss.common.utils.OSSUtils;
import com.alibaba.sdk.android.oss.internal.OSSAsyncTask;
import com.alibaba.sdk.android.oss.model.CompleteMultipartUploadResult;
Expand All @@ -32,6 +36,7 @@
import com.alibaba.sdk.android.oss.model.ListObjectsResult;
import com.alibaba.sdk.android.oss.model.MultipartUploadRequest;
import com.alibaba.sdk.android.oss.model.OSSRequest;
import com.alibaba.sdk.android.oss.model.ObjectMetadata;
import com.alibaba.sdk.android.oss.model.PutObjectRequest;
import com.alibaba.sdk.android.oss.model.PutObjectResult;
import com.alibaba.sdk.android.oss.model.ResumableUploadRequest;
Expand All @@ -40,10 +45,18 @@
import com.alibaba.sdk.android.oss.model.TriggerCallbackResult;

import java.io.File;
import java.io.FileDescriptor;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorCompletionService;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.ThreadFactory;

import okhttp3.OkHttpClient;
import okhttp3.Request;
Expand Down Expand Up @@ -304,7 +317,8 @@ public void onFailure(HeadObjectRequest request, ClientException clientExcepion,
});
}

public void asyncMultipartUpload(String uploadKey, String uploadFilePath) {
public void asyncMultipartUpload(String uploadKey, Uri uploadFilePath) {

MultipartUploadRequest request = new MultipartUploadRequest(mBucket, uploadKey,
uploadFilePath);
request.setCRC64(OSSRequest.CRC64Config.YES);
Expand All @@ -313,6 +327,9 @@ public void asyncMultipartUpload(String uploadKey, String uploadFilePath) {
@Override
public void onProgress(MultipartUploadRequest request, long currentSize, long totalSize) {
OSSLog.logDebug("[testMultipartUpload] - " + currentSize + " " + totalSize, false);
int progress = (int) (100 * currentSize / totalSize);
mDisplayer.updateProgress(progress);
mDisplayer.displayInfo("上传进度: " + String.valueOf(progress) + "%");
}
});
mOss.asyncMultipartUpload(request, new OSSCompletedCallback<MultipartUploadRequest, CompleteMultipartUploadResult>() {
Expand Down
17 changes: 16 additions & 1 deletion app/src/main/java/com/alibaba/oss/app/view/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
import java.io.IOException;
import java.io.InputStream;

import com.alibaba.sdk.android.oss.common.auth.OSSCustomSignerCredentialProvider;
import com.alibaba.sdk.android.oss.common.auth.OSSPlainTextAKSKCredentialProvider;
import com.alibaba.sdk.android.oss.common.utils.OSSUtils;
import com.tangxiaolv.telegramgallery.GalleryActivity;
import com.afollestad.materialdialogs.MaterialDialog;
import com.tangxiaolv.telegramgallery.GalleryConfig;
Expand Down Expand Up @@ -336,7 +339,10 @@ public void onClick(View v) {
multipartButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mService.asyncMultipartUpload("multipartObject", FILE_PATH);
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*");
startActivityForResult(intent, Config.REQUESTCODE_OPEN_DOCUMENT);
}
});

Expand Down Expand Up @@ -396,6 +402,15 @@ public void onClick(View v) {
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == Config.REQUESTCODE_OPEN_DOCUMENT && resultCode == RESULT_OK && data != null) {
Uri uri = data.getData();
if (uri != null) {
EditText editText = (EditText) findViewById(R.id.edit_text);
String objectName = editText.getText().toString();

mService.asyncMultipartUpload(objectName, uri);
}
}
if (requestCode == Config.REQUESTCODE_AUTH && resultCode == RESULT_OK) {
if (data != null) {
String url = data.getStringExtra("url");
Expand Down
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.android.tools.build:gradle:3.2.0'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
}
Expand All @@ -12,6 +13,7 @@ buildscript {
allprojects {
repositories {
jcenter()
google()
}
}

Expand Down
5 changes: 5 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ Github地址:https://github.com/aliyun/aliyun-oss-android-sdk

更新日志:

2020/10/12
- release 2.9.5
1. 新增通过Uri参数上传
2. 修改主线程初始化异常问题

2020/06/01
- release 2.9.4
1. fix ip visit and conf setIpWithHeader , Host: bucket.endpoint
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
Empty file modified gradlew.bat
100644 → 100755
Empty file.
23 changes: 14 additions & 9 deletions oss-android-sdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ apply plugin: 'com.android.library'
apply plugin: 'jacoco'

android {
compileSdkVersion 23
buildToolsVersion '25.0.0'
compileSdkVersion 30
buildToolsVersion '30.0.0'

useLibrary 'org.apache.http.legacy'

compileOptions {
Expand All @@ -13,9 +14,10 @@ android {

defaultConfig {
minSdkVersion 14
targetSdkVersion 25
targetSdkVersion 29
versionCode 40
versionName "2.9.4"
versionName "2.9.5"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

buildTypes {
Expand Down Expand Up @@ -44,11 +46,14 @@ repositories {
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.squareup.okhttp3:okhttp:3.11.0'
compile 'com.squareup.okio:okio:1.14.0'
androidTestCompile 'com.parse.bolts:bolts-tasks:1.3.0'
implementation fileTree(dir: 'libs', include: ['*.jar'])
testImplementation 'junit:junit:4.12'
implementation 'com.squareup.okhttp3:okhttp:3.11.0'
implementation 'com.squareup.okio:okio:1.14.0'
androidTestImplementation 'com.parse.bolts:bolts-tasks:1.3.0'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test:rules:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:2.2'
}

task releaseJar(type: Copy, dependsOn: build) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.alibaba.sdk.android;

import android.test.AndroidTestCase;
import android.Manifest;
import android.support.test.InstrumentationRegistry;
import android.support.test.rule.GrantPermissionRule;
import android.support.test.runner.AndroidJUnit4;

import com.alibaba.sdk.android.oss.ClientConfiguration;
import com.alibaba.sdk.android.oss.OSS;
Expand All @@ -9,17 +12,29 @@
import com.alibaba.sdk.android.oss.common.utils.HttpdnsMini;
import com.alibaba.sdk.android.oss.model.CreateBucketRequest;

import junit.framework.TestCase;

import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.runner.RunWith;


import static com.alibaba.sdk.android.oss.model.CannedAccessControlList.PublicReadWrite;

/**
* Created by jingdan on 2018/3/1.
*/

public abstract class BaseTestCase extends AndroidTestCase {
@RunWith(AndroidJUnit4.class)
public abstract class BaseTestCase {
protected String mBucketName;
protected String mPublicBucketName;
protected OSS oss;

@Rule
public GrantPermissionRule mRuntimePermissionRule = GrantPermissionRule.grant(Manifest.permission.WRITE_EXTERNAL_STORAGE);

abstract void initTestData() throws Exception;

protected void initOSSClient() {
Expand All @@ -31,16 +46,16 @@ protected void initOSSClient() {
// conf.setMaxErrorRetry(2); // 失败后最大重试次数,默认2次
conf.setHttpDnsEnable(false);
OSSLog.enableLog();
oss = new OSSClient(getContext(), OSSTestConfig.ENDPOINT, OSSTestConfig.credentialProvider,conf);

oss = new OSSClient(InstrumentationRegistry.getTargetContext(), OSSTestConfig.ENDPOINT, OSSTestConfig.credentialProvider,conf);
}


@Override
protected void setUp() throws Exception {
super.setUp();
@Before
public void setUp() throws Exception {
mBucketName = OSSTestUtils.produceBucketName(getName());
mPublicBucketName = OSSTestUtils.produceBucketName("public-" + getName());
OSSTestConfig.instance(getContext());
OSSTestConfig.instance(InstrumentationRegistry.getTargetContext());
if (oss == null) {
OSSLog.enableLog();
initOSSClient();
Expand All @@ -58,9 +73,12 @@ protected void setUp() throws Exception {
}
}

@Override
protected void tearDown() throws Exception {
super.tearDown();
public String getName() {
return "photo-line";
}

@After
public void tearDown() throws Exception {
try {
OSSTestUtils.cleanBucket(oss, mBucketName);
OSSTestUtils.cleanBucket(oss, mPublicBucketName);
Expand Down
Loading

0 comments on commit 7805bc6

Please sign in to comment.