Commit 3b2e1ad8b2ebdec00b6eb890ec8b183b942a8c97

Authored by 王琳
0 parents

上传文件sdk

Showing 48 changed files with 1869 additions and 0 deletions
.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/encodings.xml 0 → 100644
  1 +++ a/.idea/encodings.xml
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<project version="4">
  3 + <component name="Encoding">
  4 + <file url="PROJECT" charset="UTF-8" />
  5 + </component>
  6 +</project>
0 7 \ 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 + <output url="file://$PROJECT_DIR$/build/classes" />
  42 + </component>
  43 + <component name="ProjectType">
  44 + <option name="id" value="Android" />
  45 + </component>
  46 + <component name="SvnConfiguration">
  47 + <configuration>C:\Users\Administrator\AppData\Roaming\Subversion</configuration>
  48 + </component>
  49 + <component name="masterDetails">
  50 + <states>
  51 + <state key="ProjectJDKs.UI">
  52 + <settings>
  53 + <last-edited>1.8</last-edited>
  54 + <splitter-proportions>
  55 + <option name="proportions">
  56 + <list>
  57 + <option value="0.2" />
  58 + </list>
  59 + </option>
  60 + </splitter-proportions>
  61 + </settings>
  62 + </state>
  63 + </states>
  64 + </component>
  65 +</project>
0 66 \ 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$/UploadSdk.iml" filepath="$PROJECT_DIR$/UploadSdk.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
... ...
.idea/runConfigurations.xml 0 → 100644
  1 +++ a/.idea/runConfigurations.xml
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<project version="4">
  3 + <component name="RunConfigurationProducerService">
  4 + <option name="ignoredProducers">
  5 + <set>
  6 + <option value="org.jetbrains.plugins.gradle.execution.test.runner.AllInPackageGradleConfigurationProducer" />
  7 + <option value="org.jetbrains.plugins.gradle.execution.test.runner.TestClassGradleConfigurationProducer" />
  8 + <option value="org.jetbrains.plugins.gradle.execution.test.runner.TestMethodGradleConfigurationProducer" />
  9 + </set>
  10 + </option>
  11 + </component>
  12 +</project>
0 13 \ 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 24
  5 + buildToolsVersion "24.0.2"
  6 + defaultConfig {
  7 + applicationId "libs.cnlive.com.uploadsdk"
  8 + minSdkVersion 16
  9 + targetSdkVersion 24
  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 + useLibrary 'org.apache.http.legacy'
  21 +}
  22 +
  23 +dependencies {
  24 + compile fileTree(include: ['*.jar'], dir: 'libs')
  25 + androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
  26 + exclude group: 'com.android.support', module: 'support-annotations'
  27 + })
  28 + compile 'com.android.support:appcompat-v7:24.2.0'
  29 + testCompile 'junit:junit:4.12'
  30 + compile files('libs/android-async-http-1.4.6.jar')
  31 +}
