Commit 4ebc5fe1a148b649aa77b158ae79e875d9f8b949

Authored by 王琳
0 parents

创建锐动上传鉴权SDK,添加demo

Showing 100 changed files with 4054 additions and 0 deletions

Too many changes to show.

To preserve performance only 100 of 124 files are displayed.

.gitignore 0 → 100644
  1 +++ a/.gitignore
  1 +*.iml
  2 +.gradle
  3 +/local.properties
  4 +/.idea/workspace.xml
  5 +/.idea/libraries
  6 +.DS_Store
  7 +/build
  8 +/captures
  9 +.externalNativeBuild
... ...
.idea/compiler.xml 0 → 100644
  1 +++ a/.idea/compiler.xml
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<project version="4">
  3 + <component name="CompilerConfiguration">
  4 + <resourceExtensions />
  5 + <wildcardResourcePatterns>
  6 + <entry name="!?*.java" />
  7 + <entry name="!?*.form" />
  8 + <entry name="!?*.class" />
  9 + <entry name="!?*.groovy" />
  10 + <entry name="!?*.scala" />
  11 + <entry name="!?*.flex" />
  12 + <entry name="!?*.kt" />
  13 + <entry name="!?*.clj" />
  14 + <entry name="!?*.aj" />
  15 + </wildcardResourcePatterns>
  16 + <annotationProcessing>
  17 + <profile default="true" name="Default" enabled="false">
  18 + <processorPath useClasspath="true" />
  19 + </profile>
  20 + </annotationProcessing>
  21 + </component>
  22 +</project>
0 23 \ No newline at end of file
... ...
.idea/copyright/profiles_settings.xml 0 → 100644
  1 +++ a/.idea/copyright/profiles_settings.xml
  1 +<component name="CopyrightManager">
  2 + <settings default="" />
  3 +</component>
0 4 \ No newline at end of file
... ...
.idea/gradle.xml 0 → 100644
  1 +++ a/.idea/gradle.xml
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<project version="4">
  3 + <component name="GradleSettings">
  4 + <option name="linkedExternalProjectsSettings">
  5 + <GradleProjectSettings>
  6 + <option name="distributionType" value="DEFAULT_WRAPPED" />
  7 + <option name="externalProjectPath" value="$PROJECT_DIR$" />
  8 + <option name="modules">
  9 + <set>
  10 + <option value="$PROJECT_DIR$" />
  11 + <option value="$PROJECT_DIR$/app" />
  12 + </set>
  13 + </option>
  14 + <option name="resolveModulePerSourceSet" value="false" />
  15 + </GradleProjectSettings>
  16 + </option>
  17 + </component>
  18 +</project>
0 19 \ No newline at end of file
... ...
.idea/misc.xml 0 → 100644
  1 +++ a/.idea/misc.xml
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<project version="4">
  3 + <component name="EntryPointsManager">
  4 + <entry_points version="2.0" />
  5 + </component>
  6 + <component name="NullableNotNullManager">
  7 + <option name="myDefaultNullable" value="android.support.annotation.Nullable" />
  8 + <option name="myDefaultNotNull" value="android.support.annotation.NonNull" />
  9 + <option name="myNullables">
  10 + <value>
  11 + <list size="4">
  12 + <item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.Nullable" />
  13 + <item index="1" class="java.lang.String" itemvalue="javax.annotation.Nullable" />
  14 + <item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.Nullable" />
  15 + <item index="3" class="java.lang.String" itemvalue="android.support.annotation.Nullable" />
  16 + </list>
  17 + </value>
  18 + </option>
  19 + <option name="myNotNulls">
  20 + <value>
  21 + <list size="4">
  22 + <item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.NotNull" />
  23 + <item index="1" class="java.lang.String" itemvalue="javax.annotation.Nonnull" />
  24 + <item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.NonNull" />
  25 + <item index="3" class="java.lang.String" itemvalue="android.support.annotation.NonNull" />
  26 + </list>
  27 + </value>
  28 + </option>
  29 + </component>
  30 + <component name="ProjectLevelVcsManager" settingsEditedManually="false">
  31 + <OptionsSetting value="true" id="Add" />
  32 + <OptionsSetting value="true" id="Remove" />
  33 + <OptionsSetting value="true" id="Checkout" />
  34 + <OptionsSetting value="true" id="Update" />
  35 + <OptionsSetting value="true" id="Status" />
  36 + <OptionsSetting value="true" id="Edit" />
  37 + <ConfirmationsSetting value="0" id="Add" />
  38 + <ConfirmationsSetting value="0" id="Remove" />
  39 + </component>
  40 + <component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK" />
  41 +</project>
0 42 \ No newline at end of file
... ...
.idea/modules.xml 0 → 100644
  1 +++ a/.idea/modules.xml
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<project version="4">
  3 + <component name="ProjectModuleManager">
  4 + <modules>
  5 + <module fileurl="file://$PROJECT_DIR$/RdUpload.iml" filepath="$PROJECT_DIR$/RdUpload.iml" />
  6 + <module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
  7 + </modules>
  8 + </component>
  9 +</project>
0 10 \ No newline at end of file
... ...
app/.gitignore 0 → 100644
  1 +++ a/app/.gitignore
  1 +/build
... ...
app/build.gradle 0 → 100644
  1 +++ a/app/build.gradle
  1 +apply plugin: 'com.android.application'
  2 +
  3 +android {
  4 + compileSdkVersion 26
  5 + buildToolsVersion "26.0.0"
  6 + defaultConfig {
  7 + applicationId "com.cnlive.demo.rdupload"
  8 + minSdkVersion 15
  9 + targetSdkVersion 26
  10 + versionCode 1
  11 + versionName "1.0"
  12 + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
  13 + }
  14 + buildTypes {
  15 + release {
  16 + minifyEnabled false
  17 + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
  18 + }
  19 + }
  20 +
  21 + useLibrary 'org.apache.http.legacy'
  22 +
  23 +}
  24 +
  25 +dependencies {
  26 + compile fileTree(dir: 'libs', include: ['*.jar'])
  27 + androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
  28 + exclude group: 'com.android.support', module: 'support-annotations'
  29 + })
  30 + compile 'com.android.support:appcompat-v7:26.+'
  31 + compile 'com.android.support.constraint:constraint-layout:1.0.2'
  32 + testCompile 'junit:junit:4.12'
  33 +}
... ...
app/libs/android-async-http-1.4.6.jar 0 → 100644
No preview for this file type
app/libs/libcnliverdupload.jar 0 → 100644
No preview for this file type
app/libs/libcnliveutil.jar 0 → 100644
No preview for this file type
app/proguard-rules.pro 0 → 100644
  1 +++ a/app/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:\Users\cnlive100\AppData\Local\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 +
  19 +# Uncomment this to preserve the line number information for
  20 +# debugging stack traces.
  21 +#-keepattributes SourceFile,LineNumberTable
  22 +
  23 +# If you keep the line number information, uncomment this to
  24 +# hide the original source file name.
  25 +#-renamesourcefileattribute SourceFile
... ...
app/src/androidTest/java/com/cnlive/demo/rdupload/ExampleInstrumentedTest.java 0 → 100644
  1 +++ a/app/src/androidTest/java/com/cnlive/demo/rdupload/ExampleInstrumentedTest.java
  1 +package com.cnlive.demo.rdupload;
  2 +
  3 +import android.content.Context;
  4 +import android.support.test.InstrumentationRegistry;
  5 +import android.support.test.runner.AndroidJUnit4;
  6 +
  7 +import org.junit.Test;
  8 +import org.junit.runner.RunWith;
  9 +
  10 +import static org.junit.Assert.*;
  11 +
  12 +/**
  13 + * Instrumentation test, which will execute on an Android device.
  14 + *
  15 + * @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
  16 + */
  17 +@RunWith(AndroidJUnit4.class)
  18 +public class ExampleInstrumentedTest {
  19 + @Test
  20 + public void useAppContext() throws Exception {
  21 + // Context of the app under test.
  22 + Context appContext = InstrumentationRegistry.getTargetContext();
  23 +
  24 + assertEquals("com.cnlive.demo.rdupload", appContext.getPackageName());
  25 + }
  26 +}
... ...
app/src/main/AndroidManifest.xml 0 → 100644
  1 +++ a/app/src/main/AndroidManifest.xml
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  3 + package="com.cnlive.demo.rdupload"
  4 + android:versionCode="1"
  5 + android:versionName="1.0">
  6 +
  7 + <uses-sdk
  8 + android:minSdkVersion="8"
  9 + android:targetSdkVersion="18" />
  10 +
  11 + <uses-permission android:name="android.permission.INTERNET" />
  12 + <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
  13 + <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
  14 + <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
  15 + <uses-permission android:name="android.permission.READ_PHONE_STATE" />
  16 +
  17 + <application
  18 + android:name=".application.App"
  19 + android:allowBackup="true"
  20 + android:icon="@drawable/ic_launcher"
  21 + android:label="@string/app_name"
  22 + android:theme="@style/AppTheme">
  23 + <activity
  24 + android:name=".MainActivity"
  25 + android:label="@string/app_name">
  26 + <intent-filter>
  27 + <action android:name="android.intent.action.MAIN" />
  28 +
  29 + <category android:name="android.intent.category.LAUNCHER" />
  30 + </intent-filter>
  31 + </activity>
  32 + <activity
  33 + android:name=".UploadActivity"
  34 + android:label="@string/app_name" />
  35 + <activity
  36 + android:name=".DownloadActivity"
  37 + android:label="@string/app_name" />
  38 + <activity
  39 + android:name=".RESTAPITestResult"
  40 + android:label="@string/title_activity_main" />
  41 +
  42 + <service
  43 + android:name=".TransferService"
  44 + android:exported="false" />
  45 +
  46 + <activity android:name=".MultiUploadActivity"></activity>
  47 + </application>
  48 +
  49 +</manifest>
0 50 \ No newline at end of file
... ...
app/src/main/java/com/cnlive/demo/rdupload/AuthUtils.java 0 → 100644
  1 +++ a/app/src/main/java/com/cnlive/demo/rdupload/AuthUtils.java
  1 +package com.cnlive.demo.rdupload;
  2 +
  3 +import java.io.UnsupportedEncodingException;
  4 +import java.net.URLEncoder;
  5 +import java.security.SignatureException;
  6 +import java.util.ArrayList;
  7 +import java.util.Arrays;
  8 +import java.util.Collections;
  9 +import java.util.Comparator;
  10 +import java.util.List;
  11 +import java.util.Map;
  12 +import javax.crypto.Mac;
  13 +import javax.crypto.spec.SecretKeySpec;
  14 +
  15 +import com.ksyun.ks3.model.acl.Authorization;
  16 +import com.ksyun.ks3.services.request.Ks3HttpRequest;
  17 +import com.ksyun.ks3.util.ByteUtil;
  18 +
  19 +import android.text.TextUtils;
  20 +import android.util.Base64;
  21 +
  22 +/**
  23 + *
  24 + * 签名工具类
  25 + *
  26 + */
  27 +public class AuthUtils {
  28 + public static String calcAuthorization(Authorization auth,
  29 + Ks3HttpRequest request) throws SignatureException {
  30 + String signature = calcSignature(auth.getAccessKeySecret(), request);
  31 + String value = "KSS " + auth.getAccessKeyId() + ":" + signature;
  32 + return value;
  33 + }
  34 +
  35 + private static String calcSignature(String accessKeySecret,
  36 + Ks3HttpRequest request) throws SignatureException {
  37 + String resource = CanonicalizedKSSResource(request);
  38 + String requestMethod = request.getHttpMethod().toString();
  39 + String contentMd5 = request.getContentMD5();
  40 + String contentType = request.getContentType();
  41 + String _signDate = request.getDate();
  42 + List<String> signList = new ArrayList<String>();
  43 + signList.addAll(Arrays.asList(new String[] { requestMethod, contentMd5,
  44 + contentType, _signDate }));
  45 + String _headers = CanonicalizedKSSHeaders(request);
  46 + if (_headers != null && !_headers.equals("")) {
  47 + signList.add(_headers);
  48 + }
  49 + signList.add(resource);
  50 + String signStr = TextUtils.join("\n", signList.toArray());
  51 + String serverSignature = calculateRFC2104HMAC(signStr, accessKeySecret);
  52 + return serverSignature;
  53 + }
  54 +
  55 + // AuthListener方式,签名计算方法
  56 + public static String calcAuthToken(String httpMethod, String contentType,
  57 + String date, String contentMD5, String resource, String Headers,
  58 + String accessKeyId, String accessKeySecret)
  59 + throws SignatureException {
  60 + List<String> signList = new ArrayList<String>();
  61 + signList.addAll(Arrays.asList(new String[] { httpMethod, contentMD5,
  62 + contentType, date }));
  63 + String _headers = Headers;
  64 + if (_headers != null && !_headers.equals("")) {
  65 + signList.add(_headers);
  66 + }
  67 + signList.add(resource);
  68 + String signStr = TextUtils.join("\n", signList.toArray());
  69 + String serverSignature = calculateRFC2104HMAC(signStr, accessKeySecret);
  70 + String value = "KSS " + accessKeyId + ":" + serverSignature;
  71 + return value;
  72 + }
  73 +
  74 + public static String CanonicalizedKSSResource(Ks3HttpRequest request) {
  75 + boolean escapeDoubleSlash = true;
  76 +
  77 + String bucketName = request.getBucketname();
  78 + String objectKey = request.getObjectkey();
  79 +
  80 + StringBuffer buffer = new StringBuffer();
  81 + buffer.append("/");
  82 + if (!TextUtils.isEmpty(bucketName)) {
  83 + buffer.append(bucketName).append("/");
  84 + }
  85 +
  86 + if (!TextUtils.isEmpty(objectKey)) {
  87 + String encodedPath = null;
  88 + try {
  89 + encodedPath = URLEncoder.encode(objectKey, "UTF-8");
  90 + } catch (UnsupportedEncodingException e) {
  91 + e.printStackTrace();
  92 + }
  93 + if (escapeDoubleSlash) {
  94 + encodedPath = encodedPath.replace("//", "/%2F");
  95 + }
  96 + buffer.append(encodedPath);
  97 + }
  98 +
  99 + String resource = buffer.toString();
  100 +
  101 + String queryParams = request.getParamsToSign();
  102 + if (queryParams != null && !queryParams.equals(""))
  103 + resource = resource + "?" + queryParams;
  104 + return resource;
  105 + }
  106 +
  107 + public static String CanonicalizedKSSHeaders(Ks3HttpRequest request) {
  108 + String prefix = "x-kss";
  109 + Map<String, String> headers = request.getHeader();
  110 +
  111 + List<String> headList = new ArrayList<String>();
  112 +
  113 + for (String _header : headers.keySet()) {
  114 + if (_header.toLowerCase().startsWith(prefix)) {
  115 + headList.add(_header);
  116 + }
  117 + }
  118 +
  119 + Collections.sort(headList, new Comparator<String>() {
  120 + public int compare(String o1, String o2) {
  121 + return ByteUtil.compareTo(o1.getBytes(), o2.toString()
  122 + .getBytes());
  123 + }
  124 + });
  125 + StringBuffer buffer = new StringBuffer();
  126 + for (int i = 0; i < headList.size(); i++) {
  127 + String _key = headList.get(i);
  128 + buffer.append(headList.get(i) + ":" + headers.get(_key));
  129 + if (i < (headList.size() - 1))
  130 + buffer.append("\n");
  131 + }
  132 + return buffer.toString();
  133 + }
  134 +
  135 + private static final String HMAC_SHA1_ALGORITHM = "HmacSHA1";
  136 +
  137 + public static String calculateRFC2104HMAC(String data, String key)
  138 + throws SignatureException {
  139 + String result;
  140 + try {
  141 + // get an hmac_sha1 key from the raw key bytes
  142 + SecretKeySpec signingKey = new SecretKeySpec(key.getBytes(),
  143 + HMAC_SHA1_ALGORITHM);
  144 + // get an hmac_sha1 Mac instance and initialize with the signing key
  145 + Mac mac = Mac.getInstance(HMAC_SHA1_ALGORITHM);
  146 + mac.init(signingKey);
  147 + // compute the hmac on input data bytes
  148 + byte[] rawHmac = mac.doFinal(data.getBytes());
  149 + // base64-encode the hmac
  150 + // result = new String(Base64.encodeBase64(rawHmac), "GBK");
  151 + result = Base64.encodeToString(rawHmac, Base64.DEFAULT);
  152 + } catch (Exception e) {
  153 + throw new SignatureException("Failed to generate HMAC : " + e);
  154 + }
  155 + return result;
  156 + }
  157 +
  158 +}
... ...
app/src/main/java/com/cnlive/demo/rdupload/BucketInpuDialog.java 0 → 100644
  1 +++ a/app/src/main/java/com/cnlive/demo/rdupload/BucketInpuDialog.java
  1 +package com.cnlive.demo.rdupload;
  2 +
  3 +import android.app.Dialog;
  4 +import android.content.Context;
  5 +import android.os.Bundle;
  6 +import android.text.TextUtils;
  7 +import android.view.View;
  8 +import android.widget.Button;
  9 +import android.widget.EditText;
  10 +import android.widget.Toast;
  11 +
  12 +/**
  13 + *
  14 + * 自定义Dialog,Bucket输入对话框
  15 + *
  16 + */
  17 +public class BucketInpuDialog extends Dialog implements
  18 + View.OnClickListener {
  19 + public interface OnBucketDialogListener {
  20 + public void confirmBucket(String name);
  21 + }
  22 +
  23 + public OnBucketDialogListener listener;
  24 + private EditText bucketField;
  25 + private Button okBtn;
  26 + private Button cancelBtn;
  27 + private Context context;
  28 +
  29 + public BucketInpuDialog(Context context) {
  30 + super(context);
  31 + this.context = context;
  32 + }
  33 +
  34 + public void setOnBucketInputListener(OnBucketDialogListener listener) {
  35 + this.listener = listener;
  36 + }
  37 +
  38 + @Override
  39 + protected void onCreate(Bundle savedInstanceState) {
  40 + super.onCreate(savedInstanceState);
  41 + setContentView(R.layout.alert_bucket_input);
  42 + setTitle("Input Bucket Name");
  43 + setUpViews();
  44 + }
  45 +
  46 + private void setUpViews() {
  47 + bucketField = (EditText) findViewById(R.id.input);
  48 + okBtn = (Button) findViewById(R.id.ok);
  49 + cancelBtn = (Button) findViewById(R.id.cancel);
  50 + okBtn.setOnClickListener(this);
  51 + cancelBtn.setOnClickListener(this);
  52 + }
  53 +
  54 + @Override
  55 + public void onClick(View v) {
  56 + if (listener != null) {
  57 + switch (v.getId()) {
  58 + case R.id.ok:
  59 + if (TextUtils.isEmpty(bucketField.getText().toString())) {
  60 + Toast.makeText(context, "Bucket name should not be null",
  61 + Toast.LENGTH_SHORT).show();
  62 + } else {
  63 + String result = bucketField.getText().toString();
  64 + listener.confirmBucket(result);
  65 + BucketInpuDialog.this.dismiss();
  66 + }
  67 + break;
  68 + case R.id.cancel:
  69 + BucketInpuDialog.this.dismiss();
  70 + break;
  71 + default:
  72 + break;
  73 + }
  74 + } else {
  75 + Toast.makeText(context, "Please set OnBucketInputListener first",
  76 + Toast.LENGTH_SHORT).show();
  77 + }
  78 +
  79 + }
  80 +
  81 +}
... ...
app/src/main/java/com/cnlive/demo/rdupload/BucketObjectInpuDialog.java 0 → 100644
  1 +++ a/app/src/main/java/com/cnlive/demo/rdupload/BucketObjectInpuDialog.java
  1 +package com.cnlive.demo.rdupload;
  2 +
  3 +import android.app.Dialog;
  4 +import android.content.Context;
  5 +import android.os.Bundle;
  6 +import android.text.TextUtils;
  7 +import android.view.View;
  8 +import android.widget.Button;
  9 +import android.widget.EditText;
  10 +import android.widget.Toast;
  11 +
  12 +/**
  13 + *
  14 + * 自定义Dialog
  15 + *
  16 + */
  17 +public class BucketObjectInpuDialog extends Dialog implements
  18 + View.OnClickListener {
  19 + public interface OnBucketObjectDialogListener {
  20 + public void confirmBucketAndObject(String name, String key);
  21 + }
  22 +
  23 + public OnBucketObjectDialogListener listener;
  24 + private EditText bucketField;
  25 + private Button okBtn;
  26 + private Button cancelBtn;
  27 + private Context context;
  28 + private EditText objectField;
  29 +
  30 + public BucketObjectInpuDialog(Context context) {
  31 + super(context);
  32 + this.context = context;
  33 + }
  34 +
  35 + public void setOnBucketObjectDialogListener(
  36 + OnBucketObjectDialogListener listener) {
  37 + this.listener = listener;
  38 + }
  39 +
  40 + @Override
  41 + protected void onCreate(Bundle savedInstanceState) {
  42 + super.onCreate(savedInstanceState);
  43 + setContentView(R.layout.alert_bucket_object_input);
  44 + setTitle("Input Bucket Name");
  45 + setUpViews();
  46 + }
  47 +
  48 + private void setUpViews() {
  49 + bucketField = (EditText) findViewById(R.id.input);
  50 + objectField = (EditText) findViewById(R.id.input_second);
  51 + okBtn = (Button) findViewById(R.id.ok);
  52 + cancelBtn = (Button) findViewById(R.id.cancel);
  53 + okBtn.setOnClickListener(this);
  54 + cancelBtn.setOnClickListener(this);
  55 + }
  56 +
  57 + @Override
  58 + public void onClick(View v) {
  59 + if (listener != null) {
  60 + switch (v.getId()) {
  61 + case R.id.ok:
  62 + if (TextUtils.isEmpty(bucketField.getText().toString())
  63 + || TextUtils.isEmpty(objectField.getText().toString())) {
  64 + Toast.makeText(context,
  65 + "Bucket name or Object key should not be null",
  66 + Toast.LENGTH_SHORT).show();
  67 + } else {
  68 + String name = bucketField.getText().toString();
  69 + String key = objectField.getText().toString();
  70 + listener.confirmBucketAndObject(name, key);
  71 + BucketObjectInpuDialog.this.dismiss();
  72 + }
  73 + break;
  74 + case R.id.cancel:
  75 + BucketObjectInpuDialog.this.dismiss();
  76 + break;
  77 + default:
  78 + break;
  79 + }
  80 + } else {
  81 + Toast.makeText(context, "Please set OnBucketInputListener first",
  82 + Toast.LENGTH_SHORT).show();
  83 + }
  84 +
  85 + }
  86 +
  87 +}
