├── .gitignore
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── example
│ │ └── view
│ │ └── myview
│ │ ├── MainActivity.java
│ │ ├── MyView1Activity.java
│ │ └── view
│ │ ├── DownProgressView.java
│ │ └── MyView1.java
│ └── res
│ ├── drawable-xxhdpi
│ ├── btn_down_pause.png
│ └── btn_vedio_restart.png
│ ├── drawable-xxxhdpi
│ ├── btn_down_pause.png
│ └── btn_vedio_restart.png
│ ├── layout
│ ├── activity_main.xml
│ └── activity_my_view1.xml
│ ├── mipmap-hdpi
│ └── ic_launcher.png
│ ├── mipmap-mdpi
│ └── ic_launcher.png
│ ├── mipmap-xhdpi
│ └── ic_launcher.png
│ ├── mipmap-xxhdpi
│ └── ic_launcher.png
│ ├── mipmap-xxxhdpi
│ ├── btn_down_pause.png
│ ├── btn_vedio_restart.png
│ └── ic_launcher.png
│ ├── values-w820dp
│ └── dimens.xml
│ └── values
│ ├── colors.xml
│ ├── dimens.xml
│ ├── strings.xml
│ └── styles.xml
├── build.gradle
├── gif
└── ios_progress.gif
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # DownProgressView
2 | Android自定义view之仿ios-appstore下载进度按钮可设置大小,高度,颜色,各状态图片类型!
3 | #仿IOS -appstore之下载进度按钮
4 |
5 | ###先上效果
6 | 程序员不懂设计,大家可以自己配色换图(凑合看看)
7 |
8 | 
9 |
10 | ###使用
11 | ```java
12 | setListner(StateProgressListner listner)设置回调监听
13 | setmProgress(int mProgress)设置下载进度
14 | setmFirstColor(int mFirstColor)设置进度圆环的颜色
15 | setmSecondColor(int mSecondColor)设置第一个圆环的颜色
16 | setmCircleWidth(int mCircleWidth)设置加载环的宽度
17 | void setSrcStorp(int srcStorp)设置停止状态图片
18 | setSrcStart(int srcStart)设置开始状态图片资源
19 | void onDestory() 销毁处理
20 | ```
21 |
22 | ##思路
23 | * 画出一个空的大圆环
24 | * 然后画出进度的弧度
25 | * 监听`touch`事件控制画出暂停和开始的`bitmap`
26 | * 自定义监听返回按钮的状态
27 |
28 | ###初始化工作
29 | ```java
30 | // 第一圈的颜色
31 | private int mFirstColor;
32 | // 第二圈的颜色
33 | private int mSecondColor;
34 | // 圈的宽度
35 | private int mCircleWidth;
36 | // 画笔
37 | private Paint mPaint;
38 | // 当前进度
39 | private int mProgress;
40 | // 圆环中心点
41 | private int centre;
42 | // 状态图片
43 | private Bitmap bitmap;
44 | // 开始状态图片
45 | private int srcStart;
46 | // 暂停状态图片
47 | private int srcStorp;
48 | // 0开始状态;1暂停;2完成
49 | private int state;
50 | // 回调接口
51 | private StateProgressListner listner;
52 | ```
53 |
54 |
55 | ###画圆
56 | ```java
57 | centre = getWidth() / 2; // 获取圆心的x坐标
58 | int radius = centre - mCircleWidth;// 半径
59 | mPaint.setStrokeWidth(mCircleWidth); // 设置圆环的宽度
60 | mPaint.setAntiAlias(true); // 消除锯齿
61 | mPaint.setStyle(Paint.Style.STROKE); // 设置空心
62 | // 用于定义的圆弧的形状和大小的界限
63 | RectF oval = new RectF(centre - radius, centre - radius, centre + radius, centre + radius);
64 | mPaint.setColor(mFirstColor); // 设置圆环的颜色
65 | canvas.drawCircle(centre, centre, radius, mPaint); // 画出圆环
66 | ```
67 |
68 | ###画出经度的弧度
69 |
70 | ```java
71 | mPaint.setColor(mSecondColor); // 设置圆环的颜色
72 | mPaint.setStrokeCap(Paint.Cap.ROUND);//两边带圆弧
73 | canvas.drawArc(oval, -90, mProgress, false, mPaint); // 根据进度画圆弧
74 | ```
75 |
76 |
77 | ###监听`touch`事件
78 |
79 | **1**.监听MotionEvent事件
80 | ```java
81 | @Override
82 | public boolean onTouchEvent(MotionEvent event) {
83 | if (event.getAction() == MotionEvent.ACTION_UP) {
84 | // 判断当前状态
85 | if (state == 0) {
86 | stop();
87 | } else if (state == 1) {
88 | start();
89 | }
90 | }
91 | return true;
92 | }
93 | ```
94 | **2**.绘制开始和暂停状态图片
95 | ```java
96 | /**
97 | * 画出当前的状态图标
98 | *
99 | * @param canvas
100 | */
101 | private void drawBitmap(Canvas canvas) {
102 | if (bitmap != null) bitmap.recycle();
103 | bitmap = BitmapFactory.decodeResource(getResources(), state == 0 ? srcStart : srcStorp);
104 | if (bitmap != null) {
105 | int with = bitmap.getWidth();
106 | int height = bitmap.getHeight();
107 | canvas.drawBitmap(bitmap, centre - with / 2, centre - height / 2, mPaint);
108 | }
109 | }
110 | ```
111 |
112 | ##自定义回调接口
113 | **1**创建回调类
114 | ```java
115 | /**
116 | * 自定义监听器
117 | */
118 | public interface StateProgressListner {
119 | /**
120 | * 开始
121 | */
122 | void onstart();
123 |
124 | /**
125 | * 暂停
126 | */
127 | void onstop();
128 |
129 | /**
130 | * 结束
131 | */
132 | void onfinish();
133 | }
134 | ```
135 | **2**触发回调事件
136 |
137 | ```java
138 | /**
139 | * 停止
140 | */
141 | private void stop() {
142 | state = 1;
143 | if (listner != null) {
144 | listner.onstart();
145 | }
146 | invalidate();
147 | }
148 |
149 | /**
150 | * 开始
151 | */
152 | private void start() {
153 | state = 0;
154 | if (listner != null) {
155 | listner.onstop();
156 | }
157 | invalidate();
158 | }
159 |
160 | public int getmProgress() {
161 | return mProgress;
162 | }
163 |
164 | /**
165 | * 更新进度条
166 | *
167 | * @param mProgress
168 | */
169 | public void setmProgress(int mProgress) {
170 | this.mProgress = mProgress;
171 | if (mProgress == 360 && listner != null) {
172 | listner.onfinish();
173 | }
174 | invalidate();
175 | }
176 | ```
177 |
178 | ##主线程中控制状态
179 | 这里我并没有真正的下载,用hander模拟下载进度变化
180 | ```java
181 | public class MyView1Activity extends AppCompatActivity implements DownProgressView.StateProgressListner {
182 | @BindView(R.id.view1)
183 | DownProgressView view1;
184 | int progress;
185 |
186 | @Override
187 | protected void onCreate(Bundle savedInstanceState) {
188 | super.onCreate(savedInstanceState);
189 | setContentView(R.layout.activity_my_view1);
190 | ButterKnife.bind(this);
191 | view1.setListner(this);
192 | }
193 |
194 |
195 | Handler handler = new Handler() {
196 | @Override
197 | public void handleMessage(Message msg) {
198 | super.handleMessage(msg);
199 | view1.setmProgress(++progress);
200 | handler.sendEmptyMessageDelayed(1, 20);
201 | }
202 |
203 | };
204 |
205 | @Override
206 | public void onstart() {
207 | handler.sendEmptyMessage(1);
208 | }
209 |
210 | @Override
211 | public void onstop() {
212 | handler.removeMessages(1);
213 | }
214 |
215 | @Override
216 | public void onfinish() {
217 | progress = 0;
218 | Toast.makeText(this, "下载完成了!继续开始", Toast.LENGTH_SHORT).show();
219 | }
220 |
221 | @Override
222 | protected void onDestroy() {
223 | super.onDestroy();
224 | handler.removeMessages(1);
225 | view1.onDestory();
226 | }
227 | }
228 | ```
229 |
230 |
231 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.3"
6 |
7 | defaultConfig {
8 | applicationId "com.example.view.myview"
9 | minSdkVersion 16
10 | targetSdkVersion 23
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | buildscript {
23 | repositories {
24 | mavenCentral()
25 | }
26 | dependencies {
27 | classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
28 | }
29 | }
30 |
31 | apply plugin: 'com.neenbedankt.android-apt'
32 |
33 | dependencies {
34 | compile fileTree(include: ['*.jar'], dir: 'libs')
35 | testCompile 'junit:junit:4.12'
36 | compile 'com.android.support:appcompat-v7:23.4.0'
37 | compile 'com.jakewharton:butterknife:8.0.1'
38 | apt 'com.jakewharton:butterknife-compiler:8.0.1'
39 | }
40 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in E:\Android+tool\sdk\sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/view/myview/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.view.myview;
2 |
3 | import android.app.Activity;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.widget.Button;
7 |
8 | import butterknife.BindView;
9 | import butterknife.ButterKnife;
10 | import butterknife.OnClick;
11 |
12 | public class MainActivity extends Activity {
13 |
14 | @BindView(R.id.btn_test1)
15 | Button btnTest1;
16 |
17 | @Override
18 | public void onCreate(Bundle savedInstanceState) {
19 | super.onCreate(savedInstanceState);
20 | setContentView(R.layout.activity_main);
21 | ButterKnife.bind(this);
22 | }
23 |
24 | @OnClick(R.id.btn_test1)
25 | public void submit() {
26 | Intent intent = new Intent(this, MyView1Activity.class);
27 | startActivity(intent);
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/view/myview/MyView1Activity.java:
--------------------------------------------------------------------------------
1 | package com.example.view.myview;
2 |
3 | import android.os.Bundle;
4 | import android.os.Handler;
5 | import android.os.Message;
6 | import android.support.v7.app.AppCompatActivity;
7 | import android.widget.Toast;
8 |
9 | import com.example.view.myview.view.DownProgressView;
10 |
11 | import butterknife.BindView;
12 | import butterknife.ButterKnife;
13 |
14 | public class MyView1Activity extends AppCompatActivity implements DownProgressView.StateProgressListner {
15 | @BindView(R.id.view1)
16 | DownProgressView view1;
17 | int progress;
18 |
19 | @Override
20 | protected void onCreate(Bundle savedInstanceState) {
21 | super.onCreate(savedInstanceState);
22 | setContentView(R.layout.activity_my_view1);
23 | ButterKnife.bind(this);
24 | view1.setListner(this);
25 | }
26 |
27 |
28 | Handler handler = new Handler() {
29 | @Override
30 | public void handleMessage(Message msg) {
31 | super.handleMessage(msg);
32 | view1.setmProgress(++progress);
33 | handler.sendEmptyMessageDelayed(1, 20);
34 | }
35 |
36 | };
37 |
38 | @Override
39 | public void onstart() {
40 | handler.sendEmptyMessage(1);
41 | }
42 |
43 | @Override
44 | public void onstop() {
45 | handler.removeMessages(1);
46 | }
47 |
48 | @Override
49 | public void onfinish() {
50 | progress = 0;
51 | Toast.makeText(this, "下载完成了!继续开始", Toast.LENGTH_SHORT).show();
52 | }
53 |
54 | @Override
55 | protected void onDestroy() {
56 | super.onDestroy();
57 | handler.removeMessages(1);
58 | view1.onDestory();
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/view/myview/view/DownProgressView.java:
--------------------------------------------------------------------------------
1 | package com.example.view.myview.view;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.graphics.BitmapFactory;
6 | import android.graphics.Canvas;
7 | import android.graphics.Paint;
8 | import android.graphics.RectF;
9 | import android.util.AttributeSet;
10 | import android.view.MotionEvent;
11 | import android.view.View;
12 |
13 | import com.example.view.myview.R;
14 |
15 | /**
16 | * 模仿苹果下载暂停控件
17 | * Created by WZG on 2016/7/20.
18 | */
19 | public class DownProgressView extends View {
20 | // 第一圈的颜色
21 | private int mFirstColor;
22 | // 第二圈的颜色
23 | private int mSecondColor;
24 | // 圈的宽度
25 | private int mCircleWidth;
26 | // 画笔
27 | private Paint mPaint;
28 | // 当前进度
29 | private int mProgress;
30 | // 圆环中心点
31 | private int centre;
32 | // 状态图片
33 | private Bitmap bitmap;
34 | // 开始状态图片
35 | private int srcStart;
36 | // 暂停状态图片
37 | private int srcStorp;
38 | // 0开始状态;1暂停;2完成
39 | private int state;
40 | // 回调接口
41 | private StateProgressListner listner;
42 |
43 | public DownProgressView(Context context) {
44 | super(context);
45 | }
46 |
47 | public DownProgressView(Context context, AttributeSet attrs) {
48 | super(context, attrs);
49 | mFirstColor = getResources().getColor(R.color.white);
50 | mSecondColor = getResources().getColor(R.color.progress);
51 | mCircleWidth = 5;
52 | mPaint = new Paint();
53 | mProgress = 0;
54 | srcStart = R.drawable.btn_vedio_restart;
55 | srcStorp = R.drawable.btn_down_pause;
56 | state = 0;
57 | }
58 |
59 | public DownProgressView(Context context, AttributeSet attrs, int defStyleAttr) {
60 | super(context, attrs, defStyleAttr);
61 | }
62 |
63 | @Override
64 | protected void onDraw(Canvas canvas) {
65 | super.onDraw(canvas);
66 | drawCirle(canvas);
67 | drawBitmap(canvas);
68 | }
69 |
70 |
71 | @Override
72 | public boolean onTouchEvent(MotionEvent event) {
73 | if (event.getAction() == MotionEvent.ACTION_UP) {
74 | // 判断当前状态
75 | if (state == 0) {
76 | stop();
77 | } else if (state == 1) {
78 | start();
79 | }
80 | }
81 | return true;
82 | }
83 |
84 | /**
85 | * 圆弧进度
86 | *
87 | * @param canvas
88 | */
89 | private void drawCirle(Canvas canvas) {
90 | centre = getWidth() / 2; // 获取圆心的x坐标
91 | int radius = centre - mCircleWidth;// 半径
92 | mPaint.setStrokeWidth(mCircleWidth); // 设置圆环的宽度
93 | mPaint.setAntiAlias(true); // 消除锯齿
94 | mPaint.setStyle(Paint.Style.STROKE); // 设置空心
95 | // 用于定义的圆弧的形状和大小的界限
96 | RectF oval = new RectF(centre - radius, centre - radius, centre + radius, centre + radius);
97 | mPaint.setColor(mFirstColor); // 设置圆环的颜色
98 | canvas.drawCircle(centre, centre, radius, mPaint); // 画出圆环
99 | mPaint.setColor(mSecondColor); // 设置圆环的颜色
100 | mPaint.setStrokeCap(Paint.Cap.ROUND);//两边带圆弧
101 | canvas.drawArc(oval, -90, mProgress, false, mPaint); // 根据进度画圆弧
102 | }
103 |
104 |
105 | /**
106 | * 画出当前的状态图标
107 | *
108 | * @param canvas
109 | */
110 | private void drawBitmap(Canvas canvas) {
111 | if (bitmap != null) bitmap.recycle();
112 | bitmap = BitmapFactory.decodeResource(getResources(), state == 0 ? srcStart : srcStorp);
113 | if (bitmap != null) {
114 | int with = bitmap.getWidth();
115 | int height = bitmap.getHeight();
116 | canvas.drawBitmap(bitmap, centre - with / 2, centre - height / 2, mPaint);
117 | }
118 | }
119 |
120 |
121 | /**
122 | * 停止
123 | */
124 | private void stop() {
125 | state = 1;
126 | if (listner != null) {
127 | listner.onstart();
128 | }
129 | invalidate();
130 | }
131 |
132 | /**
133 | * 开始
134 | */
135 | private void start() {
136 | state = 0;
137 | if (listner != null) {
138 | listner.onstop();
139 | }
140 | invalidate();
141 | }
142 |
143 | public int getmProgress() {
144 | return mProgress;
145 | }
146 |
147 | /**
148 | * 更新进度条
149 | *
150 | * @param mProgress
151 | */
152 | public void setmProgress(int mProgress) {
153 | this.mProgress = mProgress;
154 | if (mProgress == 360 && listner != null) {
155 | listner.onfinish();
156 | }
157 | invalidate();
158 | }
159 |
160 | public void setListner(StateProgressListner listner) {
161 | this.listner = listner;
162 | }
163 |
164 | /**
165 | * 销毁处理
166 | */
167 | public void onDestory() {
168 | if (bitmap != null) bitmap.recycle();
169 | }
170 |
171 | /**
172 | * 设置开始状态图片资源
173 | *
174 | * @param srcStart
175 | */
176 | public void setSrcStart(int srcStart) {
177 | this.srcStart = srcStart;
178 | }
179 |
180 |
181 | /**
182 | * 设置停止状态图片
183 | *
184 | * @param srcStorp
185 | */
186 | public void setSrcStorp(int srcStorp) {
187 | this.srcStorp = srcStorp;
188 | }
189 |
190 | /**
191 | * 设置加载环的宽度
192 | *
193 | * @param mCircleWidth
194 | */
195 | public void setmCircleWidth(int mCircleWidth) {
196 | this.mCircleWidth = mCircleWidth;
197 | }
198 |
199 |
200 | /**
201 | * 设置第一个圆环的颜色
202 | *
203 | * @param mSecondColor
204 | */
205 | public void setmSecondColor(int mSecondColor) {
206 | this.mSecondColor = mSecondColor;
207 | }
208 |
209 | /**
210 | * 设置进度圆环的颜色
211 | *
212 | * @param mFirstColor
213 | */
214 | public void setmFirstColor(int mFirstColor) {
215 | this.mFirstColor = mFirstColor;
216 | }
217 |
218 | /**
219 | * 自定义监听器
220 | */
221 | public interface StateProgressListner {
222 | /**
223 | * 开始
224 | */
225 | void onstart();
226 |
227 | /**
228 | * 暂停
229 | */
230 | void onstop();
231 |
232 | /**
233 | * 结束
234 | */
235 | void onfinish();
236 | }
237 | }
238 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/view/myview/view/MyView1.java:
--------------------------------------------------------------------------------
1 | package com.example.view.myview.view;
2 |
3 | import android.content.Context;
4 | import android.graphics.Canvas;
5 | import android.graphics.Color;
6 | import android.graphics.Paint;
7 | import android.graphics.RectF;
8 | import android.util.AttributeSet;
9 | import android.util.Log;
10 | import android.view.MotionEvent;
11 | import android.view.View;
12 |
13 | /**
14 | * 第一个自定义view简单点吧
15 | *
16 | * 居中显示一个文本框
17 | * 添加点击监听
18 | * Created by WZG on 2016/7/19.
19 | */
20 | public class MyView1 extends View {
21 | // 距离边缘的位置
22 | private int pading = 60;
23 | // 边框距离x坐标
24 | private int startX = 100;
25 | // 边框距离y坐标
26 | private int startY = 100;
27 | // 文字的区域
28 | private RectF rectFTxt;
29 | // 边框区域
30 | private RectF rectF;
31 |
32 |
33 | public MyView1(Context context) {
34 | super(context);
35 | }
36 |
37 | public MyView1(Context context, AttributeSet attrs) {
38 | super(context, attrs);
39 | }
40 |
41 | public MyView1(Context context, AttributeSet attrs, int defStyleAttr) {
42 | super(context, attrs, defStyleAttr);
43 | }
44 |
45 | @Override
46 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
47 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
48 | }
49 |
50 | @Override
51 | protected void onDraw(Canvas canvas) {
52 | super.onDraw(canvas);
53 | paintCenterText("我就是一个文本显示的控件呀", canvas);
54 | }
55 |
56 | /**
57 | * 绘制一个居中显示的textview
58 | */
59 | private void paintCenterText(String name, Canvas canvas) {
60 | Paint textPaint = new Paint();
61 | textPaint.setColor(Color.BLACK);
62 | textPaint.setTextSize(40);
63 | /**
64 | * 设置绘制文字时起始点X坐标的位置
65 | * CENTER:以文字的宽度的中心点为起始点向两边绘制
66 | * LEFT:以文字左边为起始点向右边开始绘制
67 | * RIGHT:以文字宽度的右边为起始点向左边绘制
68 | */
69 | textPaint.setTextAlign(Paint.Align.CENTER);
70 | Paint.FontMetrics fm = textPaint.getFontMetrics();
71 | float textHeight = (int) Math.ceil(fm.bottom - fm.top);
72 | float textWith = textPaint.measureText(name);
73 |
74 |
75 | rectF = new RectF(startX, startY, startX + textWith + pading * 2, pading * 2 + startY + textHeight);
76 | Paint paint = new Paint();
77 | paint.setColor(Color.YELLOW);
78 |
79 | rectFTxt = new RectF(startX + pading, startY + pading, rectF.right - pading, rectF.bottom - pading);
80 | canvas.drawRect(rectF, paint);
81 |
82 | int baseline = (int) ((rectF.bottom + rectF.top - fm.bottom - fm.top) / 2);
83 | canvas.drawText(name, rectF.centerX(), baseline, textPaint);
84 | }
85 |
86 |
87 | @Override
88 | public boolean onTouchEvent(MotionEvent event) {
89 | float x = 0;
90 | float y = 0;
91 | switch (event.getAction()) {
92 | case MotionEvent.ACTION_DOWN:
93 | case MotionEvent.ACTION_MOVE:
94 | x = event.getX();
95 | y = event.getY();
96 | case MotionEvent.ACTION_UP:
97 | if (x > rectFTxt.left && x < rectFTxt.right && y > rectFTxt.top && y < rectFTxt.bottom) {
98 | Log.i("tag", "文字被点击了!");
99 | }
100 | if (x > rectF.left && x < rectFTxt.left) {
101 | Log.i("tag", "空白左的地方被点击了!");
102 | }
103 | if (x > rectFTxt.right && x < rectF.right) {
104 | Log.i("tag", "空白右的地方被点击了!");
105 | }
106 | if (y > rectF.top && y < rectFTxt.top) {
107 | Log.i("tag", "空白上的地方被点击了!");
108 | }
109 | if (y > rectFTxt.bottom && y < rectF.bottom) {
110 | Log.i("tag", "空白下的地方被点击了!");
111 | }
112 | break;
113 | }
114 | return true;
115 | }
116 |
117 |
118 | public int getFontHeight(float fontSize) {
119 | Paint paint = new Paint();
120 | paint.setTextSize(fontSize);
121 | Paint.FontMetrics fm = paint.getFontMetrics();
122 | return (int) Math.ceil(fm.descent - fm.top) + 2;
123 | }
124 | }
125 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/btn_down_pause.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wzgiceman/DownProgressView/a84c14e050b5ce52fa942f342eda419e50b83b10/app/src/main/res/drawable-xxhdpi/btn_down_pause.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/btn_vedio_restart.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wzgiceman/DownProgressView/a84c14e050b5ce52fa942f342eda419e50b83b10/app/src/main/res/drawable-xxhdpi/btn_vedio_restart.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxxhdpi/btn_down_pause.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wzgiceman/DownProgressView/a84c14e050b5ce52fa942f342eda419e50b83b10/app/src/main/res/drawable-xxxhdpi/btn_down_pause.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxxhdpi/btn_vedio_restart.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wzgiceman/DownProgressView/a84c14e050b5ce52fa942f342eda419e50b83b10/app/src/main/res/drawable-xxxhdpi/btn_vedio_restart.png
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
15 |
16 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_my_view1.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
12 |
13 |
14 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wzgiceman/DownProgressView/a84c14e050b5ce52fa942f342eda419e50b83b10/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wzgiceman/DownProgressView/a84c14e050b5ce52fa942f342eda419e50b83b10/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wzgiceman/DownProgressView/a84c14e050b5ce52fa942f342eda419e50b83b10/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wzgiceman/DownProgressView/a84c14e050b5ce52fa942f342eda419e50b83b10/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/btn_down_pause.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wzgiceman/DownProgressView/a84c14e050b5ce52fa942f342eda419e50b83b10/app/src/main/res/mipmap-xxxhdpi/btn_down_pause.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/btn_vedio_restart.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wzgiceman/DownProgressView/a84c14e050b5ce52fa942f342eda419e50b83b10/app/src/main/res/mipmap-xxxhdpi/btn_vedio_restart.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wzgiceman/DownProgressView/a84c14e050b5ce52fa942f342eda419e50b83b10/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 | #ffffff
7 | #D85823
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | MyView
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.1.0'
9 |
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | jcenter()
18 | }
19 | }
20 |
21 | task clean(type: Delete) {
22 | delete rootProject.buildDir
23 | }
24 |
--------------------------------------------------------------------------------
/gif/ios_progress.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wzgiceman/DownProgressView/a84c14e050b5ce52fa942f342eda419e50b83b10/gif/ios_progress.gif
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wzgiceman/DownProgressView/a84c14e050b5ce52fa942f342eda419e50b83b10/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 28 10:00:20 PST 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------