... ...
app/libs/android-async-http-1.4.6.jar 0 → 100644
No preview for this file type
app/libs/ks3-android-sdk-v1.1.0.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 D:\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 +#}
... ...
app/src/androidTest/java/libs/cnlive/com/uploadsdk/ExampleInstrumentedTest.java 0 → 100644
  1 +++ a/app/src/androidTest/java/libs/cnlive/com/uploadsdk/ExampleInstrumentedTest.java
  1 +package libs.cnlive.com.uploadsdk;
  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("libs.cnlive.com.uploadsdk", 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="libs.cnlive.com.uploadsdk">
  4 +
  5 + <uses-permission android:name="android.permission.INTERNET" />
  6 + <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
  7 + <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
  8 + <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
  9 +
  10 + <application
  11 + android:name=".SDK.UploadApplication"
  12 + android:allowBackup="true"
  13 + android:icon="@mipmap/ic_launcher"
  14 + android:label="@string/app_name"
  15 + android:supportsRtl="true"
  16 + android:theme="@style/AppTheme">
  17 + <activity android:name=".MainActivity">
  18 + <intent-filter>
  19 + <action android:name="android.intent.action.MAIN" />
  20 +
  21 + <category android:name="android.intent.category.LAUNCHER" />
  22 + </intent-filter>
  23 + </activity>
  24 + <activity android:name=".UploadActivity"></activity>
  25 + </application>
  26 +
  27 +</manifest>
0 28 \ No newline at end of file
... ...
app/src/main/java/libs/cnlive/com/uploadsdk/Contans.java 0 → 100644
  1 +++ a/app/src/main/java/libs/cnlive/com/uploadsdk/Contans.java
  1 +package libs.cnlive.com.uploadsdk;
  2 +
  3 +/**
  4 + * Created by Administrator on 2016/11/4.
  5 + */
  6 +
  7 +public class Contans {
  8 + public static final String ACCESS_KEY = "fWUN8KDtJZJGo0ArQ4qo";
  9 + public static final String ACCESS_SECRET = "UIWPYVeaV8kq2vWImDkLBvWs/pwmTJVF9MCNHDsC";
  10 + public static final String END_POINT = "ks3-cn-beijing.ksyun.com";
  11 + public static final long MULTI_UPLOAD_THREADHOLD = 16 * 1024 * 1024;
  12 +}
... ...
app/src/main/java/libs/cnlive/com/uploadsdk/MainActivity.java 0 → 100644
  1 +++ a/app/src/main/java/libs/cnlive/com/uploadsdk/MainActivity.java
  1 +package libs.cnlive.com.uploadsdk;
  2 +
  3 +import android.content.Intent;
  4 +import android.support.v7.app.AppCompatActivity;
  5 +import android.os.Bundle;
  6 +import android.view.View;
  7 +import android.widget.TextView;
  8 +
  9 +public class MainActivity extends AppCompatActivity implements View.OnClickListener {
  10 + private TextView textView;
  11 +
  12 + @Override
  13 + protected void onCreate(Bundle savedInstanceState) {
  14 + super.onCreate(savedInstanceState);
  15 + setContentView(R.layout.activity_main);
  16 + textView = (TextView) findViewById(R.id.upload_file);
  17 + textView.setOnClickListener(this);
  18 + }
  19 +
  20 + @Override
  21 + public void onClick(View v) {
  22 + Intent intent = new Intent(this, UploadActivity.class);
  23 + startActivity(intent);
  24 + }
  25 +}
... ...
app/src/main/java/libs/cnlive/com/uploadsdk/SDK/CNUploadActivity.java 0 → 100644
  1 +++ a/app/src/main/java/libs/cnlive/com/uploadsdk/SDK/CNUploadActivity.java
  1 +package libs.cnlive.com.uploadsdk.SDK;
  2 +
  3 +import android.content.Context;
  4 +import android.os.Bundle;
  5 +import android.os.Handler;
  6 +import android.os.Message;
  7 +import android.support.v7.app.AppCompatActivity;
  8 +import android.util.Log;
  9 +
  10 +import com.ksyun.ks3.exception.Ks3Error;
  11 +import com.ksyun.ks3.model.PartETag;
  12 +import com.ksyun.ks3.model.result.CompleteMultipartUploadResult;
  13 +import com.ksyun.ks3.model.result.InitiateMultipartUploadResult;
  14 +import com.ksyun.ks3.model.result.ListPartsResult;
  15 +import com.ksyun.ks3.services.Ks3Client;
  16 +import com.ksyun.ks3.services.Ks3ClientConfiguration;
  17 +import com.ksyun.ks3.services.handler.AbortMultipartUploadResponseHandler;
  18 +import com.ksyun.ks3.services.handler.CompleteMultipartUploadResponseHandler;
  19 +import com.ksyun.ks3.services.handler.InitiateMultipartUploadResponceHandler;
  20 +import com.ksyun.ks3.services.handler.ListPartsResponseHandler;
  21 +import com.ksyun.ks3.services.handler.UploadPartResponceHandler;
  22 +import com.ksyun.ks3.services.request.AbortMultipartUploadRequest;
  23 +import com.ksyun.ks3.services.request.CompleteMultipartUploadRequest;
  24 +import com.ksyun.ks3.services.request.InitiateMultipartUploadRequest;
  25 +import com.ksyun.ks3.services.request.ListPartsRequest;
  26 +import com.ksyun.ks3.services.request.UploadPartRequest;
  27 +
  28 +import org.apache.http.Header;
  29 +
  30 +import java.util.ArrayList;
  31 +import java.util.List;
  32 +
  33 +import libs.cnlive.com.uploadsdk.database.SQLiteDAOImpl;
  34 +
  35 +import static libs.cnlive.com.uploadsdk.SDK.UploadState.LIST_PART_FINISH;
  36 +import static libs.cnlive.com.uploadsdk.SDK.UploadState.UPDATE_SINGLE_UPLOAD_STATUS;
  37 +import static libs.cnlive.com.uploadsdk.SDK.UploadState.UPLOAD_NEXT_PART;
  38 +import static libs.cnlive.com.uploadsdk.SDK.UploadState.UPLOAD_PART_FINISH;
  39 +
  40 +/**
  41 + * Created by Administrator on 2016/11/4.
  42 + */
  43 +
  44 +public class CNUploadActivity extends AppCompatActivity {
  45 + public static final long PART_SIZE = 5 * 1024 * 1024;
  46 + private Ks3Client client;
  47 + private Ks3ClientConfiguration configuration;
  48 + // private Map<String, List<UploadFile>> dataSource;
  49 +// private File currentDir;
  50 + private SQLiteDAOImpl dao = new SQLiteDAOImpl(CNUploadActivity.this);
  51 + private MyHandler myHandler = new MyHandler();
  52 + private List<UploadFile> uploadFileList = new ArrayList<>();
  53 + private String mBucketname = "trans-test";
  54 +// private String mBucketKey = "androidtest";
  55 +
  56 +// public UploadActivity(Map<String, List<UploadFile>> dataSource, File currentDir) {
  57 +// this.dataSource = dataSource;
  58 +// this.currentDir = currentDir;
  59 +// }
  60 +
  61 +
  62 + @Override
  63 + public void onCreate(Bundle savedInstanceState) {
  64 + super.onCreate(savedInstanceState);
  65 + }
  66 +
  67 + //初始化Ks3Client
  68 + public void initUploadPart(String accessKey, String accessSecret, Context context, String endPoint) {
  69 + configuration = Ks3ClientConfiguration.getDefaultConfiguration();
  70 + client = new Ks3Client(accessKey, accessSecret, context);
  71 + client.setEndpoint(endPoint);
  72 + client.setConfiguration(configuration);
  73 + }
  74 +
  75 + //多块上传
  76 + public void uploadFile(UploadFile item) {
  77 + InitiateMultipartUploadRequest request = new InitiateMultipartUploadRequest(mBucketname, item.file.getName());
  78 + if (dao.find(item.file.getPath()) == null || dao.find(item.file.getPath()).getFilePath().isEmpty()) {
  79 + initiateMultipartUpload(request, item);
  80 + } else {
  81 + item.itemUploadPartFactory.partNumber = item.partNumber;
  82 + item.itemUploadPartFactory.offset = item.offset;
  83 + item.itemUploadPartFactory.remainingBytes = item.file.length() - (item.itemUploadPartFactory.partNumber - 1) * PART_SIZE;
  84 + item.status = UploadFile.STATUS_CONTINUE_UPLOAD_PART;
  85 + uploadpart(item);
  86 + }
  87 + }
  88 +
  89 + //初始化多块上传
  90 + private void initiateMultipartUpload(InitiateMultipartUploadRequest request, final UploadFile item) {
  91 + client.initiateMultipartUpload(request,
  92 + new InitiateMultipartUploadResponceHandler() {
  93 + @Override
  94 + public void onSuccess(int statesCode,
  95 + Header[] responceHeaders,
  96 + InitiateMultipartUploadResult result) {
  97 +// List<UploadFile> uploadFiles = dataSource
  98 +// .get(currentDir.getPath());
  99 +// for (UploadFile file : uploadFiles) {
  100 +// if (file.file.getPath().equalsIgnoreCase(item.file.getPath())) {
  101 +// file.status = UploadFile.STATUS_INIT;
  102 +// item.status = UploadFile.STATUS_INIT;
  103 +// }
  104 +// }
  105 + item.status = UploadFile.STATUS_INIT;
  106 + Log.e("++++++init", "---->" + item.file.getName() + " " + result.getUploadId());
  107 + if (dao.find(item.file.getPath()) == null || dao.find(item.file.getPath()).getFilePath().isEmpty()) {
  108 + dao.save(item.file.getPath(), result.getUploadId(), result.getKey(), 1, 0);
  109 + }
  110 + Log.e("---->", String.valueOf(dao.findAll().size()) + " " + dao.find(item.file.getPath()).getFilePath());
  111 +
  112 + uploadFileList.add(item);
  113 + beginMultiUpload(result, item);
  114 + myHandler.sendEmptyMessage(UploadState.UPDATE_SINGLE_UPLOAD_STATUS);
  115 + }
  116 +
  117 + @Override
  118 + public void onFailure(int statesCode, Ks3Error error,
  119 + Header[] responceHeaders, String response,
  120 + Throwable paramThrowable) {
  121 +// List<UploadFile> uploadFiles = dataSource
  122 +// .get(currentDir.getPath());
  123 +// for (UploadFile file : uploadFiles) {
  124 +// if (file.file.getPath().equalsIgnoreCase(
  125 +// item.file.getPath())) {
  126 +// file.status = UploadFile.STATUS_INIT_FAIL;
  127 +// item.status = UploadFile.STATUS_INIT_FAIL;
  128 +// }
  129 +// }
  130 + item.status = UploadFile.STATUS_INIT_FAIL;
  131 + Log.e("initFaliure", "---->" + statesCode);
  132 + myHandler.sendEmptyMessage(UploadState.UPDATE_SINGLE_UPLOAD_STATUS);
  133 + }
  134 + });
  135 + }
  136 +
  137 + private void beginMultiUpload(InitiateMultipartUploadResult initResult, UploadFile item) {
  138 + item.itemUploadPartFactory = new UploadPartFactory(
  139 + initResult.getBucket(), initResult.getKey(),
  140 + initResult.getUploadId(), item.file, PART_SIZE);
  141 + Message message = myHandler.obtainMessage();
  142 + message.what = UPLOAD_NEXT_PART;
  143 + Bundle bundle = new Bundle();
  144 + bundle.putSerializable("uploadFile", item);
  145 + message.setData(bundle);
  146 + myHandler.sendMessage(message);
  147 + }
  148 +
  149 + private void uploadpart(final UploadFile item) {
  150 + if (item.itemUploadPartFactory.hasMoreRequests()) {
  151 + final UploadPartRequest request = item.itemUploadPartFactory.getNextUploadPartRequest();
  152 + client.uploadPart(request, new UploadPartResponceHandler() {
  153 + double progressInFile = 0;
  154 +
  155 + @Override
  156 + public void onTaskProgress(double progress) {
  157 + long uploadedInpart = (long) (progress / 100 * request.contentLength);
  158 + long uploadedInFile = uploadedInpart + item.itemUploadPartFactory.getUploadSize();
  159 + progressInFile = Double
  160 + .valueOf(request.getFile().length() > 0 ? uploadedInFile
  161 + * 1.0D
  162 + / request.getFile().length()
  163 + * 100.0D
  164 + : -1.0D);
  165 +
  166 +// List<UploadFile> uploadFiles = dataSource.get(currentDir
  167 +// .getPath());
  168 +// for (UploadFile file : uploadFiles) {
  169 +// if (file.file.getPath().equalsIgnoreCase(item.file.getPath())) {
  170 +// if (item.isPaused) {
  171 +// Log.e("upload", "---->" + item.progress + "暂停");
  172 +// item.status = UploadFile.STATUS_PAUSED;
  173 +// file.status = UploadFile.STATUS_PAUSED;
  174 +// } else if (!item.isPaused && progressInFile > item.progress) {
  175 +// Log.e("upload", "---->" + item.progress + "上传");
  176 +// file.status = UploadFile.STATUS_UPLOADPART;
  177 +// file.progress = (int) progressInFile;
  178 +// item.status = UploadFile.STATUS_UPLOADPART;
  179 +// item.progress = (int) progressInFile;
  180 +// }
  181 +// }
  182 +// }
  183 +// item.progressInFile = progressInFile;
  184 +// item.status = UploadFile.STATUS_UPLOADPART;
  185 +
  186 +
  187 + if (item.isPaused) {
  188 +// item.progressInFile = progressInFile;
  189 + item.status = UploadFile.STATUS_PAUSED;
  190 + } else if (!item.isPaused && progressInFile > item.progress) {
  191 + item.progress = progressInFile;
  192 + item.status = UploadFile.STATUS_UPLOADPART;
  193 + }
  194 + Log.e("upload", "---->" + progressInFile + " " + item.progress);
  195 + myHandler.sendEmptyMessage(UploadState.UPDATE_SINGLE_UPLOAD_STATUS);
  196 + }
  197 +
  198 + @Override
  199 + public void onSuccess(int statesCode, Header[] responceHeaders,
  200 + PartETag result) {
  201 + if (!item.isPaused) {
  202 + Message message = myHandler.obtainMessage();
  203 + message.what = UploadState.UPLOAD_NEXT_PART;
  204 + Bundle bundle = new Bundle();
  205 + bundle.putSerializable("uploadFile", item);
  206 + message.setData(bundle);
  207 + myHandler.sendMessage(message);
  208 + }
  209 + }
  210 +
  211 + @Override
  212 + public void onFailure(int statesCode, Ks3Error error,
  213 + Header[] responceHeaders, String response,
  214 + Throwable throwable) {
  215 +// List<UploadFile> uploadFiles = dataSource.get(currentDir
  216 +// .getPath());
  217 +// for (UploadFile file : uploadFiles) {
  218 +// if (file.file.getPath().equalsIgnoreCase(
  219 +// item.file.getPath())) {
  220 +// file.status = UploadFile.STATUS_UPLOADPART_FAIL;
  221 +// file.progress = (int) progressInFile;
  222 +// item.status = UploadFile.STATUS_UPLOADPART_FAIL;
  223 +// item.progress = (int) progressInFile;
  224 +// }
  225 +// }
  226 + item.status = UploadFile.STATUS_UPLOADPART_FAIL;
  227 + item.progress = (int) progressInFile;
  228 + Log.e("upload failure", "---->" + request.getPartNumber() + " " + request.getFileOffset() + " " + request.getContentLength());
  229 + myHandler.sendEmptyMessage(UploadState.UPDATE_SINGLE_UPLOAD_STATUS);
  230 + Log.e("Upload failure", "");
  231 + }
  232 + });
  233 + Log.e("---", " " + item.file.getPath() + " " + request.getFileOffset());
  234 + item.partNumber = request.getPartNumber();
  235 + item.offset = request.getFileOffset();
  236 + dao.update(item.itemUploadPartFactory.getUploadId(), request.getPartNumber(), request.getFileOffset());
  237 + } else {
  238 + Message message = myHandler.obtainMessage();
  239 + message.what = UploadState.UPLOAD_PART_FINISH;
  240 + Bundle bundle = new Bundle();
  241 + bundle.putSerializable("uploadFile", item);
  242 + message.setData(bundle);
  243 + myHandler.sendMessage(message);
  244 + }
  245 + }
  246 +
  247 + private void listParts(ListPartsRequest request, final UploadFile item) {
  248 + client.listParts(request, new ListPartsResponseHandler() {
  249 + @Override
  250 + public void onFailure(int i, Ks3Error ks3Error, Header[] headers, String s, Throwable throwable) {
  251 +// List<UploadFile> uploadFiles = dataSource.get(currentDir.getPath());
  252 +// for (UploadFile file : uploadFiles) {
  253 +// if (file.file.getPath().equalsIgnoreCase(item.file.getPath())) {
  254 +// file.status = UploadFile.STATUS_LISTING_FAIL;
  255 +// item.status = UploadFile.STATUS_LISTING_FAIL;
  256 +// }
  257 +// }
  258 + item.status = UploadFile.STATUS_LISTING_FAIL;
  259 + myHandler.sendEmptyMessage(UPDATE_SINGLE_UPLOAD_STATUS);
  260 +
  261 + uploadFileList.remove(item);
  262 + dao.delete(item.file.getPath());
  263 + }
  264 +
  265 + @Override
  266 + public void onSuccess(int i, Header[] headers, ListPartsResult listPartsResult) {
  267 + Message message = myHandler.obtainMessage();
  268 + message.what = LIST_PART_FINISH;
  269 + message.obj = listPartsResult;
  270 + Bundle bundle = new Bundle();
  271 + bundle.putSerializable("uploadFile", item);
  272 + message.setData(bundle);
  273 + myHandler.sendMessage(message);
  274 + }
  275 + });
  276 + }
  277 +
  278 + private void completeUploadPart(CompleteMultipartUploadRequest request, final UploadFile item) {
  279 + client.completeMultipartUpload(request, new CompleteMultipartUploadResponseHandler() {
  280 + @Override
  281 + public void onFailure(int i, Ks3Error ks3Error, Header[] headers, String s, Throwable throwable) {
  282 +// List<UploadFile> uploadFiles = dataSource.get(currentDir.getPath());
  283 +// for (UploadFile file : uploadFiles) {
  284 +// if (file.file.getPath().equalsIgnoreCase(item.file.getPath())) {
  285 +// file.status = UploadFile.STATUS_COMPLETE_FAIL;
  286 +// file.progress = 100;
  287 +// item.status = UploadFile.STATUS_COMPLETE_FAIL;
  288 +// item.progress = 100;
  289 +// }
  290 +// }
  291 + item.status = UploadFile.STATUS_COMPLETE_FAIL;
  292 + item.progress = 100;
  293 + myHandler.sendEmptyMessage(0);
  294 + }
  295 +
  296 + @Override
  297 + public void onSuccess(int i, Header[] headers, CompleteMultipartUploadResult completeMultipartUploadResult) {
  298 +// List<UploadFile> uploadFiles = dataSource.get(currentDir.getPath());
  299 +// for (UploadFile file : uploadFiles) {
  300 +// if (file.file.getPath().equalsIgnoreCase(item.file.getPath())) {
  301 +// file.status = UploadFile.STATUS_COMPLETE;
  302 +// item.status = UploadFile.STATUS_COMPLETE;
  303 +// }
  304 +// }
  305 + item.status = UploadFile.STATUS_COMPLETE;
  306 + myHandler.sendEmptyMessage(0);
  307 + }
  308 + });
  309 +
  310 + uploadFileList.remove(item);
  311 + dao.delete(item.file.getPath());
  312 + }
  313 +
  314 + //取消多块上传
  315 + public void abortMultipartUpload(final UploadFile item) {
  316 + AbortMultipartUploadRequest request = new AbortMultipartUploadRequest(item.itemUploadPartFactory.getBucketName(), item.itemUploadPartFactory.getObjectKey(), item.itemUploadPartFactory.getUploadId());
  317 + client.abortMultipartUpload(request, new AbortMultipartUploadResponseHandler() {
  318 + @Override
  319 + public void onFailure(int i, Ks3Error ks3Error, Header[] headers, String s, Throwable throwable) {
  320 +
  321 + }
  322 +
  323 + @Override
  324 + public void onSuccess(int i, Header[] headers) {
  325 + uploadFileList.remove(item);
  326 + dao.delete(item.file.getPath());
  327 + }
  328 + });
  329 + }
  330 +
  331 + //暂停
  332 + public void pause(UploadFile item) {
  333 + client.pause(CNUploadActivity.this);
  334 + for (UploadFile uploadFile : uploadFileList) {
  335 + if (uploadFile.file.getPath().equals(item.file.getPath())) {
  336 + uploadFile.status = UploadFile.STATUS_PAUSED;
  337 + } else if (!uploadFile.file.getPath().equalsIgnoreCase(item.file.getPath())) {
  338 + uploadFile.itemUploadPartFactory.partNumber = uploadFile.partNumber;
  339 + uploadFile.itemUploadPartFactory.offset = uploadFile.offset;
  340 + uploadFile.itemUploadPartFactory.remainingBytes = uploadFile.file.length() - (uploadFile.partNumber - 1) * PART_SIZE;
  341 + uploadpart(uploadFile);
  342 + }
  343 + }
  344 + }
  345 +
  346 +
  347 + class MyHandler extends Handler {
  348 + @Override
  349 + public void handleMessage(Message msg) {
  350 + int what = msg.what;
  351 + Bundle bundle;
  352 + UploadFile item;
  353 + switch (what) {
  354 + case UPDATE_SINGLE_UPLOAD_STATUS:
  355 +// adapter.updateCurrent();
  356 + updateCurrent();
  357 + break;
  358 + case UPLOAD_NEXT_PART:
  359 + bundle = msg.getData();
  360 + item = (UploadFile) bundle.get("uploadFile");
  361 + uploadpart(item);
  362 + break;
  363 + case UPLOAD_PART_FINISH:
  364 + bundle = msg.getData();
  365 + item = (UploadFile) bundle.get("uploadFile");
  366 + ListPartsRequest listPartsRequest = new ListPartsRequest(
  367 + item.itemUploadPartFactory.getBucketName(),
  368 + item.itemUploadPartFactory.getObjectKey(),
  369 + item.itemUploadPartFactory.getUploadId());
  370 + listParts(listPartsRequest, item);
  371 + break;
  372 + case LIST_PART_FINISH:
  373 + ListPartsResult listResult = (ListPartsResult) msg.obj;
  374 + bundle = msg.getData();
  375 + item = (UploadFile) bundle.get("uploadFile");
  376 + CompleteMultipartUploadRequest comRequest = new CompleteMultipartUploadRequest(listResult);
  377 + completeUploadPart(comRequest, item);
  378 + break;
  379 + default:
  380 + break;
  381 + }
  382 + }
  383 + }
  384 +
  385 + public void updateCurrent() {
  386 + }
  387 +
  388 +}
... ...
app/src/main/java/libs/cnlive/com/uploadsdk/SDK/Config.java 0 → 100644
  1 +++ a/app/src/main/java/libs/cnlive/com/uploadsdk/SDK/Config.java
  1 +package libs.cnlive.com.uploadsdk.SDK;
  2 +
  3 +import android.app.Application;
  4 +import android.content.Context;
  5 +
  6 +/**
  7 + * Created by Administrator on 2016/11/4.
  8 + */
  9 +
  10 +public class Config {
  11 + private static Application context;
  12 +
  13 + public static void init(Context context) {
  14 + Config.context = ((Application) context.getApplicationContext());
  15 + }
  16 +
  17 + public static Context getContext() {
  18 + return context;
  19 + }
  20 +}
... ...
app/src/main/java/libs/cnlive/com/uploadsdk/SDK/UploadApplication.java 0 → 100644
  1 +++ a/app/src/main/java/libs/cnlive/com/uploadsdk/SDK/UploadApplication.java
  1 +package libs.cnlive.com.uploadsdk.SDK;
  2 +
  3 +import android.app.Application;
  4 +/**
  5 + * Created by Administrator on 2016/11/4.
  6 + */
  7 +
  8 +public class UploadApplication extends Application {
  9 + @Override
  10 + public void onCreate() {
  11 + super.onCreate();
  12 + Config.init(this);
  13 + }
  14 +}
... ...
app/src/main/java/libs/cnlive/com/uploadsdk/SDK/UploadFile.java 0 → 100644
  1 +++ a/app/src/main/java/libs/cnlive/com/uploadsdk/SDK/UploadFile.java
  1 +package libs.cnlive.com.uploadsdk.SDK;
  2 +
  3 +import java.io.File;
  4 +import java.io.Serializable;
  5 +
  6 +/**
  7 + * Created by Administrator on 2016/11/4.
  8 + */
  9 +
  10 +public class UploadFile implements Serializable {
  11 + public static final long serialVersionUID = 1L;
  12 + public static final int STATUS_NOT_START = 0;
  13 + // private static final int STATUS_STARTED = 1;
  14 + public static final int STATUS_UPLOADING = 2;
  15 + public static final int STATUS_INIT = 3;
  16 + public static final int STATUS_UPLOADPART = 4;
  17 + public static final int STATUS_LISTING = 5;
  18 + public static final int STATUS_COMPLETE = 6;
  19 + public static final int STATUS_FINISH = 7;
  20 + public static final int STATUS_FAIL = 8;
  21 + public static final int STATUS_INIT_FAIL = 9;
  22 + public static final int STATUS_UPLOADPART_FAIL = 10;
  23 + public static final int STATUS_LISTING_FAIL = 11;
  24 + public static final int STATUS_COMPLETE_FAIL = 12;
  25 + public static final int STATUS_PAUSED = 13;
  26 + public static final int STATUS_CONTINUE_UPLOAD_PART = 14;
  27 +
  28 + public File file;
  29 + public double progress = 0;
  30 + public int status;
  31 + public boolean isPaused = false;
  32 + public UploadPartFactory itemUploadPartFactory;
  33 + public int partNumber = 1;
  34 + public long offset;
  35 + public double progressInFile = 0;
  36 +
  37 + @Override
  38 + public String toString() {
  39 + return file.getName() + ",upload?" + status + ",progress:" + progress;
  40 + }
  41 +}
... ...
app/src/main/java/libs/cnlive/com/uploadsdk/SDK/UploadPartFactory.java 0 → 100644
  1 +++ a/app/src/main/java/libs/cnlive/com/uploadsdk/SDK/UploadPartFactory.java
  1 +package libs.cnlive.com.uploadsdk.SDK;
  2 +
  3 +import com.ksyun.ks3.services.request.UploadPartRequest;
  4 +
  5 +import java.io.File;
  6 +
  7 +/**
  8 + * Created by Administrator on 2016/11/4.
  9 + */
  10 +
  11 +public class UploadPartFactory {
  12 + private static final long serialVersionUID = 1L;
  13 + private String bucketName;
  14 + private String key;
  15 + private String uploadId;
  16 + private File file;
  17 + public int partNumber = 1;
  18 + public long offset = 0L;
  19 + public long remainingBytes;
  20 + private long partSize;
  21 + private long uploadSize;
  22 +
  23 + public UploadPartFactory(String bucketName, String objectKey, String uploadId, File file, long partSize) {
  24 + this.bucketName = bucketName;
  25 + this.key = objectKey;
  26 + this.uploadId = uploadId;
  27 + this.file = file;
  28 + this.partSize = partSize;
  29 + this.partNumber = 1;
  30 + this.uploadSize = 0;
  31 + this.remainingBytes = file.length();
  32 + }
  33 +
  34 + public synchronized boolean hasMoreRequests() {
  35 + return this.remainingBytes > 0L;
  36 + }
  37 +
  38 + //计算下一个UploadPartRequest配置参数,并返回对象
  39 + public synchronized UploadPartRequest getNextUploadPartRequest() {
  40 + boolean bool = this.remainingBytes - this.partSize <= 0L;
  41 + UploadPartRequest localUploadPartRequest;
  42 + uploadSize = file.length() - this.remainingBytes;
  43 + localUploadPartRequest = new UploadPartRequest(bucketName, key, uploadId, file, offset, partNumber++, partSize);
  44 + this.offset += partSize;
  45 + this.remainingBytes -= partSize;
  46 + localUploadPartRequest.setLastPart(bool);
  47 + return localUploadPartRequest;
  48 + }
  49 +
  50 + public synchronized long getUploadSize() {
  51 + return this.uploadSize;
  52 + }
  53 +
  54 + public synchronized File getFile() {
  55 + return this.file;
  56 + }
  57 +
  58 + public synchronized String getBucketName() {
  59 + return this.bucketName;
  60 + }
  61 +
  62 + public synchronized String getUploadId() {
  63 + return this.uploadId;
  64 + }
  65 +
  66 + public synchronized String getObjectKey() {
  67 + return this.key;
  68 + }
  69 +}
... ...
app/src/main/java/libs/cnlive/com/uploadsdk/SDK/UploadState.java 0 → 100644
  1 +++ a/app/src/main/java/libs/cnlive/com/uploadsdk/SDK/UploadState.java
  1 +package libs.cnlive.com.uploadsdk.SDK;
  2 +
  3 +/**
  4 + * Created by Administrator on 2016/11/4.
  5 + */
  6 +
  7 +public class UploadState {
  8 + public static final int UPDATE_SINGLE_UPLOAD_STATUS = 0;
  9 + public static final int PAUSE_UPLOAD = 1;
  10 + public static final int UPLOAD_NEXT_PART = 2;
  11 + public static final int UPLOAD_PART_FINISH = 3;
  12 + public static final int LIST_PART_FINISH = 4;
  13 +}
... ...
app/src/main/java/libs/cnlive/com/uploadsdk/UploadActivity.java 0 → 100644
  1 +++ a/app/src/main/java/libs/cnlive/com/uploadsdk/UploadActivity.java
  1 +package libs.cnlive.com.uploadsdk;
  2 +
  3 +import android.content.Context;
  4 +import android.os.Environment;
  5 +import android.os.Bundle;
  6 +import android.view.KeyEvent;
  7 +import android.view.LayoutInflater;
  8 +import android.view.View;
  9 +import android.view.ViewGroup;
  10 +import android.widget.AdapterView;
  11 +import android.widget.BaseAdapter;
  12 +import android.widget.LinearLayout;
  13 +import android.widget.ListView;
  14 +import android.widget.ProgressBar;
  15 +import android.widget.TextView;
  16 +import android.widget.Toast;
  17 +
  18 +
  19 +import java.io.File;
  20 +import java.util.ArrayList;
  21 +import java.util.HashMap;
  22 +import java.util.List;
  23 +import java.util.Map;
  24 +
  25 +import libs.cnlive.com.uploadsdk.SDK.CNUploadActivity;
  26 +import libs.cnlive.com.uploadsdk.SDK.UploadFile;
  27 +
  28 +public class UploadActivity extends CNUploadActivity implements AdapterView.OnItemClickListener {
  29 +
  30 + private ListView listView;
  31 + private TextView currentDirTextView;
  32 + private Map<String, List<UploadFile>> dataSource = new HashMap<>();
  33 + private File currentDir;
  34 + private FileAdapter adapter;
  35 +
  36 + @Override
  37 + public void onCreate(Bundle savedInstanceState) {
  38 + super.onCreate(savedInstanceState);
  39 + setContentView(R.layout.activity_upload);
  40 + listView = (ListView) findViewById(R.id.files);
  41 + currentDirTextView = (TextView) findViewById(R.id.current_dir_tv);
  42 + currentDir = Environment.getExternalStorageDirectory();
  43 + initUploadPart(Contans.ACCESS_KEY, Contans.ACCESS_SECRET, UploadActivity.this, Contans.END_POINT);
  44 + setUp();
  45 + }
  46 +
  47 + public void setUp() {
  48 + adapter = new FileAdapter(UploadActivity.this, null);
  49 + listView.setOnItemClickListener(this);
  50 + listView.setAdapter(adapter);
  51 + switchDir(Environment.getExternalStorageDirectory());
  52 + }
  53 +
  54 + private void switchDir(File dir) {
  55 + if (dir == null || !dir.exists() || dir.isFile()) {
  56 + throw new IllegalArgumentException("illegal dir");
  57 + }
  58 +
  59 + this.currentDir = dir;
  60 + this.currentDirTextView.setText("当前目录:" + this.currentDir.getPath());
  61 + List<UploadFile> uploadFiles = dataSource.get(dir.getPath());
  62 + if (uploadFiles != null && uploadFiles.size() > 0) {
  63 + adapter.fillDatas();
  64 + return;
  65 + }
  66 +
  67 + uploadFiles = new ArrayList<UploadFile>();
  68 + File[] files = dir.listFiles();
  69 + if (files != null && files.length > 0) {
  70 +
  71 + for (File file : files) {
  72 + UploadFile uploadFile = new UploadFile();
  73 + uploadFile.status = UploadFile.STATUS_NOT_START;
  74 + uploadFile.file = file;
  75 + uploadFile.progress = 0;
  76 + uploadFiles.add(uploadFile);
  77 + }
  78 + }
  79 + dataSource.put(dir.getPath(), uploadFiles);
  80 + adapter.fillDatas();
  81 + }
  82 +
  83 + @Override
  84 + public boolean onKeyDown(int keyCode, KeyEvent event) {
  85 + if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
  86 + if (currentDir.getPath().equalsIgnoreCase(Environment.getExternalStorageDirectory().getPath())) {
  87 + return super.onKeyDown(keyCode, event);
  88 + } else {
  89 + switchDir(currentDir.getParentFile());
  90 + return true;
  91 + }
  92 + }
  93 + return super.onKeyDown(keyCode, event);
  94 + }
  95 +
  96 + @Override
  97 + public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
  98 + UploadFile item = adapter.getItem(position);
  99 + if (item.file.isDirectory()) {
  100 + switchDir(item.file);
  101 + } else {
  102 + if (item.status == UploadFile.STATUS_UPLOADING || item.status == UploadFile.STATUS_FINISH)
  103 + return;
  104 + }
  105 + }
  106 +
  107 + class FileAdapter extends BaseAdapter {
  108 + private List<UploadFile> mUploadFiles;
  109 + private LayoutInflater mInflater;
  110 +
  111 + FileAdapter(Context context, List<UploadFile> uploadFiles) {
  112 + this.mUploadFiles = new ArrayList<>();
  113 + if (uploadFiles != null) {
  114 + this.mUploadFiles.addAll(uploadFiles);
  115 + }
  116 + this.mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  117 + }
  118 +
  119 + @Override
  120 + public int getCount() {
  121 + return mUploadFiles.size();
  122 + }
  123 +
  124 + @Override
  125 + public UploadFile getItem(int position) {
  126 + return this.mUploadFiles.get(position);
  127 + }
  128 +
  129 + @Override
  130 + public long getItemId(int position) {
  131 + return position;
  132 + }
  133 +
  134 + @Override
  135 + public View getView(final int position, View convertView, ViewGroup parent) {
  136 + final ViewHolder viewHolder;
  137 + if (convertView == null) {
  138 + convertView = mInflater.inflate(R.layout.upload_file_item,
  139 + parent, false);
  140 + viewHolder = new ViewHolder();
  141 + viewHolder.fileNameTextView = (TextView) convertView
  142 + .findViewById(R.id.file_name);
  143 + viewHolder.fileSummaryLayout = (LinearLayout) convertView
  144 + .findViewById(R.id.file_summary_layout);
  145 + viewHolder.fileSizeTextView = (TextView) convertView
  146 + .findViewById(R.id.file_size);
  147 + viewHolder.fileModiyTextView = (TextView) convertView
  148 + .findViewById(R.id.file_last_modiy);
  149 + viewHolder.uploadSummaryLayout = (LinearLayout) convertView
  150 + .findViewById(R.id.progress_summary_layout);
  151 + viewHolder.uploadProgressBar = (ProgressBar) convertView
  152 + .findViewById(R.id.upload_progress_bar);
  153 + viewHolder.progressTextView = (TextView) convertView
  154 + .findViewById(R.id.upload_progress_txt);
  155 + viewHolder.uploadBtn = (TextView) convertView
  156 + .findViewById(R.id.upload_btn);
  157 + viewHolder.pause = (TextView) convertView
  158 + .findViewById(R.id.pause);
  159 + viewHolder.abort = (TextView) convertView.findViewById(R.id.abort);
  160 + convertView.setTag(viewHolder);
  161 + } else {
  162 + viewHolder = (ViewHolder) convertView.getTag();
  163 + }
  164 + viewHolder.fileNameTextView.setText(mUploadFiles.get(position).file.getName());
  165 +
  166 + viewHolder.pause.setTag(position);
  167 + viewHolder.pause.setOnClickListener(new View.OnClickListener() {
  168 + @Override
  169 + public void onClick(View v) {
  170 + Toast.makeText(UploadActivity.this, "您点击了暂停:文件名" + getItem(position).file.getName(), Toast.LENGTH_SHORT).show();
  171 + pause(getItem(position));
  172 + getItem(position).isPaused = true;
  173 + }
  174 + });
  175 +
  176 + viewHolder.uploadBtn.setTag(position);
  177 + viewHolder.uploadBtn.setOnClickListener(new View.OnClickListener() {
  178 + @Override
  179 + public void onClick(View v) {
  180 + Toast.makeText(UploadActivity.this, "您点击了上传:文件名" + getItem(position).file.getName(), Toast.LENGTH_SHORT).show();
  181 + getItem(position).isPaused = false;
  182 + uploadFile(getItem(position));
  183 + }
  184 + });
  185 +
  186 + viewHolder.abort.setTag(position);
  187 + viewHolder.abort.setOnClickListener(new View.OnClickListener() {
  188 + @Override
  189 + public void onClick(View v) {
  190 + Toast.makeText(UploadActivity.this, "您点击了取消上传" + getItem(position).file.getName(), Toast.LENGTH_SHORT).show();
  191 + abortMultipartUpload(getItem(position));
  192 + }
  193 + });
  194 +
  195 + if (!mUploadFiles.get(position).file.isDirectory()) {
  196 + viewHolder.fileNameTextView.setVisibility(View.VISIBLE);
  197 + long size = mUploadFiles.get(position).file.length();
  198 + String sizeStr;
  199 +
  200 + if (size > 1024 * 1024) {
  201 + sizeStr = ((int) (size / 1024 / 1024) * 100) / 100 + "MB";
  202 + } else {
  203 + sizeStr = (mUploadFiles.get(position).file.length() / 1024) + "kb";
  204 + }
  205 + viewHolder.fileSizeTextView.setText(sizeStr);
  206 + if (mUploadFiles.get(position).status > UploadFile.STATUS_NOT_START) {
  207 + viewHolder.uploadSummaryLayout.setVisibility(View.VISIBLE);
  208 + viewHolder.uploadProgressBar.setProgress((int) mUploadFiles.get(position).progress);
  209 + viewHolder.fileSummaryLayout.setVisibility(View.GONE);
  210 + switch (mUploadFiles.get(position).status) {
  211 +// case UploadFile.STATUS_STARTED:
  212 +// viewHolder.progressTextView.setText("准备上传");
  213 +// break;
  214 + case UploadFile.STATUS_INIT:
  215 + viewHolder.progressTextView.setText("初始化完成");
  216 + break;
  217 + case UploadFile.STATUS_UPLOADPART:
  218 + viewHolder.progressTextView.setText("分块上传.."
  219 + + (int) (mUploadFiles.get(position).progress) + "%");
  220 + break;
  221 + case UploadFile.STATUS_LISTING:
  222 + viewHolder.progressTextView.setText("获取上传的块..");
  223 + break;
  224 + case UploadFile.STATUS_COMPLETE:
  225 + viewHolder.progressTextView.setText("合并完成");
  226 + break;
  227 + case UploadFile.STATUS_UPLOADING:
  228 + viewHolder.progressTextView.setText(mUploadFiles
  229 + .get(position).progress + "%");
  230 + break;
  231 + case UploadFile.STATUS_FINISH:
  232 + viewHolder.progressTextView.setText("完成上传");
  233 + break;
  234 + case UploadFile.STATUS_FAIL:
  235 + viewHolder.progressTextView.setText("上传失败");
  236 + break;
  237 +
  238 + case UploadFile.STATUS_INIT_FAIL:
  239 + viewHolder.progressTextView.setText("上传失败");
  240 + break;
  241 + case UploadFile.STATUS_UPLOADPART_FAIL:
  242 + viewHolder.progressTextView.setText("分块上传失败");
  243 + break;
  244 + case UploadFile.STATUS_LISTING_FAIL:
  245 + viewHolder.progressTextView.setText("获取块失败");
  246 + break;
  247 + case UploadFile.STATUS_COMPLETE_FAIL:
  248 + viewHolder.progressTextView.setText("文件合并失败");
  249 + break;
  250 + case UploadFile.STATUS_PAUSED:
  251 + viewHolder.progressTextView.setText("已暂停");
  252 + break;
  253 + case UploadFile.STATUS_CONTINUE_UPLOAD_PART:
  254 + viewHolder.progressTextView.setText("准备继续上传");
  255 + break;
  256 + }
  257 + } else {
  258 + viewHolder.fileSummaryLayout.setVisibility(View.VISIBLE);
  259 + viewHolder.uploadBtn.setVisibility(View.VISIBLE);
  260 + viewHolder.uploadSummaryLayout.setVisibility(View.GONE);
  261 + viewHolder.pause.setVisibility(View.VISIBLE);
  262 + viewHolder.abort.setVisibility(View.VISIBLE);
  263 + }
  264 + } else {
  265 + viewHolder.fileSummaryLayout.setVisibility(View.GONE);
  266 + viewHolder.uploadSummaryLayout.setVisibility(View.GONE);
  267 + viewHolder.uploadBtn.setVisibility(View.GONE);
  268 + viewHolder.pause.setVisibility(View.GONE);
  269 + viewHolder.abort.setVisibility(View.GONE);
  270 + }
  271 + return convertView;
  272 + }
  273 +
  274 + public void fillDatas() {
  275 + this.mUploadFiles.clear();
  276 + this.mUploadFiles.addAll(dataSource.get(currentDir.getPath()));
  277 + this.notifyDataSetChanged();
  278 + }
  279 +
  280 + public void updateCurrent() {
  281 + this.notifyDataSetChanged();
  282 + }
  283 +
  284 + class ViewHolder {
  285 + TextView fileNameTextView;
  286 + LinearLayout fileSummaryLayout;
  287 + TextView fileSizeTextView;
  288 + TextView fileModiyTextView;
  289 + LinearLayout uploadSummaryLayout;
  290 + ProgressBar uploadProgressBar;
  291 + TextView progressTextView;
  292 + TextView uploadBtn;
  293 + TextView pause;
  294 + TextView abort;
  295 + }
  296 + }
  297 +
  298 + @Override
  299 + public void updateCurrent() {
  300 + super.updateCurrent();
  301 + adapter.updateCurrent();
  302 + }
  303 +}
