没做啥
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
6
.idea/codeStyleSettings.xml
generated
6
.idea/codeStyleSettings.xml
generated
@ -63,7 +63,9 @@
|
|||||||
</extensions>
|
</extensions>
|
||||||
</Objective-C-extensions>
|
</Objective-C-extensions>
|
||||||
<XML>
|
<XML>
|
||||||
<option name="XML_LEGACY_SETTINGS_IMPORTED" value="true" />
|
<option name="XML_KEEP_LINE_BREAKS" value="false" />
|
||||||
|
<option name="XML_ALIGN_ATTRIBUTES" value="false" />
|
||||||
|
<option name="XML_SPACE_INSIDE_EMPTY_TAG" value="true" />
|
||||||
</XML>
|
</XML>
|
||||||
<codeStyleSettings language="XML">
|
<codeStyleSettings language="XML">
|
||||||
<option name="FORCE_REARRANGE_MODE" value="1" />
|
<option name="FORCE_REARRANGE_MODE" value="1" />
|
||||||
@ -224,6 +226,6 @@
|
|||||||
</codeStyleSettings>
|
</codeStyleSettings>
|
||||||
</value>
|
</value>
|
||||||
</option>
|
</option>
|
||||||
<option name="PREFERRED_PROJECT_CODE_STYLE" value="aria" />
|
<option name="PREFERRED_PROJECT_CODE_STYLE" value="SquareAndroid" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
6
.idea/encodings.xml
generated
6
.idea/encodings.xml
generated
@ -1,6 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="Encoding">
|
|
||||||
<file url="PROJECT" charset="UTF-8" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
2
.idea/modules.xml
generated
2
.idea/modules.xml
generated
@ -2,7 +2,7 @@
|
|||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ProjectModuleManager">
|
<component name="ProjectModuleManager">
|
||||||
<modules>
|
<modules>
|
||||||
<module fileurl="file://$PROJECT_DIR$/DownloadUtil.iml" filepath="$PROJECT_DIR$/DownloadUtil.iml" />
|
<module fileurl="file://$PROJECT_DIR$/DownloadPrj.iml" filepath="$PROJECT_DIR$/DownloadPrj.iml" />
|
||||||
<module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
|
<module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
|
||||||
<module fileurl="file://$PROJECT_DIR$/downloadutil/downloadutil.iml" filepath="$PROJECT_DIR$/downloadutil/downloadutil.iml" />
|
<module fileurl="file://$PROJECT_DIR$/downloadutil/downloadutil.iml" filepath="$PROJECT_DIR$/downloadutil/downloadutil.iml" />
|
||||||
</modules>
|
</modules>
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
apply plugin: 'com.android.application'
|
apply plugin: 'com.android.application'
|
||||||
|
|
||||||
android {
|
android {
|
||||||
compileSdkVersion 'Google Inc.:Google APIs:23'
|
compileSdkVersion 23
|
||||||
buildToolsVersion "23.0.2"
|
buildToolsVersion "23.0.2"
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
|
@ -6,8 +6,8 @@ import android.content.Intent;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v7.widget.LinearLayoutManager;
|
import android.support.v7.widget.LinearLayoutManager;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
|
|
||||||
import android.support.v7.widget.Toolbar;
|
import android.support.v7.widget.Toolbar;
|
||||||
|
import butterknife.Bind;
|
||||||
import com.arialyy.downloadutil.core.DownloadManager;
|
import com.arialyy.downloadutil.core.DownloadManager;
|
||||||
import com.arialyy.downloadutil.entity.DownloadEntity;
|
import com.arialyy.downloadutil.entity.DownloadEntity;
|
||||||
import com.arialyy.frame.util.show.L;
|
import com.arialyy.frame.util.show.L;
|
||||||
@ -17,8 +17,6 @@ import com.arialyy.simple.base.BaseActivity;
|
|||||||
import com.arialyy.simple.databinding.ActivityMultiBinding;
|
import com.arialyy.simple.databinding.ActivityMultiBinding;
|
||||||
import com.arialyy.simple.module.DownloadModule;
|
import com.arialyy.simple.module.DownloadModule;
|
||||||
|
|
||||||
import butterknife.Bind;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Lyy on 2016/9/27.
|
* Created by Lyy on 2016/9/27.
|
||||||
*/
|
*/
|
||||||
@ -40,7 +38,6 @@ public class MultiTaskActivity extends BaseActivity<ActivityMultiBinding> {
|
|||||||
mList.setAdapter(mAdapter);
|
mList.setAdapter(mAdapter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
||||||
long len = 0;
|
long len = 0;
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ import android.widget.Button;
|
|||||||
import android.widget.ProgressBar;
|
import android.widget.ProgressBar;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
import butterknife.Bind;
|
||||||
import com.arialyy.downloadutil.core.DownloadManager;
|
import com.arialyy.downloadutil.core.DownloadManager;
|
||||||
import com.arialyy.downloadutil.core.command.CommandFactory;
|
import com.arialyy.downloadutil.core.command.CommandFactory;
|
||||||
import com.arialyy.downloadutil.core.command.IDownloadCommand;
|
import com.arialyy.downloadutil.core.command.IDownloadCommand;
|
||||||
@ -25,12 +25,9 @@ import com.arialyy.simple.R;
|
|||||||
import com.arialyy.simple.base.BaseActivity;
|
import com.arialyy.simple.base.BaseActivity;
|
||||||
import com.arialyy.simple.databinding.ActivitySingleBinding;
|
import com.arialyy.simple.databinding.ActivitySingleBinding;
|
||||||
import com.arialyy.simple.module.DownloadModule;
|
import com.arialyy.simple.module.DownloadModule;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import butterknife.Bind;
|
|
||||||
|
|
||||||
public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
||||||
private static final int DOWNLOAD_PRE = 0x01;
|
private static final int DOWNLOAD_PRE = 0x01;
|
||||||
private static final int DOWNLOAD_STOP = 0x02;
|
private static final int DOWNLOAD_STOP = 0x02;
|
||||||
@ -39,7 +36,8 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
|||||||
private static final int DOWNLOAD_RESUME = 0x05;
|
private static final int DOWNLOAD_RESUME = 0x05;
|
||||||
private static final int DOWNLOAD_COMPLETE = 0x06;
|
private static final int DOWNLOAD_COMPLETE = 0x06;
|
||||||
private ProgressBar mPb;
|
private ProgressBar mPb;
|
||||||
private String mDownloadUrl = "http://static.gaoshouyou.com/d/12/0d/7f120f50c80d2e7b8c4ba24ece4f9cdd.apk";
|
private String mDownloadUrl =
|
||||||
|
"http://static.gaoshouyou.com/d/12/0d/7f120f50c80d2e7b8c4ba24ece4f9cdd.apk";
|
||||||
private Button mStart, mStop, mCancel;
|
private Button mStart, mStop, mCancel;
|
||||||
private TextView mSize;
|
private TextView mSize;
|
||||||
@Bind(R.id.toolbar) Toolbar toolbar;
|
@Bind(R.id.toolbar) Toolbar toolbar;
|
||||||
@ -72,8 +70,7 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
|||||||
break;
|
break;
|
||||||
case DOWNLOAD_RESUME:
|
case DOWNLOAD_RESUME:
|
||||||
Toast.makeText(SingleTaskActivity.this,
|
Toast.makeText(SingleTaskActivity.this,
|
||||||
"恢复下载,恢复位置 ==> " + Util.formatFileSize((Long) msg.obj),
|
"恢复下载,恢复位置 ==> " + Util.formatFileSize((Long) msg.obj), Toast.LENGTH_SHORT).show();
|
||||||
Toast.LENGTH_SHORT).show();
|
|
||||||
setBtState(false);
|
setBtState(false);
|
||||||
break;
|
break;
|
||||||
case DOWNLOAD_COMPLETE:
|
case DOWNLOAD_COMPLETE:
|
||||||
@ -88,8 +85,6 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置start 和 stop 按钮状态
|
* 设置start 和 stop 按钮状态
|
||||||
*
|
|
||||||
* @param state
|
|
||||||
*/
|
*/
|
||||||
private void setBtState(boolean state) {
|
private void setBtState(boolean state) {
|
||||||
mStart.setEnabled(state);
|
mStart.setEnabled(state);
|
||||||
@ -225,24 +220,22 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
|||||||
mEntity.setDownloadUrl(mDownloadUrl);
|
mEntity.setDownloadUrl(mDownloadUrl);
|
||||||
mEntity.setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/test.apk");
|
mEntity.setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/test.apk");
|
||||||
List<IDownloadCommand> commands = new ArrayList<>();
|
List<IDownloadCommand> commands = new ArrayList<>();
|
||||||
IDownloadCommand addCommand = mFactory.createCommand(this, mEntity,
|
IDownloadCommand addCommand = mFactory.createCommand(this, mEntity, CommandFactory.TASK_CREATE);
|
||||||
CommandFactory.TASK_CREATE);
|
IDownloadCommand startCommand =
|
||||||
IDownloadCommand startCommand = mFactory.createCommand(this, mEntity,
|
mFactory.createCommand(this, mEntity, CommandFactory.TASK_START);
|
||||||
CommandFactory.TASK_START);
|
|
||||||
commands.add(addCommand);
|
commands.add(addCommand);
|
||||||
commands.add(startCommand);
|
commands.add(startCommand);
|
||||||
mManager.setCommands(commands).exe();
|
mManager.setCommands(commands).exe();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void stop() {
|
private void stop() {
|
||||||
IDownloadCommand stopCommand = mFactory.createCommand(this, mEntity,
|
IDownloadCommand stopCommand = mFactory.createCommand(this, mEntity, CommandFactory.TASK_STOP);
|
||||||
CommandFactory.TASK_STOP);
|
|
||||||
mManager.setCommand(stopCommand).exe();
|
mManager.setCommand(stopCommand).exe();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void cancel() {
|
private void cancel() {
|
||||||
IDownloadCommand cancelCommand = mFactory.createCommand(this, mEntity,
|
IDownloadCommand cancelCommand =
|
||||||
CommandFactory.TASK_CANCEL);
|
mFactory.createCommand(this, mEntity, CommandFactory.TASK_CANCEL);
|
||||||
mManager.setCommand(cancelCommand).exe();
|
mManager.setCommand(cancelCommand).exe();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ import android.content.Context;
|
|||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
|
import butterknife.Bind;
|
||||||
import com.arialyy.absadapter.common.AbsHolder;
|
import com.arialyy.absadapter.common.AbsHolder;
|
||||||
import com.arialyy.absadapter.recycler_view.AbsRVAdapter;
|
import com.arialyy.absadapter.recycler_view.AbsRVAdapter;
|
||||||
import com.arialyy.downloadutil.core.DownloadManager;
|
import com.arialyy.downloadutil.core.DownloadManager;
|
||||||
@ -14,15 +14,12 @@ import com.arialyy.downloadutil.entity.DownloadEntity;
|
|||||||
import com.arialyy.frame.util.show.L;
|
import com.arialyy.frame.util.show.L;
|
||||||
import com.arialyy.simple.R;
|
import com.arialyy.simple.R;
|
||||||
import com.arialyy.simple.widget.HorizontalProgressBarWithNumber;
|
import com.arialyy.simple.widget.HorizontalProgressBarWithNumber;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import butterknife.Bind;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Lyy on 2016/9/27.
|
* Created by Lyy on 2016/9/27.
|
||||||
* 下载列表适配器
|
* 下载列表适配器
|
||||||
@ -145,24 +142,24 @@ public class DownloadAdapter extends AbsRVAdapter<DownloadEntity, DownloadAdapte
|
|||||||
private void start(DownloadEntity entity) {
|
private void start(DownloadEntity entity) {
|
||||||
|
|
||||||
List<IDownloadCommand> commands = new ArrayList<>();
|
List<IDownloadCommand> commands = new ArrayList<>();
|
||||||
IDownloadCommand addCommand = mFactory.createCommand(getContext(), entity,
|
IDownloadCommand addCommand =
|
||||||
CommandFactory.TASK_CREATE);
|
mFactory.createCommand(getContext(), entity, CommandFactory.TASK_CREATE);
|
||||||
IDownloadCommand startCommand = mFactory.createCommand(getContext(), entity,
|
IDownloadCommand startCommand =
|
||||||
CommandFactory.TASK_START);
|
mFactory.createCommand(getContext(), entity, CommandFactory.TASK_START);
|
||||||
commands.add(addCommand);
|
commands.add(addCommand);
|
||||||
commands.add(startCommand);
|
commands.add(startCommand);
|
||||||
mManager.setCommands(commands).exe();
|
mManager.setCommands(commands).exe();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void stop(DownloadEntity entity) {
|
private void stop(DownloadEntity entity) {
|
||||||
IDownloadCommand stopCommand = mFactory.createCommand(getContext(), entity,
|
IDownloadCommand stopCommand =
|
||||||
CommandFactory.TASK_STOP);
|
mFactory.createCommand(getContext(), entity, CommandFactory.TASK_STOP);
|
||||||
mManager.setCommand(stopCommand).exe();
|
mManager.setCommand(stopCommand).exe();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void cancel(DownloadEntity entity) {
|
private void cancel(DownloadEntity entity) {
|
||||||
IDownloadCommand cancelCommand = mFactory.createCommand(getContext(), entity,
|
IDownloadCommand cancelCommand =
|
||||||
CommandFactory.TASK_CANCEL);
|
mFactory.createCommand(getContext(), entity, CommandFactory.TASK_CANCEL);
|
||||||
mManager.setCommand(cancelCommand).exe();
|
mManager.setCommand(cancelCommand).exe();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@ package com.arialyy.simple.base;
|
|||||||
|
|
||||||
import android.databinding.ViewDataBinding;
|
import android.databinding.ViewDataBinding;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
import com.arialyy.frame.core.AbsActivity;
|
import com.arialyy.frame.core.AbsActivity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package com.arialyy.simple.base;
|
package com.arialyy.simple.base;
|
||||||
|
|
||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
|
|
||||||
import com.arialyy.downloadutil.core.DownloadManager;
|
import com.arialyy.downloadutil.core.DownloadManager;
|
||||||
import com.arialyy.frame.core.AbsFrame;
|
import com.arialyy.frame.core.AbsFrame;
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package com.arialyy.simple.base;
|
package com.arialyy.simple.base;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
import com.arialyy.frame.module.AbsModule;
|
import com.arialyy.frame.module.AbsModule;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -66,7 +66,8 @@ public class DownloadModule extends BaseModule {
|
|||||||
*/
|
*/
|
||||||
private List<DownloadEntity> createNewDownload() {
|
private List<DownloadEntity> createNewDownload() {
|
||||||
List<DownloadEntity> list = new ArrayList<>();
|
List<DownloadEntity> list = new ArrayList<>();
|
||||||
String[] urls = getContext().getResources().getStringArray(R.array.test_apk_download_url);
|
String[] urls =
|
||||||
|
getContext().getResources().getStringArray(R.array.test_apk_download_url);
|
||||||
for (String url : urls) {
|
for (String url : urls) {
|
||||||
String fileName = Util.keyToHashCode(url) + ".apk";
|
String fileName = Util.keyToHashCode(url) + ".apk";
|
||||||
DownloadEntity entity = new DownloadEntity();
|
DownloadEntity entity = new DownloadEntity();
|
||||||
|
@ -7,7 +7,6 @@ import android.graphics.Paint;
|
|||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.util.TypedValue;
|
import android.util.TypedValue;
|
||||||
import android.widget.ProgressBar;
|
import android.widget.ProgressBar;
|
||||||
|
|
||||||
import com.arialyy.simple.R;
|
import com.arialyy.simple.R;
|
||||||
|
|
||||||
public class HorizontalProgressBarWithNumber extends ProgressBar {
|
public class HorizontalProgressBarWithNumber extends ProgressBar {
|
||||||
@ -32,13 +31,13 @@ public class HorizontalProgressBarWithNumber extends ProgressBar {
|
|||||||
/**
|
/**
|
||||||
* offset of draw progress
|
* offset of draw progress
|
||||||
*/
|
*/
|
||||||
protected int mTextOffset = dp2px(
|
protected int mTextOffset =
|
||||||
DEFAULT_SIZE_TEXT_OFFSET);
|
dp2px(DEFAULT_SIZE_TEXT_OFFSET);
|
||||||
/**
|
/**
|
||||||
* height of reached progress bar
|
* height of reached progress bar
|
||||||
*/
|
*/
|
||||||
protected int mReachedProgressBarHeight = dp2px(
|
protected int mReachedProgressBarHeight =
|
||||||
DEFAULT_HEIGHT_REACHED_PROGRESS_BAR);
|
dp2px(DEFAULT_HEIGHT_REACHED_PROGRESS_BAR);
|
||||||
/**
|
/**
|
||||||
* color of reached bar
|
* color of reached bar
|
||||||
*/
|
*/
|
||||||
@ -50,8 +49,8 @@ public class HorizontalProgressBarWithNumber extends ProgressBar {
|
|||||||
/**
|
/**
|
||||||
* height of unreached progress bar
|
* height of unreached progress bar
|
||||||
*/
|
*/
|
||||||
protected int mUnReachedProgressBarHeight = dp2px(
|
protected int mUnReachedProgressBarHeight =
|
||||||
DEFAULT_HEIGHT_UNREACHED_PROGRESS_BAR);
|
dp2px(DEFAULT_HEIGHT_UNREACHED_PROGRESS_BAR);
|
||||||
/**
|
/**
|
||||||
* view width except padding
|
* view width except padding
|
||||||
*/
|
*/
|
||||||
@ -86,9 +85,7 @@ public class HorizontalProgressBarWithNumber extends ProgressBar {
|
|||||||
} else {
|
} else {
|
||||||
float textHeight = (mPaint.descent() - mPaint.ascent());
|
float textHeight = (mPaint.descent() - mPaint.ascent());
|
||||||
result = (int) (getPaddingTop() + getPaddingBottom() + Math.max(
|
result = (int) (getPaddingTop() + getPaddingBottom() + Math.max(
|
||||||
Math.max(mReachedProgressBarHeight, mUnReachedProgressBarHeight),
|
Math.max(mReachedProgressBarHeight, mUnReachedProgressBarHeight), Math.abs(textHeight)));
|
||||||
Math.abs(textHeight))
|
|
||||||
);
|
|
||||||
if (specMode == MeasureSpec.AT_MOST) {
|
if (specMode == MeasureSpec.AT_MOST) {
|
||||||
result = Math.min(result, specSize);
|
result = Math.min(result, specSize);
|
||||||
}
|
}
|
||||||
@ -101,17 +98,18 @@ public class HorizontalProgressBarWithNumber extends ProgressBar {
|
|||||||
*/
|
*/
|
||||||
private void obtainStyledAttributes(AttributeSet attrs) {
|
private void obtainStyledAttributes(AttributeSet attrs) {
|
||||||
// init values from custom attributes
|
// init values from custom attributes
|
||||||
final TypedArray attributes = getContext().obtainStyledAttributes(attrs,
|
final TypedArray attributes =
|
||||||
R.styleable.HorizontalProgressBarWithNumber);
|
getContext().obtainStyledAttributes(attrs, R.styleable.HorizontalProgressBarWithNumber);
|
||||||
mTextColor = attributes.getColor(
|
mTextColor =
|
||||||
R.styleable.HorizontalProgressBarWithNumber_progress_text_color,
|
attributes.getColor(R.styleable.HorizontalProgressBarWithNumber_progress_text_color,
|
||||||
DEFAULT_TEXT_COLOR);
|
DEFAULT_TEXT_COLOR);
|
||||||
mTextSize = (int) attributes.getDimension(
|
mTextSize = (int) attributes.getDimension(
|
||||||
R.styleable.HorizontalProgressBarWithNumber_progress_text_size, mTextSize);
|
R.styleable.HorizontalProgressBarWithNumber_progress_text_size, mTextSize);
|
||||||
mReachedBarColor = attributes.getColor(
|
mReachedBarColor =
|
||||||
R.styleable.HorizontalProgressBarWithNumber_progress_reached_color, mTextColor);
|
attributes.getColor(R.styleable.HorizontalProgressBarWithNumber_progress_reached_color,
|
||||||
mUnReachedBarColor = attributes.getColor(
|
mTextColor);
|
||||||
R.styleable.HorizontalProgressBarWithNumber_progress_unreached_color,
|
mUnReachedBarColor =
|
||||||
|
attributes.getColor(R.styleable.HorizontalProgressBarWithNumber_progress_unreached_color,
|
||||||
DEFAULT_COLOR_UNREACHED_COLOR);
|
DEFAULT_COLOR_UNREACHED_COLOR);
|
||||||
mReachedProgressBarHeight = (int) attributes.getDimension(
|
mReachedProgressBarHeight = (int) attributes.getDimension(
|
||||||
R.styleable.HorizontalProgressBarWithNumber_progress_reached_bar_height,
|
R.styleable.HorizontalProgressBarWithNumber_progress_reached_bar_height,
|
||||||
@ -121,8 +119,9 @@ public class HorizontalProgressBarWithNumber extends ProgressBar {
|
|||||||
mUnReachedProgressBarHeight);
|
mUnReachedProgressBarHeight);
|
||||||
mTextOffset = (int) attributes.getDimension(
|
mTextOffset = (int) attributes.getDimension(
|
||||||
R.styleable.HorizontalProgressBarWithNumber_progress_text_offset, mTextOffset);
|
R.styleable.HorizontalProgressBarWithNumber_progress_text_offset, mTextOffset);
|
||||||
int textVisible = attributes.getInt(
|
int textVisible =
|
||||||
R.styleable.HorizontalProgressBarWithNumber_progress_text_visibility, VISIBLE);
|
attributes.getInt(R.styleable.HorizontalProgressBarWithNumber_progress_text_visibility,
|
||||||
|
VISIBLE);
|
||||||
if (textVisible != VISIBLE) {
|
if (textVisible != VISIBLE) {
|
||||||
mIfDrawText = false;
|
mIfDrawText = false;
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<layout
|
<layout
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
|
||||||
>
|
>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
<layout xmlns:android="http://schemas.android.com/apk/res/android">
|
<layout xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
<android.support.design.widget.CoordinatorLayout
|
<android.support.design.widget.CoordinatorLayout
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
@ -3,13 +3,10 @@ package com.arialyy.downloadutil.core;
|
|||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.arialyy.downloadutil.core.command.IDownloadCommand;
|
import com.arialyy.downloadutil.core.command.IDownloadCommand;
|
||||||
import com.arialyy.downloadutil.entity.DownloadEntity;
|
import com.arialyy.downloadutil.entity.DownloadEntity;
|
||||||
import com.arialyy.downloadutil.orm.DbEntity;
|
import com.arialyy.downloadutil.orm.DbEntity;
|
||||||
import com.arialyy.downloadutil.orm.DbUtil;
|
import com.arialyy.downloadutil.orm.DbUtil;
|
||||||
import com.arialyy.downloadutil.util.Task;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -2,7 +2,6 @@ package com.arialyy.downloadutil.core;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.arialyy.downloadutil.entity.DownloadEntity;
|
import com.arialyy.downloadutil.entity.DownloadEntity;
|
||||||
import com.arialyy.downloadutil.util.Task;
|
import com.arialyy.downloadutil.util.Task;
|
||||||
|
|
||||||
|
@ -3,7 +3,6 @@ package com.arialyy.downloadutil.core;
|
|||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.arialyy.downloadutil.core.inf.IDownloader;
|
import com.arialyy.downloadutil.core.inf.IDownloader;
|
||||||
import com.arialyy.downloadutil.core.inf.ITask;
|
import com.arialyy.downloadutil.core.inf.ITask;
|
||||||
import com.arialyy.downloadutil.core.pool.CachePool;
|
import com.arialyy.downloadutil.core.pool.CachePool;
|
||||||
@ -100,8 +99,6 @@ public abstract class IDownloadTarget implements IDownloader, ITask {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取任务执行池
|
* 获取任务执行池
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
public ExecutePool getExecutePool() {
|
public ExecutePool getExecutePool() {
|
||||||
return mExecutePool;
|
return mExecutePool;
|
||||||
|
@ -2,7 +2,6 @@ package com.arialyy.downloadutil.core;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
|
|
||||||
import com.arialyy.downloadutil.entity.DownloadEntity;
|
import com.arialyy.downloadutil.entity.DownloadEntity;
|
||||||
import com.arialyy.downloadutil.util.Task;
|
import com.arialyy.downloadutil.util.Task;
|
||||||
|
|
||||||
|
@ -2,9 +2,8 @@ package com.arialyy.downloadutil.core.command;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.arialyy.downloadutil.util.Task;
|
|
||||||
import com.arialyy.downloadutil.entity.DownloadEntity;
|
import com.arialyy.downloadutil.entity.DownloadEntity;
|
||||||
|
import com.arialyy.downloadutil.util.Task;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by lyy on 2016/8/22.
|
* Created by lyy on 2016/8/22.
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
package com.arialyy.downloadutil.core.command;
|
package com.arialyy.downloadutil.core.command;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
import com.arialyy.downloadutil.util.Task;
|
|
||||||
import com.arialyy.downloadutil.entity.DownloadEntity;
|
import com.arialyy.downloadutil.entity.DownloadEntity;
|
||||||
|
import com.arialyy.downloadutil.util.Task;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by lyy on 2016/9/20.
|
* Created by lyy on 2016/9/20.
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package com.arialyy.downloadutil.core.command;
|
package com.arialyy.downloadutil.core.command;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
import com.arialyy.downloadutil.entity.DownloadEntity;
|
import com.arialyy.downloadutil.entity.DownloadEntity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package com.arialyy.downloadutil.core.command;
|
package com.arialyy.downloadutil.core.command;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
import com.arialyy.downloadutil.core.DownloadTarget;
|
import com.arialyy.downloadutil.core.DownloadTarget;
|
||||||
import com.arialyy.downloadutil.core.IDownloadTarget;
|
import com.arialyy.downloadutil.core.IDownloadTarget;
|
||||||
import com.arialyy.downloadutil.entity.DownloadEntity;
|
import com.arialyy.downloadutil.entity.DownloadEntity;
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
package com.arialyy.downloadutil.core.command;
|
package com.arialyy.downloadutil.core.command;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
import com.arialyy.downloadutil.util.Task;
|
|
||||||
import com.arialyy.downloadutil.entity.DownloadEntity;
|
import com.arialyy.downloadutil.entity.DownloadEntity;
|
||||||
|
import com.arialyy.downloadutil.util.Task;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by lyy on 2016/8/22.
|
* Created by lyy on 2016/8/22.
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package com.arialyy.downloadutil.core.command;
|
package com.arialyy.downloadutil.core.command;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
import com.arialyy.downloadutil.entity.DownloadEntity;
|
import com.arialyy.downloadutil.entity.DownloadEntity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2,7 +2,6 @@ package com.arialyy.downloadutil.core.command;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.arialyy.downloadutil.entity.DownloadEntity;
|
import com.arialyy.downloadutil.entity.DownloadEntity;
|
||||||
import com.arialyy.downloadutil.util.Task;
|
import com.arialyy.downloadutil.util.Task;
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package com.arialyy.downloadutil.core.inf;
|
package com.arialyy.downloadutil.core.inf;
|
||||||
|
|
||||||
import com.arialyy.downloadutil.util.Task;
|
|
||||||
import com.arialyy.downloadutil.entity.DownloadEntity;
|
import com.arialyy.downloadutil.entity.DownloadEntity;
|
||||||
|
import com.arialyy.downloadutil.util.Task;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by lyy on 2016/8/16.
|
* Created by lyy on 2016/8/16.
|
||||||
|
@ -2,11 +2,9 @@ package com.arialyy.downloadutil.core.pool;
|
|||||||
|
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.arialyy.downloadutil.core.inf.IPool;
|
import com.arialyy.downloadutil.core.inf.IPool;
|
||||||
import com.arialyy.downloadutil.util.Task;
|
import com.arialyy.downloadutil.util.Task;
|
||||||
import com.arialyy.downloadutil.util.Util;
|
import com.arialyy.downloadutil.util.Util;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.LinkedBlockingQueue;
|
import java.util.concurrent.LinkedBlockingQueue;
|
||||||
|
@ -2,11 +2,9 @@ package com.arialyy.downloadutil.core.pool;
|
|||||||
|
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.arialyy.downloadutil.util.Task;
|
|
||||||
import com.arialyy.downloadutil.core.inf.IPool;
|
import com.arialyy.downloadutil.core.inf.IPool;
|
||||||
|
import com.arialyy.downloadutil.util.Task;
|
||||||
import com.arialyy.downloadutil.util.Util;
|
import com.arialyy.downloadutil.util.Util;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ArrayBlockingQueue;
|
import java.util.concurrent.ArrayBlockingQueue;
|
||||||
|
@ -2,7 +2,6 @@ package com.arialyy.downloadutil.entity;
|
|||||||
|
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
|
|
||||||
import com.arialyy.downloadutil.orm.DbEntity;
|
import com.arialyy.downloadutil.orm.DbEntity;
|
||||||
import com.arialyy.downloadutil.orm.Ignore;
|
import com.arialyy.downloadutil.orm.Ignore;
|
||||||
|
|
||||||
|
@ -3,10 +3,8 @@ package com.arialyy.downloadutil.help;
|
|||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.arialyy.downloadutil.R;
|
import com.arialyy.downloadutil.R;
|
||||||
import com.arialyy.downloadutil.entity.DownloadEntity;
|
import com.arialyy.downloadutil.entity.DownloadEntity;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package com.arialyy.downloadutil.help;
|
package com.arialyy.downloadutil.help;
|
||||||
|
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
|
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
|
||||||
@ -18,15 +17,11 @@ public class PathHelp {
|
|||||||
* @return 保存路径
|
* @return 保存路径
|
||||||
*/
|
*/
|
||||||
public static String urlconvertPath(String downloadUrl) {
|
public static String urlconvertPath(String downloadUrl) {
|
||||||
return Environment.getDownloadCacheDirectory().getPath() + "/" + StringToHashKey(
|
return Environment.getDownloadCacheDirectory().getPath() + "/" + StringToHashKey(downloadUrl);
|
||||||
downloadUrl);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 字符串转换为hash码
|
* 字符串转换为hash码
|
||||||
*
|
|
||||||
* @param str
|
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
public static String StringToHashKey(String str) {
|
public static String StringToHashKey(String str) {
|
||||||
String cacheKey;
|
String cacheKey;
|
||||||
@ -42,9 +37,6 @@ public class PathHelp {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 将普通字符串转换为16位进制字符串
|
* 将普通字符串转换为16位进制字符串
|
||||||
*
|
|
||||||
* @param src
|
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
public static String bytesToHexString(byte[] src) {
|
public static String bytesToHexString(byte[] src) {
|
||||||
StringBuilder stringBuilder = new StringBuilder("0x");
|
StringBuilder stringBuilder = new StringBuilder("0x");
|
||||||
@ -59,5 +51,4 @@ public class PathHelp {
|
|||||||
}
|
}
|
||||||
return stringBuilder.toString();
|
return stringBuilder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
package com.arialyy.downloadutil.orm;
|
package com.arialyy.downloadutil.orm;
|
||||||
|
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
|
|
||||||
import com.arialyy.downloadutil.util.Util;
|
import com.arialyy.downloadutil.util.Util;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -55,7 +53,6 @@ public class DbEntity {
|
|||||||
mUtil.modifyData(this);
|
mUtil.modifyData(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 保存自身,如果表中已经有数据,则更新数据,否则插入数据
|
* 保存自身,如果表中已经有数据,则更新数据,否则插入数据
|
||||||
*/
|
*/
|
||||||
|
@ -6,9 +6,7 @@ import android.database.Cursor;
|
|||||||
import android.database.sqlite.SQLiteDatabase;
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.arialyy.downloadutil.util.Util;
|
import com.arialyy.downloadutil.util.Util;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@ -375,7 +373,8 @@ public class DbUtil {
|
|||||||
/**
|
/**
|
||||||
* 根据数据游标创建一个具体的对象
|
* 根据数据游标创建一个具体的对象
|
||||||
*/
|
*/
|
||||||
private synchronized <T extends DbEntity> List<T> newInstanceEntity(Class<T> clazz, Cursor cursor) {
|
private synchronized <T extends DbEntity> List<T> newInstanceEntity(Class<T> clazz,
|
||||||
|
Cursor cursor) {
|
||||||
Field[] fields = Util.getFields(clazz);
|
Field[] fields = Util.getFields(clazz);
|
||||||
List<T> entitys = new ArrayList<>();
|
List<T> entitys = new ArrayList<>();
|
||||||
if (fields != null && fields.length > 0) {
|
if (fields != null && fields.length > 0) {
|
||||||
@ -401,8 +400,7 @@ public class DbUtil {
|
|||||||
} else if (type == long.class || type == Long.class) {
|
} else if (type == long.class || type == Long.class) {
|
||||||
field.setLong(entity, cursor.getLong(column));
|
field.setLong(entity, cursor.getLong(column));
|
||||||
} else if (type == boolean.class || type == Boolean.class) {
|
} else if (type == boolean.class || type == Boolean.class) {
|
||||||
field.setBoolean(entity,
|
field.setBoolean(entity, !cursor.getString(column).equalsIgnoreCase("false"));
|
||||||
!cursor.getString(column).equalsIgnoreCase("false"));
|
|
||||||
} else if (type == java.util.Date.class || type == java.sql.Date.class) {
|
} else if (type == java.util.Date.class || type == java.sql.Date.class) {
|
||||||
field.set(entity, new Date(cursor.getString(column)));
|
field.set(entity, new Date(cursor.getString(column)));
|
||||||
} else if (type == byte[].class) {
|
} else if (type == byte[].class) {
|
||||||
|
@ -4,9 +4,7 @@ import android.content.Context;
|
|||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.SparseArray;
|
import android.util.SparseArray;
|
||||||
|
|
||||||
import com.arialyy.downloadutil.entity.DownloadEntity;
|
import com.arialyy.downloadutil.entity.DownloadEntity;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
@ -22,6 +20,7 @@ import java.util.Properties;
|
|||||||
*/
|
*/
|
||||||
final class DownLoadUtil {
|
final class DownLoadUtil {
|
||||||
private static final String TAG = "DownLoadUtil";
|
private static final String TAG = "DownLoadUtil";
|
||||||
|
private static final Object LOCK = new Object();
|
||||||
//下载监听
|
//下载监听
|
||||||
private IDownloadListener mListener;
|
private IDownloadListener mListener;
|
||||||
/**
|
/**
|
||||||
@ -43,7 +42,6 @@ final class DownLoadUtil {
|
|||||||
private Context mContext;
|
private Context mContext;
|
||||||
private DownloadEntity mDownloadEntity;
|
private DownloadEntity mDownloadEntity;
|
||||||
|
|
||||||
|
|
||||||
public DownLoadUtil(Context context, DownloadEntity entity) {
|
public DownLoadUtil(Context context, DownloadEntity entity) {
|
||||||
mContext = context.getApplicationContext();
|
mContext = context.getApplicationContext();
|
||||||
mDownloadEntity = entity;
|
mDownloadEntity = entity;
|
||||||
@ -84,8 +82,8 @@ final class DownLoadUtil {
|
|||||||
public void delConfigFile() {
|
public void delConfigFile() {
|
||||||
if (mContext != null && mDownloadEntity != null) {
|
if (mContext != null && mDownloadEntity != null) {
|
||||||
File dFile = new File(mDownloadEntity.getDownloadPath());
|
File dFile = new File(mDownloadEntity.getDownloadPath());
|
||||||
File config = new File(
|
File config =
|
||||||
mContext.getFilesDir().getPath() + "/temp/" + dFile.getName() + ".properties");
|
new File(mContext.getFilesDir().getPath() + "/temp/" + dFile.getName() + ".properties");
|
||||||
if (config.exists()) {
|
if (config.exists()) {
|
||||||
config.delete();
|
config.delete();
|
||||||
}
|
}
|
||||||
@ -120,8 +118,8 @@ final class DownLoadUtil {
|
|||||||
final String downloadUrl = mDownloadEntity.getDownloadUrl();
|
final String downloadUrl = mDownloadEntity.getDownloadUrl();
|
||||||
final File dFile = new File(filePath);
|
final File dFile = new File(filePath);
|
||||||
//读取已完成的线程数
|
//读取已完成的线程数
|
||||||
final File configFile = new File(
|
final File configFile =
|
||||||
mContext.getFilesDir().getPath() + "/temp/" + dFile.getName() + ".properties");
|
new File(mContext.getFilesDir().getPath() + "/temp/" + dFile.getName() + ".properties");
|
||||||
try {
|
try {
|
||||||
if (!configFile.exists()) { //记录文件被删除,则重新下载
|
if (!configFile.exists()) { //记录文件被删除,则重新下载
|
||||||
isNewTask = true;
|
isNewTask = true;
|
||||||
@ -142,11 +140,11 @@ final class DownLoadUtil {
|
|||||||
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||||
conn.setRequestMethod("GET");
|
conn.setRequestMethod("GET");
|
||||||
conn.setRequestProperty("Charset", "UTF-8");
|
conn.setRequestProperty("Charset", "UTF-8");
|
||||||
|
conn.setConnectTimeout(TIME_OUT * 4);
|
||||||
conn.setRequestProperty("User-Agent",
|
conn.setRequestProperty("User-Agent",
|
||||||
"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.2; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)");
|
"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.2; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)");
|
||||||
conn.setRequestProperty("Accept",
|
conn.setRequestProperty("Accept",
|
||||||
"image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, application/xaml+xml, application/vnd.ms-xpsdocument, application/x-ms-xbap, application/x-ms-application, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*");
|
"image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, application/xaml+xml, application/vnd.ms-xpsdocument, application/x-ms-xbap, application/x-ms-application, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*");
|
||||||
conn.setConnectTimeout(TIME_OUT * 4);
|
|
||||||
conn.connect();
|
conn.connect();
|
||||||
int len = conn.getContentLength();
|
int len = conn.getContentLength();
|
||||||
if (len < 0) { //网络被劫持时会出现这个问题
|
if (len < 0) { //网络被劫持时会出现这个问题
|
||||||
@ -207,8 +205,9 @@ final class DownLoadUtil {
|
|||||||
}
|
}
|
||||||
//分配下载位置
|
//分配下载位置
|
||||||
Object record = pro.getProperty(dFile.getName() + "_record_" + i);
|
Object record = pro.getProperty(dFile.getName() + "_record_" + i);
|
||||||
if (!isNewTask && record != null && Long.parseLong(
|
if (!isNewTask
|
||||||
record + "") > 0) { //如果有记录,则恢复下载
|
&& record != null
|
||||||
|
&& Long.parseLong(record + "") > 0) { //如果有记录,则恢复下载
|
||||||
Long r = Long.parseLong(record + "");
|
Long r = Long.parseLong(record + "");
|
||||||
mCurrentLocation += r - startL;
|
mCurrentLocation += r - startL;
|
||||||
Log.d(TAG, "++++++++++ 线程_" + i + "_恢复下载 ++++++++++");
|
Log.d(TAG, "++++++++++ 线程_" + i + "_恢复下载 ++++++++++");
|
||||||
@ -227,9 +226,8 @@ final class DownLoadUtil {
|
|||||||
//如果整个文件的大小不为线程个数的整数倍,则最后一个线程的结束位置即为文件的总长度
|
//如果整个文件的大小不为线程个数的整数倍,则最后一个线程的结束位置即为文件的总长度
|
||||||
endL = fileLength;
|
endL = fileLength;
|
||||||
}
|
}
|
||||||
ConfigEntity entity = new ConfigEntity(mContext, fileLength,
|
ConfigEntity entity =
|
||||||
downloadUrl, dFile, i, startL,
|
new ConfigEntity(mContext, fileLength, downloadUrl, dFile, i, startL, endL);
|
||||||
endL);
|
|
||||||
DownLoadTask task = new DownLoadTask(entity);
|
DownLoadTask task = new DownLoadTask(entity);
|
||||||
tasks.put(i, new Thread(task));
|
tasks.put(i, new Thread(task));
|
||||||
}
|
}
|
||||||
@ -249,9 +247,12 @@ final class DownLoadUtil {
|
|||||||
failDownload("下载失败,返回码:" + code);
|
failDownload("下载失败,返回码:" + code);
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
failDownload(
|
failDownload("下载失败【downloadUrl:"
|
||||||
"下载失败【downloadUrl:" + downloadUrl + "】\n【filePath:" + filePath + "】" + Util
|
+ downloadUrl
|
||||||
.getPrintException(e));
|
+ "】\n【filePath:"
|
||||||
|
+ filePath
|
||||||
|
+ "】"
|
||||||
|
+ Util.getPrintException(e));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
@ -272,17 +273,25 @@ final class DownLoadUtil {
|
|||||||
private ConfigEntity dEntity;
|
private ConfigEntity dEntity;
|
||||||
private String configFPath;
|
private String configFPath;
|
||||||
|
|
||||||
public DownLoadTask(ConfigEntity downloadInfo) {
|
private DownLoadTask(ConfigEntity downloadInfo) {
|
||||||
this.dEntity = downloadInfo;
|
this.dEntity = downloadInfo;
|
||||||
configFPath = dEntity.context.getFilesDir()
|
configFPath = dEntity.context.getFilesDir().getPath()
|
||||||
.getPath() + "/temp/" + dEntity.tempFile.getName() + ".properties";
|
+ "/temp/"
|
||||||
|
+ dEntity.tempFile.getName()
|
||||||
|
+ ".properties";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void run() {
|
@Override public void run() {
|
||||||
long currentLocation = 0;
|
long currentLocation = 0;
|
||||||
try {
|
try {
|
||||||
Log.d(TAG,
|
Log.d(TAG, "线程_"
|
||||||
"线程_" + dEntity.threadId + "_正在下载【" + "开始位置 : " + dEntity.startLocation + ",结束位置:" + dEntity.endLocation + "】");
|
+ dEntity.threadId
|
||||||
|
+ "_正在下载【"
|
||||||
|
+ "开始位置 : "
|
||||||
|
+ dEntity.startLocation
|
||||||
|
+ ",结束位置:"
|
||||||
|
+ dEntity.endLocation
|
||||||
|
+ "】");
|
||||||
URL url = new URL(dEntity.downloadUrl);
|
URL url = new URL(dEntity.downloadUrl);
|
||||||
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||||
//在头里面请求下载开始位置和结束位置
|
//在头里面请求下载开始位置和结束位置
|
||||||
@ -315,48 +324,19 @@ final class DownLoadUtil {
|
|||||||
}
|
}
|
||||||
//把下载数据数据写入文件
|
//把下载数据数据写入文件
|
||||||
file.write(buffer, 0, len);
|
file.write(buffer, 0, len);
|
||||||
synchronized (DownLoadUtil.this) {
|
progress(len);
|
||||||
mCurrentLocation += len;
|
|
||||||
mListener.onProgress(mCurrentLocation);
|
|
||||||
}
|
|
||||||
currentLocation += len;
|
currentLocation += len;
|
||||||
}
|
}
|
||||||
file.close();
|
file.close();
|
||||||
is.close();
|
is.close();
|
||||||
|
|
||||||
if (isCancel) {
|
if (isCancel) {
|
||||||
synchronized (DownLoadUtil.this) {
|
cancel();
|
||||||
mCancelNum++;
|
|
||||||
if (mCancelNum == THREAD_NUM) {
|
|
||||||
File configFile = new File(configFPath);
|
|
||||||
if (configFile.exists()) {
|
|
||||||
configFile.delete();
|
|
||||||
}
|
|
||||||
if (dEntity.tempFile.exists()) {
|
|
||||||
dEntity.tempFile.delete();
|
|
||||||
}
|
|
||||||
Log.d(TAG, "++++++++++++++++ onCancel +++++++++++++++++");
|
|
||||||
isDownloading = false;
|
|
||||||
mListener.onCancel();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//停止状态不需要删除记录文件
|
//停止状态不需要删除记录文件
|
||||||
if (isStop) {
|
if (isStop) {
|
||||||
synchronized (DownLoadUtil.this) {
|
stop(currentLocation);
|
||||||
mStopNum++;
|
|
||||||
String location = String.valueOf(currentLocation);
|
|
||||||
Log.i(TAG,
|
|
||||||
"thread_" + dEntity.threadId + "_stop, stop location ==> " + currentLocation);
|
|
||||||
writeConfig(dEntity.tempFile.getName() + "_record_" + dEntity.threadId,
|
|
||||||
location);
|
|
||||||
if (mStopNum == THREAD_NUM) {
|
|
||||||
Log.d(TAG, "++++++++++++++++ onStop +++++++++++++++++");
|
|
||||||
isDownloading = false;
|
|
||||||
mListener.onStop(mCurrentLocation);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Log.i(TAG, "线程【" + dEntity.threadId + "】下载完毕");
|
Log.i(TAG, "线程【" + dEntity.threadId + "】下载完毕");
|
||||||
@ -372,42 +352,59 @@ final class DownLoadUtil {
|
|||||||
mListener.onComplete();
|
mListener.onComplete();
|
||||||
}
|
}
|
||||||
} catch (MalformedURLException e) {
|
} catch (MalformedURLException e) {
|
||||||
e.printStackTrace();
|
failDownload(dEntity, currentLocation, "下载链接异常", e);
|
||||||
isDownloading = false;
|
|
||||||
synchronized (DownLoadUtil.this) {
|
|
||||||
try {
|
|
||||||
String location = String.valueOf(currentLocation);
|
|
||||||
writeConfig(dEntity.tempFile.getName() + "_record_" + dEntity.threadId,
|
|
||||||
location);
|
|
||||||
failDownload("下载链接异常");
|
|
||||||
} catch (IOException e1) {
|
|
||||||
e1.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
synchronized (DownLoadUtil.this) {
|
failDownload(dEntity, currentLocation, "下载失败【" + dEntity.downloadUrl + "】", e);
|
||||||
try {
|
|
||||||
String location = String.valueOf(currentLocation);
|
|
||||||
writeConfig(dEntity.tempFile.getName() + "_record_" + dEntity.threadId,
|
|
||||||
location);
|
|
||||||
failDownload(
|
|
||||||
"下载失败【" + dEntity.downloadUrl + "】" + Util.getPrintException(e));
|
|
||||||
} catch (IOException e1) {
|
|
||||||
e1.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
synchronized (DownLoadUtil.this) {
|
failDownload(dEntity, currentLocation, "获取流失败", e);
|
||||||
try {
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 停止下载
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
private void stop(long currentLocation) throws IOException {
|
||||||
|
synchronized (LOCK) {
|
||||||
|
mStopNum++;
|
||||||
String location = String.valueOf(currentLocation);
|
String location = String.valueOf(currentLocation);
|
||||||
writeConfig(dEntity.tempFile.getName() + "_record_" + dEntity.threadId,
|
Log.i(TAG, "thread_" + dEntity.threadId + "_stop, stop location ==> " + currentLocation);
|
||||||
location);
|
writeConfig(dEntity.tempFile.getName() + "_record_" + dEntity.threadId, location);
|
||||||
failDownload("获取流失败" + Util.getPrintException(e));
|
if (mStopNum == THREAD_NUM) {
|
||||||
} catch (IOException e1) {
|
Log.d(TAG, "++++++++++++++++ onStop +++++++++++++++++");
|
||||||
e1.printStackTrace();
|
isDownloading = false;
|
||||||
|
mListener.onStop(mCurrentLocation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 取消下载
|
||||||
|
*/
|
||||||
|
private void cancel() {
|
||||||
|
synchronized (LOCK) {
|
||||||
|
mCancelNum++;
|
||||||
|
if (mCancelNum == THREAD_NUM) {
|
||||||
|
File configFile = new File(configFPath);
|
||||||
|
if (configFile.exists()) {
|
||||||
|
configFile.delete();
|
||||||
|
}
|
||||||
|
if (dEntity.tempFile.exists()) {
|
||||||
|
dEntity.tempFile.delete();
|
||||||
|
}
|
||||||
|
Log.d(TAG, "++++++++++++++++ onCancel +++++++++++++++++");
|
||||||
|
isDownloading = false;
|
||||||
|
mListener.onCancel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void progress(long len) {
|
||||||
|
synchronized (LOCK) {
|
||||||
|
mCurrentLocation += len;
|
||||||
|
mListener.onProgress(mCurrentLocation);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -419,6 +416,30 @@ final class DownLoadUtil {
|
|||||||
pro.setProperty(key, record);
|
pro.setProperty(key, record);
|
||||||
Util.saveConfig(configFile, pro);
|
Util.saveConfig(configFile, pro);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 下载失败
|
||||||
|
*/
|
||||||
|
private void failDownload(ConfigEntity dEntity, long currentLocation, String msg,
|
||||||
|
Exception ex) {
|
||||||
|
synchronized (LOCK) {
|
||||||
|
try {
|
||||||
|
isDownloading = false;
|
||||||
|
isStop = true;
|
||||||
|
Log.e(TAG, msg);
|
||||||
|
if (ex != null) {
|
||||||
|
Log.e(TAG, Util.getPrintException(ex));
|
||||||
|
}
|
||||||
|
if (currentLocation != -1) {
|
||||||
|
String location = String.valueOf(currentLocation);
|
||||||
|
writeConfig(dEntity.tempFile.getName() + "_record_" + dEntity.threadId, location);
|
||||||
|
}
|
||||||
|
mListener.onFail();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -434,8 +455,8 @@ final class DownLoadUtil {
|
|||||||
File tempFile;
|
File tempFile;
|
||||||
Context context;
|
Context context;
|
||||||
|
|
||||||
public ConfigEntity(Context context, long fileSize, String downloadUrl, File file,
|
public ConfigEntity(Context context, long fileSize, String downloadUrl, File file, int threadId,
|
||||||
int threadId, long startLocation, long endLocation) {
|
long startLocation, long endLocation) {
|
||||||
this.fileSize = fileSize;
|
this.fileSize = fileSize;
|
||||||
this.downloadUrl = downloadUrl;
|
this.downloadUrl = downloadUrl;
|
||||||
this.tempFile = file;
|
this.tempFile = file;
|
||||||
|
@ -1,17 +1,13 @@
|
|||||||
package com.arialyy.downloadutil.util;
|
package com.arialyy.downloadutil.util;
|
||||||
|
|
||||||
import android.Manifest;
|
|
||||||
import android.app.AppOpsManager;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.arialyy.downloadutil.core.DownloadManager;
|
import com.arialyy.downloadutil.core.DownloadManager;
|
||||||
import com.arialyy.downloadutil.core.IDownloadTarget;
|
import com.arialyy.downloadutil.core.IDownloadTarget;
|
||||||
import com.arialyy.downloadutil.entity.DownloadEntity;
|
import com.arialyy.downloadutil.entity.DownloadEntity;
|
||||||
|
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -107,9 +103,6 @@ public class Task {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建特定的Intent
|
* 创建特定的Intent
|
||||||
*
|
|
||||||
* @param action
|
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
private Intent createIntent(String action) {
|
private Intent createIntent(String action) {
|
||||||
Uri.Builder builder = new Uri.Builder();
|
Uri.Builder builder = new Uri.Builder();
|
||||||
@ -144,8 +137,7 @@ public class Task {
|
|||||||
long INTERVAL_TIME = 60 * 1000; //10k大小的间隔
|
long INTERVAL_TIME = 60 * 1000; //10k大小的间隔
|
||||||
DownloadEntity downloadEntity;
|
DownloadEntity downloadEntity;
|
||||||
|
|
||||||
DownloadListener(Context context, DownloadEntity downloadEntity,
|
DownloadListener(Context context, DownloadEntity downloadEntity, Handler outHandler) {
|
||||||
Handler outHandler) {
|
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.outHandler = outHandler;
|
this.outHandler = outHandler;
|
||||||
this.downloadEntity = downloadEntity;
|
this.downloadEntity = downloadEntity;
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package com.arialyy.downloadutil.util;
|
package com.arialyy.downloadutil.util;
|
||||||
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
@ -59,9 +58,6 @@ public class Util {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 字符串转hashcode
|
* 字符串转hashcode
|
||||||
*
|
|
||||||
* @param str
|
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
public static int keyToHashCode(String str) {
|
public static int keyToHashCode(String str) {
|
||||||
int total = 0;
|
int total = 0;
|
||||||
|
@ -1,14 +0,0 @@
|
|||||||
package com.arialyy.downloadutil;
|
|
||||||
|
|
||||||
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