没做啥
This commit is contained in:
1
.idea/.name
generated
Normal file
1
.idea/.name
generated
Normal file
@ -0,0 +1 @@
|
|||||||
|
DownloadUtil
|
231
.idea/codeStyleSettings.xml
generated
Normal file
231
.idea/codeStyleSettings.xml
generated
Normal file
@ -0,0 +1,231 @@
|
|||||||
|
<?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_KEEP_LINE_BREAKS" value="false" />
|
||||||
|
<option name="XML_ALIGN_ATTRIBUTES" value="false" />
|
||||||
|
<option name="XML_SPACE_INSIDE_EMPTY_TAG" 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>
|
11
.idea/gradle.xml
generated
11
.idea/gradle.xml
generated
@ -3,9 +3,8 @@
|
|||||||
<component name="GradleSettings">
|
<component name="GradleSettings">
|
||||||
<option name="linkedExternalProjectsSettings">
|
<option name="linkedExternalProjectsSettings">
|
||||||
<GradleProjectSettings>
|
<GradleProjectSettings>
|
||||||
<option name="distributionType" value="LOCAL" />
|
<option name="distributionType" value="DEFAULT_WRAPPED" />
|
||||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||||
<option name="gradleHome" value="C:\Android Studio\gradle\gradle-2.10" />
|
|
||||||
<option name="modules">
|
<option name="modules">
|
||||||
<set>
|
<set>
|
||||||
<option value="$PROJECT_DIR$" />
|
<option value="$PROJECT_DIR$" />
|
||||||
@ -13,7 +12,13 @@
|
|||||||
<option value="$PROJECT_DIR$/downloadutil" />
|
<option value="$PROJECT_DIR$/downloadutil" />
|
||||||
</set>
|
</set>
|
||||||
</option>
|
</option>
|
||||||
<option name="resolveModulePerSourceSet" value="false" />
|
<option name="myModules">
|
||||||
|
<set>
|
||||||
|
<option value="$PROJECT_DIR$" />
|
||||||
|
<option value="$PROJECT_DIR$/app" />
|
||||||
|
<option value="$PROJECT_DIR$/downloadutil" />
|
||||||
|
</set>
|
||||||
|
</option>
|
||||||
</GradleProjectSettings>
|
</GradleProjectSettings>
|
||||||
</option>
|
</option>
|
||||||
</component>
|
</component>
|
||||||
|
16
.idea/misc.xml
generated
16
.idea/misc.xml
generated
@ -27,22 +27,6 @@
|
|||||||
</value>
|
</value>
|
||||||
</option>
|
</option>
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectInspectionProfilesVisibleTreeState">
|
|
||||||
<entry key="Project Default">
|
|
||||||
<profile-state>
|
|
||||||
<expanded-state>
|
|
||||||
<State>
|
|
||||||
<id />
|
|
||||||
</State>
|
|
||||||
</expanded-state>
|
|
||||||
<selected-state>
|
|
||||||
<State>
|
|
||||||
<id>Android</id>
|
|
||||||
</State>
|
|
||||||
</selected-state>
|
|
||||||
</profile-state>
|
|
||||||
</entry>
|
|
||||||
</component>
|
|
||||||
<component name="ProjectLevelVcsManager" settingsEditedManually="false">
|
<component name="ProjectLevelVcsManager" settingsEditedManually="false">
|
||||||
<OptionsSetting value="true" id="Add" />
|
<OptionsSetting value="true" id="Add" />
|
||||||
<OptionsSetting value="true" id="Remove" />
|
<OptionsSetting value="true" id="Remove" />
|
||||||
|
@ -1,22 +1,22 @@
|
|||||||
package com.arialyy.simple.activity;
|
package com.arialyy.simple.activity;
|
||||||
|
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import butterknife.Bind;
|
|
||||||
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.ActivityMainBinding;
|
import com.arialyy.simple.databinding.ActivityMainBinding;
|
||||||
|
|
||||||
|
import butterknife.Bind;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Lyy on 2016/9/27.
|
* Created by Lyy on 2016/9/27.
|
||||||
*/
|
*/
|
||||||
public class MainActivity extends BaseActivity<ActivityMainBinding> {
|
public class MainActivity extends BaseActivity<ActivityMainBinding> {
|
||||||
@Bind(R.id.list)
|
@Bind(R.id.list) RecyclerView mList;
|
||||||
RecyclerView mList;
|
|
||||||
|
|
||||||
@Override protected int setLayoutId() {
|
|
||||||
return R.layout.activity_main;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@Override protected int setLayoutId() {
|
||||||
|
return R.layout.activity_main;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -10,167 +10,166 @@ 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.util.DownLoadUtil;
|
import com.arialyy.downloadutil.util.DownLoadUtil;
|
||||||
import com.arialyy.downloadutil.util.Util;
|
import com.arialyy.downloadutil.util.Util;
|
||||||
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.ActivitySimpleBinding;
|
||||||
|
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
|
|
||||||
|
import butterknife.Bind;
|
||||||
|
|
||||||
public class SimpleTestActivity extends BaseActivity<ActivitySimpleBinding> {
|
public class SimpleTestActivity extends BaseActivity<ActivitySimpleBinding> {
|
||||||
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;
|
||||||
private static final int DOWNLOAD_CANCEL = 0x04;
|
private static final int DOWNLOAD_CANCEL = 0x04;
|
||||||
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 =
|
private String mDownloadUrl = "http://static.gaoshouyou.com/d/12/0d/7f120f50c80d2e7b8c4ba24ece4f9cdd.apk";
|
||||||
"http://static.gaoshouyou.com/d/12/0d/7f120f50c80d2e7b8c4ba24ece4f9cdd.apk";
|
private DownLoadUtil mUtil;
|
||||||
private DownLoadUtil mUtil;
|
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;
|
|
||||||
|
|
||||||
private Handler mUpdateHandler = new Handler() {
|
private Handler mUpdateHandler = new Handler() {
|
||||||
@Override public void handleMessage(Message msg) {
|
@Override public void handleMessage(Message msg) {
|
||||||
super.handleMessage(msg);
|
super.handleMessage(msg);
|
||||||
switch (msg.what) {
|
switch (msg.what) {
|
||||||
case DOWNLOAD_PRE:
|
case DOWNLOAD_PRE:
|
||||||
mSize.setText(Util.formatFileSize((Long) msg.obj));
|
mSize.setText(Util.formatFileSize((Long) msg.obj));
|
||||||
mStart.setEnabled(false);
|
mStart.setEnabled(false);
|
||||||
break;
|
break;
|
||||||
case DOWNLOAD_FAILE:
|
case DOWNLOAD_FAILE:
|
||||||
Toast.makeText(SimpleTestActivity.this, "下载失败", Toast.LENGTH_SHORT).show();
|
Toast.makeText(SimpleTestActivity.this, "下载失败", Toast.LENGTH_SHORT).show();
|
||||||
break;
|
break;
|
||||||
case DOWNLOAD_STOP:
|
case DOWNLOAD_STOP:
|
||||||
Toast.makeText(SimpleTestActivity.this, "暂停下载", Toast.LENGTH_SHORT).show();
|
Toast.makeText(SimpleTestActivity.this, "暂停下载", Toast.LENGTH_SHORT).show();
|
||||||
mStart.setText("恢复");
|
mStart.setText("恢复");
|
||||||
mStart.setEnabled(true);
|
mStart.setEnabled(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(SimpleTestActivity.this, "取消下载", Toast.LENGTH_SHORT).show();
|
||||||
mStart.setEnabled(true);
|
mStart.setEnabled(true);
|
||||||
mStart.setText("开始");
|
mStart.setText("开始");
|
||||||
break;
|
break;
|
||||||
case DOWNLOAD_RESUME:
|
case DOWNLOAD_RESUME:
|
||||||
Toast.makeText(SimpleTestActivity.this, "恢复下载,恢复位置 ==> " + Util.formatFileSize((Long) msg.obj),
|
Toast.makeText(SimpleTestActivity.this, "恢复下载,恢复位置 ==> " + Util.formatFileSize((Long) msg.obj), Toast.LENGTH_SHORT).show();
|
||||||
Toast.LENGTH_SHORT).show();
|
mStart.setEnabled(false);
|
||||||
mStart.setEnabled(false);
|
break;
|
||||||
break;
|
case DOWNLOAD_COMPLETE:
|
||||||
case DOWNLOAD_COMPLETE:
|
Toast.makeText(SimpleTestActivity.this, "下载完成", Toast.LENGTH_SHORT).show();
|
||||||
Toast.makeText(SimpleTestActivity.this, "下载完成", Toast.LENGTH_SHORT).show();
|
mStart.setEnabled(true);
|
||||||
mStart.setEnabled(true);
|
mCancel.setEnabled(false);
|
||||||
mCancel.setEnabled(false);
|
mStop.setEnabled(false);
|
||||||
mStop.setEnabled(false);
|
break;
|
||||||
break;
|
}
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
@Override protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
init();
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
@Override protected void onCreate(Bundle savedInstanceState) {
|
@Override protected int setLayoutId() {
|
||||||
super.onCreate(savedInstanceState);
|
return R.layout.activity_simple;
|
||||||
|
|
||||||
init();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override protected int setLayoutId() {
|
|
||||||
return R.layout.activity_simple;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override protected void init(Bundle savedInstanceState) {
|
|
||||||
super.init(savedInstanceState);
|
|
||||||
setSupportActionBar(toolbar);
|
|
||||||
init();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void init() {
|
|
||||||
mPb = (ProgressBar) findViewById(R.id.progressBar);
|
|
||||||
mStart = (Button) findViewById(R.id.start);
|
|
||||||
mStop = (Button) findViewById(R.id.stop);
|
|
||||||
mCancel = (Button) findViewById(R.id.cancel);
|
|
||||||
mSize = (TextView) findViewById(R.id.size);
|
|
||||||
mUtil = new DownLoadUtil();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onClick(View view) {
|
|
||||||
switch (view.getId()) {
|
|
||||||
case R.id.start:
|
|
||||||
start();
|
|
||||||
break;
|
|
||||||
case R.id.stop:
|
|
||||||
stop();
|
|
||||||
break;
|
|
||||||
case R.id.cancel:
|
|
||||||
cancel();
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private void start() {
|
@Override protected void init(Bundle savedInstanceState) {
|
||||||
mUtil.download(this, mDownloadUrl,
|
super.init(savedInstanceState);
|
||||||
Environment.getExternalStorageDirectory().getPath() + "/test.apk",
|
setSupportActionBar(toolbar);
|
||||||
new DownLoadUtil.DownloadListener() {
|
init();
|
||||||
long fileSize = 1;
|
}
|
||||||
|
|
||||||
@Override public void onPreDownload(HttpURLConnection connection) {
|
private void init() {
|
||||||
super.onPreDownload(connection);
|
mPb = (ProgressBar) findViewById(R.id.progressBar);
|
||||||
mPb.setMax(100);
|
mStart = (Button) findViewById(R.id.start);
|
||||||
fileSize = connection.getContentLength();
|
mStop = (Button) findViewById(R.id.stop);
|
||||||
mUpdateHandler.obtainMessage(DOWNLOAD_PRE, fileSize).sendToTarget();
|
mCancel = (Button) findViewById(R.id.cancel);
|
||||||
}
|
mSize = (TextView) findViewById(R.id.size);
|
||||||
|
mUtil = new DownLoadUtil();
|
||||||
|
}
|
||||||
|
|
||||||
@Override public void onStart(long startLocation) {
|
public void onClick(View view) {
|
||||||
super.onStart(startLocation);
|
switch (view.getId()) {
|
||||||
}
|
case R.id.start:
|
||||||
|
start();
|
||||||
|
break;
|
||||||
|
case R.id.stop:
|
||||||
|
stop();
|
||||||
|
break;
|
||||||
|
case R.id.cancel:
|
||||||
|
cancel();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override public void onChildResume(long resumeLocation) {
|
private void start() {
|
||||||
super.onChildResume(resumeLocation);
|
mUtil.download(this, mDownloadUrl, Environment.getExternalStorageDirectory().getPath() + "/test.apk", new DownLoadUtil.DownloadListener() {
|
||||||
}
|
long fileSize = 1;
|
||||||
|
|
||||||
@Override public void onChildComplete(long finishLocation) {
|
@Override public void onPreDownload(HttpURLConnection connection) {
|
||||||
super.onChildComplete(finishLocation);
|
super.onPreDownload(connection);
|
||||||
}
|
mPb.setMax(100);
|
||||||
|
fileSize = connection.getContentLength();
|
||||||
|
mUpdateHandler.obtainMessage(DOWNLOAD_PRE, fileSize).sendToTarget();
|
||||||
|
}
|
||||||
|
|
||||||
@Override public void onProgress(long currentLocation) {
|
@Override public void onStart(long startLocation) {
|
||||||
super.onProgress(currentLocation);
|
super.onStart(startLocation);
|
||||||
mPb.setProgress((int) (currentLocation * 100 / fileSize));
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override public void onStop(long stopLocation) {
|
@Override public void onChildResume(long resumeLocation) {
|
||||||
super.onStop(stopLocation);
|
super.onChildResume(resumeLocation);
|
||||||
mUpdateHandler.obtainMessage(DOWNLOAD_STOP).sendToTarget();
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override public void onCancel() {
|
@Override public void onChildComplete(long finishLocation) {
|
||||||
super.onCancel();
|
super.onChildComplete(finishLocation);
|
||||||
mUpdateHandler.obtainMessage(DOWNLOAD_CANCEL).sendToTarget();
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override public void onResume(long resumeLocation) {
|
@Override public void onProgress(long currentLocation) {
|
||||||
super.onResume(resumeLocation);
|
super.onProgress(currentLocation);
|
||||||
mUpdateHandler.obtainMessage(DOWNLOAD_RESUME, resumeLocation).sendToTarget();
|
mPb.setProgress((int) (currentLocation * 100 / fileSize));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void onFail() {
|
@Override public void onStop(long stopLocation) {
|
||||||
super.onFail();
|
super.onStop(stopLocation);
|
||||||
mUpdateHandler.obtainMessage(DOWNLOAD_FAILE).sendToTarget();
|
mUpdateHandler.obtainMessage(DOWNLOAD_STOP).sendToTarget();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void onComplete() {
|
@Override public void onCancel() {
|
||||||
super.onComplete();
|
super.onCancel();
|
||||||
mUpdateHandler.obtainMessage(DOWNLOAD_COMPLETE).sendToTarget();
|
mUpdateHandler.obtainMessage(DOWNLOAD_CANCEL).sendToTarget();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override public void onResume(long resumeLocation) {
|
||||||
|
super.onResume(resumeLocation);
|
||||||
|
mUpdateHandler.obtainMessage(DOWNLOAD_RESUME, resumeLocation).sendToTarget();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public void onFail() {
|
||||||
|
super.onFail();
|
||||||
|
mUpdateHandler.obtainMessage(DOWNLOAD_FAILE).sendToTarget();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public void onComplete() {
|
||||||
|
super.onComplete();
|
||||||
|
mUpdateHandler.obtainMessage(DOWNLOAD_COMPLETE).sendToTarget();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void stop() {
|
private void stop() {
|
||||||
mUtil.stopDownload();
|
mUtil.stopDownload();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void cancel() {
|
private void cancel() {
|
||||||
mUtil.cancelDownload();
|
mUtil.cancelDownload();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,69 +4,72 @@ import android.content.Context;
|
|||||||
import android.util.SparseArray;
|
import android.util.SparseArray;
|
||||||
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.entity.DownloadEntity;
|
import com.arialyy.downloadutil.entity.DownloadEntity;
|
||||||
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.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import butterknife.Bind;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Lyy on 2016/9/27.
|
* Created by Lyy on 2016/9/27.
|
||||||
* 下载列表适配器
|
* 下载列表适配器
|
||||||
*/
|
*/
|
||||||
public class DownloadAdapter extends AbsRVAdapter<DownloadEntity, DownloadAdapter.MyHolder> {
|
public class DownloadAdapter extends AbsRVAdapter<DownloadEntity, DownloadAdapter.MyHolder> {
|
||||||
private static final String TAG = "DownloadAdapter";
|
private static final String TAG = "DownloadAdapter";
|
||||||
private Map<String, Long> mProgress = new HashMap<>();
|
private Map<String, Long> mProgress = new HashMap<>();
|
||||||
private SparseArray<String> mPositions = new SparseArray<>();
|
private SparseArray<String> mPositions = new SparseArray<>();
|
||||||
|
|
||||||
public DownloadAdapter(Context context, List<DownloadEntity> data) {
|
public DownloadAdapter(Context context, List<DownloadEntity> data) {
|
||||||
super(context, data);
|
super(context, data);
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (DownloadEntity entity : data) {
|
for (DownloadEntity entity : data) {
|
||||||
mProgress.put(entity.getDownloadUrl(), entity.getCurrentProgress());
|
mProgress.put(entity.getDownloadUrl(), entity.getCurrentProgress());
|
||||||
mPositions.append(i, entity.getDownloadUrl());
|
mPositions.append(i, entity.getDownloadUrl());
|
||||||
i++;
|
i++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override protected MyHolder getViewHolder(View convertView, int viewType) {
|
@Override protected MyHolder getViewHolder(View convertView, int viewType) {
|
||||||
return new MyHolder(convertView);
|
return new MyHolder(convertView);
|
||||||
}
|
|
||||||
|
|
||||||
@Override protected int setLayoutId(int type) {
|
|
||||||
return R.layout.item_download;
|
|
||||||
}
|
|
||||||
|
|
||||||
public synchronized void setProgress(String url, long currentPosition) {
|
|
||||||
mProgress.put(url, currentPosition);
|
|
||||||
notifyItemChanged(indexItem(url));
|
|
||||||
}
|
|
||||||
|
|
||||||
private int indexItem(String url) {
|
|
||||||
return mPositions.indexOfValue(url);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override protected void bindData(MyHolder holder, int position, DownloadEntity item) {
|
|
||||||
//holder.progress.setProgress(item.getCurrentProgress());
|
|
||||||
long size = item.getFileSize();
|
|
||||||
int current = 0;
|
|
||||||
if (size == 0){
|
|
||||||
current = 0;
|
|
||||||
}
|
}
|
||||||
current = (int) (mProgress.get(item.getDownloadUrl()) * 100 / item.getFileSize());
|
|
||||||
holder.progress.setProgress(current);
|
|
||||||
}
|
|
||||||
|
|
||||||
class MyHolder extends AbsHolder {
|
@Override protected int setLayoutId(int type) {
|
||||||
@Bind(R.id.progressBar) HorizontalProgressBarWithNumber progress;
|
return R.layout.item_download;
|
||||||
@Bind(R.id.bt) Button bt;
|
}
|
||||||
|
|
||||||
public MyHolder(View itemView) {
|
public synchronized void setProgress(String url, long currentPosition) {
|
||||||
super(itemView);
|
mProgress.put(url, currentPosition);
|
||||||
|
notifyItemChanged(indexItem(url));
|
||||||
|
}
|
||||||
|
|
||||||
|
private int indexItem(String url) {
|
||||||
|
return mPositions.indexOfValue(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override protected void bindData(MyHolder holder, int position, DownloadEntity item) {
|
||||||
|
//holder.progress.setProgress(item.getCurrentProgress());
|
||||||
|
long size = item.getFileSize();
|
||||||
|
int current = 0;
|
||||||
|
if (size == 0) {
|
||||||
|
current = 0;
|
||||||
|
}
|
||||||
|
current = (int) (mProgress.get(item.getDownloadUrl()) * 100 / item.getFileSize());
|
||||||
|
holder.progress.setProgress(current);
|
||||||
|
}
|
||||||
|
|
||||||
|
class MyHolder extends AbsHolder {
|
||||||
|
@Bind(R.id.progressBar) HorizontalProgressBarWithNumber progress;
|
||||||
|
@Bind(R.id.bt) Button bt;
|
||||||
|
|
||||||
|
public MyHolder(View itemView) {
|
||||||
|
super(itemView);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -2,17 +2,18 @@ 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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Lyy on 2016/9/27.
|
* Created by Lyy on 2016/9/27.
|
||||||
*/
|
*/
|
||||||
public abstract class BaseActivity<VB extends ViewDataBinding> extends AbsActivity<VB> {
|
public abstract class BaseActivity<VB extends ViewDataBinding> extends AbsActivity<VB> {
|
||||||
@Override protected void dataCallback(int result, Object data) {
|
@Override protected void dataCallback(int result, Object data) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override protected void init(Bundle savedInstanceState) {
|
@Override protected void init(Bundle savedInstanceState) {
|
||||||
super.init(savedInstanceState);
|
super.init(savedInstanceState);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,15 @@
|
|||||||
package com.arialyy.simple.base;
|
package com.arialyy.simple.base;
|
||||||
|
|
||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
|
|
||||||
import com.arialyy.frame.core.AbsFrame;
|
import com.arialyy.frame.core.AbsFrame;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Lyy on 2016/9/27.
|
* Created by Lyy on 2016/9/27.
|
||||||
*/
|
*/
|
||||||
public class BaseApplication extends Application {
|
public class BaseApplication extends Application {
|
||||||
@Override public void onCreate() {
|
@Override public void onCreate() {
|
||||||
super.onCreate();
|
super.onCreate();
|
||||||
AbsFrame.init(this);
|
AbsFrame.init(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,14 @@
|
|||||||
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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Lyy on 2016/9/27.
|
* Created by Lyy on 2016/9/27.
|
||||||
*/
|
*/
|
||||||
public class BaseModule extends AbsModule{
|
public class BaseModule extends AbsModule {
|
||||||
public BaseModule(Context context) {
|
public BaseModule(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,174 +7,157 @@ 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 {
|
||||||
private static final int DEFAULT_TEXT_SIZE = 10;
|
private static final int DEFAULT_TEXT_SIZE = 10;
|
||||||
private static final int DEFAULT_TEXT_COLOR = 0XFFFC00D1;
|
private static final int DEFAULT_TEXT_COLOR = 0XFFFC00D1;
|
||||||
private static final int DEFAULT_COLOR_UNREACHED_COLOR = 0xFFd3d6da;
|
private static final int DEFAULT_COLOR_UNREACHED_COLOR = 0xFFd3d6da;
|
||||||
private static final int DEFAULT_HEIGHT_REACHED_PROGRESS_BAR = 2;
|
private static final int DEFAULT_HEIGHT_REACHED_PROGRESS_BAR = 2;
|
||||||
private static final int DEFAULT_HEIGHT_UNREACHED_PROGRESS_BAR = 2;
|
private static final int DEFAULT_HEIGHT_UNREACHED_PROGRESS_BAR = 2;
|
||||||
private static final int DEFAULT_SIZE_TEXT_OFFSET = 10;
|
private static final int DEFAULT_SIZE_TEXT_OFFSET = 10;
|
||||||
/**
|
/**
|
||||||
* painter of all drawing things
|
* painter of all drawing things
|
||||||
*/
|
*/
|
||||||
protected Paint mPaint = new Paint();
|
protected Paint mPaint = new Paint();
|
||||||
/**
|
/**
|
||||||
* color of progress number
|
* color of progress number
|
||||||
*/
|
*/
|
||||||
protected int mTextColor = DEFAULT_TEXT_COLOR;
|
protected int mTextColor = DEFAULT_TEXT_COLOR;
|
||||||
/**
|
/**
|
||||||
* size of text (sp)
|
* size of text (sp)
|
||||||
*/
|
*/
|
||||||
protected int mTextSize = sp2px(DEFAULT_TEXT_SIZE);
|
protected int mTextSize = sp2px(DEFAULT_TEXT_SIZE);
|
||||||
/**
|
/**
|
||||||
* offset of draw progress
|
* offset of draw progress
|
||||||
*/
|
*/
|
||||||
protected int mTextOffset = dp2px(DEFAULT_SIZE_TEXT_OFFSET);
|
protected int mTextOffset = dp2px(DEFAULT_SIZE_TEXT_OFFSET);
|
||||||
/**
|
/**
|
||||||
* height of reached progress bar
|
* height of reached progress bar
|
||||||
*/
|
*/
|
||||||
protected int mReachedProgressBarHeight = dp2px(DEFAULT_HEIGHT_REACHED_PROGRESS_BAR);
|
protected int mReachedProgressBarHeight = dp2px(DEFAULT_HEIGHT_REACHED_PROGRESS_BAR);
|
||||||
/**
|
/**
|
||||||
* color of reached bar
|
* color of reached bar
|
||||||
*/
|
*/
|
||||||
protected int mReachedBarColor = DEFAULT_TEXT_COLOR;
|
protected int mReachedBarColor = DEFAULT_TEXT_COLOR;
|
||||||
/**
|
/**
|
||||||
* color of unreached bar
|
* color of unreached bar
|
||||||
*/
|
*/
|
||||||
protected int mUnReachedBarColor = DEFAULT_COLOR_UNREACHED_COLOR;
|
protected int mUnReachedBarColor = DEFAULT_COLOR_UNREACHED_COLOR;
|
||||||
/**
|
/**
|
||||||
* height of unreached progress bar
|
* height of unreached progress bar
|
||||||
*/
|
*/
|
||||||
protected int mUnReachedProgressBarHeight = dp2px(DEFAULT_HEIGHT_UNREACHED_PROGRESS_BAR);
|
protected int mUnReachedProgressBarHeight = dp2px(DEFAULT_HEIGHT_UNREACHED_PROGRESS_BAR);
|
||||||
/**
|
/**
|
||||||
* view width except padding
|
* view width except padding
|
||||||
*/
|
*/
|
||||||
protected int mRealWidth;
|
protected int mRealWidth;
|
||||||
protected boolean mIfDrawText = true;
|
protected boolean mIfDrawText = true;
|
||||||
protected static final int VISIBLE = 0;
|
protected static final int VISIBLE = 0;
|
||||||
|
|
||||||
public HorizontalProgressBarWithNumber(Context context, AttributeSet attrs) {
|
public HorizontalProgressBarWithNumber(Context context, AttributeSet attrs) {
|
||||||
this(context, attrs, 0);
|
this(context, attrs, 0);
|
||||||
}
|
|
||||||
|
|
||||||
public HorizontalProgressBarWithNumber(Context context, AttributeSet attrs, int defStyle) {
|
|
||||||
super(context, attrs, defStyle);
|
|
||||||
obtainStyledAttributes(attrs);
|
|
||||||
mPaint.setTextSize(mTextSize);
|
|
||||||
mPaint.setColor(mTextColor);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override protected synchronized void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
|
||||||
int width = MeasureSpec.getSize(widthMeasureSpec);
|
|
||||||
int height = measureHeight(heightMeasureSpec);
|
|
||||||
setMeasuredDimension(width, height);
|
|
||||||
mRealWidth = getMeasuredWidth() - getPaddingRight() - getPaddingLeft();
|
|
||||||
}
|
|
||||||
|
|
||||||
private int measureHeight(int measureSpec) {
|
|
||||||
int result = 0;
|
|
||||||
int specMode = MeasureSpec.getMode(measureSpec);
|
|
||||||
int specSize = MeasureSpec.getSize(measureSpec);
|
|
||||||
if (specMode == MeasureSpec.EXACTLY) {
|
|
||||||
result = specSize;
|
|
||||||
} else {
|
|
||||||
float textHeight = (mPaint.descent() - mPaint.ascent());
|
|
||||||
result = (int) (getPaddingTop() + getPaddingBottom() + Math.max(
|
|
||||||
Math.max(mReachedProgressBarHeight, mUnReachedProgressBarHeight), Math.abs(textHeight)));
|
|
||||||
if (specMode == MeasureSpec.AT_MOST) {
|
|
||||||
result = Math.min(result, specSize);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
public HorizontalProgressBarWithNumber(Context context, AttributeSet attrs, int defStyle) {
|
||||||
* get the styled attributes
|
super(context, attrs, defStyle);
|
||||||
*/
|
obtainStyledAttributes(attrs);
|
||||||
private void obtainStyledAttributes(AttributeSet attrs) {
|
mPaint.setTextSize(mTextSize);
|
||||||
// init values from custom attributes
|
mPaint.setColor(mTextColor);
|
||||||
final TypedArray attributes =
|
|
||||||
getContext().obtainStyledAttributes(attrs, R.styleable.HorizontalProgressBarWithNumber);
|
|
||||||
mTextColor =
|
|
||||||
attributes.getColor(R.styleable.HorizontalProgressBarWithNumber_progress_text_color,
|
|
||||||
DEFAULT_TEXT_COLOR);
|
|
||||||
mTextSize = (int) attributes.getDimension(
|
|
||||||
R.styleable.HorizontalProgressBarWithNumber_progress_text_size, mTextSize);
|
|
||||||
mReachedBarColor =
|
|
||||||
attributes.getColor(R.styleable.HorizontalProgressBarWithNumber_progress_reached_color,
|
|
||||||
mTextColor);
|
|
||||||
mUnReachedBarColor =
|
|
||||||
attributes.getColor(R.styleable.HorizontalProgressBarWithNumber_progress_unreached_color,
|
|
||||||
DEFAULT_COLOR_UNREACHED_COLOR);
|
|
||||||
mReachedProgressBarHeight = (int) attributes.getDimension(
|
|
||||||
R.styleable.HorizontalProgressBarWithNumber_progress_reached_bar_height,
|
|
||||||
mReachedProgressBarHeight);
|
|
||||||
mUnReachedProgressBarHeight = (int) attributes.getDimension(
|
|
||||||
R.styleable.HorizontalProgressBarWithNumber_progress_unreached_bar_height,
|
|
||||||
mUnReachedProgressBarHeight);
|
|
||||||
mTextOffset = (int) attributes.getDimension(
|
|
||||||
R.styleable.HorizontalProgressBarWithNumber_progress_text_offset, mTextOffset);
|
|
||||||
int textVisible =
|
|
||||||
attributes.getInt(R.styleable.HorizontalProgressBarWithNumber_progress_text_visibility,
|
|
||||||
VISIBLE);
|
|
||||||
if (textVisible != VISIBLE) {
|
|
||||||
mIfDrawText = false;
|
|
||||||
}
|
}
|
||||||
attributes.recycle();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override protected synchronized void onDraw(Canvas canvas) {
|
@Override protected synchronized void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||||
canvas.save();
|
int width = MeasureSpec.getSize(widthMeasureSpec);
|
||||||
canvas.translate(getPaddingLeft(), getHeight() / 2);
|
int height = measureHeight(heightMeasureSpec);
|
||||||
boolean noNeedBg = false;
|
setMeasuredDimension(width, height);
|
||||||
float radio = getProgress() * 1.0f / getMax();
|
mRealWidth = getMeasuredWidth() - getPaddingRight() - getPaddingLeft();
|
||||||
float progressPosX = (int) (mRealWidth * radio);
|
|
||||||
String text = getProgress() + "%";
|
|
||||||
// mPaint.getTextBounds(text, 0, text.length(), mTextBound);
|
|
||||||
float textWidth = mPaint.measureText(text);
|
|
||||||
float textHeight = (mPaint.descent() + mPaint.ascent()) / 2;
|
|
||||||
if (progressPosX + textWidth > mRealWidth) {
|
|
||||||
progressPosX = mRealWidth - textWidth;
|
|
||||||
noNeedBg = true;
|
|
||||||
}
|
}
|
||||||
// draw reached bar
|
|
||||||
float endX = progressPosX - mTextOffset / 2;
|
|
||||||
if (endX > 0) {
|
|
||||||
mPaint.setColor(mReachedBarColor);
|
|
||||||
mPaint.setStrokeWidth(mReachedProgressBarHeight);
|
|
||||||
canvas.drawLine(0, 0, endX, 0, mPaint);
|
|
||||||
}
|
|
||||||
// draw progress bar
|
|
||||||
// measure text bound
|
|
||||||
if (mIfDrawText) {
|
|
||||||
mPaint.setColor(mTextColor);
|
|
||||||
canvas.drawText(text, progressPosX, -textHeight, mPaint);
|
|
||||||
}
|
|
||||||
// draw unreached bar
|
|
||||||
if (!noNeedBg) {
|
|
||||||
float start = progressPosX + mTextOffset / 2 + textWidth;
|
|
||||||
mPaint.setColor(mUnReachedBarColor);
|
|
||||||
mPaint.setStrokeWidth(mUnReachedProgressBarHeight);
|
|
||||||
canvas.drawLine(start, 0, mRealWidth, 0, mPaint);
|
|
||||||
}
|
|
||||||
canvas.restore();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
private int measureHeight(int measureSpec) {
|
||||||
* dp 2 px
|
int result = 0;
|
||||||
*/
|
int specMode = MeasureSpec.getMode(measureSpec);
|
||||||
protected int dp2px(int dpVal) {
|
int specSize = MeasureSpec.getSize(measureSpec);
|
||||||
return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dpVal,
|
if (specMode == MeasureSpec.EXACTLY) {
|
||||||
getResources().getDisplayMetrics());
|
result = specSize;
|
||||||
}
|
} else {
|
||||||
|
float textHeight = (mPaint.descent() - mPaint.ascent());
|
||||||
|
result = (int) (getPaddingTop() + getPaddingBottom() + Math.max(Math.max(mReachedProgressBarHeight, mUnReachedProgressBarHeight), Math.abs(textHeight)));
|
||||||
|
if (specMode == MeasureSpec.AT_MOST) {
|
||||||
|
result = Math.min(result, specSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* sp 2 px
|
* get the styled attributes
|
||||||
*/
|
*/
|
||||||
protected int sp2px(int spVal) {
|
private void obtainStyledAttributes(AttributeSet attrs) {
|
||||||
return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, spVal,
|
// init values from custom attributes
|
||||||
getResources().getDisplayMetrics());
|
final TypedArray attributes = getContext().obtainStyledAttributes(attrs, R.styleable.HorizontalProgressBarWithNumber);
|
||||||
}
|
mTextColor = attributes.getColor(R.styleable.HorizontalProgressBarWithNumber_progress_text_color, DEFAULT_TEXT_COLOR);
|
||||||
|
mTextSize = (int) attributes.getDimension(R.styleable.HorizontalProgressBarWithNumber_progress_text_size, mTextSize);
|
||||||
|
mReachedBarColor = attributes.getColor(R.styleable.HorizontalProgressBarWithNumber_progress_reached_color, mTextColor);
|
||||||
|
mUnReachedBarColor = attributes.getColor(R.styleable.HorizontalProgressBarWithNumber_progress_unreached_color, DEFAULT_COLOR_UNREACHED_COLOR);
|
||||||
|
mReachedProgressBarHeight = (int) attributes.getDimension(R.styleable.HorizontalProgressBarWithNumber_progress_reached_bar_height, mReachedProgressBarHeight);
|
||||||
|
mUnReachedProgressBarHeight = (int) attributes.getDimension(R.styleable.HorizontalProgressBarWithNumber_progress_unreached_bar_height, mUnReachedProgressBarHeight);
|
||||||
|
mTextOffset = (int) attributes.getDimension(R.styleable.HorizontalProgressBarWithNumber_progress_text_offset, mTextOffset);
|
||||||
|
int textVisible = attributes.getInt(R.styleable.HorizontalProgressBarWithNumber_progress_text_visibility, VISIBLE);
|
||||||
|
if (textVisible != VISIBLE) {
|
||||||
|
mIfDrawText = false;
|
||||||
|
}
|
||||||
|
attributes.recycle();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override protected synchronized void onDraw(Canvas canvas) {
|
||||||
|
canvas.save();
|
||||||
|
canvas.translate(getPaddingLeft(), getHeight() / 2);
|
||||||
|
boolean noNeedBg = false;
|
||||||
|
float radio = getProgress() * 1.0f / getMax();
|
||||||
|
float progressPosX = (int) (mRealWidth * radio);
|
||||||
|
String text = getProgress() + "%";
|
||||||
|
// mPaint.getTextBounds(text, 0, text.length(), mTextBound);
|
||||||
|
float textWidth = mPaint.measureText(text);
|
||||||
|
float textHeight = (mPaint.descent() + mPaint.ascent()) / 2;
|
||||||
|
if (progressPosX + textWidth > mRealWidth) {
|
||||||
|
progressPosX = mRealWidth - textWidth;
|
||||||
|
noNeedBg = true;
|
||||||
|
}
|
||||||
|
// draw reached bar
|
||||||
|
float endX = progressPosX - mTextOffset / 2;
|
||||||
|
if (endX > 0) {
|
||||||
|
mPaint.setColor(mReachedBarColor);
|
||||||
|
mPaint.setStrokeWidth(mReachedProgressBarHeight);
|
||||||
|
canvas.drawLine(0, 0, endX, 0, mPaint);
|
||||||
|
}
|
||||||
|
// draw progress bar
|
||||||
|
// measure text bound
|
||||||
|
if (mIfDrawText) {
|
||||||
|
mPaint.setColor(mTextColor);
|
||||||
|
canvas.drawText(text, progressPosX, -textHeight, mPaint);
|
||||||
|
}
|
||||||
|
// draw unreached bar
|
||||||
|
if (!noNeedBg) {
|
||||||
|
float start = progressPosX + mTextOffset / 2 + textWidth;
|
||||||
|
mPaint.setColor(mUnReachedBarColor);
|
||||||
|
mPaint.setStrokeWidth(mUnReachedProgressBarHeight);
|
||||||
|
canvas.drawLine(start, 0, mRealWidth, 0, mPaint);
|
||||||
|
}
|
||||||
|
canvas.restore();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* dp 2 px
|
||||||
|
*/
|
||||||
|
protected int dp2px(int dpVal) {
|
||||||
|
return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dpVal, getResources().getDisplayMetrics());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* sp 2 px
|
||||||
|
*/
|
||||||
|
protected int sp2px(int spVal) {
|
||||||
|
return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, spVal, getResources().getDisplayMetrics());
|
||||||
|
}
|
||||||
}
|
}
|
0
cache/build/mPro.properties
vendored
Normal file
0
cache/build/mPro.properties
vendored
Normal file
Reference in New Issue
Block a user