... ...
app/src/main/java/libs/cnlive/com/uploadsdk/database/DBOpenHelper.java 0 → 100644
  1 +++ a/app/src/main/java/libs/cnlive/com/uploadsdk/database/DBOpenHelper.java
  1 +package libs.cnlive.com.uploadsdk.database;
  2 +
  3 +import android.content.Context;
  4 +import android.database.sqlite.SQLiteDatabase;
  5 +import android.database.sqlite.SQLiteOpenHelper;
  6 +
  7 +/**
  8 + * Created by Administrator on 2016/10/21.
  9 + */
  10 +
  11 +public class DBOpenHelper extends SQLiteOpenHelper {
  12 + public DBOpenHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
  13 + super(context, name, factory, version);
  14 + }
  15 +
  16 + @Override
  17 + public void onCreate(SQLiteDatabase db) {
  18 + db.execSQL("create table cnlive_file(id integer primary key autoincrement,filepath varchar(200),uploadid varchar(200), bucketkey varchar(200), partnumber integer, uploadsize long)");
  19 + }
  20 +
  21 + @Override
  22 + public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
  23 +
  24 + }
  25 +}
... ...
app/src/main/java/libs/cnlive/com/uploadsdk/database/SQLiteDAOImpl.java 0 → 100644
  1 +++ a/app/src/main/java/libs/cnlive/com/uploadsdk/database/SQLiteDAOImpl.java
  1 +package libs.cnlive.com.uploadsdk.database;
  2 +
  3 +import android.content.ContentValues;
  4 +import android.content.Context;
  5 +import android.database.Cursor;
  6 +import android.database.sqlite.SQLiteDatabase;
  7 +
  8 +import java.util.ArrayList;
  9 +import java.util.List;
  10 +
  11 +/**
  12 + * Created by Administrator on 2016/9/22.
  13 + */
  14 +public class SQLiteDAOImpl {
  15 + private DBOpenHelper helper;
  16 +
  17 + public SQLiteDAOImpl(Context context) {
  18 + this.helper = new DBOpenHelper(context, "CNLuploadFile.db", null, 1);
  19 + }
  20 +
  21 + public UploadFileEntity find(String filePath) {// 根据文件路径查找纪录
  22 + UploadFileEntity uploadFileEntity = null;
  23 + SQLiteDatabase db = helper.getReadableDatabase();
  24 + // 用游标Cursor接收从数据库检索到的数据
  25 + Cursor cursor = null;
  26 + cursor = db.rawQuery("select * from cnlive_file where filepath=?", new String[]{filePath});
  27 + if (cursor.moveToFirst()) {// 依次取出数据
  28 + uploadFileEntity = new UploadFileEntity();
  29 + uploadFileEntity.setFilePath(cursor.getString(cursor.getColumnIndex("filepath")));
  30 + uploadFileEntity.setUploadId(cursor.getString(cursor.getColumnIndex("uploadid")));
  31 + uploadFileEntity.setBucketKey(cursor.getString(cursor.getColumnIndex("bucketkey")));
  32 + uploadFileEntity.setPartNumber(cursor.getInt(cursor.getColumnIndex("partnumber")));
  33 + uploadFileEntity.setUploadSize(cursor.getLong(cursor.getColumnIndex("uploadsize")));
  34 + }
  35 + db.close();
  36 + return uploadFileEntity;
  37 + }
  38 +
  39 + public void save(String filePath, String uploadId, String bucketKey, int partNumber, long uploadSize) {// 插入记录
  40 + SQLiteDatabase db = helper.getWritableDatabase();// 取得数据库操作
  41 + ContentValues values = new ContentValues();
  42 + values.put("filepath", filePath);
  43 + values.put("uploadid", uploadId);
  44 + values.put("bucketkey", bucketKey);
  45 + values.put("partnumber", partNumber);
  46 + values.put("uploadsize", uploadSize);
  47 + db.insert("cnlive_file", null, values);
  48 + db.close();// 记得关闭数据库操作
  49 + }
  50 +
  51 + public void update(String uploadId, int partNumber, long uploadSize) {// 修改纪录
  52 + SQLiteDatabase db = helper.getWritableDatabase();
  53 + ContentValues values = new ContentValues();
  54 + values.put("partnumber", partNumber);
  55 + values.put("uploadsize", uploadSize);
  56 + db.update("cnlive_file", values, "uploadid=?", new String[]{uploadId});
  57 + db.close();
  58 + }
  59 +
  60 + public void delete(String filePath) {
  61 + SQLiteDatabase db = helper.getWritableDatabase();
  62 + db.delete("cnlive_file", "filepath=?", new String[]{filePath});
  63 + db.close();
  64 + }
  65 +
  66 + public List<UploadFileEntity> findAll() {// 查询所有记录
  67 + List<UploadFileEntity> lists = new ArrayList<>();
  68 + UploadFileEntity uploadFileEntity;
  69 + SQLiteDatabase db = helper.getReadableDatabase();
  70 +
  71 + Cursor cursor = db.rawQuery("select * from cnlive_file", null);
  72 + while (cursor.moveToNext()) {
  73 + uploadFileEntity = new UploadFileEntity();
  74 + uploadFileEntity.setFilePath(cursor.getString(cursor.getColumnIndex("filepath")));
  75 + uploadFileEntity.setUploadId(cursor.getString(cursor.getColumnIndex("uploadid")));
  76 + uploadFileEntity.setBucketKey(cursor.getString(cursor.getColumnIndex("bucketkey")));
  77 + uploadFileEntity.setPartNumber(cursor.getInt(cursor.getColumnIndex("partnumber")));
  78 + lists.add(uploadFileEntity);
  79 + }
  80 + db.close();
  81 + return lists;
  82 + }
  83 +}