... ...
app/src/main/java/com/cnlive/demo/rdupload/Constants.java 0 → 100644
  1 +++ a/app/src/main/java/com/cnlive/demo/rdupload/Constants.java
  1 +package com.cnlive.demo.rdupload;
  2 +
  3 +/**
  4 + *
  5 + * Demo中一些常量
  6 + *
  7 + */
  8 +public class Constants {
  9 + // public static final String ACCESS_KEY__ID = "YOUR_ACCESS_KEY_ID";
  10 + // public static final String ACCESS_KEY_SECRET = "YOUR_ACCESS_KEY_SECRET";
  11 + public static final String TEST_TXT = "YOUR_TEST_TXT_IN_SDCARD_ROOT_PATH";
  12 + public static final String TEST_IMG = "YOUR_TEST_IMG_IN_SDCARD_ROOT_PATH";
  13 + protected static final String UPLOAD_ID = "YOUR_UPLOAD_ID";
  14 + // public static final String APP_SERTVER_HOST =
  15 + // "http://192.168.231.49:11911";
  16 + public static final String TEST_MULTIUPLOAD_FILE = "Your file in sdcard path";
  17 + public static final String TEST_MULTIUPLOAD_BUCKET = "compose";
  18 +
  19 + public static final String APP_SERTVER_HOST = "YOUR_APP_SERVER_HOST";
  20 + // 测试用AK&SK
  21 + public static final String ACCESS_KEY__ID = "Your ak";
  22 + public static final String ACCESS_KEY_SECRET = "Your sk";
  23 + public static final String END_POINT = "ks3-cn-beijing.ksyun.com";
  24 + public static final long MULTI_UPLOAD_THREADHOLD = 16 * 1024 * 1024;
  25 +}
... ...
app/src/main/java/com/cnlive/demo/rdupload/DemoUtils.java 0 → 100644
  1 +++ a/app/src/main/java/com/cnlive/demo/rdupload/DemoUtils.java
  1 +package com.cnlive.demo.rdupload;
  2 +
  3 +import java.text.SimpleDateFormat;
  4 +import java.util.Date;
  5 +import java.util.Locale;
  6 +
  7 +import android.content.Context;
  8 +import android.content.res.Resources;
  9 +import android.graphics.drawable.Drawable;
  10 +
  11 +public class DemoUtils {
  12 + public static Drawable matchImage(Context context,boolean isDir , String fileName){
  13 + Resources resources = context.getResources();
  14 + if(isDir)
  15 + return resources.getDrawable(R.drawable.ks_format_forder);
  16 + if(fileName.endsWith(".apk")) return resources.getDrawable(R.drawable.ks_format_apk);
  17 + else if(fileName.endsWith(".ogg")) return resources.getDrawable(R.drawable.ks_format_ogg);
  18 + else if(fileName.endsWith(".chm")) return resources.getDrawable(R.drawable.ks_format_chm);
  19 + else if(fileName.endsWith(".asf")) return resources.getDrawable(R.drawable.ks_format_asf);
  20 + else if(fileName.endsWith(".avi")) return resources.getDrawable(R.drawable.ks_format_avi);
  21 + else if(fileName.endsWith(".bat")) return resources.getDrawable(R.drawable.ks_format_bat);
  22 + else if(fileName.endsWith(".bin")) return resources.getDrawable(R.drawable.ks_format_bin);
  23 + else if(fileName.endsWith(".bmp")) return resources.getDrawable(R.drawable.ks_format_bmp);
  24 + else if(fileName.endsWith(".dat")) return resources.getDrawable(R.drawable.ks_format_dat);
  25 + else if(fileName.endsWith(".db")) return resources.getDrawable(R.drawable.ks_format_dat);
  26 + else if(fileName.endsWith(".dll")) return resources.getDrawable(R.drawable.ks_format_dll);
  27 + else if(fileName.endsWith(".doc")) return resources.getDrawable(R.drawable.ks_format_doc);
  28 + else if(fileName.endsWith(".docx")) return resources.getDrawable(R.drawable.ks_format_docx);
  29 + else if(fileName.endsWith(".flac")) return resources.getDrawable(R.drawable.ks_format_flac);
  30 + else if(fileName.endsWith(".flv")) return resources.getDrawable(R.drawable.ks_format_flv);
  31 + else if(fileName.endsWith(".gif")) return resources.getDrawable(R.drawable.ks_format_gif);
  32 + else if(fileName.endsWith(".html")) return resources.getDrawable(R.drawable.ks_format_html);
  33 + else if(fileName.endsWith(".info")) return resources.getDrawable(R.drawable.ks_format_inf);
  34 + else if(fileName.endsWith(".inf")) return resources.getDrawable(R.drawable.ks_format_inf);
  35 + else if(fileName.endsWith(".ini")) return resources.getDrawable(R.drawable.ks_format_ini);
  36 + else if(fileName.endsWith(".java")) return resources.getDrawable(R.drawable.ks_format_java);
  37 + else if(fileName.endsWith(".jif")) return resources.getDrawable(R.drawable.ks_format_jif);
  38 + else if(fileName.endsWith(".jpg")) return resources.getDrawable(R.drawable.ks_format_jpg);
  39 + else if(fileName.endsWith(".log")) return resources.getDrawable(R.drawable.ks_format_log);
  40 + else if(fileName.endsWith(".m4a")) return resources.getDrawable(R.drawable.ks_format_m4a);
  41 + else if(fileName.endsWith(".mid")) return resources.getDrawable(R.drawable.ks_format_mid);
  42 + else if(fileName.endsWith(".mkv")) return resources.getDrawable(R.drawable.ks_format_mkv);
  43 + else if(fileName.endsWith(".mp3")) return resources.getDrawable(R.drawable.ks_format_mp3);
  44 + else if(fileName.endsWith(".mp4")) return resources.getDrawable(R.drawable.ks_format_mp4);
  45 + else if(fileName.endsWith(".pdf")) return resources.getDrawable(R.drawable.ks_format_pdf);
  46 + else if(fileName.endsWith(".png")) return resources.getDrawable(R.drawable.ks_format_png);
  47 + else if(fileName.endsWith(".ppt")) return resources.getDrawable(R.drawable.ks_format_ppt);
  48 + else if(fileName.endsWith(".pptx")) return resources.getDrawable(R.drawable.ks_format_pptx);
  49 + else if(fileName.endsWith(".ram")) return resources.getDrawable(R.drawable.ks_format_ram);
  50 + else if(fileName.endsWith(".rar")) return resources.getDrawable(R.drawable.ks_format_rar);
  51 + else if(fileName.endsWith(".jar")) return resources.getDrawable(R.drawable.ks_format_rar);
  52 + else if(fileName.endsWith(".reg")) return resources.getDrawable(R.drawable.ks_format_reg);
  53 + else if(fileName.endsWith(".rm")) return resources.getDrawable(R.drawable.ks_format_rm);
  54 + else if(fileName.endsWith(".rmvb")) return resources.getDrawable(R.drawable.ks_format_rmvb);
  55 + else if(fileName.endsWith(".swf")) return resources.getDrawable(R.drawable.ks_format_swf);
  56 + else if(fileName.endsWith(".txt")) return resources.getDrawable(R.drawable.ks_format_txt);
  57 + else if(fileName.endsWith(".wav")) return resources.getDrawable(R.drawable.ks_format_wav);
  58 + else if(fileName.endsWith(".wma")) return resources.getDrawable(R.drawable.ks_format_wma);
  59 + else if(fileName.endsWith(".wmv")) return resources.getDrawable(R.drawable.ks_format_wmv);
  60 + else if(fileName.endsWith(".xls")) return resources.getDrawable(R.drawable.ks_format_xls);
  61 + else if(fileName.endsWith(".xlsx")) return resources.getDrawable(R.drawable.ks_format_xlsx);
  62 + else if(fileName.endsWith(".zip")) return resources.getDrawable(R.drawable.ks_format_zip);
  63 + else if(fileName.endsWith(".jpeg")) return resources.getDrawable(R.drawable.ks_format_jpg);
  64 + else if(fileName.endsWith(".xml")) return resources.getDrawable(R.drawable.ks_format_xml);
  65 + else return resources.getDrawable(R.drawable.ks_format_unkown);
  66 + }
  67 +
  68 + public static String formatDate(long time){
  69 + SimpleDateFormat format = new SimpleDateFormat("yyyy-mm-dd",Locale.US);
  70 + return format.format(new Date(time));
  71 + }
  72 + public static String formatDate(Date date){
  73 + SimpleDateFormat format = new SimpleDateFormat("yyyy-mm-dd",Locale.US);
  74 + return format.format(date);
  75 + }
  76 +
  77 +}
... ...
app/src/main/java/com/cnlive/demo/rdupload/DownloadActivity.java 0 → 100644
  1 +++ a/app/src/main/java/com/cnlive/demo/rdupload/DownloadActivity.java
  1 +package com.cnlive.demo.rdupload;
  2 +
  3 +import java.io.File;
  4 +import java.io.IOException;
  5 +import java.io.UnsupportedEncodingException;
  6 +import java.util.ArrayList;
  7 +import java.util.Date;
  8 +import java.util.HashMap;
  9 +import java.util.List;
  10 +import java.util.Map;
  11 +import java.util.Map.Entry;
  12 +
  13 +import org.apache.http.Header;
  14 +import org.apache.http.HttpResponse;
  15 +import org.apache.http.client.ClientProtocolException;
  16 +import org.apache.http.client.methods.HttpPost;
  17 +import org.apache.http.entity.StringEntity;
  18 +import org.apache.http.impl.client.DefaultHttpClient;
  19 +import org.apache.http.util.EntityUtils;
  20 +import org.json.JSONException;
  21 +import org.json.JSONObject;
  22 +
  23 +import android.annotation.SuppressLint;
  24 +import android.app.Activity;
  25 +import android.content.Context;
  26 +import android.graphics.drawable.Drawable;
  27 +import android.os.Bundle;
  28 +import android.os.Environment;
  29 +import android.os.Handler;
  30 +import android.os.Message;
  31 +import android.util.Log;
  32 +import android.view.LayoutInflater;
  33 +import android.view.View;
  34 +import android.view.ViewGroup;
  35 +import android.widget.AdapterView;
  36 +import android.widget.AdapterView.OnItemClickListener;
  37 +import android.widget.BaseAdapter;
  38 +import android.widget.ImageView;
  39 +import android.widget.LinearLayout;
  40 +import android.widget.ListView;
  41 +import android.widget.ProgressBar;
  42 +import android.widget.TextView;
  43 +import android.widget.Toast;
  44 +
  45 +import com.cnlive.lib.rdupload.network.HttpTask;
  46 +import com.ksyun.ks3.exception.Ks3Error;
  47 +import com.ksyun.ks3.model.Ks3ObjectSummary;
  48 +import com.ksyun.ks3.model.ObjectListing;
  49 +import com.ksyun.ks3.model.result.GetObjectResult;
  50 +import com.ksyun.ks3.services.AuthListener;
  51 +import com.ksyun.ks3.services.Ks3Client;
  52 +import com.ksyun.ks3.services.Ks3ClientConfiguration;
  53 +import com.ksyun.ks3.services.handler.GetObjectResponseHandler;
  54 +import com.ksyun.ks3.services.handler.ListObjectsResponseHandler;
  55 +import com.ksyun.ks3.services.request.GetObjectRequest;
  56 +import com.ksyun.ks3.services.request.ListObjectsRequest;
  57 +import com.ksyun.ks3.util.StringUtils;
  58 +
  59 +/**
  60 + * Download相关API使用示例,如getObject,listObject等
  61 + */
  62 +public class DownloadActivity extends Activity implements OnItemClickListener {
  63 +
  64 + private ListView mListView;
  65 + private ProgressBar mProgressBar;
  66 + private Ks3ClientConfiguration configuration;
  67 + private Ks3Client client;
  68 + private Map<String, RemoteFile> dataSource;
  69 + private RemoteFileAdapter adapter;
  70 + private TextView currentBucketTextView;
  71 + private File storeForder;
  72 + private myHandler mHandler = new myHandler();
  73 + private BucketInpuDialog bucketInpuDialog;
  74 +
  75 + private HttpTask httpTask;
  76 +
  77 + @Override
  78 + protected void onCreate(Bundle savedInstanceState) {
  79 + super.onCreate(savedInstanceState);
  80 + setContentView(R.layout.activity_download);
  81 + setUp();
  82 + bucketInpuDialog = new BucketInpuDialog(DownloadActivity.this);
  83 + prepareStoreForder();
  84 + bucketInpuDialog.setOnBucketInputListener(new BucketInpuDialog.OnBucketDialogListener() {
  85 + @Override
  86 + public void confirmBucket(String name) {
  87 + // 输入框确获取Bucket之后,开始ListObjects操作
  88 + listObjects(name, null);
  89 + }
  90 + });
  91 + bucketInpuDialog.show();
  92 + }
  93 +
  94 + private void prepareStoreForder() {
  95 + storeForder = new File(Environment.getExternalStorageDirectory(),
  96 + "ksyun_download");
  97 + if (!storeForder.exists()) {
  98 + storeForder.mkdirs();
  99 + } else if (storeForder.isFile()) {
  100 + storeForder.delete();
  101 + }
  102 + }
  103 +
  104 + private void listObjects(String bucketName, final String prefix) {
  105 + final ListObjectsRequest request = new ListObjectsRequest(bucketName);
  106 + if (!StringUtils.isBlank(prefix))
  107 + request.setPrefix(prefix);
  108 + request.setDelimiter("/");
  109 + client.listObjects(request, new ListObjectsResponseHandler() {
  110 + @Override
  111 + public void onSuccess(int statesCode, Header[] responceHeaders,
  112 + ObjectListing objectListing) {
  113 + mProgressBar.setVisibility(View.GONE);
  114 + currentBucketTextView.setVisibility(View.VISIBLE);
  115 + mListView.setVisibility(View.VISIBLE);
  116 + currentBucketTextView.setText("当前路径:Bucket:"
  117 + + request.getBucketname() + "-" + prefix);
  118 +
  119 + List<Ks3ObjectSummary> objectSummaries = objectListing
  120 + .getObjectSummaries();
  121 + if (objectSummaries != null && objectSummaries.size() != 0) {
  122 + for (Ks3ObjectSummary object : objectSummaries) {
  123 + String objectKey = object.getKey();
  124 + if (dataSource.get(objectKey) == null) {
  125 + RemoteFile remoteFile = new RemoteFile();
  126 + remoteFile.bucketName = objectListing
  127 + .getBucketName();
  128 + remoteFile.objectKey = objectKey;
  129 + remoteFile.isCommomPrefix = false;
  130 + remoteFile.icon = DemoUtils.matchImage(
  131 + DownloadActivity.this, false, objectKey);
  132 + remoteFile.size = object.getSize();
  133 + remoteFile.lastModified = object.getLastModified();
  134 + remoteFile.progress = 0;
  135 + remoteFile.status = RemoteFile.STATUS_NOT_START;
  136 + dataSource.put(objectKey, remoteFile);
  137 + }
  138 + }
  139 + }
  140 + List<String> commonPrefixes = objectListing.getCommonPrefixes();
  141 + if (commonPrefixes != null && commonPrefixes.size() != 0) {
  142 + for (String prifix : commonPrefixes) {
  143 + RemoteFile remoteFile = new RemoteFile();
  144 + remoteFile.bucketName = objectListing.getBucketName();
  145 + remoteFile.objectKey = prifix;
  146 + remoteFile.icon = DemoUtils.matchImage(
  147 + DownloadActivity.this, true, prifix);
  148 + remoteFile.progress = 0;
  149 + remoteFile.isCommomPrefix = true;
  150 + remoteFile.status = RemoteFile.STATUS_NOT_START;
  151 + dataSource.put(prifix, remoteFile);
  152 + }
  153 + }
  154 + adapter.fillDatas();
  155 + }
  156 +
  157 + @Override
  158 + public void onFailure(int statesCode, Ks3Error error,
  159 + Header[] responceHeaders, String response,
  160 + Throwable paramThrowable) {
  161 +
  162 + }
  163 + });
  164 + }
  165 +
  166 + private void setUp() {
  167 + // Ks3Client初始化并鉴权
  168 + configuration = Ks3ClientConfiguration.getDefaultConfiguration();
  169 + if (httpTask == null) {
  170 + httpTask = new HttpTask();
  171 + }
  172 + client = new Ks3Client(new AuthListener() {
  173 + @Override
  174 + public String onCalculateAuth(String s, String s1, String s2, String s3, String s4, String s5) {
  175 + return httpTask.requestTokenToAppServer(s, s1, s2, s3, s4, s5).getAuthorization();
  176 + }
  177 + }, this);
  178 + client.setConfiguration(configuration);
  179 +
  180 + // UI初始化
  181 + currentBucketTextView = (TextView) findViewById(R.id.current_bucket_tv);
  182 + mListView = (ListView) findViewById(R.id.object_list);
  183 + mProgressBar = (ProgressBar) findViewById(R.id.progress_bar);
  184 + dataSource = new HashMap<String, RemoteFile>();
  185 + adapter = new RemoteFileAdapter(this, null);
  186 + mListView.setAdapter(adapter);
  187 + mListView.setOnItemClickListener(this);
  188 + }
  189 +
  190 + class RemoteFileAdapter extends BaseAdapter {
  191 + private List<RemoteFile> mRemoteFiles;
  192 + private LayoutInflater mInflater;
  193 +
  194 + RemoteFileAdapter(Context context, List<RemoteFile> remoteFiles) {
  195 + this.mRemoteFiles = new ArrayList<RemoteFile>();
  196 + if (remoteFiles != null)
  197 + this.mRemoteFiles.addAll(remoteFiles);
  198 + this.mInflater = (LayoutInflater) context
  199 + .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  200 + }
  201 +
  202 + @Override
  203 + public int getCount() {
  204 + return mRemoteFiles.size();
  205 + }
  206 +
  207 + @Override
  208 + public RemoteFile getItem(int position) {
  209 + return this.mRemoteFiles.get(position);
  210 + }
  211 +
  212 + @Override
  213 + public long getItemId(int position) {
  214 + return position;
  215 + }
  216 +
  217 + public void fillDatas() {
  218 + this.mRemoteFiles.clear();
  219 + for (Entry<String, RemoteFile> entry : dataSource.entrySet()) {
  220 + this.mRemoteFiles.add(entry.getValue());
  221 + }
  222 + this.notifyDataSetChanged();
  223 + }
  224 +
  225 + public void updateCurrent() {
  226 + this.notifyDataSetChanged();
  227 + }
  228 +
  229 + @Override
  230 + public View getView(int position, View convertView, ViewGroup parent) {
  231 + ViewHolder viewHolder;
  232 + if (convertView == null) {
  233 + convertView = mInflater.inflate(R.layout.download_list_item,
  234 + parent, false);
  235 + viewHolder = new ViewHolder();
  236 + viewHolder.remoteObjectIcon = (ImageView) convertView
  237 + .findViewById(R.id.remote_object_icon);
  238 + viewHolder.remoteObjectKeyTextView = (TextView) convertView
  239 + .findViewById(R.id.remote_object_key);
  240 + viewHolder.remoteObjectSummaryLayout = (LinearLayout) convertView
  241 + .findViewById(R.id.remote_object_summary_layout);
  242 + viewHolder.remoteObjectSizeTextView = (TextView) convertView
  243 + .findViewById(R.id.remote_object_size);
  244 + viewHolder.remoteObjectModiyTextView = (TextView) convertView
  245 + .findViewById(R.id.remote_object_last_modiy);
  246 + viewHolder.downloadSummaryLayout = (LinearLayout) convertView
  247 + .findViewById(R.id.progress_summary_layout);
  248 + viewHolder.downloadProgressBar = (ProgressBar) convertView
  249 + .findViewById(R.id.download_progress_bar);
  250 + viewHolder.progressTextView = (TextView) convertView
  251 + .findViewById(R.id.download_progress_txt);
  252 + viewHolder.downloadBtn = (ImageView) convertView
  253 + .findViewById(R.id.download_btn);
  254 + convertView.setTag(viewHolder);
  255 + } else {
  256 + viewHolder = (ViewHolder) convertView.getTag();
  257 + }
  258 + viewHolder.remoteObjectIcon.setImageDrawable(mRemoteFiles
  259 + .get(position).icon);
  260 + viewHolder.remoteObjectKeyTextView.setText(mRemoteFiles
  261 + .get(position).objectKey);
  262 +
  263 + if (!mRemoteFiles.get(position).isCommomPrefix) {
  264 + viewHolder.remoteObjectKeyTextView.setVisibility(View.VISIBLE);
  265 + long size = mRemoteFiles.get(position).size;
  266 + String sizeStr = "unkown-size";
  267 +
  268 + if (size >= 1024 * 1024) {
  269 + sizeStr = ((int) (size / 1024 / 1024) * 100) / 100 + "MB";
  270 + } else {
  271 + sizeStr = (size / 1024) + "kb";
  272 + }
  273 + viewHolder.remoteObjectSizeTextView.setText(sizeStr);
  274 + String modiyStr = DemoUtils.formatDate(mRemoteFiles
  275 + .get(position).lastModified);
  276 + viewHolder.remoteObjectModiyTextView.setText(modiyStr);
  277 + if (mRemoteFiles.get(position).status > RemoteFile.STATUS_NOT_START) {
  278 + viewHolder.downloadSummaryLayout
  279 + .setVisibility(View.VISIBLE);
  280 + viewHolder.downloadProgressBar.setProgress(mRemoteFiles
  281 + .get(position).progress);
  282 + viewHolder.remoteObjectSummaryLayout
  283 + .setVisibility(View.GONE);
  284 + viewHolder.downloadBtn.setVisibility(View.GONE);
  285 + switch (mRemoteFiles.get(position).status) {
  286 + case RemoteFile.STATUS_STARTED:
  287 + viewHolder.progressTextView.setText("准备");
  288 + break;
  289 + case RemoteFile.STATUS_DOWNLOADING:
  290 + viewHolder.progressTextView.setText(mRemoteFiles
  291 + .get(position).progress + "%");
  292 + break;
  293 + case RemoteFile.STATUS_FINISH:
  294 + viewHolder.progressTextView.setText("完成下载");
  295 + break;
  296 + case RemoteFile.STATUS_FAIL:
  297 + viewHolder.progressTextView.setText("下载失败");
  298 + break;
  299 + }
  300 + } else {
  301 + viewHolder.remoteObjectSummaryLayout
  302 + .setVisibility(View.VISIBLE);
  303 + viewHolder.downloadBtn.setVisibility(View.VISIBLE);
  304 + viewHolder.downloadSummaryLayout.setVisibility(View.GONE);
  305 + }
  306 + } else {
  307 + viewHolder.remoteObjectSummaryLayout.setVisibility(View.GONE);
  308 + viewHolder.downloadSummaryLayout.setVisibility(View.GONE);
  309 + viewHolder.downloadBtn.setVisibility(View.GONE);
  310 + }
  311 +
  312 + return convertView;
  313 + }
  314 + }
  315 +
  316 + class ViewHolder {
  317 + ImageView remoteObjectIcon;
  318 + TextView remoteObjectKeyTextView;
  319 + LinearLayout remoteObjectSummaryLayout;
  320 + TextView remoteObjectSizeTextView;
  321 + TextView remoteObjectModiyTextView;
  322 + LinearLayout downloadSummaryLayout;
  323 + ProgressBar downloadProgressBar;
  324 + TextView progressTextView;
  325 + ImageView downloadBtn;
  326 + }
  327 +
  328 + class RemoteFile {
  329 + static final int STATUS_NOT_START = 0;
  330 + static final int STATUS_STARTED = 1;
  331 + static final int STATUS_DOWNLOADING = 2;
  332 + static final int STATUS_FINISH = 3;
  333 + static final int STATUS_FAIL = 4;
  334 + Drawable icon;
  335 + String bucketName;
  336 + String objectKey;
  337 + long size;
  338 + Date lastModified;
  339 + int progress;
  340 + int status;
  341 + boolean isCommomPrefix;
  342 +
  343 + @Override
  344 + public String toString() {
  345 + return bucketName + ",download?" + status + ",progress:" + progress;
  346 + }
  347 + }
  348 +
  349 + @Override
  350 + public void onItemClick(AdapterView<?> adpterView, final View view,
  351 + final int position, long arg3) {
  352 + final RemoteFile item = adapter.getItem(position);
  353 + if (item.isCommomPrefix) {
  354 + // listObjects(item.bucketName, item.objectKey);
  355 + Toast.makeText(this, "请自行实现下一级目录的检索", Toast.LENGTH_LONG).show();
  356 + } else {
  357 + if (item.status == RemoteFile.STATUS_STARTED
  358 + || item.status == RemoteFile.STATUS_DOWNLOADING
  359 + || item.status == RemoteFile.STATUS_FINISH)
  360 + return;
  361 + // 下载操作示例
  362 + final GetObjectRequest request = new GetObjectRequest(
  363 + item.bucketName, item.objectKey);
  364 + String objectName = item.objectKey.substring(item.objectKey
  365 + .lastIndexOf("/") == -1 ? 0 : item.objectKey
  366 + .lastIndexOf("/"));
  367 +// request.setCallBack(callBackUrl, callBackBody, callBackHeaders);
  368 + File file = new File(storeForder, objectName);
  369 + client.getObject(request, new GetObjectResponseHandler(file,
  370 + item.bucketName, item.objectKey) {
  371 +
  372 + @Override
  373 + public void onTaskSuccess(int paramInt,
  374 + Header[] paramArrayOfHeader,
  375 + GetObjectResult getObjectResult) {
  376 +
  377 + }
  378 +
  379 + @Override
  380 + public void onTaskStart() {
  381 + RemoteFile remoteFile = dataSource.get(item.objectKey);
  382 + remoteFile.status = RemoteFile.STATUS_STARTED;
  383 + remoteFile.progress = 0;
  384 + item.status = RemoteFile.STATUS_STARTED;
  385 + item.progress = 0;
  386 + mHandler.sendEmptyMessage(0);
  387 +
  388 + }
  389 +
  390 + @Override
  391 + public void onTaskProgress(double progress) {
  392 +// if (progress > 50.0) {
  393 +// request.abort();
  394 +// }
  395 + RemoteFile remoteFile = dataSource.get(item.objectKey);
  396 + remoteFile.status = RemoteFile.STATUS_DOWNLOADING;
  397 + remoteFile.progress = (int) progress;
  398 + item.status = RemoteFile.STATUS_DOWNLOADING;
  399 + item.progress = (int) progress;
  400 + mHandler.sendEmptyMessage(0);
  401 + }
  402 +
  403 + @Override
  404 + public void onTaskFinish() {
  405 + RemoteFile remoteFile = dataSource.get(item.objectKey);
  406 + remoteFile.status = RemoteFile.STATUS_FINISH;
  407 + remoteFile.progress = 100;
  408 + item.status = RemoteFile.STATUS_FINISH;
  409 + item.progress = 100;
  410 + mHandler.sendEmptyMessage(0);
  411 + }
  412 +
  413 + @Override
  414 + public void onTaskCancel() {
  415 + Log.d(com.ksyun.ks3.util.Constants.LOG_TAG, "cancle ok");
  416 + }
  417 +
  418 + @Override
  419 + public void onTaskFailure(int paramInt, Ks3Error ks3Error,
  420 + Header[] paramArrayOfHeader, Throwable paramThrowable,
  421 + File paramFile) {
  422 + Log.d(com.ksyun.ks3.util.Constants.LOG_TAG,
  423 + paramInt + "failure: reason = " + paramThrowable.toString() + "/n" + "response:" + ks3Error.getErrorMessage());
  424 + RemoteFile remoteFile = dataSource.get(item.objectKey);
  425 + remoteFile.status = RemoteFile.STATUS_FAIL;
  426 + item.status = RemoteFile.STATUS_FAIL;
  427 + mHandler.sendEmptyMessage(0);
  428 + }
  429 + });
  430 + }
  431 +
  432 + }
  433 +
  434 + @SuppressLint("HandlerLeak")
  435 + class myHandler extends Handler {
  436 + @Override
  437 + public void handleMessage(Message msg) {
  438 + int what = msg.what;
  439 + switch (what) {
  440 + case 0:
  441 + adapter.updateCurrent();
  442 + break;
  443 + default:
  444 + break;
  445 + }
  446 + }
  447 + }
  448 +
  449 +}
