Skip to content

Commit 8305c87

Browse files
committed
【ADD】新增圆形等待动画,和秒表型等待动画
0 parents  commit 8305c87

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1445
-0
lines changed

.gitignore

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/workspace.xml
5+
/.idea/libraries
6+
.DS_Store
7+
/build
8+
/captures
9+
.externalNativeBuild

app/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

app/build.gradle

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
apply plugin: 'com.android.application'
2+
3+
android {
4+
compileSdkVersion 25
5+
buildToolsVersion "25.0.2"
6+
defaultConfig {
7+
applicationId "com.zyao89.zcustomview"
8+
minSdkVersion 15
9+
targetSdkVersion 25
10+
versionCode 1
11+
versionName "1.0"
12+
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13+
}
14+
buildTypes {
15+
release {
16+
minifyEnabled false
17+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18+
}
19+
}
20+
}
21+
22+
dependencies {
23+
compile fileTree(dir: 'libs', include: ['*.jar'])
24+
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
25+
exclude group: 'com.android.support', module: 'support-annotations'
26+
})
27+
compile 'com.android.support:appcompat-v7:25.2.0'
28+
testCompile 'junit:junit:4.12'
29+
compile project(path: ':zloadingview')
30+
}

app/proguard-rules.pro

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Add project specific ProGuard rules here.
2+
# By default, the flags in this file are appended to flags specified
3+
# in /Users/zyao89/Library/Android/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+
#}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.zyao89.zcustomview;
2+
3+
import android.content.Context;
4+
import android.support.test.InstrumentationRegistry;
5+
import android.support.test.runner.AndroidJUnit4;
6+
7+
import org.junit.Test;
8+
import org.junit.runner.RunWith;
9+
10+
import static org.junit.Assert.*;
11+
12+
/**
13+
* Instrumentation test, which will execute on an Android device.
14+
*
15+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
16+
*/
17+
@RunWith(AndroidJUnit4.class)
18+
public class ExampleInstrumentedTest
19+
{
20+
@Test
21+
public void useAppContext() throws Exception
22+
{
23+
// Context of the app under test.
24+
Context appContext = InstrumentationRegistry.getTargetContext();
25+
26+
assertEquals("com.zyao89.zcustomview", appContext.getPackageName());
27+
}
28+
}