... ...
app/src/main/java/libs/cnlive/com/uploadsdk/database/UploadFileEntity.java 0 → 100644
  1 +++ a/app/src/main/java/libs/cnlive/com/uploadsdk/database/UploadFileEntity.java
  1 +package libs.cnlive.com.uploadsdk.database;
  2 +
  3 +/**
  4 + * Created by Administrator on 2016/10/21.
  5 + */
  6 +
  7 +public class UploadFileEntity {
  8 + private String filePath;
  9 + private String uploadId;
  10 + private String bucketKey;
  11 + private int partNumber;
  12 + private long uploadSize;
  13 +
  14 + public String getFilePath() {
  15 + return filePath;
  16 + }
  17 +
  18 + public void setFilePath(String filePath) {
  19 + this.filePath = filePath;
  20 + }
  21 +
  22 + public String getUploadId() {
  23 + return uploadId;
  24 + }
  25 +
  26 + public void setUploadId(String uploadId) {
  27 + this.uploadId = uploadId;
  28 + }
  29 +
  30 + public String getBucketKey() {
  31 + return bucketKey;
  32 + }
  33 +
  34 + public void setBucketKey(String bucketKey) {
  35 + this.bucketKey = bucketKey;
  36 + }
  37 +
  38 + public int getPartNumber() {
  39 + return partNumber;
  40 + }
  41 +
  42 + public void setPartNumber(int partNumber) {
  43 + this.partNumber = partNumber;
  44 + }
  45 +
  46 + public long getUploadSize() {
  47 + return uploadSize;
  48 + }
  49 +
  50 + public void setUploadSize(long uploadSize) {
  51 + this.uploadSize = uploadSize;
  52 + }
  53 +}