... ...
app/src/main/java/com/cnlive/demo/rdupload/Ks3ClientFactory.java 0 → 100644
  1 +++ a/app/src/main/java/com/cnlive/demo/rdupload/Ks3ClientFactory.java
  1 +package com.cnlive.demo.rdupload;
  2 +
  3 +import android.content.Context;
  4 +
  5 +import com.cnlive.lib.rdupload.network.HttpTask;
  6 +import com.ksyun.ks3.services.AuthListener;
  7 +import com.ksyun.ks3.services.Ks3Client;
  8 +import com.ksyun.ks3.services.Ks3ClientConfiguration;
  9 +
  10 +public class Ks3ClientFactory {
  11 + private Ks3Client ks3Client;
  12 + private Ks3ClientConfiguration configuration;
  13 + private HttpTask httpTask;
  14 +
  15 + public Ks3ClientFactory() {
  16 + httpTask = new HttpTask();
  17 + }
  18 +
  19 + public Ks3Client getDefaultClient(Context context) {
  20 + if (ks3Client == null) {
  21 + configuration = Ks3ClientConfiguration.getDefaultConfiguration();
  22 + ks3Client = new Ks3Client(new AuthListener() {
  23 + @Override
  24 + public String onCalculateAuth(String s, String s1, String s2, String s3, String s4, String s5) {
  25 + return httpTask.requestTokenToAppServer(s, s1, s2, s3, s4, s5).getAuthorization();
  26 + }
  27 + }, context);
  28 + ks3Client.setConfiguration(configuration);
  29 + ks3Client.setEndpoint(Constants.END_POINT);
  30 + }
  31 + return ks3Client;
  32 + }
  33 +
  34 +}
