Skip to content

Commit 4e421ad

Browse files
committed
增加一个Loading控件
1 parent 8cea8a5 commit 4e421ad

File tree

11 files changed

+234
-3
lines changed

11 files changed

+234
-3
lines changed

.idea/caches/build_file_checksums.ser

0 Bytes
Binary file not shown.

.idea/dictionaries/kingadmin.xml

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

app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@
3838
<activity android:name=".SpiderWebActivity" />
3939
<activity android:name=".QRCodeActivity" />
4040
<activity android:name=".PhotoActivity" />
41-
<activity android:name=".BlurActivity">
41+
<activity android:name=".BlurActivity"/>
42+
<activity android:name=".LoadingActivity">
4243

4344
</activity>
4445
</application>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package cn.ypz.com.killetomrxmaterialdesignutil
2+
3+
import android.os.Bundle
4+
import android.support.v7.app.AppCompatActivity
5+
import kotlinx.android.synthetic.main.activity_loading.*
6+
7+
class LoadingActivity : AppCompatActivity() {
8+
9+
override fun onCreate(savedInstanceState: Bundle?) {
10+
super.onCreate(savedInstanceState)
11+
setContentView(R.layout.activity_loading)
12+
l1.start()
13+
}
14+
}

app/src/main/java/cn/ypz/com/killetomrxmaterialdesignutil/MainActivity.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@ class MainActivity : BaseActivity() {
1919
qrcode.setOnClickListener { easyStartActivity(QRCodeActivity::class.java) }
2020
photo.setOnClickListener { easyStartActivity(PhotoActivity::class.java) }
2121
blur.setOnClickListener { easyStartActivity(BlurActivity::class.java) }
22+
load.setOnClickListener { easyStartActivity(LoadingActivity::class.java) }
2223
}
2324
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
xmlns:tools="http://schemas.android.com/tools"
5+
android:layout_width="match_parent"
6+
android:layout_height="match_parent"
7+
android:background="@android:color/white"
8+
tools:context=".LoadingActivity">
9+
10+
<cn.ypz.com.killetomrxmateria.rxwidget.loading.RxEasyArcLoading
11+
android:id="@+id/l1"
12+
android:layout_width="200dp"
13+
android:layout_height="200dp"
14+
android:layout_marginBottom="8dp"
15+
android:layout_marginEnd="8dp"
16+
android:layout_marginStart="8dp"
17+
android:layout_marginTop="8dp"
18+
app:layout_constraintBottom_toBottomOf="parent"
19+
app:layout_constraintEnd_toEndOf="parent"
20+
app:layout_constraintStart_toStartOf="parent"
21+
app:layout_constraintTop_toTopOf="parent" />
22+
23+
24+
</android.support.constraint.ConstraintLayout>

app/src/main/res/layout/activity_main.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,14 @@
8888
android:theme="@style/RxRaisedDropPrimaryStyle2"
8989
android:layout_gravity="center_horizontal"/>
9090

91+
<cn.ypz.com.killetomrxmateria.rxwidget.raisebutton.RxRaisedDropButton
92+
android:id="@+id/load"
93+
android:layout_width="wrap_content"
94+
android:layout_height="wrap_content"
95+
android:text="load"
96+
android:theme="@style/RxRaisedDropPrimaryStyle2"
97+
android:layout_gravity="center_horizontal"/>
98+
9199
</LinearLayout>
92100

93101
</ScrollView>
294 KB
Loading

killetomRxMateria/src/main/java/cn/ypz/com/killetomrxmateria/rxwidget/base/BaseView.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cn.ypz.com.killetomrxmateria.rxwidget.base;
22