... ...
app/src/main/res/layout/activity_main.xml 0 → 100644
  1 +++ a/app/src/main/res/layout/activity_main.xml
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3 + xmlns:tools="http://schemas.android.com/tools"
  4 + android:id="@+id/activity_main"
  5 + android:layout_width="match_parent"
  6 + android:layout_height="match_parent"
  7 + android:paddingBottom="@dimen/activity_vertical_margin"
  8 + android:paddingLeft="@dimen/activity_horizontal_margin"
  9 + android:paddingRight="@dimen/activity_horizontal_margin"
  10 + android:paddingTop="@dimen/activity_vertical_margin"
  11 + tools:context="libs.cnlive.com.uploadsdk.MainActivity">
  12 +
  13 + <TextView
  14 + android:id="@+id/upload_file"
  15 + android:layout_width="wrap_content"
  16 + android:layout_height="wrap_content"
  17 + android:text="UPLOAD FILE" />
  18 +</RelativeLayout>
... ...
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/upload_file_item.xml 0 → 100644
  1 +++ a/app/src/main/res/layout/upload_file_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 +
  12 + <LinearLayout
  13 + android:id="@+id/summary_layout"
  14 + android:layout_width="0dip"
  15 + android:layout_height="wrap_content"
  16 + android:layout_marginLeft="20dip"
  17 + android:layout_weight="3"
  18 + android:orientation="vertical"
  19 +
  20 + >
  21 +
  22 + <LinearLayout
  23 + android:id="@+id/file_name_layout"
  24 + android:layout_width="match_parent"
  25 + android:layout_height="wrap_content"
  26 + android:layout_marginTop="10dip"
  27 + android:orientation="horizontal"
  28 +
  29 + >
  30 +
  31 + <TextView
  32 + android:id="@+id/file_name"
  33 + android:layout_width="wrap_content"
  34 + android:layout_height="wrap_content"
  35 + android:singleLine="true"
  36 + android:textColor="#303030"
  37 + android:textSize="13sp" />
  38 + </LinearLayout>
  39 +
  40 + <LinearLayout
  41 + android:id="@+id/file_summary_layout"
  42 + android:layout_width="match_parent"
  43 + android:layout_height="wrap_content"
  44 + android:layout_marginTop="6dip"
  45 + android:orientation="horizontal"
  46 + android:visibility="gone"
  47 + android:weightSum="5">
  48 +
  49 + <TextView
  50 + android:id="@+id/file_size"
  51 + android:layout_width="0dip"
  52 + android:layout_height="wrap_content"
  53 + android:layout_weight="1"
  54 + android:singleLine="true"
  55 + android:textColor="#708090"
  56 + android:textSize="10sp" />
  57 +
  58 + <TextView
  59 + android:id="@+id/file_last_modiy"
  60 + android:layout_width="0dip"
  61 + android:layout_height="wrap_content"
  62 + android:layout_weight="2"
  63 + android:singleLine="true"
  64 + android:textColor="#708090"
  65 + android:textSize="10sp" />
  66 +
  67 + <TextView
  68 + android:layout_width="0dip"
  69 + android:layout_height="wrap_content"
  70 + android:layout_weight="2" />
  71 + </LinearLayout>
  72 +
  73 + <LinearLayout
  74 + android:id="@+id/progress_summary_layout"
  75 + android:layout_width="match_parent"
  76 + android:layout_height="wrap_content"
  77 + android:layout_marginBottom="5dip"
  78 + android:layout_marginTop="10dip"
  79 + android:orientation="horizontal"
  80 + android:visibility="gone"
  81 + android:weightSum="4">
  82 +
  83 + <ProgressBar
  84 + android:id="@+id/upload_progress_bar"
  85 + style="?android:attr/progressBarStyleHorizontal"
  86 + android:layout_width="0dip"
  87 + android:layout_height="match_parent"
  88 + android:layout_weight="2" />
  89 +
  90 + <TextView
  91 + android:id="@+id/upload_progress_txt"
  92 + android:layout_width="0dip"
  93 + android:layout_height="wrap_content"
  94 + android:layout_marginLeft="10dip"
  95 + android:layout_weight="2"
  96 + android:text="0%"
  97 + android:textColor="#32CD32"
  98 + android:textSize="10sp" />
  99 +
  100 + </LinearLayout>
  101 +
  102 + </LinearLayout>
  103 +
  104 + <RelativeLayout
  105 + android:layout_width="0dip"
  106 + android:layout_height="wrap_content"
  107 + android:layout_gravity="center"
  108 + android:layout_weight="3">
  109 +
  110 + <TextView
  111 + android:id="@+id/upload_btn"
  112 + android:layout_width="40dp"
  113 + android:layout_height="40dp"
  114 + android:gravity="center"
  115 + android:text="上传" />
  116 +
  117 + <TextView
  118 + android:id="@+id/pause"
  119 + android:layout_width="40dp"
  120 + android:layout_height="40dp"
  121 + android:layout_marginLeft="5dp"
  122 + android:layout_toRightOf="@+id/upload_btn"
  123 + android:background="#00ff00"
  124 + android:gravity="center"
  125 + android:text="暂停" />
  126 +
  127 + <TextView
  128 + android:id="@+id/abort"
  129 + android:layout_width="40dp"
  130 + android:layout_height="40dp"
  131 + android:layout_marginLeft="5dp"
  132 + android:layout_toRightOf="@+id/pause"
  133 + android:background="#00f0ff"
  134 + android:gravity="center"
  135 + android:text="取消" />
  136 +
  137 +
  138 + </RelativeLayout>
  139 +
  140 +
  141 +</LinearLayout>