... ...
app/src/main/java/com/cnlive/demo/rdupload/MainActivity.java 0 → 100644
  1 +++ a/app/src/main/java/com/cnlive/demo/rdupload/MainActivity.java
  1 +package com.cnlive.demo.rdupload;
  2 +
  3 +import java.io.File;
  4 +import java.io.IOException;
  5 +import java.io.UnsupportedEncodingException;
  6 +import java.util.ArrayList;
  7 +import java.util.HashSet;
  8 +import java.util.List;
  9 +
  10 +import org.apache.http.Header;
  11 +import org.apache.http.HttpResponse;
  12 +import org.apache.http.client.ClientProtocolException;
  13 +import org.apache.http.client.methods.HttpPost;
  14 +import org.apache.http.entity.StringEntity;
  15 +import org.apache.http.impl.client.DefaultHttpClient;
  16 +import org.apache.http.util.EntityUtils;
  17 +import org.json.JSONException;
  18 +import org.json.JSONObject;
  19 +
  20 +import android.app.Activity;
  21 +import android.app.AlertDialog.Builder;
  22 +import android.content.Intent;
  23 +import android.os.Bundle;
  24 +import android.os.Environment;
  25 +import android.util.Log;
  26 +import android.view.Menu;
  27 +import android.view.View;
  28 +import android.widget.AdapterView;
  29 +import android.widget.AdapterView.OnItemClickListener;
  30 +import android.widget.ArrayAdapter;
  31 +import android.widget.ListView;
  32 +import android.widget.TextView;
  33 +import android.widget.Toast;
  34 +
  35 +import com.cnlive.lib.rdupload.network.HttpTask;
  36 +import com.ksyun.ks3.exception.Ks3Error;
  37 +import com.ksyun.ks3.model.Bucket;
  38 +import com.ksyun.ks3.model.Ks3ObjectSummary;
  39 +import com.ksyun.ks3.model.ObjectListing;
  40 +import com.ksyun.ks3.model.ObjectMetadata;
  41 +import com.ksyun.ks3.model.Owner;
  42 +import com.ksyun.ks3.model.acl.AccessControlPolicy;
  43 +import com.ksyun.ks3.model.acl.CannedAccessControlList;
  44 +import com.ksyun.ks3.model.acl.Grant;
  45 +import com.ksyun.ks3.model.result.HeadObjectResult;
  46 +import com.ksyun.ks3.model.result.ListPartsResult;
  47 +import com.ksyun.ks3.services.AuthListener;
  48 +import com.ksyun.ks3.services.Ks3Client;
  49 +import com.ksyun.ks3.services.Ks3ClientConfiguration;
  50 +import com.ksyun.ks3.services.handler.CreateBucketResponceHandler;
  51 +import com.ksyun.ks3.services.handler.DeleteBucketResponceHandler;
  52 +import com.ksyun.ks3.services.handler.DeleteObjectRequestHandler;
  53 +import com.ksyun.ks3.services.handler.GetBucketACLResponceHandler;
  54 +import com.ksyun.ks3.services.handler.GetObjectACLResponseHandler;
  55 +import com.ksyun.ks3.services.handler.HeadBucketResponseHandler;
  56 +import com.ksyun.ks3.services.handler.HeadObjectResponseHandler;
  57 +import com.ksyun.ks3.services.handler.ListBucketsResponceHandler;
  58 +import com.ksyun.ks3.services.handler.ListObjectsResponseHandler;
  59 +import com.ksyun.ks3.services.handler.ListPartsResponseHandler;
  60 +import com.ksyun.ks3.services.handler.PutBucketACLResponseHandler;
  61 +import com.ksyun.ks3.services.handler.PutObjectACLResponseHandler;
  62 +import com.ksyun.ks3.services.handler.PutObjectResponseHandler;
  63 +import com.ksyun.ks3.services.request.DeleteObjectRequest;
  64 +import com.ksyun.ks3.services.request.ListObjectsRequest;
  65 +import com.ksyun.ks3.services.request.PutBucketACLRequest;
  66 +import com.ksyun.ks3.services.request.PutObjectACLRequest;
  67 +
  68 +/**
  69 + * 包含一系列资源管理操作Api使用示例
  70 + */
  71 +public class MainActivity extends Activity {
  72 +
  73 + private static final String API = "api";
  74 + private static final String RESULT = "result";
  75 + private Ks3ClientConfiguration configuration;
  76 + private Ks3Client client;
  77 + private TextView resultTv;
  78 + private ListView commandList;
  79 + private String[] command_array;
  80 + private Builder bucketDialogBuilder;
  81 + // Bucket
  82 + public static final int LIST_BUCKETS = 0;
  83 + public static final int CREATE_BUCKET = 1;
  84 + public static final int GET_BUCKET_ACL = 2;
  85 + public static final int PUT_BUCKET_ACL = 3;
  86 + public static final int HEAD_BUCKET = 4;
  87 + public static final int DELETE_BUCKET = 5;
  88 + // Object
  89 + public static final int GET_OBJECT = 6;
  90 + public static final int HEAD_OBJECT = 7;
  91 + public static final int PUT_OBJECT = 8;
  92 + public static final int DELETE_OBJECT = 9;
  93 + public static final int GET_OBJECT_ACL = 10;
  94 + public static final int PUT_OBJECT_ACL = 11;
  95 + public static final int LIST_OBJECTS = 12;
  96 + // Upload
  97 + public static final int UPLOAD = 13;
  98 + // Download
  99 + public static final int DOWNLOAD = 14;
  100 + public static final int LIST_PART = 15;
  101 + public static final int MultiPartUpload = 16;
  102 +
  103 + private BucketInpuDialog bucketInpuDialog;
  104 + private BucketObjectInpuDialog bucketObjectInpuDialog;
  105 + private HttpTask httpTask;
  106 +
  107 + @Override
  108 + protected void onCreate(Bundle savedInstanceState) {
  109 + super.onCreate(savedInstanceState);
  110 + setContentView(R.layout.activity_dummy);
  111 + setUpKs3Client();
  112 + setUpUserInterface();
  113 + }
  114 +
  115 + private void setUpUserInterface() {
  116 + bucketInpuDialog = new BucketInpuDialog(MainActivity.this);
  117 + bucketObjectInpuDialog = new BucketObjectInpuDialog(MainActivity.this);
  118 + commandList = (ListView) findViewById(R.id.command_list);
  119 + command_array = getResources().getStringArray(R.array.command_array);
  120 + commandList.setAdapter(new ArrayAdapter<String>(this,
  121 + android.R.layout.simple_list_item_1, command_array));
  122 + commandList.setOnItemClickListener(new OnItemClickListener() {
  123 + @Override
  124 + public void onItemClick(AdapterView<?> arg0, View arg1,
  125 + int position, long arg3) {
  126 + switch (position) {
  127 + case UPLOAD:
  128 + Intent intent_upload = new Intent(MainActivity.this,
  129 + UploadActivity.class);
  130 + startActivity(intent_upload);
  131 + break;
  132 + case DOWNLOAD:
  133 + Intent intent_download = new Intent(MainActivity.this,
  134 + DownloadActivity.class);
  135 + startActivity(intent_download);
  136 + break;
  137 + case LIST_BUCKETS:
  138 + listBuckets();
  139 + break;
  140 + case CREATE_BUCKET:
  141 + createBucket();
  142 + break;
  143 + case GET_BUCKET_ACL:
  144 + getBucketACL();
  145 + break;
  146 + case PUT_BUCKET_ACL:
  147 + putBucketACL();
  148 + break;
  149 + case HEAD_BUCKET:
  150 + headBucket();
  151 + break;
  152 + case DELETE_BUCKET:
  153 + deleteBucket();
  154 + break;
  155 + case GET_OBJECT:
  156 + getObject();
  157 + break;
  158 + case HEAD_OBJECT:
  159 + headObject();
  160 + break;
  161 + case PUT_OBJECT:
  162 + putObject();
  163 + break;
  164 + case DELETE_OBJECT:
  165 + deleteObject();
  166 + break;
  167 + case GET_OBJECT_ACL:
  168 + getObjectACL();
  169 + break;
  170 + case PUT_OBJECT_ACL:
  171 + putObjectACL();
  172 + break;
  173 + case LIST_OBJECTS:
  174 + listObjects();
  175 + break;
  176 + case LIST_PART:
  177 + listParts();
  178 + break;
  179 + case MultiPartUpload:
  180 + Intent multi_upload = new Intent(MainActivity.this,
  181 + MultiUploadActivity.class);
  182 + startActivity(multi_upload);
  183 + break;
  184 + default:
  185 + break;
  186 + }
  187 + }
  188 +
  189 + });
  190 + }
  191 +
  192 + private void putObject() {
  193 + final File file = new File(Environment.getExternalStorageDirectory()
  194 + + File.separator + Constants.TEST_IMG);
  195 +
  196 + bucketObjectInpuDialog
  197 + .setOnBucketObjectDialogListener(new BucketObjectInpuDialog.OnBucketObjectDialogListener() {
  198 + @Override
  199 + public void confirmBucketAndObject(String name, String key) {
  200 + client.putObject(name, key, file,
  201 + new PutObjectResponseHandler() {
  202 +
  203 + @Override
  204 + public void onTaskSuccess(int statesCode,
  205 + Header[] responceHeaders) {
  206 + StringBuffer stringBuffer = new StringBuffer();
  207 + stringBuffer.append(
  208 + "upload file success,file = "
  209 + + Constants.TEST_IMG
  210 + + ",states code = "
  211 + + statesCode).append(
  212 + "\n");
  213 +
  214 + Intent intent = new Intent(
  215 + MainActivity.this,
  216 + RESTAPITestResult.class);
  217 +
  218 + Bundle data = new Bundle();
  219 + data.putString(RESULT,
  220 + stringBuffer.toString());
  221 + data.putString(API, "put object Result");
  222 + intent.putExtras(data);
  223 + startActivity(intent);
  224 + }
  225 +
  226 + @Override
  227 + public void onTaskStart() {
  228 +
  229 + }
  230 +
  231 + @Override
  232 + public void onTaskFinish() {
  233 +
  234 + }
  235 +
  236 + @Override
  237 + public void onTaskProgress(double progress) {
  238 +
  239 + }
  240 +
  241 + @Override
  242 + public void onTaskCancel() {
  243 + // TODO Auto-generated method stub
  244 +
  245 + }
  246 +
  247 + @Override
  248 + public void onTaskFailure(int statesCode,
  249 + Ks3Error error,
  250 + Header[] responceHeaders,
  251 + String response,
  252 + Throwable paramThrowable) {
  253 + StringBuffer stringBuffer = new StringBuffer();
  254 + stringBuffer.append(
  255 + "upload file failure,file = "
  256 + + Constants.TEST_IMG
  257 + + ",states code = "
  258 + + statesCode).append(
  259 + "\n").append("response:").append(response);
  260 +
  261 + }
  262 + });
  263 + }
  264 + });
  265 + bucketObjectInpuDialog.show();
  266 +
  267 + }
  268 +
  269 + protected void listParts() {
  270 + bucketObjectInpuDialog
  271 + .setOnBucketObjectDialogListener(new BucketObjectInpuDialog.OnBucketObjectDialogListener() {
  272 + @Override
  273 + public void confirmBucketAndObject(String name, String key) {
  274 +
  275 + client.listParts(name, key, Constants.UPLOAD_ID,
  276 + new ListPartsResponseHandler() {
  277 +
  278 + @Override
  279 + public void onSuccess(int statesCode,
  280 + Header[] responceHeaders,
  281 + ListPartsResult listPartsResult) {
  282 +
  283 + }
  284 +
  285 + @Override
  286 + public void onFailure(int statesCode,
  287 + Ks3Error error,
  288 + Header[] responceHeaders,
  289 + String response,
  290 + Throwable paramThrowable) {
  291 + // TODO Auto-generated method stub
  292 +
  293 + }
  294 + });
  295 + }
  296 + });
  297 + bucketObjectInpuDialog.show();
  298 +
  299 + }
  300 +
  301 + private void setUpKs3Client() {
  302 + // 使用AuthListener方式鉴权
  303 + if (httpTask == null) httpTask = new HttpTask();
  304 + client = new Ks3Client(new AuthListener() {
  305 + @Override
  306 + public String onCalculateAuth(String s, String s1, String s2, String s3, String s4, String s5) {
  307 + return httpTask.requestTokenToAppServer(s, s1, s2, s3, s4, s5).getAuthorization();
  308 + }
  309 + }, this);
  310 + client.setEndpoint("ks3-cn-beijing.ksyun.com");
  311 + configuration = Ks3ClientConfiguration.getDefaultConfiguration();
  312 + client.setConfiguration(configuration);
  313 +
  314 + }
  315 +
  316 + @Override
  317 + public boolean onCreateOptionsMenu(Menu menu) {
  318 + getMenuInflater().inflate(R.menu.main, menu);
  319 + return true;
  320 + }
  321 +
  322 + //这块有疑问,没进行操作
  323 + protected void getObject() {
  324 + Toast.makeText(MainActivity.this, "Please See Download Activity",
  325 + Toast.LENGTH_SHORT).show();
  326 + }
  327 +
  328 + private void headObject() {
  329 + bucketObjectInpuDialog
  330 + .setOnBucketObjectDialogListener(new BucketObjectInpuDialog.OnBucketObjectDialogListener() {
  331 + @Override
  332 + public void confirmBucketAndObject(String name, String key) {
  333 + client.headObject(name, key,
  334 + new HeadObjectResponseHandler() {
  335 + @Override
  336 + public void onSuccess(int statesCode,
  337 + Header[] responceHeaders,
  338 + HeadObjectResult headObjectResult) {
  339 +
  340 + StringBuffer stringBuffer = new StringBuffer();
  341 + stringBuffer
  342 + .append("lastModifiedDate = "
  343 + + headObjectResult
  344 + .getLastmodified())
  345 + .append("\n");
  346 + stringBuffer.append(
  347 + "ETag = "
  348 + + headObjectResult
  349 + .getETag())
  350 + .append("\n");
  351 + ObjectMetadata metadata = headObjectResult
  352 + .getObjectMetadata();
  353 + stringBuffer.append(metadata);
  354 + Intent intent = new Intent(
  355 + MainActivity.this,
  356 + RESTAPITestResult.class);
  357 +
  358 + Bundle data = new Bundle();
  359 + data.putString(RESULT,
  360 + stringBuffer.toString());
  361 + data.putString(API,
  362 + "head object Result");
  363 + intent.putExtras(data);
  364 + startActivity(intent);
  365 +
  366 + }
  367 +
  368 + @Override
  369 + public void onFailure(int statesCode,
  370 + Ks3Error error,
  371 + Header[] responceHeaders,
  372 + String response,
  373 + Throwable paramThrowable) {
  374 + StringBuffer stringBuffer = new StringBuffer();
  375 + stringBuffer.append(
  376 + "head object , states code :"
  377 + + statesCode).append(
  378 + "\n");
  379 + stringBuffer.append("Exception :"
  380 + + paramThrowable.toString());
  381 + Intent intent = new Intent(
  382 + MainActivity.this,
  383 + RESTAPITestResult.class);
  384 + Bundle data = new Bundle();
  385 + data.putString(RESULT,
  386 + stringBuffer.toString());
  387 + data.putString(API,
  388 + "head object Result");
  389 + intent.putExtras(data);
  390 + startActivity(intent);
  391 + }
  392 + });
  393 +
  394 + }
  395 + });
  396 + bucketObjectInpuDialog.show();
  397 + }
  398 +
  399 + private void getObjectACL() {
  400 + bucketObjectInpuDialog
  401 + .setOnBucketObjectDialogListener(new BucketObjectInpuDialog.OnBucketObjectDialogListener() {
  402 + @Override
  403 + public void confirmBucketAndObject(String name, String key) {
  404 + client.getObjectACL(name, key,
  405 + new GetObjectACLResponseHandler() {
  406 +
  407 + @Override
  408 + public void onSuccess(
  409 + int statesCode,
  410 + Header[] responceHeaders,
  411 + AccessControlPolicy accessControlPolicy) {
  412 + StringBuffer stringBuffer = new StringBuffer();
  413 + Owner owner = accessControlPolicy
  414 + .getOwner();
  415 + stringBuffer
  416 + .append("=======Owner : ID "
  417 + + owner.getId()
  418 + + " ; NAME :"
  419 + + owner.getDisplayName())
  420 + .append("\n");
  421 + stringBuffer
  422 + .append("==============ACL LIST=========");
  423 + HashSet<Grant> grants = accessControlPolicy
  424 + .getAccessControlList()
  425 + .getGrants();
  426 + for (Grant grant : grants) {
  427 + stringBuffer
  428 + .append(grant.getGrantee()
  429 + .getIdentifier()
  430 + + "========>"
  431 + + grant.getPermission()
  432 + .toString())
  433 + .append("\n");
  434 + }
  435 + Intent intent = new Intent(
  436 + MainActivity.this,
  437 + RESTAPITestResult.class);
  438 +
  439 + Bundle data = new Bundle();
  440 + data.putString(RESULT,
  441 + stringBuffer.toString());
  442 + data.putString(API,
  443 + "head object Result");
  444 + intent.putExtras(data);
  445 + startActivity(intent);
  446 +
  447 + }
  448 +
  449 + @Override
  450 + public void onFailure(int statesCode,
  451 + Ks3Error error,
  452 + Header[] responceHeaders,
  453 + String response,
  454 + Throwable paramThrowable) {
  455 + StringBuffer stringBuffer = new StringBuffer();
  456 + stringBuffer.append(
  457 + "get object ACL FAIL !!!!!!, states code :"
  458 + + statesCode).append(
  459 + "\n").append("response:").append(response);
  460 + stringBuffer.append("Exception :"
  461 + + paramThrowable.toString());
  462 + Intent intent = new Intent(
  463 + MainActivity.this,
  464 + RESTAPITestResult.class);
  465 + Bundle data = new Bundle();
  466 + data.putString(RESULT,
  467 + stringBuffer.toString());
  468 + data.putString(API,
  469 + "GET Object ACL Result");
  470 + intent.putExtras(data);
  471 + startActivity(intent);
  472 + }
  473 + });
  474 +
  475 + }
  476 + });
  477 + bucketObjectInpuDialog.show();
  478 + }
  479 +
  480 + private void deleteBucket() {
  481 + bucketInpuDialog.setOnBucketInputListener(new BucketInpuDialog.OnBucketDialogListener() {
  482 + @Override
  483 + public void confirmBucket(String name) {
  484 + client.deleteBucket(name, new DeleteBucketResponceHandler() {
  485 +
  486 + @Override
  487 + public void onSuccess(int statesCode,
  488 + Header[] responceHeaders) {
  489 + Intent intent = new Intent(MainActivity.this,
  490 + RESTAPITestResult.class);
  491 + Bundle data = new Bundle();
  492 + StringBuffer stringBuffer = new StringBuffer();
  493 + stringBuffer
  494 + .append("Delete bucket success , states code :"
  495 + + statesCode);
  496 + data.putString(RESULT, stringBuffer.toString());
  497 + data.putString(API, "Delete Bucket Result");
  498 + intent.putExtras(data);
  499 + startActivity(intent);
  500 + }
  501 +
  502 + @Override
  503 + public void onFailure(int statesCode, Ks3Error error,
  504 + Header[] responceHeaders, String response,
  505 + Throwable paramThrowable) {
  506 + Intent intent = new Intent(MainActivity.this,
  507 + RESTAPITestResult.class);
  508 + Bundle data = new Bundle();
  509 + StringBuffer stringBuffer = new StringBuffer();
  510 + stringBuffer
  511 + .append("Delete bucket failed , states code :"
  512 + + statesCode).append("/n").append("responce:").append(response);
  513 + data.putString(RESULT, stringBuffer.toString());
  514 + data.putString(API, "Delete Bucket Result");
  515 + intent.putExtras(data);
  516 + startActivity(intent);
  517 + }
  518 + });
  519 + }
  520 + });
  521 + bucketInpuDialog.show();
  522 + }
  523 +
  524 + private void putObjectACL() {
  525 + bucketObjectInpuDialog
  526 + .setOnBucketObjectDialogListener(new BucketObjectInpuDialog.OnBucketObjectDialogListener() {
  527 + @Override
  528 + public void confirmBucketAndObject(String name, String key) {
  529 + PutObjectACLRequest request = new PutObjectACLRequest(
  530 + name, key);
  531 + CannedAccessControlList cannedList = CannedAccessControlList.PublicRead;
  532 + // AccessControlList acList = new AccessControlList();
  533 +
  534 + // GranteeId grantee = new GranteeId();
  535 + // grantee.setIdentifier("123456");
  536 + // grantee.setDisplayName("TESTTEST1");
  537 + // acList.addGrant(grantee, Permission.Read);
  538 + // GranteeId grantee1 = new GranteeId();
  539 + // grantee1.setIdentifier("1235789");
  540 + // grantee1.setDisplayName("TESTTEST1");
  541 + // acList.addGrant(grantee1, Permission.FullControl);
  542 + //
  543 + // request.setAccessControlList(acList);
  544 + request.setCannedAcl(cannedList);
  545 +
  546 + client.putObjectACL(request,
  547 + new PutObjectACLResponseHandler() {
  548 +
  549 + @Override
  550 + public void onSuccess(int statesCode,
  551 + Header[] responceHeaders) {
  552 + StringBuffer stringBuffer = new StringBuffer();
  553 + stringBuffer
  554 + .append("Put Object ACL success , states code :"
  555 + + statesCode);
  556 + Intent intent = new Intent(
  557 + MainActivity.this,
  558 + RESTAPITestResult.class);
  559 + Bundle data = new Bundle();
  560 + data.putString(RESULT,
  561 + stringBuffer.toString());
  562 + data.putString(API,
  563 + "Put Object ACL Result");
  564 + intent.putExtras(data);
  565 + startActivity(intent);
  566 +
  567 + }
  568 +
  569 + @Override
  570 + public void onFailure(int statesCode,
  571 + Ks3Error error,
  572 + Header[] responceHeaders,
  573 + String response,
  574 + Throwable paramThrowable) {
  575 + StringBuffer stringBuffer = new StringBuffer();
  576 + stringBuffer.append(
  577 + "PUT Object ACL FAIL !!!!!!!!!, states code :"
  578 + + statesCode).append(
  579 + "\n").append("responce:").append(response);
  580 + stringBuffer.append("Exception :"
  581 + + paramThrowable.toString());
  582 + Intent intent = new Intent(
  583 + MainActivity.this,
  584 + RESTAPITestResult.class);
  585 + Bundle data = new Bundle();
  586 + data.putString(RESULT,
  587 + stringBuffer.toString());
  588 + data.putString(API,
  589 + "PUT Object ACL Result");
  590 + intent.putExtras(data);
  591 + startActivity(intent);
  592 + }
  593 + });
  594 + }
  595 + });
  596 + bucketObjectInpuDialog.show();
  597 + }
  598 +
  599 + private void headBucket() {
  600 + bucketInpuDialog.setOnBucketInputListener(new BucketInpuDialog.OnBucketDialogListener() {
  601 + @Override
  602 + public void confirmBucket(String name) {
  603 + client.headBucket(name, new HeadBucketResponseHandler() {
  604 + @Override
  605 + public void onSuccess(int statesCode,
  606 + Header[] responceHeaders) {
  607 + StringBuffer stringBuffer = new StringBuffer();
  608 + stringBuffer
  609 + .append("head Bucket success , states code :"
  610 + + statesCode);
  611 + Intent intent = new Intent(MainActivity.this,
  612 + RESTAPITestResult.class);
  613 + Bundle data = new Bundle();
  614 + data.putString(RESULT, stringBuffer.toString());
  615 + data.putString(API, "head Bucket Result");
  616 + intent.putExtras(data);
  617 + startActivity(intent);
  618 + }
  619 +
  620 + @Override
  621 + public void onFailure(int statesCode, Ks3Error error,
  622 + Header[] responceHeaders, String response,
  623 + Throwable paramThrowable) {
  624 + StringBuffer stringBuffer = new StringBuffer();
  625 + stringBuffer.append(
  626 + "head Bucket Fail, states code :" + statesCode)
  627 + .append("\n").append("response:").append(response);
  628 + stringBuffer.append("Exception :"
  629 + + paramThrowable.toString());
  630 + Intent intent = new Intent(MainActivity.this,
  631 + RESTAPITestResult.class);
  632 + Bundle data = new Bundle();
  633 + data.putString(RESULT, stringBuffer.toString());
  634 + data.putString(API, "head Bucket Result");
  635 + intent.putExtras(data);
  636 + startActivity(intent);
  637 + }
  638 + });
  639 + }
  640 + });
  641 + bucketInpuDialog.show();
  642 + }
  643 +
  644 + private void putBucketACL() {
  645 + bucketInpuDialog.setOnBucketInputListener(new BucketInpuDialog.OnBucketDialogListener() {
  646 + @Override
  647 + public void confirmBucket(String name) {
  648 + PutBucketACLRequest request = new PutBucketACLRequest(name);
  649 + // AccessControlList acl = new AccessControlList();
  650 + // // GranteeUri urigrantee = GranteeUri.AllUsers;
  651 + // // Permission permission = Permission.Read;
  652 + //
  653 + // GranteeEmail email = new GranteeEmail();
  654 + // email.setEmail("guoli@gmail.com");
  655 + // Permission permission = Permission.Read;
  656 + // Grant g = new Grant(email, permission);
  657 + //
  658 + // GranteeUri uirGroup = GranteeUri.AllUsers;
  659 + // Permission uripermission = Permission.Read;
  660 + // Grant g1 = new Grant(uirGroup, uripermission);
  661 +
  662 + // acl.addGrant(g);
  663 + // acl.addGrant(g1);
  664 +
  665 + // GranteeId grantee = new GranteeId() ;
  666 + // grantee.setIdentifier("12773456");
  667 + // grantee.setDisplayName("guoliTest222");
  668 + // acl.addGrant(grantee, Permission.Read);
  669 +
  670 + // GranteeId grantee1 = new GranteeId() ;
  671 + // grantee1.setIdentifier("123005789");
  672 + // grantee1.setDisplayName("guoliTest2D2");
  673 + // acl.addGrant(grantee1, Permission.Write);
  674 +
  675 + // request.setAccessControlList(acl) ;
  676 +
  677 + CannedAccessControlList cannedAcl = CannedAccessControlList.PublicReadWrite;
  678 + request.setCannedAcl(cannedAcl);
  679 + // request.setAccessControlList(acl);
  680 + client.putBucketACL(request, new PutBucketACLResponseHandler() {
  681 +
  682 + @Override
  683 + public void onSuccess(int statesCode,
  684 + Header[] responceHeaders) {
  685 + StringBuffer stringBuffer = new StringBuffer();
  686 + stringBuffer
  687 + .append("Put Bucket ACL success, states code :"
  688 + + statesCode);
  689 + Intent intent = new Intent(MainActivity.this,
  690 + RESTAPITestResult.class);
  691 + Bundle data = new Bundle();
  692 + data.putString(RESULT, stringBuffer.toString());
  693 + data.putString(API, "Put Bucket ACL Result");
  694 + intent.putExtras(data);
  695 + startActivity(intent);
  696 + }
  697 +
  698 + @Override
  699 + public void onFailure(int statesCode, Ks3Error error,
  700 + Header[] responceHeaders, String response,
  701 + Throwable paramThrowable) {
  702 + StringBuffer stringBuffer = new StringBuffer();
  703 + stringBuffer.append(
  704 + "PUT Bucket ACL FAIL, states code :"
  705 + + statesCode).append("\n").append("responce :").append(response);
  706 + stringBuffer.append("Exception :"
  707 + + paramThrowable.toString());
  708 + Intent intent = new Intent(MainActivity.this,
  709 + RESTAPITestResult.class);
  710 + Bundle data = new Bundle();
  711 + data.putString(RESULT, stringBuffer.toString());
  712 + data.putString(API, "PUT Bucket ACL Result");
  713 + intent.putExtras(data);
  714 + startActivity(intent);
  715 + }
  716 + });
  717 + }
  718 + });
  719 + bucketInpuDialog.show();
  720 +
  721 + }
  722 +
  723 + private void getBucketACL() {
  724 + bucketInpuDialog.setOnBucketInputListener(new BucketInpuDialog.OnBucketDialogListener() {
  725 + @Override
  726 + public void confirmBucket(String name) {
  727 + client.getBucketACL(name, new GetBucketACLResponceHandler() {
  728 +
  729 + @Override
  730 + public void onSuccess(int statesCode,
  731 + Header[] responceHeaders,
  732 + AccessControlPolicy accessControlPolicy) {
  733 + StringBuffer stringBuffer = new StringBuffer();
  734 + Owner owner = accessControlPolicy.getOwner();
  735 + stringBuffer.append(
  736 + "=======Owner : ID " + owner.getId()
  737 + + " ; NAME :" + owner.getDisplayName())
  738 + .append("\n");
  739 + stringBuffer.append("==============ACL LIST=========");
  740 + HashSet<Grant> grants = accessControlPolicy
  741 + .getAccessControlList().getGrants();
  742 + for (Grant grant : grants) {
  743 + stringBuffer.append(
  744 + grant.getGrantee().getIdentifier()
  745 + + "========>"
  746 + + grant.getPermission().toString())
  747 + .append("\n");
  748 + }
  749 + Intent intent = new Intent(MainActivity.this,
  750 + RESTAPITestResult.class);
  751 + Bundle data = new Bundle();
  752 + data.putString(RESULT, stringBuffer.toString());
  753 + data.putString(API, "GET BUCKET ACL Result");
  754 + intent.putExtras(data);
  755 + startActivity(intent);
  756 + }
  757 +
  758 + @Override
  759 + public void onFailure(int statesCode, Ks3Error error,
  760 + Header[] responceHeaders, String response,
  761 + Throwable paramThrowable) {
  762 + StringBuffer stringBuffer = new StringBuffer();
  763 + stringBuffer.append(
  764 + "GET BUCKET ACL fail , states code :"
  765 + + statesCode).append("\n").append("response = ").append(response);
  766 + stringBuffer.append("Exception :"
  767 + + paramThrowable.toString());
  768 + Intent intent = new Intent(MainActivity.this,
  769 + RESTAPITestResult.class);
  770 + Bundle data = new Bundle();
  771 + data.putString(RESULT, stringBuffer.toString());
  772 + data.putString(API, "GET BUCKET ACL Result");
  773 + intent.putExtras(data);
  774 + startActivity(intent);
  775 + }
  776 + });
  777 + }
  778 + });
  779 + bucketInpuDialog.show();
  780 +
  781 + }
  782 +
  783 + private void deleteObject() {
  784 + bucketObjectInpuDialog
  785 + .setOnBucketObjectDialogListener(new BucketObjectInpuDialog.OnBucketObjectDialogListener() {
  786 + @Override
  787 + public void confirmBucketAndObject(String name, String key) {
  788 + DeleteObjectRequest request = new DeleteObjectRequest(
  789 + name, key);
  790 + client.deleteObject(request,
  791 + new DeleteObjectRequestHandler() {
  792 +
  793 + @Override
  794 + public void onSuccess(int statesCode,
  795 + Header[] responceHeaders) {
  796 + StringBuffer stringBuffer = new StringBuffer();
  797 + stringBuffer
  798 + .append("Delete success , states code :"
  799 + + statesCode);
  800 + Intent intent = new Intent(
  801 + MainActivity.this,
  802 + RESTAPITestResult.class);
  803 + Bundle data = new Bundle();
  804 + data.putString(RESULT,
  805 + stringBuffer.toString());
  806 + data.putString(API,
  807 + "Delete Object Result");
  808 + intent.putExtras(data);
  809 + startActivity(intent);
  810 + }
  811 +
  812 + @Override
  813 + public void onFailure(int statesCode,
  814 + Ks3Error error,
  815 + Header[] responceHeaders,
  816 + String response,
  817 + Throwable paramThrowable) {
  818 + StringBuffer stringBuffer = new StringBuffer();
  819 + stringBuffer.append(
  820 + "Delete fail , states code :"
  821 + + statesCode).append(
  822 + "\n").append("response:").append(response);
  823 + stringBuffer.append("Exception :"
  824 + + paramThrowable.toString());
  825 + Intent intent = new Intent(
  826 + MainActivity.this,
  827 + RESTAPITestResult.class);
  828 + Bundle data = new Bundle();
  829 + data.putString(RESULT,
  830 + stringBuffer.toString());
  831 + data.putString(API,
  832 + "Delete Object Result");
  833 + intent.putExtras(data);
  834 + startActivity(intent);
  835 + }
  836 + });
  837 + }
  838 + });
  839 + bucketObjectInpuDialog.show();
  840 +
  841 + }
  842 +
  843 + private void listObjects() {
  844 + bucketInpuDialog.setOnBucketInputListener(new BucketInpuDialog.OnBucketDialogListener() {
  845 + @Override
  846 + public void confirmBucket(String name) {
  847 + ListObjectsRequest request = new ListObjectsRequest(name);
  848 + // request.setPrefix("android_test/");
  849 + // request.setDelimiter("/");
  850 + client.listObjects(request, new ListObjectsResponseHandler() {
  851 +
  852 + @Override
  853 + public void onSuccess(int statesCode,
  854 + Header[] responceHeaders,
  855 + ObjectListing objectListing) {
  856 + StringBuffer stringBuffer = new StringBuffer();
  857 + stringBuffer.append(
  858 + "name = " + objectListing.getBucketName())
  859 + .append("\n");
  860 + stringBuffer.append(
  861 + "Prefix = " + objectListing.getPrefix())
  862 + .append("\n");
  863 + stringBuffer.append(
  864 + "Marker = " + objectListing.getMarker())
  865 + .append("\n");
  866 + stringBuffer.append(
  867 + "Delimiter = " + objectListing.getDelimiter())
  868 + .append("\n");
  869 + stringBuffer.append(
  870 + "IsTruncated = " + objectListing.isTruncated())
  871 + .append("\n");
  872 + List<Ks3ObjectSummary> objectSummaries = objectListing
  873 + .getObjectSummaries();
  874 + Ks3ObjectSummary objectSummary = null;
  875 + Owner owner = null;
  876 + for (int i = 0; i < objectSummaries.size(); i++) {
  877 + objectSummary = objectSummaries.get(i);
  878 + owner = objectSummary.getOwner();
  879 + stringBuffer.append(
  880 + "================Object :" + i
  881 + + " ===================").append(
  882 + "\n");
  883 + stringBuffer.append(
  884 + " key ="
  885 + + objectSummary.getKey()).append(
  886 + "\n");
  887 + stringBuffer.append(
  888 + " LastModified ="
  889 + + objectSummary.getLastModified())
  890 + .append("\n");
  891 + stringBuffer.append(
  892 + " ETag =" + objectSummary.getETag())
  893 + .append("\n");
  894 + stringBuffer.append(
  895 + " Size =" + objectSummary.getSize())
  896 + .append("\n");
  897 + stringBuffer.append(
  898 + " owner.ID =" + owner.getId())
  899 + .append("\n");
  900 + stringBuffer.append(
  901 + " Size.displayName ="
  902 + + owner.getDisplayName()).append(
  903 + "\n");
  904 + stringBuffer.append(
  905 + " StorageClass = "
  906 + + objectSummary.getStorageClass())
  907 + .append("\n");
  908 + }
  909 +
  910 + List<String> commonPrefixes = objectListing
  911 + .getCommonPrefixes();
  912 + for (int i = 0; i < commonPrefixes.size(); i++) {
  913 + stringBuffer.append(
  914 + " commonPrefixes =>" + i + "="
  915 + + objectSummary.getStorageClass())
  916 + .append("\n");
  917 + }
  918 + Intent intent = new Intent(MainActivity.this,
  919 + RESTAPITestResult.class);
  920 + Bundle data = new Bundle();
  921 + data.putString(RESULT, stringBuffer.toString());
  922 + data.putString(API, "RESULT for ListObjects");
  923 + intent.putExtras(data);
  924 + startActivity(intent);
  925 + }
  926 +
  927 + @Override
  928 + public void onFailure(int statesCode, Ks3Error error,
  929 + Header[] responceHeaders, String response,
  930 + Throwable paramThrowable) {
  931 + // TODO Auto-generated method stub
  932 +
  933 + }
  934 + });
  935 + }
  936 + });
  937 + bucketInpuDialog.show();
  938 +
  939 + }
  940 +
  941 + private void listBuckets() {
  942 + client.listBuckets(new ListBucketsResponceHandler() {
  943 + @Override
  944 + public void onSuccess(int paramInt, Header[] paramArrayOfHeader,
  945 + ArrayList<Bucket> resultList) {
  946 + StringBuffer stringBuffer = new StringBuffer();
  947 + for (Bucket bucket : resultList) {
  948 + stringBuffer.append(bucket.getName()).append("\n");
  949 + stringBuffer.append(bucket.getCreationDate()).append("\n");
  950 + stringBuffer.append(bucket.getOwner().getDisplayName())
  951 + .append("\n");
  952 + stringBuffer.append(bucket.getOwner().getId()).append("\n");
  953 + }
  954 + Intent intent = new Intent(MainActivity.this,
  955 + RESTAPITestResult.class);
  956 + Bundle data = new Bundle();
  957 + data.putString(RESULT, stringBuffer.toString());
  958 + data.putString(API, "List Bucket Result");
  959 + intent.putExtras(data);
  960 + startActivity(intent);
  961 + }
  962 +
  963 + @Override
  964 + public void onFailure(int statesCode, Ks3Error error,
  965 + Header[] responceHeaders, String response,
  966 + Throwable paramThrowable) {
  967 + StringBuffer stringBuffer = new StringBuffer();
  968 + stringBuffer.append(
  969 + "list bucket fail , states code :" + statesCode)
  970 + .append("\n").append("responce :").append(response);
  971 + stringBuffer.append("Exception :" + paramThrowable.toString());
  972 + Intent intent = new Intent(MainActivity.this,
  973 + RESTAPITestResult.class);
  974 + Bundle data = new Bundle();
  975 + data.putString(RESULT, stringBuffer.toString());
  976 + data.putString(API, "List Buckets");
  977 + intent.putExtras(data);
  978 + startActivity(intent);
  979 + }
  980 + });
  981 + }
  982 +
  983 + private void createBucket() {
  984 + bucketInpuDialog.setOnBucketInputListener(new BucketInpuDialog.OnBucketDialogListener() {
  985 + @Override
  986 + public void confirmBucket(String name) {
  987 + client.createBucket(name, new CreateBucketResponceHandler() {
  988 + @Override
  989 + public void onSuccess(int statesCode,
  990 + Header[] responceHeaders) {
  991 + Intent intent = new Intent(MainActivity.this,
  992 + RESTAPITestResult.class);
  993 + Bundle data = new Bundle();
  994 + data.putString(RESULT, "success");
  995 + data.putString(API, "Create Bucket Result");
  996 + intent.putExtras(data);
  997 + startActivity(intent);
  998 + }
  999 +
  1000 + @Override
  1001 + public void onFailure(int statesCode, Ks3Error error,
  1002 + Header[] responceHeaders, String response,
  1003 + Throwable paramThrowable) {
  1004 + StringBuffer stringBuffer = new StringBuffer();
  1005 + stringBuffer.append(
  1006 + "Delete fail , states code :" + statesCode)
  1007 + .append("\n").append("responce :").append(response);
  1008 + stringBuffer.append("Exception :"
  1009 + + paramThrowable.toString());
  1010 + Intent intent = new Intent(MainActivity.this,
  1011 + RESTAPITestResult.class);
  1012 + Bundle data = new Bundle();
  1013 + data.putString(RESULT, stringBuffer.toString());
  1014 + data.putString(API, "List Buckets");
  1015 + intent.putExtras(data);
  1016 + startActivity(intent);
  1017 + }
  1018 + });
  1019 + }
  1020 + });
  1021 + bucketInpuDialog.show();
  1022 + }
  1023 +
  1024 +}
