优化demo代码,demo添加代码使用示例

This commit is contained in:
laoyuyu
2019-05-28 19:09:46 +08:00
parent ce43e48097
commit 7b15d4c052
107 changed files with 4337 additions and 842 deletions

View File

@@ -44,8 +44,9 @@ android {
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
testImplementation 'junit:junit:4.12'
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
implementation "com.android.support:cardview-v7:${rootProject.ext.supportLibVersion}"
implementation "com.android.support:design:${rootProject.ext.supportLibVersion}"
implementation "org.jetbrains.kotlin:kotlin-stdlib:${rootProject.ext.kotlin_version}"
api project(':Aria')
kapt project(':AriaCompiler')
@@ -58,7 +59,7 @@ dependencies {
implementation project(':AppFrame')
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.5.4'
implementation 'com.github.bumptech.glide:glide:3.7.0'
implementation 'com.pddstudio:highlightjs-android:1.5.0'
}
repositories {
mavenCentral()

View File

@@ -42,6 +42,11 @@
<activity android:name=".core.upload.HttpUploadActivity"/>
<activity android:name=".core.upload.FtpUploadActivity"/>
<activity android:name=".core.download.KotlinDownloadActivity"/>
<activity
android:name=".core.FullScreenCodeActivity"
android:theme="@style/FullScreen"
android:screenOrientation="landscape"
android:windowSoftInputMode="stateHidden|adjustResize"/>
<service android:name=".core.download.service_download.DownloadService"/>

View File

@@ -0,0 +1,90 @@
import android.os.Bundle;
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.aria.util.CommonUtil;
import com.arialyy.simple.R;
import com.arialyy.simple.base.BaseActivity;
import com.arialyy.simple.databinding.ActivityTestBinding;
import java.io.File;
/**
* Created by lyy on 2019/5/28.
* Ftp 下载
* <a href="https://aria.laoyuyu.me/aria_doc/">文档</>
*/
public class FtpDownload extends BaseActivity<ActivityTestBinding> {
String TAG = "TestFTPActivity";
private final String URL = "ftp://192.168.1.3:21/download//AriaPrj.rar";
private final String FILE_PATH = "/mnt/sdcard/AriaPrj.rar";
@Override protected int setLayoutId() {
return R.layout.activity_test;
}
@Override protected void init(Bundle savedInstanceState) {
super.init(savedInstanceState);
mBar.setVisibility(View.GONE);
Aria.download(this).register();
}
@Download.onWait void onWait(DownloadTask task) {
Log.d(TAG, "wait ==> " + task.getEntity().getFileName());
}
@Download.onPre protected void onPre(DownloadTask task) {
Log.d(TAG, "onPre");
}
@Download.onTaskStart void taskStart(DownloadTask task) {
Log.d(TAG, "onStart");
}
@Download.onTaskRunning protected void running(DownloadTask task) {
Log.d(TAG, "runningspeed=" + task.getConvertSpeed());
}
@Download.onTaskResume void taskResume(DownloadTask task) {
Log.d(TAG, "resume");
}
@Download.onTaskStop void taskStop(DownloadTask task) {
Log.d(TAG, "stop");
}
@Download.onTaskCancel void taskCancel(DownloadTask task) {
Log.d(TAG, "cancel");
}
@Download.onTaskFail void taskFail(DownloadTask task) {
Log.d(TAG, "fail");
}
@Download.onTaskComplete void taskComplete(DownloadTask task) {
Log.d(TAG, "complete, md5 => " + CommonUtil.getFileMD5(new File(task.getKey())));
}
public void onClick(View view) {
switch (view.getId()) {
case R.id.start:
Aria.download(this)
.loadFtp(URL)
.setFilePath(FILE_PATH)
.login("lao", "123456")
//.asFtps() // ftps 配置
//.setStorePath("/mnt/sdcard/Download/server.crt") //设置证书路径
// .setAlias("www.laoyuyu.me") // 设置证书别名
.start();
break;
case R.id.stop:
Aria.download(this).loadFtp(FILE_PATH).stop();
break;
case R.id.cancel:
Aria.download(this).loadFtp(FILE_PATH).cancel();
break;
}
}
}

View File

@@ -0,0 +1,127 @@
/*
* 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.
*/
import android.app.Activity;
import android.os.Bundle;
import android.os.Environment;
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.frame.util.FileUtil;
import com.arialyy.frame.util.show.T;
import com.arialyy.simple.R;
import java.io.File;
import java.util.List;
/**
* Created by lyy on 2019/5/28. Ftp 文件上传demo
* <a href="https://aria.laoyuyu.me/aria_doc/">文档</>
*/
public class FtpUpload extends Activity {
private static final String TAG = "FtpUpload";
private String mFilePath = Environment.getExternalStorageDirectory().getPath() + "/AriaPrj.rar";
private String mUrl = "ftp://172.168.1.2:2121/aa/你好";
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Aria.upload(this).register();
// 读取历史记录信息
UploadEntity entity = Aria.upload(this).getUploadEntity(mFilePath);
if (entity != null) {
// 设置界面的进度、文件大小等信息
}
}
public void onClick(View view) {
switch (view.getId()) {
case R.id.start:
if (Aria.upload(this).load(mFilePath).isRunning()) {
Aria.upload(this).loadFtp(mFilePath).stop(); // 停止任务
} else {
Aria.upload(this)
.loadFtp(mFilePath) // 需要上传的文件
.setUploadUrl(mUrl) // 服务器地址
// 如果ftp服务器端有同名文件可通过拦截器处理是覆盖服务器端文件还是修改文件名
.setUploadInterceptor(
new IFtpUploadInterceptor() {
@Override
public FtpInterceptHandler onIntercept(UploadEntity entity,
List<String> fileList) {
FtpInterceptHandler.Builder builder = new FtpInterceptHandler.Builder();
//builder.coverServerFile();
builder.resetFileName("test.zip");
return builder.build();
}
})
.login("N0rI", "0qcK")
.start();
}
break;
case R.id.cancel:
Aria.upload(this).loadFtp(mFilePath).cancel();
break;
}
}
@Upload.onWait void onWait(UploadTask task) {
Log.d(TAG, task.getTaskName() + "_wait");
}
@Upload.onPre public void onPre(UploadTask task) {
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) {
setSpeed("");
Log.d(TAG, "停止上传");
}
@Upload.onTaskCancel public void taskCancel(UploadTask task) {
setSpeed("");
setFileSize("");
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());
setProgress(task.getPercent());
setSpeed(task.getConvertSpeed());
}
@Upload.onTaskComplete public void taskComplete(UploadTask task) {
setProgress(100);
setSpeed("");
T.showShort(this, "文件:" + task.getEntity().getFileName() + ",上传完成");
}
}

View File

@@ -0,0 +1,119 @@
/*
* 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.app.Activity;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.View;
import com.arialyy.annotations.Download;
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.download.DownloadEntity;
import com.arialyy.aria.core.upload.UploadEntity;
import com.arialyy.aria.core.upload.UploadTask;
import com.arialyy.frame.util.FileUtil;
import com.arialyy.frame.util.show.T;
import com.arialyy.simple.R;
import java.io.File;
import java.util.List;
/**
* Created by lyy on 2017/7/28. HTTP 文件下载demo
* <a href="https://aria.laoyuyu.me/aria_doc/">文档</>
*/
public class FtpUpload extends Activity {
private static final String TAG = "FtpUpload";
private String mFilePath = Environment.getExternalStorageDirectory().getPath() + "/test.apk";
private String mUrl = "http://hzdown.muzhiwan.com/2017/05/08/nl.noio.kingdom_59104935e56f0.apk";
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Aria.download(this).register();
// 读取历史记录信息
DownloadEntity entity = Aria.download(this).getDownloadEntity(mFilePath);
if (entity != null) {
// 设置界面的进度、文件大小等信息
}
}
public void onClick(View view) {
switch (view.getId()) {
case R.id.start:
if (Aria.download(this).load(mUrl).isRunning()) {
Aria.download(this).load(mUrl).stop(); // 停止任务
} else {
Aria.download(this)
.load(mUrl) // 下载url
.setFilePath(mFilePath) // 文件保存路径
//.addHeader(key, value) // 添加头
//.asPost() //或 asGet()
//.setParam() // 设置参数
.start();
}
break;
case R.id.cancel:
Aria.download(this).load(mUrl).cancel();
break;
}
}
@Download.onWait void onWait(DownloadTask task) {
Log.d(TAG, task.getTaskName() + "_wait");
}
@Download.onPre public void onPre(DownloadTask task) {
setFileSize(task.getConvertFileSize());
}
@Download.onTaskStart public void taskStart(DownloadTask task) {
Log.d(TAG, "开始下载md5" + FileUtil.getFileMD5(new File(task.getEntity().getFilePath())));
}
@Download.onTaskResume public void taskResume(DownloadTask task) {
Log.d(TAG, "恢复下载");
}
@Download.onTaskStop public void taskStop(DownloadTask task) {
setSpeed("");
Log.d(TAG, "停止下载");
}
@Download.onTaskCancel public void taskCancel(DownloadTask task) {
setSpeed("");
setFileSize("");
setProgress(0);
Log.d(TAG, "删除任务");
}
@Download.onTaskFail public void taskFail(DownloadTask task) {
Log.d(TAG, "下载失败");
}
@Download.onTaskRunning public void taskRunning(DownloadTask task) {
Log.d(TAG, "PP = " + task.getPercent());
setProgress(task.getPercent());
setSpeed(task.getConvertSpeed());
}
@Download.onTaskComplete public void taskComplete(DownloadTask task) {
setProgress(100);
setSpeed("");
T.showShort(this, "文件:" + task.getEntity().getFileName() + ",下载完成");
}
}

View File

@@ -0,0 +1,170 @@
/*
* 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.
*/
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.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 = "开始"
}
}
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()
}
}

View File