... ...
app/src/main/res/mipmap-hdpi/ic_launcher.png 0 → 100644

3.34 KB

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

2.15 KB

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

4.73 KB

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

7.54 KB

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

10.2 KB

app/src/main/res/values-w820dp/dimens.xml 0 → 100644
  1 +++ a/app/src/main/res/values-w820dp/dimens.xml
  1 +<resources>
  2 + <!-- Example customization of dimensions originally defined in res/values/dimens.xml
  3 + (such as screen margins) for screens with more than 820dp of available width. This
  4 + would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). -->
  5 + <dimen name="activity_horizontal_margin">64dp</dimen>
  6 +</resources>
... ...
app/src/main/res/values/colors.xml 0 → 100644
  1 +++ a/app/src/main/res/values/colors.xml
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<resources>
  3 + <color name="colorPrimary">#3F51B5</color>
  4 + <color name="colorPrimaryDark">#303F9F</color>
  5 + <color name="colorAccent">#FF4081</color>
  6 +</resources>
... ...
app/src/main/res/values/dimens.xml 0 → 100644
  1 +++ a/app/src/main/res/values/dimens.xml
  1 +<resources>
  2 + <!-- Default screen margins, per the Android Design guidelines. -->
  3 + <dimen name="activity_horizontal_margin">16dp</dimen>
  4 + <dimen name="activity_vertical_margin">16dp</dimen>
  5 +</resources>
