下载工具死锁修复
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
apply plugin: 'com.android.application'
|
||||
|
||||
android {
|
||||
compileSdkVersion 'Google Inc.:Google APIs:23'
|
||||
compileSdkVersion 23
|
||||
buildToolsVersion "23.0.2"
|
||||
|
||||
defaultConfig {
|
||||
|
@ -7,7 +7,7 @@ import android.test.ApplicationTestCase;
|
||||
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
|
||||
*/
|
||||
public class ApplicationTest extends ApplicationTestCase<Application> {
|
||||
public ApplicationTest() {
|
||||
super(Application.class);
|
||||
}
|
||||
public ApplicationTest() {
|
||||
super(Application.class);
|
||||
}
|
||||
}
|
@ -1,29 +1,32 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.arialyy.simple">
|
||||
package="com.arialyy.simple">
|
||||
|
||||
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
|
||||
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
|
||||
|
||||
<application
|
||||
android:name=".base.BaseApplication"
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
<application
|
||||
android:name=".base.BaseApplication"
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme">
|
||||
<!--android:name=".activity.SingleTaskActivity"-->
|
||||
<activity
|
||||
android:name=".activity.MainActivity"
|
||||
android:label="@string/app_name"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme">
|
||||
<!--android:name=".activity.SimpleTestActivity"-->
|
||||
<activity
|
||||
android:name=".activity.MainActivity"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/AppTheme.NoActionBar">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
android:theme="@style/AppTheme.NoActionBar">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity android:name=".activity.SingleTaskActivity"/>
|
||||
<activity android:name=".activity.MultiTaskActivity"/>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
|
@ -1,90 +1,38 @@
|
||||
package com.arialyy.simple.activity;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
|
||||
import com.arialyy.downloadutil.core.DownloadManager;
|
||||
import com.arialyy.downloadutil.entity.DownloadEntity;
|
||||
import com.arialyy.frame.util.show.L;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.View;
|
||||
import butterknife.Bind;
|
||||
import com.arialyy.simple.R;
|
||||
import com.arialyy.simple.adapter.DownloadAdapter;
|
||||
import com.arialyy.simple.base.BaseActivity;
|
||||
import com.arialyy.simple.databinding.ActivityMainBinding;
|
||||
import com.arialyy.simple.module.DownloadModule;
|
||||
|
||||
import butterknife.Bind;
|
||||
|
||||
/**
|
||||
* Created by Lyy on 2016/9/27.
|
||||
* Created by Lyy on 2016/10/13.
|
||||
*/
|
||||
public class MainActivity extends BaseActivity<ActivityMainBinding> {
|
||||
@Bind(R.id.list) RecyclerView mList;
|
||||
DownloadAdapter mAdapter;
|
||||
@Bind(R.id.toolbar) Toolbar mBar;
|
||||
|
||||
@Override protected int setLayoutId() {
|
||||
return R.layout.activity_main;
|
||||
}
|
||||
|
||||
@Override protected void init(Bundle savedInstanceState) {
|
||||
super.init(savedInstanceState);
|
||||
mAdapter = new DownloadAdapter(this, getModule(DownloadModule.class).getDownloadData());
|
||||
mList.setLayoutManager(new LinearLayoutManager(this));
|
||||
mList.setAdapter(mAdapter);
|
||||
}
|
||||
|
||||
|
||||
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
||||
long len = 0;
|
||||
|
||||
@Override public void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
DownloadEntity entity = intent.getParcelableExtra(DownloadManager.ENTITY);
|
||||
switch (action) {
|
||||
case DownloadManager.ACTION_PRE:
|
||||
len = entity.getFileSize();
|
||||
L.d(TAG, "download pre");
|
||||
break;
|
||||
case DownloadManager.ACTION_START:
|
||||
L.d(TAG, "download start");
|
||||
break;
|
||||
case DownloadManager.ACTION_RESUME:
|
||||
L.d(TAG, "download resume");
|
||||
long location = intent.getLongExtra(DownloadManager.CURRENT_LOCATION, 1);
|
||||
mAdapter.updateState(entity);
|
||||
break;
|
||||
case DownloadManager.ACTION_RUNNING:
|
||||
long current = intent.getLongExtra(DownloadManager.CURRENT_LOCATION, 0);
|
||||
mAdapter.setProgress(entity.getDownloadUrl(), current);
|
||||
break;
|
||||
case DownloadManager.ACTION_STOP:
|
||||
L.d(TAG, "download stop");
|
||||
mAdapter.updateState(entity);
|
||||
break;
|
||||
case DownloadManager.ACTION_COMPLETE:
|
||||
L.d(TAG, "download complete");
|
||||
mAdapter.updateState(entity);
|
||||
break;
|
||||
case DownloadManager.ACTION_CANCEL:
|
||||
L.d(TAG, "download cancel");
|
||||
break;
|
||||
case DownloadManager.ACTION_FAIL:
|
||||
L.d(TAG, "download fail");
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Override protected void onResume() {
|
||||
super.onResume();
|
||||
registerReceiver(mReceiver, getModule(DownloadModule.class).getDownloadFilter());
|
||||
}
|
||||
|
||||
@Override protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
unregisterReceiver(mReceiver);
|
||||
@Override protected int setLayoutId() {
|
||||
return R.layout.activity_main;
|
||||
}
|
||||
|
||||
@Override protected void init(Bundle savedInstanceState) {
|
||||
super.init(savedInstanceState);
|
||||
setSupportActionBar(mBar);
|
||||
mBar.setTitle("多线程多任务下载");
|
||||
}
|
||||
|
||||
public void onClick(View view) {
|
||||
switch (view.getId()) {
|
||||
case R.id.single_task:
|
||||
startActivity(new Intent(this, SingleTaskActivity.class));
|
||||
break;
|
||||
case R.id.multi_task:
|
||||
startActivity(new Intent(this, MultiTaskActivity.class));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,91 @@
|
||||
package com.arialyy.simple.activity;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import butterknife.Bind;
|
||||
import com.arialyy.downloadutil.core.DownloadManager;
|
||||
import com.arialyy.downloadutil.entity.DownloadEntity;
|
||||
import com.arialyy.frame.util.show.L;
|
||||
import com.arialyy.simple.R;
|
||||
import com.arialyy.simple.adapter.DownloadAdapter;
|
||||
import com.arialyy.simple.base.BaseActivity;
|
||||
import com.arialyy.simple.databinding.ActivityMultiBinding;
|
||||
import com.arialyy.simple.module.DownloadModule;
|
||||
|
||||
/**
|
||||
* Created by Lyy on 2016/9/27.
|
||||
*/
|
||||
public class MultiTaskActivity extends BaseActivity<ActivityMultiBinding> {
|
||||
@Bind(R.id.list) RecyclerView mList;
|
||||
@Bind(R.id.toolbar) Toolbar mBar;
|
||||
DownloadAdapter mAdapter;
|
||||
|
||||
@Override protected int setLayoutId() {
|
||||
return R.layout.activity_multi;
|
||||
}
|
||||
|
||||
@Override protected void init(Bundle savedInstanceState) {
|
||||
super.init(savedInstanceState);
|
||||
setSupportActionBar(mBar);
|
||||
mBar.setTitle("多任务下载");
|
||||
mAdapter = new DownloadAdapter(this, getModule(DownloadModule.class).getDownloadData());
|
||||
mList.setLayoutManager(new LinearLayoutManager(this));
|
||||
mList.setAdapter(mAdapter);
|
||||
}
|
||||
|
||||
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
||||
long len = 0;
|
||||
|
||||
@Override public void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
DownloadEntity entity = intent.getParcelableExtra(DownloadManager.ENTITY);
|
||||
switch (action) {
|
||||
case DownloadManager.ACTION_PRE:
|
||||
len = entity.getFileSize();
|
||||
L.d(TAG, "download pre");
|
||||
break;
|
||||
case DownloadManager.ACTION_START:
|
||||
L.d(TAG, "download start");
|
||||
break;
|
||||
case DownloadManager.ACTION_RESUME:
|
||||
L.d(TAG, "download resume");
|
||||
long location = intent.getLongExtra(DownloadManager.CURRENT_LOCATION, 1);
|
||||
mAdapter.updateState(entity);
|
||||
break;
|
||||
case DownloadManager.ACTION_RUNNING:
|
||||
long current = intent.getLongExtra(DownloadManager.CURRENT_LOCATION, 0);
|
||||
mAdapter.setProgress(entity.getDownloadUrl(), current);
|
||||
break;
|
||||
case DownloadManager.ACTION_STOP:
|
||||
L.d(TAG, "download stop");
|
||||
mAdapter.updateState(entity);
|
||||
break;
|
||||
case DownloadManager.ACTION_COMPLETE:
|
||||
L.d(TAG, "download complete");
|
||||
mAdapter.updateState(entity);
|
||||
break;
|
||||
case DownloadManager.ACTION_CANCEL:
|
||||
L.d(TAG, "download cancel");
|
||||
break;
|
||||
case DownloadManager.ACTION_FAIL:
|
||||
L.d(TAG, "download fail");
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Override protected void onResume() {
|
||||
super.onResume();
|
||||
registerReceiver(mReceiver, getModule(DownloadModule.class).getDownloadFilter());
|
||||
}
|
||||
|
||||
@Override protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
unregisterReceiver(mReceiver);
|
||||
}
|
||||
}
|
@ -1,248 +0,0 @@
|
||||
package com.arialyy.simple.activity;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.arialyy.downloadutil.core.DownloadManager;
|
||||
import com.arialyy.downloadutil.core.command.CommandFactory;
|
||||
import com.arialyy.downloadutil.core.command.IDownloadCommand;
|
||||
import com.arialyy.downloadutil.entity.DownloadEntity;
|
||||
import com.arialyy.downloadutil.orm.DbEntity;
|
||||
import com.arialyy.downloadutil.util.Util;
|
||||
import com.arialyy.frame.util.show.L;
|
||||
import com.arialyy.simple.R;
|
||||
import com.arialyy.simple.base.BaseActivity;
|
||||
import com.arialyy.simple.databinding.ActivitySimpleBinding;
|
||||
import com.arialyy.simple.module.DownloadModule;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.Bind;
|
||||
|
||||
public class SimpleTestActivity extends BaseActivity<ActivitySimpleBinding> {
|
||||
private static final int DOWNLOAD_PRE = 0x01;
|
||||
private static final int DOWNLOAD_STOP = 0x02;
|
||||
private static final int DOWNLOAD_FAILE = 0x03;
|
||||
private static final int DOWNLOAD_CANCEL = 0x04;
|
||||
private static final int DOWNLOAD_RESUME = 0x05;
|
||||
private static final int DOWNLOAD_COMPLETE = 0x06;
|
||||
private ProgressBar mPb;
|
||||
private String mDownloadUrl = "http://static.gaoshouyou.com/d/12/0d/7f120f50c80d2e7b8c4ba24ece4f9cdd.apk";
|
||||
private Button mStart, mStop, mCancel;
|
||||
private TextView mSize;
|
||||
@Bind(R.id.toolbar) Toolbar toolbar;
|
||||
private CommandFactory mFactory;
|
||||
private DownloadManager mManager;
|
||||
private DownloadEntity mEntity;
|
||||
|
||||
private Handler mUpdateHandler = new Handler() {
|
||||
@Override public void handleMessage(Message msg) {
|
||||
super.handleMessage(msg);
|
||||
switch (msg.what) {
|
||||
case DOWNLOAD_PRE:
|
||||
mSize.setText(Util.formatFileSize((Long) msg.obj));
|
||||
setBtState(false);
|
||||
break;
|
||||
case DOWNLOAD_FAILE:
|
||||
Toast.makeText(SimpleTestActivity.this, "下载失败", Toast.LENGTH_SHORT).show();
|
||||
setBtState(true);
|
||||
break;
|
||||
case DOWNLOAD_STOP:
|
||||
Toast.makeText(SimpleTestActivity.this, "暂停下载", Toast.LENGTH_SHORT).show();
|
||||
mStart.setText("恢复");
|
||||
setBtState(true);
|
||||
break;
|
||||
case DOWNLOAD_CANCEL:
|
||||
mPb.setProgress(0);
|
||||
Toast.makeText(SimpleTestActivity.this, "取消下载", Toast.LENGTH_SHORT).show();
|
||||
mStart.setText("开始");
|
||||
setBtState(true);
|
||||
break;
|
||||
case DOWNLOAD_RESUME:
|
||||
Toast.makeText(SimpleTestActivity.this,
|
||||
"恢复下载,恢复位置 ==> " + Util.formatFileSize((Long) msg.obj),
|
||||
Toast.LENGTH_SHORT).show();
|
||||
setBtState(false);
|
||||
break;
|
||||
case DOWNLOAD_COMPLETE:
|
||||
Toast.makeText(SimpleTestActivity.this, "下载完成", Toast.LENGTH_SHORT).show();
|
||||
mStart.setText("重新开始?");
|
||||
mCancel.setEnabled(false);
|
||||
setBtState(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 设置start 和 stop 按钮状态
|
||||
*
|
||||
* @param state
|
||||
*/
|
||||
private void setBtState(boolean state) {
|
||||
mStart.setEnabled(state);
|
||||
mStop.setEnabled(!state);
|
||||
}
|
||||
|
||||
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
||||
long len = 0;
|
||||
|
||||
@Override public void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
switch (action) {
|
||||
case DownloadManager.ACTION_PRE:
|
||||
DownloadEntity entity = intent.getParcelableExtra(DownloadManager.ENTITY);
|
||||
len = entity.getFileSize();
|
||||
L.d(TAG, "download pre");
|
||||
mUpdateHandler.obtainMessage(DOWNLOAD_PRE, len).sendToTarget();
|
||||
break;
|
||||
case DownloadManager.ACTION_START:
|
||||
L.d(TAG, "download start");
|
||||
break;
|
||||
case DownloadManager.ACTION_RESUME:
|
||||
L.d(TAG, "download resume");
|
||||
long location = intent.getLongExtra(DownloadManager.CURRENT_LOCATION, 1);
|
||||
mUpdateHandler.obtainMessage(DOWNLOAD_RESUME, location).sendToTarget();
|
||||
break;
|
||||
case DownloadManager.ACTION_RUNNING:
|
||||
long current = intent.getLongExtra(DownloadManager.CURRENT_LOCATION, 0);
|
||||
if (len == 0) {
|
||||
mPb.setProgress(0);
|
||||
} else {
|
||||
mPb.setProgress((int) ((current * 100) / len));
|
||||
}
|
||||
break;
|
||||
case DownloadManager.ACTION_STOP:
|
||||
L.d(TAG, "download stop");
|
||||
mUpdateHandler.sendEmptyMessage(DOWNLOAD_STOP);
|
||||
break;
|
||||
case DownloadManager.ACTION_COMPLETE:
|
||||
mUpdateHandler.sendEmptyMessage(DOWNLOAD_COMPLETE);
|
||||
break;
|
||||
case DownloadManager.ACTION_CANCEL:
|
||||
mUpdateHandler.sendEmptyMessage(DOWNLOAD_CANCEL);
|
||||
break;
|
||||
case DownloadManager.ACTION_FAIL:
|
||||
mUpdateHandler.sendEmptyMessage(DOWNLOAD_FAILE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Override protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
init();
|
||||
}
|
||||
|
||||
@Override protected void onResume() {
|
||||
super.onResume();
|
||||
registerReceiver(mReceiver, getModule(DownloadModule.class).getDownloadFilter());
|
||||
}
|
||||
|
||||
@Override protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
unregisterReceiver(mReceiver);
|
||||
}
|
||||
|
||||
@Override protected int setLayoutId() {
|
||||
return R.layout.activity_simple;
|
||||
}
|
||||
|
||||
@Override protected void init(Bundle savedInstanceState) {
|
||||
super.init(savedInstanceState);
|
||||
setSupportActionBar(toolbar);
|
||||
init();
|
||||
|
||||
}
|
||||
|
||||
private void init() {
|
||||
mPb = (ProgressBar) findViewById(R.id.progressBar);
|
||||
mStart = (Button) findViewById(R.id.start);
|
||||
mStop = (Button) findViewById(R.id.stop);
|
||||
mCancel = (Button) findViewById(R.id.cancel);
|
||||
mSize = (TextView) findViewById(R.id.size);
|
||||
mFactory = CommandFactory.getInstance();
|
||||
mManager = DownloadManager.getInstance();
|
||||
mEntity = DbEntity.findData(DownloadEntity.class, new String[]{"downloadUrl"},
|
||||
new String[]{mDownloadUrl});
|
||||
if (mEntity != null) {
|
||||
mPb.setProgress((int) ((mEntity.getCurrentProgress() * 100) / mEntity.getFileSize()));
|
||||
mSize.setText(Util.formatFileSize(mEntity.getFileSize()));
|
||||
if (mEntity.getState() == DownloadEntity.STATE_DOWNLOAD_ING) {
|
||||
setBtState(false);
|
||||
} else if (mEntity.isDownloadComplete()) {
|
||||
mStart.setText("重新开始?");
|
||||
setBtState(true);
|
||||
}
|
||||
} else {
|
||||
mEntity = new DownloadEntity();
|
||||
}
|
||||
}
|
||||
|
||||
public void onClick(View view) {
|
||||
switch (view.getId()) {
|
||||
case R.id.start:
|
||||
start();
|
||||
// if (PermissionManager.getInstance()
|
||||
// .checkPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
|
||||
// start();
|
||||
// } else {
|
||||
// PermissionManager.getInstance()
|
||||
// .requestPermission(this, new OnPermissionCallback() {
|
||||
// @Override public void onSuccess(String... permissions) {
|
||||
// start();
|
||||
// }
|
||||
//
|
||||
// @Override public void onFail(String... permissions) {
|
||||
//
|
||||
// }
|
||||
// }, Manifest.permission.WRITE_EXTERNAL_STORAGE);
|
||||
// }
|
||||
break;
|
||||
case R.id.stop:
|
||||
stop();
|
||||
break;
|
||||
case R.id.cancel:
|
||||
cancel();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void start() {
|
||||
mEntity.setFileName("test.apk");
|
||||
mEntity.setDownloadUrl(mDownloadUrl);
|
||||
mEntity.setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/test.apk");
|
||||
List<IDownloadCommand> commands = new ArrayList<>();
|
||||
IDownloadCommand addCommand = mFactory.createCommand(this, mEntity,
|
||||
CommandFactory.TASK_CREATE);
|
||||
IDownloadCommand startCommand = mFactory.createCommand(this, mEntity,
|
||||
CommandFactory.TASK_START);
|
||||
commands.add(addCommand);
|
||||
commands.add(startCommand);
|
||||
mManager.setCommands(commands).exe();
|
||||
}
|
||||
|
||||
private void stop() {
|
||||
IDownloadCommand stopCommand = mFactory.createCommand(this, mEntity,
|
||||
CommandFactory.TASK_STOP);
|
||||
mManager.setCommand(stopCommand).exe();
|
||||
}
|
||||
|
||||
private void cancel() {
|
||||
IDownloadCommand cancelCommand = mFactory.createCommand(this, mEntity,
|
||||
CommandFactory.TASK_CANCEL);
|
||||
mManager.setCommand(cancelCommand).exe();
|
||||
}
|
||||
}
|
@ -0,0 +1,241 @@
|
||||
package com.arialyy.simple.activity;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import butterknife.Bind;
|
||||
import com.arialyy.downloadutil.core.DownloadManager;
|
||||
import com.arialyy.downloadutil.core.command.CommandFactory;
|
||||
import com.arialyy.downloadutil.core.command.IDownloadCommand;
|
||||
import com.arialyy.downloadutil.entity.DownloadEntity;
|
||||
import com.arialyy.downloadutil.orm.DbEntity;
|
||||
import com.arialyy.downloadutil.util.Util;
|
||||
import com.arialyy.frame.util.show.L;
|
||||
import com.arialyy.simple.R;
|
||||
import com.arialyy.simple.base.BaseActivity;
|
||||
import com.arialyy.simple.databinding.ActivitySingleBinding;
|
||||
import com.arialyy.simple.module.DownloadModule;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
||||
private static final int DOWNLOAD_PRE = 0x01;
|
||||
private static final int DOWNLOAD_STOP = 0x02;
|
||||
private static final int DOWNLOAD_FAILE = 0x03;
|
||||
private static final int DOWNLOAD_CANCEL = 0x04;
|
||||
private static final int DOWNLOAD_RESUME = 0x05;
|
||||
private static final int DOWNLOAD_COMPLETE = 0x06;
|
||||
private ProgressBar mPb;
|
||||
private String mDownloadUrl =
|
||||
"http://static.gaoshouyou.com/d/12/0d/7f120f50c80d2e7b8c4ba24ece4f9cdd.apk";
|
||||
private Button mStart, mStop, mCancel;
|
||||
private TextView mSize;
|
||||
@Bind(R.id.toolbar) Toolbar toolbar;
|
||||
private CommandFactory mFactory;
|
||||
private DownloadManager mManager;
|
||||
private DownloadEntity mEntity;
|
||||
|
||||
private Handler mUpdateHandler = new Handler() {
|
||||
@Override public void handleMessage(Message msg) {
|
||||
super.handleMessage(msg);
|
||||
switch (msg.what) {
|
||||
case DOWNLOAD_PRE:
|
||||
mSize.setText(Util.formatFileSize((Long) msg.obj));
|
||||
setBtState(false);
|
||||
break;
|
||||
case DOWNLOAD_FAILE:
|
||||
Toast.makeText(SingleTaskActivity.this, "下载失败", Toast.LENGTH_SHORT).show();
|
||||
setBtState(true);
|
||||
break;
|
||||
case DOWNLOAD_STOP:
|
||||
Toast.makeText(SingleTaskActivity.this, "暂停下载", Toast.LENGTH_SHORT).show();
|
||||
mStart.setText("恢复");
|
||||
setBtState(true);
|
||||
break;
|
||||
case DOWNLOAD_CANCEL:
|
||||
mPb.setProgress(0);
|
||||
Toast.makeText(SingleTaskActivity.this, "取消下载", Toast.LENGTH_SHORT).show();
|
||||
mStart.setText("开始");
|
||||
setBtState(true);
|
||||
break;
|
||||
case DOWNLOAD_RESUME:
|
||||
Toast.makeText(SingleTaskActivity.this,
|
||||
"恢复下载,恢复位置 ==> " + Util.formatFileSize((Long) msg.obj), Toast.LENGTH_SHORT).show();
|
||||
setBtState(false);
|
||||
break;
|
||||
case DOWNLOAD_COMPLETE:
|
||||
Toast.makeText(SingleTaskActivity.this, "下载完成", Toast.LENGTH_SHORT).show();
|
||||
mStart.setText("重新开始?");
|
||||
mCancel.setEnabled(false);
|
||||
setBtState(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 设置start 和 stop 按钮状态
|
||||
*/
|
||||
private void setBtState(boolean state) {
|
||||
mStart.setEnabled(state);
|
||||
mStop.setEnabled(!state);
|
||||
}
|
||||
|
||||
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
||||
long len = 0;
|
||||
|
||||
@Override public void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
switch (action) {
|
||||
case DownloadManager.ACTION_PRE:
|
||||
DownloadEntity entity = intent.getParcelableExtra(DownloadManager.ENTITY);
|
||||
len = entity.getFileSize();
|
||||
L.d(TAG, "download pre");
|
||||
mUpdateHandler.obtainMessage(DOWNLOAD_PRE, len).sendToTarget();
|
||||
break;
|
||||
case DownloadManager.ACTION_START:
|
||||
L.d(TAG, "download start");
|
||||
break;
|
||||
case DownloadManager.ACTION_RESUME:
|
||||
L.d(TAG, "download resume");
|
||||
long location = intent.getLongExtra(DownloadManager.CURRENT_LOCATION, 1);
|
||||
mUpdateHandler.obtainMessage(DOWNLOAD_RESUME, location).sendToTarget();
|
||||
break;
|
||||
case DownloadManager.ACTION_RUNNING:
|
||||
long current = intent.getLongExtra(DownloadManager.CURRENT_LOCATION, 0);
|
||||
if (len == 0) {
|
||||
mPb.setProgress(0);
|
||||
} else {
|
||||
mPb.setProgress((int) ((current * 100) / len));
|
||||
}
|
||||
break;
|
||||
case DownloadManager.ACTION_STOP:
|
||||
L.d(TAG, "download stop");
|
||||
mUpdateHandler.sendEmptyMessage(DOWNLOAD_STOP);
|
||||
break;
|
||||
case DownloadManager.ACTION_COMPLETE:
|
||||
mUpdateHandler.sendEmptyMessage(DOWNLOAD_COMPLETE);
|
||||
break;
|
||||
case DownloadManager.ACTION_CANCEL:
|
||||
mUpdateHandler.sendEmptyMessage(DOWNLOAD_CANCEL);
|
||||
break;
|
||||
case DownloadManager.ACTION_FAIL:
|
||||
mUpdateHandler.sendEmptyMessage(DOWNLOAD_FAILE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Override protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
init();
|
||||
}
|
||||
|
||||
@Override protected void onResume() {
|
||||
super.onResume();
|
||||
registerReceiver(mReceiver, getModule(DownloadModule.class).getDownloadFilter());
|
||||
}
|
||||
|
||||
@Override protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
unregisterReceiver(mReceiver);
|
||||
}
|
||||
|
||||
@Override protected int setLayoutId() {
|
||||
return R.layout.activity_single;
|
||||
}
|
||||
|
||||
@Override protected void init(Bundle savedInstanceState) {
|
||||
super.init(savedInstanceState);
|
||||
setSupportActionBar(toolbar);
|
||||
toolbar.setTitle("单任务下载");
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
mPb = (ProgressBar) findViewById(R.id.progressBar);
|
||||
mStart = (Button) findViewById(R.id.start);
|
||||
mStop = (Button) findViewById(R.id.stop);
|
||||
mCancel = (Button) findViewById(R.id.cancel);
|
||||
mSize = (TextView) findViewById(R.id.size);
|
||||
mFactory = CommandFactory.getInstance();
|
||||
mManager = DownloadManager.getInstance();
|
||||
mEntity = DbEntity.findData(DownloadEntity.class, new String[] { "downloadUrl" },
|
||||
new String[] { mDownloadUrl });
|
||||
if (mEntity != null) {
|
||||
mPb.setProgress((int) ((mEntity.getCurrentProgress() * 100) / mEntity.getFileSize()));
|
||||
mSize.setText(Util.formatFileSize(mEntity.getFileSize()));
|
||||
if (mEntity.getState() == DownloadEntity.STATE_DOWNLOAD_ING) {
|
||||
setBtState(false);
|
||||
} else if (mEntity.isDownloadComplete()) {
|
||||
mStart.setText("重新开始?");
|
||||
setBtState(true);
|
||||
}
|
||||
} else {
|
||||
mEntity = new DownloadEntity();
|
||||
}
|
||||
}
|
||||
|
||||
public void onClick(View view) {
|
||||
switch (view.getId()) {
|
||||
case R.id.start:
|
||||
start();
|
||||
// if (PermissionManager.getInstance()
|
||||
// .checkPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
|
||||
// start();
|
||||
// } else {
|
||||
// PermissionManager.getInstance()
|
||||
// .requestPermission(this, new OnPermissionCallback() {
|
||||
// @Override public void onSuccess(String... permissions) {
|
||||
// start();
|
||||
// }
|
||||
//
|
||||
// @Override public void onFail(String... permissions) {
|
||||
//
|
||||
// }
|
||||
// }, Manifest.permission.WRITE_EXTERNAL_STORAGE);
|
||||
// }
|
||||
break;
|
||||
case R.id.stop:
|
||||
stop();
|
||||
break;
|
||||
case R.id.cancel:
|
||||
cancel();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void start() {
|
||||
mEntity.setFileName("test.apk");
|
||||
mEntity.setDownloadUrl(mDownloadUrl);
|
||||
mEntity.setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/test.apk");
|
||||
List<IDownloadCommand> commands = new ArrayList<>();
|
||||
IDownloadCommand addCommand = mFactory.createCommand(this, mEntity, CommandFactory.TASK_CREATE);
|
||||
IDownloadCommand startCommand =
|
||||
mFactory.createCommand(this, mEntity, CommandFactory.TASK_START);
|
||||
commands.add(addCommand);
|
||||
commands.add(startCommand);
|
||||
mManager.setCommands(commands).exe();
|
||||
}
|
||||
|
||||
private void stop() {
|
||||
IDownloadCommand stopCommand = mFactory.createCommand(this, mEntity, CommandFactory.TASK_STOP);
|
||||
mManager.setCommand(stopCommand).exe();
|
||||
}
|
||||
|
||||
private void cancel() {
|
||||
IDownloadCommand cancelCommand =
|
||||
mFactory.createCommand(this, mEntity, CommandFactory.TASK_CANCEL);
|
||||
mManager.setCommand(cancelCommand).exe();
|
||||
}
|
||||
}
|
@ -4,7 +4,7 @@ import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
|
||||
import butterknife.Bind;
|
||||
import com.arialyy.absadapter.common.AbsHolder;
|
||||
import com.arialyy.absadapter.recycler_view.AbsRVAdapter;
|
||||
import com.arialyy.downloadutil.core.DownloadManager;
|
||||
@ -14,165 +14,162 @@ import com.arialyy.downloadutil.entity.DownloadEntity;
|
||||
import com.arialyy.frame.util.show.L;
|
||||
import com.arialyy.simple.R;
|
||||
import com.arialyy.simple.widget.HorizontalProgressBarWithNumber;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import butterknife.Bind;
|
||||
|
||||
/**
|
||||
* Created by Lyy on 2016/9/27.
|
||||
* 下载列表适配器
|
||||
*/
|
||||
public class DownloadAdapter extends AbsRVAdapter<DownloadEntity, DownloadAdapter.MyHolder> {
|
||||
private static final String TAG = "DownloadAdapter";
|
||||
private DownloadManager mManager;
|
||||
private CommandFactory mFactory;
|
||||
private Map<String, Long> mProgress = new HashMap<>();
|
||||
private Map<String, Integer> mPositions = new HashMap<>();
|
||||
private static final String TAG = "DownloadAdapter";
|
||||
private DownloadManager mManager;
|
||||
private CommandFactory mFactory;
|
||||
private Map<String, Long> mProgress = new HashMap<>();
|
||||
private Map<String, Integer> mPositions = new HashMap<>();
|
||||
|
||||
public DownloadAdapter(Context context, List<DownloadEntity> data) {
|
||||
super(context, data);
|
||||
int i = 0;
|
||||
for (DownloadEntity entity : data) {
|
||||
mProgress.put(entity.getDownloadUrl(), entity.getCurrentProgress());
|
||||
mPositions.put(entity.getDownloadUrl(), i);
|
||||
i++;
|
||||
}
|
||||
mFactory = CommandFactory.getInstance();
|
||||
mManager = DownloadManager.getInstance();
|
||||
public DownloadAdapter(Context context, List<DownloadEntity> data) {
|
||||
super(context, data);
|
||||
int i = 0;
|
||||
for (DownloadEntity entity : data) {
|
||||
mProgress.put(entity.getDownloadUrl(), entity.getCurrentProgress());
|
||||
mPositions.put(entity.getDownloadUrl(), i);
|
||||
i++;
|
||||
}
|
||||
mFactory = CommandFactory.getInstance();
|
||||
mManager = DownloadManager.getInstance();
|
||||
}
|
||||
|
||||
@Override protected MyHolder getViewHolder(View convertView, int viewType) {
|
||||
return new MyHolder(convertView);
|
||||
}
|
||||
|
||||
@Override protected int setLayoutId(int type) {
|
||||
return R.layout.item_download;
|
||||
}
|
||||
|
||||
public synchronized void updateState(DownloadEntity entity) {
|
||||
notifyItemChanged(indexItem(entity.getDownloadUrl()));
|
||||
}
|
||||
|
||||
public synchronized void setProgress(String url, long currentPosition) {
|
||||
mProgress.put(url, currentPosition);
|
||||
// int index = indexItem(url);
|
||||
// L.d(TAG, "index ==> " + index);
|
||||
// notifyItemChanged(index);
|
||||
notifyItemChanged(indexItem(url));
|
||||
}
|
||||
|
||||
private synchronized int indexItem(String url) {
|
||||
Set set = mPositions.entrySet();
|
||||
for (Object aSet : set) {
|
||||
Map.Entry entry = (Map.Entry) aSet;
|
||||
if (entry.getKey().equals(url)) {
|
||||
return (int) entry.getValue();
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override protected void bindData(MyHolder holder, int position, DownloadEntity item) {
|
||||
//holder.progress.setProgress(item.getCurrentProgress());
|
||||
long size = item.getFileSize();
|
||||
int current = 0;
|
||||
if (size == 0) {
|
||||
current = 0;
|
||||
}
|
||||
current = (int) (mProgress.get(item.getDownloadUrl()) * 100 / item.getFileSize());
|
||||
holder.progress.setProgress(current);
|
||||
BtClickListener listener = new BtClickListener(position, item);
|
||||
holder.bt.setOnClickListener(listener);
|
||||
String str = "";
|
||||
int color = android.R.color.holo_green_light;
|
||||
switch (item.getState()) {
|
||||
case DownloadEntity.STATE_WAIT:
|
||||
case DownloadEntity.STATE_OTHER:
|
||||
case DownloadEntity.STATE_FAIL:
|
||||
str = "开始";
|
||||
break;
|
||||
case DownloadEntity.STATE_STOP:
|
||||
str = "恢复";
|
||||
color = android.R.color.holo_blue_light;
|
||||
break;
|
||||
case DownloadEntity.STATE_DOWNLOAD_ING:
|
||||
str = "暂停";
|
||||
color = android.R.color.holo_red_light;
|
||||
break;
|
||||
case DownloadEntity.STATE_COMPLETE:
|
||||
str = "重新开始?";
|
||||
holder.progress.setProgress(100);
|
||||
break;
|
||||
}
|
||||
holder.bt.setText(str);
|
||||
holder.bt.setTextColor(getColor(color));
|
||||
}
|
||||
|
||||
private int getColor(int color) {
|
||||
return Resources.getSystem().getColor(color);
|
||||
}
|
||||
|
||||
private class BtClickListener implements View.OnClickListener {
|
||||
private DownloadEntity entity;
|
||||
private int position;
|
||||
|
||||
BtClickListener(int position, DownloadEntity entity) {
|
||||
this.entity = entity;
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
@Override protected MyHolder getViewHolder(View convertView, int viewType) {
|
||||
return new MyHolder(convertView);
|
||||
@Override public void onClick(View v) {
|
||||
L.d(TAG, "position ==> " + position);
|
||||
switch (entity.getState()) {
|
||||
case DownloadEntity.STATE_WAIT:
|
||||
case DownloadEntity.STATE_OTHER:
|
||||
case DownloadEntity.STATE_FAIL:
|
||||
case DownloadEntity.STATE_STOP:
|
||||
case DownloadEntity.STATE_COMPLETE:
|
||||
start(entity);
|
||||
break;
|
||||
case DownloadEntity.STATE_DOWNLOAD_ING:
|
||||
stop(entity);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override protected int setLayoutId(int type) {
|
||||
return R.layout.item_download;
|
||||
private void start(DownloadEntity entity) {
|
||||
|
||||
List<IDownloadCommand> commands = new ArrayList<>();
|
||||
IDownloadCommand addCommand =
|
||||
mFactory.createCommand(getContext(), entity, CommandFactory.TASK_CREATE);
|
||||
IDownloadCommand startCommand =
|
||||
mFactory.createCommand(getContext(), entity, CommandFactory.TASK_START);
|
||||
commands.add(addCommand);
|
||||
commands.add(startCommand);
|
||||
mManager.setCommands(commands).exe();
|
||||
}
|
||||
|
||||
public synchronized void updateState(DownloadEntity entity) {
|
||||
notifyItemChanged(indexItem(entity.getDownloadUrl()));
|
||||
private void stop(DownloadEntity entity) {
|
||||
IDownloadCommand stopCommand =
|
||||
mFactory.createCommand(getContext(), entity, CommandFactory.TASK_STOP);
|
||||
mManager.setCommand(stopCommand).exe();
|
||||
}
|
||||
|
||||
public synchronized void setProgress(String url, long currentPosition) {
|
||||
mProgress.put(url, currentPosition);
|
||||
// int index = indexItem(url);
|
||||
// L.d(TAG, "index ==> " + index);
|
||||
// notifyItemChanged(index);
|
||||
notifyItemChanged(indexItem(url));
|
||||
private void cancel(DownloadEntity entity) {
|
||||
IDownloadCommand cancelCommand =
|
||||
mFactory.createCommand(getContext(), entity, CommandFactory.TASK_CANCEL);
|
||||
mManager.setCommand(cancelCommand).exe();
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized int indexItem(String url) {
|
||||
Set set = mPositions.entrySet();
|
||||
for (Object aSet : set) {
|
||||
Map.Entry entry = (Map.Entry) aSet;
|
||||
if (entry.getKey().equals(url)) {
|
||||
return (int) entry.getValue();
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override protected void bindData(MyHolder holder, int position, DownloadEntity item) {
|
||||
//holder.progress.setProgress(item.getCurrentProgress());
|
||||
long size = item.getFileSize();
|
||||
int current = 0;
|
||||
if (size == 0) {
|
||||
current = 0;
|
||||
}
|
||||
current = (int) (mProgress.get(item.getDownloadUrl()) * 100 / item.getFileSize());
|
||||
holder.progress.setProgress(current);
|
||||
BtClickListener listener = new BtClickListener(position, item);
|
||||
holder.bt.setOnClickListener(listener);
|
||||
String str = "";
|
||||
int color = android.R.color.holo_green_light;
|
||||
switch (item.getState()) {
|
||||
case DownloadEntity.STATE_WAIT:
|
||||
case DownloadEntity.STATE_OTHER:
|
||||
case DownloadEntity.STATE_FAIL:
|
||||
str = "开始";
|
||||
break;
|
||||
case DownloadEntity.STATE_STOP:
|
||||
str = "恢复";
|
||||
color = android.R.color.holo_blue_light;
|
||||
break;
|
||||
case DownloadEntity.STATE_DOWNLOAD_ING:
|
||||
str = "暂停";
|
||||
color = android.R.color.holo_red_light;
|
||||
break;
|
||||
case DownloadEntity.STATE_COMPLETE:
|
||||
str = "重新开始?";
|
||||
holder.progress.setProgress(100);
|
||||
break;
|
||||
}
|
||||
holder.bt.setText(str);
|
||||
holder.bt.setTextColor(getColor(color));
|
||||
}
|
||||
|
||||
private int getColor(int color) {
|
||||
return Resources.getSystem().getColor(color);
|
||||
}
|
||||
|
||||
private class BtClickListener implements View.OnClickListener {
|
||||
private DownloadEntity entity;
|
||||
private int position;
|
||||
|
||||
BtClickListener(int position, DownloadEntity entity) {
|
||||
this.entity = entity;
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
@Override public void onClick(View v) {
|
||||
L.d(TAG, "position ==> " + position);
|
||||
switch (entity.getState()) {
|
||||
case DownloadEntity.STATE_WAIT:
|
||||
case DownloadEntity.STATE_OTHER:
|
||||
case DownloadEntity.STATE_FAIL:
|
||||
case DownloadEntity.STATE_STOP:
|
||||
case DownloadEntity.STATE_COMPLETE:
|
||||
start(entity);
|
||||
break;
|
||||
case DownloadEntity.STATE_DOWNLOAD_ING:
|
||||
stop(entity);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void start(DownloadEntity entity) {
|
||||
|
||||
List<IDownloadCommand> commands = new ArrayList<>();
|
||||
IDownloadCommand addCommand = mFactory.createCommand(getContext(), entity,
|
||||
CommandFactory.TASK_CREATE);
|
||||
IDownloadCommand startCommand = mFactory.createCommand(getContext(), entity,
|
||||
CommandFactory.TASK_START);
|
||||
commands.add(addCommand);
|
||||
commands.add(startCommand);
|
||||
mManager.setCommands(commands).exe();
|
||||
}
|
||||
|
||||
private void stop(DownloadEntity entity) {
|
||||
IDownloadCommand stopCommand = mFactory.createCommand(getContext(), entity,
|
||||
CommandFactory.TASK_STOP);
|
||||
mManager.setCommand(stopCommand).exe();
|
||||
}
|
||||
|
||||
private void cancel(DownloadEntity entity) {
|
||||
IDownloadCommand cancelCommand = mFactory.createCommand(getContext(), entity,
|
||||
CommandFactory.TASK_CANCEL);
|
||||
mManager.setCommand(cancelCommand).exe();
|
||||
}
|
||||
}
|
||||
|
||||
class MyHolder extends AbsHolder {
|
||||
@Bind(R.id.progressBar) HorizontalProgressBarWithNumber progress;
|
||||
@Bind(R.id.bt) Button bt;
|
||||
|
||||
MyHolder(View itemView) {
|
||||
super(itemView);
|
||||
}
|
||||
class MyHolder extends AbsHolder {
|
||||
@Bind(R.id.progressBar) HorizontalProgressBarWithNumber progress;
|
||||
@Bind(R.id.bt) Button bt;
|
||||
|
||||
MyHolder(View itemView) {
|
||||
super(itemView);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,18 +2,17 @@ package com.arialyy.simple.base;
|
||||
|
||||
import android.databinding.ViewDataBinding;
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.arialyy.frame.core.AbsActivity;
|
||||
|
||||
/**
|
||||
* Created by Lyy on 2016/9/27.
|
||||
*/
|
||||
public abstract class BaseActivity<VB extends ViewDataBinding> extends AbsActivity<VB> {
|
||||
@Override protected void dataCallback(int result, Object data) {
|
||||
@Override protected void dataCallback(int result, Object data) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override protected void init(Bundle savedInstanceState) {
|
||||
super.init(savedInstanceState);
|
||||
}
|
||||
@Override protected void init(Bundle savedInstanceState) {
|
||||
super.init(savedInstanceState);
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.arialyy.simple.base;
|
||||
|
||||
import android.app.Application;
|
||||
|
||||
import com.arialyy.downloadutil.core.DownloadManager;
|
||||
import com.arialyy.frame.core.AbsFrame;
|
||||
|
||||
@ -9,9 +8,9 @@ import com.arialyy.frame.core.AbsFrame;
|
||||
* Created by Lyy on 2016/9/27.
|
||||
*/
|
||||
public class BaseApplication extends Application {
|
||||
@Override public void onCreate() {
|
||||
super.onCreate();
|
||||
AbsFrame.init(this);
|
||||
DownloadManager.init(this);
|
||||
}
|
||||
@Override public void onCreate() {
|
||||
super.onCreate();
|
||||
AbsFrame.init(this);
|
||||
DownloadManager.init(this);
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,13 @@
|
||||
package com.arialyy.simple.base;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.arialyy.frame.module.AbsModule;
|
||||
|
||||
/**
|
||||
* Created by Lyy on 2016/9/27.
|
||||
*/
|
||||
public class BaseModule extends AbsModule {
|
||||
public BaseModule(Context context) {
|
||||
super(context);
|
||||
}
|
||||
public BaseModule(Context context) {
|
||||
super(context);
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package com.arialyy.simple.module;
|
||||
import android.content.Context;
|
||||
import android.content.IntentFilter;
|
||||
import android.os.Environment;
|
||||
|
||||
import com.arialyy.downloadutil.core.DownloadManager;
|
||||
import com.arialyy.downloadutil.entity.DownloadEntity;
|
||||
import com.arialyy.downloadutil.util.Util;
|
||||
@ -11,7 +10,6 @@ import com.arialyy.frame.util.AndroidUtils;
|
||||
import com.arialyy.frame.util.StringUtil;
|
||||
import com.arialyy.simple.R;
|
||||
import com.arialyy.simple.base.BaseModule;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -20,65 +18,95 @@ import java.util.List;
|
||||
* Created by Lyy on 2016/9/27.
|
||||
*/
|
||||
public class DownloadModule extends BaseModule {
|
||||
public DownloadModule(Context context) {
|
||||
super(context);
|
||||
}
|
||||
public DownloadModule(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置下载数据
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public List<DownloadEntity> getDownloadData() {
|
||||
List<DownloadEntity> list = DownloadEntity.findAllData(DownloadEntity.class);
|
||||
if (list == null) {
|
||||
list = createNewDownload();
|
||||
/**
|
||||
* 设置下载数据
|
||||
*/
|
||||
public List<DownloadEntity> getDownloadData() {
|
||||
List<DownloadEntity> list = DownloadEntity.findAllData(DownloadEntity.class);
|
||||
List<DownloadEntity> newDownload = createNewDownload();
|
||||
if (list == null) {
|
||||
list = newDownload;
|
||||
} else {
|
||||
list = filter(list, newDownload);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 过滤任务
|
||||
*
|
||||
* @param sqlEntity 数据库的下载实体
|
||||
* @param createdEntity 通过下载链接生成的下载实体
|
||||
*/
|
||||
private List<DownloadEntity> filter(List<DownloadEntity> sqlEntity,
|
||||
List<DownloadEntity> createdEntity) {
|
||||
List<DownloadEntity> list = new ArrayList<>();
|
||||
list.addAll(sqlEntity);
|
||||
for (DownloadEntity cEntity : createdEntity) {
|
||||
int count = 0;
|
||||
for (DownloadEntity sEntity : sqlEntity) {
|
||||
if (cEntity.getDownloadUrl().equals(sEntity.getDownloadUrl())) {
|
||||
break;
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
private List<DownloadEntity> createNewDownload() {
|
||||
List<DownloadEntity> list = new ArrayList<>();
|
||||
String[] urls = getContext().getResources()
|
||||
.getStringArray(R.array.test_apk_download_url);
|
||||
for (String url : urls) {
|
||||
String fileName = Util.keyToHashCode(url) + ".apk";
|
||||
DownloadEntity entity = new DownloadEntity();
|
||||
entity.setDownloadUrl(url);
|
||||
entity.setDownloadPath(getDownloadPath(url));
|
||||
entity.setFileName(fileName);
|
||||
list.add(entity);
|
||||
count++;
|
||||
if (count == sqlEntity.size()) {
|
||||
list.add(cEntity);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载广播过滤器
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public IntentFilter getDownloadFilter() {
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addDataScheme(getContext().getPackageName());
|
||||
filter.addAction(DownloadManager.ACTION_PRE);
|
||||
filter.addAction(DownloadManager.ACTION_RESUME);
|
||||
filter.addAction(DownloadManager.ACTION_START);
|
||||
filter.addAction(DownloadManager.ACTION_RUNNING);
|
||||
filter.addAction(DownloadManager.ACTION_STOP);
|
||||
filter.addAction(DownloadManager.ACTION_CANCEL);
|
||||
filter.addAction(DownloadManager.ACTION_COMPLETE);
|
||||
filter.addAction(DownloadManager.ACTION_FAIL);
|
||||
return filter;
|
||||
/**
|
||||
* 创建下载列表
|
||||
*/
|
||||
private List<DownloadEntity> createNewDownload() {
|
||||
List<DownloadEntity> list = new ArrayList<>();
|
||||
String[] urls =
|
||||
getContext().getResources().getStringArray(R.array.test_apk_download_url);
|
||||
for (String url : urls) {
|
||||
String fileName = Util.keyToHashCode(url) + ".apk";
|
||||
DownloadEntity entity = new DownloadEntity();
|
||||
entity.setDownloadUrl(url);
|
||||
entity.setDownloadPath(getDownloadPath(url));
|
||||
entity.setFileName(fileName);
|
||||
list.add(entity);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
private String getDownloadPath(String url) {
|
||||
String path = Environment.getExternalStorageDirectory()
|
||||
.getPath() + "/" + AndroidUtils.getAppName(getContext()) + "downloads/" + StringUtil
|
||||
.keyToHashKey(url) + ".apk";
|
||||
File file = new File(path);
|
||||
if (!file.getParentFile().exists()) {
|
||||
file.getParentFile().mkdirs();
|
||||
}
|
||||
return path;
|
||||
/**
|
||||
* 下载广播过滤器
|
||||
*/
|
||||
public IntentFilter getDownloadFilter() {
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addDataScheme(getContext().getPackageName());
|
||||
filter.addAction(DownloadManager.ACTION_PRE);
|
||||
filter.addAction(DownloadManager.ACTION_RESUME);
|
||||
filter.addAction(DownloadManager.ACTION_START);
|
||||
filter.addAction(DownloadManager.ACTION_RUNNING);
|
||||
filter.addAction(DownloadManager.ACTION_STOP);
|
||||
filter.addAction(DownloadManager.ACTION_CANCEL);
|
||||
filter.addAction(DownloadManager.ACTION_COMPLETE);
|
||||
filter.addAction(DownloadManager.ACTION_FAIL);
|
||||
return filter;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置下载队列
|
||||
*/
|
||||
private String getDownloadPath(String url) {
|
||||
String path =
|
||||
Environment.getExternalStorageDirectory().getPath() + "/" + AndroidUtils.getAppName(
|
||||
getContext()) + "downloads/" + StringUtil.keyToHashKey(url) + ".apk";
|
||||
File file = new File(path);
|
||||
if (!file.getParentFile().exists()) {
|
||||
file.getParentFile().mkdirs();
|
||||
}
|
||||
return path;
|
||||
}
|
||||
}
|
||||
|
@ -7,178 +7,177 @@ import android.graphics.Paint;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.TypedValue;
|
||||
import android.widget.ProgressBar;
|
||||
|
||||
import com.arialyy.simple.R;
|
||||
|
||||
public class HorizontalProgressBarWithNumber extends ProgressBar {
|
||||
private static final int DEFAULT_TEXT_SIZE = 10;
|
||||
private static final int DEFAULT_TEXT_COLOR = 0XFFFC00D1;
|
||||
private static final int DEFAULT_COLOR_UNREACHED_COLOR = 0xFFd3d6da;
|
||||
private static final int DEFAULT_HEIGHT_REACHED_PROGRESS_BAR = 2;
|
||||
private static final int DEFAULT_HEIGHT_UNREACHED_PROGRESS_BAR = 2;
|
||||
private static final int DEFAULT_SIZE_TEXT_OFFSET = 10;
|
||||
/**
|
||||
* painter of all drawing things
|
||||
*/
|
||||
protected Paint mPaint = new Paint();
|
||||
/**
|
||||
* color of progress number
|
||||
*/
|
||||
protected int mTextColor = DEFAULT_TEXT_COLOR;
|
||||
/**
|
||||
* size of text (sp)
|
||||
*/
|
||||
protected int mTextSize = sp2px(DEFAULT_TEXT_SIZE);
|
||||
/**
|
||||
* offset of draw progress
|
||||
*/
|
||||
protected int mTextOffset = dp2px(
|
||||
DEFAULT_SIZE_TEXT_OFFSET);
|
||||
/**
|
||||
* height of reached progress bar
|
||||
*/
|
||||
protected int mReachedProgressBarHeight = dp2px(
|
||||
DEFAULT_HEIGHT_REACHED_PROGRESS_BAR);
|
||||
/**
|
||||
* color of reached bar
|
||||
*/
|
||||
protected int mReachedBarColor = DEFAULT_TEXT_COLOR;
|
||||
/**
|
||||
* color of unreached bar
|
||||
*/
|
||||
protected int mUnReachedBarColor = DEFAULT_COLOR_UNREACHED_COLOR;
|
||||
/**
|
||||
* height of unreached progress bar
|
||||
*/
|
||||
protected int mUnReachedProgressBarHeight = dp2px(
|
||||
DEFAULT_HEIGHT_UNREACHED_PROGRESS_BAR);
|
||||
/**
|
||||
* view width except padding
|
||||
*/
|
||||
protected int mRealWidth;
|
||||
protected boolean mIfDrawText = true;
|
||||
protected static final int VISIBLE = 0;
|
||||
private static final int DEFAULT_TEXT_SIZE = 10;
|
||||
private static final int DEFAULT_TEXT_COLOR = 0XFFFC00D1;
|
||||
private static final int DEFAULT_COLOR_UNREACHED_COLOR = 0xFFd3d6da;
|
||||
private static final int DEFAULT_HEIGHT_REACHED_PROGRESS_BAR = 2;
|
||||
private static final int DEFAULT_HEIGHT_UNREACHED_PROGRESS_BAR = 2;
|
||||
private static final int DEFAULT_SIZE_TEXT_OFFSET = 10;
|
||||
/**
|
||||
* painter of all drawing things
|
||||
*/
|
||||
protected Paint mPaint = new Paint();
|
||||
/**
|
||||
* color of progress number
|
||||
*/
|
||||
protected int mTextColor = DEFAULT_TEXT_COLOR;
|
||||
/**
|
||||
* size of text (sp)
|
||||
*/
|
||||
protected int mTextSize = sp2px(DEFAULT_TEXT_SIZE);
|
||||
/**
|
||||
* offset of draw progress
|
||||
*/
|
||||
protected int mTextOffset =
|
||||
dp2px(DEFAULT_SIZE_TEXT_OFFSET);
|
||||
/**
|
||||
* height of reached progress bar
|
||||
*/
|
||||
protected int mReachedProgressBarHeight =
|
||||
dp2px(DEFAULT_HEIGHT_REACHED_PROGRESS_BAR);
|
||||
/**
|
||||
* color of reached bar
|
||||
*/
|
||||
protected int mReachedBarColor = DEFAULT_TEXT_COLOR;
|
||||
/**
|
||||
* color of unreached bar
|
||||
*/
|
||||
protected int mUnReachedBarColor = DEFAULT_COLOR_UNREACHED_COLOR;
|
||||
/**
|
||||
* height of unreached progress bar
|
||||
*/
|
||||
protected int mUnReachedProgressBarHeight =
|
||||
dp2px(DEFAULT_HEIGHT_UNREACHED_PROGRESS_BAR);
|
||||
/**
|
||||
* view width except padding
|
||||
*/
|
||||
protected int mRealWidth;
|
||||
protected boolean mIfDrawText = true;
|
||||
protected static final int VISIBLE = 0;
|
||||
|
||||
public HorizontalProgressBarWithNumber(Context context, AttributeSet attrs) {
|
||||
this(context, attrs, 0);
|
||||
}
|
||||
public HorizontalProgressBarWithNumber(Context context, AttributeSet attrs) {
|
||||
this(context, attrs, 0);
|
||||
}
|
||||
|
||||
public HorizontalProgressBarWithNumber(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
obtainStyledAttributes(attrs);
|
||||
mPaint.setTextSize(mTextSize);
|
||||
mPaint.setColor(mTextColor);
|
||||
}
|
||||
public HorizontalProgressBarWithNumber(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
obtainStyledAttributes(attrs);
|
||||
mPaint.setTextSize(mTextSize);
|
||||
mPaint.setColor(mTextColor);
|
||||
}
|
||||
|
||||
@Override protected synchronized void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
int width = MeasureSpec.getSize(widthMeasureSpec);
|
||||
int height = measureHeight(heightMeasureSpec);
|
||||
setMeasuredDimension(width, height);
|
||||
mRealWidth = getMeasuredWidth() - getPaddingRight() - getPaddingLeft();
|
||||
}
|
||||
@Override protected synchronized void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
int width = MeasureSpec.getSize(widthMeasureSpec);
|
||||
int height = measureHeight(heightMeasureSpec);
|
||||
setMeasuredDimension(width, height);
|
||||
mRealWidth = getMeasuredWidth() - getPaddingRight() - getPaddingLeft();
|
||||
}
|
||||
|
||||
private int measureHeight(int measureSpec) {
|
||||
int result = 0;
|
||||
int specMode = MeasureSpec.getMode(measureSpec);
|
||||
int specSize = MeasureSpec.getSize(measureSpec);
|
||||
if (specMode == MeasureSpec.EXACTLY) {
|
||||
result = specSize;
|
||||
} else {
|
||||
float textHeight = (mPaint.descent() - mPaint.ascent());
|
||||
result = (int) (getPaddingTop() + getPaddingBottom() + Math.max(
|
||||
Math.max(mReachedProgressBarHeight, mUnReachedProgressBarHeight),
|
||||
Math.abs(textHeight))
|
||||
);
|
||||
if (specMode == MeasureSpec.AT_MOST) {
|
||||
result = Math.min(result, specSize);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
private int measureHeight(int measureSpec) {
|
||||
int result = 0;
|
||||
int specMode = MeasureSpec.getMode(measureSpec);
|
||||
int specSize = MeasureSpec.getSize(measureSpec);
|
||||
if (specMode == MeasureSpec.EXACTLY) {
|
||||
result = specSize;
|
||||
} else {
|
||||
float textHeight = (mPaint.descent() - mPaint.ascent());
|
||||
result = (int) (getPaddingTop() + getPaddingBottom() + Math.max(
|
||||
Math.max(mReachedProgressBarHeight, mUnReachedProgressBarHeight), Math.abs(textHeight)));
|
||||
if (specMode == MeasureSpec.AT_MOST) {
|
||||
result = Math.min(result, specSize);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* get the styled attributes
|
||||
*/
|
||||
private void obtainStyledAttributes(AttributeSet attrs) {
|
||||
// init values from custom attributes
|
||||
final TypedArray attributes = getContext().obtainStyledAttributes(attrs,
|
||||
R.styleable.HorizontalProgressBarWithNumber);
|
||||
mTextColor = attributes.getColor(
|
||||
R.styleable.HorizontalProgressBarWithNumber_progress_text_color,
|
||||
DEFAULT_TEXT_COLOR);
|
||||
mTextSize = (int) attributes.getDimension(
|
||||
R.styleable.HorizontalProgressBarWithNumber_progress_text_size, mTextSize);
|
||||
mReachedBarColor = attributes.getColor(
|
||||
R.styleable.HorizontalProgressBarWithNumber_progress_reached_color, mTextColor);
|
||||
mUnReachedBarColor = attributes.getColor(
|
||||
R.styleable.HorizontalProgressBarWithNumber_progress_unreached_color,
|
||||
DEFAULT_COLOR_UNREACHED_COLOR);
|
||||
mReachedProgressBarHeight = (int) attributes.getDimension(
|
||||
R.styleable.HorizontalProgressBarWithNumber_progress_reached_bar_height,
|
||||
mReachedProgressBarHeight);
|
||||
mUnReachedProgressBarHeight = (int) attributes.getDimension(
|
||||
R.styleable.HorizontalProgressBarWithNumber_progress_unreached_bar_height,
|
||||
mUnReachedProgressBarHeight);
|
||||
mTextOffset = (int) attributes.getDimension(
|
||||
R.styleable.HorizontalProgressBarWithNumber_progress_text_offset, mTextOffset);
|
||||
int textVisible = attributes.getInt(
|
||||
R.styleable.HorizontalProgressBarWithNumber_progress_text_visibility, VISIBLE);
|
||||
if (textVisible != VISIBLE) {
|
||||
mIfDrawText = false;
|
||||
}
|
||||
attributes.recycle();
|
||||
/**
|
||||
* get the styled attributes
|
||||
*/
|
||||
private void obtainStyledAttributes(AttributeSet attrs) {
|
||||
// init values from custom attributes
|
||||
final TypedArray attributes =
|
||||
getContext().obtainStyledAttributes(attrs, R.styleable.HorizontalProgressBarWithNumber);
|
||||
mTextColor =
|
||||
attributes.getColor(R.styleable.HorizontalProgressBarWithNumber_progress_text_color,
|
||||
DEFAULT_TEXT_COLOR);
|
||||
mTextSize = (int) attributes.getDimension(
|
||||
R.styleable.HorizontalProgressBarWithNumber_progress_text_size, mTextSize);
|
||||
mReachedBarColor =
|
||||
attributes.getColor(R.styleable.HorizontalProgressBarWithNumber_progress_reached_color,
|
||||
mTextColor);
|
||||
mUnReachedBarColor =
|
||||
attributes.getColor(R.styleable.HorizontalProgressBarWithNumber_progress_unreached_color,
|
||||
DEFAULT_COLOR_UNREACHED_COLOR);
|
||||
mReachedProgressBarHeight = (int) attributes.getDimension(
|
||||
R.styleable.HorizontalProgressBarWithNumber_progress_reached_bar_height,
|
||||
mReachedProgressBarHeight);
|
||||
mUnReachedProgressBarHeight = (int) attributes.getDimension(
|
||||
R.styleable.HorizontalProgressBarWithNumber_progress_unreached_bar_height,
|
||||
mUnReachedProgressBarHeight);
|
||||
mTextOffset = (int) attributes.getDimension(
|
||||
R.styleable.HorizontalProgressBarWithNumber_progress_text_offset, mTextOffset);
|
||||
int textVisible =
|
||||
attributes.getInt(R.styleable.HorizontalProgressBarWithNumber_progress_text_visibility,
|
||||
VISIBLE);
|
||||
if (textVisible != VISIBLE) {
|
||||
mIfDrawText = false;
|
||||
}
|
||||
attributes.recycle();
|
||||
}
|
||||
|
||||
@Override protected synchronized void onDraw(Canvas canvas) {
|
||||
canvas.save();
|
||||
canvas.translate(getPaddingLeft(), getHeight() / 2);
|
||||
boolean noNeedBg = false;
|
||||
float radio = getProgress() * 1.0f / getMax();
|
||||
float progressPosX = (int) (mRealWidth * radio);
|
||||
String text = getProgress() + "%";
|
||||
// mPaint.getTextBounds(text, 0, text.length(), mTextBound);
|
||||
float textWidth = mPaint.measureText(text);
|
||||
float textHeight = (mPaint.descent() + mPaint.ascent()) / 2;
|
||||
if (progressPosX + textWidth > mRealWidth) {
|
||||
progressPosX = mRealWidth - textWidth;
|
||||
noNeedBg = true;
|
||||
}
|
||||
// draw reached bar
|
||||
float endX = progressPosX - mTextOffset / 2;
|
||||
if (endX > 0) {
|
||||
mPaint.setColor(mReachedBarColor);
|
||||
mPaint.setStrokeWidth(mReachedProgressBarHeight);
|
||||
canvas.drawLine(0, 0, endX, 0, mPaint);
|
||||
}
|
||||
// draw progress bar
|
||||
// measure text bound
|
||||
if (mIfDrawText) {
|
||||
mPaint.setColor(mTextColor);
|
||||
canvas.drawText(text, progressPosX, -textHeight, mPaint);
|
||||
}
|
||||
// draw unreached bar
|
||||
if (!noNeedBg) {
|
||||
float start = progressPosX + mTextOffset / 2 + textWidth;
|
||||
mPaint.setColor(mUnReachedBarColor);
|
||||
mPaint.setStrokeWidth(mUnReachedProgressBarHeight);
|
||||
canvas.drawLine(start, 0, mRealWidth, 0, mPaint);
|
||||
}
|
||||
canvas.restore();
|
||||
@Override protected synchronized void onDraw(Canvas canvas) {
|
||||
canvas.save();
|
||||
canvas.translate(getPaddingLeft(), getHeight() / 2);
|
||||
boolean noNeedBg = false;
|
||||
float radio = getProgress() * 1.0f / getMax();
|
||||
float progressPosX = (int) (mRealWidth * radio);
|
||||
String text = getProgress() + "%";
|
||||
// mPaint.getTextBounds(text, 0, text.length(), mTextBound);
|
||||
float textWidth = mPaint.measureText(text);
|
||||
float textHeight = (mPaint.descent() + mPaint.ascent()) / 2;
|
||||
if (progressPosX + textWidth > mRealWidth) {
|
||||
progressPosX = mRealWidth - textWidth;
|
||||
noNeedBg = true;
|
||||
}
|
||||
// draw reached bar
|
||||
float endX = progressPosX - mTextOffset / 2;
|
||||
if (endX > 0) {
|
||||
mPaint.setColor(mReachedBarColor);
|
||||
mPaint.setStrokeWidth(mReachedProgressBarHeight);
|
||||
canvas.drawLine(0, 0, endX, 0, mPaint);
|
||||
}
|
||||
// draw progress bar
|
||||
// measure text bound
|
||||
if (mIfDrawText) {
|
||||
mPaint.setColor(mTextColor);
|
||||
canvas.drawText(text, progressPosX, -textHeight, mPaint);
|
||||
}
|
||||
// draw unreached bar
|
||||
if (!noNeedBg) {
|
||||
float start = progressPosX + mTextOffset / 2 + textWidth;
|
||||
mPaint.setColor(mUnReachedBarColor);
|
||||
mPaint.setStrokeWidth(mUnReachedProgressBarHeight);
|
||||
canvas.drawLine(start, 0, mRealWidth, 0, mPaint);
|
||||
}
|
||||
canvas.restore();
|
||||
}
|
||||
|
||||
/**
|
||||
* dp 2 px
|
||||
*/
|
||||
protected int dp2px(int dpVal) {
|
||||
return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dpVal,
|
||||
getResources().getDisplayMetrics());
|
||||
}
|
||||
/**
|
||||
* dp 2 px
|
||||
*/
|
||||
protected int dp2px(int dpVal) {
|
||||
return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dpVal,
|
||||
getResources().getDisplayMetrics());
|
||||
}
|
||||
|
||||
/**
|
||||
* sp 2 px
|
||||
*/
|
||||
protected int sp2px(int spVal) {
|
||||
return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, spVal,
|
||||
getResources().getDisplayMetrics());
|
||||
}
|
||||
/**
|
||||
* sp 2 px
|
||||
*/
|
||||
protected int sp2px(int spVal) {
|
||||
return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, spVal,
|
||||
getResources().getDisplayMetrics());
|
||||
}
|
||||
}
|
@ -1,18 +1,32 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<layout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
>
|
||||
|
||||
<LinearLayout
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
>
|
||||
|
||||
<include layout="@layout/layout_bar"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/single_task"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
>
|
||||
android:layout_height="wrap_content"
|
||||
android:onClick="onClick"
|
||||
android:text="单任务下载"
|
||||
style="?buttonBarButtonStyle"
|
||||
/>
|
||||
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
/>
|
||||
<Button
|
||||
android:id="@+id/multi_task"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:onClick="onClick"
|
||||
android:text="多任务下载"
|
||||
style="?buttonBarButtonStyle"
|
||||
/>
|
||||
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</layout>
|
||||
|
20
app/src/main/res/layout/activity_multi.xml
Normal file
20
app/src/main/res/layout/activity_multi.xml
Normal file
@ -0,0 +1,20 @@
|
||||
<?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"
|
||||
>
|
||||
<include layout="@layout/layout_bar"/>
|
||||
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
/>
|
||||
|
||||
</LinearLayout>
|
||||
</layout>
|
@ -1,42 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layout xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<android.support.design.widget.CoordinatorLayout
|
||||
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:fitsSystemWindows="true"
|
||||
tools:context="com.arialyy.simple.activity.SimpleTestActivity"
|
||||
>
|
||||
|
||||
<android.support.design.widget.AppBarLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:theme="@style/AppTheme.AppBarOverlay"
|
||||
>
|
||||
|
||||
<android.support.v7.widget.Toolbar
|
||||
android:id="@+id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?attr/actionBarSize"
|
||||
android:background="?attr/colorPrimary"
|
||||
app:popupTheme="@style/AppTheme.PopupOverlay"
|
||||
/>
|
||||
|
||||
</android.support.design.widget.AppBarLayout>
|
||||
|
||||
<include layout="@layout/content_simple"/>
|
||||
|
||||
<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"
|
||||
/>
|
||||
|
||||
</android.support.design.widget.CoordinatorLayout>
|
||||
</layout>
|
34
app/src/main/res/layout/activity_single.xml
Normal file
34
app/src/main/res/layout/activity_single.xml
Normal file
@ -0,0 +1,34 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layout xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<android.support.design.widget.CoordinatorLayout
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:fitsSystemWindows="true"
|
||||
tools:context="com.arialyy.simple.activity.SingleTaskActivity"
|
||||
>
|
||||
|
||||
<android.support.design.widget.AppBarLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:theme="@style/AppTheme.AppBarOverlay"
|
||||
>
|
||||
|
||||
<include layout="@layout/layout_bar"/>
|
||||
|
||||
</android.support.design.widget.AppBarLayout>
|
||||
|
||||
<include layout="@layout/content_single"/>
|
||||
|
||||
<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"
|
||||
/>
|
||||
|
||||
</android.support.design.widget.CoordinatorLayout>
|
||||
</layout>
|
@ -1,72 +0,0 @@
|
||||
<?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"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior"
|
||||
tools:context="com.arialyy.simple.activity.SimpleTestActivity"
|
||||
tools:showIn="@layout/activity_simple"
|
||||
>
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/progressBar"
|
||||
style="?android:attr/progressBarStyleHorizontal"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="20dp"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_margin="16dp"
|
||||
android:layout_toLeftOf="@+id/size"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/size"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_alignTop="@+id/progressBar"
|
||||
android:layout_marginRight="16dp"
|
||||
android:text="ssss"
|
||||
android:textSize="16sp"
|
||||
/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/progressBar"
|
||||
android:orientation="horizontal"
|
||||
>
|
||||
|
||||
<Button
|
||||
android:id="@+id/start"
|
||||
style="?buttonBarButtonStyle"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:onClick="onClick"
|
||||
android:text="开始"
|
||||
/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/stop"
|
||||
style="?buttonBarButtonStyle"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:onClick="onClick"
|
||||
android:text="暂停"
|
||||
/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/cancel"
|
||||
style="?buttonBarButtonStyle"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:onClick="onClick"
|
||||
android:text="删除任务"
|
||||
/>
|
||||
</LinearLayout>
|
||||
</RelativeLayout>
|
72
app/src/main/res/layout/content_single.xml
Normal file
72
app/src/main/res/layout/content_single.xml
Normal file
@ -0,0 +1,72 @@
|
||||
<?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"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior"
|
||||
tools:context="com.arialyy.simple.activity.SingleTaskActivity"
|
||||
tools:showIn="@layout/activity_single"
|
||||
>
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/progressBar"
|
||||
style="?android:attr/progressBarStyleHorizontal"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="20dp"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_margin="16dp"
|
||||
android:layout_toLeftOf="@+id/size"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/size"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_alignTop="@+id/progressBar"
|
||||
android:layout_marginRight="16dp"
|
||||
android:text="ssss"
|
||||
android:textSize="16sp"
|
||||
/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/progressBar"
|
||||
android:orientation="horizontal"
|
||||
>
|
||||
|
||||
<Button
|
||||
android:id="@+id/start"
|
||||
style="?buttonBarButtonStyle"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:onClick="onClick"
|
||||
android:text="开始"
|
||||
/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/stop"
|
||||
style="?buttonBarButtonStyle"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:onClick="onClick"
|
||||
android:text="暂停"
|
||||
/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/cancel"
|
||||
style="?buttonBarButtonStyle"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:onClick="onClick"
|
||||
android:text="删除任务"
|
||||
/>
|
||||
</LinearLayout>
|
||||
</RelativeLayout>
|
@ -1,27 +1,27 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="16dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="16dp"
|
||||
>
|
||||
|
||||
<com.arialyy.simple.widget.HorizontalProgressBarWithNumber
|
||||
android:id="@+id/progressBar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_marginRight="16dp"
|
||||
android:layout_toLeftOf="@+id/bt"
|
||||
android:max="100"
|
||||
/>
|
||||
<com.arialyy.simple.widget.HorizontalProgressBarWithNumber
|
||||
android:id="@+id/progressBar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_marginRight="16dp"
|
||||
android:layout_toLeftOf="@+id/bt"
|
||||
android:max="100"
|
||||
/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/bt"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentRight="true"
|
||||
android:text="开始"
|
||||
style="?buttonBarButtonStyle"
|
||||
/>
|
||||
<Button
|
||||
android:id="@+id/bt"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentRight="true"
|
||||
android:text="开始"
|
||||
style="?buttonBarButtonStyle"
|
||||
/>
|
||||
|
||||
</RelativeLayout>
|
10
app/src/main/res/layout/layout_bar.xml
Normal file
10
app/src/main/res/layout/layout_bar.xml
Normal file
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<android.support.v7.widget.Toolbar
|
||||
android:id="@+id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?attr/actionBarSize"
|
||||
android:background="?attr/colorPrimary"
|
||||
app:popupTheme="@style/AppTheme.PopupOverlay"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
/>
|
@ -1,10 +1,10 @@
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
tools:context="com.example.arial.downloaddemo.com.arialyy.simple.MainActivity">
|
||||
<item
|
||||
android:id="@+id/action_settings"
|
||||
android:title="@string/action_settings"
|
||||
android:orderInCategory="100"
|
||||
app:showAsAction="never"/>
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
tools:context="com.example.arial.downloaddemo.com.arialyy.simple.MainActivity">
|
||||
<item
|
||||
android:id="@+id/action_settings"
|
||||
android:title="@string/action_settings"
|
||||
android:orderInCategory="100"
|
||||
app:showAsAction="never"/>
|
||||
</menu>
|
||||
|
@ -1,12 +1,28 @@
|
||||
<resources>
|
||||
|
||||
<style name="AppTheme.NoActionBar">
|
||||
<item name="windowActionBar">false</item>
|
||||
<item name="windowNoTitle">true</item>
|
||||
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
|
||||
<item name="android:statusBarColor">@android:color/transparent</item>
|
||||
<item name="colorPrimary">@color/colorPrimary</item>
|
||||
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
|
||||
<item name="colorAccent">@color/colorAccent</item>
|
||||
</style>
|
||||
<style name="AppTheme.NoActionBar">
|
||||
<item name="windowActionBar">false</item>
|
||||
<item name="windowNoTitle">true</item>
|
||||
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
|
||||
<item name="android:statusBarColor">@android:color/transparent</item>
|
||||
<item name="colorPrimary">@color/colorPrimary</item>
|
||||
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
|
||||
<item name="colorAccent">@color/colorAccent</item>
|
||||
</style>
|
||||
|
||||
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
|
||||
<!-- Customize your theme here. -->
|
||||
<item name="colorPrimary">@color/colorPrimary</item>
|
||||
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
|
||||
<item name="colorAccent">@color/colorAccent</item>
|
||||
<!--设置导航栏内容可用-->
|
||||
<!--<item name="android:windowTranslucentNavigation">true</item>-->
|
||||
<!--设置状态栏内容可以-->
|
||||
<!--<item name="android:windowTranslucentStatus">true</item>-->
|
||||
<item name="windowActionBar">false</item>
|
||||
<item name="windowNoTitle">true</item>
|
||||
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
|
||||
<item name="android:statusBarColor">@android:color/transparent</item>
|
||||
<item name="android:windowIsTranslucent">true</item>
|
||||
</style>
|
||||
</resources>
|
||||
|
@ -1,6 +1,6 @@
|
||||
<resources>
|
||||
<!-- Example customization of dimensions originally defined in res/values/dimens.xml
|
||||
(such as screen margins) for screens with more than 820dp of available width. This
|
||||
would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). -->
|
||||
<dimen name="activity_horizontal_margin">64dp</dimen>
|
||||
<!-- Example customization of dimensions originally defined in res/values/dimens.xml
|
||||
(such as screen margins) for screens with more than 820dp of available width. This
|
||||
would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). -->
|
||||
<dimen name="activity_horizontal_margin">64dp</dimen>
|
||||
</resources>
|
||||
|
@ -1,16 +1,16 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<declare-styleable name="HorizontalProgressBarWithNumber">
|
||||
<attr name="progress_unreached_color" format="color"/>
|
||||
<attr name="progress_reached_color" format="color"/>
|
||||
<attr name="progress_reached_bar_height" format="dimension"/>
|
||||
<attr name="progress_unreached_bar_height" format="dimension"/>
|
||||
<attr name="progress_text_size" format="dimension"/>
|
||||
<attr name="progress_text_color" format="color"/>
|
||||
<attr name="progress_text_offset" format="dimension"/>
|
||||
<attr name="progress_text_visibility" format="enum">
|
||||
<enum name="visible" value="0"/>
|
||||
<enum name="invisible" value="1"/>
|
||||
</attr>
|
||||
</declare-styleable>
|
||||
<declare-styleable name="HorizontalProgressBarWithNumber">
|
||||
<attr name="progress_unreached_color" format="color"/>
|
||||
<attr name="progress_reached_color" format="color"/>
|
||||
<attr name="progress_reached_bar_height" format="dimension"/>
|
||||
<attr name="progress_unreached_bar_height" format="dimension"/>
|
||||
<attr name="progress_text_size" format="dimension"/>
|
||||
<attr name="progress_text_color" format="color"/>
|
||||
<attr name="progress_text_offset" format="dimension"/>
|
||||
<attr name="progress_text_visibility" format="enum">
|
||||
<enum name="visible" value="0"/>
|
||||
<enum name="invisible" value="1"/>
|
||||
</attr>
|
||||
</declare-styleable>
|
||||
</resources>
|
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<color name="colorPrimary">#3F51B5</color>
|
||||
<color name="colorPrimaryDark">#303F9F</color>
|
||||
<color name="colorAccent">#FF4081</color>
|
||||
<color name="colorPrimary">#3F51B5</color>
|
||||
<color name="colorPrimaryDark">#303F9F</color>
|
||||
<color name="colorAccent">#FF4081</color>
|
||||
</resources>
|
||||
|
@ -1,6 +1,6 @@
|
||||
<resources>
|
||||
<!-- Default screen margins, per the Android Design guidelines. -->
|
||||
<dimen name="activity_horizontal_margin">16dp</dimen>
|
||||
<dimen name="activity_vertical_margin">16dp</dimen>
|
||||
<dimen name="fab_margin">16dp</dimen>
|
||||
<!-- Default screen margins, per the Android Design guidelines. -->
|
||||
<dimen name="activity_horizontal_margin">16dp</dimen>
|
||||
<dimen name="activity_vertical_margin">16dp</dimen>
|
||||
<dimen name="fab_margin">16dp</dimen>
|
||||
</resources>
|
||||
|
@ -1,18 +1,18 @@
|
||||
<resources>
|
||||
<string name="app_name">DownloadDemo</string>
|
||||
<string name="action_settings">Settings</string>
|
||||
<string name="app_name">DownloadDemo</string>
|
||||
<string name="action_settings">Settings</string>
|
||||
|
||||
<string-array name="test_apk_download_url">
|
||||
<item>http://static.gaoshouyou.com/d/22/94/822260b849944492caadd2983f9bb624.apk</item> <!--300M的文件-->
|
||||
<item>http://static.gaoshouyou.com/d/21/e8/61218d78d0e8b79df68dbc18dd484c97.apk</item>
|
||||
<item>http://static.gaoshouyou.com/d/12/0d/7f120f50c80d2e7b8c4ba24ece4f9cdd.apk</item>
|
||||
<item>http://static.gaoshouyou.com/d/d4/4f/d6d48db3794fb9ecf47e83c346570881.apk</item>
|
||||
<!--<item>http://static.gaoshouyou.com/d/18/cf/ba18113bc6cf56c1c5863e761e717003.apk</item>-->
|
||||
<!--<item>http://static.gaoshouyou.com/d/60/17/2460921367173ea7145f11194a6f2587.apk</item>-->
|
||||
<!--<item>http://static.gaoshouyou.com/d/32/e0/1a32123ecbe0ee010d35479df248f90f.apk</item>-->
|
||||
<!--<item>http://static.gaoshouyou.com/d/22/94/822260b849944492caadd2983f9bb624.apk</item>-->
|
||||
<!--<item>http://static.gaoshouyou.com/d/e6/f5/4de6329f9cf5dc3a1d1e6bbcca0d003c.apk</item>-->
|
||||
<!--<item>http://static.gaoshouyou.com/d/6e/e5/ff6ecaaf45e532e6d07747af82357472.apk</item>-->
|
||||
<!--<item>http://static.gaoshouyou.com/d/36/69/2d3699acfa69e9632262442c46516ad8.apk</item>-->
|
||||
</string-array>
|
||||
<string-array name="test_apk_download_url">
|
||||
<item>http://static.gaoshouyou.com/d/22/94/822260b849944492caadd2983f9bb624.apk</item> <!--300M的文件-->
|
||||
<item>http://static.gaoshouyou.com/d/21/e8/61218d78d0e8b79df68dbc18dd484c97.apk</item>
|
||||
<item>http://static.gaoshouyou.com/d/12/0d/7f120f50c80d2e7b8c4ba24ece4f9cdd.apk</item>
|
||||
<item>http://static.gaoshouyou.com/d/d4/4f/d6d48db3794fb9ecf47e83c346570881.apk</item>
|
||||
<!--<item>http://static.gaoshouyou.com/d/18/cf/ba18113bc6cf56c1c5863e761e717003.apk</item>-->
|
||||
<!--<item>http://static.gaoshouyou.com/d/60/17/2460921367173ea7145f11194a6f2587.apk</item>-->
|
||||
<!--<item>http://static.gaoshouyou.com/d/32/e0/1a32123ecbe0ee010d35479df248f90f.apk</item>-->
|
||||
<!--<item>http://static.gaoshouyou.com/d/22/94/822260b849944492caadd2983f9bb624.apk</item>-->
|
||||
<!--<item>http://static.gaoshouyou.com/d/e6/f5/4de6329f9cf5dc3a1d1e6bbcca0d003c.apk</item>-->
|
||||
<!--<item>http://static.gaoshouyou.com/d/6e/e5/ff6ecaaf45e532e6d07747af82357472.apk</item>-->
|
||||
<!--<item>http://static.gaoshouyou.com/d/36/69/2d3699acfa69e9632262442c46516ad8.apk</item>-->
|
||||
</string-array>
|
||||
</resources>
|
||||
|
@ -1,23 +1,25 @@
|
||||
<resources>
|
||||
|
||||
<!-- Base application theme. -->
|
||||
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
|
||||
<!-- Customize your theme here. -->
|
||||
<item name="colorPrimary">@color/colorPrimary</item>
|
||||
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
|
||||
<item name="colorAccent">@color/colorAccent</item>
|
||||
</style>
|
||||
<!-- Base application theme. -->
|
||||
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
|
||||
<!-- Customize your theme here. -->
|
||||
<item name="colorPrimary">@color/colorPrimary</item>
|
||||
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
|
||||
<item name="colorAccent">@color/colorAccent</item>
|
||||
<item name="windowActionBar">false</item>
|
||||
<item name="windowNoTitle">true</item>
|
||||
</style>
|
||||
|
||||
<style name="AppTheme.NoActionBar">
|
||||
<item name="windowActionBar">false</item>
|
||||
<item name="windowNoTitle">true</item>
|
||||
<item name="colorPrimary">@color/colorPrimary</item>
|
||||
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
|
||||
<item name="colorAccent">@color/colorAccent</item>
|
||||
</style>
|
||||
<style name="AppTheme.NoActionBar">
|
||||
<item name="windowActionBar">false</item>
|
||||
<item name="windowNoTitle">true</item>
|
||||
<item name="colorPrimary">@color/colorPrimary</item>
|
||||
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
|
||||
<item name="colorAccent">@color/colorAccent</item>
|
||||
</style>
|
||||
|
||||
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar"/>
|
||||
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar"/>
|
||||
|
||||
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light"/>
|
||||
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light"/>
|
||||
|
||||
</resources>
|
||||
|
@ -1,14 +0,0 @@
|
||||
package com.example.arial.downloaddemo;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* To work on unit tests, switch the Test Artifact in the Build Variants view.
|
||||
*/
|
||||
public class ExampleUnitTest {
|
||||
@Test public void addition_isCorrect() throws Exception {
|
||||
assertEquals(4, 2 + 2);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user