@@ -43,9 +43,11 @@ public abstract class BaseActivity<VB extends ViewDataBinding> extends AbsActivi
@Override protected void init(Bundle savedInstanceState) {
super.init(savedInstanceState);
mBar = findViewById(R.id.toolbar);
setSupportActionBar(mBar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
mBar.setOnMenuItemClickListener(this);
if (mBar != null) {
setSupportActionBar(mBar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
mBar.setOnMenuItemClickListener(this);
}
}
protected void setTile(String title) {

View File

@@ -23,7 +23,6 @@ import android.os.StrictMode;
import com.arialyy.aria.core.Aria;
import com.arialyy.frame.core.AbsFrame;
import com.arialyy.simple.BuildConfig;
import com.arialyy.simple.common.ConnectionChangeReceiver;
//import com.squareup.leakcanary.LeakCanary;
/**
@@ -46,15 +45,15 @@ public class BaseApplication extends Application {
StrictMode.setThreadPolicy(
new StrictMode.ThreadPolicy.Builder().detectAll().penaltyLog().build());
//if (LeakCanary.isInAnalyzerProcess(this)) {//1
// This process is dedicated to LeakCanary for heap analysis.
// You should not init your app in this process.
//return;
// This process is dedicated to LeakCanary for heap analysis.
// You should not init your app in this process.
//return;
//}
//LeakCanary.install(this);
}
}
//registerReceiver(new ConnectionChangeReceiver(), new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
}
//registerReceiver(new ConnectionChangeReceiver(), new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
}
public static BaseApplication getApp() {
return INSTANCE;

View File

@@ -0,0 +1,58 @@
/*
* 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.common;
import android.arch.lifecycle.LiveData;
import android.arch.lifecycle.MutableLiveData;
import android.text.TextUtils;
import com.arialyy.aria.util.ALog;
import com.arialyy.frame.base.BaseViewModule;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
public class DialogModule extends BaseViewModule {
private MutableLiveData<List<File>> mDirs = new MutableLiveData<>();
/**
* 获取指定目录下的文件夹
*
* @param path 指定路径
*/
LiveData<List<File>> getDirs(String path) {
if (TextUtils.isEmpty(path)) {
ALog.e(TAG, "路径为空");
return mDirs;
}
if (!path.startsWith("/")) {
ALog.e(TAG, "路径错误");
return mDirs;
}
File file = new File(path);
File[] files = file.listFiles();
List<File> data = new ArrayList<>();
for (File f : files) {
if (f.isDirectory()) {
data.add(f);
}
}
mDirs.postValue(data);
return mDirs;
}
}

View File

@@ -0,0 +1,177 @@
/*
* 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.common;
import android.annotation.SuppressLint;
import android.app.Dialog;
import android.arch.lifecycle.Observer;
import android.arch.lifecycle.ViewModelProviders;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.os.Environment;
import android.support.annotation.Nullable;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.DisplayMetrics;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.TextView;
import com.arialyy.aria.util.ALog;
import com.arialyy.simple.R;
import com.arialyy.simple.base.BaseDialog;
import com.arialyy.simple.base.adapter.AbsHolder;
import com.arialyy.simple.base.adapter.AbsRVAdapter;
import com.arialyy.simple.base.adapter.RvItemClickSupport;
import com.arialyy.simple.databinding.DialogChooseDirBinding;
import com.arialyy.simple.databinding.DialogMsgBinding;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
/**
* Created by AriaL on 2019/5/28.
*/
@SuppressLint("ValidFragment") public class DirChooseDialog
extends BaseDialog<DialogChooseDirBinding> {
public static final int DIR_CHOOSE_DIALOG_RESULT = 0xB2;
private String mCurrentPath = Environment.getExternalStorageDirectory().getPath();
private List<File> mData = new ArrayList<>();
private DialogModule mModule;
public DirChooseDialog(Object obj) {
super(obj);
}
@Override protected void init(Bundle savedInstanceState) {
super.init(savedInstanceState);
getBinding().list.setLayoutManager(new LinearLayoutManager(getContext()));
getBinding().list.addItemDecoration(
new DividerItemDecoration(getContext(), DividerItemDecoration.VERTICAL));
final Adapter adapter = new Adapter(getContext(), mData);
getBinding().list.setAdapter(adapter);
getBinding().setCurrentPath(mCurrentPath);
mModule = ViewModelProviders.of(this).get(DialogModule.class);
mModule.getDirs(mCurrentPath).observe(this, new Observer<List<File>>() {
@Override public void onChanged(@Nullable List<File> files) {
mData.clear();
if (files != null && !files.isEmpty()) {
mData.addAll(files);
}
adapter.notifyDataSetChanged();
if (mCurrentPath.equals(Environment.getExternalStorageDirectory().getPath())) {
getBinding().up.setVisibility(View.GONE);
}
getBinding().setCurrentPath(mCurrentPath);
getBinding().currentPath.setSelected(true);
}
});
getBinding().up.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View v) {
up();
}
});
getBinding().enter.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View v) {
getSimplerModule().onDialog(DIR_CHOOSE_DIALOG_RESULT, mCurrentPath);
dismiss();
}
});
RvItemClickSupport.addTo(getBinding().list).setOnItemClickListener(
new RvItemClickSupport.OnItemClickListener() {
@Override public void onItemClicked(RecyclerView recyclerView, int position, View v) {
getBinding().up.setVisibility(View.VISIBLE);
mCurrentPath = mCurrentPath.concat("/").concat(mData.get(position).getName());
mModule.getDirs(mCurrentPath);
}
});
}
private void up() {
int endIndex = mCurrentPath.lastIndexOf("/");
mCurrentPath = mCurrentPath.substring(0, endIndex);
mModule.getDirs(mCurrentPath);
}
@Override public void onStart() {
super.onStart();
Dialog dialog = getDialog();
if (dialog != null) {
DisplayMetrics dm = new DisplayMetrics();
getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
dialog.getWindow()
.setLayout((dm.widthPixels), ViewGroup.LayoutParams.WRAP_CONTENT);
// 拦截返回键
dialog.setOnKeyListener(new DialogInterface.OnKeyListener() {
@Override public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) {
if (mCurrentPath.equals(Environment.getExternalStorageDirectory().getPath())) {
dismiss();
} else {
up();
}
return true;
}
return false;
}
});
}
}
@Override protected int setLayoutId() {
return R.layout.dialog_choose_dir;
}
/**
* 适配器
*/
private class Adapter extends AbsRVAdapter<File, Adapter.Holder> {
Adapter(Context context, List<File> data) {
super(context, data);
}
@Override protected Holder getViewHolder(View convertView, int viewType) {
return new Holder(convertView);
}
@Override protected int setLayoutId(int type) {
return R.layout.item_choose_dir;
}
@Override protected void bindData(Holder holder, int position, File item) {
holder.text.setSelected(true);
holder.text.setText(item.getName());
}
private class Holder extends AbsHolder {
private TextView text;
Holder(View itemView) {
super(itemView);
text = findViewById(R.id.text);
}
}
}
}

View File

@@ -0,0 +1,93 @@
/*
* 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.common;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Toast;
import com.arialyy.simple.R;
import com.arialyy.simple.base.BaseDialog;
import com.arialyy.simple.databinding.DialogModifyPathBinding;
import com.arialyy.simple.databinding.DialogMsgBinding;
import java.io.File;
/**
* Created by AriaL on 2019/5/28.
* 修改文件路径
*/
@SuppressLint("ValidFragment") public class ModifyPathDialog
extends BaseDialog<DialogModifyPathBinding> {
public static final int MODIFY_PATH_RESULT = 0xB3;
private String mTitle, mFilePath, mDir;
public ModifyPathDialog(Object obj, String title, String filePath) {
super(obj);
mTitle = title;
mFilePath = filePath;
}
@Override protected void init(Bundle savedInstanceState) {
super.init(savedInstanceState);
getBinding().setTitle(mTitle);
getBinding().setViewModel(this);
final File temp = new File(mFilePath);
mDir = temp.getParent();
getBinding().setDir(mDir);
getBinding().setName(temp.getName());
getBinding().edit.post(new Runnable() {
@Override public void run() {
getBinding().edit.setSelection(temp.getName().length());
}
});
getBinding().enter.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View v) {
if (TextUtils.isEmpty(getBinding().getName())) {
Toast.makeText(getContext(), getString(R.string.error_file_name_null), Toast.LENGTH_SHORT)
.show();
return;
}
mFilePath = mDir + "/" + getBinding().getName();
getSimplerModule().onDialog(MODIFY_PATH_RESULT, mFilePath);
dismiss();
}
});
getBinding().cancel.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View v) {
dismiss();
}
});
}
public void chooseDir() {
DirChooseDialog dirChooseDialog = new DirChooseDialog(this);
dirChooseDialog.show(getChildFragmentManager(), "DirChooseDialog");
}
@Override protected int setLayoutId() {
return R.layout.dialog_modify_path;
}
@Override protected void dataCallback(int result, Object data) {
super.dataCallback(result, data);
if (result == DirChooseDialog.DIR_CHOOSE_DIALOG_RESULT) {
mDir = String.valueOf(data);
getBinding().setDir(mDir);
}
}
}

View File