... ...
app/src/main/res/values/strings.xml 0 → 100644
  1 +++ a/app/src/main/res/values/strings.xml
  1 +<resources>
  2 + <string name="app_name">UploadSdk</string>
  3 +</resources>
... ...
app/src/main/res/values/styles.xml 0 → 100644
  1 +++ a/app/src/main/res/values/styles.xml
  1 +<resources>
  2 +
  3 + <!-- Base application theme. -->
  4 + <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
  5 + <!-- Customize your theme here. -->
  6 + <item name="colorPrimary">@color/colorPrimary</item>
  7 + <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
  8 + <item name="colorAccent">@color/colorAccent</item>
  9 + </style>
  10 +
  11 +</resources>
... ...
app/src/test/java/libs/cnlive/com/uploadsdk/ExampleUnitTest.java 0 → 100644
  1 +++ a/app/src/test/java/libs/cnlive/com/uploadsdk/ExampleUnitTest.java
  1 +package libs.cnlive.com.uploadsdk;
  2 +
  3 +import org.junit.Test;
  4 +
  5 +import static org.junit.Assert.*;
  6 +
  7 +/**
  8 + * Example local unit test, which will execute on the development machine (host).
  9 + *
  10 + * @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
  11 + */
  12 +public class ExampleUnitTest {
  13 + @Test
  14 + public void addition_isCorrect() throws Exception {
  15 + assertEquals(4, 2 + 2);
  16 + }
  17 +}
0 18 \ No newline at end of file
... ...
build.gradle 0 → 100644
  1 +++ a/build.gradle
  1 +// Top-level build file where you can add configuration options common to all sub-projects/modules.
  2 +
  3 +buildscript {
  4 + repositories {
  5 + jcenter()
  6 + }
  7 + dependencies {
  8 + classpath 'com.android.tools.build:gradle:2.2.2'
  9 +
  10 + // NOTE: Do not place your application dependencies here; they belong
  11 + // in the individual module build.gradle files
  12 + }
  13 +}
  14 +
  15 +allprojects {
  16 + repositories {
  17 + jcenter()
  18 + }
  19 +}
  20 +
  21 +task clean(type: Delete) {
  22 + delete rootProject.buildDir
  23 +}
... ...
gradle.properties 0 → 100644
  1 +++ a/gradle.properties
  1 +# Project-wide Gradle settings.
  2 +
  3 +# IDE (e.g. Android Studio) users:
  4 +# Gradle settings configured through the IDE *will override*
  5 +# any settings specified in this file.
  6 +
  7 +# For more details on how to configure your build environment visit
  8 +# http://www.gradle.org/docs/current/userguide/build_environment.html
  9 +
  10 +# Specifies the JVM arguments used for the daemon process.
  11 +# The setting is particularly useful for tweaking memory settings.
  12 +org.gradle.jvmargs=-Xmx1536m
  13 +
  14 +# When configured, Gradle will run in incubating parallel mode.
  15 +# This option should only be used with decoupled projects. More details, visit
  16 +# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
  17 +# org.gradle.parallel=true