33
import android.content.Context;
4+
import android.graphics.Paint;
45
import android.support.annotation.Nullable;
56
import android.util.AttributeSet;
67
import android.view.View;
@@ -29,4 +30,8 @@ public BaseView(Context context, @Nullable AttributeSet attrs, int defStyleAttr,
2930
protected boolean isSetDimen(int measureSpecSize) {
3031
return (MeasureSpec.getMode(measureSpecSize) == MeasureSpec.EXACTLY);
3132
}
33+
34+
protected void paintSetColorId(Paint paint,int colorId){
35+
paint.setColor(getResources().getColor(colorId));
36+
}
3237
}
Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
package cn.ypz.com.killetomrxmateria.rxwidget.loading;
2+
3+
import android.animation.ValueAnimator;
4+
import android.content.Context;
5+
import android.graphics.Canvas;
6+
import android.graphics.Paint;
7+
import android.graphics.RectF;
8+
import android.support.annotation.Nullable;
9+
import android.util.AttributeSet;
10+
import android.util.Log;
11+
import android.view.animation.LinearInterpolator;
12+
13+
import cn.ypz.com.killetomrxmateria.R;
14+
import cn.ypz.com.killetomrxmateria.rxwidget.RxDimenUtils;
15+
import cn.ypz.com.killetomrxmateria.rxwidget.base.BaseView;
16+
17+
public class RxEasyArcLoading extends BaseView {
18+
private Paint arc0FP = new Paint();
19+
private Paint arc1FP = new Paint();
20+
private Paint arc2FP = new Paint();
21+
private Paint arc3FP = new Paint();
22+
private int dp50 = RxDimenUtils.dpToPx(50, getResources());
23+
private int dp10 = RxDimenUtils.dpToPx(10, getResources());
24+
private float multiple;
25+
private int arc0_f, arc1_f, arc2_f, arc3_f;
26+
private int arc0_s, arc1_s, arc2_s, arc3_s;
27+
private RectF oval;
28+
private int w; //View宽高
29+
private int h;
30+
private float r;
31+
private int mini;
32+
33+
private ValueAnimator arc0Animator = ValueAnimator.ofInt(0, 360);
34+
private ValueAnimator arc1Animator = ValueAnimator.ofInt(0, 360);
35+
private ValueAnimator arc2Animator = ValueAnimator.ofInt(0, 360);
36+
private ValueAnimator arc3Animator = ValueAnimator.ofInt(0, 360);
37+
38+
public RxEasyArcLoading(Context context) {
39+
super(context);
40+
}
41+
42+
public RxEasyArcLoading(Context context, @Nullable AttributeSet attrs) {
43+
super(context, attrs);
44+
paintSetColorId(arc0FP, R.color.deepskyblue);
45+
paintSetColorId(arc1FP, R.color.goldenrod);
46+
paintSetColorId(arc2FP, R.color.crimson);
47+
paintSetColorId(arc3FP, R.color.violet);
48+
reset();
49+
arc1Animator.addUpdateListener(animation -> {
50+
arc1_f = (int) animation.getAnimatedValue() + 31;
51+
arc2_s = (int) animation.getAnimatedValue() - 127;
52+
});
53+
arc2Animator.addUpdateListener(animation -> {
54+
arc2_f = (int) animation.getAnimatedValue() - 127;
55+
arc3_s = (int) animation.getAnimatedValue() + 100;
56+
});
57+
arc3Animator.addUpdateListener(animation -> {
58+
arc3_f = (int) animation.getAnimatedValue() + 100;
59+
arc0_s = (int) animation.getAnimatedValue() - 26;
60+
});
61+
arc0Animator.addUpdateListener(animation -> {
62+
arc0_f = (int) animation.getAnimatedValue() - 26;
63+
arc1_s = (int) animation.getAnimatedValue() + 31;
64+
postInvalidate();
65+
});
66+
arc0Animator.setDuration(3200);
67+
arc0Animator.setRepeatCount(-1);
68+
arc0Animator.setRepeatMode(ValueAnimator.RESTART);
69+
arc0Animator.setInterpolator(new LinearInterpolator());
70+
arc1Animator.setDuration(2850);
71+
arc2Animator.setDuration(2300);
72+
arc3Animator.setDuration(1950);
73+
arc1Animator.setRepeatCount(-1);
74+
arc2Animator.setRepeatCount(-1);
75+
arc3Animator.setRepeatCount(-1);
76+
arc1Animator.setInterpolator(new LinearInterpolator());
77+
arc2Animator.setInterpolator(new LinearInterpolator());
78+
arc3Animator.setInterpolator(new LinearInterpolator());
79+
oval = new RectF();
80+
setPaint(arc0FP);
81+
setPaint(arc1FP);
82+
setPaint(arc2FP);
83+
setPaint(arc3FP);
84+
}
85+
86+
private void setPaint(Paint paint) {
87+
paint.setAntiAlias(true);//使用抗锯齿功能
88+
paint.setStyle(Paint.Style.STROKE);//
89+
if (multiple > 1) paint.setStrokeWidth(dp10 * multiple / 5);
90+
else paint.setStrokeWidth(dp10 / 4);
91+
}
92+
93+
protected void reset() {
94+
arc0_s = arc0_f = -26;
95+
arc1_s = arc1_f = 31;
96+
arc2_s = arc2_f = -127;
97+
arc3_s = arc3_f = 100;
98+
}
99+
100+
protected void stop() {
101+
if (arc0Animator.isRunning()) arc0Animator.pause();
102+
if (arc1Animator.isRunning()) arc1Animator.pause();
103+
if (arc2Animator.isRunning()) arc2Animator.pause();
104+
if (arc3Animator.isRunning()) arc3Animator.pause();
105+
}
106+
107+
protected void reStart() {
108+
if (arc0Animator.isPaused()) arc0Animator.resume();
109+
if (arc1Animator.isPaused()) arc0Animator.resume();
110+
if (arc2Animator.isPaused()) arc0Animator.resume();
111+
if (arc3Animator.isPaused()) arc0Animator.resume();
112+
}
113+
114+
public void cancle() {
115+
if (arc0Animator.isStarted()) arc0Animator.cancel();
116+
if (arc1Animator.isStarted()) arc1Animator.cancel();
117+
if (arc2Animator.isStarted()) arc2Animator.cancel();
118+
if (arc3Animator.isStarted()) arc3Animator.cancel();
119+
}
120+
121+
public void start() {
122+
if (!arc0Animator.isStarted()) arc0Animator.start();
123+
if (!arc1Animator.isStarted()) arc1Animator.start();
124+
if (!arc2Animator.isStarted()) arc2Animator.start();
125+
if (!arc3Animator.isStarted()) arc3Animator.start();
126+
}
127+
128+
@Override
129+
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
130+
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
131+
Log.i("ypzLoading", widthMeasureSpec + "\n" + dp50);
132+
if (!isSetDimen(widthMeasureSpec) || widthMeasureSpec < dp50) {
133+
widthMeasureSpec = dp50;
134+
}
135+
if (!isSetDimen(heightMeasureSpec) || heightMeasureSpec < dp50) {
136+
heightMeasureSpec = dp50;
137+
}
138+
setMeasuredDimension(widthMeasureSpec, heightMeasureSpec);
139+
}
140+
141+
@Override
142+
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
143+
super.onSizeChanged(w, h, oldw, oldh);
144+
this.w = w;
145+
this.h = h;
146+
mini = Math.min(w,h);
147+
multiple = Math.min(w, h) / dp50;
148+
149+
}
150+
151+
@Override
152+
protected void initAttr(Context context, @Nullable AttributeSet attrs) {
153+
154+
}
155+
156+
@Override
157+
protected void onDraw(Canvas canvas) {
158+
super.onDraw(canvas);
159+
canvas.translate(w / 2, h / 2);//绘画点移动至中心点
160+
int i = 1;
161+
for (int nextR=mini/2-dp10;nextR>0; nextR-=dp10){
162+
oval.set(-nextR, -nextR, nextR, nextR);
163+
if (i%2==0){
164+
canvas.drawArc(oval, arc0_s, 52, false, arc0FP);
165+
canvas.drawArc(oval, arc1_s, 64, false, arc1FP);
166+
canvas.drawArc(oval, arc2_s, 96, false, arc2FP);
167+
canvas.drawArc(oval, arc3_s, 128, false, arc3FP);
168+
}else {
169+
canvas.drawArc(oval, arc0_f, 52, false, arc0FP);
170+
canvas.drawArc(oval, arc1_f, 64, false, arc1FP);
171+
canvas.drawArc(oval, arc2_f, 96, false, arc2FP);
172+
canvas.drawArc(oval, arc3_f, 128, false, arc3FP);
173+
}
174+
i+=1;
175+
}
176+
}
177+
}

0 commit comments

Comments
 (0)