... ...
app/src/main/java/com/cnlive/demo/rdupload/MultiUploadActivity.java 0 → 100644
  1 +++ a/app/src/main/java/com/cnlive/demo/rdupload/MultiUploadActivity.java
  1 +package com.cnlive.demo.rdupload;
  2 +
  3 +import android.app.Activity;
  4 +import android.content.Context;
  5 +import android.os.Bundle;
  6 +import android.view.LayoutInflater;
  7 +import android.view.View;
  8 +import android.view.ViewGroup;
  9 +import android.widget.BaseAdapter;
  10 +import android.widget.Button;
  11 +import android.widget.ListView;
  12 +import android.widget.TextView;
  13 +
  14 +import com.ksyun.ks3.services.Ks3Client;
  15 +
  16 +import java.io.File;
  17 +import java.util.ArrayList;
  18 +import java.util.List;
  19 +
  20 +public class MultiUploadActivity extends Activity {
  21 +
  22 + private List<MultiUploader> fileInfos;
  23 +
  24 + @Override
  25 + protected void onCreate(Bundle savedInstanceState) {
  26 + super.onCreate(savedInstanceState);
  27 + setContentView(R.layout.activity_multi_upload);
  28 + getFileInfo();
  29 + ListView listView = (ListView) findViewById(R.id.listView);
  30 + listView.setAdapter(new ListViewAdapter(fileInfos));
  31 + }
  32 +
  33 + private void getFileInfo(){
  34 + fileInfos = new ArrayList<MultiUploader>();
  35 + Ks3ClientFactory ks3ClientFactory = new Ks3ClientFactory();
  36 + Ks3Client client = ks3ClientFactory.getDefaultClient(MultiUploadActivity.this);
  37 + fileInfos.add(new MultiUploader(client, Constants.TEST_MULTIUPLOAD_BUCKET, "11.txt",
  38 + new File(Constants.TEST_MULTIUPLOAD_FILE)));//, "bb20153e438047b3bc3212f37e25fd9c"));
  39 + fileInfos.add(new MultiUploader(client, Constants.TEST_MULTIUPLOAD_BUCKET, "11.txt",
  40 + new File(Constants.TEST_MULTIUPLOAD_FILE), "8b67c9679fae436ba754b4bafc29ca37"));
  41 + }
  42 +
  43 + public class ListViewAdapter extends BaseAdapter {
  44 + View[] itemViews;
  45 +
  46 + public ListViewAdapter(List<MultiUploader> list) {
  47 + itemViews = new View[list.size()];
  48 + for(int i=0;i<list.size();i++){
  49 + MultiUploader uploader = list.get(i);
  50 + itemViews[i]=makeItemView(uploader.getKey(), uploader);
  51 + }
  52 + }
  53 +
  54 + private View makeItemView(String key, final MultiUploader uploader) {
  55 + LayoutInflater inflater = (LayoutInflater) MultiUploadActivity.this
  56 + .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  57 + // 使用View的对象itemView与R.layout.item关联
  58 + View itemView = inflater.inflate(R.layout.multiupload_item, null);
  59 + TextView fileNameView = (TextView) itemView.findViewById(R.id.file_name);
  60 + fileNameView.setText(key);
  61 + Button btn = (Button) itemView.findViewById(R.id.uploadBtn);
  62 + btn.setOnClickListener(new View.OnClickListener() {
  63 + @Override
  64 + public void onClick(View view) {
  65 + if(uploader.getUploadId()==null)
  66 + uploader.upload();
  67 + else
  68 + uploader.reUpload();
  69 + }
  70 + });
  71 + return itemView;
  72 + }
  73 +
  74 + @Override
  75 + public int getCount() {
  76 + return itemViews.length;
  77 + }
  78 +
  79 + @Override
  80 + public Object getItem(int i) {
  81 + return itemViews[i];
  82 + }
  83 +
  84 + @Override
  85 + public long getItemId(int i) {
  86 + return i;
  87 + }
  88 +
  89 + @Override
  90 + public View getView(int i, View view, ViewGroup viewGroup) {
  91 + if (view == null)
  92 + return itemViews[i];
  93 + return view;
  94 + }
  95 + }
  96 +}
... ...
app/src/main/java/com/cnlive/demo/rdupload/MultiUploader.java 0 → 100644
  1 +++ a/app/src/main/java/com/cnlive/demo/rdupload/MultiUploader.java
  1 +package com.cnlive.demo.rdupload;
  2 +
  3 +import android.os.Handler;
  4 +import android.os.Message;
  5 +import android.util.Log;
  6 +
  7 +import com.ksyun.ks3.exception.Ks3Error;
  8 +import com.ksyun.ks3.model.Part;
  9 +import com.ksyun.ks3.model.PartETag;
  10 +import com.ksyun.ks3.model.result.CompleteMultipartUploadResult;
  11 +import com.ksyun.ks3.model.result.InitiateMultipartUploadResult;
  12 +import com.ksyun.ks3.model.result.ListPartsResult;
  13 +import com.ksyun.ks3.services.Ks3Client;
  14 +import com.ksyun.ks3.services.handler.CompleteMultipartUploadResponseHandler;
  15 +import com.ksyun.ks3.services.handler.InitiateMultipartUploadResponceHandler;
  16 +import com.ksyun.ks3.services.handler.ListPartsResponseHandler;
  17 +import com.ksyun.ks3.services.handler.UploadPartResponceHandler;
  18 +import com.ksyun.ks3.services.request.AbortMultipartUploadRequest;
  19 +import com.ksyun.ks3.services.request.InitiateMultipartUploadRequest;
  20 +import com.ksyun.ks3.services.request.ListPartsRequest;
  21 +import com.ksyun.ks3.services.request.UploadPartRequest;
  22 +
  23 +import org.apache.http.Header;
  24 +
  25 +import java.io.File;
  26 +import java.util.ArrayList;
  27 +import java.util.Collections;
  28 +import java.util.HashSet;
  29 +import java.util.List;
  30 +import java.util.Set;
  31 +import java.util.concurrent.CountDownLatch;
  32 +
  33 +/**
  34 + * Created by zhaotao on 4/27/17.
  35 + */
  36 +
  37 +public class MultiUploader {
  38 + final private String TAG = "MultiUploader";
  39 +
  40 + private String bucketName;
  41 + private String key;
  42 + private File file;
  43 + private long partSize = 5*1024*1024; // 5MB
  44 + private String uploadId;
  45 + private Ks3Client client;
  46 + final static private int INIT_DONE = 0;
  47 + final static private int PARTS_DONE = 1;
  48 + final static private int COMPLETE_DONE = 2;
  49 + final static private int GET_UPLOADED_DONE=3;
  50 +
  51 + final List<PartETag> doneParts = Collections.synchronizedList(new ArrayList());
  52 +
  53 + private void create(Ks3Client client, String bucketName, String key, File file, String uploadId, long partSize){
  54 + this.client = client;
  55 + this.bucketName = bucketName;
  56 + this.key = key;
  57 + this.file = file;
  58 + this.uploadId = uploadId;
  59 + this.partSize = partSize;
  60 + }
  61 +
  62 + public MultiUploader(Ks3Client client, String bucketName, String key, File file, String uploadId, long partSize){
  63 + create(client, bucketName,key, file, uploadId, partSize);
  64 + }
  65 +
  66 + public MultiUploader(Ks3Client client, String bucketName, String key, File file, String uploadId){
  67 + create(client, bucketName, key, file, uploadId, partSize);
  68 + }
  69 + public MultiUploader(Ks3Client client, String bucketName, String key, File file){
  70 + create(client, bucketName, key, file, null, partSize);
  71 + }
  72 + public MultiUploader(Ks3Client client, String bucketName, String key, File file, long partSize){
  73 + create(client, bucketName, key, file, null, partSize);
  74 + }
  75 +
  76 + public String getKey(){
  77 + return key;
  78 + }
  79 + public String getUploadId(){
  80 + return uploadId;
  81 + }
  82 +
  83 + abstract class MyUploadPartResponceHandler extends UploadPartResponceHandler{
  84 + private String key;
  85 + private int partNo;
  86 + private String uploadId;
  87 + public abstract void onSuccess(int statesCode, Header[] responceHeaders, PartETag result, String key, int partNo, String uploadId);
  88 + public abstract void onFailure(int statesCode, Ks3Error error, Header[] responceHeaders, String response, Throwable throwable
  89 + , String key, int partNo, String uploadId);
  90 + public abstract void onTaskProgress(double progress, String key, int partNo, String uploadId);
  91 +
  92 + public MyUploadPartResponceHandler(String key, int partNo, String uploadId){
  93 + this.key = key;
  94 + this.partNo = partNo;
  95 + this.uploadId = uploadId;
  96 + }
  97 + @Override
  98 + public void onTaskProgress(double progress) {
  99 + onTaskProgress(progress, key, partNo, uploadId);
  100 + }
  101 + @Override
  102 + public void onSuccess(int statesCode, Header[] responceHeaders, PartETag result) {
  103 + onSuccess(statesCode, responceHeaders, result, key, partNo, uploadId);
  104 + }
  105 + @Override
  106 + public void onFailure(int statesCode, Ks3Error error, Header[] responceHeaders, String response, Throwable throwable) {
  107 + onFailure(statesCode,error,responceHeaders,response,throwable, key, partNo, uploadId);
  108 + }
  109 + }
  110 +
  111 + private final MyHandler mHandler = new MyHandler();
  112 +
  113 + class MyHandler extends Handler {
  114 + @Override
  115 + public void handleMessage(Message msg) {
  116 + switch (msg.what) {
  117 + case INIT_DONE:
  118 + uploadParts();
  119 + break;
  120 + case PARTS_DONE:
  121 + completeUpload();
  122 + break;
  123 + case GET_UPLOADED_DONE:
  124 + List<PartETag> res = (List<PartETag>)msg.obj;
  125 + reUpload(res);
  126 + break;
  127 + default:
  128 + break;
  129 + }
  130 + }
  131 + }
  132 +
  133 + /*
  134 + return false, if uploadId hasbeen got
  135 + */
  136 + public boolean upload(){
  137 + if(uploadId != null) return false;
  138 + InitiateMultipartUploadRequest request = new InitiateMultipartUploadRequest(bucketName, key);
  139 + client.initiateMultipartUpload(request, new InitiateMultipartUploadResponceHandler(){
  140 + @Override
  141 + public void onFailure(int statesCode, Ks3Error error, Header[] responceHeaders, String response, Throwable paramThrowable) {
  142 + Log.w(TAG, "init multiupload fail, statesCode="+statesCode, paramThrowable);
  143 + }
  144 + @Override
  145 + public void onSuccess(int statesCode, Header[] responceHeaders, InitiateMultipartUploadResult result) {
  146 + uploadId = result.getUploadId();
  147 + Log.d(TAG, "init multiupload success, uploadId="+uploadId + ",key="+key);
  148 + mHandler.sendEmptyMessage(INIT_DONE);
  149 + }
  150 + });
  151 + return true;
  152 + }
  153 +
  154 + private List<PartETag> convertPart(List<Part> list){
  155 + List<PartETag> res = new ArrayList<PartETag>();
  156 + for(Part p : list) {
  157 + res.add(new PartETag(p.getPartNumber(), p.getETag()));
  158 + }
  159 + return res;
  160 + }
  161 + /*
  162 + Get from ks3 server. call list parts API.
  163 + */
  164 + public void getUploadedParts(){
  165 + final List<PartETag> res = new ArrayList<PartETag>();
  166 + final ListPartsResponseHandler listPartsResponseHandler = new ListPartsResponseHandler() {
  167 + @Override
  168 + public void onFailure(int statesCode, Ks3Error error, Header[] responceHeaders, String response, Throwable paramThrowable) {
  169 + Log.w(TAG, "list parts, statesCode="+statesCode, paramThrowable);
  170 + }
  171 + @Override
  172 + public void onSuccess(int statesCode, Header[] responceHeaders, ListPartsResult listPartsResult) {
  173 + res.addAll(convertPart(listPartsResult.getParts()));
  174 + if(! listPartsResult.isTruncated())
  175 + mHandler.sendMessage(Message.obtain(mHandler, GET_UPLOADED_DONE, res));
  176 + else
  177 + Log.e(TAG, "File size too largs. You may not use phone to upload");
  178 + }
  179 + };
  180 + client.listParts(bucketName, key, uploadId, listPartsResponseHandler);
  181 + }
  182 +
  183 + public List<Integer> getLeftParts(List<PartETag> uploadedParts){
  184 + List<Integer> res = new ArrayList<Integer>();
  185 + long start = 0L;
  186 + int partNumber = 1;
  187 + Set<Integer> set = new HashSet<Integer>();
  188 + for(PartETag p : uploadedParts){
  189 + set.add(p.getPartNumber());
  190 + }
  191 + while(start<file.length()){
  192 + if(! set.contains(partNumber))
  193 + res.add(partNumber);
  194 + partNumber++;
  195 + start += partSize;
  196 + }
  197 + return res;
  198 + }
  199 +
  200 + public void reUpload(){
  201 + if(uploadId == null) {
  202 + Log.i(TAG, "no upload id, cannot reupload");
  203 + return;
  204 + }
  205 + getUploadedParts();
  206 + }
  207 +
  208 + public void reUpload(final List<PartETag> uploadedParts){
  209 + final List<Integer> leftParts = getLeftParts(uploadedParts);
  210 + final int N = leftParts.size() + uploadedParts.size();
  211 + doneParts.addAll(uploadedParts);
  212 + if(leftParts.isEmpty())
  213 + mHandler.sendEmptyMessage(PARTS_DONE);
  214 + for(Integer partNumber : leftParts){
  215 + long offset = partNumber * partSize - partSize;
  216 + UploadPartRequest uploadPartRequest = new UploadPartRequest(bucketName, key,uploadId, file,
  217 + offset, partNumber, Math.min(file.length()-offset, partSize));
  218 + client.uploadPart(uploadPartRequest, new MyUploadPartResponceHandler(key, partNumber, uploadId){
  219 + @Override
  220 + public void onSuccess(int statesCode, Header[] responceHeaders, PartETag result, String key, int partNo, String uploadId) {
  221 + result.setPartNumber(partNo);
  222 + doneParts.add(result);
  223 + if(doneParts.size() == N)
  224 + mHandler.sendEmptyMessage(PARTS_DONE);
  225 + }
  226 + @Override
  227 + public void onFailure(int statesCode, Ks3Error error, Header[] responceHeaders, String response, Throwable throwable,
  228 + String key, int partNo, String uploadId) {
  229 + // you may record this failure info in file, database, or backend
  230 + Log.w(TAG, "upload part fail, uploadId="+uploadId+",key="+key+",partNo="+partNo, throwable);
  231 + }
  232 + @Override
  233 + public void onTaskProgress(double progress, String key, int partNo, String uploadId) {
  234 + if(progress>=99)
  235 + Log.i(TAG, "progress:"+progress+",key="+key+",partNo"+partNo);
  236 + }
  237 + });
  238 + }
  239 + }
  240 +
  241 + private void uploadParts(){
  242 + reUpload(new ArrayList<PartETag>());
  243 + }
  244 +
  245 + private void completeUpload(){
  246 + client.completeMultipartUpload(bucketName,key,uploadId,doneParts,new CompleteMultipartUploadResponseHandler(){
  247 + @Override
  248 + public void onFailure(int statesCode, Ks3Error error, Header[] responceHeaders, String response, Throwable paramThrowable) {
  249 + Log.w(TAG, "complete upload fail, statusCode="+statesCode, paramThrowable);
  250 + }
  251 + @Override
  252 + public void onSuccess(int statesCode, Header[] responceHeaders, CompleteMultipartUploadResult result) {
  253 + Log.i(TAG, "complete upload, key="+key);
  254 + }
  255 + });
  256 + }
  257 +}
... ...
app/src/main/java/com/cnlive/demo/rdupload/RESTAPITestResult.java 0 → 100644
  1 +++ a/app/src/main/java/com/cnlive/demo/rdupload/RESTAPITestResult.java
  1 +package com.cnlive.demo.rdupload;
  2 +
  3 +import android.os.Bundle;
  4 +import android.app.Activity;
  5 +import android.view.Menu;
  6 +import android.widget.TextView;
  7 +
  8 +public class RESTAPITestResult extends Activity {
  9 +
  10 + @Override
  11 + protected void onCreate(Bundle savedInstanceState) {
  12 + super.onCreate(savedInstanceState);
  13 + setContentView(R.layout.rest_api_test_result);
  14 + String result = getIntent().getExtras().getString("result");
  15 + String api = getIntent().getExtras().getString("api");
  16 + TextView resulTextView = (TextView) findViewById(R.id.result);
  17 + resulTextView.setText(result);
  18 + TextView apiTextView = (TextView) findViewById(R.id.api);
  19 + apiTextView.setText(api);
  20 + }
  21 +
  22 + @Override
  23 + public boolean onCreateOptionsMenu(Menu menu) {
  24 + // Inflate the menu; this adds items to the action bar if it is present.
  25 + getMenuInflater().inflate(R.menu.main, menu);
  26 + return true;
  27 + }
  28 +
  29 +}
