├── .gitignore
├── README.md
├── apk
└── app-debug.apk
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── wang
│ │ └── avi
│ │ └── sample
│ │ └── ApplicationTest.java
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── wang
│ │ └── avi
│ │ └── sample
│ │ ├── IndicatorActivity.java
│ │ ├── MyCustomIndicator.java
│ │ └── SampleActivity.java
│ └── res
│ ├── layout
│ ├── activity_indicator.xml
│ ├── activity_sample.xml
│ └── item_indicator.xml
│ ├── menu
│ └── menu_main.xml
│ ├── mipmap-hdpi
│ └── ic_launcher.png
│ ├── mipmap-mdpi
│ └── ic_launcher.png
│ ├── mipmap-xhdpi
│ └── ic_launcher.png
│ ├── mipmap-xxhdpi
│ └── ic_launcher.png
│ ├── values-w820dp
│ └── dimens.xml
│ └── values
│ ├── dimens.xml
│ ├── strings.xml
│ └── styles.xml
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── library
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── wang
│ │ └── avi
│ │ └── ApplicationTest.java
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── wang
│ │ └── avi
│ │ ├── AVLoadingIndicatorView.java
│ │ ├── Indicator.java
│ │ └── indicators
│ │ ├── BallBeatIndicator.java
│ │ ├── BallClipRotateIndicator.java
│ │ ├── BallClipRotateMultipleIndicator.java
│ │ ├── BallClipRotatePulseIndicator.java
│ │ ├── BallGridBeatIndicator.java
│ │ ├── BallGridPulseIndicator.java
│ │ ├── BallPulseIndicator.java
│ │ ├── BallPulseRiseIndicator.java
│ │ ├── BallPulseSyncIndicator.java
│ │ ├── BallRotateIndicator.java
│ │ ├── BallScaleIndicator.java
│ │ ├── BallScaleMultipleIndicator.java
│ │ ├── BallScaleRippleIndicator.java
│ │ ├── BallScaleRippleMultipleIndicator.java
│ │ ├── BallSpinFadeLoaderIndicator.java
│ │ ├── BallTrianglePathIndicator.java
│ │ ├── BallZigZagDeflectIndicator.java
│ │ ├── BallZigZagIndicator.java
│ │ ├── CubeTransitionIndicator.java
│ │ ├── LineScaleIndicator.java
│ │ ├── LineScalePartyIndicator.java
│ │ ├── LineScalePulseOutIndicator.java
│ │ ├── LineScalePulseOutRapidIndicator.java
│ │ ├── LineSpinFadeLoaderIndicator.java
│ │ ├── PacmanIndicator.java
│ │ ├── SemiCircleSpinIndicator.java
│ │ ├── SquareSpinIndicator.java
│ │ └── TriangleSkewSpinIndicator.java
│ └── res
│ └── values
│ ├── attrs.xml
│ ├── strings.xml
│ └── style.xml
├── screenshots
└── avi.gif
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | # built application files
2 | *.ap_
3 |
4 | # files for the dex VM
5 | *.dex
6 |
7 | # Java class files
8 | *.class
9 |
10 | # generated files
11 | bin/
12 | gen/
13 |
14 | # Local configuration file (sdk path, etc)
15 | local.properties
16 |
17 | # Proguard folder generated by Eclipse
18 | proguard/
19 |
20 | # Ignore gradle files
21 | .gradle/
22 | build/
23 |
24 | # Eclipse project files
25 | .classpath
26 | .project
27 | .settings/
28 |
29 | # Intellij project files
30 | *.iml
31 | *.ipr
32 | *.iws
33 | .idea/
34 |
35 | # Mac system files
36 | .DS_Store
37 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # PLEASE NOTE, THIS PROJECT IS NO LONGER BEING MAINTAINED
2 |
3 | * * *
4 |
5 | [](https://android-arsenal.com/details/1/2686)
6 |
7 | AVLoadingIndicatorView
8 | ===================
9 |
10 | > **Now AVLoadingIndicatorView was updated version to 2.X , If you have any question or suggestion with this library , welcome to tell me !**
11 |
12 | ## Introduction
13 | AVLoadingIndicatorView is a collection of nice loading animations for Android.
14 |
15 | You can also find iOS version of this [here](https://github.com/ninjaprox/NVActivityIndicatorView).
16 |
17 | ## Demo
18 | 
19 |
20 | ## Usage
21 |
22 | ### Step 1
23 |
24 | Add dependencies in build.gradle.
25 | ```groovy
26 | dependencies {
27 | compile 'com.wang.avi:library:2.1.3'
28 | }
29 | ```
30 |
31 | ### Step 2
32 |
33 | Add the AVLoadingIndicatorView to your layout:
34 |
35 | Simple
36 |
37 | ```java
38 |
43 | ```
44 |
45 | Advance
46 |
47 | ```java
48 |
57 | ```
58 |
59 | ### Step 3
60 |
61 | It's very simple use just like .
62 | ```java
63 | void startAnim(){
64 | avi.show();
65 | // or avi.smoothToShow();
66 | }
67 |
68 | void stopAnim(){
69 | avi.hide();
70 | // or avi.smoothToHide();
71 | }
72 |
73 | ```
74 |
75 | ## Custom Indicator
76 |
77 | See [MyCustomIndicator](https://github.com/81813780/AVLoadingIndicatorView/blob/master/app/src/main/java/com/wang/avi/sample/MyCustomIndicator.java) in Sample .
78 |
79 | ## Proguard
80 |
81 | When using proguard need add rules:
82 |
83 | ```
84 | -keep class com.wang.avi.** { *; }
85 | -keep class com.wang.avi.indicators.** { *; }
86 | ```
87 |
88 | Indicators is load from class names, proguard may change it (rename).
89 |
90 | ## Indicators
91 |
92 | As seen above in the **Demo**, the indicators are as follows:
93 |
94 | **Row 1**
95 | * `BallPulseIndicator`
96 | * `BallGridPulseIndicator`
97 | * `BallClipRotateIndicator`
98 | * `BallClipRotatePulseIndicator`
99 |
100 | **Row 2**
101 | * `SquareSpinIndicator`
102 | * `BallClipRotateMultipleIndicator`
103 | * `BallPulseRiseIndicator`
104 | * `BallRotateIndicator`
105 |
106 | **Row 3**
107 | * `CubeTransitionIndicator`
108 | * `BallZigZagIndicator`
109 | * `BallZigZagDeflectIndicator`
110 | * `BallTrianglePathIndicator`
111 |
112 | **Row 4**
113 | * `BallScaleIndicator`
114 | * `LineScaleIndicator`
115 | * `LineScalePartyIndicator`
116 | * `BallScaleMultipleIndicator`
117 |
118 | **Row 5**
119 | * `BallPulseSyncIndicator`
120 | * `BallBeatIndicator`
121 | * `LineScalePulseOutIndicator`
122 | * `LineScalePulseOutRapidIndicator`
123 |
124 | **Row 6**
125 | * `BallScaleRippleIndicator`
126 | * `BallScaleRippleMultipleIndicator`
127 | * `BallSpinFadeLoaderIndicator`
128 | * `LineSpinFadeLoaderIndicator`
129 |
130 | **Row 7**
131 | * `TriangleSkewSpinIndicator`
132 | * `PacmanIndicator`
133 | * `BallGridBeatIndicator`
134 | * `SemiCircleSpinIndicator`
135 |
136 | **Row 8**
137 | * `com.wang.avi.sample.MyCustomIndicator`
138 |
139 | ## Thanks
140 | - [NVActivityIndicatorView](https://github.com/ninjaprox/NVActivityIndicatorView)
141 | - [Connor Atherton](https://github.com/ConnorAtherton)
142 |
143 | ## Contact me
144 |
145 | If you have a better idea or way on this project, please let me know, thanks :)
146 |
147 | [Email](mailto:81813780@qq.com)
148 |
149 | [Weibo](http://weibo.com/601265161)
150 |
151 | [My Blog](http://hlong.xyz)
152 |
153 | ### License
154 | ```
155 | Copyright 2015 jack wang
156 |
157 | Licensed under the Apache License, Version 2.0 (the "License");
158 | you may not use this file except in compliance with the License.
159 | You may obtain a copy of the License at
160 |
161 | http://www.apache.org/licenses/LICENSE-2.0
162 |
163 | Unless required by applicable law or agreed to in writing, software
164 | distributed under the License is distributed on an "AS IS" BASIS,
165 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
166 | See the License for the specific language governing permissions and
167 | limitations under the License.
168 | ```
169 |
170 |
--------------------------------------------------------------------------------
/apk/app-debug.apk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HarlonWang/AVLoadingIndicatorView/841f98d230b14f0617e541a8b421f8dd96acd030/apk/app-debug.apk
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | # built application files
2 | *.ap_
3 |
4 | # files for the dex VM
5 | *.dex
6 |
7 | # Java class files
8 | *.class
9 |
10 | # generated files
11 | bin/
12 | gen/
13 |
14 | # Local configuration file (sdk path, etc)
15 | local.properties
16 |
17 | # Proguard folder generated by Eclipse
18 | proguard/
19 |
20 | # Ignore gradle files
21 | .gradle/
22 | build/
23 |
24 | # Eclipse project files
25 | .classpath
26 | .project
27 | .settings/
28 |
29 | # Intellij project files
30 | *.iml
31 | *.ipr
32 | *.iws
33 | .idea/
34 |
35 | # Mac system files
36 | .DS_Store
37 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.2"
6 |
7 | defaultConfig {
8 | applicationId "com.wang.avi.sample"
9 | minSdkVersion 14
10 | targetSdkVersion 23
11 | versionCode 33
12 | versionName "2.1.3"
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(include: ['*.jar'], dir: 'libs')
24 | compile 'com.android.support:appcompat-v7:23.2.0'
25 | compile 'com.android.support:recyclerview-v7:23.2.0'
26 | compile project(':library')
27 | }
28 |
--------------------------------------------------------------------------------
/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 C:\Users\Jack\AppData\Local\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 | #}
18 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/wang/avi/sample/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.wang.avi.sample;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
10 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/app/src/main/java/com/wang/avi/sample/IndicatorActivity.java:
--------------------------------------------------------------------------------
1 | package com.wang.avi.sample;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.view.View;
7 |
8 | import com.wang.avi.AVLoadingIndicatorView;
9 |
10 | /**
11 | * Created by Jack Wang on 2016/8/5.
12 | */
13 |
14 | public class IndicatorActivity extends AppCompatActivity{
15 |
16 | private AVLoadingIndicatorView avi;
17 |
18 | @Override
19 | protected void onCreate(@Nullable Bundle savedInstanceState) {
20 | super.onCreate(savedInstanceState);
21 | setContentView(R.layout.activity_indicator);
22 |
23 | String indicator=getIntent().getStringExtra("indicator");
24 | avi= (AVLoadingIndicatorView) findViewById(R.id.avi);
25 | avi.setIndicator(indicator);
26 | }
27 |
28 | public void hideClick(View view) {
29 | avi.hide();
30 | // or avi.smoothToHide();
31 | }
32 |
33 | public void showClick(View view) {
34 | avi.show();
35 | // or avi.smoothToShow();
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/app/src/main/java/com/wang/avi/sample/MyCustomIndicator.java:
--------------------------------------------------------------------------------
1 | package com.wang.avi.sample;
2 |
3 | import android.graphics.Canvas;
4 | import android.graphics.Paint;
5 |
6 | import android.animation.ValueAnimator;
7 | import com.wang.avi.Indicator;
8 |
9 | import java.util.ArrayList;
10 |
11 | /**
12 | * Created by Jack Wang on 2016/8/5.
13 | */
14 |
15 | public class MyCustomIndicator extends Indicator{
16 |
17 |
18 | public static final float SCALE=1.0f;
19 |
20 | //scale x ,y
21 | private float[] scaleFloats=new float[]{SCALE,
22 | SCALE,
23 | SCALE,
24 | SCALE,
25 | SCALE};
26 |
27 |
28 |
29 | @Override
30 | public void draw(Canvas canvas, Paint paint) {
31 | float circleSpacing=4;
32 | float radius=(Math.min(getWidth(),getHeight())-circleSpacing*2)/12;
33 | float x = getWidth()/ 2-(radius*2+circleSpacing);
34 | float y=getHeight() / 2;
35 | for (int i = 0; i < 4; i++) {
36 | canvas.save();
37 | float translateX=x+(radius*2)*i+circleSpacing*i;
38 | canvas.translate(translateX, y);
39 | canvas.scale(scaleFloats[i], scaleFloats[i]);
40 | canvas.drawCircle(0, 0, radius, paint);
41 | canvas.restore();
42 | }
43 | }
44 |
45 | @Override
46 | public ArrayList onCreateAnimators() {
47 | ArrayList animators=new ArrayList<>();
48 | int[] delays=new int[]{120,240,360,480};
49 | for (int i = 0; i < 4; i++) {
50 | final int index=i;
51 |
52 | ValueAnimator scaleAnim=ValueAnimator.ofFloat(1,0.3f,1);
53 |
54 | scaleAnim.setDuration(750);
55 | scaleAnim.setRepeatCount(-1);
56 | scaleAnim.setStartDelay(delays[i]);
57 |
58 | addUpdateListener(scaleAnim,new ValueAnimator.AnimatorUpdateListener() {
59 | @Override
60 | public void onAnimationUpdate(ValueAnimator animation) {
61 | scaleFloats[index] = (float) animation.getAnimatedValue();
62 | postInvalidate();
63 |
64 | }
65 | });
66 | animators.add(scaleAnim);
67 | }
68 | return animators;
69 | }
70 |
71 |
72 | }
73 |
--------------------------------------------------------------------------------
/app/src/main/java/com/wang/avi/sample/SampleActivity.java:
--------------------------------------------------------------------------------
1 | package com.wang.avi.sample;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.annotation.Nullable;
6 | import android.support.v7.app.AppCompatActivity;
7 | import android.support.v7.widget.GridLayoutManager;
8 | import android.support.v7.widget.RecyclerView;
9 | import android.view.View;
10 | import android.view.ViewGroup;
11 |
12 | import com.wang.avi.AVLoadingIndicatorView;
13 |
14 | /**
15 | * Created by Jack Wang on 2016/8/5.
16 | */
17 |
18 | public class SampleActivity extends AppCompatActivity{
19 |
20 | private RecyclerView mRecycler;
21 |
22 | @Override
23 | protected void onCreate(@Nullable Bundle savedInstanceState) {
24 | super.onCreate(savedInstanceState);
25 | setContentView(R.layout.activity_sample);
26 |
27 | mRecycler= (RecyclerView) findViewById(R.id.recycler);
28 |
29 | GridLayoutManager layoutManager=new GridLayoutManager(this,4);
30 | mRecycler.setLayoutManager(layoutManager);
31 | mRecycler.setAdapter(new RecyclerView.Adapter() {
32 | @Override
33 | public IndicatorHolder onCreateViewHolder(ViewGroup parent, int viewType) {
34 | View itemView=getLayoutInflater().inflate(R.layout.item_indicator,parent,false);
35 | return new IndicatorHolder(itemView);
36 | }
37 |
38 | @Override
39 | public void onBindViewHolder(IndicatorHolder holder, final int position) {
40 | holder.indicatorView.setIndicator(INDICATORS[position]);
41 | holder.itemLayout.setOnClickListener(new View.OnClickListener() {
42 | @Override
43 | public void onClick(View v) {
44 | Intent intent=new Intent(SampleActivity.this,IndicatorActivity.class);
45 | intent.putExtra("indicator",INDICATORS[position]);
46 | startActivity(intent);
47 | }
48 | });
49 | }
50 |
51 | @Override
52 | public int getItemCount() {
53 | return INDICATORS.length;
54 | }
55 | });
56 | }
57 |
58 | final static class IndicatorHolder extends RecyclerView.ViewHolder{
59 |
60 | public AVLoadingIndicatorView indicatorView;
61 | public View itemLayout;
62 |
63 | public IndicatorHolder(View itemView) {
64 | super(itemView);
65 | itemLayout= itemView.findViewById(R.id.itemLayout);
66 | indicatorView= (AVLoadingIndicatorView) itemView.findViewById(R.id.indicator);
67 | }
68 | }
69 |
70 |
71 |
72 | private static final String[] INDICATORS=new String[]{
73 | "BallPulseIndicator",
74 | "BallGridPulseIndicator",
75 | "BallClipRotateIndicator",
76 | "BallClipRotatePulseIndicator",
77 | "SquareSpinIndicator",
78 | "BallClipRotateMultipleIndicator",
79 | "BallPulseRiseIndicator",
80 | "BallRotateIndicator",
81 | "CubeTransitionIndicator",
82 | "BallZigZagIndicator",
83 | "BallZigZagDeflectIndicator",
84 | "BallTrianglePathIndicator",
85 | "BallScaleIndicator",
86 | "LineScaleIndicator",
87 | "LineScalePartyIndicator",
88 | "BallScaleMultipleIndicator",
89 | "BallPulseSyncIndicator",
90 | "BallBeatIndicator",
91 | "LineScalePulseOutIndicator",
92 | "LineScalePulseOutRapidIndicator",
93 | "BallScaleRippleIndicator",
94 | "BallScaleRippleMultipleIndicator",
95 | "BallSpinFadeLoaderIndicator",
96 | "LineSpinFadeLoaderIndicator",
97 | "TriangleSkewSpinIndicator",
98 | "PacmanIndicator",
99 | "BallGridBeatIndicator",
100 | "SemiCircleSpinIndicator",
101 | "com.wang.avi.sample.MyCustomIndicator"
102 | };
103 |
104 | }
105 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_indicator.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
14 |
15 |
21 |
22 |
23 |
24 |
25 |
28 |
29 |
36 |
37 |
44 |
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_sample.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_indicator.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
18 |
19 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu_main.xml:
--------------------------------------------------------------------------------
1 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HarlonWang/AVLoadingIndicatorView/841f98d230b14f0617e541a8b421f8dd96acd030/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HarlonWang/AVLoadingIndicatorView/841f98d230b14f0617e541a8b421f8dd96acd030/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HarlonWang/AVLoadingIndicatorView/841f98d230b14f0617e541a8b421f8dd96acd030/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HarlonWang/AVLoadingIndicatorView/841f98d230b14f0617e541a8b421f8dd96acd030/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | AVLoadingIndicatorView
3 |
4 | Hello world!
5 | Settings
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/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:1.5.0'
9 |
10 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.3.1'
11 | classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
12 | // NOTE: Do not place your application dependencies here; they belong
13 | // in the individual module build.gradle files
14 | }
15 | }
16 |
17 | Properties properties = new Properties()
18 | properties.load(project.rootProject.file('local.properties').newDataInputStream())
19 |
20 | allprojects {
21 | repositories {
22 | maven {
23 | url properties.getProperty("sdk.dir")+"/extras/android/m2repository"
24 | }
25 | mavenLocal()
26 | jcenter()
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/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/HarlonWang/AVLoadingIndicatorView/841f98d230b14f0617e541a8b421f8dd96acd030/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Fri Oct 16 02:32:07 CST 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.8-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 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
46 | if $cygwin ; then
47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48 | fi
49 |
50 | # Attempt to set APP_HOME
51 | # Resolve links: $0 may be a link
52 | PRG="$0"
53 | # Need this for relative symlinks.
54 | while [ -h "$PRG" ] ; do
55 | ls=`ls -ld "$PRG"`
56 | link=`expr "$ls" : '.*-> \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/library/.gitignore:
--------------------------------------------------------------------------------
1 | # built application files
2 | *.ap_
3 |
4 | # files for the dex VM
5 | *.dex
6 |
7 | # Java class files
8 | *.class
9 |
10 | # generated files
11 | bin/
12 | gen/
13 |
14 | # Local configuration file (sdk path, etc)
15 | local.properties
16 |
17 | # Proguard folder generated by Eclipse
18 | proguard/
19 |
20 | # Ignore gradle files
21 | .gradle/
22 | build/
23 |
24 | # Eclipse project files
25 | .classpath
26 | .project
27 | .settings/
28 |
29 | # Intellij project files
30 | *.iml
31 | *.ipr
32 | *.iws
33 | .idea/
34 |
35 | # Mac system files
36 | .DS_Store
37 |
--------------------------------------------------------------------------------
/library/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.2"
6 |
7 | defaultConfig {
8 | minSdkVersion 14
9 | targetSdkVersion 23
10 | versionCode 33
11 | versionName "2.1.3"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | compile fileTree(dir: 'libs', include: ['*.jar'])
23 | }
24 |
25 | ext {
26 | PUBLISH_GROUP_ID = 'com.wang.avi'
27 | PUBLISH_VERSION = '2.1.3'
28 | PUBLISH_DES = 'Nice loading animations for Android'
29 | LIB_NAME = 'AVLoadingIndicatorView'
30 |
31 | WEBSITE_URL = 'https://github.com/81813780/AVLoadingIndicatorView'
32 | ISSUE_TRACKER_URL = 'https://github.com/81813780/AVLoadingIndicatorView/issues'
33 | VSC_URL = 'https://github.com/81813780/AVLoadingIndicatorView'
34 | }
35 |
36 | apply from: 'https://raw.githubusercontent.com/andforce/release-android-lib-to-jcenter/master/bintray.gradle'
--------------------------------------------------------------------------------
/library/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 C:\Users\Jack\AppData\Local\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 | #}
18 |
--------------------------------------------------------------------------------
/library/src/androidTest/java/com/wang/avi/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.wang.avi;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/library/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
--------------------------------------------------------------------------------
/library/src/main/java/com/wang/avi/AVLoadingIndicatorView.java:
--------------------------------------------------------------------------------
1 | package com.wang.avi;
2 |
3 | import android.annotation.TargetApi;
4 | import android.content.Context;
5 | import android.content.res.TypedArray;
6 | import android.graphics.Canvas;
7 | import android.graphics.Color;
8 | import android.graphics.Rect;
9 | import android.graphics.drawable.Animatable;
10 | import android.graphics.drawable.Drawable;
11 | import android.os.Build;
12 | import android.text.TextUtils;
13 | import android.util.AttributeSet;
14 | import android.util.Log;
15 | import android.view.View;
16 | import android.view.animation.AnimationUtils;
17 |
18 | import com.wang.avi.indicators.BallPulseIndicator;
19 |
20 | public class AVLoadingIndicatorView extends View {
21 |
22 | private static final String TAG="AVLoadingIndicatorView";
23 |
24 | private static final BallPulseIndicator DEFAULT_INDICATOR=new BallPulseIndicator();
25 |
26 | private static final int MIN_SHOW_TIME = 500; // ms
27 | private static final int MIN_DELAY = 500; // ms
28 |
29 | private long mStartTime = -1;
30 |
31 | private boolean mPostedHide = false;
32 |
33 | private boolean mPostedShow = false;
34 |
35 | private boolean mDismissed = false;
36 |
37 | private final Runnable mDelayedHide = new Runnable() {
38 |
39 | @Override
40 | public void run() {
41 | mPostedHide = false;
42 | mStartTime = -1;
43 | setVisibility(View.GONE);
44 | }
45 | };
46 |
47 | private final Runnable mDelayedShow = new Runnable() {
48 |
49 | @Override
50 | public void run() {
51 | mPostedShow = false;
52 | if (!mDismissed) {
53 | mStartTime = System.currentTimeMillis();
54 | setVisibility(View.VISIBLE);
55 | }
56 | }
57 | };
58 |
59 | int mMinWidth;
60 | int mMaxWidth;
61 | int mMinHeight;
62 | int mMaxHeight;
63 |
64 | private Indicator mIndicator;
65 | private int mIndicatorColor;
66 |
67 | private boolean mShouldStartAnimationDrawable;
68 |
69 | public AVLoadingIndicatorView(Context context) {
70 | super(context);
71 | init(context, null,0,0);
72 | }
73 |
74 | public AVLoadingIndicatorView(Context context, AttributeSet attrs) {
75 | super(context, attrs);
76 | init(context, attrs,0,R.style.AVLoadingIndicatorView);
77 | }
78 |
79 | public AVLoadingIndicatorView(Context context, AttributeSet attrs, int defStyleAttr) {
80 | super(context, attrs, defStyleAttr);
81 | init(context, attrs,defStyleAttr,R.style.AVLoadingIndicatorView);
82 | }
83 |
84 | @TargetApi(Build.VERSION_CODES.LOLLIPOP)
85 | public AVLoadingIndicatorView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
86 | super(context, attrs, defStyleAttr, defStyleRes);
87 | init(context,attrs,defStyleAttr,R.style.AVLoadingIndicatorView);
88 | }
89 |
90 | private void init(Context context,AttributeSet attrs,int defStyleAttr, int defStyleRes) {
91 | mMinWidth = 24;
92 | mMaxWidth = 48;
93 | mMinHeight = 24;
94 | mMaxHeight = 48;
95 |
96 | final TypedArray a = context.obtainStyledAttributes(
97 | attrs, R.styleable.AVLoadingIndicatorView, defStyleAttr, defStyleRes);
98 |
99 | mMinWidth = a.getDimensionPixelSize(R.styleable.AVLoadingIndicatorView_minWidth, mMinWidth);
100 | mMaxWidth = a.getDimensionPixelSize(R.styleable.AVLoadingIndicatorView_maxWidth, mMaxWidth);
101 | mMinHeight = a.getDimensionPixelSize(R.styleable.AVLoadingIndicatorView_minHeight, mMinHeight);
102 | mMaxHeight = a.getDimensionPixelSize(R.styleable.AVLoadingIndicatorView_maxHeight, mMaxHeight);
103 | String indicatorName=a.getString(R.styleable.AVLoadingIndicatorView_indicatorName);
104 | mIndicatorColor=a.getColor(R.styleable.AVLoadingIndicatorView_indicatorColor, Color.WHITE);
105 | setIndicator(indicatorName);
106 | if (mIndicator==null){
107 | setIndicator(DEFAULT_INDICATOR);
108 | }
109 | a.recycle();
110 | }
111 |
112 | public Indicator getIndicator() {
113 | return mIndicator;
114 | }
115 |
116 | public void setIndicator(Indicator d) {
117 | if (mIndicator != d) {
118 | if (mIndicator != null) {
119 | mIndicator.setCallback(null);
120 | unscheduleDrawable(mIndicator);
121 | }
122 |
123 | mIndicator = d;
124 | //need to set indicator color again if you didn't specified when you update the indicator .
125 | setIndicatorColor(mIndicatorColor);
126 | if (d != null) {
127 | d.setCallback(this);
128 | }
129 | postInvalidate();
130 | }
131 | }
132 |
133 |
134 | /**
135 | * setIndicatorColor(0xFF00FF00)
136 | * or
137 | * setIndicatorColor(Color.BLUE)
138 | * or
139 | * setIndicatorColor(Color.parseColor("#FF4081"))
140 | * or
141 | * setIndicatorColor(0xFF00FF00)
142 | * or
143 | * setIndicatorColor(getResources().getColor(android.R.color.black))
144 | * @param color
145 | */
146 | public void setIndicatorColor(int color){
147 | this.mIndicatorColor=color;
148 | mIndicator.setColor(color);
149 | }
150 |
151 |
152 | /**
153 | * You should pay attention to pass this parameter with two way:
154 | * for example:
155 | * 1. Only class Name,like "SimpleIndicator".(This way would use default package name with
156 | * "com.wang.avi.indicators")
157 | * 2. Class name with full package,like "com.my.android.indicators.SimpleIndicator".
158 | * @param indicatorName the class must be extend Indicator .
159 | */
160 | public void setIndicator(String indicatorName){
161 | if (TextUtils.isEmpty(indicatorName)){
162 | return;
163 | }
164 | StringBuilder drawableClassName=new StringBuilder();
165 | if (!indicatorName.contains(".")){
166 | String defaultPackageName=getClass().getPackage().getName();
167 | drawableClassName.append(defaultPackageName)
168 | .append(".indicators")
169 | .append(".");
170 | }
171 | drawableClassName.append(indicatorName);
172 | try {
173 | Class> drawableClass = Class.forName(drawableClassName.toString());
174 | Indicator indicator = (Indicator) drawableClass.newInstance();
175 | setIndicator(indicator);
176 | } catch (ClassNotFoundException e) {
177 | Log.e(TAG,"Didn't find your class , check the name again !");
178 | } catch (InstantiationException e) {
179 | e.printStackTrace();
180 | } catch (IllegalAccessException e) {
181 | e.printStackTrace();
182 | }
183 | }
184 |
185 | public void smoothToShow(){
186 | startAnimation(AnimationUtils.loadAnimation(getContext(),android.R.anim.fade_in));
187 | setVisibility(VISIBLE);
188 | }
189 |
190 | public void smoothToHide(){
191 | startAnimation(AnimationUtils.loadAnimation(getContext(),android.R.anim.fade_out));
192 | setVisibility(GONE);
193 | }
194 |
195 | public void hide() {
196 | mDismissed = true;
197 | removeCallbacks(mDelayedShow);
198 | long diff = System.currentTimeMillis() - mStartTime;
199 | if (diff >= MIN_SHOW_TIME || mStartTime == -1) {
200 | // The progress spinner has been shown long enough
201 | // OR was not shown yet. If it wasn't shown yet,
202 | // it will just never be shown.
203 | setVisibility(View.GONE);
204 | } else {
205 | // The progress spinner is shown, but not long enough,
206 | // so put a delayed message in to hide it when its been
207 | // shown long enough.
208 | if (!mPostedHide) {
209 | postDelayed(mDelayedHide, MIN_SHOW_TIME - diff);
210 | mPostedHide = true;
211 | }
212 | }
213 | }
214 |
215 | public void show() {
216 | // Reset the start time.
217 | mStartTime = -1;
218 | mDismissed = false;
219 | removeCallbacks(mDelayedHide);
220 | if (!mPostedShow) {
221 | postDelayed(mDelayedShow, MIN_DELAY);
222 | mPostedShow = true;
223 | }
224 | }
225 |
226 | @Override
227 | protected boolean verifyDrawable(Drawable who) {
228 | return who == mIndicator
229 | || super.verifyDrawable(who);
230 | }
231 |
232 | void startAnimation() {
233 | if (getVisibility() != VISIBLE) {
234 | return;
235 | }
236 |
237 | if (mIndicator instanceof Animatable) {
238 | mShouldStartAnimationDrawable = true;
239 | }
240 | postInvalidate();
241 | }
242 |
243 | void stopAnimation() {
244 | if (mIndicator instanceof Animatable) {
245 | mIndicator.stop();
246 | mShouldStartAnimationDrawable = false;
247 | }
248 | postInvalidate();
249 | }
250 |
251 | @Override
252 | public void setVisibility(int v) {
253 | if (getVisibility() != v) {
254 | super.setVisibility(v);
255 | if (v == GONE || v == INVISIBLE) {
256 | stopAnimation();
257 | } else {
258 | startAnimation();
259 | }
260 | }
261 | }
262 |
263 | @Override
264 | protected void onVisibilityChanged(View changedView, int visibility) {
265 | super.onVisibilityChanged(changedView, visibility);
266 | if (visibility == GONE || visibility == INVISIBLE) {
267 | stopAnimation();
268 | } else {
269 | startAnimation();
270 | }
271 | }
272 |
273 | @Override
274 | public void invalidateDrawable(Drawable dr) {
275 | if (verifyDrawable(dr)) {
276 | final Rect dirty = dr.getBounds();
277 | final int scrollX = getScrollX() + getPaddingLeft();
278 | final int scrollY = getScrollY() + getPaddingTop();
279 |
280 | invalidate(dirty.left + scrollX, dirty.top + scrollY,
281 | dirty.right + scrollX, dirty.bottom + scrollY);
282 | } else {
283 | super.invalidateDrawable(dr);
284 | }
285 | }
286 |
287 | @Override
288 | protected void onSizeChanged(int w, int h, int oldw, int oldh) {
289 | updateDrawableBounds(w, h);
290 | }
291 |
292 | private void updateDrawableBounds(int w, int h) {
293 | // onDraw will translate the canvas so we draw starting at 0,0.
294 | // Subtract out padding for the purposes of the calculations below.
295 | w -= getPaddingRight() + getPaddingLeft();
296 | h -= getPaddingTop() + getPaddingBottom();
297 |
298 | int right = w;
299 | int bottom = h;
300 | int top = 0;
301 | int left = 0;
302 |
303 | if (mIndicator != null) {
304 | // Maintain aspect ratio. Certain kinds of animated drawables
305 | // get very confused otherwise.
306 | final int intrinsicWidth = mIndicator.getIntrinsicWidth();
307 | final int intrinsicHeight = mIndicator.getIntrinsicHeight();
308 | final float intrinsicAspect = (float) intrinsicWidth / intrinsicHeight;
309 | final float boundAspect = (float) w / h;
310 | if (intrinsicAspect != boundAspect) {
311 | if (boundAspect > intrinsicAspect) {
312 | // New width is larger. Make it smaller to match height.
313 | final int width = (int) (h * intrinsicAspect);
314 | left = (w - width) / 2;
315 | right = left + width;
316 | } else {
317 | // New height is larger. Make it smaller to match width.
318 | final int height = (int) (w * (1 / intrinsicAspect));
319 | top = (h - height) / 2;
320 | bottom = top + height;
321 | }
322 | }
323 | mIndicator.setBounds(left, top, right, bottom);
324 | }
325 | }
326 |
327 | @Override
328 | protected synchronized void onDraw(Canvas canvas) {
329 | super.onDraw(canvas);
330 | drawTrack(canvas);
331 | }
332 |
333 | void drawTrack(Canvas canvas) {
334 | final Drawable d = mIndicator;
335 | if (d != null) {
336 | // Translate canvas so a indeterminate circular progress bar with padding
337 | // rotates properly in its animation
338 | final int saveCount = canvas.save();
339 |
340 | canvas.translate(getPaddingLeft(), getPaddingTop());
341 |
342 | d.draw(canvas);
343 | canvas.restoreToCount(saveCount);
344 |
345 | if (mShouldStartAnimationDrawable && d instanceof Animatable) {
346 | ((Animatable) d).start();
347 | mShouldStartAnimationDrawable = false;
348 | }
349 | }
350 | }
351 |
352 | @Override
353 | protected synchronized void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
354 | int dw = 0;
355 | int dh = 0;
356 |
357 | final Drawable d = mIndicator;
358 | if (d != null) {
359 | dw = Math.max(mMinWidth, Math.min(mMaxWidth, d.getIntrinsicWidth()));
360 | dh = Math.max(mMinHeight, Math.min(mMaxHeight, d.getIntrinsicHeight()));
361 | }
362 |
363 | updateDrawableState();
364 |
365 | dw += getPaddingLeft() + getPaddingRight();
366 | dh += getPaddingTop() + getPaddingBottom();
367 |
368 | final int measuredWidth = resolveSizeAndState(dw, widthMeasureSpec, 0);
369 | final int measuredHeight = resolveSizeAndState(dh, heightMeasureSpec, 0);
370 | setMeasuredDimension(measuredWidth, measuredHeight);
371 | }
372 |
373 | @Override
374 | protected void drawableStateChanged() {
375 | super.drawableStateChanged();
376 | updateDrawableState();
377 | }
378 |
379 | private void updateDrawableState() {
380 | final int[] state = getDrawableState();
381 | if (mIndicator != null && mIndicator.isStateful()) {
382 | mIndicator.setState(state);
383 | }
384 | }
385 |
386 | @TargetApi(Build.VERSION_CODES.LOLLIPOP)
387 | @Override
388 | public void drawableHotspotChanged(float x, float y) {
389 | super.drawableHotspotChanged(x, y);
390 |
391 | if (mIndicator != null) {
392 | mIndicator.setHotspot(x, y);
393 | }
394 | }
395 |
396 | @Override
397 | protected void onAttachedToWindow() {
398 | super.onAttachedToWindow();
399 | startAnimation();
400 | removeCallbacks();
401 | }
402 |
403 | @Override
404 | protected void onDetachedFromWindow() {
405 | stopAnimation();
406 | // This should come after stopAnimation(), otherwise an invalidate message remains in the
407 | // queue, which can prevent the entire view hierarchy from being GC'ed during a rotation
408 | super.onDetachedFromWindow();
409 | removeCallbacks();
410 | }
411 |
412 | private void removeCallbacks() {
413 | removeCallbacks(mDelayedHide);
414 | removeCallbacks(mDelayedShow);
415 | }
416 |
417 |
418 | }
419 |
--------------------------------------------------------------------------------
/library/src/main/java/com/wang/avi/Indicator.java:
--------------------------------------------------------------------------------
1 | package com.wang.avi;
2 |
3 | import android.animation.ValueAnimator;
4 | import android.graphics.Canvas;
5 | import android.graphics.Color;
6 | import android.graphics.ColorFilter;
7 | import android.graphics.Paint;
8 | import android.graphics.PixelFormat;
9 | import android.graphics.Rect;
10 | import android.graphics.drawable.Animatable;
11 | import android.graphics.drawable.Drawable;
12 |
13 | import java.util.ArrayList;
14 | import java.util.HashMap;
15 |
16 | /**
17 | * Created by Jack Wang on 2016/8/5.
18 | */
19 |
20 | public abstract class Indicator extends Drawable implements Animatable {
21 |
22 | private HashMap mUpdateListeners=new HashMap<>();
23 |
24 | private ArrayList mAnimators;
25 | private int alpha = 255;
26 | private static final Rect ZERO_BOUNDS_RECT = new Rect();
27 | protected Rect drawBounds = ZERO_BOUNDS_RECT;
28 |
29 | private boolean mHasAnimators;
30 |
31 | private Paint mPaint=new Paint();
32 |
33 | public Indicator(){
34 | mPaint.setColor(Color.WHITE);
35 | mPaint.setStyle(Paint.Style.FILL);
36 | mPaint.setAntiAlias(true);
37 | }
38 |
39 | public int getColor() {
40 | return mPaint.getColor();
41 | }
42 |
43 | public void setColor(int color) {
44 | mPaint.setColor(color);
45 | }
46 |
47 | @Override
48 | public void setAlpha(int alpha) {
49 | this.alpha = alpha;
50 | }
51 |
52 | @Override
53 | public int getAlpha() {
54 | return alpha;
55 | }
56 |
57 | @Override
58 | public int getOpacity() {
59 | return PixelFormat.OPAQUE;
60 | }
61 |
62 | @Override
63 | public void setColorFilter(ColorFilter colorFilter) {
64 |
65 | }
66 |
67 | @Override
68 | public void draw(Canvas canvas) {
69 | draw(canvas,mPaint);
70 | }
71 |
72 | public abstract void draw(Canvas canvas, Paint paint);
73 |
74 | public abstract ArrayList onCreateAnimators();
75 |
76 | @Override
77 | public void start() {
78 | ensureAnimators();
79 |
80 | if (mAnimators == null) {
81 | return;
82 | }
83 |
84 | // If the animators has not ended, do nothing.
85 | if (isStarted()) {
86 | return;
87 | }
88 | startAnimators();
89 | invalidateSelf();
90 | }
91 |
92 | private void startAnimators() {
93 | for (int i = 0; i < mAnimators.size(); i++) {
94 | ValueAnimator animator = mAnimators.get(i);
95 |
96 | //when the animator restart , add the updateListener again because they
97 | // was removed by animator stop .
98 | ValueAnimator.AnimatorUpdateListener updateListener=mUpdateListeners.get(animator);
99 | if (updateListener!=null){
100 | animator.addUpdateListener(updateListener);
101 | }
102 |
103 | animator.start();
104 | }
105 | }
106 |
107 | private void stopAnimators() {
108 | if (mAnimators!=null){
109 | for (ValueAnimator animator : mAnimators) {
110 | if (animator != null && animator.isStarted()) {
111 | animator.removeAllUpdateListeners();
112 | animator.end();
113 | }
114 | }
115 | }
116 | }
117 |
118 | private void ensureAnimators() {
119 | if (!mHasAnimators) {
120 | mAnimators = onCreateAnimators();
121 | mHasAnimators = true;
122 | }
123 | }
124 |
125 | @Override
126 | public void stop() {
127 | stopAnimators();
128 | }
129 |
130 | private boolean isStarted() {
131 | for (ValueAnimator animator : mAnimators) {
132 | return animator.isStarted();
133 | }
134 | return false;
135 | }
136 |
137 | @Override
138 | public boolean isRunning() {
139 | for (ValueAnimator animator : mAnimators) {
140 | return animator.isRunning();
141 | }
142 | return false;
143 | }
144 |
145 | /**
146 | * Your should use this to add AnimatorUpdateListener when
147 | * create animator , otherwise , animator doesn't work when
148 | * the animation restart .
149 | * @param updateListener
150 | */
151 | public void addUpdateListener(ValueAnimator animator, ValueAnimator.AnimatorUpdateListener updateListener){
152 | mUpdateListeners.put(animator,updateListener);
153 | }
154 |
155 | @Override
156 | protected void onBoundsChange(Rect bounds) {
157 | super.onBoundsChange(bounds);
158 | setDrawBounds(bounds);
159 | }
160 |
161 | public void setDrawBounds(Rect drawBounds) {
162 | setDrawBounds(drawBounds.left, drawBounds.top, drawBounds.right, drawBounds.bottom);
163 | }
164 |
165 | public void setDrawBounds(int left, int top, int right, int bottom) {
166 | this.drawBounds = new Rect(left, top, right, bottom);
167 | }
168 |
169 | public void postInvalidate(){
170 | invalidateSelf();
171 | }
172 |
173 | public Rect getDrawBounds() {
174 | return drawBounds;
175 | }
176 |
177 | public int getWidth(){
178 | return drawBounds.width();
179 | }
180 |
181 | public int getHeight(){
182 | return drawBounds.height();
183 | }
184 |
185 | public int centerX(){
186 | return drawBounds.centerX();
187 | }
188 |
189 | public int centerY(){
190 | return drawBounds.centerY();
191 | }
192 |
193 | public float exactCenterX(){
194 | return drawBounds.exactCenterX();
195 | }
196 |
197 | public float exactCenterY(){
198 | return drawBounds.exactCenterY();
199 | }
200 |
201 | }
202 |
--------------------------------------------------------------------------------
/library/src/main/java/com/wang/avi/indicators/BallBeatIndicator.java:
--------------------------------------------------------------------------------
1 | package com.wang.avi.indicators;
2 |
3 | import android.graphics.Canvas;
4 | import android.graphics.Paint;
5 |
6 | import android.animation.ValueAnimator;
7 | import com.wang.avi.Indicator;
8 |
9 | import java.util.ArrayList;
10 |
11 | /**
12 | * Created by Jack on 2015/10/19.
13 | */
14 | public class BallBeatIndicator extends Indicator {
15 |
16 | public static final float SCALE=1.0f;
17 |
18 | public static final int ALPHA=255;
19 |
20 | private float[] scaleFloats=new float[]{SCALE,
21 | SCALE,
22 | SCALE};
23 |
24 | int[] alphas=new int[]{ALPHA,
25 | ALPHA,
26 | ALPHA,};
27 |
28 | @Override
29 | public void draw(Canvas canvas, Paint paint) {
30 | float circleSpacing=4;
31 | float radius=(getWidth()-circleSpacing*2)/6;
32 | float x = getWidth()/ 2-(radius*2+circleSpacing);
33 | float y=getHeight() / 2;
34 | for (int i = 0; i < 3; i++) {
35 | canvas.save();
36 | float translateX=x+(radius*2)*i+circleSpacing*i;
37 | canvas.translate(translateX, y);
38 | canvas.scale(scaleFloats[i], scaleFloats[i]);
39 | paint.setAlpha(alphas[i]);
40 | canvas.drawCircle(0, 0, radius, paint);
41 | canvas.restore();
42 | }
43 | }
44 |
45 | @Override
46 | public ArrayList onCreateAnimators() {
47 | ArrayList animators=new ArrayList<>();
48 | int[] delays=new int[]{350,0,350};
49 | for (int i = 0; i < 3; i++) {
50 | final int index=i;
51 | ValueAnimator scaleAnim=ValueAnimator.ofFloat(1,0.75f,1);
52 | scaleAnim.setDuration(700);
53 | scaleAnim.setRepeatCount(-1);
54 | scaleAnim.setStartDelay(delays[i]);
55 | addUpdateListener(scaleAnim,new ValueAnimator.AnimatorUpdateListener() {
56 | @Override
57 | public void onAnimationUpdate(ValueAnimator animation) {
58 | scaleFloats[index] = (float) animation.getAnimatedValue();
59 | postInvalidate();
60 | }
61 | });
62 |
63 | ValueAnimator alphaAnim=ValueAnimator.ofInt(255,51,255);
64 | alphaAnim.setDuration(700);
65 | alphaAnim.setRepeatCount(-1);
66 | alphaAnim.setStartDelay(delays[i]);
67 | addUpdateListener(alphaAnim,new ValueAnimator.AnimatorUpdateListener() {
68 | @Override
69 | public void onAnimationUpdate(ValueAnimator animation) {
70 | alphas[index] = (int) animation.getAnimatedValue();
71 | postInvalidate();
72 | }
73 | });
74 | animators.add(scaleAnim);
75 | animators.add(alphaAnim);
76 | }
77 | return animators;
78 | }
79 |
80 |
81 | }
82 |
--------------------------------------------------------------------------------
/library/src/main/java/com/wang/avi/indicators/BallClipRotateIndicator.java:
--------------------------------------------------------------------------------
1 | package com.wang.avi.indicators;
2 |
3 | import android.graphics.Canvas;
4 | import android.graphics.Paint;
5 | import android.graphics.RectF;
6 |
7 | import android.animation.ValueAnimator;
8 | import com.wang.avi.Indicator;
9 |
10 | import java.util.ArrayList;
11 |
12 | /**
13 | * Created by Jack on 2015/10/16.
14 | */
15 | public class BallClipRotateIndicator extends Indicator {
16 |
17 | float scaleFloat=1,degrees;
18 |
19 | @Override
20 | public void draw(Canvas canvas, Paint paint) {
21 | paint.setStyle(Paint.Style.STROKE);
22 | paint.setStrokeWidth(3);
23 |
24 | float circleSpacing=12;
25 | float x = (getWidth()) / 2;
26 | float y=(getHeight()) / 2;
27 | canvas.translate(x, y);
28 | canvas.scale(scaleFloat, scaleFloat);
29 | canvas.rotate(degrees);
30 | RectF rectF=new RectF(-x+circleSpacing,-y+circleSpacing,0+x-circleSpacing,0+y-circleSpacing);
31 | canvas.drawArc(rectF, -45, 270, false, paint);
32 | }
33 |
34 | @Override
35 | public ArrayList onCreateAnimators() {
36 | ArrayList animators=new ArrayList<>();
37 | ValueAnimator scaleAnim=ValueAnimator.ofFloat(1,0.6f,0.5f,1);
38 | scaleAnim.setDuration(750);
39 | scaleAnim.setRepeatCount(-1);
40 | addUpdateListener(scaleAnim,new ValueAnimator.AnimatorUpdateListener() {
41 | @Override
42 | public void onAnimationUpdate(ValueAnimator animation) {
43 | scaleFloat = (float) animation.getAnimatedValue();
44 | postInvalidate();
45 | }
46 | });
47 | ValueAnimator rotateAnim=ValueAnimator.ofFloat(0,180,360);
48 | rotateAnim.setDuration(750);
49 | rotateAnim.setRepeatCount(-1);
50 | addUpdateListener(rotateAnim,new ValueAnimator.AnimatorUpdateListener() {
51 | @Override
52 | public void onAnimationUpdate(ValueAnimator animation) {
53 | degrees = (float) animation.getAnimatedValue();
54 | postInvalidate();
55 | }
56 | });
57 | animators.add(scaleAnim);
58 | animators.add(rotateAnim);
59 | return animators;
60 | }
61 |
62 | }
63 |
--------------------------------------------------------------------------------
/library/src/main/java/com/wang/avi/indicators/BallClipRotateMultipleIndicator.java:
--------------------------------------------------------------------------------
1 | package com.wang.avi.indicators;
2 |
3 | import android.graphics.Canvas;
4 | import android.graphics.Paint;
5 | import android.graphics.RectF;
6 |
7 | import android.animation.ValueAnimator;
8 | import com.wang.avi.Indicator;
9 |
10 | import java.util.ArrayList;
11 |
12 | /**
13 | * Created by Jack on 2015/10/17.
14 | */
15 | public class BallClipRotateMultipleIndicator extends Indicator {
16 |
17 | float scaleFloat=1,degrees;
18 |
19 |
20 | @Override
21 | public void draw(Canvas canvas, Paint paint) {
22 | paint.setStrokeWidth(3);
23 | paint.setStyle(Paint.Style.STROKE);
24 |
25 | float circleSpacing=12;
26 | float x=getWidth()/2;
27 | float y=getHeight()/2;
28 |
29 | canvas.save();
30 |
31 | canvas.translate(x, y);
32 | canvas.scale(scaleFloat, scaleFloat);
33 | canvas.rotate(degrees);
34 |
35 | //draw two big arc
36 | float[] bStartAngles=new float[]{135,-45};
37 | for (int i = 0; i < 2; i++) {
38 | RectF rectF=new RectF(-x+circleSpacing,-y+circleSpacing,x-circleSpacing,y-circleSpacing);
39 | canvas.drawArc(rectF, bStartAngles[i], 90, false, paint);
40 | }
41 |
42 | canvas.restore();
43 | canvas.translate(x, y);
44 | canvas.scale(scaleFloat, scaleFloat);
45 | canvas.rotate(-degrees);
46 | //draw two small arc
47 | float[] sStartAngles=new float[]{225,45};
48 | for (int i = 0; i < 2; i++) {
49 | RectF rectF=new RectF(-x/1.8f+circleSpacing,-y/1.8f+circleSpacing,x/1.8f-circleSpacing,y/1.8f-circleSpacing);
50 | canvas.drawArc(rectF, sStartAngles[i], 90, false, paint);
51 | }
52 | }
53 |
54 | @Override
55 | public ArrayList onCreateAnimators() {
56 | ArrayList animators=new ArrayList<>();
57 | ValueAnimator scaleAnim=ValueAnimator.ofFloat(1,0.6f,1);
58 | scaleAnim.setDuration(1000);
59 | scaleAnim.setRepeatCount(-1);
60 | addUpdateListener(scaleAnim,new ValueAnimator.AnimatorUpdateListener() {
61 | @Override
62 | public void onAnimationUpdate(ValueAnimator animation) {
63 | scaleFloat = (float) animation.getAnimatedValue();
64 | postInvalidate();
65 | }
66 | });
67 |
68 | ValueAnimator rotateAnim=ValueAnimator.ofFloat(0, 180,360);
69 | rotateAnim.setDuration(1000);
70 | rotateAnim.setRepeatCount(-1);
71 | addUpdateListener(rotateAnim,new ValueAnimator.AnimatorUpdateListener() {
72 | @Override
73 | public void onAnimationUpdate(ValueAnimator animation) {
74 | degrees = (float) animation.getAnimatedValue();
75 | postInvalidate();
76 | }
77 | });
78 | animators.add(scaleAnim);
79 | animators.add(rotateAnim);
80 | return animators;
81 | }
82 |
83 | }
84 |
--------------------------------------------------------------------------------
/library/src/main/java/com/wang/avi/indicators/BallClipRotatePulseIndicator.java:
--------------------------------------------------------------------------------
1 | package com.wang.avi.indicators;
2 |
3 | import android.graphics.Canvas;
4 | import android.graphics.Paint;
5 | import android.graphics.RectF;
6 |
7 | import android.animation.ValueAnimator;
8 | import com.wang.avi.Indicator;
9 |
10 | import java.util.ArrayList;
11 |
12 | /**
13 | * Created by Jack on 2015/10/16.
14 | */
15 | public class BallClipRotatePulseIndicator extends Indicator {
16 |
17 | float scaleFloat1,scaleFloat2,degrees;
18 |
19 |
20 | @Override
21 | public void draw(Canvas canvas, Paint paint) {
22 | float circleSpacing=12;
23 | float x=getWidth()/2;
24 | float y=getHeight()/2;
25 |
26 | //draw fill circle
27 | canvas.save();
28 | canvas.translate(x, y);
29 | canvas.scale(scaleFloat1, scaleFloat1);
30 | paint.setStyle(Paint.Style.FILL);
31 | canvas.drawCircle(0, 0, x / 2.5f, paint);
32 |
33 | canvas.restore();
34 |
35 | canvas.translate(x, y);
36 | canvas.scale(scaleFloat2, scaleFloat2);
37 | canvas.rotate(degrees);
38 |
39 | paint.setStrokeWidth(3);
40 | paint.setStyle(Paint.Style.STROKE);
41 |
42 | //draw two arc
43 | float[] startAngles=new float[]{225,45};
44 | for (int i = 0; i < 2; i++) {
45 | RectF rectF=new RectF(-x+circleSpacing,-y+circleSpacing,x-circleSpacing,y-circleSpacing);
46 | canvas.drawArc(rectF, startAngles[i], 90, false, paint);
47 | }
48 | }
49 |
50 | @Override
51 | public ArrayList onCreateAnimators() {
52 | ValueAnimator scaleAnim=ValueAnimator.ofFloat(1,0.3f,1);
53 | scaleAnim.setDuration(1000);
54 | scaleAnim.setRepeatCount(-1);
55 | addUpdateListener(scaleAnim,new ValueAnimator.AnimatorUpdateListener() {
56 | @Override
57 | public void onAnimationUpdate(ValueAnimator animation) {
58 | scaleFloat1 = (float) animation.getAnimatedValue();
59 | postInvalidate();
60 | }
61 | });
62 |
63 | ValueAnimator scaleAnim2=ValueAnimator.ofFloat(1,0.6f,1);
64 | scaleAnim2.setDuration(1000);
65 | scaleAnim2.setRepeatCount(-1);
66 | addUpdateListener(scaleAnim2,new ValueAnimator.AnimatorUpdateListener() {
67 | @Override
68 | public void onAnimationUpdate(ValueAnimator animation) {
69 | scaleFloat2 = (float) animation.getAnimatedValue();
70 | postInvalidate();
71 | }
72 | });
73 |
74 | ValueAnimator rotateAnim=ValueAnimator.ofFloat(0, 180,360);
75 | rotateAnim.setDuration(1000);
76 | rotateAnim.setRepeatCount(-1);
77 | addUpdateListener(rotateAnim,new ValueAnimator.AnimatorUpdateListener() {
78 | @Override
79 | public void onAnimationUpdate(ValueAnimator animation) {
80 | degrees = (float) animation.getAnimatedValue();
81 | postInvalidate();
82 | }
83 | });
84 | ArrayList animators=new ArrayList<>();
85 | animators.add(scaleAnim);
86 | animators.add(scaleAnim2);
87 | animators.add(rotateAnim);
88 | return animators;
89 | }
90 |
91 |
92 | }
93 |
--------------------------------------------------------------------------------
/library/src/main/java/com/wang/avi/indicators/BallGridBeatIndicator.java:
--------------------------------------------------------------------------------
1 | package com.wang.avi.indicators;
2 |
3 | import android.graphics.Canvas;
4 | import android.graphics.Paint;
5 |
6 | import android.animation.ValueAnimator;
7 | import com.wang.avi.Indicator;
8 |
9 | import java.util.ArrayList;
10 |
11 | /**
12 | * Created by Jack on 2015/10/20.
13 | */
14 | public class BallGridBeatIndicator extends Indicator {
15 |
16 | public static final int ALPHA=255;
17 |
18 | int[] alphas=new int[]{ALPHA,
19 | ALPHA,
20 | ALPHA,
21 | ALPHA,
22 | ALPHA,
23 | ALPHA,
24 | ALPHA,
25 | ALPHA,
26 | ALPHA};
27 |
28 | @Override
29 | public void draw(Canvas canvas, Paint paint) {
30 | float circleSpacing=4;
31 | float radius=(getWidth()-circleSpacing*4)/6;
32 | float x = getWidth()/ 2-(radius*2+circleSpacing);
33 | float y = getWidth()/ 2-(radius*2+circleSpacing);
34 |
35 | for (int i = 0; i < 3; i++) {
36 | for (int j = 0; j < 3; j++) {
37 | canvas.save();
38 | float translateX=x+(radius*2)*j+circleSpacing*j;
39 | float translateY=y+(radius*2)*i+circleSpacing*i;
40 | canvas.translate(translateX, translateY);
41 | paint.setAlpha(alphas[3 * i + j]);
42 | canvas.drawCircle(0, 0, radius, paint);
43 | canvas.restore();
44 | }
45 | }
46 | }
47 |
48 | @Override
49 | public ArrayList onCreateAnimators() {
50 | ArrayList animators=new ArrayList<>();
51 |
52 | int[] durations={960, 930, 1190, 1130, 1340, 940, 1200, 820, 1190};
53 | int[] delays= {360, 400, 680, 410, 710, -150, -120, 10, 320};
54 |
55 | for (int i = 0; i < 9; i++) {
56 | final int index=i;
57 | ValueAnimator alphaAnim=ValueAnimator.ofInt(255, 168,255);
58 | alphaAnim.setDuration(durations[i]);
59 | alphaAnim.setRepeatCount(-1);
60 | alphaAnim.setStartDelay(delays[i]);
61 | addUpdateListener(alphaAnim,new ValueAnimator.AnimatorUpdateListener() {
62 | @Override
63 | public void onAnimationUpdate(ValueAnimator animation) {
64 | alphas[index] = (int) animation.getAnimatedValue();
65 | postInvalidate();
66 | }
67 | });
68 | animators.add(alphaAnim);
69 | }
70 | return animators;
71 | }
72 |
73 |
74 |
75 |
76 | }
77 |
--------------------------------------------------------------------------------
/library/src/main/java/com/wang/avi/indicators/BallGridPulseIndicator.java:
--------------------------------------------------------------------------------
1 | package com.wang.avi.indicators;
2 |
3 | import android.graphics.Canvas;
4 | import android.graphics.Paint;
5 |
6 | import android.animation.ValueAnimator;
7 | import com.wang.avi.Indicator;
8 |
9 | import java.util.ArrayList;
10 |
11 | /**
12 | * Created by Jack on 2015/10/16.
13 | */
14 | public class BallGridPulseIndicator extends Indicator {
15 |
16 | public static final int ALPHA=255;
17 |
18 | public static final float SCALE=1.0f;
19 |
20 | int[] alphas=new int[]{ALPHA,
21 | ALPHA,
22 | ALPHA,
23 | ALPHA,
24 | ALPHA,
25 | ALPHA,
26 | ALPHA,
27 | ALPHA,
28 | ALPHA};
29 |
30 | float[] scaleFloats=new float[]{SCALE,
31 | SCALE,
32 | SCALE,
33 | SCALE,
34 | SCALE,
35 | SCALE,
36 | SCALE,
37 | SCALE,
38 | SCALE};
39 |
40 |
41 |
42 | @Override
43 | public void draw(Canvas canvas, Paint paint) {
44 | float circleSpacing=4;
45 | float radius=(getWidth()-circleSpacing*4)/6;
46 | float x = getWidth()/ 2-(radius*2+circleSpacing);
47 | float y = getWidth()/ 2-(radius*2+circleSpacing);
48 |
49 | for (int i = 0; i < 3; i++) {
50 | for (int j = 0; j < 3; j++) {
51 | canvas.save();
52 | float translateX=x+(radius*2)*j+circleSpacing*j;
53 | float translateY=y+(radius*2)*i+circleSpacing*i;
54 | canvas.translate(translateX, translateY);
55 | canvas.scale(scaleFloats[3 * i + j], scaleFloats[3 * i + j]);
56 | paint.setAlpha(alphas[3 * i + j]);
57 | canvas.drawCircle(0, 0, radius, paint);
58 | canvas.restore();
59 | }
60 | }
61 | }
62 |
63 | @Override
64 | public ArrayList onCreateAnimators() {
65 | ArrayList animators=new ArrayList<>();
66 | int[] durations={720, 1020, 1280, 1420, 1450, 1180, 870, 1450, 1060};
67 | int[] delays= {-60, 250, -170, 480, 310, 30, 460, 780, 450};
68 |
69 | for (int i = 0; i < 9; i++) {
70 | final int index=i;
71 | ValueAnimator scaleAnim=ValueAnimator.ofFloat(1,0.5f,1);
72 | scaleAnim.setDuration(durations[i]);
73 | scaleAnim.setRepeatCount(-1);
74 | scaleAnim.setStartDelay(delays[i]);
75 | addUpdateListener(scaleAnim,new ValueAnimator.AnimatorUpdateListener() {
76 | @Override
77 | public void onAnimationUpdate(ValueAnimator animation) {
78 | scaleFloats[index] = (float) animation.getAnimatedValue();
79 | postInvalidate();
80 | }
81 | });
82 |
83 | ValueAnimator alphaAnim=ValueAnimator.ofInt(255, 210, 122, 255);
84 | alphaAnim.setDuration(durations[i]);
85 | alphaAnim.setRepeatCount(-1);
86 | alphaAnim.setStartDelay(delays[i]);
87 | addUpdateListener(alphaAnim,new ValueAnimator.AnimatorUpdateListener() {
88 | @Override
89 | public void onAnimationUpdate(ValueAnimator animation) {
90 | alphas[index] = (int) animation.getAnimatedValue();
91 | postInvalidate();
92 | }
93 | });
94 | animators.add(scaleAnim);
95 | animators.add(alphaAnim);
96 | }
97 | return animators;
98 | }
99 |
100 | }
101 |
--------------------------------------------------------------------------------
/library/src/main/java/com/wang/avi/indicators/BallPulseIndicator.java:
--------------------------------------------------------------------------------
1 | package com.wang.avi.indicators;
2 |
3 | import android.graphics.Canvas;
4 | import android.graphics.Paint;
5 |
6 | import android.animation.ValueAnimator;
7 | import com.wang.avi.Indicator;
8 |
9 | import java.util.ArrayList;
10 |
11 | /**
12 | * Created by Jack on 2015/10/16.
13 | */
14 | public class BallPulseIndicator extends Indicator {
15 |
16 | public static final float SCALE=1.0f;
17 |
18 | //scale x ,y
19 | private float[] scaleFloats=new float[]{SCALE,
20 | SCALE,
21 | SCALE};
22 |
23 |
24 |
25 | @Override
26 | public void draw(Canvas canvas, Paint paint) {
27 | float circleSpacing=4;
28 | float radius=(Math.min(getWidth(),getHeight())-circleSpacing*2)/6;
29 | float x = getWidth()/ 2-(radius*2+circleSpacing);
30 | float y=getHeight() / 2;
31 | for (int i = 0; i < 3; i++) {
32 | canvas.save();
33 | float translateX=x+(radius*2)*i+circleSpacing*i;
34 | canvas.translate(translateX, y);
35 | canvas.scale(scaleFloats[i], scaleFloats[i]);
36 | canvas.drawCircle(0, 0, radius, paint);
37 | canvas.restore();
38 | }
39 | }
40 |
41 | @Override
42 | public ArrayList onCreateAnimators() {
43 | ArrayList animators=new ArrayList<>();
44 | int[] delays=new int[]{120,240,360};
45 | for (int i = 0; i < 3; i++) {
46 | final int index=i;
47 |
48 | ValueAnimator scaleAnim=ValueAnimator.ofFloat(1,0.3f,1);
49 |
50 | scaleAnim.setDuration(750);
51 | scaleAnim.setRepeatCount(-1);
52 | scaleAnim.setStartDelay(delays[i]);
53 |
54 | addUpdateListener(scaleAnim,new ValueAnimator.AnimatorUpdateListener() {
55 | @Override
56 | public void onAnimationUpdate(ValueAnimator animation) {
57 | scaleFloats[index] = (float) animation.getAnimatedValue();
58 | postInvalidate();
59 | }
60 | });
61 | animators.add(scaleAnim);
62 | }
63 | return animators;
64 | }
65 |
66 |
67 | }
68 |
--------------------------------------------------------------------------------
/library/src/main/java/com/wang/avi/indicators/BallPulseRiseIndicator.java:
--------------------------------------------------------------------------------
1 | package com.wang.avi.indicators;
2 |
3 | import android.animation.ValueAnimator;
4 | import android.graphics.Camera;
5 | import android.graphics.Canvas;
6 | import android.graphics.Matrix;
7 | import android.graphics.Paint;
8 | import android.view.animation.LinearInterpolator;
9 |
10 | import com.wang.avi.Indicator;
11 |
12 | import java.util.ArrayList;
13 |
14 | /**
15 | * Created by Jack on 2015/10/17.
16 | */
17 | public class BallPulseRiseIndicator extends Indicator {
18 |
19 | private Camera mCamera;
20 | private Matrix mMatrix;
21 |
22 | private float degress;
23 |
24 | public BallPulseRiseIndicator(){
25 | mCamera=new Camera();
26 | mMatrix=new Matrix();
27 | }
28 |
29 | @Override
30 | public void draw(Canvas canvas, Paint paint) {
31 |
32 | mMatrix.reset();
33 | mCamera.save();
34 | mCamera.rotateX(degress);
35 | mCamera.getMatrix(mMatrix);
36 | mCamera.restore();
37 |
38 | mMatrix.preTranslate(-centerX(), -centerY());
39 | mMatrix.postTranslate(centerX(), centerY());
40 | canvas.concat(mMatrix);
41 |
42 | float radius=getWidth()/10;
43 | canvas.drawCircle(getWidth()/4,radius*2,radius,paint);
44 | canvas.drawCircle(getWidth()*3/4,radius*2,radius,paint);
45 |
46 | canvas.drawCircle(radius,getHeight()-2*radius,radius,paint);
47 | canvas.drawCircle(getWidth()/2,getHeight()-2*radius,radius,paint);
48 | canvas.drawCircle(getWidth()-radius,getHeight()-2*radius,radius,paint);
49 | }
50 |
51 | @Override
52 | public ArrayList onCreateAnimators() {
53 | ArrayList animators=new ArrayList<>();
54 | ValueAnimator animator=ValueAnimator.ofFloat(0,360);
55 | addUpdateListener(animator,new ValueAnimator.AnimatorUpdateListener() {
56 | @Override
57 | public void onAnimationUpdate(ValueAnimator animation) {
58 | degress = (float) animation.getAnimatedValue();
59 | postInvalidate();
60 | }
61 | });
62 | animator.setInterpolator(new LinearInterpolator());
63 | animator.setRepeatCount(-1);
64 | animator.setDuration(1500);
65 | animators.add(animator);
66 | return animators;
67 | }
68 |
69 | }
70 |
--------------------------------------------------------------------------------
/library/src/main/java/com/wang/avi/indicators/BallPulseSyncIndicator.java:
--------------------------------------------------------------------------------
1 | package com.wang.avi.indicators;
2 |
3 | import android.graphics.Canvas;
4 | import android.graphics.Paint;
5 |
6 | import android.animation.ValueAnimator;
7 | import com.wang.avi.Indicator;
8 |
9 | import java.util.ArrayList;
10 |
11 | /**
12 | * Created by Jack on 2015/10/19.
13 | */
14 | public class BallPulseSyncIndicator extends Indicator {
15 |
16 | float[] translateYFloats=new float[3];
17 |
18 | @Override
19 | public void draw(Canvas canvas, Paint paint) {
20 | float circleSpacing=4;
21 | float radius=(getWidth()-circleSpacing*2)/6;
22 | float x = getWidth()/ 2-(radius*2+circleSpacing);
23 | for (int i = 0; i < 3; i++) {
24 | canvas.save();
25 | float translateX=x+(radius*2)*i+circleSpacing*i;
26 | canvas.translate(translateX, translateYFloats[i]);
27 | canvas.drawCircle(0, 0, radius, paint);
28 | canvas.restore();
29 | }
30 | }
31 |
32 | @Override
33 | public ArrayList onCreateAnimators() {
34 | ArrayList animators=new ArrayList<>();
35 | float circleSpacing=4;
36 | float radius=(getWidth()-circleSpacing*2)/6;
37 | int[] delays=new int[]{70,140,210};
38 | for (int i = 0; i < 3; i++) {
39 | final int index=i;
40 | ValueAnimator scaleAnim=ValueAnimator.ofFloat(getHeight()/2,getHeight()/2-radius*2,getHeight()/2);
41 | scaleAnim.setDuration(600);
42 | scaleAnim.setRepeatCount(-1);
43 | scaleAnim.setStartDelay(delays[i]);
44 | addUpdateListener(scaleAnim,new ValueAnimator.AnimatorUpdateListener() {
45 | @Override
46 | public void onAnimationUpdate(ValueAnimator animation) {
47 | translateYFloats[index] = (float) animation.getAnimatedValue();
48 | postInvalidate();
49 | }
50 | });
51 | animators.add(scaleAnim);
52 | }
53 | return animators;
54 | }
55 |
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/library/src/main/java/com/wang/avi/indicators/BallRotateIndicator.java:
--------------------------------------------------------------------------------
1 | package com.wang.avi.indicators;
2 |
3 | import android.animation.ValueAnimator;
4 | import android.graphics.Canvas;
5 | import android.graphics.Matrix;
6 | import android.graphics.Paint;
7 |
8 | import com.wang.avi.Indicator;
9 |
10 | import java.util.ArrayList;
11 |
12 | /**
13 | * Created by Jack on 2015/10/17.
14 | */
15 | public class BallRotateIndicator extends Indicator {
16 |
17 | float scaleFloat=0.5f;
18 |
19 | float degress;
20 |
21 | private Matrix mMatrix;
22 |
23 | public BallRotateIndicator(){
24 | mMatrix=new Matrix();
25 | }
26 |
27 | @Override
28 | public void draw(Canvas canvas, Paint paint) {
29 | float radius=getWidth()/10;
30 | float x = getWidth()/ 2;
31 | float y=getHeight()/2;
32 |
33 | /*mMatrix.preTranslate(-centerX(), -centerY());
34 | mMatrix.preRotate(degress,centerX(),centerY());
35 | mMatrix.postTranslate(centerX(), centerY());
36 | canvas.concat(mMatrix);*/
37 |
38 | canvas.rotate(degress,centerX(),centerY());
39 |
40 | canvas.save();
41 | canvas.translate(x - radius * 2 - radius, y);
42 | canvas.scale(scaleFloat, scaleFloat);
43 | canvas.drawCircle(0, 0, radius, paint);
44 | canvas.restore();
45 |
46 | canvas.save();
47 | canvas.translate(x, y);
48 | canvas.scale(scaleFloat, scaleFloat);
49 | canvas.drawCircle(0, 0, radius, paint);
50 | canvas.restore();
51 |
52 | canvas.save();
53 | canvas.translate(x + radius * 2 + radius, y);
54 | canvas.scale(scaleFloat, scaleFloat);
55 | canvas.drawCircle(0,0,radius, paint);
56 | canvas.restore();
57 | }
58 |
59 | @Override
60 | public ArrayList onCreateAnimators() {
61 | ArrayList animators=new ArrayList<>();
62 | ValueAnimator scaleAnim=ValueAnimator.ofFloat(0.5f,1,0.5f);
63 | scaleAnim.setDuration(1000);
64 | scaleAnim.setRepeatCount(-1);
65 | addUpdateListener(scaleAnim,new ValueAnimator.AnimatorUpdateListener() {
66 | @Override
67 | public void onAnimationUpdate(ValueAnimator animation) {
68 | scaleFloat = (float) animation.getAnimatedValue();
69 | postInvalidate();
70 | }
71 | });
72 |
73 | ValueAnimator rotateAnim=ValueAnimator.ofFloat(0,180,360);
74 | addUpdateListener(rotateAnim,new ValueAnimator.AnimatorUpdateListener() {
75 | @Override
76 | public void onAnimationUpdate(ValueAnimator animation) {
77 | degress = (float) animation.getAnimatedValue();
78 | postInvalidate();
79 | }
80 | });
81 | rotateAnim.setDuration(1000);
82 | rotateAnim.setRepeatCount(-1);
83 |
84 | animators.add(scaleAnim);
85 | animators.add(rotateAnim);
86 | return animators;
87 | }
88 |
89 | }
90 |
--------------------------------------------------------------------------------
/library/src/main/java/com/wang/avi/indicators/BallScaleIndicator.java:
--------------------------------------------------------------------------------
1 | package com.wang.avi.indicators;
2 |
3 | import android.graphics.Canvas;
4 | import android.graphics.Paint;
5 | import android.view.animation.LinearInterpolator;
6 |
7 | import android.animation.ValueAnimator;
8 | import com.wang.avi.Indicator;
9 |
10 | import java.util.ArrayList;
11 |
12 | /**
13 | * Created by Jack on 2015/10/19.
14 | */
15 | public class BallScaleIndicator extends Indicator {
16 |
17 | float scale=1;
18 | int alpha=255;
19 |
20 | @Override
21 | public void draw(Canvas canvas, Paint paint) {
22 | float circleSpacing=4;
23 | paint.setAlpha(alpha);
24 | canvas.scale(scale,scale,getWidth()/2,getHeight()/2);
25 | paint.setAlpha(alpha);
26 | canvas.drawCircle(getWidth()/2,getHeight()/2,getWidth()/2-circleSpacing,paint);
27 | }
28 |
29 | @Override
30 | public ArrayList onCreateAnimators() {
31 | ArrayList animators=new ArrayList<>();
32 | ValueAnimator scaleAnim=ValueAnimator.ofFloat(0,1);
33 | scaleAnim.setInterpolator(new LinearInterpolator());
34 | scaleAnim.setDuration(1000);
35 | scaleAnim.setRepeatCount(-1);
36 | addUpdateListener(scaleAnim,new ValueAnimator.AnimatorUpdateListener() {
37 | @Override
38 | public void onAnimationUpdate(ValueAnimator animation) {
39 | scale = (float) animation.getAnimatedValue();
40 | postInvalidate();
41 | }
42 | });
43 |
44 | ValueAnimator alphaAnim=ValueAnimator.ofInt(255, 0);
45 | alphaAnim.setInterpolator(new LinearInterpolator());
46 | alphaAnim.setDuration(1000);
47 | alphaAnim.setRepeatCount(-1);
48 | addUpdateListener(alphaAnim,new ValueAnimator.AnimatorUpdateListener() {
49 | @Override
50 | public void onAnimationUpdate(ValueAnimator animation) {
51 | alpha = (int) animation.getAnimatedValue();
52 | postInvalidate();
53 | }
54 | });
55 | animators.add(scaleAnim);
56 | animators.add(alphaAnim);
57 | return animators;
58 | }
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/library/src/main/java/com/wang/avi/indicators/BallScaleMultipleIndicator.java:
--------------------------------------------------------------------------------
1 | package com.wang.avi.indicators;
2 |
3 | import android.graphics.Canvas;
4 | import android.graphics.Paint;
5 | import android.view.animation.LinearInterpolator;
6 |
7 | import android.animation.ValueAnimator;
8 | import com.wang.avi.Indicator;
9 |
10 | import java.util.ArrayList;
11 |
12 | /**
13 | * Created by Jack on 2015/10/19.
14 | */
15 | public class BallScaleMultipleIndicator extends Indicator {
16 |
17 | float[] scaleFloats=new float[]{1,1,1};
18 | int[] alphaInts=new int[]{255,255,255};
19 |
20 | @Override
21 | public void draw(Canvas canvas, Paint paint) {
22 | float circleSpacing=4;
23 | for (int i = 0; i < 3; i++) {
24 | paint.setAlpha(alphaInts[i]);
25 | canvas.scale(scaleFloats[i],scaleFloats[i],getWidth()/2,getHeight()/2);
26 | canvas.drawCircle(getWidth()/2,getHeight()/2,getWidth()/2-circleSpacing,paint);
27 | }
28 | }
29 |
30 | @Override
31 | public ArrayList onCreateAnimators() {
32 | ArrayList animators=new ArrayList<>();
33 | long[] delays=new long[]{0, 200, 400};
34 | for (int i = 0; i < 3; i++) {
35 | final int index=i;
36 | ValueAnimator scaleAnim=ValueAnimator.ofFloat(0,1);
37 | scaleAnim.setInterpolator(new LinearInterpolator());
38 | scaleAnim.setDuration(1000);
39 | scaleAnim.setRepeatCount(-1);
40 | addUpdateListener(scaleAnim,new ValueAnimator.AnimatorUpdateListener() {
41 | @Override
42 | public void onAnimationUpdate(ValueAnimator animation) {
43 | scaleFloats[index] = (float) animation.getAnimatedValue();
44 | postInvalidate();
45 | }
46 | });
47 | scaleAnim.setStartDelay(delays[i]);
48 |
49 | ValueAnimator alphaAnim=ValueAnimator.ofInt(255,0);
50 | alphaAnim.setInterpolator(new LinearInterpolator());
51 | alphaAnim.setDuration(1000);
52 | alphaAnim.setRepeatCount(-1);
53 | addUpdateListener(alphaAnim,new ValueAnimator.AnimatorUpdateListener() {
54 | @Override
55 | public void onAnimationUpdate(ValueAnimator animation) {
56 | alphaInts[index] = (int) animation.getAnimatedValue();
57 | postInvalidate();
58 | }
59 | });
60 | scaleAnim.setStartDelay(delays[i]);
61 |
62 | animators.add(scaleAnim);
63 | animators.add(alphaAnim);
64 | }
65 | return animators;
66 | }
67 |
68 | }
69 |
--------------------------------------------------------------------------------
/library/src/main/java/com/wang/avi/indicators/BallScaleRippleIndicator.java:
--------------------------------------------------------------------------------
1 | package com.wang.avi.indicators;
2 |
3 | import android.graphics.Canvas;
4 | import android.graphics.Paint;
5 | import android.view.animation.LinearInterpolator;
6 |
7 | import android.animation.ValueAnimator;
8 |
9 | import java.util.ArrayList;
10 |
11 | /**
12 | * Created by Jack on 2015/10/19.
13 | */
14 | public class BallScaleRippleIndicator extends BallScaleIndicator {
15 |
16 |
17 | @Override
18 | public void draw(Canvas canvas, Paint paint) {
19 | paint.setStyle(Paint.Style.STROKE);
20 | paint.setStrokeWidth(3);
21 | super.draw(canvas, paint);
22 | }
23 |
24 | @Override
25 | public ArrayList onCreateAnimators() {
26 | ArrayList animators=new ArrayList<>();
27 | ValueAnimator scaleAnim=ValueAnimator.ofFloat(0,1);
28 | scaleAnim.setInterpolator(new LinearInterpolator());
29 | scaleAnim.setDuration(1000);
30 | scaleAnim.setRepeatCount(-1);
31 | addUpdateListener(scaleAnim,new ValueAnimator.AnimatorUpdateListener() {
32 | @Override
33 | public void onAnimationUpdate(ValueAnimator animation) {
34 | scale = (float) animation.getAnimatedValue();
35 | postInvalidate();
36 | }
37 | });
38 |
39 | ValueAnimator alphaAnim=ValueAnimator.ofInt(0, 255);
40 | alphaAnim.setInterpolator(new LinearInterpolator());
41 | alphaAnim.setDuration(1000);
42 | alphaAnim.setRepeatCount(-1);
43 | addUpdateListener(alphaAnim,new ValueAnimator.AnimatorUpdateListener() {
44 | @Override
45 | public void onAnimationUpdate(ValueAnimator animation) {
46 | alpha = (int) animation.getAnimatedValue();
47 | postInvalidate();
48 | }
49 | });
50 |
51 | animators.add(scaleAnim);
52 | animators.add(alphaAnim);
53 | return animators;
54 | }
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/library/src/main/java/com/wang/avi/indicators/BallScaleRippleMultipleIndicator.java:
--------------------------------------------------------------------------------
1 | package com.wang.avi.indicators;
2 |
3 | import android.graphics.Canvas;
4 | import android.graphics.Paint;
5 | import android.view.animation.LinearInterpolator;
6 |
7 | import android.animation.ValueAnimator;
8 |
9 | import java.util.ArrayList;
10 |
11 | /**
12 | * Created by Jack on 2015/10/19.
13 | */
14 | public class BallScaleRippleMultipleIndicator extends BallScaleMultipleIndicator {
15 |
16 |
17 | @Override
18 | public void draw(Canvas canvas, Paint paint) {
19 | paint.setStyle(Paint.Style.STROKE);
20 | paint.setStrokeWidth(3);
21 | super.draw(canvas, paint);
22 | }
23 |
24 | @Override
25 | public ArrayList onCreateAnimators() {
26 | ArrayList animators=new ArrayList<>();
27 | long[] delays=new long[]{0, 200, 400};
28 | for (int i = 0; i < 3; i++) {
29 | final int index=i;
30 | ValueAnimator scaleAnim=ValueAnimator.ofFloat(0,1);
31 | scaleAnim.setInterpolator(new LinearInterpolator());
32 | scaleAnim.setDuration(1000);
33 | scaleAnim.setRepeatCount(-1);
34 | addUpdateListener(scaleAnim,new ValueAnimator.AnimatorUpdateListener() {
35 | @Override
36 | public void onAnimationUpdate(ValueAnimator animation) {
37 | scaleFloats[index] = (float) animation.getAnimatedValue();
38 | postInvalidate();
39 | }
40 | });
41 | scaleAnim.setStartDelay(delays[i]);
42 |
43 | ValueAnimator alphaAnim=ValueAnimator.ofInt(0,255);
44 | scaleAnim.setInterpolator(new LinearInterpolator());
45 | alphaAnim.setDuration(1000);
46 | alphaAnim.setRepeatCount(-1);
47 | addUpdateListener(alphaAnim,new ValueAnimator.AnimatorUpdateListener() {
48 | @Override
49 | public void onAnimationUpdate(ValueAnimator animation) {
50 | alphaInts[index] = (int) animation.getAnimatedValue();
51 | postInvalidate();
52 | }
53 | });
54 | scaleAnim.setStartDelay(delays[i]);
55 |
56 | animators.add(scaleAnim);
57 | animators.add(alphaAnim);
58 | }
59 | return animators;
60 | }
61 |
62 | }
63 |
--------------------------------------------------------------------------------
/library/src/main/java/com/wang/avi/indicators/BallSpinFadeLoaderIndicator.java:
--------------------------------------------------------------------------------
1 | package com.wang.avi.indicators;
2 |
3 | import android.graphics.Canvas;
4 | import android.graphics.Paint;
5 |
6 | import android.animation.ValueAnimator;
7 | import com.wang.avi.Indicator;
8 |
9 | import java.util.ArrayList;
10 |
11 | /**
12 | * Created by Jack on 2015/10/20.
13 | */
14 | public class BallSpinFadeLoaderIndicator extends Indicator {
15 |
16 | public static final float SCALE=1.0f;
17 |
18 | public static final int ALPHA=255;
19 |
20 | float[] scaleFloats=new float[]{SCALE,
21 | SCALE,
22 | SCALE,
23 | SCALE,
24 | SCALE,
25 | SCALE,
26 | SCALE,
27 | SCALE};
28 |
29 | int[] alphas=new int[]{ALPHA,
30 | ALPHA,
31 | ALPHA,
32 | ALPHA,
33 | ALPHA,
34 | ALPHA,
35 | ALPHA,
36 | ALPHA};
37 |
38 |
39 | @Override
40 | public void draw(Canvas canvas, Paint paint) {
41 | float radius=getWidth()/10;
42 | for (int i = 0; i < 8; i++) {
43 | canvas.save();
44 | Point point=circleAt(getWidth(),getHeight(),getWidth()/2-radius,i*(Math.PI/4));
45 | canvas.translate(point.x,point.y);
46 | canvas.scale(scaleFloats[i],scaleFloats[i]);
47 | paint.setAlpha(alphas[i]);
48 | canvas.drawCircle(0,0,radius,paint);
49 | canvas.restore();
50 | }
51 | }
52 |
53 | @Override
54 | public ArrayList onCreateAnimators() {
55 | ArrayList animators=new ArrayList<>();
56 | int[] delays= {0, 120, 240, 360, 480, 600, 720, 780, 840};
57 | for (int i = 0; i < 8; i++) {
58 | final int index=i;
59 | ValueAnimator scaleAnim=ValueAnimator.ofFloat(1,0.4f,1);
60 | scaleAnim.setDuration(1000);
61 | scaleAnim.setRepeatCount(-1);
62 | scaleAnim.setStartDelay(delays[i]);
63 | addUpdateListener(scaleAnim,new ValueAnimator.AnimatorUpdateListener() {
64 | @Override
65 | public void onAnimationUpdate(ValueAnimator animation) {
66 | scaleFloats[index] = (float) animation.getAnimatedValue();
67 | postInvalidate();
68 | }
69 | });
70 |
71 | ValueAnimator alphaAnim=ValueAnimator.ofInt(255, 77, 255);
72 | alphaAnim.setDuration(1000);
73 | alphaAnim.setRepeatCount(-1);
74 | alphaAnim.setStartDelay(delays[i]);
75 | addUpdateListener(alphaAnim,new ValueAnimator.AnimatorUpdateListener() {
76 | @Override
77 | public void onAnimationUpdate(ValueAnimator animation) {
78 | alphas[index] = (int) animation.getAnimatedValue();
79 | postInvalidate();
80 | }
81 | });
82 | animators.add(scaleAnim);
83 | animators.add(alphaAnim);
84 | }
85 | return animators;
86 | }
87 |
88 | /**
89 | * 圆O的圆心为(a,b),半径为R,点A与到X轴的为角α.
90 | *则点A的坐标为(a+R*cosα,b+R*sinα)
91 | * @param width
92 | * @param height
93 | * @param radius
94 | * @param angle
95 | * @return
96 | */
97 | Point circleAt(int width,int height,float radius,double angle){
98 | float x= (float) (width/2+radius*(Math.cos(angle)));
99 | float y= (float) (height/2+radius*(Math.sin(angle)));
100 | return new Point(x,y);
101 | }
102 |
103 | final class Point{
104 | public float x;
105 | public float y;
106 |
107 | public Point(float x, float y){
108 | this.x=x;
109 | this.y=y;
110 | }
111 | }
112 |
113 |
114 | }
115 |
--------------------------------------------------------------------------------
/library/src/main/java/com/wang/avi/indicators/BallTrianglePathIndicator.java:
--------------------------------------------------------------------------------
1 | package com.wang.avi.indicators;
2 |
3 | import android.graphics.Canvas;
4 | import android.graphics.Paint;
5 | import android.view.animation.LinearInterpolator;
6 |
7 | import android.animation.ValueAnimator;
8 | import com.wang.avi.Indicator;
9 |
10 | import java.util.ArrayList;
11 |
12 | /**
13 | * Created by Jack on 2015/10/19.
14 | */
15 | public class BallTrianglePathIndicator extends Indicator {
16 |
17 | float[] translateX=new float[3],translateY=new float[3];
18 |
19 | @Override
20 | public void draw(Canvas canvas, Paint paint) {
21 | paint.setStrokeWidth(3);
22 | paint.setStyle(Paint.Style.STROKE);
23 | for (int i = 0; i < 3; i++) {
24 | canvas.save();
25 | canvas.translate(translateX[i], translateY[i]);
26 | canvas.drawCircle(0, 0, getWidth() / 10, paint);
27 | canvas.restore();
28 | }
29 | }
30 |
31 | @Override
32 | public ArrayList onCreateAnimators() {
33 | ArrayList animators=new ArrayList<>();
34 | float startX=getWidth()/5;
35 | float startY=getWidth()/5;
36 | for (int i = 0; i < 3; i++) {
37 | final int index=i;
38 | ValueAnimator translateXAnim=ValueAnimator.ofFloat(getWidth()/2,getWidth()-startX,startX,getWidth()/2);
39 | if (i==1){
40 | translateXAnim=ValueAnimator.ofFloat(getWidth()-startX,startX,getWidth()/2,getWidth()-startX);
41 | }else if (i==2){
42 | translateXAnim=ValueAnimator.ofFloat(startX,getWidth()/2,getWidth()-startX,startX);
43 | }
44 | ValueAnimator translateYAnim=ValueAnimator.ofFloat(startY,getHeight()-startY,getHeight()-startY,startY);
45 | if (i==1){
46 | translateYAnim=ValueAnimator.ofFloat(getHeight()-startY,getHeight()-startY,startY,getHeight()-startY);
47 | }else if (i==2){
48 | translateYAnim=ValueAnimator.ofFloat(getHeight()-startY,startY,getHeight()-startY,getHeight()-startY);
49 | }
50 |
51 | translateXAnim.setDuration(2000);
52 | translateXAnim.setInterpolator(new LinearInterpolator());
53 | translateXAnim.setRepeatCount(-1);
54 | addUpdateListener(translateXAnim,new ValueAnimator.AnimatorUpdateListener() {
55 | @Override
56 | public void onAnimationUpdate(ValueAnimator animation) {
57 | translateX [index]= (float) animation.getAnimatedValue();
58 | postInvalidate();
59 | }
60 | });
61 |
62 | translateYAnim.setDuration(2000);
63 | translateYAnim.setInterpolator(new LinearInterpolator());
64 | translateYAnim.setRepeatCount(-1);
65 | addUpdateListener(translateYAnim,new ValueAnimator.AnimatorUpdateListener() {
66 | @Override
67 | public void onAnimationUpdate(ValueAnimator animation) {
68 | translateY [index]= (float) animation.getAnimatedValue();
69 | postInvalidate();
70 | }
71 | });
72 |
73 | animators.add(translateXAnim);
74 | animators.add(translateYAnim);
75 | }
76 | return animators;
77 | }
78 |
79 |
80 | }
81 |
--------------------------------------------------------------------------------
/library/src/main/java/com/wang/avi/indicators/BallZigZagDeflectIndicator.java:
--------------------------------------------------------------------------------
1 | package com.wang.avi.indicators;
2 |
3 |
4 | import android.view.animation.LinearInterpolator;
5 | import android.animation.ValueAnimator;
6 | import java.util.ArrayList;
7 |
8 | /**
9 | * Created by Jack on 2015/10/19.
10 | */
11 | public class BallZigZagDeflectIndicator extends BallZigZagIndicator {
12 |
13 |
14 |
15 |
16 | @Override
17 | public ArrayList onCreateAnimators() {
18 | ArrayList animators=new ArrayList<>();
19 | float startX=getWidth()/6;
20 | float startY=getWidth()/6;
21 | for (int i = 0; i < 2; i++) {
22 | final int index=i;
23 | ValueAnimator translateXAnim=ValueAnimator.ofFloat(startX,getWidth()-startX,startX,getWidth()-startX,startX);
24 | if (i==1){
25 | translateXAnim=ValueAnimator.ofFloat(getWidth()-startX,startX,getWidth()-startX,startX,getWidth()-startX);
26 | }
27 | ValueAnimator translateYAnim=ValueAnimator.ofFloat(startY,startY,getHeight()-startY,getHeight()-startY,startY);
28 | if (i==1){
29 | translateYAnim=ValueAnimator.ofFloat(getHeight()-startY,getHeight()-startY,startY,startY,getHeight()-startY);
30 | }
31 |
32 | translateXAnim.setDuration(2000);
33 | translateXAnim.setInterpolator(new LinearInterpolator());
34 | translateXAnim.setRepeatCount(-1);
35 | addUpdateListener(translateXAnim,new ValueAnimator.AnimatorUpdateListener() {
36 | @Override
37 | public void onAnimationUpdate(ValueAnimator animation) {
38 | translateX [index]= (float) animation.getAnimatedValue();
39 | postInvalidate();
40 | }
41 | });
42 |
43 | translateYAnim.setDuration(2000);
44 | translateYAnim.setInterpolator(new LinearInterpolator());
45 | translateYAnim.setRepeatCount(-1);
46 | addUpdateListener(translateYAnim,new ValueAnimator.AnimatorUpdateListener() {
47 | @Override
48 | public void onAnimationUpdate(ValueAnimator animation) {
49 | translateY [index]= (float) animation.getAnimatedValue();
50 | postInvalidate();
51 | }
52 | });
53 |
54 | animators.add(translateXAnim);
55 | animators.add(translateYAnim);
56 | }
57 | return animators;
58 | }
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/library/src/main/java/com/wang/avi/indicators/BallZigZagIndicator.java:
--------------------------------------------------------------------------------
1 | package com.wang.avi.indicators;
2 |
3 | import android.graphics.Canvas;
4 | import android.graphics.Paint;
5 | import android.view.animation.LinearInterpolator;
6 |
7 | import android.animation.ValueAnimator;
8 | import com.wang.avi.Indicator;
9 |
10 | import java.util.ArrayList;
11 |
12 | /**
13 | * Created by Jack on 2015/10/19.
14 | */
15 | public class BallZigZagIndicator extends Indicator {
16 |
17 | float[] translateX=new float[2],translateY=new float[2];
18 |
19 |
20 | @Override
21 | public void draw(Canvas canvas, Paint paint) {
22 | for (int i = 0; i < 2; i++) {
23 | canvas.save();
24 | canvas.translate(translateX[i], translateY[i]);
25 | canvas.drawCircle(0, 0, getWidth() / 10, paint);
26 | canvas.restore();
27 | }
28 | }
29 |
30 | @Override
31 | public ArrayList onCreateAnimators() {
32 | ArrayList animators=new ArrayList<>();
33 | float startX=getWidth()/6;
34 | float startY=getWidth()/6;
35 | for (int i = 0; i < 2; i++) {
36 | final int index=i;
37 | ValueAnimator translateXAnim=ValueAnimator.ofFloat(startX,getWidth()-startX,getWidth()/2,startX);
38 | if (i==1){
39 | translateXAnim=ValueAnimator.ofFloat(getWidth()-startX,startX,getWidth()/2,getWidth()-startX);
40 | }
41 | ValueAnimator translateYAnim=ValueAnimator.ofFloat(startY,startY,getHeight()/2,startY);
42 | if (i==1){
43 | translateYAnim=ValueAnimator.ofFloat(getHeight()-startY,getHeight()-startY,getHeight()/2,getHeight()-startY);
44 | }
45 |
46 | translateXAnim.setDuration(1000);
47 | translateXAnim.setInterpolator(new LinearInterpolator());
48 | translateXAnim.setRepeatCount(-1);
49 | addUpdateListener(translateXAnim,new ValueAnimator.AnimatorUpdateListener() {
50 | @Override
51 | public void onAnimationUpdate(ValueAnimator animation) {
52 | translateX[index] = (float) animation.getAnimatedValue();
53 | postInvalidate();
54 | }
55 | });
56 |
57 | translateYAnim.setDuration(1000);
58 | translateYAnim.setInterpolator(new LinearInterpolator());
59 | translateYAnim.setRepeatCount(-1);
60 | addUpdateListener(translateYAnim,new ValueAnimator.AnimatorUpdateListener() {
61 | @Override
62 | public void onAnimationUpdate(ValueAnimator animation) {
63 | translateY[index] = (float) animation.getAnimatedValue();
64 | postInvalidate();
65 | }
66 | });
67 | animators.add(translateXAnim);
68 | animators.add(translateYAnim);
69 | }
70 | return animators;
71 | }
72 |
73 | }
74 |
--------------------------------------------------------------------------------
/library/src/main/java/com/wang/avi/indicators/CubeTransitionIndicator.java:
--------------------------------------------------------------------------------
1 | package com.wang.avi.indicators;
2 |
3 | import android.graphics.Canvas;
4 | import android.graphics.Paint;
5 | import android.graphics.RectF;
6 | import android.view.animation.LinearInterpolator;
7 |
8 | import android.animation.ValueAnimator;
9 | import com.wang.avi.Indicator;
10 |
11 | import java.util.ArrayList;
12 |
13 | /**
14 | * Created by Jack on 2015/10/18.
15 | */
16 | public class CubeTransitionIndicator extends Indicator {
17 |
18 | float[] translateX=new float[2],translateY=new float[2];
19 | float degrees,scaleFloat=1.0f;
20 |
21 | @Override
22 | public void draw(Canvas canvas, Paint paint) {
23 | float rWidth=getWidth()/5;
24 | float rHeight=getHeight()/5;
25 | for (int i = 0; i < 2; i++) {
26 | canvas.save();
27 | canvas.translate(translateX[i], translateY[i]);
28 | canvas.rotate(degrees);
29 | canvas.scale(scaleFloat,scaleFloat);
30 | RectF rectF=new RectF(-rWidth/2,-rHeight/2,rWidth/2,rHeight/2);
31 | canvas.drawRect(rectF,paint);
32 | canvas.restore();
33 | }
34 | }
35 |
36 | @Override
37 | public ArrayList onCreateAnimators() {
38 | ArrayList animators=new ArrayList<>();
39 | float startX=getWidth()/5;
40 | float startY=getHeight()/5;
41 | for (int i = 0; i < 2; i++) {
42 | final int index=i;
43 | translateX[index]=startX;
44 | ValueAnimator translationXAnim=ValueAnimator.ofFloat(startX,getWidth()-startX,getWidth()-startX, startX,startX);
45 | if (i==1){
46 | translationXAnim=ValueAnimator.ofFloat(getWidth()-startX,startX,startX, getWidth()-startX,getWidth()-startX);
47 | }
48 | translationXAnim.setInterpolator(new LinearInterpolator());
49 | translationXAnim.setDuration(1600);
50 | translationXAnim.setRepeatCount(-1);
51 | translationXAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
52 | @Override
53 | public void onAnimationUpdate(ValueAnimator animation) {
54 | translateX[index] = (float) animation.getAnimatedValue();
55 | postInvalidate();
56 | }
57 | });
58 | translateY[index]=startY;
59 | ValueAnimator translationYAnim=ValueAnimator.ofFloat(startY,startY,getHeight()-startY,getHeight()- startY,startY);
60 | if (i==1){
61 | translationYAnim=ValueAnimator.ofFloat(getHeight()-startY,getHeight()-startY,startY,startY,getHeight()-startY);
62 | }
63 | translationYAnim.setDuration(1600);
64 | translationYAnim.setInterpolator(new LinearInterpolator());
65 | translationYAnim.setRepeatCount(-1);
66 | addUpdateListener(translationYAnim,new ValueAnimator.AnimatorUpdateListener() {
67 | @Override
68 | public void onAnimationUpdate(ValueAnimator animation) {
69 | translateY[index] = (float) animation.getAnimatedValue();
70 | postInvalidate();
71 | }
72 | });
73 |
74 | animators.add(translationXAnim);
75 | animators.add(translationYAnim);
76 | }
77 |
78 | ValueAnimator scaleAnim=ValueAnimator.ofFloat(1,0.5f,1,0.5f,1);
79 | scaleAnim.setDuration(1600);
80 | scaleAnim.setInterpolator(new LinearInterpolator());
81 | scaleAnim.setRepeatCount(-1);
82 | addUpdateListener(scaleAnim,new ValueAnimator.AnimatorUpdateListener() {
83 | @Override
84 | public void onAnimationUpdate(ValueAnimator animation) {
85 | scaleFloat = (float) animation.getAnimatedValue();
86 | postInvalidate();
87 | }
88 | });
89 |
90 | ValueAnimator rotateAnim=ValueAnimator.ofFloat(0,180,360,1.5f*360,2*360);
91 | rotateAnim.setDuration(1600);
92 | rotateAnim.setInterpolator(new LinearInterpolator());
93 | rotateAnim.setRepeatCount(-1);
94 | addUpdateListener(rotateAnim,new ValueAnimator.AnimatorUpdateListener() {
95 | @Override
96 | public void onAnimationUpdate(ValueAnimator animation) {
97 | degrees = (float) animation.getAnimatedValue();
98 | postInvalidate();
99 | }
100 | });
101 |
102 | animators.add(scaleAnim);
103 | animators.add(rotateAnim);
104 | return animators;
105 | }
106 | }
107 |
--------------------------------------------------------------------------------
/library/src/main/java/com/wang/avi/indicators/LineScaleIndicator.java:
--------------------------------------------------------------------------------
1 | package com.wang.avi.indicators;
2 |
3 | import android.graphics.Canvas;
4 | import android.graphics.Paint;
5 | import android.graphics.RectF;
6 |
7 | import android.animation.ValueAnimator;
8 | import com.wang.avi.Indicator;
9 |
10 | import java.util.ArrayList;
11 |
12 | /**
13 | * Created by Jack on 2015/10/19.
14 | */
15 | public class LineScaleIndicator extends Indicator {
16 |
17 | public static final float SCALE=1.0f;
18 |
19 | float[] scaleYFloats=new float[]{SCALE,
20 | SCALE,
21 | SCALE,
22 | SCALE,
23 | SCALE,};
24 |
25 | @Override
26 | public void draw(Canvas canvas, Paint paint) {
27 | float translateX=getWidth()/11;
28 | float translateY=getHeight()/2;
29 | for (int i = 0; i < 5; i++) {
30 | canvas.save();
31 | canvas.translate((2 + i * 2) * translateX - translateX / 2, translateY);
32 | canvas.scale(SCALE, scaleYFloats[i]);
33 | RectF rectF=new RectF(-translateX/2,-getHeight()/2.5f,translateX/2,getHeight()/2.5f);
34 | canvas.drawRoundRect(rectF, 5, 5, paint);
35 | canvas.restore();
36 | }
37 | }
38 |
39 | @Override
40 | public ArrayList onCreateAnimators() {
41 | ArrayList animators=new ArrayList<>();
42 | long[] delays=new long[]{100,200,300,400,500};
43 | for (int i = 0; i < 5; i++) {
44 | final int index=i;
45 | ValueAnimator scaleAnim=ValueAnimator.ofFloat(1, 0.4f, 1);
46 | scaleAnim.setDuration(1000);
47 | scaleAnim.setRepeatCount(-1);
48 | scaleAnim.setStartDelay(delays[i]);
49 | addUpdateListener(scaleAnim,new ValueAnimator.AnimatorUpdateListener() {
50 | @Override
51 | public void onAnimationUpdate(ValueAnimator animation) {
52 | scaleYFloats[index] = (float) animation.getAnimatedValue();
53 | postInvalidate();
54 | }
55 | });
56 | animators.add(scaleAnim);
57 | }
58 | return animators;
59 | }
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/library/src/main/java/com/wang/avi/indicators/LineScalePartyIndicator.java:
--------------------------------------------------------------------------------
1 | package com.wang.avi.indicators;
2 |
3 | import android.graphics.Canvas;
4 | import android.graphics.Paint;
5 | import android.graphics.RectF;
6 |
7 | import android.animation.ValueAnimator;
8 | import com.wang.avi.Indicator;
9 |
10 | import java.util.ArrayList;
11 |
12 | /**
13 | * Created by Jack on 2015/10/19.
14 | */
15 | public class LineScalePartyIndicator extends Indicator {
16 |
17 | public static final float SCALE=1.0f;
18 |
19 | float[] scaleFloats=new float[]{SCALE,
20 | SCALE,
21 | SCALE,
22 | SCALE,
23 | SCALE,};
24 |
25 | @Override
26 | public void draw(Canvas canvas, Paint paint) {
27 | float translateX=getWidth()/9;
28 | float translateY=getHeight()/2;
29 | for (int i = 0; i < 4; i++) {
30 | canvas.save();
31 | canvas.translate((2 + i * 2) * translateX - translateX / 2, translateY);
32 | canvas.scale(scaleFloats[i], scaleFloats[i]);
33 | RectF rectF=new RectF(-translateX/2,-getHeight()/2.5f,translateX/2,getHeight()/2.5f);
34 | canvas.drawRoundRect(rectF,5,5,paint);
35 | canvas.restore();
36 | }
37 | }
38 |
39 |
40 | @Override
41 | public ArrayList onCreateAnimators() {
42 | ArrayList animators=new ArrayList<>();
43 | long[] durations=new long[]{1260, 430, 1010, 730};
44 | long[] delays=new long[]{770, 290, 280, 740};
45 | for (int i = 0; i < 4; i++) {
46 | final int index=i;
47 | ValueAnimator scaleAnim=ValueAnimator.ofFloat(1,0.4f,1);
48 | scaleAnim.setDuration(durations[i]);
49 | scaleAnim.setRepeatCount(-1);
50 | scaleAnim.setStartDelay(delays[i]);
51 | addUpdateListener(scaleAnim,new ValueAnimator.AnimatorUpdateListener() {
52 | @Override
53 | public void onAnimationUpdate(ValueAnimator animation) {
54 | scaleFloats[index] = (float) animation.getAnimatedValue();
55 | postInvalidate();
56 | }
57 | });
58 | animators.add(scaleAnim);
59 | }
60 | return animators;
61 | }
62 |
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/library/src/main/java/com/wang/avi/indicators/LineScalePulseOutIndicator.java:
--------------------------------------------------------------------------------
1 | package com.wang.avi.indicators;
2 |
3 |
4 | import android.animation.ValueAnimator;
5 |
6 | import java.util.ArrayList;
7 |
8 | /**
9 | * Created by Jack on 2015/10/19.
10 | */
11 | public class LineScalePulseOutIndicator extends LineScaleIndicator {
12 |
13 | @Override
14 | public ArrayList onCreateAnimators() {
15 | ArrayList animators=new ArrayList<>();
16 | long[] delays=new long[]{500,250,0,250,500};
17 | for (int i = 0; i < 5; i++) {
18 | final int index=i;
19 | ValueAnimator scaleAnim=ValueAnimator.ofFloat(1,0.3f,1);
20 | scaleAnim.setDuration(900);
21 | scaleAnim.setRepeatCount(-1);
22 | scaleAnim.setStartDelay(delays[i]);
23 | addUpdateListener(scaleAnim,new ValueAnimator.AnimatorUpdateListener() {
24 | @Override
25 | public void onAnimationUpdate(ValueAnimator animation) {
26 | scaleYFloats[index] = (float) animation.getAnimatedValue();
27 | postInvalidate();
28 | }
29 | });
30 | animators.add(scaleAnim);
31 | }
32 | return animators;
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/library/src/main/java/com/wang/avi/indicators/LineScalePulseOutRapidIndicator.java:
--------------------------------------------------------------------------------
1 | package com.wang.avi.indicators;
2 |
3 |
4 | import android.animation.ValueAnimator;
5 |
6 | import java.util.ArrayList;
7 |
8 | /**
9 | * Created by Jack on 2015/10/19.
10 | */
11 | public class LineScalePulseOutRapidIndicator extends LineScaleIndicator {
12 |
13 | @Override
14 | public ArrayList onCreateAnimators() {
15 | ArrayList animators=new ArrayList<>();
16 | long[] delays=new long[]{400,200,0,200,400};
17 | for (int i = 0; i < 5; i++) {
18 | final int index=i;
19 | ValueAnimator scaleAnim=ValueAnimator.ofFloat(1,0.4f,1);
20 | scaleAnim.setDuration(1000);
21 | scaleAnim.setRepeatCount(-1);
22 | scaleAnim.setStartDelay(delays[i]);
23 | addUpdateListener(scaleAnim,new ValueAnimator.AnimatorUpdateListener() {
24 | @Override
25 | public void onAnimationUpdate(ValueAnimator animation) {
26 | scaleYFloats[index] = (float) animation.getAnimatedValue();
27 | postInvalidate();
28 | }
29 | });
30 | animators.add(scaleAnim);
31 | }
32 | return animators;
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/library/src/main/java/com/wang/avi/indicators/LineSpinFadeLoaderIndicator.java:
--------------------------------------------------------------------------------
1 | package com.wang.avi.indicators;
2 |
3 | import android.graphics.Canvas;
4 | import android.graphics.Paint;
5 | import android.graphics.RectF;
6 |
7 | /**
8 | * Created by Jack on 2015/10/24.
9 | * Email:81813780@qq.com
10 | */
11 | public class LineSpinFadeLoaderIndicator extends BallSpinFadeLoaderIndicator {
12 |
13 |
14 | @Override
15 | public void draw(Canvas canvas, Paint paint) {
16 | float radius=getWidth()/10;
17 | for (int i = 0; i < 8; i++) {
18 | canvas.save();
19 | Point point=circleAt(getWidth(),getHeight(),getWidth()/2.5f-radius,i*(Math.PI/4));
20 | canvas.translate(point.x, point.y);
21 | canvas.scale(scaleFloats[i], scaleFloats[i]);
22 | canvas.rotate(i*45);
23 | paint.setAlpha(alphas[i]);
24 | RectF rectF=new RectF(-radius,-radius/1.5f,1.5f*radius,radius/1.5f);
25 | canvas.drawRoundRect(rectF,5,5,paint);
26 | canvas.restore();
27 | }
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/library/src/main/java/com/wang/avi/indicators/PacmanIndicator.java:
--------------------------------------------------------------------------------
1 | package com.wang.avi.indicators;
2 |
3 | import android.graphics.Canvas;
4 | import android.graphics.Paint;
5 | import android.graphics.RectF;
6 | import android.view.animation.LinearInterpolator;
7 |
8 | import android.animation.ValueAnimator;
9 | import com.wang.avi.Indicator;
10 |
11 | import java.util.ArrayList;
12 |
13 | /**
14 | * Created by Jack on 2015/10/16.
15 | */
16 | public class PacmanIndicator extends Indicator {
17 |
18 | private float translateX;
19 |
20 | private int alpha;
21 |
22 | private float degrees1,degrees2;
23 |
24 | @Override
25 | public void draw(Canvas canvas, Paint paint) {
26 | drawPacman(canvas,paint);
27 | drawCircle(canvas,paint);
28 | }
29 |
30 | private void drawPacman(Canvas canvas,Paint paint){
31 | float x=getWidth()/2;
32 | float y=getHeight()/2;
33 |
34 | canvas.save();
35 |
36 | canvas.translate(x, y);
37 | canvas.rotate(degrees1);
38 | paint.setAlpha(255);
39 | RectF rectF1=new RectF(-x/1.7f,-y/1.7f,x/1.7f,y/1.7f);
40 | canvas.drawArc(rectF1, 0, 270, true, paint);
41 |
42 | canvas.restore();
43 |
44 | canvas.save();
45 | canvas.translate(x, y);
46 | canvas.rotate(degrees2);
47 | paint.setAlpha(255);
48 | RectF rectF2=new RectF(-x/1.7f,-y/1.7f,x/1.7f,y/1.7f);
49 | canvas.drawArc(rectF2,90,270,true,paint);
50 | canvas.restore();
51 | }
52 |
53 |
54 | private void drawCircle(Canvas canvas, Paint paint) {
55 | float radius=getWidth()/11;
56 | paint.setAlpha(alpha);
57 | canvas.drawCircle(translateX, getHeight() / 2, radius, paint);
58 | }
59 |
60 | @Override
61 | public ArrayList onCreateAnimators() {
62 | ArrayList animators=new ArrayList<>();
63 | float startT=getWidth()/11;
64 | ValueAnimator translationAnim=ValueAnimator.ofFloat(getWidth()-startT,getWidth()/2);
65 | translationAnim.setDuration(650);
66 | translationAnim.setInterpolator(new LinearInterpolator());
67 | translationAnim.setRepeatCount(-1);
68 | addUpdateListener(translationAnim,new ValueAnimator.AnimatorUpdateListener() {
69 | @Override
70 | public void onAnimationUpdate(ValueAnimator animation) {
71 | translateX = (float) animation.getAnimatedValue();
72 | postInvalidate();
73 | }
74 | });
75 |
76 | ValueAnimator alphaAnim=ValueAnimator.ofInt(255,122);
77 | alphaAnim.setDuration(650);
78 | alphaAnim.setRepeatCount(-1);
79 | addUpdateListener(alphaAnim,new ValueAnimator.AnimatorUpdateListener() {
80 | @Override
81 | public void onAnimationUpdate(ValueAnimator animation) {
82 | alpha = (int) animation.getAnimatedValue();
83 | postInvalidate();
84 | }
85 | });
86 |
87 | ValueAnimator rotateAnim1=ValueAnimator.ofFloat(0, 45, 0);
88 | rotateAnim1.setDuration(650);
89 | rotateAnim1.setRepeatCount(-1);
90 | addUpdateListener(rotateAnim1,new ValueAnimator.AnimatorUpdateListener() {
91 | @Override
92 | public void onAnimationUpdate(ValueAnimator animation) {
93 | degrees1 = (float) animation.getAnimatedValue();
94 | postInvalidate();
95 | }
96 | });
97 |
98 | ValueAnimator rotateAnim2=ValueAnimator.ofFloat(0,-45,0);
99 | rotateAnim2.setDuration(650);
100 | rotateAnim2.setRepeatCount(-1);
101 | addUpdateListener(rotateAnim2,new ValueAnimator.AnimatorUpdateListener() {
102 | @Override
103 | public void onAnimationUpdate(ValueAnimator animation) {
104 | degrees2 = (float) animation.getAnimatedValue();
105 | postInvalidate();
106 | }
107 | });
108 |
109 | animators.add(translationAnim);
110 | animators.add(alphaAnim);
111 | animators.add(rotateAnim1);
112 | animators.add(rotateAnim2);
113 | return animators;
114 | }
115 | }
116 |
--------------------------------------------------------------------------------
/library/src/main/java/com/wang/avi/indicators/SemiCircleSpinIndicator.java:
--------------------------------------------------------------------------------
1 | package com.wang.avi.indicators;
2 |
3 | import android.animation.ValueAnimator;
4 | import android.graphics.Canvas;
5 | import android.graphics.Paint;
6 | import android.graphics.RectF;
7 |
8 | import com.wang.avi.Indicator;
9 |
10 | import java.util.ArrayList;
11 |
12 | /**
13 | * Created by Jack on 2015/10/20.
14 | */
15 | public class SemiCircleSpinIndicator extends Indicator {
16 |
17 | private float degress;
18 |
19 | @Override
20 | public void draw(Canvas canvas, Paint paint) {
21 | canvas.rotate(degress,centerX(),centerY());
22 | RectF rectF=new RectF(0,0,getWidth(),getHeight());
23 | canvas.drawArc(rectF,-60,120,false,paint);
24 | }
25 |
26 | @Override
27 | public ArrayList onCreateAnimators() {
28 | ArrayList animators=new ArrayList<>();
29 | ValueAnimator rotateAnim=ValueAnimator.ofFloat(0,180,360);
30 | addUpdateListener(rotateAnim,new ValueAnimator.AnimatorUpdateListener() {
31 | @Override
32 | public void onAnimationUpdate(ValueAnimator animation) {
33 | degress= (float) animation.getAnimatedValue();
34 | postInvalidate();
35 | }
36 | });
37 | rotateAnim.setDuration(600);
38 | rotateAnim.setRepeatCount(-1);
39 | animators.add(rotateAnim);
40 | return animators;
41 | }
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/library/src/main/java/com/wang/avi/indicators/SquareSpinIndicator.java:
--------------------------------------------------------------------------------
1 | package com.wang.avi.indicators;
2 |
3 | import android.animation.ValueAnimator;
4 | import android.graphics.Camera;
5 | import android.graphics.Canvas;
6 | import android.graphics.Matrix;
7 | import android.graphics.Paint;
8 | import android.graphics.RectF;
9 | import android.view.animation.LinearInterpolator;
10 |
11 | import com.wang.avi.Indicator;
12 |
13 | import java.util.ArrayList;
14 |
15 | /**
16 | * Created by Jack on 2015/10/16.
17 | */
18 | public class SquareSpinIndicator extends Indicator {
19 |
20 | private float rotateX;
21 | private float rotateY;
22 |
23 | private Camera mCamera;
24 | private Matrix mMatrix;
25 |
26 | public SquareSpinIndicator(){
27 | mCamera=new Camera();
28 | mMatrix=new Matrix();
29 | }
30 |
31 | @Override
32 | public void draw(Canvas canvas, Paint paint) {
33 |
34 | mMatrix.reset();
35 | mCamera.save();
36 | mCamera.rotateX(rotateX);
37 | mCamera.rotateY(rotateY);
38 | mCamera.getMatrix(mMatrix);
39 | mCamera.restore();
40 |
41 | mMatrix.preTranslate(-centerX(), -centerY());
42 | mMatrix.postTranslate(centerX(), centerY());
43 | canvas.concat(mMatrix);
44 |
45 | canvas.drawRect(new RectF(getWidth()/5,getHeight()/5,getWidth()*4/5,getHeight()*4/5),paint);
46 | }
47 |
48 | @Override
49 | public ArrayList onCreateAnimators() {
50 | ArrayList animators=new ArrayList<>();
51 | ValueAnimator animator=ValueAnimator.ofFloat(0,180,180,0,0);
52 | addUpdateListener(animator,new ValueAnimator.AnimatorUpdateListener() {
53 | @Override
54 | public void onAnimationUpdate(ValueAnimator animation) {
55 | rotateX= (float) animation.getAnimatedValue();
56 | postInvalidate();
57 | }
58 | });
59 | animator.setInterpolator(new LinearInterpolator());
60 | animator.setRepeatCount(-1);
61 | animator.setDuration(2500);
62 |
63 | ValueAnimator animator1=ValueAnimator.ofFloat(0,0,180,180,0);
64 | addUpdateListener(animator1,new ValueAnimator.AnimatorUpdateListener() {
65 | @Override
66 | public void onAnimationUpdate(ValueAnimator animation) {
67 | rotateY= (float) animation.getAnimatedValue();
68 | postInvalidate();
69 | }
70 | });
71 | animator1.setInterpolator(new LinearInterpolator());
72 | animator1.setRepeatCount(-1);
73 | animator1.setDuration(2500);
74 |
75 | animators.add(animator);
76 | animators.add(animator1);
77 | return animators;
78 | }
79 |
80 | }
81 |
--------------------------------------------------------------------------------
/library/src/main/java/com/wang/avi/indicators/TriangleSkewSpinIndicator.java:
--------------------------------------------------------------------------------
1 | package com.wang.avi.indicators;
2 |
3 | import android.animation.ValueAnimator;
4 | import android.graphics.Camera;
5 | import android.graphics.Canvas;
6 | import android.graphics.Matrix;
7 | import android.graphics.Paint;
8 | import android.graphics.Path;
9 | import android.view.animation.LinearInterpolator;
10 |
11 | import com.wang.avi.Indicator;
12 |
13 | import java.util.ArrayList;
14 |
15 | /**
16 | * Created by Jack on 2015/10/20.
17 | */
18 | public class TriangleSkewSpinIndicator extends Indicator {
19 |
20 | private float rotateX;
21 | private float rotateY;
22 |
23 | private Camera mCamera;
24 | private Matrix mMatrix;
25 |
26 | public TriangleSkewSpinIndicator(){
27 | mCamera=new Camera();
28 | mMatrix=new Matrix();
29 | }
30 |
31 | @Override
32 | public void draw(Canvas canvas, Paint paint) {
33 |
34 |
35 | mMatrix.reset();
36 | mCamera.save();
37 | mCamera.rotateX(rotateX);
38 | mCamera.rotateY(rotateY);
39 | mCamera.getMatrix(mMatrix);
40 | mCamera.restore();
41 |
42 | mMatrix.preTranslate(-centerX(), -centerY());
43 | mMatrix.postTranslate(centerX(), centerY());
44 | canvas.concat(mMatrix);
45 |
46 | Path path=new Path();
47 | path.moveTo(getWidth()/5,getHeight()*4/5);
48 | path.lineTo(getWidth()*4/5, getHeight()*4/5);
49 | path.lineTo(getWidth()/2,getHeight()/5);
50 | path.close();
51 | canvas.drawPath(path, paint);
52 | }
53 |
54 | @Override
55 | public ArrayList onCreateAnimators() {
56 | ArrayList animators=new ArrayList<>();
57 | ValueAnimator animator=ValueAnimator.ofFloat(0,180,180,0,0);
58 | addUpdateListener(animator,new ValueAnimator.AnimatorUpdateListener() {
59 | @Override
60 | public void onAnimationUpdate(ValueAnimator animation) {
61 | rotateX= (float) animation.getAnimatedValue();
62 | postInvalidate();
63 | }
64 | });
65 | animator.setInterpolator(new LinearInterpolator());
66 | animator.setRepeatCount(-1);
67 | animator.setDuration(2500);
68 |
69 | ValueAnimator animator1=ValueAnimator.ofFloat(0,0,180,180,0);
70 | addUpdateListener(animator1,new ValueAnimator.AnimatorUpdateListener() {
71 | @Override
72 | public void onAnimationUpdate(ValueAnimator animation) {
73 | rotateY= (float) animation.getAnimatedValue();
74 | postInvalidate();
75 | }
76 | });
77 | animator1.setInterpolator(new LinearInterpolator());
78 | animator1.setRepeatCount(-1);
79 | animator1.setDuration(2500);
80 |
81 | animators.add(animator);
82 | animators.add(animator1);
83 | return animators;
84 | }
85 |
86 | }
87 |
--------------------------------------------------------------------------------
/library/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/library/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Library
3 |
4 |
--------------------------------------------------------------------------------
/library/src/main/res/values/style.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
10 |
11 |
18 |
19 |
26 |
27 |
--------------------------------------------------------------------------------
/screenshots/avi.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HarlonWang/AVLoadingIndicatorView/841f98d230b14f0617e541a8b421f8dd96acd030/screenshots/avi.gif
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':library'
2 |
--------------------------------------------------------------------------------