v3.6.6
parent
15978cd2b6
commit
d40f8fa385
@ -0,0 +1,41 @@ |
||||
/* |
||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
package com.arialyy.aria.core.command.normal; |
||||
|
||||
import com.arialyy.aria.core.inf.AbsTask; |
||||
import com.arialyy.aria.core.inf.AbsTaskWrapper; |
||||
import com.arialyy.aria.core.inf.TaskSchedulerType; |
||||
|
||||
/** |
||||
* 重新开始任务命令 |
||||
*/ |
||||
public class ReStartCmd<T extends AbsTaskWrapper> extends AbsNormalCmd<T> { |
||||
|
||||
ReStartCmd(T entity, int taskType) { |
||||
super(entity, taskType); |
||||
} |
||||
|
||||
@Override public void executeCmd() { |
||||
AbsTask task = getTask(); |
||||
if (task == null) { |
||||
task = createTask(); |
||||
} |
||||
if (task != null) { |
||||
task.cancel(TaskSchedulerType.TYPE_CANCEL_AND_NOT_NOTIFY); |
||||
task.start(TaskSchedulerType.TYPE_START_AND_RESET_STATE); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,100 @@ |
||||
/* |
||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
package com.arialyy.aria.core.common.ftp; |
||||
|
||||
import android.text.TextUtils; |
||||
|
||||
/** |
||||
* Ftp上传拦截器处理 |
||||
* |
||||
* 如果使用者同时实现{@link Builder#resetFileName(String)}和{@link Builder#coverServerFile}, |
||||
* 将默认使用{@link Builder#coverServerFile} |
||||
*/ |
||||
public class FtpInterceptHandler { |
||||
|
||||
private boolean coverServerFile; |
||||
|
||||
private String newFileName; |
||||
|
||||
private boolean stopUpload; |
||||
|
||||
private FtpInterceptHandler() { |
||||
} |
||||
|
||||
public boolean isCoverServerFile() { |
||||
return coverServerFile; |
||||
} |
||||
|
||||
public String getNewFileName() { |
||||
return newFileName; |
||||
} |
||||
|
||||
public boolean isStopUpload() { |
||||
return stopUpload; |
||||
} |
||||
|
||||
public static final class Builder { |
||||
private boolean coverServerFile = false; |
||||
|
||||
private String newFileName; |
||||
|
||||
private boolean stopUpload = false; |
||||
|
||||
/** |
||||
* 如果ftp服务器端已经有同名文件,控制是否覆盖远端的同名文件; |
||||
* 如果你不希望覆盖远端文件,可以使用{@link #resetFileName(String)} |
||||
* |
||||
* @return {@code true} 如果ftp服务器端已经有同名文件,覆盖服务器端的同名文件 |
||||
*/ |
||||
public Builder coverServerFile() { |
||||
coverServerFile = true; |
||||
return this; |
||||
} |
||||
|
||||
/** |
||||
* 如果ftp服务器端已经有同名文件,修改该文件上传到远端的文件名,该操作不会修改本地文件名 |
||||
* 如果你希望覆盖远端的同名文件,可以使用{@link #coverServerFile()} |
||||
*/ |
||||
public Builder resetFileName(String newFileName) { |
||||
this.newFileName = newFileName; |
||||
return this; |
||||
} |
||||
|
||||
/** |
||||
* 如果你希望停止上传任务,可以调用该方法 |
||||
*/ |
||||
public Builder stopUpload() { |
||||
stopUpload = true; |
||||
return this; |
||||
} |
||||
|
||||
/** |
||||
* 如果使用者同时实现{@link Builder#resetFileName(String)}和{@link Builder#coverServerFile}, |
||||
* 将默认使用{@link Builder#coverServerFile} |
||||
*/ |
||||
public FtpInterceptHandler build() { |
||||
FtpInterceptHandler handler = new FtpInterceptHandler(); |
||||
if (stopUpload) { |
||||
handler.stopUpload = true; |
||||
} else if (coverServerFile) { |
||||
handler.coverServerFile = true; |
||||
} else if (!TextUtils.isEmpty(newFileName)) { |
||||
handler.newFileName = newFileName; |
||||
} |
||||
return handler; |
||||
} |
||||
} |
||||
} |
@ -1,62 +1,75 @@ |
||||
/* |
||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
package com.arialyy.aria.core.common.ftp; |
||||
|
||||
import com.arialyy.aria.core.FtpUrlEntity; |
||||
import com.arialyy.aria.core.inf.ITargetHeadDelegate; |
||||
import java.net.Proxy; |
||||
|
||||
/** |
||||
* fTP任务设置的信息,如:用户名、密码、端口等信息 |
||||
*/ |
||||
public class FtpTaskDelegate implements ITargetHeadDelegate { |
||||
|
||||
/** |
||||
* 账号和密码 |
||||
*/ |
||||
private FtpUrlEntity urlEntity; |
||||
|
||||
private Proxy proxy; |
||||
|
||||
/** |
||||
* 字符编码,默认为"utf-8" |
||||
*/ |
||||
private String charSet = "utf-8"; |
||||
|
||||
public FtpUrlEntity getUrlEntity() { |
||||
return urlEntity; |
||||
} |
||||
|
||||
public void setUrlEntity(FtpUrlEntity urlEntity) { |
||||
this.urlEntity = urlEntity; |
||||
} |
||||
|
||||
public void setProxy(Proxy proxy) { |
||||
this.proxy = proxy; |
||||
} |
||||
|
||||
public Proxy getProxy() { |
||||
return proxy; |
||||
} |
||||
|
||||
public String getCharSet() { |
||||
return charSet; |
||||
} |
||||
|
||||
public void setCharSet(String charSet) { |
||||
this.charSet = charSet; |
||||
} |
||||
} |
||||
/* |
||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
package com.arialyy.aria.core.common.ftp; |
||||
|
||||
import com.arialyy.aria.core.FtpUrlEntity; |
||||
import com.arialyy.aria.core.inf.ITargetHeadDelegate; |
||||
import java.net.Proxy; |
||||
|
||||
/** |
||||
* fTP任务设置的信息,如:用户名、密码、端口等信息 |
||||
*/ |
||||
public class FtpTaskDelegate implements ITargetHeadDelegate { |
||||
|
||||
/** |
||||
* 账号和密码 |
||||
*/ |
||||
private FtpUrlEntity urlEntity; |
||||
|
||||
private Proxy proxy; |
||||
|
||||
/** |
||||
* 字符编码,默认为"utf-8" |
||||
*/ |
||||
private String charSet = "utf-8"; |
||||
|
||||
/** |
||||
* 上传拦截器 |
||||
*/ |
||||
private IFtpUploadInterceptor uploadInterceptor; |
||||
|
||||
public IFtpUploadInterceptor getUploadInterceptor() { |
||||
return uploadInterceptor; |
||||
} |
||||
|
||||
public void setUploadInterceptor(IFtpUploadInterceptor uploadInterceptor) { |
||||
this.uploadInterceptor = uploadInterceptor; |
||||
} |
||||
|
||||
public FtpUrlEntity getUrlEntity() { |
||||
return urlEntity; |
||||
} |
||||
|
||||
public void setUrlEntity(FtpUrlEntity urlEntity) { |
||||
this.urlEntity = urlEntity; |
||||
} |
||||
|
||||
public void setProxy(Proxy proxy) { |
||||
this.proxy = proxy; |
||||
} |
||||
|
||||
public Proxy getProxy() { |
||||
return proxy; |
||||
} |
||||
|
||||
public String getCharSet() { |
||||
return charSet; |
||||
} |
||||
|
||||
public void setCharSet(String charSet) { |
||||
this.charSet = charSet; |
||||
} |
||||
} |
||||
|
@ -0,0 +1,54 @@ |
||||
/* |
||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
package com.arialyy.aria.core.common.ftp; |
||||
|
||||
import com.arialyy.aria.core.upload.UploadEntity; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* FTP文件上传拦截器,如果远端已有同名文件,可使用该拦截器控制覆盖文件或修改该文件上传到服务器端端文件名 |
||||
* simple |
||||
* <pre> |
||||
* <code> |
||||
* Aria.upload(this) |
||||
* .loadFtp(FILE_PATH) |
||||
* .setUploadUrl(URL) |
||||
* .setUploadInterceptor( |
||||
* new IFtpUploadInterceptor() { |
||||
* |
||||
* @Override |
||||
* public FtpInterceptHandler onIntercept(UploadEntity entity, List<String> fileList) { |
||||
* FtpInterceptHandler.Builder builder = new FtpInterceptHandler.Builder(); |
||||
* builder.coverServerFile(); |
||||
* //builder.resetFileName("test");
|
||||
* return builder.build(); |
||||
* } |
||||
* }) |
||||
* .start(); |
||||
* </code> |
||||
* |
||||
* </pre> |
||||
*/ |
||||
public interface IFtpUploadInterceptor { |
||||
|
||||
/** |
||||
* 处理拦截事件 |
||||
* |
||||
* @param entity 上传信息实体 |
||||
* @param fileList ftp服务器端remotePath下的文件列表 |
||||
*/ |
||||
FtpInterceptHandler onIntercept(UploadEntity entity, List<String> fileList); |
||||
} |
@ -0,0 +1,32 @@ |
||||
/* |
||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
package com.arialyy.aria.exception; |
||||
|
||||
/** |
||||
* Created by lyy on 2017/1/18. |
||||
* Aria 文件异常 |
||||
*/ |
||||
public class FileNotFoundException extends BaseException { |
||||
private static final String ARIA_FILE_EXCEPTION = "Aria File not found Exception:"; |
||||
|
||||
public FileNotFoundException(String tag, String detailMessage) { |
||||
super(tag, String.format("%s%s", ARIA_FILE_EXCEPTION, detailMessage)); |
||||
} |
||||
|
||||
public FileNotFoundException(String tag, String message, Exception e){ |
||||
super(tag, message, e); |
||||
} |
||||
} |
@ -1,75 +1,166 @@ |
||||
//package com.arialyy.simple.core.download |
||||
// |
||||
//import android.os.Bundle |
||||
//import android.os.Environment |
||||
//import android.support.v7.app.AppCompatActivity |
||||
//import android.util.Log |
||||
//import android.view.View |
||||
//import com.arialyy.annotations.Download |
||||
//import com.arialyy.aria.core.Aria |
||||
//import com.arialyy.aria.core.download.DownloadTask |
||||
//import com.arialyy.simple.R |
||||
//import com.arialyy.simple.base.BaseActivity |
||||
// |
||||
///** |
||||
// * Created by lyy on 2017/10/23. |
||||
// */ |
||||
//class KotlinDownloadActivity : AppCompatActivity() { |
||||
// |
||||
// private val DOWNLOAD_URL = "http://static.gaoshouyou.com/d/22/94/822260b849944492caadd2983f9bb624.apk" |
||||
// |
||||
// private val TAG = "KotlinDownloadActivity"; |
||||
// |
||||
// override fun onCreate(savedInstanceState: Bundle?) { |
||||
// super.onCreate(savedInstanceState) |
||||
// setContentView(setLayoutId()) |
||||
// } |
||||
// |
||||
// fun setLayoutId(): Int { |
||||
// return R.layout.activity_single |
||||
// } |
||||
// |
||||
// fun init(savedInstanceState: Bundle?) { |
||||
// title = "单任务下载" |
||||
//// val target = Aria.download(this).load(DOWNLOAD_URL) |
||||
//// binding.progress = target.getPercent() |
||||
//// if (target.getTaskState() == IEntity.STATE_STOP) { |
||||
//// mStart.setText("恢复") |
||||
//// mStart.setTextColor(resources.getColor(android.R.color.holo_blue_light)) |
||||
//// setBtState(true) |
||||
//// } else if (target.isDownloading()) { |
||||
//// setBtState(false) |
||||
//// } |
||||
//// binding.fileSize = target.getConvertFileSize() |
||||
// Aria.get(this).downloadConfig.maxTaskNum = 2 |
||||
// Aria.download(this).register() |
||||
// } |
||||
// |
||||
// @Download.onTaskRunning |
||||
// protected fun running(task: DownloadTask) { |
||||
// Log.d(TAG, task.percent.toString() + "") |
||||
//// val len = task.fileSize |
||||
//// if (len == 0L) { |
||||
//// binding.progress = 0 |
||||
//// } else { |
||||
//// binding.progress = task.percent |
||||
//// } |
||||
//// binding.speed = task.convertSpeed |
||||
// } |
||||
// |
||||
// fun onClick(view: View) { |
||||
// when (view.id) { |
||||
// R.id.start -> startD() |
||||
// R.id.stop -> Aria.download(this).load(DOWNLOAD_URL).stop() |
||||
// R.id.cancel -> Aria.download(this).load(DOWNLOAD_URL).cancel() |
||||
// } |
||||
// } |
||||
// |
||||
// private fun startD() { |
||||
// Aria.download(this) |
||||
// .load(DOWNLOAD_URL) |
||||
// .addHeader("groupHash", "value") |
||||
// .setDownloadPath(Environment.getExternalStorageDirectory().path + "/hhhhhhhh.apk") |
||||
// .start() |
||||
// } |
||||
//} |
||||
package com.arialyy.simple.core.download |
||||
|
||||
import android.os.Bundle |
||||
import android.os.Environment |
||||
import android.util.Log |
||||
import android.view.View |
||||
import android.widget.Button |
||||
import android.widget.Toast |
||||
import com.arialyy.annotations.Download |
||||
import com.arialyy.aria.core.Aria |
||||
import com.arialyy.aria.core.download.DownloadTarget |
||||
import com.arialyy.aria.core.download.DownloadTask |
||||
import com.arialyy.aria.core.inf.IEntity |
||||
import com.arialyy.frame.util.show.T |
||||
import com.arialyy.simple.R |
||||
import com.arialyy.simple.base.BaseActivity |
||||
import com.arialyy.simple.databinding.ActivitySingleBinding |
||||
|
||||
/** |
||||
* Created by lyy on 2017/10/23. |
||||
*/ |
||||
class KotlinDownloadActivity : BaseActivity<ActivitySingleBinding>() { |
||||
|
||||
private val DOWNLOAD_URL = |
||||
"http://static.gaoshouyou.com/d/22/94/822260b849944492caadd2983f9bb624.apk" |
||||
|
||||
private lateinit var mStart: Button |
||||
private lateinit var mStop: Button |
||||
private lateinit var mCancel: Button |
||||
private lateinit var target: DownloadTarget |
||||
|
||||
override fun setLayoutId(): Int { |
||||
return R.layout.activity_single |
||||
} |
||||
|
||||
override fun init(savedInstanceState: Bundle?) { |
||||
title = "kotlin测试" |
||||
Aria.get(this) |
||||
.downloadConfig.maxTaskNum = 2 |
||||
Aria.download(this) |
||||
.register() |
||||
mStart = findViewById(R.id.start) |
||||
mStop = findViewById(R.id.stop) |
||||
mCancel = findViewById(R.id.cancel) |
||||
mStop.visibility = View.GONE |
||||
|
||||
target = Aria.download(this) |
||||
.load(DOWNLOAD_URL) |
||||
binding.progress = target.percent |
||||
if (target.taskState == IEntity.STATE_STOP) { |
||||
mStart.text = "恢复" |
||||
} else if (target.isRunning) { |
||||
mStart.text = "停止" |
||||
} |
||||
binding.fileSize = target.convertFileSize |
||||
} |
||||
|
||||
/** |
||||
* 注解方法不能添加internal修饰符,否则会出现e: [kapt] An exception occurred: java.lang.IllegalArgumentException: index 1 for '$a' not in range (received 0 arguments)错误 |
||||
*/ |
||||
@Download.onTaskRunning |
||||
fun running(task: DownloadTask) { |
||||
Log.d(TAG, task.percent.toString()) |
||||
val len = task.fileSize |
||||
if (len == 0L) { |
||||
binding.progress = 0 |
||||
} else { |
||||
binding.progress = task.percent |
||||
} |
||||
binding.speed = task.convertSpeed |
||||
} |
||||
|
||||
@Download.onWait |
||||
fun onWait(task: DownloadTask) { |
||||
if (task.key == DOWNLOAD_URL) { |
||||
Log.d(TAG, "wait ==> " + task.downloadEntity.fileName) |
||||
} |
||||
} |
||||
|
||||
@Download.onPre |
||||
fun onPre(task: DownloadTask) { |
||||
if (task.key == DOWNLOAD_URL) { |
||||
mStart.text = "停止" |
||||
} |
||||
} |
||||
|
||||
@Download.onTaskStart |
||||
fun taskStart(task: DownloadTask) { |
||||
if (task.key == DOWNLOAD_URL) { |
||||
binding.fileSize = task.convertFileSize |
||||
} |
||||
} |
||||
|
||||
@Download.onTaskComplete |
||||
fun complete(task: DownloadTask) { |
||||
Log.d(TAG, "完成") |
||||
} |
||||
|
||||
@Download.onTaskResume |
||||
fun taskResume(task: DownloadTask) { |
||||
if (task.key == DOWNLOAD_URL) { |
||||
mStart.text = "停止" |
||||
} |
||||
} |
||||
|
||||
@Download.onTaskStop |
||||
fun taskStop(task: DownloadTask) { |
||||
if (task.key == DOWNLOAD_URL) { |
||||
mStart.text = "恢复" |
||||
binding.speed = "" |
||||
} |
||||
} |
||||
|
||||
@Download.onTaskCancel |
||||
fun taskCancel(task: DownloadTask) { |
||||
if (task.key == DOWNLOAD_URL) { |
||||
binding.progress = 0 |
||||
Toast.makeText(this@KotlinDownloadActivity, "取消下载", Toast.LENGTH_SHORT) |
||||
.show() |
||||
mStart.text = "开始" |
||||
binding.speed = "" |
||||
Log.d(TAG, "cancel") |
||||
} |
||||
} |
||||
|
||||
@Download.onTaskFail |
||||
fun taskFail(task: DownloadTask) { |
||||
if (task.key == DOWNLOAD_URL) { |
||||
Toast.makeText(this@KotlinDownloadActivity, "下载失败", Toast.LENGTH_SHORT) |
||||
.show() |
||||
mStart.text = "开始" |
||||
} |
||||
} |
||||
|
||||
@Download.onNoSupportBreakPoint |
||||
fun onNoSupportBreakPoint(task: DownloadTask) { |
||||
Log.d(TAG, "该下载链接不支持断点") |
||||
if (task.key == DOWNLOAD_URL) { |
||||
T.showShort(this@KotlinDownloadActivity, "该下载链接不支持断点") |
||||
} |
||||
} |
||||
|
||||
fun onClick(view: View) { |
||||
when (view.id) { |
||||
R.id.start -> { |
||||
if (target.isRunning) { |
||||
Aria.download(this) |
||||
.load(DOWNLOAD_URL) |
||||
.stop() |
||||
} else { |
||||
startD() |
||||
} |
||||
} |
||||
R.id.stop -> Aria.download(this).load(DOWNLOAD_URL).stop() |
||||
R.id.cancel -> Aria.download(this).load(DOWNLOAD_URL).cancel() |
||||
} |
||||
} |
||||
|
||||
private fun startD() { |
||||
Aria.download(this) |
||||
.load(DOWNLOAD_URL) |
||||
.addHeader("groupHash", "value") |
||||
.setFilePath(Environment.getExternalStorageDirectory().path + "/kotlin.apk") |
||||
.start() |
||||
} |
||||
} |
@ -1,113 +1,126 @@ |
||||
/* |
||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
package com.arialyy.simple.core.upload; |
||||
|
||||
import android.os.Bundle; |
||||
import android.util.Log; |
||||
import android.view.View; |
||||
import com.arialyy.annotations.Upload; |
||||
import com.arialyy.aria.core.Aria; |
||||
import com.arialyy.aria.core.upload.UploadEntity; |
||||
import com.arialyy.aria.core.upload.UploadTask; |
||||
import com.arialyy.aria.util.CommonUtil; |
||||
import com.arialyy.frame.util.FileUtil; |
||||
import com.arialyy.frame.util.show.T; |
||||
import com.arialyy.simple.R; |
||||
import com.arialyy.simple.base.BaseActivity; |
||||
import com.arialyy.simple.databinding.ActivityFtpUploadBinding; |
||||
import java.io.File; |
||||
|
||||
/** |
||||
* Created by lyy on 2017/7/28. Ftp 文件上传demo |
||||
*/ |
||||
public class FtpUploadActivity extends BaseActivity<ActivityFtpUploadBinding> { |
||||
private final String FILE_PATH = "/mnt/sdcard/AriaPrj.rar"; |
||||
private final String URL = "ftp://9.9.9.205:2121/aa/你好"; |
||||
|
||||
@Override protected void init(Bundle savedInstanceState) { |
||||
setTile("D_FTP 文件上传"); |
||||
super.init(savedInstanceState); |
||||
Aria.upload(this).register(); |
||||
UploadEntity entity = Aria.upload(this).getUploadEntity(FILE_PATH); |
||||
if (entity != null) { |
||||
getBinding().setFileSize(CommonUtil.formatFileSize(entity.getFileSize())); |
||||
getBinding().setProgress(entity.isComplete() ? 100 |
||||
: (int) (entity.getCurrentProgress() * 100 / entity.getFileSize())); |
||||
} |
||||
} |
||||
|
||||
@Override protected int setLayoutId() { |
||||
return R.layout.activity_ftp_upload; |
||||
} |
||||
|
||||
public void onClick(View view) { |
||||
switch (view.getId()) { |
||||
case R.id.start: |
||||
Aria.upload(this).loadFtp(FILE_PATH).setUploadUrl(URL).login("lao", "123456").start(); |
||||
break; |
||||
case R.id.stop: |
||||
Aria.upload(this).loadFtp(FILE_PATH).stop(); |
||||
break; |
||||
case R.id.cancel: |
||||
Aria.upload(this).loadFtp(FILE_PATH).cancel(); |
||||
break; |
||||
} |
||||
} |
||||
|
||||
@Upload.onWait void onWait(UploadTask task) { |
||||
Log.d(TAG, task.getTaskName() + "_wait"); |
||||
} |
||||
|
||||
@Upload.onPre public void onPre(UploadTask task) { |
||||
getBinding().setFileSize(task.getConvertFileSize()); |
||||
} |
||||
|
||||
@Upload.onTaskStart public void taskStart(UploadTask task) { |
||||
Log.d(TAG, "开始上传,md5:" + FileUtil.getFileMD5(new File(task.getEntity().getFilePath()))); |
||||
} |
||||
|
||||
@Upload.onTaskResume public void taskResume(UploadTask task) { |
||||
Log.d(TAG, "恢复上传"); |
||||
} |
||||
|
||||
@Upload.onTaskStop public void taskStop(UploadTask task) { |
||||
getBinding().setSpeed(""); |
||||
Log.d(TAG, "停止上传"); |
||||
} |
||||
|
||||
@Upload.onTaskCancel public void taskCancel(UploadTask task) { |
||||
getBinding().setSpeed(""); |
||||
getBinding().setFileSize(""); |
||||
getBinding().setProgress(0); |
||||
Log.d(TAG, "删除任务"); |
||||
} |
||||
|
||||
@Upload.onTaskFail public void taskFail(UploadTask task) { |
||||
Log.d(TAG, "上传失败"); |
||||
} |
||||
|
||||
@Upload.onTaskRunning public void taskRunning(UploadTask task) { |
||||
Log.d(TAG, "PP = " + task.getPercent()); |
||||
getBinding().setProgress(task.getPercent()); |
||||
getBinding().setSpeed(task.getConvertSpeed()); |
||||
} |
||||
|
||||
@Upload.onTaskComplete public void taskComplete(UploadTask task) { |
||||
getBinding().setProgress(100); |
||||
getBinding().setSpeed(""); |
||||
T.showShort(this, "文件:" + task.getEntity().getFileName() + ",上传完成"); |
||||
} |
||||
} |
||||
/* |
||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
package com.arialyy.simple.core.upload; |
||||
|
||||
import android.os.Bundle; |
||||
import android.util.Log; |
||||
import android.view.View; |
||||
import com.arialyy.annotations.Upload; |
||||
import com.arialyy.aria.core.Aria; |
||||
import com.arialyy.aria.core.common.ftp.FtpInterceptHandler; |
||||
import com.arialyy.aria.core.common.ftp.IFtpUploadInterceptor; |
||||
import com.arialyy.aria.core.upload.UploadEntity; |
||||
import com.arialyy.aria.core.upload.UploadTask; |
||||
import com.arialyy.aria.util.CommonUtil; |
||||
import com.arialyy.frame.util.FileUtil; |
||||
import com.arialyy.frame.util.show.T; |
||||
import com.arialyy.simple.R; |
||||
import com.arialyy.simple.base.BaseActivity; |
||||
import com.arialyy.simple.databinding.ActivityFtpUploadBinding; |
||||
import java.io.File; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* Created by lyy on 2017/7/28. Ftp 文件上传demo |
||||
*/ |
||||
public class FtpUploadActivity extends BaseActivity<ActivityFtpUploadBinding> { |
||||
private final String FILE_PATH = "/mnt/sdcard/AriaPrj.rar"; |
||||
private final String URL = "ftp://9.9.9.205:2121/aa/你好"; |
||||
|
||||
@Override protected void init(Bundle savedInstanceState) { |
||||
setTile("D_FTP 文件上传"); |
||||
super.init(savedInstanceState); |
||||
Aria.upload(this).register(); |
||||
UploadEntity entity = Aria.upload(this).getUploadEntity(FILE_PATH); |
||||
if (entity != null) { |
||||
getBinding().setFileSize(CommonUtil.formatFileSize(entity.getFileSize())); |
||||
getBinding().setProgress(entity.isComplete() ? 100 |
||||
: (int) (entity.getCurrentProgress() * 100 / entity.getFileSize())); |
||||
} |
||||
} |
||||
|
||||
@Override protected int setLayoutId() { |
||||
return R.layout.activity_ftp_upload; |
||||
} |
||||
|
||||
public void onClick(View view) { |
||||
switch (view.getId()) { |
||||
case R.id.start: |
||||
Aria.upload(this).loadFtp(FILE_PATH).setUploadUrl(URL).setUploadInterceptor( |
||||
new IFtpUploadInterceptor() { |
||||
|
||||
@Override |
||||
public FtpInterceptHandler onIntercept(UploadEntity entity, List<String> fileList) { |
||||
FtpInterceptHandler.Builder builder = new FtpInterceptHandler.Builder(); |
||||
builder.coverServerFile(); |
||||
//builder.resetFileName("test");
|
||||
return builder.build(); |
||||
} |
||||
}).login("lao", "123456").start(); |
||||
break; |
||||
case R.id.stop: |
||||
Aria.upload(this).loadFtp(FILE_PATH).stop(); |
||||
break; |
||||
case R.id.cancel: |
||||
Aria.upload(this).loadFtp(FILE_PATH).cancel(); |
||||
break; |
||||
} |
||||
} |
||||
|
||||
@Upload.onWait void onWait(UploadTask task) { |
||||
Log.d(TAG, task.getTaskName() + "_wait"); |
||||
} |
||||
|
||||
@Upload.onPre public void onPre(UploadTask task) { |
||||
getBinding().setFileSize(task.getConvertFileSize()); |
||||
} |
||||
|
||||
@Upload.onTaskStart public void taskStart(UploadTask task) { |
||||
Log.d(TAG, "开始上传,md5:" + FileUtil.getFileMD5(new File(task.getEntity().getFilePath()))); |
||||
} |
||||
|
||||
@Upload.onTaskResume public void taskResume(UploadTask task) { |
||||
Log.d(TAG, "恢复上传"); |
||||
} |
||||
|
||||
@Upload.onTaskStop public void taskStop(UploadTask task) { |
||||
getBinding().setSpeed(""); |
||||
Log.d(TAG, "停止上传"); |
||||
} |
||||
|
||||
@Upload.onTaskCancel public void taskCancel(UploadTask task) { |
||||
getBinding().setSpeed(""); |
||||
getBinding().setFileSize(""); |
||||
getBinding().setProgress(0); |
||||
Log.d(TAG, "删除任务"); |
||||
} |
||||
|
||||
@Upload.onTaskFail public void taskFail(UploadTask task) { |
||||
Log.d(TAG, "上传失败"); |
||||
} |
||||
|
||||
@Upload.onTaskRunning public void taskRunning(UploadTask task) { |
||||
Log.d(TAG, "PP = " + task.getPercent()); |
||||
getBinding().setProgress(task.getPercent()); |
||||
getBinding().setSpeed(task.getConvertSpeed()); |
||||
} |
||||
|
||||
@Upload.onTaskComplete public void taskComplete(UploadTask task) { |
||||
getBinding().setProgress(100); |
||||
getBinding().setSpeed(""); |
||||
T.showShort(this, "文件:" + task.getEntity().getFileName() + ",上传完成"); |
||||
} |
||||
} |
||||
|
@ -0,0 +1,4 @@ |
||||
<vector android:height="24dp" android:viewportHeight="1024" |
||||
android:viewportWidth="1024" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android"> |
||||
<path android:fillColor="@color/icon_color" android:pathData="M863.1,914.43a116.03,116.03 0,0 1,-166.4 8.32L419.9,665.6q-2.18,-1.79 -4.29,-3.9L633.6,537.98l221.31,205.63a123.01,123.01 0,0 1,8.19 170.82zM381.82,280.83v-23.49A128,128 0,0 0,255.62 128a128,128 0,0 0,-126.21 129.34L129.41,424.32zM128,822.02v7.23A129.22,129.22 0,0 0,255.62 960a129.22,129.22 0,0 0,127.62 -130.75L383.23,677.25zM881.22,196.35a116.54,116.54 0,0 0,-160.38 -47.17l-587.52,333.44v276.48l701.82,-398.34a122.5,122.5 0,0 0,46.08 -164.42z"/> |
||||
</vector> |
Loading…
Reference in new issue