... ...
app/src/main/java/com/cnlive/demo/rdupload/TransferUtils.java 0 → 100644
  1 +++ a/app/src/main/java/com/cnlive/demo/rdupload/TransferUtils.java
  1 +package com.cnlive.demo.rdupload;
  2 +
  3 +import java.io.File;
  4 +import android.util.Log;
  5 +import com.ksyun.ks3.model.transfer.TransferManagerConfiguration;
  6 +import com.ksyun.ks3.services.request.PutObjectRequest;
  7 +
  8 +/**
  9 + *
  10 + * 上传下载工具类
  11 + *
  12 + */
  13 +public class TransferUtils {
  14 + // 判断当前上传是否需要使用分块上传
  15 + public static boolean needUseMultipartUpload(File mFile,
  16 + TransferManagerConfiguration configuration) {
  17 + if (mFile != null) {
  18 + return mFile.length() > configuration.getMultipartUploadThreshold();
  19 + }
  20 + return false;
  21 + }
  22 +
  23 + // 获取最优分块大小
  24 + public static long getOptimalPartSize(File file,
  25 + TransferManagerConfiguration configuration) {
  26 + long resultSize = calculateOptimalPartSize(file, configuration);
  27 + return resultSize;
  28 + }
  29 +
  30 + public static long calculateOptimalPartSize(File file,
  31 + TransferManagerConfiguration paramTransferManagerConfiguration) {
  32 + double d1 = file.length();
  33 + double d2 = d1 / 10000.0D;
  34 + d2 = Math.ceil(d2);
  35 + return (long) Math.max(d2,
  36 + paramTransferManagerConfiguration.getMinimumUploadPartSize());
  37 + }
  38 +
  39 + public static File getRequestFile(PutObjectRequest paramPutObjectRequest)
  40 + {
  41 + if (paramPutObjectRequest.getFile() != null)
  42 + return paramPutObjectRequest.getFile();
  43 + return null;
  44 + }
  45 +
  46 + public static long getContentLength(PutObjectRequest paramPutObjectRequest)
  47 + {
  48 + File localFile = getRequestFile(paramPutObjectRequest);
  49 + if (localFile != null)
  50 + return localFile.length();
  51 + if ((paramPutObjectRequest.getRequestBody() != null) && (paramPutObjectRequest.getObjectMeta().getContentLength() > 0L))
  52 + return paramPutObjectRequest.getObjectMeta().getContentLength();
  53 + return -1L;
  54 + }
  55 +}
... ...
app/src/main/java/com/cnlive/demo/rdupload/UploadActivity.java 0 → 100644
  1 +++ a/app/src/main/java/com/cnlive/demo/rdupload/UploadActivity.java
  1 +package com.cnlive.demo.rdupload;
  2 +
  3 +import java.io.File;
  4 +import java.io.Serializable;
  5 +import java.util.ArrayList;
  6 +import java.util.HashMap;
  7 +import java.util.List;
  8 +import java.util.Map;
  9 +
  10 +import org.apache.http.Header;
  11 +
  12 +import android.annotation.SuppressLint;
  13 +import android.app.Activity;
  14 +import android.content.Context;
  15 +import android.graphics.drawable.Drawable;
  16 +import android.os.Bundle;
  17 +import android.os.Environment;
  18 +import android.os.Handler;
  19 +import android.os.Message;
  20 +import android.support.annotation.NonNull;
  21 +import android.util.Log;
  22 +import android.view.KeyEvent;
  23 +import android.view.LayoutInflater;
  24 +import android.view.View;
  25 +import android.view.ViewGroup;
  26 +import android.widget.AdapterView;
  27 +import android.widget.AdapterView.OnItemClickListener;
  28 +import android.widget.BaseAdapter;
  29 +import android.widget.ImageView;
  30 +import android.widget.LinearLayout;
  31 +import android.widget.ListView;
  32 +import android.widget.ProgressBar;
  33 +import android.widget.TextView;
  34 +
  35 +import com.cnlive.lib.rdupload.network.HttpTask;
  36 +import com.ksyun.ks3.exception.Ks3Error;
  37 +import com.ksyun.ks3.model.PartETag;
  38 +import com.ksyun.ks3.model.acl.AccessControlList;
  39 +import com.ksyun.ks3.model.acl.CannedAccessControlList;
  40 +import com.ksyun.ks3.model.result.CompleteMultipartUploadResult;
  41 +import com.ksyun.ks3.model.result.InitiateMultipartUploadResult;
  42 +import com.ksyun.ks3.model.result.ListPartsResult;
  43 +import com.ksyun.ks3.services.AuthListener;
  44 +import com.ksyun.ks3.services.Ks3Client;
  45 +import com.ksyun.ks3.services.Ks3ClientConfiguration;
  46 +import com.ksyun.ks3.services.handler.CompleteMultipartUploadResponseHandler;
  47 +import com.ksyun.ks3.services.handler.InitiateMultipartUploadResponceHandler;
  48 +import com.ksyun.ks3.services.handler.ListPartsResponseHandler;
  49 +import com.ksyun.ks3.services.handler.PutObjectResponseHandler;
  50 +import com.ksyun.ks3.services.handler.UploadPartResponceHandler;
  51 +import com.ksyun.ks3.services.request.CompleteMultipartUploadRequest;
  52 +import com.ksyun.ks3.services.request.InitiateMultipartUploadRequest;
  53 +import com.ksyun.ks3.services.request.ListPartsRequest;
  54 +import com.ksyun.ks3.services.request.PutObjectRequest;
  55 +import com.ksyun.ks3.services.request.UploadPartRequest;
  56 +
  57 +/**
  58 + * Upload相关API使用示例,Initiate Multipart Upload,Upload Part,List Parts, Complete
  59 + * Multipart Upload等
  60 + */
  61 +public class UploadActivity extends Activity implements OnItemClickListener {
  62 + public static final long PART_SIZE = 5 * 1024 * 1024;
  63 + private Ks3ClientConfiguration configuration;
  64 + private Ks3Client client;
  65 + private File currentDir;
  66 + private ListView listView;
  67 + private TextView currentDirTextView;
  68 + private Map<String, List<UploadFile>> dataSource;
  69 + private FileAdapter adapter;
  70 + private final myHandler mHandler = new myHandler();
  71 + private BucketInpuDialog bucketInpuDialog;
  72 + private String mBucketName;
  73 +
  74 + private HttpTask httpTask;
  75 +
  76 + class ViewHolder {
  77 + ImageView fileIcon;
  78 + TextView fileNameTextView;
  79 + LinearLayout fileSummaryLayout;
  80 + TextView fileSizeTextView;
  81 + TextView fileModiyTextView;
  82 + LinearLayout uploadSummaryLayout;
  83 + ProgressBar uploadProgressBar;
  84 + TextView progressTextView;
  85 + ImageView uploadBtn;
  86 + }
  87 +
  88 + class FileAdapter extends BaseAdapter {
  89 + private List<UploadFile> mUploadFiles;
  90 + private LayoutInflater mInflater;
  91 +
  92 + FileAdapter(Context context, List<UploadFile> uploadFiles) {
  93 + this.mUploadFiles = new ArrayList<UploadFile>();
  94 + if (uploadFiles != null)
  95 + this.mUploadFiles.addAll(uploadFiles);
  96 + this.mInflater = (LayoutInflater) context
  97 + .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  98 + }
  99 +
  100 + @Override
  101 + public int getCount() {
  102 + return mUploadFiles.size();
  103 + }
  104 +
  105 + @Override
  106 + public UploadFile getItem(int position) {
  107 + return this.mUploadFiles.get(position);
  108 + }
  109 +
  110 + @Override
  111 + public long getItemId(int position) {
  112 + return position;
  113 + }
  114 +
  115 + @Override
  116 + public View getView(int position, View convertView, ViewGroup parent) {
  117 + ViewHolder viewHolder;
  118 + if (convertView == null) {
  119 + convertView = mInflater.inflate(R.layout.upload_list_item,
  120 + parent, false);
  121 + viewHolder = new ViewHolder();
  122 + viewHolder.fileIcon = (ImageView) convertView
  123 + .findViewById(R.id.file_icon);
  124 + viewHolder.fileNameTextView = (TextView) convertView
  125 + .findViewById(R.id.file_name);
  126 + viewHolder.fileSummaryLayout = (LinearLayout) convertView
  127 + .findViewById(R.id.file_summary_layout);
  128 + viewHolder.fileSizeTextView = (TextView) convertView
  129 + .findViewById(R.id.file_size);
  130 + viewHolder.fileModiyTextView = (TextView) convertView
  131 + .findViewById(R.id.file_last_modiy);
  132 + viewHolder.uploadSummaryLayout = (LinearLayout) convertView
  133 + .findViewById(R.id.progress_summary_layout);
  134 + viewHolder.uploadProgressBar = (ProgressBar) convertView
  135 + .findViewById(R.id.upload_progress_bar);
  136 + viewHolder.progressTextView = (TextView) convertView
  137 + .findViewById(R.id.upload_progress_txt);
  138 + viewHolder.uploadBtn = (ImageView) convertView
  139 + .findViewById(R.id.upload_btn);
  140 + convertView.setTag(viewHolder);
  141 + } else {
  142 + viewHolder = (ViewHolder) convertView.getTag();
  143 + }
  144 + viewHolder.fileIcon
  145 + .setImageDrawable(mUploadFiles.get(position).icon);
  146 + viewHolder.fileNameTextView.setText(mUploadFiles.get(position).file
  147 + .getName());
  148 +
  149 + if (!mUploadFiles.get(position).file.isDirectory()) {
  150 + viewHolder.fileSizeTextView.setVisibility(View.VISIBLE);
  151 + long size = mUploadFiles.get(position).file.length();
  152 + String sizeStr = "unkown-size";
  153 +
  154 + if (size >= 1024 * 1024) {
  155 + sizeStr = ((int) (size / 1024 / 1024) * 100) / 100 + "MB";
  156 + } else {
  157 + sizeStr = (mUploadFiles.get(position).file.length() / 1024)
  158 + + "kb";
  159 + }
  160 + viewHolder.fileSizeTextView.setText(sizeStr);
  161 + String modiyStr = DemoUtils.formatDate(mUploadFiles
  162 + .get(position).file.lastModified());
  163 + viewHolder.fileModiyTextView.setText(modiyStr);
  164 + if (mUploadFiles.get(position).status > UploadFile.STATUS_NOT_START) {
  165 + viewHolder.uploadSummaryLayout.setVisibility(View.VISIBLE);
  166 + viewHolder.uploadProgressBar.setProgress(mUploadFiles
  167 + .get(position).progress);
  168 + viewHolder.fileSummaryLayout.setVisibility(View.GONE);
  169 + viewHolder.uploadBtn.setVisibility(View.GONE);
  170 + switch (mUploadFiles.get(position).status) {
  171 + case UploadFile.STATUS_STARTED:
  172 + viewHolder.progressTextView.setText("准备上传");
  173 + break;
  174 + case UploadFile.STATUS_INIT:
  175 + viewHolder.progressTextView.setText("初始化完成");
  176 + break;
  177 + case UploadFile.STATUS_UPLOADPART:
  178 + viewHolder.progressTextView.setText("分块上传.."
  179 + + mUploadFiles.get(position).progress + "%");
  180 + break;
  181 + case UploadFile.STATUS_LISTING:
  182 + viewHolder.progressTextView.setText("获取上传的快..");
  183 + break;
  184 + case UploadFile.STATUS_COMPLETE:
  185 + viewHolder.progressTextView.setText("合并完成");
  186 + break;
  187 + case UploadFile.STATUS_UPLOADING:
  188 + viewHolder.progressTextView.setText(mUploadFiles
  189 + .get(position).progress + "%");
  190 + break;
  191 + case UploadFile.STATUS_FINISH:
  192 + viewHolder.progressTextView.setText("完成上传");
  193 + break;
  194 + case UploadFile.STATUS_FAIL:
  195 + viewHolder.progressTextView.setText("上传失败");
  196 + break;
  197 +
  198 + case UploadFile.STATUS_INIT_FAIL:
  199 + viewHolder.progressTextView.setText("上传失败");
  200 + break;
  201 + case UploadFile.STATUS_UPLOADPART_FAIL:
  202 + viewHolder.progressTextView.setText("分块上传失败");
  203 + break;
  204 + case UploadFile.STATUS_LISTING_FAIL:
  205 + viewHolder.progressTextView.setText("获取块失败");
  206 + break;
  207 + case UploadFile.STATUS_COMPLETE_FAIL:
  208 + viewHolder.progressTextView.setText("文件合并失败");
  209 + break;
  210 + }
  211 + } else {
  212 + viewHolder.fileSummaryLayout.setVisibility(View.VISIBLE);
  213 + viewHolder.uploadBtn.setVisibility(View.VISIBLE);
  214 + viewHolder.uploadSummaryLayout.setVisibility(View.GONE);
  215 + }
  216 + } else {
  217 + viewHolder.fileSummaryLayout.setVisibility(View.GONE);
  218 + viewHolder.uploadSummaryLayout.setVisibility(View.GONE);
  219 + viewHolder.uploadBtn.setVisibility(View.GONE);
  220 + }
  221 +
  222 + return convertView;
  223 + }
  224 +
  225 + public void fillDatas() {
  226 + this.mUploadFiles.clear();
  227 + this.mUploadFiles.addAll(dataSource.get(currentDir.getPath()));
  228 + this.notifyDataSetChanged();
  229 + }
  230 +
  231 + public void updateCurrent() {
  232 + this.notifyDataSetChanged();
  233 + }
  234 + }
  235 +
  236 + class UploadFile implements Serializable {
  237 + private static final long serialVersionUID = 1L;
  238 + static final int STATUS_NOT_START = 0;
  239 + static final int STATUS_STARTED = 1;
  240 + static final int STATUS_UPLOADING = 2;
  241 + static final int STATUS_INIT = 3;
  242 + static final int STATUS_UPLOADPART = 4;
  243 + static final int STATUS_LISTING = 5;
  244 + static final int STATUS_COMPLETE = 6;
  245 + static final int STATUS_FINISH = 7;
  246 + static final int STATUS_FAIL = 8;
  247 + static final int STATUS_INIT_FAIL = 9;
  248 + static final int STATUS_UPLOADPART_FAIL = 10;
  249 + static final int STATUS_LISTING_FAIL = 11;
  250 + static final int STATUS_COMPLETE_FAIL = 12;
  251 + Drawable icon;
  252 + File file;
  253 + int progress;
  254 + int status;
  255 +
  256 + @Override
  257 + public String toString() {
  258 + return file.getName() + ",upload?" + status + ",progress:"
  259 + + progress;
  260 + }
  261 + }
  262 +
  263 + @Override
  264 + protected void onCreate(Bundle savedInstanceState) {
  265 + super.onCreate(savedInstanceState);
  266 + setContentView(R.layout.activity_upload);
  267 + listView = (ListView) findViewById(R.id.files);
  268 + currentDirTextView = (TextView) findViewById(R.id.current_dir_tv);
  269 + currentDir = Environment.getExternalStorageDirectory();
  270 + setUp();
  271 +
  272 + }
  273 +
  274 + private void setUp() {
  275 + //初始化Ks3Client并做鉴权
  276 + if (httpTask == null) httpTask = new HttpTask();
  277 + configuration = Ks3ClientConfiguration.getDefaultConfiguration();
  278 + client = new Ks3Client(new AuthListener() {
  279 + @Override
  280 + public String onCalculateAuth(String s, String s1, String s2, String s3, String s4, String s5) {
  281 + return httpTask.requestTokenToAppServer(s, s1, s2, s3, s4, s5).getAuthorization();
  282 + }
  283 + }, this);
  284 + client.setEndpoint("ks3-cn-beijing.ksyun.com");
  285 + client.setConfiguration(configuration);
  286 +
  287 +
  288 + // 输入框确获取Bucket之后,允许选择文件,开始Upload操作
  289 + bucketInpuDialog = new BucketInpuDialog(UploadActivity.this);
  290 + bucketInpuDialog.setOnBucketInputListener(new BucketInpuDialog.OnBucketDialogListener() {
  291 + @Override
  292 + public void confirmBucket(String name) {
  293 + mBucketName = name;
  294 + dataSource = new HashMap<String, List<UploadFile>>();
  295 + adapter = new FileAdapter(UploadActivity.this, null);
  296 + listView.setOnItemClickListener(UploadActivity.this);
  297 + listView.setAdapter(adapter);
  298 + switchDir(Environment.getExternalStorageDirectory());
  299 + }
  300 + });
  301 + bucketInpuDialog.show();
  302 + client.setConfiguration(configuration);
  303 + }
  304 +
  305 + private void switchDir(File dir) {
  306 + if (dir == null || !dir.exists() || dir.isFile())
  307 + throw new IllegalArgumentException("illegal dir");
  308 +
  309 + this.currentDir = dir;
  310 + this.currentDirTextView.setText("当前目录:" + this.currentDir.getPath());
  311 + List<UploadFile> uploadFiles = dataSource.get(dir.getPath());
  312 + if (uploadFiles != null && uploadFiles.size() > 0) {
  313 + adapter.fillDatas();
  314 + return;
  315 + }
  316 +
  317 + uploadFiles = new ArrayList<UploadFile>();
  318 + File[] files = dir.listFiles();
  319 + if (files != null && files.length > 0) {
  320 + for (File file : files) {
  321 + UploadFile uploadFile = new UploadFile();
  322 + uploadFile.status = UploadFile.STATUS_NOT_START;
  323 + uploadFile.file = file;
  324 + uploadFile.icon = DemoUtils.matchImage(this,
  325 + file.isDirectory(), file.getName());
  326 + uploadFile.progress = 0;
  327 + uploadFiles.add(uploadFile);
  328 + }
  329 + }
  330 + dataSource.put(dir.getPath(), uploadFiles);
  331 + adapter.fillDatas();
  332 + }
  333 +
  334 + @Override
  335 + public void onItemClick(AdapterView<?> adpterView, final View view,
  336 + final int position, long arg3) {
  337 + final UploadFile item = adapter.getItem(position);
  338 + if (item.file.isDirectory()) {
  339 + switchDir(item.file);
  340 + } else {
  341 + if (item.status == UploadFile.STATUS_STARTED
  342 + || item.status == UploadFile.STATUS_UPLOADING
  343 + || item.status == UploadFile.STATUS_FINISH)
  344 + return;
  345 + // 上传操作
  346 + doUpload(mBucketName, item);
  347 + }
  348 + }
  349 +
  350 + @Override
  351 + public boolean onKeyDown(int keyCode, KeyEvent event) {
  352 + if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
  353 + if (currentDir.getPath().equalsIgnoreCase(
  354 + Environment.getExternalStorageDirectory().getPath())) {
  355 + return super.onKeyDown(keyCode, event);
  356 + } else {
  357 + switchDir(currentDir.getParentFile());
  358 + return true;
  359 + }
  360 + }
  361 + return super.onKeyDown(keyCode, event);
  362 + }
  363 +
  364 + private void doUpload(String bucketName, UploadFile item) {
  365 + if (item.file == null)
  366 + throw new IllegalArgumentException("file can not be null");
  367 + // 根据指定的文件大小,选择用直接上传或者分块上传
  368 + if (item.file.length() >= Constants.MULTI_UPLOAD_THREADHOLD)
  369 + doMultipartUpload(bucketName, item);
  370 + else
  371 + doSingleUpload(bucketName, item);
  372 + }
  373 +
  374 + // 上传文件
  375 + private void doSingleUpload(final String bucketName, final UploadFile item) {
  376 + final PutObjectRequest request = new PutObjectRequest(bucketName,
  377 + item.file.getName(), item.file);
  378 + request.setCannedAcl(CannedAccessControlList.PublicRead);
  379 +// Map<String,String> customParams = new HashMap<String, String>();
  380 + //自定义参数必须以kss-开头
  381 +// customParams.put("kss-location", "user_input_location");
  382 +// customParams.put("kss-name", "user_input_name");
  383 +// request.setCallBack("http://127.0.0.1:19091/kss/call_back", "objectKey=${key}&etag=${etag}&location=${kss-location}&name=${kss-name}", customParams);
  384 + client.putObject(request, new PutObjectResponseHandler() {
  385 +
  386 + @Override
  387 + public void onTaskProgress(double progress) {
  388 + // if (progress > 50.0) {
  389 + // request.abort();
  390 + // }
  391 + List<UploadFile> uploadFiles = dataSource.get(currentDir
  392 + .getPath());
  393 + for (UploadFile file : uploadFiles) {
  394 + if (file.file.getPath().equalsIgnoreCase(
  395 + item.file.getPath())) {
  396 + file.status = UploadFile.STATUS_UPLOADING;
  397 + file.progress = (int) progress;
  398 + item.status = UploadFile.STATUS_UPLOADING;
  399 + item.progress = (int) progress;
  400 + }
  401 + }
  402 + mHandler.sendEmptyMessage(UPDATE_SINGLE_UPLOAD_STATUS);
  403 + }
  404 +
  405 + @Override
  406 + public void onTaskSuccess(int statesCode, Header[] responceHeaders) {
  407 + Log.d(com.ksyun.ks3.util.Constants.LOG_TAG, "success");
  408 + }
  409 +
  410 + @Override
  411 + public void onTaskStart() {
  412 + List<UploadFile> uploadFiles = dataSource.get(currentDir
  413 + .getPath());
  414 + for (UploadFile file : uploadFiles) {
  415 + if (file.file.getPath().equalsIgnoreCase(
  416 + item.file.getPath())) {
  417 + file.status = UploadFile.STATUS_STARTED;
  418 + file.progress = 0;
  419 + item.status = UploadFile.STATUS_STARTED;
  420 + item.progress = 0;
  421 + }
  422 + }
  423 + mHandler.sendEmptyMessage(UPDATE_SINGLE_UPLOAD_STATUS);
  424 + }
  425 +
  426 + @Override
  427 + public void onTaskFinish() {
  428 + List<UploadFile> uploadFiles = dataSource.get(currentDir
  429 + .getPath());
  430 + for (UploadFile file : uploadFiles) {
  431 + if (file.file.getPath().equalsIgnoreCase(
  432 + item.file.getPath())) {
  433 + file.status = UploadFile.STATUS_FINISH;
  434 + file.progress = 100;
  435 + item.status = UploadFile.STATUS_FINISH;
  436 + file.progress = 100;
  437 + }
  438 + }
  439 + mHandler.sendEmptyMessage(UPDATE_SINGLE_UPLOAD_STATUS);
  440 + }
  441 +
  442 + @Override
  443 + public void onTaskCancel() {
  444 + Log.d(com.ksyun.ks3.util.Constants.LOG_TAG, "cancle ok");
  445 + }
  446 +
  447 + @Override
  448 + public void onTaskFailure(int statesCode, Ks3Error error,
  449 + Header[] responceHeaders, String response,
  450 + Throwable paramThrowable) {
  451 + Log.d(com.ksyun.ks3.util.Constants.LOG_TAG,
  452 + paramThrowable.toString());
  453 + Log.d(com.ksyun.ks3.util.Constants.LOG_TAG,
  454 + response);
  455 + List<UploadFile> uploadFiles = dataSource.get(currentDir
  456 + .getPath());
  457 + for (UploadFile file : uploadFiles) {
  458 + if (file.file.getPath().equalsIgnoreCase(
  459 + item.file.getPath())) {
  460 + file.status = UploadFile.STATUS_FAIL;
  461 + item.status = UploadFile.STATUS_FAIL;
  462 + }
  463 + }
  464 + mHandler.sendEmptyMessage(UPDATE_SINGLE_UPLOAD_STATUS);
  465 +
  466 + }
  467 + });
  468 + }
  469 +
  470 + // 分快上传
  471 + private void doMultipartUpload(final String bucketName,
  472 + final UploadFile item) {
  473 + InitiateMultipartUploadRequest request = new InitiateMultipartUploadRequest(
  474 + bucketName, item.file.getName());
  475 + initiateMultipartUpload(request, item);
  476 + }
  477 +
  478 + private void initiateMultipartUpload(
  479 + final InitiateMultipartUploadRequest request, final UploadFile item) {
  480 + client.initiateMultipartUpload(request,
  481 + new InitiateMultipartUploadResponceHandler() {
  482 + @Override
  483 + public void onSuccess(int statesCode,
  484 + Header[] responceHeaders,
  485 + InitiateMultipartUploadResult result) {
  486 + List<UploadFile> uploadFiles = dataSource
  487 + .get(currentDir.getPath());
  488 + for (UploadFile file : uploadFiles) {
  489 + if (file.file.getPath().equalsIgnoreCase(
  490 + item.file.getPath())) {
  491 + file.status = UploadFile.STATUS_INIT;
  492 + item.status = UploadFile.STATUS_INIT;
  493 + }
  494 + }
  495 + mHandler.sendEmptyMessage(UPDATE_SINGLE_UPLOAD_STATUS);
  496 +
  497 + beginMultiUpload(result, item);
  498 + }
  499 +
  500 + @Override
  501 + public void onFailure(int statesCode, Ks3Error error,
  502 + Header[] responceHeaders, String response,
  503 + Throwable paramThrowable) {
  504 + List<UploadFile> uploadFiles = dataSource
  505 + .get(currentDir.getPath());
  506 + for (UploadFile file : uploadFiles) {
  507 + if (file.file.getPath().equalsIgnoreCase(
  508 + item.file.getPath())) {
  509 + file.status = UploadFile.STATUS_INIT_FAIL;
  510 + item.status = UploadFile.STATUS_INIT_FAIL;
  511 + }
  512 + }
  513 + mHandler.sendEmptyMessage(UPDATE_SINGLE_UPLOAD_STATUS);
  514 + }
  515 + });
  516 + }
  517 +
  518 + private void beginMultiUpload(InitiateMultipartUploadResult initResult,
  519 + UploadFile item) {
  520 + UploadPartRequestFactory localUploadPartRequestFactory = new UploadPartRequestFactory(
  521 + initResult.getBucket(), initResult.getKey(),
  522 + initResult.getUploadId(), item.file, PART_SIZE);
  523 + Message message = mHandler.obtainMessage();
  524 + message.what = UPLOAD_NEXT_PART;
  525 + Bundle bundle = new Bundle();
  526 + bundle.putSerializable("requestFactory", localUploadPartRequestFactory);
  527 + bundle.putSerializable("uploadFile", item);
  528 + message.setData(bundle);
  529 + mHandler.sendMessage(message);
  530 + }
  531 +
  532 + private void uploadpart(final UploadPartRequestFactory requestFactory,
  533 + final UploadFile item) {
  534 + if (requestFactory.hasMoreRequests()) {
  535 + final UploadPartRequest request = requestFactory
  536 + .getNextUploadPartRequest();
  537 + client.uploadPart(request, new UploadPartResponceHandler() {
  538 + double progressInFile = 0;
  539 +
  540 + @Override
  541 + public void onTaskProgress(double progress) {
  542 + long uploadedInpart = (long) (progress / 100 * request.contentLength);
  543 + long uploadedInFile = uploadedInpart
  544 + + requestFactory.getUploadedSize();
  545 + progressInFile = Double
  546 + .valueOf(request.getFile().length() > 0 ? uploadedInFile
  547 + * 1.0D
  548 + / request.getFile().length()
  549 + * 100.0D
  550 + : -1.0D);
  551 +
  552 + List<UploadFile> uploadFiles = dataSource.get(currentDir
  553 + .getPath());
  554 + for (UploadFile file : uploadFiles) {
  555 + if (file.file.getPath().equalsIgnoreCase(
  556 + item.file.getPath())) {
  557 + file.status = UploadFile.STATUS_UPLOADPART;
  558 + file.progress = (int) progressInFile;
  559 + item.status = UploadFile.STATUS_UPLOADPART;
  560 + file.progress = (int) progressInFile;
  561 + }
  562 + }
  563 + mHandler.sendEmptyMessage(UPDATE_SINGLE_UPLOAD_STATUS);
  564 + }
  565 +
  566 + @Override
  567 + public void onSuccess(int statesCode, Header[] responceHeaders,
  568 + PartETag result) {
  569 + Message message = mHandler.obtainMessage();
  570 + message.what = UPLOAD_NEXT_PART;
  571 + Bundle bundle = new Bundle();
  572 + bundle.putSerializable("requestFactory", requestFactory);
  573 + bundle.putSerializable("uploadFile", item);
  574 + message.setData(bundle);
  575 + mHandler.sendMessage(message);
  576 + }
  577 +
  578 + @Override
  579 + public void onFailure(int statesCode, Ks3Error error,
  580 + Header[] responceHeaders, String response,
  581 + Throwable throwable) {
  582 + List<UploadFile> uploadFiles = dataSource.get(currentDir
  583 + .getPath());
  584 + for (UploadFile file : uploadFiles) {
  585 + if (file.file.getPath().equalsIgnoreCase(
  586 + item.file.getPath())) {
  587 + file.status = UploadFile.STATUS_UPLOADPART_FAIL;
  588 + file.progress = (int) progressInFile;
  589 + item.status = UploadFile.STATUS_UPLOADPART_FAIL;
  590 + file.progress = (int) progressInFile;
  591 + }
  592 + }
  593 + mHandler.sendEmptyMessage(UPDATE_SINGLE_UPLOAD_STATUS);
  594 + }
  595 + });
  596 + } else {
  597 + Message message = mHandler.obtainMessage();
  598 + message.what = UPLOAD_PART_FINISH;
  599 + Bundle bundle = new Bundle();
  600 + bundle.putSerializable("requestFactory", requestFactory);
  601 + bundle.putSerializable("uploadFile", item);
  602 + message.setData(bundle);
  603 + mHandler.sendMessage(message);
  604 + }
  605 + }
  606 +
  607 + private void listParts(final ListPartsRequest request, final UploadFile item) {
  608 + client.listParts(request, new ListPartsResponseHandler() {
  609 + @Override
  610 + public void onSuccess(int statesCode, Header[] responceHeaders,
  611 + ListPartsResult result) {
  612 + Message message = mHandler.obtainMessage();
  613 + message.what = LIST_PART_FINISH;
  614 + message.obj = result;
  615 + Bundle bundle = new Bundle();
  616 + bundle.putSerializable("uploadFile", item);
  617 + message.setData(bundle);
  618 + mHandler.sendMessage(message);
  619 + }
  620 +
  621 + @Override
  622 + public void onFailure(int statesCode, Ks3Error error,
  623 + Header[] responceHeaders, String response,
  624 + Throwable paramThrowable) {
  625 + List<UploadFile> uploadFiles = dataSource.get(currentDir
  626 + .getPath());
  627 + for (UploadFile file : uploadFiles) {
  628 + if (file.file.getPath().equalsIgnoreCase(
  629 + item.file.getPath())) {
  630 + file.status = UploadFile.STATUS_LISTING_FAIL;
  631 + item.status = UploadFile.STATUS_LISTING_FAIL;
  632 + }
  633 + }
  634 + mHandler.sendEmptyMessage(UPDATE_SINGLE_UPLOAD_STATUS);
  635 + }
  636 + });
  637 + }
  638 +
  639 + private void completeUploadPart(
  640 + final CompleteMultipartUploadRequest request, final UploadFile item) {
  641 + client.completeMultipartUpload(request,
  642 + new CompleteMultipartUploadResponseHandler() {
  643 + @Override
  644 + public void onSuccess(int statesCode,
  645 + Header[] responceHeaders,
  646 + CompleteMultipartUploadResult result) {
  647 + List<UploadFile> uploadFiles = dataSource
  648 + .get(currentDir.getPath());
  649 + for (UploadFile file : uploadFiles) {
  650 + if (file.file.getPath().equalsIgnoreCase(
  651 + item.file.getPath())) {
  652 + file.status = UploadFile.STATUS_COMPLETE;
  653 + item.status = UploadFile.STATUS_COMPLETE;
  654 + }
  655 + }
  656 + mHandler.sendEmptyMessage(0);
  657 + }
  658 +
  659 + @Override
  660 + public void onFailure(int statesCode, Ks3Error error,
  661 + Header[] responceHeaders, String response,
  662 + Throwable paramThrowable) {
  663 + List<UploadFile> uploadFiles = dataSource
  664 + .get(currentDir.getPath());
  665 + for (UploadFile file : uploadFiles) {
  666 + if (file.file.getPath().equalsIgnoreCase(
  667 + item.file.getPath())) {
  668 + file.status = UploadFile.STATUS_COMPLETE_FAIL;
  669 + file.progress = 100;
  670 + item.status = UploadFile.STATUS_COMPLETE_FAIL;
  671 + item.progress = 100;
  672 + }
  673 + }
  674 + mHandler.sendEmptyMessage(0);
  675 + }
  676 + });
  677 + }
  678 +
  679 + private static final int UPDATE_SINGLE_UPLOAD_STATUS = 0;
  680 + private static final int UPLOAD_NEXT_PART = 2;
  681 + private static final int UPLOAD_PART_FINISH = 3;
  682 + private static final int LIST_PART_FINISH = 4;
  683 +
  684 + @SuppressLint("HandlerLeak")
  685 + class myHandler extends Handler {
  686 + @Override
  687 + public void handleMessage(Message msg) {
  688 + int what = msg.what;
  689 + Bundle bundle;
  690 + UploadFile item;
  691 + UploadPartRequestFactory requestFactory;
  692 + switch (what) {
  693 + case UPDATE_SINGLE_UPLOAD_STATUS:
  694 + adapter.updateCurrent();
  695 + break;
  696 + case UPLOAD_NEXT_PART:
  697 + bundle = msg.getData();
  698 + requestFactory = (UploadPartRequestFactory) bundle
  699 + .get("requestFactory");
  700 + item = (UploadFile) bundle.get("uploadFile");
  701 + uploadpart(requestFactory, item);
  702 + break;
  703 + case UPLOAD_PART_FINISH:
  704 + bundle = msg.getData();
  705 + requestFactory = (UploadPartRequestFactory) bundle
  706 + .get("requestFactory");
  707 + item = (UploadFile) bundle.get("uploadFile");
  708 + ListPartsRequest listRequest = new ListPartsRequest(
  709 + requestFactory.getBucketName(),
  710 + requestFactory.getObjectKey(),
  711 + requestFactory.getUploadId());
  712 + listParts(listRequest, item);
  713 + break;
  714 + case LIST_PART_FINISH:
  715 + ListPartsResult listResult = (ListPartsResult) msg.obj;
  716 + bundle = msg.getData();
  717 + item = (UploadFile) bundle.get("uploadFile");
  718 + CompleteMultipartUploadRequest comRequest = new CompleteMultipartUploadRequest(
  719 + listResult);
  720 + completeUploadPart(comRequest, item);
  721 + break;
  722 + default:
  723 + break;
  724 + }
  725 + }
  726 + }
  727 +
  728 + @Override
  729 + public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
  730 + super.onRequestPermissionsResult(requestCode, permissions, grantResults);
  731 + }
  732 +}
