bug fix
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.
229
.idea/codeStyleSettings.xml
generated
Normal file
229
.idea/codeStyleSettings.xml
generated
Normal file
@ -0,0 +1,229 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectCodeStyleSettingsManager">
|
||||||
|
<option name="PER_PROJECT_SETTINGS">
|
||||||
|
<value>
|
||||||
|
<option name="CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND" value="99" />
|
||||||
|
<option name="NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND" value="99" />
|
||||||
|
<option name="PACKAGES_TO_USE_IMPORT_ON_DEMAND">
|
||||||
|
<value />
|
||||||
|
</option>
|
||||||
|
<option name="IMPORT_LAYOUT_TABLE">
|
||||||
|
<value>
|
||||||
|
<package name="android" withSubpackages="true" static="false" />
|
||||||
|
<emptyLine />
|
||||||
|
<package name="com" withSubpackages="true" static="false" />
|
||||||
|
<emptyLine />
|
||||||
|
<package name="junit" withSubpackages="true" static="false" />
|
||||||
|
<emptyLine />
|
||||||
|
<package name="net" withSubpackages="true" static="false" />
|
||||||
|
<emptyLine />
|
||||||
|
<package name="org" withSubpackages="true" static="false" />
|
||||||
|
<emptyLine />
|
||||||
|
<package name="java" withSubpackages="true" static="false" />
|
||||||
|
<emptyLine />
|
||||||
|
<package name="javax" withSubpackages="true" static="false" />
|
||||||
|
<emptyLine />
|
||||||
|
<package name="" withSubpackages="true" static="false" />
|
||||||
|
<emptyLine />
|
||||||
|
<package name="" withSubpackages="true" static="true" />
|
||||||
|
<emptyLine />
|
||||||
|
</value>
|
||||||
|
</option>
|
||||||
|
<option name="RIGHT_MARGIN" value="100" />
|
||||||
|
<AndroidXmlCodeStyleSettings>
|
||||||
|
<option name="USE_CUSTOM_SETTINGS" value="true" />
|
||||||
|
</AndroidXmlCodeStyleSettings>
|
||||||
|
<Objective-C-extensions>
|
||||||
|
<option name="GENERATE_INSTANCE_VARIABLES_FOR_PROPERTIES" value="ASK" />
|
||||||
|
<option name="RELEASE_STYLE" value="IVAR" />
|
||||||
|
<option name="TYPE_QUALIFIERS_PLACEMENT" value="BEFORE" />
|
||||||
|
<file>
|
||||||
|
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Import" />
|
||||||
|
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Macro" />
|
||||||
|
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Typedef" />
|
||||||
|
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Enum" />
|
||||||
|
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Constant" />
|
||||||
|
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Global" />
|
||||||
|
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Struct" />
|
||||||
|
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="FunctionPredecl" />
|
||||||
|
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Function" />
|
||||||
|
</file>
|
||||||
|
<class>
|
||||||
|
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Property" />
|
||||||
|
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Synthesize" />
|
||||||
|
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="InitMethod" />
|
||||||
|
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="StaticMethod" />
|
||||||
|
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="InstanceMethod" />
|
||||||
|
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="DeallocMethod" />
|
||||||
|
</class>
|
||||||
|
<extensions>
|
||||||
|
<pair source="cpp" header="h" />
|
||||||
|
<pair source="c" header="h" />
|
||||||
|
</extensions>
|
||||||
|
</Objective-C-extensions>
|
||||||
|
<XML>
|
||||||
|
<option name="XML_LEGACY_SETTINGS_IMPORTED" value="true" />
|
||||||
|
</XML>
|
||||||
|
<codeStyleSettings language="XML">
|
||||||
|
<option name="FORCE_REARRANGE_MODE" value="1" />
|
||||||
|
<indentOptions>
|
||||||
|
<option name="CONTINUATION_INDENT_SIZE" value="4" />
|
||||||
|
</indentOptions>
|
||||||
|
<arrangement>
|
||||||
|
<rules>
|
||||||
|
<section>
|
||||||
|
<rule>
|
||||||
|
<match>
|
||||||
|
<AND>
|
||||||
|
<NAME>xmlns:android</NAME>
|
||||||
|
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||||
|
</AND>
|
||||||
|
</match>
|
||||||
|
</rule>
|
||||||
|
</section>
|
||||||
|
<section>
|
||||||
|
<rule>
|
||||||
|
<match>
|
||||||
|
<AND>
|
||||||
|
<NAME>xmlns:.*</NAME>
|
||||||
|
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||||
|
</AND>
|
||||||
|
</match>
|
||||||
|
<order>BY_NAME</order>
|
||||||
|
</rule>
|
||||||
|
</section>
|
||||||
|
<section>
|
||||||
|
<rule>
|
||||||
|
<match>
|
||||||
|
<AND>
|
||||||
|
<NAME>.*:id</NAME>
|
||||||
|
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||||
|
</AND>
|
||||||
|
</match>
|
||||||
|
</rule>
|
||||||
|
</section>
|
||||||
|
<section>
|
||||||
|
<rule>
|
||||||
|
<match>
|
||||||
|
<AND>
|
||||||
|
<NAME>.*:name</NAME>
|
||||||
|
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||||
|
</AND>
|
||||||
|
</match>
|
||||||
|
</rule>
|
||||||
|
</section>
|
||||||
|
<section>
|
||||||
|
<rule>
|
||||||
|
<match>
|
||||||
|
<AND>
|
||||||
|
<NAME>name</NAME>
|
||||||
|
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||||
|
</AND>
|
||||||
|
</match>
|
||||||
|
</rule>
|
||||||
|
</section>
|
||||||
|
<section>
|
||||||
|
<rule>
|
||||||
|
<match>
|
||||||
|
<AND>
|
||||||
|
<NAME>style</NAME>
|
||||||
|
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||||
|
</AND>
|
||||||
|
</match>
|
||||||
|
</rule>
|
||||||
|
</section>
|
||||||
|
<section>
|
||||||
|
<rule>
|
||||||
|
<match>
|
||||||
|
<AND>
|
||||||
|
<NAME>.*</NAME>
|
||||||
|
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||||
|
</AND>
|
||||||
|
</match>
|
||||||
|
<order>BY_NAME</order>
|
||||||
|
</rule>
|
||||||
|
</section>
|
||||||
|
<section>
|
||||||
|
<rule>
|
||||||
|
<match>
|
||||||
|
<AND>
|
||||||
|
<NAME>.*:layout_width</NAME>
|
||||||
|
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||||
|
</AND>
|
||||||
|
</match>
|
||||||
|
</rule>
|
||||||
|
</section>
|
||||||
|
<section>
|
||||||
|
<rule>
|
||||||
|
<match>
|
||||||
|
<AND>
|
||||||
|
<NAME>.*:layout_height</NAME>
|
||||||
|
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||||
|
</AND>
|
||||||
|
</match>
|
||||||
|
</rule>
|
||||||
|
</section>
|
||||||
|
<section>
|
||||||
|
<rule>
|
||||||
|
<match>
|
||||||
|
<AND>
|
||||||
|
<NAME>.*:layout_.*</NAME>
|
||||||
|
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||||
|
</AND>
|
||||||
|
</match>
|
||||||
|
<order>BY_NAME</order>
|
||||||
|
</rule>
|
||||||
|
</section>
|
||||||
|
<section>
|
||||||
|
<rule>
|
||||||
|
<match>
|
||||||
|
<AND>
|
||||||
|
<NAME>.*:width</NAME>
|
||||||
|
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||||
|
</AND>
|
||||||
|
</match>
|
||||||
|
<order>BY_NAME</order>
|
||||||
|
</rule>
|
||||||
|
</section>
|
||||||
|
<section>
|
||||||
|
<rule>
|
||||||
|
<match>
|
||||||
|
<AND>
|
||||||
|
<NAME>.*:height</NAME>
|
||||||
|
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||||
|
</AND>
|
||||||
|
</match>
|
||||||
|
<order>BY_NAME</order>
|
||||||
|
</rule>
|
||||||
|
</section>
|
||||||
|
<section>
|
||||||
|
<rule>
|
||||||
|
<match>
|
||||||
|
<AND>
|
||||||
|
<NAME>.*</NAME>
|
||||||
|
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||||
|
</AND>
|
||||||
|
</match>
|
||||||
|
<order>BY_NAME</order>
|
||||||
|
</rule>
|
||||||
|
</section>
|
||||||
|
<section>
|
||||||
|
<rule>
|
||||||
|
<match>
|
||||||
|
<AND>
|
||||||
|
<NAME>.*</NAME>
|
||||||
|
<XML_NAMESPACE>.*</XML_NAMESPACE>
|
||||||
|
</AND>
|
||||||
|
</match>
|
||||||
|
<order>BY_NAME</order>
|
||||||
|
</rule>
|
||||||
|
</section>
|
||||||
|
</rules>
|
||||||
|
</arrangement>
|
||||||
|
</codeStyleSettings>
|
||||||
|
</value>
|
||||||
|
</option>
|
||||||
|
<option name="PREFERRED_PROJECT_CODE_STYLE" value="aria" />
|
||||||
|
</component>
|
||||||
|
</project>
|
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
@ -37,7 +37,7 @@
|
|||||||
<ConfirmationsSetting value="0" id="Add" />
|
<ConfirmationsSetting value="0" id="Add" />
|
||||||
<ConfirmationsSetting value="0" id="Remove" />
|
<ConfirmationsSetting value="0" id="Remove" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectType">
|
<component name="ProjectType">
|
||||||
|
1
.idea/modules.xml
generated
1
.idea/modules.xml
generated
@ -3,6 +3,7 @@
|
|||||||
<component name="ProjectModuleManager">
|
<component name="ProjectModuleManager">
|
||||||
<modules>
|
<modules>
|
||||||
<module fileurl="file://$PROJECT_DIR$/DownloadPrj.iml" filepath="$PROJECT_DIR$/DownloadPrj.iml" />
|
<module fileurl="file://$PROJECT_DIR$/DownloadPrj.iml" filepath="$PROJECT_DIR$/DownloadPrj.iml" />
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/DownloadUtil.iml" filepath="$PROJECT_DIR$/DownloadUtil.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>
|
||||||
|
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -13,7 +13,7 @@
|
|||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
android:theme="@style/AppTheme">
|
android:theme="@style/AppTheme">
|
||||||
<!--android:name=".activity.SimpleTestActivity"-->
|
<!--android:name=".activity.SingleTaskActivity"-->
|
||||||
<activity
|
<activity
|
||||||
android:name=".activity.MainActivity"
|
android:name=".activity.MainActivity"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
@ -24,6 +24,9 @@
|
|||||||
<category android:name="android.intent.category.LAUNCHER"/>
|
<category android:name="android.intent.category.LAUNCHER"/>
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
|
<activity android:name=".activity.SingleTaskActivity"/>
|
||||||
|
<activity android:name=".activity.MultiTaskActivity"/>
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
||||||
|
@ -1,29 +1,19 @@
|
|||||||
package com.arialyy.simple.activity;
|
package com.arialyy.simple.activity;
|
||||||
|
|
||||||
import android.content.BroadcastReceiver;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v7.widget.LinearLayoutManager;
|
import android.support.v7.widget.Toolbar;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.view.View;
|
||||||
|
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.R;
|
||||||
import com.arialyy.simple.adapter.DownloadAdapter;
|
|
||||||
import com.arialyy.simple.base.BaseActivity;
|
import com.arialyy.simple.base.BaseActivity;
|
||||||
import com.arialyy.simple.databinding.ActivityMainBinding;
|
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> {
|
public class MainActivity extends BaseActivity<ActivityMainBinding> {
|
||||||
@Bind(R.id.list) RecyclerView mList;
|
@Bind(R.id.toolbar) Toolbar mBar;
|
||||||
DownloadAdapter mAdapter;
|
|
||||||
|
|
||||||
@Override protected int setLayoutId() {
|
@Override protected int setLayoutId() {
|
||||||
return R.layout.activity_main;
|
return R.layout.activity_main;
|
||||||
@ -31,60 +21,18 @@ public class MainActivity extends BaseActivity<ActivityMainBinding> {
|
|||||||
|
|
||||||
@Override protected void init(Bundle savedInstanceState) {
|
@Override protected void init(Bundle savedInstanceState) {
|
||||||
super.init(savedInstanceState);
|
super.init(savedInstanceState);
|
||||||
mAdapter = new DownloadAdapter(this, getModule(DownloadModule.class).getDownloadData());
|
setSupportActionBar(mBar);
|
||||||
mList.setLayoutManager(new LinearLayoutManager(this));
|
mBar.setTitle("多线程多任务下载");
|
||||||
mList.setAdapter(mAdapter);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void onClick(View view) {
|
||||||
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
switch (view.getId()) {
|
||||||
long len = 0;
|
case R.id.single_task:
|
||||||
|
startActivity(new Intent(this, SingleTaskActivity.class));
|
||||||
@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;
|
break;
|
||||||
case DownloadManager.ACTION_START:
|
case R.id.multi_task:
|
||||||
L.d(TAG, "download start");
|
startActivity(new Intent(this, MultiTaskActivity.class));
|
||||||
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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
@Override protected void onResume() {
|
|
||||||
super.onResume();
|
|
||||||
registerReceiver(mReceiver, getModule(DownloadModule.class).getDownloadFilter());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override protected void onDestroy() {
|
|
||||||
super.onDestroy();
|
|
||||||
unregisterReceiver(mReceiver);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,94 @@
|
|||||||
|
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 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;
|
||||||
|
|
||||||
|
import butterknife.Bind;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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);
|
||||||
|
}
|
||||||
|
}
|
@ -23,7 +23,7 @@ import com.arialyy.downloadutil.util.Util;
|
|||||||
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.base.BaseActivity;
|
import com.arialyy.simple.base.BaseActivity;
|
||||||
import com.arialyy.simple.databinding.ActivitySimpleBinding;
|
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;
|
||||||
@ -31,7 +31,7 @@ import java.util.List;
|
|||||||
|
|
||||||
import butterknife.Bind;
|
import butterknife.Bind;
|
||||||
|
|
||||||
public class SimpleTestActivity extends BaseActivity<ActivitySimpleBinding> {
|
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;
|
||||||
private static final int DOWNLOAD_FAILE = 0x03;
|
private static final int DOWNLOAD_FAILE = 0x03;
|
||||||
@ -56,28 +56,28 @@ public class SimpleTestActivity extends BaseActivity<ActivitySimpleBinding> {
|
|||||||
setBtState(false);
|
setBtState(false);
|
||||||
break;
|
break;
|
||||||
case DOWNLOAD_FAILE:
|
case DOWNLOAD_FAILE:
|
||||||
Toast.makeText(SimpleTestActivity.this, "下载失败", Toast.LENGTH_SHORT).show();
|
Toast.makeText(SingleTaskActivity.this, "下载失败", Toast.LENGTH_SHORT).show();
|
||||||
setBtState(true);
|
setBtState(true);
|
||||||
break;
|
break;
|
||||||
case DOWNLOAD_STOP:
|
case DOWNLOAD_STOP:
|
||||||
Toast.makeText(SimpleTestActivity.this, "暂停下载", Toast.LENGTH_SHORT).show();
|
Toast.makeText(SingleTaskActivity.this, "暂停下载", Toast.LENGTH_SHORT).show();
|
||||||
mStart.setText("恢复");
|
mStart.setText("恢复");
|
||||||
setBtState(true);
|
setBtState(true);
|
||||||
break;
|
break;
|
||||||
case DOWNLOAD_CANCEL:
|
case DOWNLOAD_CANCEL:
|
||||||
mPb.setProgress(0);
|
mPb.setProgress(0);
|
||||||
Toast.makeText(SimpleTestActivity.this, "取消下载", Toast.LENGTH_SHORT).show();
|
Toast.makeText(SingleTaskActivity.this, "取消下载", Toast.LENGTH_SHORT).show();
|
||||||
mStart.setText("开始");
|
mStart.setText("开始");
|
||||||
setBtState(true);
|
setBtState(true);
|
||||||
break;
|
break;
|
||||||
case DOWNLOAD_RESUME:
|
case DOWNLOAD_RESUME:
|
||||||
Toast.makeText(SimpleTestActivity.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:
|
||||||
Toast.makeText(SimpleTestActivity.this, "下载完成", Toast.LENGTH_SHORT).show();
|
Toast.makeText(SingleTaskActivity.this, "下载完成", Toast.LENGTH_SHORT).show();
|
||||||
mStart.setText("重新开始?");
|
mStart.setText("重新开始?");
|
||||||
mCancel.setEnabled(false);
|
mCancel.setEnabled(false);
|
||||||
setBtState(true);
|
setBtState(true);
|
||||||
@ -157,14 +157,14 @@ public class SimpleTestActivity extends BaseActivity<ActivitySimpleBinding> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override protected int setLayoutId() {
|
@Override protected int setLayoutId() {
|
||||||
return R.layout.activity_simple;
|
return R.layout.activity_single;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override protected void init(Bundle savedInstanceState) {
|
@Override protected void init(Bundle savedInstanceState) {
|
||||||
super.init(savedInstanceState);
|
super.init(savedInstanceState);
|
||||||
setSupportActionBar(toolbar);
|
setSupportActionBar(toolbar);
|
||||||
|
toolbar.setTitle("单任务下载");
|
||||||
init();
|
init();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void init() {
|
private void init() {
|
@ -3,7 +3,6 @@ package com.arialyy.simple.module;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
|
|
||||||
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.downloadutil.util.Util;
|
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.frame.util.StringUtil;
|
||||||
import com.arialyy.simple.R;
|
import com.arialyy.simple.R;
|
||||||
import com.arialyy.simple.base.BaseModule;
|
import com.arialyy.simple.base.BaseModule;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -26,21 +24,49 @@ public class DownloadModule extends BaseModule {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置下载数据
|
* 设置下载数据
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
public List<DownloadEntity> getDownloadData() {
|
public List<DownloadEntity> getDownloadData() {
|
||||||
List<DownloadEntity> list = DownloadEntity.findAllData(DownloadEntity.class);
|
List<DownloadEntity> list = DownloadEntity.findAllData(DownloadEntity.class);
|
||||||
|
List<DownloadEntity> newDownload = createNewDownload();
|
||||||
if (list == null) {
|
if (list == null) {
|
||||||
list = createNewDownload();
|
list = newDownload;
|
||||||
|
} else {
|
||||||
|
list = filter(list, newDownload);
|
||||||
}
|
}
|
||||||
return list;
|
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;
|
||||||
|
}
|
||||||
|
count++;
|
||||||
|
if (count == sqlEntity.size()) {
|
||||||
|
list.add(cEntity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建下载列表
|
||||||
|
*/
|
||||||
private List<DownloadEntity> createNewDownload() {
|
private List<DownloadEntity> createNewDownload() {
|
||||||
List<DownloadEntity> list = new ArrayList<>();
|
List<DownloadEntity> list = new ArrayList<>();
|
||||||
String[] urls = getContext().getResources()
|
String[] urls = getContext().getResources().getStringArray(R.array.test_apk_download_url);
|
||||||
.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();
|
||||||
@ -54,8 +80,6 @@ public class DownloadModule extends BaseModule {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 下载广播过滤器
|
* 下载广播过滤器
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
public IntentFilter getDownloadFilter() {
|
public IntentFilter getDownloadFilter() {
|
||||||
IntentFilter filter = new IntentFilter();
|
IntentFilter filter = new IntentFilter();
|
||||||
@ -71,10 +95,13 @@ public class DownloadModule extends BaseModule {
|
|||||||
return filter;
|
return filter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置下载队列
|
||||||
|
*/
|
||||||
private String getDownloadPath(String url) {
|
private String getDownloadPath(String url) {
|
||||||
String path = Environment.getExternalStorageDirectory()
|
String path =
|
||||||
.getPath() + "/" + AndroidUtils.getAppName(getContext()) + "downloads/" + StringUtil
|
Environment.getExternalStorageDirectory().getPath() + "/" + AndroidUtils.getAppName(
|
||||||
.keyToHashKey(url) + ".apk";
|
getContext()) + "downloads/" + StringUtil.keyToHashKey(url) + ".apk";
|
||||||
File file = new File(path);
|
File file = new File(path);
|
||||||
if (!file.getParentFile().exists()) {
|
if (!file.getParentFile().exists()) {
|
||||||
file.getParentFile().mkdirs();
|
file.getParentFile().mkdirs();
|
||||||
|
@ -1,6 +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">
|
>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
@ -8,10 +8,24 @@
|
|||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
>
|
>
|
||||||
|
|
||||||
<android.support.v7.widget.RecyclerView
|
<include layout="@layout/layout_bar"/>
|
||||||
android:id="@+id/list"
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/single_task"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="wrap_content"
|
||||||
|
android:onClick="onClick"
|
||||||
|
android:text="单任务下载"
|
||||||
|
style="?buttonBarButtonStyle"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<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>
|
||||||
|
21
app/src/main/res/layout/activity_multi.xml
Normal file
21
app/src/main/res/layout/activity_multi.xml
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<layout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
>
|
||||||
|
|
||||||
|
<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>
|
@ -2,13 +2,12 @@
|
|||||||
<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: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"
|
||||||
android:fitsSystemWindows="true"
|
android:fitsSystemWindows="true"
|
||||||
tools:context="com.arialyy.simple.activity.SimpleTestActivity"
|
tools:context="com.arialyy.simple.activity.SingleTaskActivity"
|
||||||
>
|
>
|
||||||
|
|
||||||
<android.support.design.widget.AppBarLayout
|
<android.support.design.widget.AppBarLayout
|
||||||
@ -17,17 +16,11 @@
|
|||||||
android:theme="@style/AppTheme.AppBarOverlay"
|
android:theme="@style/AppTheme.AppBarOverlay"
|
||||||
>
|
>
|
||||||
|
|
||||||
<android.support.v7.widget.Toolbar
|
<include layout="@layout/layout_bar"/>
|
||||||
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>
|
</android.support.design.widget.AppBarLayout>
|
||||||
|
|
||||||
<include layout="@layout/content_simple"/>
|
<include layout="@layout/content_single"/>
|
||||||
|
|
||||||
<android.support.design.widget.FloatingActionButton
|
<android.support.design.widget.FloatingActionButton
|
||||||
android:id="@+id/fab"
|
android:id="@+id/fab"
|
@ -5,8 +5,8 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
app:layout_behavior="@string/appbar_scrolling_view_behavior"
|
app:layout_behavior="@string/appbar_scrolling_view_behavior"
|
||||||
tools:context="com.arialyy.simple.activity.SimpleTestActivity"
|
tools:context="com.arialyy.simple.activity.SingleTaskActivity"
|
||||||
tools:showIn="@layout/activity_simple"
|
tools:showIn="@layout/activity_single"
|
||||||
>
|
>
|
||||||
|
|
||||||
<ProgressBar
|
<ProgressBar
|
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"
|
||||||
|
/>
|
@ -9,4 +9,20 @@
|
|||||||
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
|
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
|
||||||
<item name="colorAccent">@color/colorAccent</item>
|
<item name="colorAccent">@color/colorAccent</item>
|
||||||
</style>
|
</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>
|
</resources>
|
||||||
|
@ -6,6 +6,8 @@
|
|||||||
<item name="colorPrimary">@color/colorPrimary</item>
|
<item name="colorPrimary">@color/colorPrimary</item>
|
||||||
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
|
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
|
||||||
<item name="colorAccent">@color/colorAccent</item>
|
<item name="colorAccent">@color/colorAccent</item>
|
||||||
|
<item name="windowActionBar">false</item>
|
||||||
|
<item name="windowNoTitle">true</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="AppTheme.NoActionBar">
|
<style name="AppTheme.NoActionBar">
|
||||||
|
0
cache/build/mPro.properties
vendored
Normal file
0
cache/build/mPro.properties
vendored
Normal file
@ -142,11 +142,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) { //网络被劫持时会出现这个问题
|
||||||
@ -290,11 +290,11 @@ final class DownLoadUtil {
|
|||||||
"bytes=" + dEntity.startLocation + "-" + dEntity.endLocation);
|
"bytes=" + dEntity.startLocation + "-" + dEntity.endLocation);
|
||||||
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.setReadTimeout(TIME_OUT * 24); //设置读取流的等待时间,必须设置该参数
|
conn.setReadTimeout(TIME_OUT * 24); //设置读取流的等待时间,必须设置该参数
|
||||||
InputStream is = conn.getInputStream();
|
InputStream is = conn.getInputStream();
|
||||||
//创建可设置位置的文件
|
//创建可设置位置的文件
|
||||||
@ -323,6 +323,7 @@ final class DownLoadUtil {
|
|||||||
}
|
}
|
||||||
file.close();
|
file.close();
|
||||||
is.close();
|
is.close();
|
||||||
|
|
||||||
if (isCancel) {
|
if (isCancel) {
|
||||||
synchronized (DownLoadUtil.this) {
|
synchronized (DownLoadUtil.this) {
|
||||||
mCancelNum++;
|
mCancelNum++;
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
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;
|
||||||
|
Reference in New Issue
Block a user