app/src/main/AndroidManifest.xml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.zyao89.zcustomview">
4+
5+
<application
6+
android:allowBackup="true"
7+
android:icon="@mipmap/ic_launcher"
8+
android:label="@string/app_name"
9+
android:supportsRtl="true"
10+
android:theme="@style/AppTheme">
11+
<activity android:name=".MainActivity">
12+
<intent-filter>
13+
<action android:name="android.intent.action.MAIN"/>
14+
15+
<category android:name="android.intent.category.LAUNCHER"/>
16+
</intent-filter>
17+
</activity>
18+
<activity android:name=".loading.ShowActivity">
19+
</activity>
20+
</application>
21+
22+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.zyao89.zcustomview;
2+
3+
import android.content.Intent;
4+
import android.support.v7.app.AppCompatActivity;
5+
import android.os.Bundle;
6+
import android.support.v7.widget.AppCompatButton;
7+
import android.view.View;
8+
9+
import com.zyao89.zcustomview.loading.ShowActivity;
10+
11+
public class MainActivity extends AppCompatActivity
12+
{
13+
14+
private AppCompatButton mClockLoading;
15+
16+
@Override
17+
protected void onCreate(Bundle savedInstanceState)
18+
{
19+
super.onCreate(savedInstanceState);
20+
setContentView(R.layout.activity_main);
21+
mClockLoading = (AppCompatButton) findViewById(R.id.clockLoading);
22+
23+
initListeners();
24+
}
25+
26+
private void initListeners()
27+
{
28+
mClockLoading.setOnClickListener(new View.OnClickListener() {
29+
@Override
30+
public void onClick(View v)
31+
{
32+
Intent intent = new Intent(MainActivity.this, ShowActivity.class);
33+
startActivity(intent);
34+
}
35+
});
36+
}
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
package com.zyao89.zcustomview.loading;
2+
3+
import android.animation.Animator;
4+
import android.animation.ValueAnimator;
5+
import android.content.Context;
6+
import android.graphics.Canvas;
7+
import android.graphics.Color;
8+
import android.graphics.Paint;
9+
import android.graphics.RectF;
10+
import android.util.AttributeSet;
11+
import android.view.View;
12+
13+
/**
14+
* Created by zyao89 on 2017/3/16.
15+
16+
* For more projects: https://github.com/zyao89
17+
* My Blog: http://zyao89.me
18+
*/
19+
public class ClockLoading extends View implements Animator.AnimatorListener, ValueAnimator.AnimatorUpdateListener
20+
{
21+
private Paint mPaint;
22+
private int mViewWidth;
23+
private int mViewHeight;
24+
private int mViewCenterX;
25+
private int mViewCenterY;
26+
private int mBigRadius;
27+
private int mInnerRadius;
28+
private RectF mInnerCircleRectF;
29+
private float mStartAngle;
30+
private float mEndAngle;
31+
private ValueAnimator mStartAnimator;
32+
private boolean mIsFirstState = true;
33+
34+
public ClockLoading(Context context)
35+
{
36+
this(context, null);
37+
}
38+
39+
public ClockLoading(Context context, AttributeSet attrs)
40+
{
41+
this(context, attrs, 0);
42+
}
43+
44+
public ClockLoading(Context context, AttributeSet attrs, int defStyleAttr)
45+
{
46+
super(context, attrs, defStyleAttr);
47+
init(context, attrs);
48+
}
49+
50+
private void init(Context context, AttributeSet attrs)
51+
{
52+
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
53+
mPaint.setColor(Color.BLACK);
54+
55+
mStartAnimator = ValueAnimator.ofFloat(0, 359);
56+
mStartAnimator.setStartDelay(500);
57+
58+
initValues();
59+
}
60+
61+
private void initValues()
62+
{
63+
mBigRadius = 50;
64+
mInnerRadius = mBigRadius - 10;
65+
mInnerCircleRectF = new RectF();
66+
67+
mStartAngle = 0;
68+
mEndAngle = 0;
69+
}
70+
71+
@Override
72+
protected void onSizeChanged(int w, int h, int oldw, int oldh)
73+
{
74+
mViewWidth = w;
75+
mViewHeight = h;
76+
mViewCenterX = w / 2;
77+
mViewCenterY = h / 2;
78+
79+
mInnerCircleRectF.set(mViewCenterX - mInnerRadius, mViewCenterY - mInnerRadius, mViewCenterX + mInnerRadius, mViewCenterY + mInnerRadius);
80+
}
81+
82+
@Override
83+
protected void onAttachedToWindow()
84+
{
85+
super.onAttachedToWindow();
86+
if (mStartAnimator != null)
87+
{
88+
mStartAnimator.setRepeatCount(ValueAnimator.INFINITE);
89+
mStartAnimator.setDuration(1000);
90+
mStartAnimator.addListener(this);
91+
mStartAnimator.addUpdateListener(this);
92+
mStartAnimator.start();
93+
}
94+
}
95+
96+
@Override
97+
protected void onDetachedFromWindow()
98+
{
99+
super.onDetachedFromWindow();
100+
if (mStartAnimator != null)
101+
{
102+
mStartAnimator.setRepeatCount(0);
103+
mStartAnimator.setDuration(0);
104+
mStartAnimator.cancel();
105+
mStartAnimator.removeAllUpdateListeners();
106+
mStartAnimator.removeAllListeners();
107+
}
108+
}
109+
110+
@Override
111+
protected void onDraw(Canvas canvas)
112+
{
113+
// canvas.drawCircle(mViewCenterX, mViewCenterY ,50, mPaint);
114+
115+
canvas.drawArc(mInnerCircleRectF, mStartAngle, mEndAngle - mStartAngle, true, mPaint);
116+
}
117+
118+
119+
@Override
120+
public void onAnimationStart(Animator animation)
121+
{
122+
mStartAngle = 0;
123+
mEndAngle = 0;
124+
}
125+
126+
@Override
127+
public void onAnimationEnd(Animator animation)
128+
{
129+
mStartAngle = 0;
130+
mEndAngle = 0;
131+
}
132+
133+
@Override
134+
public void onAnimationCancel(Animator animation)
135+
{
136+
mStartAngle = 0;
137+
mEndAngle = 0;
138+
}
139+
140+
@Override
141+
public void onAnimationRepeat(Animator animation)
142+
{
143+
mIsFirstState = !mIsFirstState;
144+
if (mIsFirstState)
145+
{
146+
mStartAngle = 0;
147+
mEndAngle = 0;
148+
}
149+
else
150+
{
151+
mStartAngle = 0;
152+
mEndAngle = 360;
153+
}
154+
155+
}
156+
157+
@Override
158+
public void onAnimationUpdate(ValueAnimator animation)
159+
{
160+
float value = (float) animation.getAnimatedValue();
161+
162+
if (mIsFirstState)
163+
{
164+
mEndAngle = value;
165+
}
166+
else
167+
{
168+
mStartAngle = value;
169+
}
170+
171+
postInvalidate();
172+
}
173+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.zyao89.zcustomview.loading;
2+
3+
import android.graphics.Color;
4+
import android.support.v7.app.AppCompatActivity;
5+
import android.os.Bundle;
6+
7+
import com.zyao89.view.zloading.Z_TYPE;
8+
import com.zyao89.view.zloading.ZLoadingView;
9+
import com.zyao89.zcustomview.R;
10+
11+
public class ShowActivity extends AppCompatActivity
12+
{
13+
14+
@Override
15+
protected void onCreate(Bundle savedInstanceState)
16+
{
17+
super.onCreate(savedInstanceState);
18+
setContentView(R.layout.activity_show);
19+
20+
init();
21+
}
22+
23+
private void init()
24+
{
25+
ZLoadingView clockLoading = (ZLoadingView) findViewById(R.id.loadingView);
26+
clockLoading.setColorFilter(Color.BLUE);
27+
clockLoading.setLoadingBuilder(Z_TYPE.CIRCLE_CLOCK);
28+
}
29+
}
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<android.support.v4.widget.NestedScrollView
3+
xmlns:android="http://schemas.android.com/apk/res/android"
4+
xmlns:tools="http://schemas.android.com/tools"
5+
android:id="@+id/activity_main"
6+
android:layout_width="match_parent"
7+
android:layout_height="match_parent"
8+
android:paddingBottom="@dimen/activity_vertical_margin"
9+
android:paddingLeft="@dimen/activity_horizontal_margin"
10+
android:paddingRight="@dimen/activity_horizontal_margin"
11+
android:paddingTop="@dimen/activity_vertical_margin"
12+
tools:context="com.zyao89.zcustomview.MainActivity">
13+
14+
<android.support.v7.widget.AppCompatButton
15+
android:id="@+id/clockLoading"
16+
android:layout_width="match_parent"
17+
android:layout_height="wrap_content"
18+
android:padding="10dp"
19+
android:text="Clock Loading"/>
20+
21+
</android.support.v4.widget.NestedScrollView>

0 commit comments

Comments
 (0)