... ...
app/src/main/java/com/cnlive/demo/rdupload/UploadPartRequestFactory.java 0 → 100644
  1 +++ a/app/src/main/java/com/cnlive/demo/rdupload/UploadPartRequestFactory.java
  1 +package com.cnlive.demo.rdupload;
  2 +
  3 +import java.io.File;
  4 +import java.io.Serializable;
  5 +
  6 +import com.ksyun.ks3.services.request.UploadPartRequest;
  7 +
  8 +/**
  9 + *
  10 + * UploadPartRequest工厂,用于分块上传操作
  11 + *
  12 + */
  13 +public class UploadPartRequestFactory implements Serializable{
  14 + private static final long serialVersionUID = 1L;
  15 + private String bucketName;
  16 + private String key;
  17 + private String uploadId;
  18 + private File file;
  19 + public int partNumber = 1;
  20 + private long offset = 0L;
  21 + private long remainingBytes;
  22 + public long partSize ;
  23 + private long uploadedSize;
  24 +
  25 + public UploadPartRequestFactory(String bucketName ,String objectKey , String uploadId , File file , long partSize ) {
  26 + this.uploadId = uploadId;
  27 + this.bucketName = bucketName;
  28 + this.key = objectKey;
  29 + this.file = file;
  30 + this.remainingBytes = file.length();
  31 + this.partSize = partSize;
  32 + this.partNumber = 1;
  33 + this.uploadedSize = 0;
  34 + }
  35 +
  36 + public synchronized boolean hasMoreRequests() {
  37 + return this.remainingBytes > 0L;
  38 + }
  39 +
  40 + // 计算下一个UploadPartRequest配置参数,并返回对象
  41 + public synchronized UploadPartRequest getNextUploadPartRequest() {
  42 + boolean bool = this.remainingBytes - this.partSize <= 0L;
  43 + UploadPartRequest localUploadPartRequest = null;
  44 + uploadedSize = file.length() - this.remainingBytes ;
  45 + localUploadPartRequest = new UploadPartRequest(bucketName, key,uploadId, file, offset, partNumber++, partSize);
  46 + this.offset += partSize;
  47 + this.remainingBytes -= partSize;
  48 + localUploadPartRequest.setLastPart(bool);
  49 + return localUploadPartRequest;
  50 + }
  51 +
  52 +
  53 + public synchronized long getUploadedSize (){
  54 + return this.uploadedSize;
  55 + }
  56 +
  57 + public synchronized File getFile(){
  58 + return this.file;
  59 + }
  60 +
  61 + public synchronized String getBucketName(){
  62 + return this.bucketName;
  63 + }
  64 +
  65 + public synchronized String getUploadId(){
  66 + return this.uploadId;
  67 + }
  68 + public synchronized String getObjectKey() {
  69 + return this.key;
  70 + }
  71 +
  72 +}
... ...
app/src/main/java/com/cnlive/demo/rdupload/application/App.java 0 → 100644
  1 +++ a/app/src/main/java/com/cnlive/demo/rdupload/application/App.java
  1 +package com.cnlive.demo.rdupload.application;
  2 +
  3 +import android.app.Application;
  4 +
  5 +import com.cnlive.libs.util.Config;
  6 +
  7 +/**
  8 + * Created by Lynn on 2017/8/4.
  9 + */
  10 +
  11 +public class App extends Application {
  12 +
  13 + /**
  14 + * 正式环境
  15 + * ID : 60_j5xi58ra64
  16 + * KEY : 3557a67052f756520d2a7e7933598233fbebfe12ae6055
  17 + * SECRET : ce0db6ef39cc50d0a35f2a17290785216f3362306cfa17
  18 + */
  19 +
  20 + /**
  21 + * 测试环境
  22 + * ID : 60_j5xilfyl12
  23 + * kEY : 8b58d3dcdd828359e6113d5531029801e5d2b53e9a980c
  24 + * SECRET : 860e44bf12b9a215c6f25a619b03d6f88903e28b21c5a8
  25 + */
  26 + @Override
  27 + public void onCreate() {
  28 + super.onCreate();
  29 + //初始化上传SDK
  30 + /**
  31 + * true-->测试环境 false-->正式环境
  32 + */
  33 + Config.init(this, "60_j5xilfyl12", "8b58d3dcdd828359e6113d5531029801e5d2b53e9a980c", true);
  34 +
  35 + }
  36 +}
... ...
app/src/main/res/drawable-hdpi/home_download.png 0 → 100644

299 Bytes

app/src/main/res/drawable-hdpi/ic_launcher.png 0 → 100644

4.65 KB

app/src/main/res/drawable-hdpi/ks_download.png 0 → 100644

509 Bytes

app/src/main/res/drawable-hdpi/ks_format_apk.png 0 → 100644

3.7 KB

app/src/main/res/drawable-hdpi/ks_format_asf.png 0 → 100644

4.58 KB

app/src/main/res/drawable-hdpi/ks_format_avi.png 0 → 100644

3.76 KB

app/src/main/res/drawable-hdpi/ks_format_bat.png 0 → 100644

3.96 KB

app/src/main/res/drawable-hdpi/ks_format_bin.png 0 → 100644

3.8 KB

app/src/main/res/drawable-hdpi/ks_format_bmp.png 0 → 100644

3.58 KB

app/src/main/res/drawable-hdpi/ks_format_chm.png 0 → 100644

3.56 KB

app/src/main/res/drawable-hdpi/ks_format_dat.png 0 → 100644

2.98 KB

app/src/main/res/drawable-hdpi/ks_format_dll.png 0 → 100644

2.64 KB

app/src/main/res/drawable-hdpi/ks_format_doc.png 0 → 100644

2.99 KB

app/src/main/res/drawable-hdpi/ks_format_docx.png 0 → 100644

3.59 KB

app/src/main/res/drawable-hdpi/ks_format_flac.png 0 → 100644

3.3 KB

app/src/main/res/drawable-hdpi/ks_format_flv.png 0 → 100644

3.5 KB

app/src/main/res/drawable-hdpi/ks_format_forder.png 0 → 100644

972 Bytes

app/src/main/res/drawable-hdpi/ks_format_gif.png 0 → 100644

3.34 KB

app/src/main/res/drawable-hdpi/ks_format_html.png 0 → 100644

5.78 KB

app/src/main/res/drawable-hdpi/ks_format_inf.png 0 → 100644

2.76 KB

app/src/main/res/drawable-hdpi/ks_format_ini.png 0 → 100644

2.67 KB

app/src/main/res/drawable-hdpi/ks_format_java.png 0 → 100644

5.24 KB

app/src/main/res/drawable-hdpi/ks_format_jif.png 0 → 100644

2.93 KB

app/src/main/res/drawable-hdpi/ks_format_jpg.png 0 → 100644

3.7 KB

app/src/main/res/drawable-hdpi/ks_format_log.png 0 → 100644

2.12 KB

app/src/main/res/drawable-hdpi/ks_format_m4a.png 0 → 100644

5.76 KB

app/src/main/res/drawable-hdpi/ks_format_mid.png 0 → 100644

2.86 KB

app/src/main/res/drawable-hdpi/ks_format_mkv.png 0 → 100644

5.86 KB

app/src/main/res/drawable-hdpi/ks_format_mp3.png 0 → 100644

3.3 KB

app/src/main/res/drawable-hdpi/ks_format_mp4.png 0 → 100644

3.77 KB

app/src/main/res/drawable-hdpi/ks_format_ogg.png 0 → 100644

3.69 KB

app/src/main/res/drawable-hdpi/ks_format_pdf.png 0 → 100644

3.93 KB

app/src/main/res/drawable-hdpi/ks_format_png.png 0 → 100644

3.75 KB

app/src/main/res/drawable-hdpi/ks_format_ppt.png 0 → 100644

2.52 KB

app/src/main/res/drawable-hdpi/ks_format_pptx.png 0 → 100644

3.62 KB

app/src/main/res/drawable-hdpi/ks_format_ram.png 0 → 100644

2.21 KB

app/src/main/res/drawable-hdpi/ks_format_rar.png 0 → 100644

2.85 KB

app/src/main/res/drawable-hdpi/ks_format_reg.png 0 → 100644

4.2 KB

app/src/main/res/drawable-hdpi/ks_format_rm.png 0 → 100644

3.63 KB

app/src/main/res/drawable-hdpi/ks_format_rmvb.png 0 → 100644

4.48 KB

app/src/main/res/drawable-hdpi/ks_format_swf.png 0 → 100644

3.64 KB

app/src/main/res/drawable-hdpi/ks_format_txt.png 0 → 100644

1.85 KB

app/src/main/res/drawable-hdpi/ks_format_unkown.png 0 → 100644

1.47 KB

app/src/main/res/drawable-hdpi/ks_format_wav.png 0 → 100644

3.6 KB

app/src/main/res/drawable-hdpi/ks_format_wma.png 0 → 100644

4.71 KB

app/src/main/res/drawable-hdpi/ks_format_wmv.png 0 → 100644

4.24 KB

app/src/main/res/drawable-hdpi/ks_format_xls.png 0 → 100644

2.93 KB

app/src/main/res/drawable-hdpi/ks_format_xlsx.png 0 → 100644

3.46 KB

app/src/main/res/drawable-hdpi/ks_format_xml.png 0 → 100644

6.13 KB

app/src/main/res/drawable-hdpi/ks_format_xsl.png 0 → 100644

6.36 KB

