Skip to content
This repository was archived by the owner on Jan 8, 2022. It is now read-only.

Commit 8afc950

Browse files
committed
新增一个Loading样式
1 parent 90f9395 commit 8afc950

18 files changed

Lines changed: 235 additions & 19 deletions

File tree

.idea/gradle.xml

Lines changed: 3 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

LoadingDialog/src/main/java/com/xiasuhuei321/loadingdialog/manager/StyleManager.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,22 @@ public StyleManager(boolean open, int repeatTime, LoadingDialog.Speed speed,
2727

2828
}
2929

30+
public StyleManager(boolean open, int repeatTime, LoadingDialog.Speed speed,
31+
int contentSize, int textSize, long showTime, boolean interceptBack,
32+
String loadText, String successText, String failedText,int loadStyle) {
33+
this.openAnim = open;
34+
this.repeatTime = repeatTime;
35+
this.speed = speed;
36+
this.contentSize = contentSize;
37+
this.textSize = textSize;
38+
this.showTime = showTime;
39+
this.interceptBack = interceptBack;
40+
this.loadText = loadText;
41+
this.successText = successText;
42+
this.failedText = failedText;
43+
this.loadStyle = loadStyle;
44+
}
45+
3046
/**
3147
* 是否开启绘制
3248
*/
@@ -62,6 +78,17 @@ public StyleManager(boolean open, int repeatTime, LoadingDialog.Speed speed,
6278

6379
private String failedText = "加载失败";
6480

81+
private int loadStyle = LoadingDialog.STYLE_RING;
82+
83+
public StyleManager setLoadStyle(int loadStyle) {
84+
this.loadStyle = loadStyle;
85+
return this;
86+
}
87+
88+
public int getLoadStyle() {
89+
return loadStyle;
90+
}
91+
6592
public boolean isOpenAnim() {
6693
return openAnim;
6794
}

LoadingDialog/src/main/java/com/xiasuhuei321/loadingdialog/readme.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

LoadingDialog/src/main/java/com/xiasuhuei321/loadingdialog/view/LVCircularRing.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import android.graphics.RectF;
1111
import android.support.annotation.ColorInt;
1212
import android.util.AttributeSet;
13+
import android.util.Log;
1314
import android.view.View;
1415
import android.view.animation.LinearInterpolator;
1516

@@ -18,6 +19,7 @@
1819
* desc:
1920
*/
2021
public class LVCircularRing extends View {
22+
public final String TAG = getClass().getSimpleName();
2123
private float mWidth = 0f;
2224
private float mPadding = 0f;
2325
private float startAngle = 0f;
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
package com.xiasuhuei321.loadingdialog.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.View;
11+
12+
/**
13+
* Created by xiasuhuei321 on 2017/5/15.
14+
* author:luo
15+
* e-mail:xiasuhuei321@163.com
16+
*/
17+
18+
public class LoadCircleView extends View {
19+
public final String TAG = getClass().getSimpleName();
20+
21+
private float mPadding = 0f;
22+
private RectF rectF;
23+
private Context mContext;
24+
private Paint mPaint;
25+
private int mWidth = 0;
26+
private int currentLineIndex = 0;
27+
28+
public LoadCircleView(Context context) {
29+
this(context, null);
30+
}
31+
32+
public LoadCircleView(Context context, AttributeSet attrs) {
33+
this(context, attrs, 0);
34+
}
35+
36+
public LoadCircleView(Context context, AttributeSet attrs, int defStyleAttr) {
37+
super(context, attrs, defStyleAttr);
38+
mContext = context;
39+
init();
40+
}
41+
42+
public void init() {
43+
mPaint = new Paint();
44+
mPaint.setAntiAlias(true);
45+
mPaint.setStyle(Paint.Style.STROKE);
46+
// mPaint.setColor(Color.BLACK);
47+
mPaint.setStrokeWidth(8);
48+
}
49+
50+
@Override
51+
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
52+
int widthSpecMode = MeasureSpec.getMode(widthMeasureSpec);
53+
int widthSpecSize = MeasureSpec.getSize(widthMeasureSpec);
54+
55+
int heightSpecMode = MeasureSpec.getMode(heightMeasureSpec);
56+
int heightSpecSize = MeasureSpec.getSize(heightMeasureSpec);
57+
58+
if (widthSpecMode != MeasureSpec.AT_MOST && heightSpecMode != MeasureSpec.AT_MOST) {
59+
mWidth = widthSpecSize >= heightSpecSize ? widthSpecSize : heightSpecSize;
60+
} else if (widthSpecMode == MeasureSpec.AT_MOST && heightSpecMode != MeasureSpec.AT_MOST) {
61+
mWidth = heightSpecSize;
62+
} else if (widthSpecMode != MeasureSpec.AT_MOST) {
63+
mWidth = widthSpecSize;
64+
} else {
65+
mWidth = SizeUtils.dip2px(mContext, 50);
66+
}
67+
setMeasuredDimension(mWidth, mWidth);
68+
mPadding = 8;
69+
// rectF = new RectF(mPadding, mPadding, mWidth - mPadding, mWidth - mPadding);
70+
}
71+
72+
@Override
73+
protected void onDraw(Canvas canvas) {
74+
// 圆心坐标 (center,center)
75+
int center = mWidth / 2;
76+
int radius = mWidth / 2 - 8;
77+
if (currentLineIndex >= 12)
78+
currentLineIndex = 0;
79+
// canvas.rotate(currentLineIndex * 30, center, center);
80+
// 画12根线
81+
for (int i = 0; i < 12; i++) {
82+
if (i < currentLineIndex + 4 && i >= currentLineIndex) {
83+
mPaint.setColor(Color.GRAY);
84+
} else if (currentLineIndex > 8 && i < currentLineIndex + 4 - 12) {
85+
mPaint.setColor(Color.GRAY);
86+
} else {
87+
mPaint.setColor(Color.WHITE);
88+
}
89+
90+
// canvas.drawLine(center, (float) (center + 1.0 / 4 * center),
91+
// center, (float) (center + 1.0 / 2 * radius), mPaint);
92+
canvas.drawLine(center, (float) (center + 1.0 / 2 * radius),
93+
center, 2 * radius, mPaint);
94+
canvas.rotate(30, center, center);
95+
}
96+
currentLineIndex++;
97+
postInvalidateDelayed(50);
98+
}
99+
100+
101+
}

LoadingDialog/src/main/java/com/xiasuhuei321/loadingdialog/view/LoadingDialog.java

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
* desc:加载等待的Dialog
2525
*/
2626
public class LoadingDialog implements FinishDrawListener {
27+
public final String TAG = "LoadingDialog";
28+
public static final int STYLE_RING = 0;
29+
public static final int STYLE_LINE = 1;
2730
private Context mContext;
2831

2932
private LVCircularRing mLoadingView;
@@ -42,15 +45,19 @@ public class LoadingDialog implements FinishDrawListener {
4245
private boolean openFailedAnim = true;
4346
private int speed = 1;
4447
private long time = 1000;
48+
private int loadStyle = STYLE_RING;
4549

4650
private static StyleManager s = new StyleManager(true, 0, Speed.SPEED_TWO, -1, -1, 1000L,
4751
true, "加载中...", "加载成功", "加载失败");
52+
private LoadCircleView mCircleLoadView;
4853

4954
public enum Speed {
5055
SPEED_ONE,
5156
SPEED_TWO
5257
}
5358

59+
private OnFinshListener o;
60+
5461
public LoadingDialog(Context context) {
5562
mContext = context;
5663
// 首先得到整个View
@@ -82,6 +89,7 @@ private void initView(View view) {
8289
loadingText = (TextView) view.findViewById(R.id.loading_text);
8390
mSuccessView = (RightDiaView) view.findViewById(R.id.rdv_right);
8491
mFailedView = (WrongDiaView) view.findViewById(R.id.wv_wrong);
92+
mCircleLoadView = (LoadCircleView) view.findViewById(R.id.lcv_circleload);
8593
initData();
8694
}
8795

@@ -90,6 +98,7 @@ private void initData() {
9098
viewList.add(mLoadingView);
9199
viewList.add(mSuccessView);
92100
viewList.add(mFailedView);
101+
viewList.add(mCircleLoadView);
93102

94103
mSuccessView.setOnDrawFinishListener(this);
95104
mFailedView.setOnDrawFinishListener(this);
@@ -133,6 +142,7 @@ private void setParams(int size) {
133142
@Override
134143
public void handleMessage(Message msg) {
135144
LoadingDialog.this.close();
145+
if (o != null) o.onFinish();
136146
}
137147
};
138148

@@ -151,6 +161,7 @@ private void initStyle() {
151161
setLoadingText(s.getLoadText());
152162
setSuccessText(s.getSuccessText());
153163
setFailedText(s.getFailedText());
164+
setLoadStyle(s.getLoadStyle());
154165
}
155166
}
156167

@@ -161,9 +172,23 @@ private void initStyle() {
161172
*/
162173
public void show() {
163174
hideAll();
164-
mLoadingView.setVisibility(View.VISIBLE);
165-
mLoadingDialog.show();
166-
mLoadingView.startAnim();
175+
if (loadStyle == STYLE_RING) {
176+
mLoadingView.setVisibility(View.VISIBLE);
177+
mCircleLoadView.setVisibility(View.GONE);
178+
mLoadingDialog.show();
179+
mLoadingView.startAnim();
180+
} else if(loadStyle == STYLE_LINE) {
181+
mCircleLoadView.setVisibility(View.VISIBLE);
182+
mLoadingView.setVisibility(View.GONE);
183+
mLoadingDialog.show();
184+
}
185+
}
186+
187+
public void setLoadStyle(int style) {
188+
if (style >= 3) {
189+
throw new IllegalArgumentException("Your style is wrong!");
190+
}
191+
this.loadStyle = style;
167192
}
168193

169194
/**
@@ -370,4 +395,21 @@ public static void initStyle(StyleManager style) {
370395
s = style;
371396
}
372397

398+
/**
399+
* 传递绘制完成的事件
400+
*
401+
* @param o 回调接口
402+
*/
403+
public void setOnFinishListener(OnFinshListener o) {
404+
this.o = o;
405+
}
406+
407+
/**
408+
* 监听器
409+
*/
410+
public interface OnFinshListener {
411+
void onFinish();
412+
}
413+
414+
373415
}

LoadingDialog/src/main/java/com/xiasuhuei321/loadingdialog/view/RightDiaView.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
/**
1212
* Created by Luo_xiasuhuei321@163.com on 2016/11/5.
1313
* desc:
14+
* TODO: 目前这个对勾还有点问题,在下个版本发布之前解决这个问题!问题在两条线的交点
1415
*/
1516

1617
public class RightDiaView extends View {
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## 更新工作笔记
2+
* 一个类似于SwipeRefreshLayout的loading
3+
* 一个类似于很多应用下拉刷新的的进度条(比如XRecyclerView默认的那个loading)

0 commit comments

Comments
 (0)