... ...
gradle/wrapper/gradle-wrapper.jar 0 → 100644
No preview for this file type
gradle/wrapper/gradle-wrapper.properties 0 → 100644
  1 +++ a/gradle/wrapper/gradle-wrapper.properties
  1 +#Mon Dec 28 10:00:20 PST 2015
  2 +distributionBase=GRADLE_USER_HOME
  3 +distributionPath=wrapper/dists
  4 +zipStoreBase=GRADLE_USER_HOME
  5 +zipStorePath=wrapper/dists
  6 +distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
... ...
gradlew 0 → 100644
  1 +++ a/gradlew
  1 +#!/usr/bin/env bash
  2 +
  3 +##############################################################################
  4 +##
  5 +## Gradle start up script for UN*X
  6 +##
  7 +##############################################################################
  8 +
  9 +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
  10 +DEFAULT_JVM_OPTS=""
  11 +
  12 +APP_NAME="Gradle"
  13 +APP_BASE_NAME=`basename "$0"`
  14 +
  15 +# Use the maximum available, or set MAX_FD != -1 to use that value.
  16 +MAX_FD="maximum"
  17 +
  18 +warn ( ) {
  19 + echo "$*"
  20 +}
  21 +
  22 +die ( ) {
  23 + echo
  24 + echo "$*"
  25 + echo
  26 + exit 1
  27 +}
  28 +
  29 +# OS specific support (must be 'true' or 'false').
  30 +cygwin=false
  31 +msys=false
  32 +darwin=false
  33 +case "`uname`" in
  34 + CYGWIN* )
  35 + cygwin=true
  36 + ;;
  37 + Darwin* )
  38 + darwin=true
  39 + ;;
  40 + MINGW* )
  41 + msys=true
  42 + ;;
  43 +esac
  44 +
  45 +# Attempt to set APP_HOME
  46 +# Resolve links: $0 may be a link
  47 +PRG="$0"
  48 +# Need this for relative symlinks.
  49 +while [ -h "$PRG" ] ; do
  50 + ls=`ls -ld "$PRG"`
  51 + link=`expr "$ls" : '.*-> \(.*\)$'`
  52 + if expr "$link" : '/.*' > /dev/null; then
  53 + PRG="$link"
  54 + else
  55 + PRG=`dirname "$PRG"`"/$link"
  56 + fi
  57 +done
  58 +SAVED="`pwd`"
  59 +cd "`dirname \"$PRG\"`/" >/dev/null
  60 +APP_HOME="`pwd -P`"
  61 +cd "$SAVED" >/dev/null
  62 +
  63 +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
  64 +
  65 +# Determine the Java command to use to start the JVM.
  66 +if [ -n "$JAVA_HOME" ] ; then
  67 + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
  68 + # IBM's JDK on AIX uses strange locations for the executables
  69 + JAVACMD="$JAVA_HOME/jre/sh/java"
  70 + else
  71 + JAVACMD="$JAVA_HOME/bin/java"
  72 + fi
  73 + if [ ! -x "$JAVACMD" ] ; then
  74 + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
  75 +
  76 +Please set the JAVA_HOME variable in your environment to match the
  77 +location of your Java installation."
  78 + fi
  79 +else
  80 + JAVACMD="java"
  81 + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
  82 +
  83 +Please set the JAVA_HOME variable in your environment to match the
  84 +location of your Java installation."
  85 +fi
  86 +
  87 +# Increase the maximum file descriptors if we can.
  88 +if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
  89 + MAX_FD_LIMIT=`ulimit -H -n`
  90 + if [ $? -eq 0 ] ; then
  91 + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
  92 + MAX_FD="$MAX_FD_LIMIT"
  93 + fi
  94 + ulimit -n $MAX_FD
  95 + if [ $? -ne 0 ] ; then
  96 + warn "Could not set maximum file descriptor limit: $MAX_FD"
  97 + fi
  98 + else
  99 + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
  100 + fi
  101 +fi
  102 +
  103 +# For Darwin, add options to specify how the application appears in the dock
  104 +if $darwin; then
  105 + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
  106 +fi
  107 +
  108 +# For Cygwin, switch paths to Windows format before running java
  109 +if $cygwin ; then
  110 + APP_HOME=`cygpath --path --mixed "$APP_HOME"`
  111 + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
  112 + JAVACMD=`cygpath --unix "$JAVACMD"`
  113 +
  114 + # We build the pattern for arguments to be converted via cygpath
  115 + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
  116 + SEP=""
  117 + for dir in $ROOTDIRSRAW ; do
  118 + ROOTDIRS="$ROOTDIRS$SEP$dir"
  119 + SEP="|"
  120 + done
  121 + OURCYGPATTERN="(^($ROOTDIRS))"
  122 + # Add a user-defined pattern to the cygpath arguments
  123 + if [ "$GRADLE_CYGPATTERN" != "" ] ; then
  124 + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
  125 + fi
  126 + # Now convert the arguments - kludge to limit ourselves to /bin/sh
  127 + i=0
  128 + for arg in "$@" ; do
  129 + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
  130 + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
  131 +
  132 + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
  133 + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
  134 + else
  135 + eval `echo args$i`="\"$arg\""
  136 + fi
  137 + i=$((i+1))
  138 + done
  139 + case $i in
  140 + (0) set -- ;;
  141 + (1) set -- "$args0" ;;
  142 + (2) set -- "$args0" "$args1" ;;
  143 + (3) set -- "$args0" "$args1" "$args2" ;;
  144 + (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
  145 + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
  146 + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
  147 + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
  148 + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
  149 + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
  150 + esac
  151 +fi
  152 +
  153 +# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
  154 +function splitJvmOpts() {
  155 + JVM_OPTS=("$@")
  156 +}
  157 +eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
  158 +JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
  159 +
  160 +exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
... ...
gradlew.bat 0 → 100644
  1 +++ a/gradlew.bat
  1 +@if "%DEBUG%" == "" @echo off
  2 +@rem ##########################################################################
  3 +@rem
  4 +@rem Gradle startup script for Windows
  5 +@rem
  6 +@rem ##########################################################################
  7 +
  8 +@rem Set local scope for the variables with windows NT shell
  9 +if "%OS%"=="Windows_NT" setlocal
  10 +
  11 +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
  12 +set DEFAULT_JVM_OPTS=
  13 +
  14 +set DIRNAME=%~dp0
  15 +if "%DIRNAME%" == "" set DIRNAME=.
  16 +set APP_BASE_NAME=%~n0
  17 +set APP_HOME=%DIRNAME%
  18 +
  19 +@rem Find java.exe
  20 +if defined JAVA_HOME goto findJavaFromJavaHome
  21 +
  22 +set JAVA_EXE=java.exe
  23 +%JAVA_EXE% -version >NUL 2>&1
  24 +if "%ERRORLEVEL%" == "0" goto init
  25 +
  26 +echo.
  27 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
  28 +echo.
  29 +echo Please set the JAVA_HOME variable in your environment to match the
  30 +echo location of your Java installation.
  31 +
  32 +goto fail
  33 +
  34 +:findJavaFromJavaHome
  35 +set JAVA_HOME=%JAVA_HOME:"=%
  36 +set JAVA_EXE=%JAVA_HOME%/bin/java.exe
  37 +
  38 +if exist "%JAVA_EXE%" goto init
  39 +
  40 +echo.
  41 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
  42 +echo.
  43 +echo Please set the JAVA_HOME variable in your environment to match the
  44 +echo location of your Java installation.
  45 +
  46 +goto fail
  47 +
  48 +:init
  49 +@rem Get command-line arguments, handling Windowz variants
  50 +
  51 +if not "%OS%" == "Windows_NT" goto win9xME_args
  52 +if "%@eval[2+2]" == "4" goto 4NT_args
  53 +
  54 +:win9xME_args
  55 +@rem Slurp the command line arguments.
  56 +set CMD_LINE_ARGS=
  57 +set _SKIP=2
  58 +
  59 +:win9xME_args_slurp
  60 +if "x%~1" == "x" goto execute
  61 +
  62 +set CMD_LINE_ARGS=%*
  63 +goto execute
  64 +
  65 +:4NT_args
  66 +@rem Get arguments from the 4NT Shell from JP Software
  67 +set CMD_LINE_ARGS=%$
  68 +
  69 +:execute
  70 +@rem Setup the command line
  71 +
  72 +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
  73 +
  74 +@rem Execute Gradle
  75 +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
  76 +
  77 +:end
  78 +@rem End local scope for the variables with windows NT shell
  79 +if "%ERRORLEVEL%"=="0" goto mainEnd
  80 +
  81 +:fail
  82 +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
  83 +rem the _cmd.exe /c_ return code!
  84 +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
  85 +exit /b 1
  86 +
  87 +:mainEnd
  88 +if "%OS%"=="Windows_NT" endlocal
  89 +
  90 +:omega
... ...
settings.gradle 0 → 100644
  1 +++ a/settings.gradle
  1 +include ':app'
... ...