@@ -23,7 +23,7 @@ import com.arialyy.simple.base.BaseDialog;
import com.arialyy.simple.databinding.DialogModifyUrlBinding;
/**
* Created by AriaL on 2017/6/3.
* Created by AriaL on 2019/5/27.
*/
@SuppressLint("ValidFragment") public class ModifyUrlDialog
extends BaseDialog<DialogModifyUrlBinding> {
@@ -48,7 +48,9 @@ import com.arialyy.simple.databinding.DialogModifyUrlBinding;
});
getBinding().enter.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View v) {
mText = getBinding().getText();
getSimplerModule().onDialog(MODIFY_URL_DIALOG_RESULT, mText);
dismiss();
}
});
getBinding().edit.post(new Runnable() {

View File

@@ -0,0 +1,68 @@
/*
* 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;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.Window;
import android.view.WindowManager;
import com.arialyy.aria.util.ALog;
import com.arialyy.simple.R;
import com.arialyy.simple.base.BaseActivity;
import com.arialyy.simple.databinding.ActivityFullScreenCodeBinding;
import com.pddstudio.highlightjs.models.Language;
import com.pddstudio.highlightjs.models.Theme;
import java.io.File;
/**
* 全是显示代码的actiivty
*/
public class FullScreenCodeActivity extends BaseActivity<ActivityFullScreenCodeBinding> {
private static final String TAG = "FullScreenCodeActivity";
public static final String KEY_FILE_PATH = "KEY_FILE_PATH";
@Override protected int setLayoutId() {
return R.layout.activity_full_screen_code;
}
@Override protected void onCreate(Bundle savedInstanceState) {
//去除标题栏
requestWindowFeature(Window.FEATURE_NO_TITLE);
//去除状态栏
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
super.onCreate(savedInstanceState);
}
@Override protected void init(Bundle savedInstanceState) {
super.init(savedInstanceState);
String filePath = getIntent().getStringExtra(KEY_FILE_PATH);
if (TextUtils.isEmpty(filePath)) {
ALog.e(TAG, "代码的文件路径为空");
finish();
return;
}
getBinding().codeView.setZoomSupportEnabled(true);
getBinding().codeView.setHighlightLanguage(Language.JAVA);
getBinding().codeView.setTheme(Theme.ANDROID_STUDIO);
getBinding().codeView.setSource(new File(filePath));
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
}

View File

@@ -0,0 +1,95 @@
/*
* 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.download;
import android.arch.lifecycle.LiveData;
import android.arch.lifecycle.MutableLiveData;
import android.content.Context;
import android.os.Environment;
import android.text.TextUtils;
import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.util.ALog;
import com.arialyy.frame.base.BaseViewModule;
import com.arialyy.simple.util.AppUtil;
import java.io.File;
public class DownloadModule1 extends BaseViewModule {
private final String DOWNLOAD_URL_KEY = "DOWNLOAD_URL_KEY";
private final String DOWNLOAD_PATH_KEY = "DOWNLOAD_PATH_KEY";
private final String defUrl =
"http://hzdown.muzhiwan.com/2017/05/08/nl.noio.kingdom_59104935e56f0.apk";
private final String defFilePath =
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getPath();
private MutableLiveData<DownloadEntity> liveData = new MutableLiveData<>();
private DownloadEntity singDownloadInfo;
/**
* 单任务下载的信息
*/
LiveData<DownloadEntity> getSingDownloadInfo(Context context) {
String url = AppUtil.getConfigValue(context, DOWNLOAD_URL_KEY, defUrl);
String filePath = AppUtil.getConfigValue(context, DOWNLOAD_PATH_KEY, defFilePath);
singDownloadInfo = Aria.download(context).getDownloadEntity(url);
if (singDownloadInfo == null) {
singDownloadInfo = new DownloadEntity();
singDownloadInfo.setUrl(url);
File temp = new File(defFilePath);
singDownloadInfo.setDownloadPath(filePath);
singDownloadInfo.setFileName(temp.getName());
} else {
AppUtil.setConfigValue(context, DOWNLOAD_PATH_KEY, singDownloadInfo.getDownloadPath());
AppUtil.setConfigValue(context, DOWNLOAD_URL_KEY, singDownloadInfo.getUrl());
}
liveData.postValue(singDownloadInfo);
return liveData;
}
/**
* 更新文件保存路径
*
* @param filePath 文件保存路径
*/
void updateFilePath(Context context, String filePath) {
if (TextUtils.isEmpty(filePath)) {
ALog.e(TAG, "文件保存路径为空");
return;
}
File temp = new File(filePath);
AppUtil.setConfigValue(context, DOWNLOAD_PATH_KEY, filePath);
singDownloadInfo.setFileName(temp.getName());
singDownloadInfo.setDownloadPath(filePath);
liveData.postValue(singDownloadInfo);
}
/**
* 更新url
*/
void uploadUrl(Context context, String url) {
if (TextUtils.isEmpty(url)) {
ALog.e(TAG, "下载地址为空");
return;
}
AppUtil.setConfigValue(context, DOWNLOAD_URL_KEY, url);
singDownloadInfo.setUrl(url);
liveData.postValue(singDownloadInfo);
}
}

View File

@@ -1,166 +1,317 @@
/*
* 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.download
import android.arch.lifecycle.Observer
import android.arch.lifecycle.ViewModelProviders
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.os.Environment
import android.util.Log
import android.view.Menu
import android.view.MenuItem
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.DownloadEntity
import com.arialyy.aria.core.download.DownloadTarget
import com.arialyy.aria.core.download.DownloadTask
import com.arialyy.aria.core.inf.IEntity
import com.arialyy.aria.core.inf.IHttpFileLenAdapter
import com.arialyy.aria.core.scheduler.ISchedulers
import com.arialyy.aria.util.ALog
import com.arialyy.aria.util.CommonUtil
import com.arialyy.frame.util.show.T
import com.arialyy.simple.R
import com.arialyy.simple.base.BaseActivity
import com.arialyy.simple.databinding.ActivitySingleBinding
import com.arialyy.simple.common.ModifyPathDialog
import com.arialyy.simple.common.ModifyUrlDialog
import com.arialyy.simple.databinding.ActivitySingleKotlinBinding
import com.arialyy.simple.util.AppUtil
import com.pddstudio.highlightjs.models.Language
/**
* Created by lyy on 2017/10/23.
*/
class KotlinDownloadActivity : BaseActivity<ActivitySingleBinding>() {
import java.io.IOException
private val DOWNLOAD_URL =
"http://static.gaoshouyou.com/d/22/94/822260b849944492caadd2983f9bb624.apk"
class KotlinDownloadActivity : BaseActivity<ActivitySingleKotlinBinding>() {
private lateinit var mStart: Button
private lateinit var mStop: Button
private lateinit var mCancel: Button
private lateinit var target: DownloadTarget
private var mUrl: String? = null
private var mFilePath: String? = null
private var mModule: DownloadModule1? = null
private var mTarget: DownloadTarget? = null
override fun setLayoutId(): Int {
return R.layout.activity_single
internal var receiver: BroadcastReceiver = object : BroadcastReceiver() {
override fun onReceive(
context: Context,
intent: Intent
) {
if (intent.action == ISchedulers.ARIA_TASK_INFO_ACTION) {
ALog.d(TAG, "state = " + intent.getIntExtra(ISchedulers.TASK_STATE, -1))
ALog.d(TAG, "type = " + intent.getIntExtra(ISchedulers.TASK_TYPE, -1))
ALog.d(TAG, "speed = " + intent.getLongExtra(ISchedulers.TASK_SPEED, -1))
ALog.d(TAG, "percent = " + intent.getIntExtra(ISchedulers.TASK_PERCENT, -1))
ALog.d(
TAG, "entity = " + intent.getParcelableExtra<DownloadEntity>(
ISchedulers.TASK_ENTITY
).toString()
)
}
}
}
override fun onResume() {
super.onResume()
//registerReceiver(receiver, new IntentFilter(ISchedulers.ARIA_TASK_INFO_ACTION));
}
override fun onDestroy() {
super.onDestroy()
//unregisterReceiver(receiver);
Aria.download(this)
.unRegister()
}
override fun init(savedInstanceState: Bundle?) {
title = "kotlin测试"
Aria.get(this)
.downloadConfig.maxTaskNum = 2
super.init(savedInstanceState)
title = "单任务下载"
Aria.download(this)
.register()
mStart = findViewById(R.id.start)
mStop = findViewById(R.id.stop)
mCancel = findViewById(R.id.cancel)
mStop.visibility = View.GONE
mModule = ViewModelProviders.of(this)
.get(DownloadModule1::class.java)
mModule!!.getSingDownloadInfo(this)
.observe(this, Observer { entity ->
if (entity == null) {
return@Observer
}
mTarget = Aria.download(this)
.load(entity.url)
if (mTarget!!.taskState == IEntity.STATE_STOP) {
binding.stateStr = getString(R.string.resume)
} else if (mTarget!!.isRunning) {
binding.stateStr = getString(R.string.stop)
}
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 = "停止"
if (entity.fileSize != 0L) {
binding.fileSize = CommonUtil.formatFileSize(entity.fileSize.toDouble())
binding.progress = if (entity.isComplete)
100
else
(entity.currentProgress * 100 / entity.fileSize).toInt()
}
binding.url = entity.url
binding.filePath = entity.filePath
mUrl = entity.url
mFilePath = entity.filePath
})
binding.viewModel = this
try {
binding.codeView.setSource(AppUtil.getHelpCode(this, "KotlinHttpDownload.kt"), Language.JAVA)
} catch (e: IOException) {
e.printStackTrace()
}
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
fun chooseUrl() {
val dialog = ModifyUrlDialog(this, getString(R.string.modify_url_dialog_title), mUrl)
dialog.show(supportFragmentManager, "ModifyUrlDialog")
}
fun chooseFilePath() {
val dialog = ModifyPathDialog(this, getString(R.string.modify_file_path), mFilePath)
dialog.show(supportFragmentManager, "ModifyPathDialog")
}
override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.menu_single_task_activity, menu)
return super.onCreateOptionsMenu(menu)
}
override fun onMenuItemClick(item: MenuItem): Boolean {
var speed = -1
var msg = ""
when (item.itemId) {
R.id.help -> {
msg = ("一些小知识点:\n"
+ "1、你可以在注解中增加链接用于指定被注解的方法只能被特定的下载任务回调以防止progress乱跳\n"
+ "2、当遇到网络慢的情况时你可以先使用onPre()更新UI界面待连接成功时再在onTaskPre()获取完整的task数据然后给UI界面设置正确的数据\n"
+ "3、你可以在界面初始化时通过Aria.download(this).load(URL).getPercent()等方法快速获取相关任务的一些数据")
showMsgDialog("tip", msg)
}
R.id.speed_0 -> speed = 0
R.id.speed_128 -> speed = 128
R.id.speed_256 -> speed = 256
R.id.speed_512 -> speed = 512
R.id.speed_1m -> speed = 1024
}
binding.speed = task.convertSpeed
if (speed > -1) {
msg = item.title.toString()
Aria.download(this)
.setMaxSpeed(speed)
T.showShort(this, msg)
}
return true
}
@Download.onWait
fun onWait(task: DownloadTask) {
if (task.key == DOWNLOAD_URL) {
if (task.key == mUrl) {
Log.d(TAG, "wait ==> " + task.downloadEntity.fileName)
}
}
@Download.onPre
fun onPre(task: DownloadTask) {
if (task.key == DOWNLOAD_URL) {
mStart.text = "停止"
if (task.key == mUrl) {
binding.stateStr = getString(R.string.stop)
}
}
@Download.onTaskStart
fun taskStart(task: DownloadTask) {
if (task.key == DOWNLOAD_URL) {
if (task.key == mUrl) {
binding.fileSize = task.convertFileSize
}
}
@Download.onTaskComplete
fun complete(task: DownloadTask) {
Log.d(TAG, "完成")
@Download.onTaskRunning
fun running(task: DownloadTask) {
if (task.key == mUrl) {
//Log.d(TAG, task.getKey());
val len = task.fileSize
if (len == 0L) {
binding.progress = 0
} else {
binding.progress = task.percent
}
binding.speed = task.convertSpeed
}
}
@Download.onTaskResume
fun taskResume(task: DownloadTask) {
if (task.key == DOWNLOAD_URL) {
mStart.text = "停止"
if (task.key == mUrl) {
binding.stateStr = getString(R.string.stop)
}
}
@Download.onTaskStop
fun taskStop(task: DownloadTask) {
if (task.key == DOWNLOAD_URL) {
mStart.text = "恢复"
if (task.key == mUrl) {
binding.stateStr = getString(R.string.resume)
binding.speed = ""
}
}
@Download.onTaskCancel
fun taskCancel(task: DownloadTask) {
if (task.key == DOWNLOAD_URL) {
if (task.key == mUrl) {
binding.progress = 0
Toast.makeText(this@KotlinDownloadActivity, "取消下载", Toast.LENGTH_SHORT)
.show()
mStart.text = "开始"
binding.stateStr = getString(R.string.start)
binding.speed = ""
Log.d(TAG, "cancel")
}
}
/**
*
*/
@Download.onTaskFail
fun taskFail(task: DownloadTask) {
if (task.key == DOWNLOAD_URL) {
Toast.makeText(this@KotlinDownloadActivity, "下载失败", Toast.LENGTH_SHORT)
fun taskFail(
task: DownloadTask,
e: Exception
) {
if (task.key == mUrl) {
Toast.makeText(this, getString(R.string.download_fail), Toast.LENGTH_SHORT)
.show()
mStart.text = "开始"
binding.stateStr = getString(R.string.start)
}
}
@Download.onNoSupportBreakPoint
fun onNoSupportBreakPoint(task: DownloadTask) {
Log.d(TAG, "该下载链接不支持断点")
if (task.key == DOWNLOAD_URL) {
T.showShort(this@KotlinDownloadActivity, "该下载链接不支持断点")
@Download.onTaskComplete
fun taskComplete(task: DownloadTask) {
if (task.key == mUrl) {
binding.progress = 100
Toast.makeText(
this, getString(R.string.download_success),
Toast.LENGTH_SHORT
)
.show()
binding.stateStr = getString(R.string.re_start)
binding.speed = ""
}
}
override fun setLayoutId(): Int {
return R.layout.activity_single_kotlin
}
fun onClick(view: View) {
when (view.id) {
R.id.start -> {
if (target.isRunning) {
Aria.download(this)
.load(DOWNLOAD_URL)
.stop()
} else {
startD()
}
R.id.start -> if (mTarget!!.isRunning) {
Aria.download(this)
.load(mUrl!!)
.stop()
} else {
startD()
}
R.id.stop -> Aria.download(this).load(DOWNLOAD_URL).stop()
R.id.cancel -> Aria.download(this).load(DOWNLOAD_URL).cancel()
R.id.stop -> Aria.download(this).load(mUrl!!).stop()
R.id.cancel -> Aria.download(this).load(mUrl!!).cancel(true)
}
}
private fun startD() {
Aria.download(this)
.load(DOWNLOAD_URL)
.addHeader("groupHash", "value")
.setFilePath(Environment.getExternalStorageDirectory().path + "/kotlin.apk")
.load(mUrl!!)
//.addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3")
//.addHeader("Accept-Encoding", "gzip, deflate")
//.addHeader("DNT", "1")
//.addHeader("Cookie", "BAIDUID=648E5FF020CC69E8DD6F492D1068AAA9:FG=1; BIDUPSID=648E5FF020CC69E8DD6F492D1068AAA9; PSTM=1519099573; BD_UPN=12314753; locale=zh; BDSVRTM=0")
.useServerFileName(true)
.setFilePath(mFilePath!!, true)
.setFileLenAdapter(IHttpFileLenAdapter { headers ->
val sLength = headers["Content-Length"]
if (sLength == null || sLength.isEmpty()) {
return@IHttpFileLenAdapter -1
}
val temp = sLength[0]
java.lang.Long.parseLong(temp)
})
.start()
}
override fun onStop() {
super.onStop()
//Aria.download(this).unRegister();
}
override fun dataCallback(
result: Int,
data: Any
) {
super.dataCallback(result, data)
if (result == ModifyUrlDialog.MODIFY_URL_DIALOG_RESULT) {
mModule!!.uploadUrl(this, data.toString())
} else if (result == ModifyPathDialog.MODIFY_PATH_RESULT) {
mModule!!.updateFilePath(this, data.toString())
}
}
}

View File

@@ -16,25 +16,21 @@
package com.arialyy.simple.core.download;
import android.arch.lifecycle.Observer;
import android.arch.lifecycle.ViewModelProviders;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.text.TextUtils;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.RadioGroup;
import android.widget.Toast;
import com.arialyy.annotations.Download;
import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.download.DTaskWrapper;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.DownloadTarget;
import com.arialyy.aria.core.download.DownloadTask;
@@ -43,43 +39,24 @@ import com.arialyy.aria.core.inf.IHttpFileLenAdapter;
import com.arialyy.aria.core.scheduler.ISchedulers;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CommonUtil;
import com.arialyy.frame.util.show.L;
import com.arialyy.frame.util.show.T;
import com.arialyy.simple.R;
import com.arialyy.simple.base.BaseActivity;
import com.arialyy.simple.common.ModifyPathDialog;
import com.arialyy.simple.common.ModifyUrlDialog;
import com.arialyy.simple.databinding.ActivitySingleBinding;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.bitmap.BitmapTransformation;
import com.bumptech.glide.load.resource.transcode.BitmapBytesTranscoder;
import java.io.File;
import java.util.HashMap;
import com.arialyy.simple.util.AppUtil;
import java.io.IOException;
import java.util.List;
import java.util.Map;
public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
private String DOWNLOAD_URL =
//"http://kotlinlang.org/docs/kotlin-docs.pdf";
//"https://atom-installer.github.com/v1.13.0/AtomSetup.exe?s=1484074138&ext=.exe";
//"http://static.gaoshouyou.com/d/22/94/822260b849944492caadd2983f9bb624.apks";
"http://hzdown.muzhiwan.com/2017/05/08/nl.noio.kingdom_59104935e56f0.apk";
//"http://120.55.95.61:8811/ghcg/zg/武义总规纲要成果.zip";
//"https://yizi-kejian.oss-cn-beijing.aliyuncs.com/qimeng/package1/qmtable11.zip";
//"http://rs.0.gaoshouyou.com/d/04/1e/400423a7551e1f3f0eb1812afa1f9b44.apk";
//"http://chargepile2.techsum.net/car-manage/file/download?path=2019-04-26/c0242efd18be4ecbb23911b1c509dcad--掌通各系统汇总.xls"; // 无长度的chunked
//"http://58.210.9.131/tpk/sipgt//TDLYZTGH.tpk"; //chunked 下载
//"http://apk500.bce.baidu-mgame.com/game/67000/67734/20170622040827_oem_5502845.apk?r=1";
//"https://dl.genymotion.com/releases/genymotion-2.12.1/genymotion-2.12.1-vbox.exe";
//"http://9.9.9.50:5000/download/CentOS-7-x86_64-Minimal-1804.iso";
//"http://v2.qingdian1.com/m_20180730_991/2/2B9FB34A4BCD8CE61481D1C8418EFE36_1080P.m3u8";
//"https://firmwareapi.azurewebsites.net/firmware-overview?name=A19_Filament_W_IMG0038_00102411-encrypted.ota";
Button mStart;
Button mStop;
Button mCancel;
RadioGroup mRg;
DownloadTarget target;
private String mUrl;
private String mFilePath;
private DownloadModule1 mModule;
private DownloadTarget mTarget;
BroadcastReceiver receiver = new BroadcastReceiver() {
@Override
@@ -110,22 +87,51 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
@Override
protected void init(Bundle savedInstanceState) {
super.init(savedInstanceState);
mStart = findViewById(R.id.start);
mStop = findViewById(R.id.stop);
mCancel = findViewById(R.id.cancel);
mRg = findViewById(R.id.speeds);
mStop.setVisibility(View.GONE);
setTitle("单任务下载");
Aria.download(this).register();
target = Aria.download(this).load(DOWNLOAD_URL);
getBinding().setProgress(target.getPercent());
if (target.getTaskState() == IEntity.STATE_STOP) {
mStart.setText("恢复");
//mStart.setTextColor(getResources().getColor(android.R.color.holo_blue_light));
} else if (target.isRunning()) {
mStart.setText("停止");
mModule = ViewModelProviders.of(this).get(DownloadModule1.class);
mModule.getSingDownloadInfo(this).observe(this, new Observer<DownloadEntity>() {
@Override public void onChanged(@Nullable DownloadEntity entity) {
if (entity == null) {
return;
}
mTarget = Aria.download(SingleTaskActivity.this).load(entity.getUrl());
if (mTarget.getTaskState() == IEntity.STATE_STOP) {
getBinding().setStateStr(getString(R.string.resume));
} else if (mTarget.isRunning()) {
getBinding().setStateStr(getString(R.string.stop));
}
if (entity.getFileSize() != 0) {
getBinding().setFileSize(CommonUtil.formatFileSize(entity.getFileSize()));
getBinding().setProgress(entity.isComplete() ? 100
: (int) (entity.getCurrentProgress() * 100 / entity.getFileSize()));
}
getBinding().setUrl(entity.getUrl());
getBinding().setFilePath(entity.getFilePath());
mUrl = entity.getUrl();
mFilePath = entity.getFilePath();
}
});
getBinding().setViewModel(this);
try {
getBinding().codeView.setSource(AppUtil.getHelpCode(this, "HttpDownload.java"));
} catch (IOException e) {
e.printStackTrace();
}
getBinding().setFileSize(target.getConvertFileSize());
}
public void chooseUrl() {
ModifyUrlDialog dialog =
new ModifyUrlDialog(this, getString(R.string.modify_url_dialog_title), mUrl);
dialog.show(getSupportFragmentManager(), "ModifyUrlDialog");
}
public void chooseFilePath() {
ModifyPathDialog dialog =
new ModifyPathDialog(this, getString(R.string.modify_file_path), mFilePath);
dialog.show(getSupportFragmentManager(), "ModifyPathDialog");
}
@Override
@@ -172,61 +178,59 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
@Download.onWait
void onWait(DownloadTask task) {
if (task.getKey().equals(DOWNLOAD_URL)) {
if (task.getKey().equals(mUrl)) {
Log.d(TAG, "wait ==> " + task.getDownloadEntity().getFileName());
}
}
@Download.onPre
protected void onPre(DownloadTask task) {
if (task.getKey().equals(DOWNLOAD_URL)) {
mStart.setText("停止");
if (task.getKey().equals(mUrl)) {
getBinding().setStateStr(getString(R.string.stop));
}
}
@Download.onTaskStart
void taskStart(DownloadTask task) {
if (task.getKey().equals(DOWNLOAD_URL)) {
if (task.getKey().equals(mUrl)) {
getBinding().setFileSize(task.getConvertFileSize());
}
}
@Download.onTaskRunning
protected void running(DownloadTask task) {
//ALog.d(TAG, String.format("%s_running_%s", getClass().getName(), hashCode()));
//if (task.getKey().equals(DOWNLOAD_URL)) {
//Log.d(TAG, task.getKey());
long len = task.getFileSize();
if (len == 0) {
getBinding().setProgress(0);
} else {
getBinding().setProgress(task.getPercent());
if (task.getKey().equals(mUrl)) {
//Log.d(TAG, task.getKey());
long len = task.getFileSize();
if (len == 0) {
getBinding().setProgress(0);
} else {
getBinding().setProgress(task.getPercent());
}
getBinding().setSpeed(task.getConvertSpeed());
}
getBinding().setSpeed(task.getConvertSpeed());
//}
}
@Download.onTaskResume
void taskResume(DownloadTask task) {
if (task.getKey().equals(DOWNLOAD_URL)) {
mStart.setText("停止");
if (task.getKey().equals(mUrl)) {
getBinding().setStateStr(getString(R.string.stop));
}
}
@Download.onTaskStop
void taskStop(DownloadTask task) {
if (task.getKey().equals(DOWNLOAD_URL)) {
mStart.setText("恢复");
if (task.getKey().equals(mUrl)) {
getBinding().setStateStr(getString(R.string.resume));
getBinding().setSpeed("");
}
}
@Download.onTaskCancel
void taskCancel(DownloadTask task) {
if (task.getKey().equals(DOWNLOAD_URL)) {
if (task.getKey().equals(mUrl)) {
getBinding().setProgress(0);
Toast.makeText(SingleTaskActivity.this, "取消下载", Toast.LENGTH_SHORT).show();
mStart.setText("开始");
getBinding().setStateStr(getString(R.string.start));
getBinding().setSpeed("");
Log.d(TAG, "cancel");
}
@@ -237,48 +241,22 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
*/
@Download.onTaskFail
void taskFail(DownloadTask task, Exception e) {
if (task.getKey().equals(DOWNLOAD_URL)) {
Toast.makeText(SingleTaskActivity.this, "下载失败", Toast.LENGTH_SHORT).show();
mStart.setText("开始");
if (task.getKey().equals(mUrl)) {
Toast.makeText(SingleTaskActivity.this, getString(R.string.download_fail), Toast.LENGTH_SHORT)
.show();
getBinding().setStateStr(getString(R.string.start));
}
}
@Download.onTaskComplete
void taskComplete(DownloadTask task) {
//Glide.with(this).load("").asBitmap().transform(new BitmapTransformation() {
// @Override
// protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) {
// return null;
// }
//
// @Override public String getId() {
// return null;
// }
//})
//if (task.getKey().equals(DOWNLOAD_URL)) {
getBinding().setProgress(100);
Toast.makeText(SingleTaskActivity.this, "下载完成", Toast.LENGTH_SHORT).show();
mStart.setText("重新开始?");
//mCancel.setEnabled(false);
getBinding().setSpeed("");
L.d(TAG, "path = " + task.getDownloadEntity().getDownloadPath());
L.d(TAG, "md5Code = " + CommonUtil.getFileMD5(new File(task.getDownloadPath())));
L.d(TAG, "data = " + Aria.download(this).getDownloadEntity(DOWNLOAD_URL));
//DownloadEntity temp = Aria.download(this).getDownloadEntity(DOWNLOAD_URL);
//L.d(TAG, "status = " + temp.getState() + ", isComplete = " + temp.isComplete());
//Intent install = new Intent(Intent.ACTION_VIEW);
//install.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//File apkFile = new File(task.getDownloadPath());
//install.setDataAndType(Uri.fromFile(apkFile), "application/vnd.android.package-archive");
//startActivity(install);
//}
}
@Download.onNoSupportBreakPoint
public void onNoSupportBreakPoint(DownloadTask task) {
Log.d(TAG, "该下载链接不支持断点");
if (task.getKey().equals(DOWNLOAD_URL)) {
T.showShort(SingleTaskActivity.this, "该下载链接不支持断点");
if (task.getKey().equals(mUrl)) {
getBinding().setProgress(100);
Toast.makeText(SingleTaskActivity.this, getString(R.string.download_success),
Toast.LENGTH_SHORT).show();
getBinding().setStateStr(getString(R.string.re_start));
getBinding().setSpeed("");
}
}
@@ -290,35 +268,30 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
public void onClick(View view) {
switch (view.getId()) {
case R.id.start:
if (target.isRunning()) {
Aria.download(this).load(DOWNLOAD_URL).stop();
if (mTarget.isRunning()) {
Aria.download(this).load(mUrl).stop();
} else {
startD();
}
break;
case R.id.stop:
Aria.download(this).load(DOWNLOAD_URL).stop();
Aria.download(this).load(mUrl).stop();
break;
case R.id.cancel:
Aria.download(this).load(DOWNLOAD_URL).reStart();
//Aria.download(this).load(DOWNLOAD_URL).cancel(true);
//Aria.download(this).load(DOWNLOAD_URL).removeRecord();
Aria.download(this).load(mUrl).cancel(true);
break;
}
}
int i = 1;
private void startD() {
String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/ggsg14.apk";
Aria.download(SingleTaskActivity.this)
.load(DOWNLOAD_URL)
.load(mUrl)
//.addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3")
//.addHeader("Accept-Encoding", "gzip, deflate")
//.addHeader("DNT", "1")
//.addHeader("Cookie", "BAIDUID=648E5FF020CC69E8DD6F492D1068AAA9:FG=1; BIDUPSID=648E5FF020CC69E8DD6F492D1068AAA9; PSTM=1519099573; BD_UPN=12314753; locale=zh; BDSVRTM=0")
.useServerFileName(true)
.setFilePath(path, true)
.setFilePath(mFilePath, true)
.setFileLenAdapter(new IHttpFileLenAdapter() {
@Override public long handleFileLen(Map<String, List<String>> headers) {
@@ -331,15 +304,7 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
return Long.parseLong(temp);
}
})
//.asGet()
//.asPost()
//.setParams(params)
//.setExtendField("{\n"
// + "\"id\":\"你的样子\"\n< > "
// + "}")
//.resetState()
.start();
//.add();
}
@Override
@@ -347,4 +312,13 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
super.onStop();
//Aria.download(this).unRegister();
}
@Override protected void dataCallback(int result, Object data) {
super.dataCallback(result, data);
if (result == ModifyUrlDialog.MODIFY_URL_DIALOG_RESULT) {
mModule.uploadUrl(this, String.valueOf(data));
} else if (result == ModifyPathDialog.MODIFY_PATH_RESULT) {
mModule.updateFilePath(this, String.valueOf(data));
}
}
}

View File

@@ -3,9 +3,9 @@ package com.arialyy.simple.core.test;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import com.arialyy.annotations.Upload;
import com.arialyy.annotations.Download;
import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.upload.UploadTask;
import com.arialyy.aria.core.download.DownloadTask;
import com.arialyy.aria.util.CommonUtil;
import com.arialyy.simple.R;
import com.arialyy.simple.base.BaseActivity;
@@ -13,16 +13,14 @@ import com.arialyy.simple.databinding.ActivityTestBinding;
import java.io.File;
/**
* Created by Administrator on 2018/4/12.
* Created by lyy on 2019/5/28.
* Ftp 下载
* <a href="https://aria.laoyuyu.me/aria_doc/">文档</>
*/
public class TestFTPActivity extends BaseActivity<ActivityTestBinding> {
String TAG = "TestFTPActivity";
//String URL = "http://58.210.9.131/tpk/sipgt//TDLYZTGH.tpk"; //chunked 下载
//private final String URL = "ftp://192.168.1.3:21/download//AriaPrj.rar";
private final String FILE_PATH = "/mnt/sdcard/mmm.mp4";
private final String URL = "ftps://9.9.9.59:990/aa/你好";
private final String URL = "ftp://192.168.1.3:21/download//AriaPrj.rar";
private final String FILE_PATH = "/mnt/sdcard/AriaPrj.rar";
@Override protected int setLayoutId() {
return R.layout.activity_test;
@@ -31,65 +29,62 @@ public class TestFTPActivity extends BaseActivity<ActivityTestBinding> {
@Override protected void init(Bundle savedInstanceState) {
super.init(savedInstanceState);
mBar.setVisibility(View.GONE);
Aria.upload(this).register();
Aria.upload(this).setMaxSpeed(128);
Aria.download(this).register();
}
@Upload.onWait void onWait(UploadTask task) {
@Download.onWait void onWait(DownloadTask task) {
Log.d(TAG, "wait ==> " + task.getEntity().getFileName());
}
@Upload.onPre protected void onPre(UploadTask task) {
@Download.onPre protected void onPre(DownloadTask task) {
Log.d(TAG, "onPre");
}
@Upload.onTaskStart void taskStart(UploadTask task) {
@Download.onTaskStart void taskStart(DownloadTask task) {
Log.d(TAG, "onStart");
}
@Upload.onTaskRunning protected void running(UploadTask task) {
@Download.onTaskRunning protected void running(DownloadTask task) {
Log.d(TAG, "runningspeed=" + task.getConvertSpeed());
}
@Upload.onTaskResume void taskResume(UploadTask task) {
@Download.onTaskResume void taskResume(DownloadTask task) {
Log.d(TAG, "resume");
}
@Upload.onTaskStop void taskStop(UploadTask task) {
@Download.onTaskStop void taskStop(DownloadTask task) {
Log.d(TAG, "stop");
}
@Upload.onTaskCancel void taskCancel(UploadTask task) {
@Download.onTaskCancel void taskCancel(DownloadTask task) {
Log.d(TAG, "cancel");
}
@Upload.onTaskFail void taskFail(UploadTask task) {
@Download.onTaskFail void taskFail(DownloadTask task) {
Log.d(TAG, "fail");
}
@Upload.onTaskComplete void taskComplete(UploadTask task) {
@Download.onTaskComplete void taskComplete(DownloadTask task) {
Log.d(TAG, "complete, md5 => " + CommonUtil.getFileMD5(new File(task.getKey())));
}
public void onClick(View view) {
switch (view.getId()) {
case R.id.start:
Aria.upload(this)
.loadFtp(FILE_PATH)
Aria.download(this)
.loadFtp(URL)
.setFilePath(FILE_PATH)
.login("lao", "123456")
.setUploadUrl(URL)
.asFtps()
.setStorePath("/mnt/sdcard/Download/server.crt")
.setAlias("www.laoyuyu.me")
//.asFtps() // ftps 配置
//.setStorePath("/mnt/sdcard/Download/server.crt") //设置证书路径
// .setAlias("www.laoyuyu.me") // 设置证书别名
.start();
//Uri uri = Uri.parse("ftp://z:z@dygod18.com:21211/[电影天堂www.dy2018.com]猩球崛起3终极之战BD国英双语中英双字.mkv");
//ALog.d(TAG, "sh = " + uri.getScheme() + ", user = " + uri.getUserInfo() + ", host = " + uri.getHost() + ", port = " + uri.getPort() + " remotePath = " + uri.getPath());
break;
case R.id.stop:
Aria.upload(this).loadFtp(FILE_PATH).stop();
Aria.download(this).loadFtp(FILE_PATH).stop();
break;
case R.id.cancel:
Aria.upload(this).loadFtp(FILE_PATH).cancel();
Aria.download(this).loadFtp(FILE_PATH).cancel();
break;
}
}

View File

@@ -15,11 +15,11 @@
*/
package com.arialyy.simple.core.upload;
import android.arch.lifecycle.Observer;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.content.FileProvider;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.View;
import com.arialyy.annotations.Upload;
@@ -28,38 +28,64 @@ 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.ALog;
import com.arialyy.aria.util.CommonUtil;
import com.arialyy.frame.util.FileUtil;
import com.arialyy.frame.util.show.T;
import com.arialyy.simple.BuildConfig;
import com.arialyy.simple.R;
import com.arialyy.simple.base.BaseActivity;
import com.arialyy.simple.common.ModifyUrlDialog;
import com.arialyy.simple.databinding.ActivityFtpUploadBinding;
import com.arialyy.simple.util.AppUtil;
import java.io.File;
import java.io.IOException;
import java.util.List;
import android.arch.lifecycle.ViewModelProviders;
/**
* Created by lyy on 2017/7/28. Ftp 文件上传demo
*/
public class FtpUploadActivity extends BaseActivity<ActivityFtpUploadBinding> {
private final int OPEN_FILE_MANAGER_CODE = 0xB1;
private String mFilePath = "/mnt/sdcard/AriaPrj.rar";
private String mUrl = "ftp://9.9.9.205:2121/aa/你好";
private String mFilePath;
private String mUrl;
private UploadModule mModule;
@Override protected void init(Bundle savedInstanceState) {
setTile("D_FTP 文件上传");
super.init(savedInstanceState);
Aria.upload(this).register();
UploadEntity entity = Aria.upload(this).getUploadEntity(mFilePath);
if (entity != null) {
getBinding().setFileSize(CommonUtil.formatFileSize(entity.getFileSize()));
getBinding().setProgress(entity.isComplete() ? 100
: (int) (entity.getCurrentProgress() * 100 / entity.getFileSize()));
}
getBinding().setUrl(mUrl);
getBinding().setFilePath(mFilePath);
getBinding().setViewModel(this);
setUI();
}
private void setUI() {
mModule = ViewModelProviders.of(this).get(UploadModule.class);
mModule.getFtpInfo(this).observe(this, new Observer<UploadEntity>() {
@Override public void onChanged(@Nullable UploadEntity entity) {
if (entity != null) {
if (entity.getFileSize() != 0) {
getBinding().setFileSize(CommonUtil.formatFileSize(entity.getFileSize()));
getBinding().setProgress(entity.isComplete() ? 100
: (int) (entity.getCurrentProgress() * 100 / entity.getFileSize()));
}
getBinding().setUrl(entity.getUrl());
getBinding().setFilePath(entity.getFilePath());
mUrl = entity.getUrl();
mFilePath = entity.getFilePath();
}
}
});
setHelpCode();
}
private void setHelpCode() {
try {
getBinding().codeView.setSource(AppUtil.getHelpCode(this, "FtpUpload.java"));
} catch (IOException e) {
e.printStackTrace();
}
}
@Override protected int setLayoutId() {
@@ -73,23 +99,7 @@ public class FtpUploadActivity extends BaseActivity<ActivityFtpUploadBinding> {
}
public void chooseFilePath() {
File parentFile = new File(mFilePath);
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
Uri uri;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
uri = FileProvider.getUriForFile(this,
BuildConfig.APPLICATION_ID + ".provider",
parentFile.getParentFile());
} else {
uri = Uri.fromFile(parentFile.getParentFile());
}
intent.setDataAndType(uri, "*/*");
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivityForResult(intent, OPEN_FILE_MANAGER_CODE);
AppUtil.chooseFile(this, new File(mFilePath), null, OPEN_FILE_MANAGER_CODE);
}
public void onClick(View view) {
@@ -169,8 +179,7 @@ public class FtpUploadActivity extends BaseActivity<ActivityFtpUploadBinding> {
@Override protected void dataCallback(int result, Object data) {
super.dataCallback(result, data);
if (result == ModifyUrlDialog.MODIFY_URL_DIALOG_RESULT) {
mUrl = String.valueOf(data);
getBinding().setUrl(mUrl);
mModule.updateFtpUrl(this, String.valueOf(data));
}
}
@@ -178,7 +187,12 @@ public class FtpUploadActivity extends BaseActivity<ActivityFtpUploadBinding> {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == OPEN_FILE_MANAGER_CODE && resultCode == RESULT_OK) {
Uri uri = data.getData();
//Toast.makeText(this, "文件路径:" + uri.getPath(), Toast.LENGTH_SHORT).show();
if (uri != null) {
mModule.updateFtpFilePath(this, uri.getPath());
ALog.d(TAG, String.format("选择的文件路径:%s", uri.getPath()));
} else {
ALog.d(TAG, "没有选择文件");
}
}
}
}

View File

@@ -0,0 +1,74 @@
/*
* 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.arch.lifecycle.LiveData;
import android.arch.lifecycle.MutableLiveData;
import android.content.Context;
import android.os.Environment;
import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.upload.UploadEntity;
import com.arialyy.frame.base.BaseViewModule;
import com.arialyy.simple.util.AppUtil;
public class UploadModule extends BaseViewModule {
private final String FTP_URL_KEY = "FTP_URL_KEY";
private final String FTP_PATH_KEY = "FTP_PATH_KEY";
private MutableLiveData<UploadEntity> liveData = new MutableLiveData<>();
UploadEntity uploadInfo;
/**
* 获取Ftp上传信息
*/
LiveData<UploadEntity> getFtpInfo(Context context) {
String url = AppUtil.getConfigValue(context, FTP_URL_KEY, "ftp://9.9.9.205:2121/aa/你好");
String filePath = AppUtil.getConfigValue(context, FTP_PATH_KEY,
Environment.getExternalStorageDirectory().getPath() + "/AriaPrj.rar");
UploadEntity entity = Aria.upload(context).getUploadEntity(filePath);
if (entity != null) {
uploadInfo = entity;
AppUtil.setConfigValue(context, FTP_URL_KEY, uploadInfo.getUrl());
AppUtil.setConfigValue(context, FTP_PATH_KEY, uploadInfo.getFilePath());
} else {
uploadInfo = new UploadEntity();
uploadInfo.setUrl(url);
uploadInfo.setFilePath(filePath);
}
liveData.postValue(uploadInfo);
return liveData;
}
/**
* 更新Url
*/
void updateFtpUrl(Context context, String url) {
uploadInfo.setUrl(url);
AppUtil.setConfigValue(context, FTP_URL_KEY, url);
liveData.postValue(uploadInfo);
}
/**
* 更新文件路径
*/
void updateFtpFilePath(Context context, String filePath) {
uploadInfo.setFilePath(filePath);
AppUtil.setConfigValue(context, FTP_PATH_KEY, filePath);
liveData.postValue(uploadInfo);
}
}

View File

@@ -0,0 +1,106 @@
/*
* 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.util;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Build;
import android.support.v4.content.FileProvider;
import android.text.TextUtils;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CommonUtil;
import com.arialyy.simple.BuildConfig;
import java.io.File;
import java.io.IOException;
public class AppUtil {
private static final String TAG = "AppUtil";
private static final String ARIA_SHARE_PRE_KEY = "ARIA_SHARE_PRE_KEY";
/**
* http下载示例代码
*/
public static File getHelpCode(Context context, String fileName) throws IOException {
String path = String.format("%s/code/%s", context.getFilesDir().getPath(), fileName);
File ftpCode = new File(path);
if (!ftpCode.exists()) {
CommonUtil.createFile(path);
CommonUtil.createFileFormInputStream(context.getAssets()
.open(String.format("help_code/%s", fileName)),
path);
}
return ftpCode;
}
/**
* 读取配置文件字段
*
* @param key key
* @param defStr 默认字符串
*/
public static String getConfigValue(Context context, String key, String defStr) {
SharedPreferences preferences =
context.getSharedPreferences(ARIA_SHARE_PRE_KEY, Context.MODE_PRIVATE);
return preferences.getString(key, defStr);
}
/**
* set配置文件字段
*
* @param key key
* @param value 需要保存的字符串
*/
public static void setConfigValue(Context context, String key, String value) {
SharedPreferences preferences =
context.getSharedPreferences(ARIA_SHARE_PRE_KEY, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putString(key, value);
editor.apply();
}
/**
* 调用系统文件管理器选择文件
*
* @param file 不能是文件夹
* @param mineType android 可用的minetype
* @param requestCode 请求码
*/
public static void chooseFile(Activity activity, File file, String mineType, int requestCode) {
if (file.isDirectory()) {
ALog.e(TAG, "不能选择文件夹");
return;
}
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
Uri uri;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
uri = FileProvider.getUriForFile(activity.getApplicationContext(),
BuildConfig.APPLICATION_ID + ".provider",
file);
} else {
uri = Uri.fromFile(file);
}
intent.setDataAndType(uri, TextUtils.isEmpty(mineType) ? "*/*" : mineType);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
activity.startActivityForResult(intent, requestCode);
}
}

View File

@@ -0,0 +1,76 @@
/*
* 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.widget;
import android.content.Context;
import android.content.Intent;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.RelativeLayout;
import com.arialyy.simple.R;
import com.arialyy.simple.core.FullScreenCodeActivity;
import com.pddstudio.highlightjs.HighlightJsView;
import com.pddstudio.highlightjs.models.Language;
import com.pddstudio.highlightjs.models.Theme;
import java.io.File;
/**
* 代码高亮控件
*/
public class CodeView extends RelativeLayout {
private HighlightJsView mCodeView;
private File mSourceFile;
public CodeView(Context context) {
super(context, null);
}
public CodeView(Context context, AttributeSet attrs) {
super(context, attrs);
init(context);
}
private void init(Context context) {
LayoutInflater.from(context).inflate(R.layout.layout_code_demo, this, true);
mCodeView = findViewById(R.id.js_view);
mCodeView.setHighlightLanguage(Language.JAVA);
mCodeView.setTheme(Theme.ANDROID_STUDIO);
mCodeView.setZoomSupportEnabled(true);
findViewById(R.id.full_screen).setOnClickListener(new OnClickListener() {
@Override public void onClick(View v) {
// 横屏显示代码
Intent intent = new Intent(getContext(), FullScreenCodeActivity.class);
intent.putExtra(FullScreenCodeActivity.KEY_FILE_PATH, mSourceFile.getPath());
getContext().startActivity(intent);
}
});
}
public void setSource(File sourceFile) {
mSourceFile = sourceFile;
mCodeView.setSource(sourceFile);
}
public void setSource(File sourceFile, Language language) {
mSourceFile = sourceFile;
mCodeView.setHighlightLanguage(language);
mCodeView.setSource(sourceFile);
}
}

View File

@@ -21,6 +21,7 @@ import android.databinding.BindingAdapter;
import android.graphics.drawable.Drawable;
import android.support.annotation.DrawableRes;
import android.support.v7.widget.AppCompatImageView;
import android.text.Html;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
@@ -78,7 +79,7 @@ public class SvgTextView extends RelativeLayout {
icon.setImageResource(drawable);
}
public void setText(CharSequence text) {
textView.setText(text);
public void setText(String text) {
textView.setText(Html.fromHtml(text));
}
}

View File

@@ -1,6 +1,15 @@
<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="#2b2b2b" android:pathData="M895.65,672.81c14.3,0 23.74,-9.54 23.74,-23.74L919.39,269.29a30.46,30.46 0,0 0,-8.66 -21.29L738.23,71.19A30.46,30.46 0,0 0,716.42 62L199.21,62c-52.29,0 -95.07,42.78 -95.07,95.07v654h-0.1v51.85h0.1c0,52.25 42.81,95.07 95.07,95.07h625.11c52.25,0 95.07,-42.81 95.07,-95.07v-71.31c0,-14.31 -9.54,-23.74 -23.74,-23.74s-23.74,9.54 -23.74,23.74v71.32a47.69,47.69 0,0 1,-47.48 47.58L199.21,910.51a47.72,47.72 0,0 1,-47.58 -47.58v-28.11h0.1L151.73,157.06a47.63,47.63 0,0 1,47.58 -47.48h482.47v123.57a71.32,71.32 0,0 0,71.32 71.32h118.8v344.6c-0.09,14.2 9.44,23.74 23.75,23.74zM847.19,256.81L753,256.81v0.1c-14.3,0 -23.74,-11.92 -23.74,-23.74v-98.75a2.4,2.4 0,0 1,4.13 -1.67l115.52,120a2.4,2.4 0,0 1,-1.73 4.04z"/>
<path android:fillColor="#2b2b2b" android:pathData="M318.91,394.59c-14.78,0 -26.81,-12.25 -26.81,-27.3s12,-27.3 26.81,-27.3h300.47c14.78,0 26.81,12.25 26.81,27.3s-12,27.3 -26.81,27.3zM318.91,569.8c-14.78,0 -26.81,-12.25 -26.81,-27.3s12,-27.3 26.81,-27.3h384.85c14.78,0 26.81,12.25 26.81,27.3s-12,27.3 -26.81,27.3zM318.91,742c-14.78,0 -26.81,-12.25 -26.81,-27.3s12,-27.3 26.81,-27.3h261.3c14.78,0 26.81,12.25 26.81,27.3S595,742 580.21,742z"/>
<path android:fillColor="#2b2b2b" android:pathData="M704.01,367.3m-27.3,0a27.3,27.3 0,1 0,54.6 0,27.3 27.3,0 1,0 -54.6,0Z"/>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:viewportHeight="1024"
android:viewportWidth="1024"
android:width="24dp">
<path
android:fillColor="@color/icon_black"
android:pathData="M895.65,672.81c14.3,0 23.74,-9.54 23.74,-23.74L919.39,269.29a30.46,30.46 0,0 0,-8.66 -21.29L738.23,71.19A30.46,30.46 0,0 0,716.42 62L199.21,62c-52.29,0 -95.07,42.78 -95.07,95.07v654h-0.1v51.85h0.1c0,52.25 42.81,95.07 95.07,95.07h625.11c52.25,0 95.07,-42.81 95.07,-95.07v-71.31c0,-14.31 -9.54,-23.74 -23.74,-23.74s-23.74,9.54 -23.74,23.74v71.32a47.69,47.69 0,0 1,-47.48 47.58L199.21,910.51a47.72,47.72 0,0 1,-47.58 -47.58v-28.11h0.1L151.73,157.06a47.63,47.63 0,0 1,47.58 -47.48h482.47v123.57a71.32,71.32 0,0 0,71.32 71.32h118.8v344.6c-0.09,14.2 9.44,23.74 23.75,23.74zM847.19,256.81L753,256.81v0.1c-14.3,0 -23.74,-11.92 -23.74,-23.74v-98.75a2.4,2.4 0,0 1,4.13 -1.67l115.52,120a2.4,2.4 0,0 1,-1.73 4.04z"/>
<path
android:fillColor="@color/icon_black"
android:pathData="M318.91,394.59c-14.78,0 -26.81,-12.25 -26.81,-27.3s12,-27.3 26.81,-27.3h300.47c14.78,0 26.81,12.25 26.81,27.3s-12,27.3 -26.81,27.3zM318.91,569.8c-14.78,0 -26.81,-12.25 -26.81,-27.3s12,-27.3 26.81,-27.3h384.85c14.78,0 26.81,12.25 26.81,27.3s-12,27.3 -26.81,27.3zM318.91,742c-14.78,0 -26.81,-12.25 -26.81,-27.3s12,-27.3 26.81,-27.3h261.3c14.78,0 26.81,12.25 26.81,27.3S595,742 580.21,742z"/>
<path
android:fillColor="@color/icon_black"
android:pathData="M704.01,367.3m-27.3,0a27.3,27.3 0,1 0,54.6 0,27.3 27.3,0 1,0 -54.6,0Z"/>
</vector>

View File

@@ -0,0 +1,6 @@
<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="#CE9F06" android:pathData="M975,774.77H49V220.37h857.09c38.11,0 69.04,30.93 69.04,69.04v485.37h-0.14zM627.71,220.37c0,-63.93 -51.78,-115.71 -115.71,-115.71H49v115.71h578.71"/>
<path android:fillColor="#FFFFFF" android:pathData="M164.72,620.26V273.11h694.56v347.14h-694.56z"/>
<path android:fillColor="#FFCD2C" android:pathData="M975,848.1V398.49c0,-31.9 -25.96,-57.86 -57.86,-57.86H106.86c-31.9,0 -57.86,25.96 -57.86,57.86v449.46c0,39.35 31.9,71.39 71.39,71.39h783.35c39.35,0.14 71.25,-31.9 71.25,-71.25z"/>
</vector>

View File

@@ -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_black" android:pathData="M432,636.8l-41.6,-41.6 -150.4,150.4L128,633.6L128,896h259.2l-108.8,-108.8 153.6,-150.4zM595.2,387.2l41.6,41.6 150.4,-150.4 108.8,108.8L896,128h-259.2l108.8,108.8 -150.4,150.4zM128,128v259.2l108.8,-108.8 150.4,150.4 41.6,-41.6 -147.2,-150.4L390.4,128L128,128zM595.2,636.8l150.4,150.4 -108.8,108.8L896,896v-259.2l-108.8,108.8 -150.4,-150.4 -41.6,41.6zM595.2,636.8"/>
</vector>

View File

@@ -4,6 +4,6 @@
android:viewportWidth="1024"
android:width="24dp">
<path
android:fillColor="#2b2b2b"
android:fillColor="@color/icon_black"
android:pathData="M768.49,388.36L590.76,215.07 210.93,594.49l-66.2,242.16v0.4L386.48,769.8zM739.52,66.62l-95.2,95.04 178.3,172.65 92.38,-92.3c48.49,-48.41 48.49,-126.99 0,-175.39 -48.4,-48.41 -127.07,-48.41 -175.47,-0zM79.03,878.71h872.33v114.98H79.03z"/>
</vector>

View File

@@ -71,5 +71,13 @@
bind:stateStr="@{stateStr}"
/>
<com.arialyy.simple.widget.CodeView
android:id="@+id/code_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>
</layout>

View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<com.pddstudio.highlightjs.HighlightJsView
android:id="@+id/code_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
/>
</LinearLayout>
</layout>

View File

@@ -16,40 +16,71 @@
name="progress"
type="int"
/>
<variable
name="stateStr"
type="String"
/>
<variable
name="url"
type="String"
/>
<variable
name="filePath"
type="String"
/>
<variable
name="viewModel"
type="com.arialyy.simple.core.download.SingleTaskActivity"
/>
</data>
<android.support.design.widget.CoordinatorLayout
<LinearLayout
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:orientation="vertical"
tools:context=".core.download.SingleTaskActivity"
>
<android.support.design.widget.AppBarLayout
<include layout="@layout/layout_bar"/>
<com.arialyy.simple.widget.SvgTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="16dp"
bind:iconClickListener="@{() -> viewModel.chooseUrl()}"
bind:svg_text_view_icon="@drawable/ic_modify"
bind:text="@{@string/url(url)}"
/>
<include layout="@layout/layout_bar"/>
</android.support.design.widget.AppBarLayout>
<com.arialyy.simple.widget.SvgTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="8dp"
bind:iconClickListener="@{() -> viewModel.chooseFilePath()}"
bind:svg_text_view_icon="@drawable/ic_choose_file"
bind:text="@{@string/file_path(filePath)}"
/>
<include
layout="@layout/content_single"
layout="@layout/layout_content_single"
bind:fileSize="@{fileSize}"
bind:progress="@{progress}"
bind:speed="@{speed}"
bind:stateStr="@{stateStr}"
/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
android:src="@android:drawable/ic_dialog_email"
<com.arialyy.simple.widget.CodeView
android:id="@+id/code_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</android.support.design.widget.CoordinatorLayout>
</LinearLayout>
</layout>

View File

@@ -0,0 +1,86 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:bind="http://schemas.android.com/apk/res-auto"
>
<data>
<variable
name="fileSize"
type="String"
/>
<variable
name="speed"
type="String"
/>
<variable
name="progress"
type="int"
/>
<variable
name="stateStr"
type="String"
/>
<variable
name="url"
type="String"
/>
<variable
name="filePath"
type="String"
/>
<variable
name="viewModel"
type="com.arialyy.simple.core.download.KotlinDownloadActivity"
/>
</data>
<LinearLayout
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:orientation="vertical"
tools:context=".core.download.SingleTaskActivity"
>
<include layout="@layout/layout_bar"/>
<com.arialyy.simple.widget.SvgTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="16dp"
bind:iconClickListener="@{() -> viewModel.chooseUrl()}"
bind:svg_text_view_icon="@drawable/ic_modify"
bind:text="@{@string/url(url)}"
/>
<com.arialyy.simple.widget.SvgTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="8dp"
bind:iconClickListener="@{() -> viewModel.chooseFilePath()}"
bind:svg_text_view_icon="@drawable/ic_choose_file"
bind:text="@{@string/file_path(filePath)}"
/>
<include
layout="@layout/layout_content_single"
bind:fileSize="@{fileSize}"
bind:progress="@{progress}"
bind:speed="@{speed}"
bind:stateStr="@{stateStr}"
/>
<com.arialyy.simple.widget.CodeView
android:id="@+id/code_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>
</layout>

View File

@@ -0,0 +1,81 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<variable
name="currentPath"
type="String"
/>
<import type="android.text.Html"/>
</data>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:orientation="vertical"
>
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/background_color"
android:maxHeight="400dp"
android:paddingBottom="8dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="8dp"
android:text="@string/choose_dir"
android:textColor="@android:color/black"
android:textSize="22sp"
/>
<TextView
android:id="@+id/current_path"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/title"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="4dp"
android:ellipsize="marquee"
android:singleLine="true"
android:text="@{Html.fromHtml(@string/current_path(currentPath))}"
/>
<TextView
android:id="@+id/up"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/current_path"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:gravity="center_vertical"
android:text=".."
android:textColor="@color/text_black"
android:textSize="18sp"
android:textStyle="bold"
/>
<android.support.v7.widget.RecyclerView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/enter"
android:layout_below="@+id/up"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="4dp"
/>
<Button
android:id="@+id/enter"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="@string/choose_current_dir"
style="?buttonBarButtonStyle"
/>
</RelativeLayout>
</layout>

View File

@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:bind="http://schemas.android.com/apk/res-auto"
>
<data>
<variable
name="title"
type="String"
/>
<variable
name="name"
type="String"
/>
<variable
name="dir"
type="String"
/>
<variable
name="viewModel"
type="com.arialyy.simple.common.ModifyPathDialog"
/>
</data>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:orientation="vertical"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/background_color"
android:gravity="center|left"
android:maxHeight="400dp"
android:paddingBottom="8dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="8dp"
android:text="@{title}"
android:textColor="@android:color/black"
android:textSize="22sp"
/>
<com.arialyy.simple.widget.SvgTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="16dp"
bind:iconClickListener="@{() -> viewModel.chooseDir()}"
bind:svg_text_view_icon="@drawable/ic_modify"
bind:text="@{@string/dir_path(dir)}"
/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="8dp"
>
<TextView
android:id="@+id/dir_hint"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="@string/name"
android:textColor="@color/text_black"
android:textSize="@dimen/text_size_normal"
android:textStyle="bold"
/>
<EditText
android:id="@+id/edit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginBottom="15dp"
android:layout_marginLeft="8dp"
android:layout_toRightOf="@+id/dir_hint"
android:background="@android:color/transparent"
android:hint="@string/file_name_hint"
android:lineSpacingMultiplier="1.2"
android:text="@={name}"
android:textColor="@color/text_black"
android:textSize="@dimen/text_size_normal"
/>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<Button
android:id="@+id/cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/cancel"
style="?buttonBarButtonStyle"
/>
<Button
android:id="@+id/enter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/enter"
style="?buttonBarButtonStyle"
/>
</LinearLayout>
</LinearLayout>
</layout>

View File

@@ -41,8 +41,9 @@
android:layout_marginRight="16dp"
android:layout_marginTop="16dp"
android:background="@android:color/transparent"
android:hint="@string/url_hint"
android:lineSpacingMultiplier="1.2"
android:text="@{text}"
android:text="@={text}"
android:textColor="#000"
android:textSize="16sp"
/>

View File

@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="@dimen/bar_height"
android:background="@drawable/item_bg"
android:orientation="vertical"
>
<android.support.v7.widget.AppCompatImageView
android:id="@+id/icon"
android:layout_width="@dimen/icon_size"
android:layout_height="@dimen/icon_size"
android:layout_centerVertical="true"
app:srcCompat="@drawable/ic_dir"
/>
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="8dp"
android:layout_toRightOf="@+id/icon"
android:ellipsize="marquee"
android:singleLine="true"
android:textColor="@color/text_black"
android:textSize="@dimen/text_size_normal"
/>
</RelativeLayout>

View File

@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
>
<TextView
android:id="@+id/hint"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="@string/code_simple"
android:textColor="@color/text_black"
android:textSize="@dimen/text_size_normal"
android:textStyle="bold"
/>
<android.support.v7.widget.AppCompatImageView
android:id="@+id/full_screen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
app:srcCompat="@drawable/ic_full_screen"
/>
</RelativeLayout>
<com.pddstudio.highlightjs.HighlightJsView
android:id="@+id/js_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>

View File

@@ -96,12 +96,5 @@
/>
</LinearLayout>
<TextView
android:id="@+id/speed_hint"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/handle_bar"
/>
</RelativeLayout>
</layout>

View File

@@ -6,6 +6,7 @@
<color name="icon_color">#FF4081</color>
<color name="black">#2B2B2B</color>
<color name="text_black">#2B2B2B</color>
<color name="icon_black">#2B2B2B</color>
<color name="bg_grey">#efefef</color>
<color name="bg_line">#597F96</color>
</resources>

View File

@@ -14,5 +14,6 @@
<dimen name="text_size_biggest">18sp</dimen>
<dimen name="icon_size">24dp</dimen>
<dimen name="bar_height">48dp</dimen>
</resources>

View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="code_ftp_upload">
Aria.upload(this)
.loadFtp("/mnt/sdcard/gggg.apk") //上传文件路径
.setUploadUrl(URL) //上传的ftp服务器地址
.login("lao", "123456")
.start();
</string>
</resources>

View File

@@ -2,9 +2,9 @@
<string name="app_name">Aria</string>
<string name="action_settings">Settings</string>
<string name="url">URL: %1$s</string>
<string name="file_name">文件名: %1$s</string>
<string name="file_path">文件路径: %1$s</string>
<string name="url"><![CDATA[<b><font color=#2B2B2B>URL:</b>]]> %1$s</string>
<string name="file_name"><![CDATA[<b><font color=#2B2B2B>NAME:</b>]]> %1$s</string>
<string name="file_path"><![CDATA[<b><font color=#2B2B2B>PATH:</b>]]> %1$s</string>
<string name="enter">确认</string>
<string name="cancel">取消</string>
<string name="modify_url_dialog_title">修改URL</string>
@@ -12,6 +12,21 @@
<string name="start">开始</string>
<string name="resume">恢复</string>
<string name="delete">删除</string>
<string name="code_simple">代码示例:</string>
<string name="download_success">下载完成</string>
<string name="download_fail">下载失败</string>
<string name="re_start">重新开始</string>
<string name="choose_current_dir">选择当前文件夹</string>
<string name="choose_dir">选择文件夹</string>
<string name="current_path"><![CDATA[<b><font color=#2B2B2B>PATH:</b>]]> %1$s</string>
<string name="dir_path"><![CDATA[<b><font color=#2B2B2B>DIR:</b>]]> %1$s</string>
<string name="file_name_hint">文件名</string>
<string name="url_hint">url</string>
<string name="name">NAME: </string>
<string name="modify_file_path">修改文件路径</string>
<string name="error_file_name_null">文件名为空</string>
<string-array name="main_items">
<item>http 下载</item>

View File

@@ -23,9 +23,9 @@
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light"/>
<style name="dialogStyle" parent="@android:style/Animation.Dialog">
<item name="@android:windowEnterAnimation">@anim/dialog_enter</item>
<item name="android:windowEnterAnimation">@anim/dialog_enter</item>
<!-- 进入时的动画 -->
<item name="@android:windowExitAnimation">@anim/dialog_exit</item>
<item name="android:windowExitAnimation">@anim/dialog_exit</item>
<!-- 退出时的动画 -->
</style>
@@ -38,5 +38,10 @@
<item name="android:scrollHorizontally">true</item>
</style>
<style name="FullScreen" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
</style>
</resources>