app/src/main/res/drawable-hdpi/ks_format_zip.png 0 → 100644

2.32 KB

app/src/main/res/drawable-hdpi/ks_upload.png 0 → 100644

354 Bytes

app/src/main/res/drawable-hdpi/pcs_download.png 0 → 100644

4.61 KB

app/src/main/res/drawable-mdpi/ic_launcher.png 0 → 100644

3.69 KB

app/src/main/res/drawable-xhdpi/ic_launcher.png 0 → 100644

12.2 KB

app/src/main/res/drawable-xxhdpi/ic_launcher.png 0 → 100644

24.2 KB

app/src/main/res/layout/activity_download.xml 0 → 100644
  1 +++ a/app/src/main/res/layout/activity_download.xml
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3 + android:layout_width="match_parent"
  4 + android:layout_height="match_parent"
  5 + android:weightSum="8"
  6 + android:orientation="vertical"
  7 + >
  8 +
  9 + <TextView
  10 + android:id="@+id/current_bucket_tv"
  11 + android:layout_width="match_parent"
  12 + android:layout_height="0dip"
  13 + android:layout_weight="1"
  14 + android:text="current_dir"
  15 + android:textSize="15sp"
  16 + android:layout_marginBottom="10dip"
  17 + android:textColor="#FF3030"
  18 + android:background="#36648B"
  19 + android:gravity="center"
  20 + android:visibility="gone"
  21 + />
  22 +
  23 + <RelativeLayout
  24 + android:layout_weight="7"
  25 + android:layout_width="match_parent"
  26 + android:layout_height="0dip"
  27 +
  28 + >
  29 + <ProgressBar
  30 + android:id="@+id/progress_bar"
  31 + style="?android:attr/progressBarStyleLarge"
  32 + android:layout_width="wrap_content"
  33 + android:layout_height="wrap_content"
  34 + android:layout_centerHorizontal="true"
  35 + android:layout_centerVertical="true" />
  36 +
  37 + <ListView
  38 + android:id="@+id/object_list"
  39 + android:visibility="invisible"
  40 + android:layout_width="match_parent"
  41 + android:layout_height="wrap_content"
  42 + android:layout_alignParentLeft="true"
  43 + android:layout_alignParentTop="true" >
  44 + </ListView>
  45 +
  46 +
  47 +
  48 +
  49 + </RelativeLayout>
  50 +
  51 +
  52 +</LinearLayout>
... ...
app/src/main/res/layout/activity_dummy.xml 0 → 100644
  1 +++ a/app/src/main/res/layout/activity_dummy.xml
  1 +<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2 + xmlns:tools="http://schemas.android.com/tools"
  3 + android:layout_width="match_parent"
  4 + android:layout_height="match_parent"
  5 + android:paddingBottom="@dimen/activity_vertical_margin"
  6 + android:paddingLeft="@dimen/activity_horizontal_margin"
  7 + android:paddingRight="@dimen/activity_horizontal_margin"
  8 + android:paddingTop="@dimen/activity_vertical_margin"
  9 + tools:context=".MainActivity" >
  10 +
  11 + <ListView
  12 + android:id="@+id/command_list"
  13 + android:layout_width="match_parent"
  14 + android:layout_height="wrap_content"
  15 + android:layout_centerHorizontal="true"
  16 + android:layout_centerVertical="true" >
  17 + </ListView>
  18 +
  19 +</RelativeLayout>
... ...
app/src/main/res/layout/activity_main.xml 0 → 100644
  1 +++ a/app/src/main/res/layout/activity_main.xml
  1 +<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2 + xmlns:tools="http://schemas.android.com/tools"
  3 + android:layout_width="match_parent"
  4 + android:layout_height="match_parent"
  5 + android:paddingBottom="@dimen/activity_vertical_margin"
  6 + android:paddingLeft="@dimen/activity_horizontal_margin"
  7 + android:paddingRight="@dimen/activity_horizontal_margin"
  8 + android:paddingTop="@dimen/activity_vertical_margin"
  9 + tools:context=".MainActivity" >
  10 +
  11 + <TextView
  12 + android:layout_width="wrap_content"
  13 + android:layout_height="wrap_content"
  14 + android:text="@string/hello_world" />
  15 +
  16 +</RelativeLayout>
... ...
app/src/main/res/layout/activity_multi_upload.xml 0 → 100644
  1 +++ a/app/src/main/res/layout/activity_multi_upload.xml
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3 + xmlns:app="http://schemas.android.com/apk/res-auto"
  4 + xmlns:tools="http://schemas.android.com/tools"
  5 + android:layout_width="match_parent"
  6 + android:layout_height="match_parent"
  7 + tools:context="com.ks3.demo.main.MultiUploadActivity">
  8 + <ListView
  9 + android:id="@+id/listView"
  10 + android:layout_width="match_parent"
  11 + android:layout_height="wrap_content" >
  12 + </ListView>
  13 +</android.support.constraint.ConstraintLayout>
... ...
app/src/main/res/layout/activity_upload.xml 0 → 100644
  1 +++ a/app/src/main/res/layout/activity_upload.xml
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3 + android:layout_width="match_parent"
  4 + android:layout_height="match_parent"
  5 + android:orientation="vertical"
  6 + android:layout_gravity="center_horizontal"
  7 + android:background="#FFFAFA"
  8 + >
  9 +
  10 +
  11 + <TextView
  12 + android:id="@+id/current_dir_tv"
  13 + android:layout_width="match_parent"
  14 + android:layout_height="50dip"
  15 + android:text="current_dir"
  16 + android:textSize="15sp"
  17 + android:layout_marginBottom="10dip"
  18 + android:textColor="#FF3030"
  19 + android:background="#36648B"
  20 + android:gravity="center"
  21 + />
  22 + <ListView
  23 + android:id="@+id/files"
  24 + android:layout_width="match_parent"
  25 + android:layout_height="wrap_content"
  26 + android:cacheColorHint="#848484"
  27 + android:background="#00000000"
  28 + android:divider="#8B8989"
  29 + android:dividerHeight="1dip"
  30 + ></ListView>
  31 +
  32 +
  33 +</LinearLayout>
... ...
app/src/main/res/layout/alert_bucket_input.xml 0 → 100644
  1 +++ a/app/src/main/res/layout/alert_bucket_input.xml
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3 + android:layout_width="match_parent"
  4 + android:layout_height="150dp" >
  5 +
  6 + <EditText
  7 + android:id="@+id/input"
  8 + android:layout_width="match_parent"
  9 + android:layout_height="wrap_content"
  10 + android:layout_alignParentLeft="true"
  11 + android:layout_alignParentTop="true"
  12 + android:ems="10"
  13 + android:hint="Bucket Name"
  14 + android:text="compose"
  15 + android:singleLine="true" >
  16 + <requestFocus />
  17 + </EditText>
  18 +
  19 + <Button
  20 + android:id="@+id/ok"
  21 + style="?android:attr/buttonStyleSmall"
  22 + android:layout_width="wrap_content"
  23 + android:layout_height="wrap_content"
  24 + android:layout_alignParentRight="true"
  25 + android:layout_centerVertical="true"
  26 + android:layout_marginRight="16dp"
  27 + android:text="OK" />
  28 +
  29 + <Button
  30 + android:id="@+id/cancel"
  31 + style="?android:attr/buttonStyleSmall"
  32 + android:layout_width="wrap_content"
  33 + android:layout_height="wrap_content"
  34 + android:layout_alignBaseline="@+id/ok"
  35 + android:layout_alignBottom="@+id/ok"
  36 + android:layout_marginRight="15dp"
  37 + android:layout_toLeftOf="@+id/ok"
  38 + android:text="CANCEL" />
  39 +
  40 +</RelativeLayout>
0 41 \ No newline at end of file
... ...
app/src/main/res/layout/alert_bucket_object_input.xml 0 → 100644
  1 +++ a/app/src/main/res/layout/alert_bucket_object_input.xml
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3 + android:layout_width="match_parent"
  4 + android:layout_height="150dp" >
  5 +
  6 + <Button
  7 + android:id="@+id/cancel"
  8 + style="?android:attr/buttonStyleSmall"
  9 + android:layout_width="wrap_content"
  10 + android:layout_height="wrap_content"
  11 + android:layout_alignParentBottom="true"
  12 + android:layout_marginBottom="18dp"
  13 + android:layout_marginRight="18dp"
  14 + android:layout_toLeftOf="@+id/ok"
  15 + android:text="CANCEL" />
  16 +
  17 + <Button
  18 + android:id="@+id/ok"
  19 + style="?android:attr/buttonStyleSmall"
  20 + android:layout_width="wrap_content"
  21 + android:layout_height="wrap_content"
  22 + android:layout_alignBaseline="@+id/cancel"
  23 + android:layout_alignBottom="@+id/cancel"
  24 + android:layout_alignParentRight="true"
  25 + android:layout_marginRight="19dp"
  26 + android:text="OK" />
  27 +
  28 + <EditText
  29 + android:id="@+id/input_second"
  30 + android:layout_width="match_parent"
  31 + android:layout_height="wrap_content"
  32 + android:layout_alignParentRight="true"
  33 + android:layout_below="@+id/input"
  34 + android:ems="10"
  35 + android:hint="Object Key"
  36 + android:singleLine="true" />
  37 +
  38 + <EditText
  39 + android:id="@+id/input"
  40 + android:layout_width="match_parent"
  41 + android:layout_height="wrap_content"
  42 + android:layout_alignParentLeft="true"
  43 + android:layout_alignParentTop="true"
  44 + android:ems="10"
  45 + android:hint="Bucket Name"
  46 + android:text="compose"
  47 + android:singleLine="true" >
  48 + <requestFocus />
  49 + </EditText>
  50 +
  51 +</RelativeLayout>
0 52 \ No newline at end of file
... ...
app/src/main/res/layout/download_list_item.xml 0 → 100644
  1 +++ a/app/src/main/res/layout/download_list_item.xml
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3 + android:layout_width="match_parent"
  4 + android:layout_height="60dip"
  5 + android:background="#00000000"
  6 + android:baselineAligned="false"
  7 + android:descendantFocusability="blocksDescendants"
  8 + android:orientation="horizontal"
  9 + android:weightSum="6" >
  10 +
  11 + <LinearLayout
  12 + android:id="@+id/remote_object_icon_layout"
  13 + android:layout_width="0dip"
  14 + android:layout_height="match_parent"
  15 + android:layout_gravity="center"
  16 + android:layout_weight="1" >
  17 +
  18 + <ImageView
  19 + android:id="@+id/remote_object_icon"
  20 + android:layout_width="40dip"
  21 + android:layout_height="40dip"
  22 + android:layout_margin="10dip" />
  23 + </LinearLayout>
  24 +
  25 + <LinearLayout
  26 + android:id="@+id/summary_layout"
  27 + android:layout_width="0dip"
  28 + android:layout_height="wrap_content"
  29 + android:layout_marginLeft="20dip"
  30 + android:layout_weight="4"
  31 + android:orientation="vertical" >
  32 +
  33 + <LinearLayout
  34 + android:id="@+id/remote_object_key_layout"
  35 + android:layout_width="match_parent"
  36 + android:layout_height="wrap_content"
  37 + android:layout_marginTop="10dip"
  38 + android:orientation="horizontal" >
  39 +
  40 + <TextView
  41 + android:id="@+id/remote_object_key"
  42 + android:layout_width="wrap_content"
  43 + android:layout_height="wrap_content"
  44 + android:singleLine="true"
  45 + android:textColor="#303030"
  46 + android:textSize="13sp" />
  47 + </LinearLayout>
  48 +
  49 + <LinearLayout
  50 + android:id="@+id/remote_object_summary_layout"
  51 + android:layout_width="match_parent"
  52 + android:layout_height="wrap_content"
  53 + android:layout_marginTop="6dip"
  54 + android:orientation="horizontal"
  55 + android:visibility="gone"
  56 + android:weightSum="5" >
  57 +
  58 + <TextView
  59 + android:id="@+id/remote_object_size"
  60 + android:layout_width="0dip"
  61 + android:layout_height="wrap_content"
  62 + android:layout_weight="1"
  63 + android:singleLine="true"
  64 + android:textColor="#708090"
  65 + android:textSize="10sp" />
  66 +
  67 + <TextView
  68 + android:id="@+id/remote_object_last_modiy"
  69 + android:layout_width="0dip"
  70 + android:layout_height="wrap_content"
  71 + android:layout_weight="2"
  72 + android:singleLine="true"
  73 + android:textColor="#708090"
  74 + android:textSize="10sp" />
  75 +
  76 + <TextView
  77 + android:layout_width="0dip"
  78 + android:layout_height="wrap_content"
  79 + android:layout_weight="2" />
  80 + </LinearLayout>
  81 +
  82 + <LinearLayout
  83 + android:id="@+id/progress_summary_layout"
  84 + android:layout_width="match_parent"
  85 + android:layout_height="wrap_content"
  86 + android:layout_marginBottom="5dip"
  87 + android:layout_marginTop="10dip"
  88 + android:orientation="horizontal"
  89 + android:visibility="gone"
  90 + android:weightSum="4" >
  91 +
  92 + <ProgressBar
  93 + android:id="@+id/download_progress_bar"
  94 + style="?android:attr/progressBarStyleHorizontal"
  95 + android:layout_width="0dip"
  96 + android:layout_height="match_parent"
  97 + android:layout_weight="3" />
  98 +
  99 + <TextView
  100 + android:id="@+id/download_progress_txt"
  101 + android:layout_width="0dip"
  102 + android:layout_height="wrap_content"
  103 + android:layout_marginLeft="10dip"
  104 + android:layout_weight="1"
  105 + android:text="0%"
  106 + android:textColor="#32CD32"
  107 + android:textSize="10sp" />
  108 + </LinearLayout>
  109 + </LinearLayout>
  110 +
  111 + <LinearLayout
  112 + android:layout_width="0dip"
  113 + android:layout_height="wrap_content"
  114 + android:layout_gravity="center"
  115 + android:layout_weight="1" >
  116 +
  117 + <ImageView
  118 + android:id="@+id/download_btn"
  119 + android:layout_width="20dip"
  120 + android:layout_height="20dip"
  121 + android:layout_marginRight="5dip"
  122 + android:background="#00000000"
  123 + android:focusable="false"
  124 + android:src="@drawable/ks_download" />
  125 + </LinearLayout>
  126 +
  127 +</LinearLayout>
0 128 \ No newline at end of file
... ...
app/src/main/res/layout/multiupload_item.xml 0 → 100644
  1 +++ a/app/src/main/res/layout/multiupload_item.xml
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3 + android:layout_width="match_parent"
  4 + android:layout_height="60dip"
  5 + android:background="#00000000"
  6 + android:orientation="horizontal">
  7 +
  8 + <TextView
  9 + android:id="@+id/file_name"
  10 + android:layout_width="wrap_content"
  11 + android:layout_height="match_parent"
  12 + android:text="filename"
  13 + android:textSize="25sp"
  14 + android:textColor="#303030"
  15 + android:singleLine="true"
  16 + />
  17 + <Button
  18 + android:id="@+id/uploadBtn"
  19 + android:layout_width="wrap_content"
  20 + android:layout_height="match_parent"
  21 + android:text="续传"/>
  22 +</LinearLayout>
0 23 \ No newline at end of file
... ...
app/src/main/res/layout/rest_api_test_result.xml 0 → 100644
  1 +++ a/app/src/main/res/layout/rest_api_test_result.xml
  1 +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2 + xmlns:tools="http://schemas.android.com/tools"
  3 + android:layout_width="match_parent"
  4 + android:layout_height="match_parent"
  5 + android:orientation="vertical"
  6 + >
  7 +
  8 + <TextView
  9 + android:id="@+id/api"
  10 + android:layout_width="wrap_content"
  11 + android:layout_height="wrap_content"
  12 + android:text="result"
  13 + android:textSize="20sp"
  14 + android:textColor="#555555"
  15 + android:layout_weight="1"
  16 + />
  17 +
  18 +
  19 + <ScrollView
  20 + android:layout_width="wrap_content"
  21 + android:layout_height="wrap_content"
  22 + android:layout_weight="4"
  23 + >
  24 +
  25 + <TextView
  26 + android:id="@+id/result"
  27 + android:layout_width="wrap_content"
  28 + android:layout_height="wrap_content"
  29 + android:text="@string/hello_world" />
  30 +
  31 + </ScrollView>
  32 +
  33 +</LinearLayout>
... ...
app/src/main/res/layout/upload_list_item.xml 0 → 100644
  1 +++ a/app/src/main/res/layout/upload_list_item.xml
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3 + android:layout_width="match_parent"
  4 + android:layout_height="60dip"
  5 + android:background="#00000000"
  6 + android:weightSum="6"
  7 + android:orientation="horizontal"
  8 + android:descendantFocusability= "blocksDescendants"
  9 + android:baselineAligned = "false"
  10 + >
  11 +
  12 + <LinearLayout
  13 + android:layout_width="0dip"
  14 + android:layout_height="match_parent"
  15 + android:layout_weight="1"
  16 + android:layout_gravity="center"
  17 + android:id="@+id/file_icon_layout"
  18 + >
  19 +
  20 + <ImageView
  21 + android:id="@+id/file_icon"
  22 + android:layout_width="40dip"
  23 + android:layout_height="40dip"
  24 + android:layout_margin="10dip"
  25 + />
  26 + </LinearLayout>
  27 +
  28 +
  29 +
  30 +
  31 +
  32 + <LinearLayout
  33 + android:layout_width="0dip"
  34 + android:layout_height="wrap_content"
  35 + android:layout_weight="4"
  36 + android:id="@+id/summary_layout"
  37 + android:orientation="vertical"
  38 + android:layout_marginLeft="20dip"
  39 +
  40 + >
  41 +
  42 + <LinearLayout
  43 + android:id="@+id/file_name_layout"
  44 + android:layout_height="wrap_content"
  45 + android:layout_width="match_parent"
  46 + android:orientation="horizontal"
  47 + android:layout_marginTop="10dip"
  48 +
  49 + >
  50 + <TextView
  51 + android:id="@+id/file_name"
  52 + android:layout_width="wrap_content"
  53 + android:layout_height="wrap_content"
  54 + android:textSize="13sp"
  55 + android:textColor="#303030"
  56 + android:singleLine="true"
  57 + />
  58 + </LinearLayout>
  59 + <LinearLayout
  60 + android:id="@+id/file_summary_layout"
  61 + android:layout_width="match_parent"
  62 + android:layout_height="wrap_content"
  63 + android:orientation="horizontal"
  64 + android:layout_marginTop="6dip"
  65 + android:visibility="gone"
  66 + android:weightSum="5"
  67 + >
  68 +
  69 + <TextView
  70 + android:id="@+id/file_size"
  71 + android:layout_width="0dip"
  72 + android:layout_height="wrap_content"
  73 + android:textSize="10sp"
  74 + android:textColor="#708090"
  75 + android:singleLine="true"
  76 + android:layout_weight="1"
  77 + />
  78 + <TextView
  79 + android:id="@+id/file_last_modiy"
  80 + android:layout_width="0dip"
  81 + android:layout_height="wrap_content"
  82 + android:textSize="10sp"
  83 + android:textColor="#708090"
  84 + android:singleLine="true"
  85 + android:layout_weight="2"
  86 + />
  87 + <TextView
  88 + android:layout_width="0dip"
  89 + android:layout_height="wrap_content"
  90 + android:layout_weight="2"
  91 + />
  92 + </LinearLayout>
  93 +
  94 + <LinearLayout
  95 + android:id="@+id/progress_summary_layout"
  96 + android:layout_width="match_parent"
  97 + android:layout_height="wrap_content"
  98 + android:orientation="horizontal"
  99 + android:layout_marginBottom="5dip"
  100 + android:layout_marginTop="10dip"
  101 + android:visibility="gone"
  102 + android:weightSum="4"
  103 + >
  104 +
  105 + <ProgressBar
  106 + android:id="@+id/upload_progress_bar"
  107 + android:layout_width="0dip"
  108 + android:layout_height="match_parent"
  109 + style="?android:attr/progressBarStyleHorizontal"
  110 + android:layout_weight="2"
  111 + />
  112 +
  113 + <TextView
  114 + android:id="@+id/upload_progress_txt"
  115 + android:layout_width="0dip"
  116 + android:layout_height="wrap_content"
  117 + android:text="0%"
  118 + android:textSize="10sp"
  119 + android:textColor="#32CD32"
  120 + android:layout_marginLeft="10dip"
  121 + android:layout_weight="2"
  122 + />
  123 +
  124 + </LinearLayout>
  125 +
  126 + </LinearLayout>
  127 +
  128 + <LinearLayout
  129 + android:layout_width="0dip"
  130 + android:layout_weight="1"
  131 + android:layout_height="wrap_content"
  132 + android:layout_gravity="center"
  133 + >
  134 +
  135 + <ImageView
  136 + android:id="@+id/upload_btn"
  137 + android:layout_height="20dip"
  138 + android:layout_width="20dip"
  139 + android:src="@drawable/ks_upload"
  140 + android:layout_marginRight="5dip"
  141 + android:background="#00000000"
  142 + android:focusable = "false"
  143 + />
  144 +
  145 +
  146 + </LinearLayout>
  147 +
  148 +
  149 +
  150 +
  151 +
  152 +
  153 +</LinearLayout>
... ...
app/src/main/res/menu/main.xml 0 → 100644
  1 +++ a/app/src/main/res/menu/main.xml
  1 +<menu xmlns:android="http://schemas.android.com/apk/res/android" >
  2 +
  3 + <item
  4 + android:id="@+id/action_settings"
  5 + android:orderInCategory="100"
  6 + android:showAsAction="never"
  7 + android:title="@string/action_settings"/>
  8 +
  9 +</menu>
... ...
app/src/main/res/mipmap-hdpi/ic_launcher.png 0 → 100644

3.34 KB

app/src/main/res/mipmap-hdpi/ic_launcher_round.png 0 → 100644

4.11 KB

app/src/main/res/mipmap-mdpi/ic_launcher.png 0 → 100644

2.15 KB