├── app ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── values │ │ │ │ ├── strings.xml │ │ │ │ ├── colors.xml │ │ │ │ └── styles.xml │ │ │ ├── mipmap-hdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-mdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-anydpi-v26 │ │ │ │ ├── ic_launcher.xml │ │ │ │ └── ic_launcher_round.xml │ │ │ ├── drawable-v24 │ │ │ │ └── ic_launcher_foreground.xml │ │ │ ├── drawable │ │ │ │ └── ic_launcher_background.xml │ │ │ └── layout │ │ │ │ └── activity_main.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── example │ │ │ │ └── mzy │ │ │ │ └── loadinganimations │ │ │ │ └── MainActivity.java │ │ └── AndroidManifest.xml │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ └── mzy │ │ │ └── loadinganimations │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── example │ │ └── mzy │ │ └── loadinganimations │ │ └── ExampleInstrumentedTest.java ├── proguard-rules.pro └── build.gradle ├── library ├── .gitignore ├── src │ └── main │ │ ├── res │ │ └── values │ │ │ ├── strings.xml │ │ │ ├── styles.xml │ │ │ └── attrs.xml │ │ ├── AndroidManifest.xml │ │ └── java │ │ └── com │ │ └── example │ │ └── mzy │ │ └── indicators │ │ ├── Star │ │ ├── VertexF.java │ │ ├── StarIndicator.java │ │ └── StarModel.java │ │ ├── Circle │ │ ├── CircleWaveIndicator.java │ │ ├── CircleScaleIndicator.java │ │ ├── ArcRotateIndicator.java │ │ ├── CircleRotateIndicator.java │ │ ├── BasketBallIndicator.java │ │ ├── CircleJumpIndicator.java │ │ ├── ArcRotateScaleIndicator.java │ │ ├── DropIndicator.java │ │ ├── CircleRotateScaleIndicator.java │ │ ├── CircleTriangleIndicator.java │ │ ├── CircleCollisionIndicator.java │ │ └── TrackIndicator.java │ │ ├── Rect │ │ ├── ChartRectIndicator1.java │ │ ├── ParallelogramIndicator.java │ │ ├── ChartRectIndicator2.java │ │ └── RectJumpMoveIndicator.java │ │ ├── IndicatorDrawable.java │ │ └── LoadingIndicator.java ├── build.gradle └── proguard-rules.pro ├── settings.gradle ├── screenshots └── preview.gif ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .gitignore ├── gradle.properties ├── README.md ├── gradlew.bat └── gradlew /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /library/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':library' 2 | -------------------------------------------------------------------------------- /screenshots/preview.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ma-zhengyang/LoadingAnimations/HEAD/screenshots/preview.gif -------------------------------------------------------------------------------- /library/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | library 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | LoadingAnimations 3 | 4 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ma-zhengyang/LoadingAnimations/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ma-zhengyang/LoadingAnimations/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ma-zhengyang/LoadingAnimations/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ma-zhengyang/LoadingAnimations/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ma-zhengyang/LoadingAnimations/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ma-zhengyang/LoadingAnimations/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ma-zhengyang/LoadingAnimations/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ma-zhengyang/LoadingAnimations/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ma-zhengyang/LoadingAnimations/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ma-zhengyang/LoadingAnimations/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ma-zhengyang/LoadingAnimations/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sun Aug 26 20:45:22 CST 2018 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-4.1-all.zip 7 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /library/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 9 | 10 | -------------------------------------------------------------------------------- /library/src/main/java/com/example/mzy/indicators/Star/VertexF.java: -------------------------------------------------------------------------------- 1 | package com.example.mzy.indicators.Star; 2 | 3 | class VertexF { 4 | public VertexF() { 5 | } 6 | 7 | public VertexF(float x, float y) { 8 | this.x = x; 9 | this.y = y; 10 | } 11 | 12 | public float x; 13 | public float y; 14 | 15 | public VertexF next; 16 | } 17 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /library/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/mzy/loadinganimations/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.mzy.loadinganimations; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.app.AppCompatActivity; 5 | 6 | public class MainActivity extends AppCompatActivity { 7 | 8 | private final String TAG = MainActivity.class.getSimpleName(); 9 | 10 | @Override 11 | protected void onCreate(Bundle savedInstanceState) { 12 | super.onCreate(savedInstanceState); 13 | setContentView(R.layout.activity_main); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /app/src/test/java/com/example/mzy/loadinganimations/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.example.mzy.loadinganimations; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /library/src/main/res/values/attrs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /library/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'com.novoda.bintray-release' 3 | 4 | android { 5 | compileSdkVersion 27 6 | defaultConfig { 7 | minSdkVersion 15 8 | targetSdkVersion 27 9 | versionCode 1 10 | versionName "1.0" 11 | } 12 | lintOptions { 13 | abortOnError false 14 | } 15 | buildToolsVersion '27.0.1' 16 | } 17 | 18 | dependencies { 19 | implementation fileTree(include: ['*.jar'], dir: 'libs') 20 | } 21 | 22 | publish { 23 | userOrg = 'mazhengyang' 24 | groupId = 'com.example.mzy.indicators' 25 | artifactId = 'LoadingAnimations' 26 | publishVersion = '1.0.3' 27 | desc = 'a nice view of loading animation' 28 | website = 'https://github.com/Ma-zhengyang/LoadingAnimations' 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 | org.gradle.jvmargs=-Xmx1024m 13 | 14 | # When configured, Gradle will run in incubating parallel mode. 15 | # This option should only be used with decoupled projects. More details, visit 16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 17 | # org.gradle.parallel=true 18 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /library/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/example/mzy/loadinganimations/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.example.mzy.loadinganimations; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.example.mzy.loadinganimations", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 27 5 | defaultConfig { 6 | applicationId "com.example.mzy.loadinganimations" 7 | minSdkVersion 15 8 | targetSdkVersion 27 9 | versionCode 1 10 | versionName "1.0" 11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 17 | } 18 | } 19 | buildToolsVersion '27.0.1' 20 | } 21 | 22 | dependencies { 23 | configurations.all { 24 | resolutionStrategy.force 'com.android.support:support-annotations:27.0.1' 25 | } 26 | implementation fileTree(include: ['*.jar'], dir: 'libs') 27 | implementation 'com.android.support:appcompat-v7:27.0.1' 28 | testImplementation 'junit:junit:4.12' 29 | androidTestImplementation 'com.android.support.test:runner:1.0.2' 30 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 31 | //recyclerview 32 | implementation 'com.android.support:recyclerview-v7:27.0.1' 33 | implementation 'com.android.support:design:27.0.1' 34 | compile project(path: ':library') 35 | } 36 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # LoadingAnimations 2 | 3 | ## Demo 4 | 5 | ![Screenshot](screenshots/preview.gif) 6 | 7 | ## Usage 8 | 9 | ### Step 1 10 | 11 | Add dependencies in build.gradle. 12 | 13 | ```gradle 14 | compile 'com.example.mzy.indicators:LoadingAnimations:1.0.3' 15 | ``` 16 | 17 | 18 | ### Step 2 19 | 20 | Add the LoadingAnimations to your layout: 21 | 22 | e.g. 23 | 24 | ```xml 25 | 29 | ``` 30 | 31 | ```attribute 32 | 33 | indicatorColor: indicator color, default is white. 34 | indicatorSpeed: animation duration, must be a number greater than zero. 35 | indicatorName: indicator name, refer to the **Indicators** below. 36 | 37 | ``` 38 | 39 | ## Indicators 40 | 41 | As seen above in the **Demo**, the indicators are as follows: 42 | 43 | **Row 1** 44 | * `BasketBallIndicator` 45 | * `StarIndicator` 46 | * `CircleScaleIndicator` 47 | * `CircleWaveIndicator` 48 | 49 | **Row 2** 50 | * `CircleJumpIndicator` 51 | * `CircleCollisionIndicator` 52 | * `DropIndicator` 53 | * `TrackIndicator` 54 | 55 | **Row 3** 56 | * `CircleRotateScaleIndicator` 57 | * `CircleTriangleIndicator` 58 | * `ChartRectIndicator1` 59 | * `ChartRectIndicator2` 60 | 61 | **Row4** 62 | * `ParallelogramIndicator` 63 | * `RectJumpMoveIndicator` 64 | * `ArcRotateIndicator` 65 | * `ArcRotateScaleIndicator` 66 | 67 | **Row5** 68 | * `CircleRotateIndicator` 69 | 70 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /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/src/main/java/com/example/mzy/indicators/Circle/CircleWaveIndicator.java: -------------------------------------------------------------------------------- 1 | package com.example.mzy.indicators.Circle; 2 | 3 | import android.animation.Animator; 4 | import android.animation.ValueAnimator; 5 | import android.content.Context; 6 | import android.graphics.Canvas; 7 | import android.graphics.Paint; 8 | import android.util.Log; 9 | 10 | import com.example.mzy.indicators.IndicatorDrawable; 11 | 12 | import java.util.ArrayList; 13 | 14 | /** 15 | * Created by mazhengyang on 18-10-24. 16 | */ 17 | 18 | public class CircleWaveIndicator extends IndicatorDrawable { 19 | 20 | private final String TAG = CircleWaveIndicator.class.getSimpleName(); 21 | 22 | private final int mCount = 3; 23 | private float space;//相邻两圆间距 24 | private float radius;//圆的半径 25 | private float leftPadding; 26 | 27 | private float[] mAnimatedValue = new float[]{ 28 | 0.0f, 0.0f, 0.0f 29 | }; 30 | 31 | public CircleWaveIndicator(Context context, int indicatorColor, int indicatorSpeed) { 32 | Log.d(TAG, "CircleWaveIndicator: "); 33 | this.indicatorColor = indicatorColor; 34 | this.indicatorSpeed = indicatorSpeed; 35 | if (indicatorSpeed <= 0) { 36 | this.indicatorSpeed = 1000; 37 | } 38 | 39 | init(context); 40 | } 41 | 42 | @Override 43 | protected void init(Context context) { 44 | Log.d(TAG, "init: "); 45 | mPaint.setAntiAlias(true); 46 | mPaint.setStyle(Paint.Style.FILL); 47 | mPaint.setStrokeWidth(dip2px(context, 1.0f)); 48 | mPaint.setColor(indicatorColor); 49 | 50 | space = dip2px(context, 2.0f); 51 | } 52 | 53 | @Override 54 | protected ArrayList getAnimation() { 55 | int[] delay = new int[]{100, 200, 300}; 56 | 57 | ArrayList list = new ArrayList<>(); 58 | 59 | for (int i = 0; i < mCount; i++) { 60 | final int index = i; 61 | ValueAnimator valueAnimator = ValueAnimator.ofFloat(0.0f, 1.0f, 0.0f); 62 | valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 63 | @Override 64 | public void onAnimationUpdate(ValueAnimator valueAnimator) { 65 | mAnimatedValue[index] = ((float) valueAnimator.getAnimatedValue()); 66 | invalidateSelf(); 67 | } 68 | }); 69 | 70 | valueAnimator.setRepeatCount(ValueAnimator.INFINITE); 71 | valueAnimator.setDuration(indicatorSpeed); 72 | valueAnimator.setStartDelay(delay[i]); 73 | list.add(valueAnimator); 74 | } 75 | 76 | return list; 77 | } 78 | 79 | @Override 80 | protected void draw(Canvas canvas, Paint paint) { 81 | if (leftPadding == 0) { 82 | radius = getWidth() / 25; 83 | leftPadding = (getWidth() - (radius * 2) * mCount + space * (mCount - 1)) / 2; 84 | } 85 | 86 | for (int i = 0; i < mCount; i++) { 87 | float x = leftPadding + radius * ((i + 1) * 2 - 1) + space * i; 88 | float y = getHeight() / 2 - getHeight() / 4 * mAnimatedValue[i]; 89 | canvas.drawCircle(x, y, radius, paint); 90 | } 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /library/src/main/java/com/example/mzy/indicators/Rect/ChartRectIndicator1.java: -------------------------------------------------------------------------------- 1 | package com.example.mzy.indicators.Rect; 2 | 3 | import android.animation.Animator; 4 | import android.animation.ValueAnimator; 5 | import android.content.Context; 6 | import android.graphics.Canvas; 7 | import android.graphics.Paint; 8 | import android.graphics.RectF; 9 | import android.util.Log; 10 | 11 | import com.example.mzy.indicators.IndicatorDrawable; 12 | 13 | import java.util.ArrayList; 14 | 15 | /** 16 | * Created by mzy on 2018/9/19. 17 | */ 18 | 19 | public class ChartRectIndicator1 extends IndicatorDrawable { 20 | 21 | private final String TAG = ChartRectIndicator1.class.getSimpleName(); 22 | 23 | private final int mCount = 5; 24 | 25 | private float[] mAnimatedValue = new float[]{ 26 | 1.0f, 1.0f, 1.0f, 1.0f, 1.0f 27 | }; 28 | private RectF rectF = new RectF(); 29 | 30 | public ChartRectIndicator1(Context context, int indicatorColor, int indicatorSpeed) { 31 | Log.d(TAG, "ChartRectIndicator1: "); 32 | this.indicatorColor = indicatorColor; 33 | this.indicatorSpeed = indicatorSpeed; 34 | if (indicatorSpeed <= 0) { 35 | this.indicatorSpeed = 1000; 36 | } 37 | 38 | init(context); 39 | } 40 | 41 | @Override 42 | protected void init(Context context) { 43 | Log.d(TAG, "init: "); 44 | mPaint.setAntiAlias(true); 45 | mPaint.setStyle(Paint.Style.FILL); 46 | mPaint.setStrokeWidth(dip2px(context, 1.0f)); 47 | mPaint.setColor(indicatorColor); 48 | } 49 | 50 | @Override 51 | protected ArrayList getAnimation() { 52 | 53 | int[] delay = new int[]{100, 200, 300, 400, 500}; 54 | 55 | ArrayList list = new ArrayList<>(); 56 | 57 | for (int i = 0; i < mCount; i++) { 58 | final int index = i; 59 | ValueAnimator valueAnimator = ValueAnimator.ofFloat(1.0f, 0.5f, 1.0f); 60 | valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 61 | @Override 62 | public void onAnimationUpdate(ValueAnimator valueAnimator) { 63 | mAnimatedValue[index] = ((float) valueAnimator.getAnimatedValue()); 64 | invalidateSelf(); 65 | } 66 | }); 67 | 68 | valueAnimator.setRepeatCount(ValueAnimator.INFINITE); 69 | valueAnimator.setDuration(indicatorSpeed); 70 | valueAnimator.setStartDelay(delay[i]); 71 | list.add(valueAnimator); 72 | } 73 | 74 | return list; 75 | } 76 | 77 | @Override 78 | protected void draw(Canvas canvas, Paint paint) { 79 | 80 | float rectWidth = getWidth() / 25; 81 | float rectSpace = rectWidth; 82 | float startX = (getWidth() - (rectWidth * mCount + rectSpace * (mCount - 1))) / 2; 83 | float bottomY = getHeight() / 1.5f; 84 | float rectMax = getHeight() / 1.5f; 85 | 86 | for (int i = 0; i < mCount; i++) { 87 | canvas.save(); 88 | rectF.setEmpty(); 89 | rectF.set(startX + i * (rectWidth + rectSpace), 90 | rectMax * mAnimatedValue[i], 91 | startX + i * (rectWidth + rectSpace) + rectWidth, 92 | bottomY); 93 | canvas.drawRect(rectF, paint); 94 | canvas.restore(); 95 | } 96 | } 97 | 98 | } 99 | -------------------------------------------------------------------------------- /library/src/main/java/com/example/mzy/indicators/Circle/CircleScaleIndicator.java: -------------------------------------------------------------------------------- 1 | package com.example.mzy.indicators.Circle; 2 | 3 | import android.animation.Animator; 4 | import android.animation.ValueAnimator; 5 | import android.content.Context; 6 | import android.graphics.Canvas; 7 | import android.graphics.Paint; 8 | import android.util.Log; 9 | 10 | import com.example.mzy.indicators.IndicatorDrawable; 11 | 12 | import java.util.ArrayList; 13 | 14 | /** 15 | * Created by mazhengyang on 18-9-4. 16 | */ 17 | 18 | public class CircleScaleIndicator extends IndicatorDrawable { 19 | 20 | private final String TAG = CircleScaleIndicator.class.getSimpleName(); 21 | 22 | private final int mCount = 4; 23 | private float space;//相邻两圆间距 24 | private float radius;//圆的半径 25 | private float leftPadding; 26 | 27 | private float[] mAnimatedValue = new float[]{ 28 | 1.0f, 1.0f, 1.0f, 1.0f 29 | }; 30 | 31 | public CircleScaleIndicator(Context context, int indicatorColor, int indicatorSpeed) { 32 | Log.d(TAG, "CircleScaleIndicator: "); 33 | this.indicatorColor = indicatorColor; 34 | this.indicatorSpeed = indicatorSpeed; 35 | if (indicatorSpeed <= 0) { 36 | this.indicatorSpeed = 1000; 37 | } 38 | 39 | init(context); 40 | } 41 | 42 | @Override 43 | protected void init(Context context) { 44 | Log.d(TAG, "init: "); 45 | mPaint.setAntiAlias(true); 46 | mPaint.setStyle(Paint.Style.FILL); 47 | mPaint.setStrokeWidth(dip2px(context, 1.0f)); 48 | mPaint.setColor(indicatorColor); 49 | 50 | space = dip2px(context, 2.0f); 51 | } 52 | 53 | @Override 54 | protected ArrayList getAnimation() { 55 | 56 | int[] delay = new int[]{100, 200, 300, 400}; 57 | 58 | ArrayList list = new ArrayList<>(); 59 | 60 | for (int i = 0; i < mCount; i++) { 61 | final int index = i; 62 | ValueAnimator valueAnimator = ValueAnimator.ofFloat(1.0f, 0.3f, 1.0f); 63 | valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 64 | @Override 65 | public void onAnimationUpdate(ValueAnimator valueAnimator) { 66 | mAnimatedValue[index] = ((float) valueAnimator.getAnimatedValue()); 67 | invalidateSelf(); 68 | } 69 | }); 70 | 71 | valueAnimator.setRepeatCount(ValueAnimator.INFINITE); 72 | valueAnimator.setDuration(indicatorSpeed); 73 | valueAnimator.setStartDelay(delay[i]); 74 | list.add(valueAnimator); 75 | } 76 | 77 | return list; 78 | } 79 | 80 | @Override 81 | protected void draw(Canvas canvas, Paint paint) { 82 | 83 | if (leftPadding == 0) { 84 | radius = getWidth() / 20; 85 | leftPadding = (getWidth() - (radius * 2) * mCount + space * (mCount - 1)) / 2; 86 | } 87 | 88 | for (int i = 0; i < mCount; i++) { 89 | canvas.save(); 90 | float translateX = leftPadding + radius * ((i + 1) * 2 - 1) + space * i; 91 | canvas.translate(translateX, getHeight() / 2); 92 | canvas.scale(mAnimatedValue[i], mAnimatedValue[i]); 93 | canvas.drawCircle(0, 0, radius, paint); 94 | canvas.restore(); 95 | } 96 | 97 | } 98 | 99 | } 100 | 101 | -------------------------------------------------------------------------------- /library/src/main/java/com/example/mzy/indicators/IndicatorDrawable.java: -------------------------------------------------------------------------------- 1 | package com.example.mzy.indicators; 2 | 3 | import android.animation.Animator; 4 | import android.content.Context; 5 | import android.graphics.Canvas; 6 | import android.graphics.Color; 7 | import android.graphics.ColorFilter; 8 | import android.graphics.Paint; 9 | import android.graphics.PixelFormat; 10 | import android.graphics.Rect; 11 | import android.graphics.drawable.Animatable; 12 | import android.graphics.drawable.Drawable; 13 | import android.util.Log; 14 | 15 | import java.util.ArrayList; 16 | 17 | /** 18 | * Created by mazhengyang on 18-9-18. 19 | */ 20 | 21 | public abstract class IndicatorDrawable extends Drawable implements Animatable { 22 | 23 | private final String TAG = IndicatorDrawable.class.getSimpleName(); 24 | 25 | private ArrayList mAnimatorsList; 26 | private Rect mBounds = new Rect(); 27 | protected Paint mPaint = new Paint(); 28 | protected int indicatorColor = Color.WHITE; 29 | protected int indicatorSpeed = 0; 30 | 31 | protected abstract void init(Context context); 32 | 33 | protected abstract ArrayList getAnimation(); 34 | 35 | protected abstract void draw(Canvas canvas, Paint paint); 36 | 37 | 38 | @Override 39 | public int getAlpha() { 40 | return super.getAlpha(); 41 | } 42 | 43 | @Override 44 | public void setAlpha(int alpha) { 45 | 46 | } 47 | 48 | @Override 49 | public ColorFilter getColorFilter() { 50 | return super.getColorFilter(); 51 | } 52 | 53 | @Override 54 | public void setColorFilter(ColorFilter colorFilter) { 55 | 56 | } 57 | 58 | @Override 59 | public int getOpacity() { 60 | return PixelFormat.OPAQUE; 61 | } 62 | 63 | @Override 64 | protected void onBoundsChange(Rect bounds) { 65 | super.onBoundsChange(bounds); 66 | mBounds.set(bounds); 67 | } 68 | 69 | protected int getWidth() { 70 | return mBounds.width(); 71 | } 72 | 73 | protected int getHeight() { 74 | return mBounds.height(); 75 | } 76 | 77 | 78 | @Override 79 | public void draw(Canvas canvas) { 80 | draw(canvas, mPaint); 81 | } 82 | 83 | @Override 84 | public void start() { 85 | if (mAnimatorsList == null) { 86 | mAnimatorsList = getAnimation(); 87 | } 88 | if (mAnimatorsList != null) { 89 | startAnimation(); 90 | } else { 91 | Log.d(TAG, "start: mAnimatorsList is null."); 92 | } 93 | } 94 | 95 | @Override 96 | public void stop() { 97 | if (mAnimatorsList != null) { 98 | stopAnimation(); 99 | } else { 100 | Log.d(TAG, "stop: mAnimatorsList is null."); 101 | } 102 | } 103 | 104 | @Override 105 | public boolean isRunning() { 106 | return false; 107 | } 108 | 109 | private void startAnimation() { 110 | for (Animator animator : mAnimatorsList) { 111 | if (!animator.isStarted()) { 112 | animator.start(); 113 | } 114 | } 115 | } 116 | 117 | private void stopAnimation() { 118 | for (Animator animator : mAnimatorsList) { 119 | if (animator.isStarted()) { 120 | animator.end(); 121 | } 122 | } 123 | } 124 | 125 | public static float dip2px(Context context, float dpValue) { 126 | final float scale = context.getResources().getDisplayMetrics().density; 127 | return dpValue * scale + 0.5f; 128 | } 129 | 130 | 131 | } 132 | -------------------------------------------------------------------------------- /library/src/main/java/com/example/mzy/indicators/Circle/ArcRotateIndicator.java: -------------------------------------------------------------------------------- 1 | package com.example.mzy.indicators.Circle; 2 | 3 | import android.animation.Animator; 4 | import android.animation.ValueAnimator; 5 | import android.content.Context; 6 | import android.graphics.Canvas; 7 | import android.graphics.Paint; 8 | import android.graphics.RectF; 9 | import android.util.Log; 10 | import android.view.animation.LinearInterpolator; 11 | 12 | import com.example.mzy.indicators.IndicatorDrawable; 13 | 14 | import java.util.ArrayList; 15 | 16 | /** 17 | * Created by mzy on 2018/10/3. 18 | */ 19 | 20 | public class ArcRotateIndicator extends IndicatorDrawable { 21 | 22 | private final String TAG = ArcRotateIndicator.class.getSimpleName(); 23 | 24 | private static final int IN_ANGLE = 90; 25 | private static final int OUT_ANGLE = 270; 26 | 27 | private float inRadius; 28 | private float outRadius; 29 | 30 | private RectF inRectF, outRectF; 31 | 32 | private float mAnimatedValue; 33 | 34 | public ArcRotateIndicator(Context context, int indicatorColor, int indicatorSpeed) { 35 | Log.d(TAG, "ArcRotateIndicator: "); 36 | this.indicatorColor = indicatorColor; 37 | this.indicatorSpeed = indicatorSpeed; 38 | if (indicatorSpeed <= 0) { 39 | this.indicatorSpeed = 2000; 40 | } 41 | 42 | init(context); 43 | } 44 | 45 | @Override 46 | protected void init(Context context) { 47 | Log.d(TAG, "init: "); 48 | mPaint.setAntiAlias(true); 49 | mPaint.setStyle(Paint.Style.STROKE); 50 | mPaint.setStrokeWidth(dip2px(context, 1.0f)); 51 | mPaint.setColor(indicatorColor); 52 | mPaint.setStrokeCap(Paint.Cap.ROUND); 53 | mPaint.setStrokeJoin(Paint.Join.ROUND); 54 | mPaint.setDither(true); 55 | 56 | inRadius = dip2px(context, 5.0f); 57 | outRadius = dip2px(context, 10.0f); 58 | } 59 | 60 | @Override 61 | protected ArrayList getAnimation() { 62 | 63 | ArrayList list = new ArrayList<>(); 64 | 65 | ValueAnimator valueAnimator = ValueAnimator.ofFloat(0.0f, 1.0f); 66 | valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 67 | @Override 68 | public void onAnimationUpdate(ValueAnimator valueAnimator) { 69 | mAnimatedValue = (float) valueAnimator.getAnimatedValue(); 70 | invalidateSelf(); 71 | } 72 | }); 73 | 74 | valueAnimator.setInterpolator(new LinearInterpolator()); 75 | valueAnimator.setRepeatCount(ValueAnimator.INFINITE); 76 | valueAnimator.setDuration(indicatorSpeed); 77 | list.add(valueAnimator); 78 | 79 | return list; 80 | } 81 | 82 | @Override 83 | protected void draw(Canvas canvas, Paint paint) { 84 | 85 | if (inRectF == null || outRectF == null) { 86 | inRectF = new RectF(); 87 | outRectF = new RectF(); 88 | inRectF.set(getWidth() / 2 - inRadius, 89 | getHeight() / 2 - inRadius, 90 | getWidth() / 2 + inRadius, 91 | getHeight() / 2 + inRadius); 92 | outRectF.set(getWidth() / 2 - outRadius, 93 | getHeight() / 2 - outRadius, 94 | getWidth() / 2 + outRadius, 95 | getHeight() / 2 + outRadius); 96 | } 97 | 98 | int rotateAngle = (int) (360 * mAnimatedValue); 99 | 100 | canvas.save(); 101 | 102 | //外圆 103 | canvas.drawArc(inRectF, rotateAngle % 360, IN_ANGLE, false, paint); 104 | //内圆 105 | canvas.drawArc(outRectF, 270 - rotateAngle % 360, OUT_ANGLE, false, paint); 106 | canvas.restore(); 107 | 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /library/src/main/java/com/example/mzy/indicators/Circle/CircleRotateIndicator.java: -------------------------------------------------------------------------------- 1 | package com.example.mzy.indicators.Circle; 2 | 3 | import android.animation.Animator; 4 | import android.animation.ValueAnimator; 5 | import android.content.Context; 6 | import android.graphics.Camera; 7 | import android.graphics.Canvas; 8 | import android.graphics.Matrix; 9 | import android.graphics.Paint; 10 | import android.util.Log; 11 | 12 | import com.example.mzy.indicators.IndicatorDrawable; 13 | 14 | import java.util.ArrayList; 15 | 16 | /** 17 | * Created by mazhengyang on 18-12-14. 18 | */ 19 | 20 | public class CircleRotateIndicator extends IndicatorDrawable { 21 | 22 | private final String TAG = CircleRotateIndicator.class.getSimpleName(); 23 | 24 | private float rotateX = 0.0f; 25 | private float rotateY = 0.0f; 26 | 27 | private Camera mCamera; 28 | private Matrix mMatrix; 29 | 30 | public CircleRotateIndicator(Context context, int indicatorColor, int indicatorSpeed) { 31 | Log.d(TAG, "CircleRotateIndicator: "); 32 | this.indicatorColor = indicatorColor; 33 | this.indicatorSpeed = indicatorSpeed; 34 | if (indicatorSpeed <= 0) { 35 | this.indicatorSpeed = 3000; 36 | } 37 | 38 | init(context); 39 | } 40 | 41 | @Override 42 | protected void init(Context context) { 43 | Log.d(TAG, "init: "); 44 | 45 | mCamera = new Camera(); 46 | mMatrix = new Matrix(); 47 | 48 | mPaint.setAntiAlias(true); 49 | mPaint.setStyle(Paint.Style.STROKE); 50 | mPaint.setStrokeWidth(dip2px(context, 1.0f)); 51 | mPaint.setColor(indicatorColor); 52 | } 53 | 54 | @Override 55 | protected ArrayList getAnimation() { 56 | 57 | ArrayList list = new ArrayList<>(); 58 | 59 | ValueAnimator valueAnimatorX = ValueAnimator.ofFloat(0, 360); 60 | valueAnimatorX.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 61 | @Override 62 | public void onAnimationUpdate(ValueAnimator valueAnimator) { 63 | rotateX = ((float) valueAnimator.getAnimatedValue()); 64 | invalidateSelf(); 65 | } 66 | }); 67 | valueAnimatorX.setRepeatCount(ValueAnimator.INFINITE); 68 | valueAnimatorX.setDuration(indicatorSpeed); 69 | list.add(valueAnimatorX); 70 | 71 | ValueAnimator valueAnimatorY = ValueAnimator.ofFloat(0, 360); 72 | valueAnimatorY.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 73 | @Override 74 | public void onAnimationUpdate(ValueAnimator valueAnimator) { 75 | rotateY = ((float) valueAnimator.getAnimatedValue()); 76 | invalidateSelf(); 77 | } 78 | }); 79 | 80 | valueAnimatorY.setRepeatCount(ValueAnimator.INFINITE); 81 | valueAnimatorY.setDuration(indicatorSpeed / 3); 82 | list.add(valueAnimatorY); 83 | 84 | return list; 85 | } 86 | 87 | @Override 88 | protected void draw(Canvas canvas, Paint paint) { 89 | 90 | mMatrix.reset(); 91 | mCamera.save(); 92 | mCamera.rotateX(rotateX); 93 | mCamera.rotateY(rotateY); 94 | mCamera.getMatrix(mMatrix); 95 | mCamera.restore(); 96 | 97 | float centerX = getWidth() / 2; 98 | float centerY = getHeight() / 2; 99 | //由于缩放/旋转等操作是以(0,0)为中心的,所以为了把界面的中心与(0,0)对齐,就要preTranslate(-centerX, -centerY), 100 | //操作结束后再postTranslate(centerX, centerY)移回来,这样看到的动画就是界面图片以中心点不停的缩放/旋转了 101 | mMatrix.preTranslate(-centerX, -centerY); 102 | mMatrix.postTranslate(centerX, centerY); 103 | canvas.concat(mMatrix); 104 | 105 | float radius = getWidth() / 10; 106 | 107 | canvas.drawCircle(centerX, centerY, radius, paint); 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /library/src/main/java/com/example/mzy/indicators/Circle/BasketBallIndicator.java: -------------------------------------------------------------------------------- 1 | package com.example.mzy.indicators.Circle; 2 | 3 | import android.animation.Animator; 4 | import android.animation.ValueAnimator; 5 | import android.content.Context; 6 | import android.graphics.Canvas; 7 | import android.graphics.Color; 8 | import android.graphics.Paint; 9 | import android.graphics.RectF; 10 | import android.util.Log; 11 | import android.view.animation.AccelerateInterpolator; 12 | 13 | import com.example.mzy.indicators.IndicatorDrawable; 14 | 15 | import java.util.ArrayList; 16 | 17 | /** 18 | * Created by mzy on 2018/8/26. 19 | */ 20 | 21 | public class BasketBallIndicator extends IndicatorDrawable { 22 | 23 | private final String TAG = BasketBallIndicator.class.getSimpleName(); 24 | 25 | private float mAnimatedValue = 0.0f; 26 | 27 | public BasketBallIndicator(Context context, int indicatorColor, int indicatorSpeed) { 28 | Log.d(TAG, "BasketBallIndicator: "); 29 | this.indicatorColor = indicatorColor; 30 | this.indicatorSpeed = indicatorSpeed; 31 | if (indicatorSpeed <= 0) { 32 | this.indicatorSpeed = 500; 33 | } 34 | 35 | init(context); 36 | } 37 | 38 | @Override 39 | protected void init(Context context) { 40 | Log.d(TAG, "init: "); 41 | mPaint.setAntiAlias(true); 42 | mPaint.setStyle(Paint.Style.FILL); 43 | mPaint.setStrokeWidth(dip2px(context, 1.0f)); 44 | mPaint.setColor(indicatorColor); 45 | } 46 | 47 | @Override 48 | protected ArrayList getAnimation() { 49 | 50 | /** 51 | * |___o 52 | * |___o 53 | * | 54 | * | 55 | */ 56 | ArrayList list = new ArrayList<>(); 57 | 58 | ValueAnimator valueAnimator = ValueAnimator.ofFloat(0.25f, 0.5f); 59 | valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 60 | @Override 61 | public void onAnimationUpdate(ValueAnimator valueAnimator) { 62 | mAnimatedValue = ((float) valueAnimator.getAnimatedValue()); 63 | invalidateSelf(); 64 | } 65 | }); 66 | 67 | valueAnimator.setInterpolator(new AccelerateInterpolator()); 68 | valueAnimator.setRepeatMode(ValueAnimator.REVERSE); 69 | valueAnimator.setRepeatCount(ValueAnimator.INFINITE); 70 | valueAnimator.setDuration(indicatorSpeed); 71 | list.add(valueAnimator); 72 | 73 | return list; 74 | } 75 | 76 | @Override 77 | protected void draw(Canvas canvas, Paint paint) { 78 | canvas.save(); 79 | drawBall(canvas, paint); 80 | drawInverted(canvas, paint); 81 | canvas.restore(); 82 | } 83 | 84 | private void drawBall(Canvas canvas, Paint paint) { 85 | paint.setColor(indicatorColor); 86 | 87 | float x = getWidth() / 2; 88 | float move_y = getHeight() * mAnimatedValue; 89 | float radius = getWidth() / 20; 90 | 91 | if (mAnimatedValue < 0.4f) { 92 | canvas.drawCircle(x, move_y, radius, paint); 93 | } else { 94 | RectF rectF = new RectF(x - radius, move_y - radius, 95 | x + radius, move_y + radius - 2); 96 | canvas.drawOval(rectF, paint); 97 | } 98 | } 99 | 100 | private void drawInverted(Canvas canvas, Paint paint) { 101 | 102 | float x = getWidth() / 2; 103 | 104 | float ratio = (float) ((mAnimatedValue - 0.25) / 0.25); 105 | 106 | if (ratio < 0.3) { 107 | return; 108 | } 109 | 110 | float radius = getWidth() / 10; 111 | 112 | float cut = radius * ratio * 0.6f; 113 | 114 | paint.setColor(Color.GRAY); 115 | RectF rectF = new RectF(x - cut, 116 | getHeight() / 2 + radius * 0.5f, 117 | x + cut, 118 | getHeight() / 2 + radius * 0.7f); 119 | canvas.drawOval(rectF, paint); 120 | } 121 | 122 | } 123 | -------------------------------------------------------------------------------- /library/src/main/java/com/example/mzy/indicators/Circle/CircleJumpIndicator.java: -------------------------------------------------------------------------------- 1 | package com.example.mzy.indicators.Circle; 2 | 3 | import android.animation.Animator; 4 | import android.animation.ValueAnimator; 5 | import android.content.Context; 6 | import android.graphics.Canvas; 7 | import android.graphics.Paint; 8 | import android.util.Log; 9 | import android.view.animation.LinearInterpolator; 10 | 11 | import com.example.mzy.indicators.IndicatorDrawable; 12 | 13 | import java.util.ArrayList; 14 | 15 | /** 16 | * Created by mazhengyang on 18-10-24. 17 | */ 18 | 19 | public class CircleJumpIndicator extends IndicatorDrawable { 20 | 21 | private final String TAG = CircleJumpIndicator.class.getSimpleName(); 22 | 23 | private final int mCount = 3; 24 | private float space;//相邻两圆间距 25 | private float radius;//圆的半径 26 | private float leftPadding; 27 | 28 | private float[] mAnimatedValue = new float[]{ 29 | 0.0f, 0.0f, 0.0f 30 | }; 31 | 32 | public CircleJumpIndicator(Context context, int indicatorColor, int indicatorSpeed) { 33 | Log.d(TAG, "CircleJumpIndicator: "); 34 | this.indicatorColor = indicatorColor; 35 | this.indicatorSpeed = indicatorSpeed; 36 | if (indicatorSpeed <= 0) { 37 | this.indicatorSpeed = 2000; 38 | } 39 | 40 | init(context); 41 | } 42 | 43 | @Override 44 | protected void init(Context context) { 45 | Log.d(TAG, "init: "); 46 | mPaint.setAntiAlias(true); 47 | mPaint.setStyle(Paint.Style.FILL); 48 | mPaint.setStrokeWidth(dip2px(context, 1.0f)); 49 | mPaint.setColor(indicatorColor); 50 | 51 | space = dip2px(context, 2.0f); 52 | } 53 | 54 | @Override 55 | protected ArrayList getAnimation() { 56 | int[] delay = new int[]{100, 400, 800}; 57 | 58 | ArrayList list = new ArrayList<>(); 59 | 60 | for (int i = 0; i < mCount; i++) { 61 | final int index = i; 62 | ValueAnimator valueAnimator = ValueAnimator.ofFloat(0.0f, 1.0f, 0.0f, -1.0f, 0.0f); 63 | valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 64 | @Override 65 | public void onAnimationUpdate(ValueAnimator valueAnimator) { 66 | mAnimatedValue[index] = ((float) valueAnimator.getAnimatedValue()); 67 | if (mAnimatedValue[index] <= 0) { 68 | mAnimatedValue[index] = 0; 69 | } 70 | invalidateSelf(); 71 | } 72 | }); 73 | 74 | valueAnimator.setInterpolator(new LinearInterpolator()); 75 | valueAnimator.setRepeatCount(ValueAnimator.INFINITE); 76 | valueAnimator.setDuration(indicatorSpeed); 77 | valueAnimator.setStartDelay(delay[i]); 78 | list.add(valueAnimator); 79 | } 80 | 81 | //监听最后一个对象结束,重新播放动画 82 | // list.get(mCount - 1).addListener(new Animator.AnimatorListener() { 83 | // @Override 84 | // public void onAnimationStart(Animator animation) { 85 | // 86 | // } 87 | // 88 | // @Override 89 | // public void onAnimationEnd(Animator animation) { 90 | // Log.d(TAG, "onAnimationEnd: "); 91 | // stop(); 92 | // start(); 93 | // } 94 | // 95 | // @Override 96 | // public void onAnimationCancel(Animator animation) { 97 | // 98 | // } 99 | // 100 | // @Override 101 | // public void onAnimationRepeat(Animator animation) { 102 | // 103 | // } 104 | // }); 105 | 106 | return list; 107 | } 108 | 109 | @Override 110 | protected void draw(Canvas canvas, Paint paint) { 111 | if (leftPadding == 0) { 112 | radius = getWidth() / 25; 113 | leftPadding = (getWidth() - (radius * 2) * mCount + space * (mCount - 1)) / 2; 114 | } 115 | 116 | for (int i = 0; i < mCount; i++) { 117 | float x = leftPadding + radius * ((i + 1) * 2 - 1) + space * i; 118 | float y = getHeight() / 2 - getHeight() / 4 * mAnimatedValue[i]; 119 | canvas.drawCircle(x, y, radius, paint); 120 | } 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /library/src/main/java/com/example/mzy/indicators/Circle/ArcRotateScaleIndicator.java: -------------------------------------------------------------------------------- 1 | package com.example.mzy.indicators.Circle; 2 | 3 | import android.animation.Animator; 4 | import android.animation.ValueAnimator; 5 | import android.content.Context; 6 | import android.graphics.Canvas; 7 | import android.graphics.Paint; 8 | import android.graphics.RectF; 9 | import android.util.Log; 10 | import android.view.animation.AccelerateInterpolator; 11 | import android.view.animation.LinearInterpolator; 12 | 13 | import com.example.mzy.indicators.IndicatorDrawable; 14 | 15 | import java.util.ArrayList; 16 | 17 | /** 18 | * Created by mazhengyang on 18-10-9. 19 | */ 20 | 21 | public class ArcRotateScaleIndicator extends IndicatorDrawable { 22 | private final String TAG = ArcRotateScaleIndicator.class.getSimpleName(); 23 | 24 | private float radius; 25 | 26 | private RectF mRectF; 27 | 28 | private float mScaleValue; 29 | private float mRotateValue; 30 | 31 | public ArcRotateScaleIndicator(Context context, int indicatorColor, int indicatorSpeed) { 32 | Log.d(TAG, "ArcRotateScaleIndicator: "); 33 | this.indicatorColor = indicatorColor; 34 | this.indicatorSpeed = indicatorSpeed; 35 | if (indicatorSpeed <= 0) { 36 | this.indicatorSpeed = 2000; 37 | } 38 | 39 | init(context); 40 | } 41 | 42 | @Override 43 | protected void init(Context context) { 44 | Log.d(TAG, "init: "); 45 | mPaint.setAntiAlias(true); 46 | mPaint.setStyle(Paint.Style.STROKE); 47 | mPaint.setStrokeWidth(dip2px(context, 1.0f)); 48 | mPaint.setColor(indicatorColor); 49 | mPaint.setStrokeCap(Paint.Cap.ROUND); 50 | mPaint.setStrokeJoin(Paint.Join.ROUND); 51 | mPaint.setDither(true); 52 | 53 | radius = dip2px(context, 10.0f); 54 | } 55 | 56 | @Override 57 | protected ArrayList getAnimation() { 58 | 59 | ArrayList list = new ArrayList<>(); 60 | 61 | ValueAnimator scaleAnimator = ValueAnimator.ofFloat(1.0f, 0.5f, 1.0f); 62 | scaleAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 63 | @Override 64 | public void onAnimationUpdate(ValueAnimator valueAnimator) { 65 | mScaleValue = (float) valueAnimator.getAnimatedValue(); 66 | invalidateSelf(); 67 | } 68 | }); 69 | 70 | scaleAnimator.setInterpolator(new LinearInterpolator()); 71 | scaleAnimator.setRepeatCount(ValueAnimator.INFINITE); 72 | scaleAnimator.setDuration(indicatorSpeed); 73 | 74 | ValueAnimator rotateAnimator = ValueAnimator.ofFloat(0, 180, 360); 75 | rotateAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 76 | @Override 77 | public void onAnimationUpdate(ValueAnimator valueAnimator) { 78 | mRotateValue = (float) valueAnimator.getAnimatedValue(); 79 | invalidateSelf(); 80 | } 81 | }); 82 | 83 | rotateAnimator.setInterpolator(new AccelerateInterpolator()); 84 | rotateAnimator.setRepeatCount(ValueAnimator.INFINITE); 85 | rotateAnimator.setDuration(indicatorSpeed / 2); 86 | 87 | list.add(scaleAnimator); 88 | list.add(rotateAnimator); 89 | 90 | return list; 91 | } 92 | 93 | @Override 94 | protected void draw(Canvas canvas, Paint paint) { 95 | 96 | if (mRectF == null) { 97 | mRectF = new RectF(); 98 | mRectF.set(-radius, -radius, radius, radius); 99 | } 100 | 101 | canvas.save(); 102 | 103 | float x = getWidth() / 2; 104 | float y = getHeight() / 2; 105 | canvas.translate(x, y); 106 | canvas.scale(mScaleValue, mScaleValue); 107 | canvas.rotate(mRotateValue); 108 | 109 | // paint.setColor(Color.RED); 110 | // canvas.drawOval(mRectF,paint); 111 | 112 | /** 113 | * 360 114 | * | 115 | * 225 | 116 | * 270 ----------- 0 117 | * | 45 118 | * | 119 | * 90 120 | */ 121 | paint.setStyle(Paint.Style.STROKE); 122 | canvas.drawArc(mRectF, 225, 90, false, paint); 123 | canvas.drawArc(mRectF, 45, 90, false, paint); 124 | 125 | canvas.restore(); 126 | 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /library/src/main/java/com/example/mzy/indicators/Circle/DropIndicator.java: -------------------------------------------------------------------------------- 1 | package com.example.mzy.indicators.Circle; 2 | 3 | import android.animation.Animator; 4 | import android.animation.ValueAnimator; 5 | import android.content.Context; 6 | import android.graphics.Canvas; 7 | import android.graphics.Color; 8 | import android.graphics.Paint; 9 | import android.graphics.RectF; 10 | import android.util.Log; 11 | import android.view.animation.LinearInterpolator; 12 | 13 | import com.example.mzy.indicators.IndicatorDrawable; 14 | 15 | import java.util.ArrayList; 16 | 17 | /** 18 | * Created by mazhengyang on 18-9-25. 19 | */ 20 | 21 | public class DropIndicator extends IndicatorDrawable { 22 | 23 | private final String TAG = DropIndicator.class.getSimpleName(); 24 | 25 | private float mAnimatedValue; 26 | 27 | private RectF mRectF = new RectF(); 28 | 29 | private boolean drawAssist = false; 30 | 31 | public DropIndicator(Context context, int indicatorColor, int indicatorSpeed) { 32 | Log.d(TAG, "DropIndicator: "); 33 | this.indicatorColor = indicatorColor; 34 | this.indicatorSpeed = indicatorSpeed; 35 | if (indicatorSpeed <= 0) { 36 | this.indicatorSpeed = 1500; 37 | } 38 | 39 | init(context); 40 | } 41 | 42 | @Override 43 | protected void init(Context context) { 44 | Log.d(TAG, "init: "); 45 | mPaint.setAntiAlias(true); 46 | mPaint.setStyle(Paint.Style.FILL); 47 | mPaint.setStrokeWidth(dip2px(context, 1.0f)); 48 | mPaint.setColor(indicatorColor); 49 | } 50 | 51 | @Override 52 | protected ArrayList getAnimation() { 53 | 54 | ArrayList list = new ArrayList<>(); 55 | 56 | ValueAnimator valueAnimator = ValueAnimator.ofFloat(0.0f, 1.0f); 57 | valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 58 | @Override 59 | public void onAnimationUpdate(ValueAnimator valueAnimator) { 60 | mAnimatedValue = (float) valueAnimator.getAnimatedValue(); 61 | invalidateSelf(); 62 | } 63 | }); 64 | 65 | valueAnimator.setInterpolator(new LinearInterpolator()); 66 | valueAnimator.setRepeatCount(ValueAnimator.INFINITE); 67 | valueAnimator.setDuration(indicatorSpeed); 68 | list.add(valueAnimator); 69 | 70 | return list; 71 | } 72 | 73 | @Override 74 | protected void draw(Canvas canvas, Paint paint) { 75 | drawAssist(canvas, paint); 76 | drawBall(canvas, paint); 77 | } 78 | 79 | private void drawAssist(Canvas canvas, Paint paint) { 80 | 81 | if (drawAssist) { 82 | canvas.drawColor(Color.RED); 83 | 84 | float maxMove = getWidth() / 2; 85 | 86 | float x = (getWidth() - maxMove) / 2; 87 | 88 | canvas.drawLine(x, 0, x, getHeight(), paint); 89 | canvas.drawLine(x + maxMove / 2, 0, x + maxMove / 2, getHeight(), paint); 90 | canvas.drawLine(x + maxMove, 0, x + maxMove, getHeight(), paint); 91 | } 92 | 93 | } 94 | 95 | private void drawBall(Canvas canvas, Paint paint) { 96 | 97 | float maxMove = getWidth() / 2; 98 | 99 | float radius = getWidth() / 25; 100 | 101 | float x = (getWidth() - maxMove) / 2; 102 | float y = getHeight() / 2; 103 | 104 | float percent = 0.0f; 105 | if (mAnimatedValue <= 0.5) { // 0~0.5,从左到右 106 | percent = mAnimatedValue; 107 | } else if (mAnimatedValue <= 1.0f) { // 0.5~1.0,从右到左 108 | percent = 1.0f - mAnimatedValue; 109 | } 110 | 111 | float extra_percent = 0.0f; 112 | if (mAnimatedValue <= 0.25) { // 0~0.25 113 | extra_percent = mAnimatedValue; 114 | } else if (mAnimatedValue <= 0.5f) { // 0.25~0.5 115 | extra_percent = 0.5f - mAnimatedValue; 116 | } else if (mAnimatedValue <= 0.75) {// 0.5~0.75 117 | extra_percent = mAnimatedValue - 0.5f; 118 | } else if (mAnimatedValue <= 1.0) {// 0.75~1.0 119 | extra_percent = 1.0f - mAnimatedValue; 120 | } 121 | 122 | 123 | // 0.5时要达到maxMove最大,*2 124 | // extra_percent控制椭圆效果,等于0.25或0.75时,即最中间区域,达到两倍直径 125 | 126 | mRectF.set(x - radius + maxMove * 2 * percent - radius * 4 * extra_percent, 127 | y - radius, 128 | x + radius + maxMove * 2 * percent + radius * 4 * extra_percent, 129 | y + radius); 130 | canvas.drawOval(mRectF, paint); 131 | } 132 | 133 | } 134 | -------------------------------------------------------------------------------- /library/src/main/java/com/example/mzy/indicators/Circle/CircleRotateScaleIndicator.java: -------------------------------------------------------------------------------- 1 | package com.example.mzy.indicators.Circle; 2 | 3 | import android.animation.Animator; 4 | import android.animation.AnimatorSet; 5 | import android.animation.ValueAnimator; 6 | import android.content.Context; 7 | import android.graphics.Canvas; 8 | import android.graphics.Color; 9 | import android.graphics.Paint; 10 | import android.util.Log; 11 | import android.view.animation.LinearInterpolator; 12 | 13 | import com.example.mzy.indicators.IndicatorDrawable; 14 | 15 | import java.util.ArrayList; 16 | 17 | /** 18 | * Created by mazhengyang on 18-10-24. 19 | */ 20 | 21 | public class CircleRotateScaleIndicator extends IndicatorDrawable { 22 | 23 | private final String TAG = CircleRotateScaleIndicator.class.getSimpleName(); 24 | 25 | private final int mCount = 5; 26 | 27 | private float mAnimatedValue = 0.0f; 28 | 29 | private float[] scaleAnimatedValue = new float[]{1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f}; 30 | 31 | private boolean drawAssist = false; 32 | 33 | public CircleRotateScaleIndicator(Context context, int indicatorColor, int indicatorSpeed) { 34 | Log.d(TAG, "CircleRotateScaleIndicator: "); 35 | this.indicatorColor = indicatorColor; 36 | this.indicatorSpeed = indicatorSpeed; 37 | if (indicatorSpeed <= 0) { 38 | this.indicatorSpeed = 2000; 39 | } 40 | 41 | init(context); 42 | } 43 | 44 | @Override 45 | protected void init(Context context) { 46 | Log.d(TAG, "init: "); 47 | mPaint.setAntiAlias(true); 48 | mPaint.setStyle(Paint.Style.FILL); 49 | mPaint.setStrokeWidth(dip2px(context, 1.0f)); 50 | mPaint.setColor(indicatorColor); 51 | } 52 | 53 | @Override 54 | protected ArrayList getAnimation() { 55 | 56 | ArrayList list = new ArrayList<>(); 57 | 58 | ValueAnimator rotateAnimator = ValueAnimator.ofFloat(0, 360); 59 | rotateAnimator.setRepeatCount(ValueAnimator.INFINITE); 60 | rotateAnimator.setDuration(indicatorSpeed); 61 | rotateAnimator.setInterpolator(new LinearInterpolator()); 62 | 63 | rotateAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 64 | @Override 65 | public void onAnimationUpdate(ValueAnimator animation) { 66 | mAnimatedValue = ((float) animation.getAnimatedValue()); 67 | invalidateSelf(); 68 | } 69 | }); 70 | 71 | int[] delays = {0, 100, 200, 300, 400}; 72 | for (int i = 0; i < mCount; i++) { 73 | final int index = i; 74 | ValueAnimator scaleAnimator = ValueAnimator.ofFloat(1, 0.4f, 1); 75 | scaleAnimator.setDuration(indicatorSpeed); 76 | scaleAnimator.setRepeatCount(ValueAnimator.INFINITE); 77 | scaleAnimator.setStartDelay(delays[i]); 78 | scaleAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 79 | @Override 80 | public void onAnimationUpdate(ValueAnimator animation) { 81 | scaleAnimatedValue[index] = ((float) animation.getAnimatedValue()); 82 | } 83 | }); 84 | 85 | AnimatorSet animatorSet = new AnimatorSet(); 86 | animatorSet.playTogether(rotateAnimator, scaleAnimator); 87 | 88 | list.add(animatorSet); 89 | } 90 | 91 | return list; 92 | } 93 | 94 | @Override 95 | protected void draw(Canvas canvas, Paint paint) { 96 | 97 | canvas.save(); 98 | drawAssist(canvas, paint); 99 | drawBall(canvas, paint); 100 | canvas.restore(); 101 | } 102 | 103 | private void drawAssist(Canvas canvas, Paint paint) { 104 | if (drawAssist) { 105 | canvas.drawColor(Color.RED); 106 | 107 | canvas.drawLine(getWidth() / 2, 0, getWidth() / 2, getHeight(), paint); 108 | canvas.drawLine(0, getHeight() / 2, getWidth(), getHeight() / 2, paint); 109 | } 110 | } 111 | 112 | private void drawBall(Canvas canvas, Paint paint) { 113 | 114 | //五个圆的中心点到每个小圆的圆心距离 115 | float out_radius = getWidth() / 10; 116 | float radius = getWidth() / 25; 117 | 118 | for (int i = 0; i < mCount; i++) { 119 | 120 | int degree = (int) (360 / mCount * i + mAnimatedValue);//改成负值变成逆时针 121 | double angle = degree * Math.PI / 180; 122 | float x = getWidth() / 2 + out_radius * (float) Math.cos(angle); 123 | float y = getHeight() / 2 + out_radius * (float) Math.sin(angle); 124 | canvas.drawCircle(x, y, radius * scaleAnimatedValue[i], paint); 125 | } 126 | } 127 | 128 | } 129 | -------------------------------------------------------------------------------- /library/src/main/java/com/example/mzy/indicators/Circle/CircleTriangleIndicator.java: -------------------------------------------------------------------------------- 1 | package com.example.mzy.indicators.Circle; 2 | 3 | import android.animation.Animator; 4 | import android.animation.AnimatorSet; 5 | import android.animation.ValueAnimator; 6 | import android.content.Context; 7 | import android.graphics.Canvas; 8 | import android.graphics.Color; 9 | import android.graphics.Paint; 10 | import android.util.Log; 11 | import android.view.animation.LinearInterpolator; 12 | 13 | import com.example.mzy.indicators.IndicatorDrawable; 14 | 15 | import java.util.ArrayList; 16 | 17 | /** 18 | * Created by mazhengyang on 18-12-19. 19 | */ 20 | 21 | public class CircleTriangleIndicator extends IndicatorDrawable { 22 | 23 | private final String TAG = CircleTriangleIndicator.class.getSimpleName(); 24 | 25 | private float rotateAnimatedValue = 0.0f; 26 | private float scaleAnimatedValue = 0.0f; 27 | 28 | private boolean drawAssist = false; 29 | 30 | public CircleTriangleIndicator(Context context, int indicatorColor, int indicatorSpeed) { 31 | Log.d(TAG, "CircleTriangleIndicator: "); 32 | this.indicatorColor = indicatorColor; 33 | this.indicatorSpeed = indicatorSpeed; 34 | if (indicatorSpeed <= 0) { 35 | this.indicatorSpeed = 1500; 36 | } 37 | 38 | init(context); 39 | } 40 | 41 | @Override 42 | protected void init(Context context) { 43 | Log.d(TAG, "init: "); 44 | mPaint.setAntiAlias(true); 45 | mPaint.setStyle(Paint.Style.FILL); 46 | mPaint.setStrokeWidth(dip2px(context, 1.0f)); 47 | mPaint.setColor(indicatorColor); 48 | } 49 | 50 | @Override 51 | protected ArrayList getAnimation() { 52 | 53 | ArrayList list = new ArrayList<>(); 54 | 55 | ValueAnimator rotateAnimator = ValueAnimator.ofFloat(360, 0); 56 | rotateAnimator.setRepeatCount(ValueAnimator.INFINITE); 57 | rotateAnimator.setDuration(indicatorSpeed); 58 | rotateAnimator.setInterpolator(new LinearInterpolator()); 59 | 60 | rotateAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 61 | @Override 62 | public void onAnimationUpdate(ValueAnimator animation) { 63 | rotateAnimatedValue = ((float) animation.getAnimatedValue()); 64 | invalidateSelf(); 65 | } 66 | }); 67 | 68 | ValueAnimator scaleAnimator = ValueAnimator.ofFloat(1.0f, 0.3f, 1.0f); 69 | scaleAnimator.setRepeatCount(ValueAnimator.INFINITE); 70 | scaleAnimator.setDuration(indicatorSpeed); 71 | scaleAnimator.setInterpolator(new LinearInterpolator()); 72 | 73 | scaleAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 74 | @Override 75 | public void onAnimationUpdate(ValueAnimator animation) { 76 | scaleAnimatedValue = ((float) animation.getAnimatedValue()); 77 | // invalidateSelf(); 78 | } 79 | }); 80 | 81 | AnimatorSet animatorSet = new AnimatorSet(); 82 | animatorSet.playTogether(rotateAnimator, scaleAnimator); 83 | 84 | list.add(animatorSet); 85 | 86 | return list; 87 | } 88 | 89 | @Override 90 | protected void draw(Canvas canvas, Paint paint) { 91 | 92 | drawAssist(canvas, paint); 93 | drawCircleTriangle(canvas, paint); 94 | } 95 | 96 | private void drawAssist(Canvas canvas, Paint paint) { 97 | if (drawAssist) { 98 | canvas.drawColor(Color.RED); 99 | 100 | canvas.drawLine(getWidth() / 2, 0, getWidth() / 2, getHeight(), paint); 101 | canvas.drawLine(0, getHeight() / 2, getWidth(), getHeight() / 2, paint); 102 | } 103 | } 104 | 105 | /** 106 | * 中心点o(0,0),边长 a 107 | * 108 | * A (0, - sqrt(3) * a / 3) 109 | * B (- a/2, sqrt(3) * a / 6) 110 | * C (a/2, sqrt(3) * a / 6) 111 | * 112 | * 113 | * A 114 | * 115 | * 116 | * O 117 | * 118 | * B C 119 | * 120 | */ 121 | 122 | private void drawCircleTriangle(Canvas canvas, Paint paint) { 123 | 124 | float sideLength = getWidth() / 5; 125 | float radius = getWidth() / 30; 126 | canvas.save(); 127 | canvas.translate(getWidth()/2, getHeight()/2); 128 | canvas.scale(scaleAnimatedValue, scaleAnimatedValue); 129 | canvas.rotate(rotateAnimatedValue); 130 | float xA = 0; 131 | float yA = -(float)Math.sqrt(3)*sideLength/3; 132 | float xB = -sideLength/2; 133 | float yB = (float)Math.sqrt(3)*sideLength/6; 134 | float xC = sideLength/2; 135 | float yC = (float)Math.sqrt(3)*sideLength/6; 136 | canvas.drawCircle(xA, yA, radius,paint);//A 137 | canvas.drawCircle(xB, yB, radius,paint);//B 138 | canvas.drawCircle(xC, yC, radius,paint);//C 139 | canvas.drawLine(xA,yA,xB,yB,paint); 140 | canvas.drawLine(xB,yB,xC,yC,paint); 141 | canvas.drawLine(xC,yC,xA,yA,paint); 142 | canvas.restore(); 143 | } 144 | 145 | } 146 | -------------------------------------------------------------------------------- /library/src/main/java/com/example/mzy/indicators/Circle/CircleCollisionIndicator.java: -------------------------------------------------------------------------------- 1 | package com.example.mzy.indicators.Circle; 2 | 3 | import android.animation.Animator; 4 | import android.animation.ValueAnimator; 5 | import android.content.Context; 6 | import android.graphics.Canvas; 7 | import android.graphics.Paint; 8 | import android.util.Log; 9 | import android.view.animation.AccelerateInterpolator; 10 | import android.view.animation.DecelerateInterpolator; 11 | import android.view.animation.Interpolator; 12 | import android.view.animation.LinearInterpolator; 13 | 14 | import com.example.mzy.indicators.IndicatorDrawable; 15 | 16 | import java.util.ArrayList; 17 | 18 | /** 19 | * Created by mzy on 2018/9/3. 20 | */ 21 | 22 | public class CircleCollisionIndicator extends IndicatorDrawable { 23 | 24 | private final String TAG = CircleCollisionIndicator.class.getSimpleName(); 25 | 26 | private final int mCount = 4; 27 | private float leftBallMoveXOffset = 0; 28 | private float rightBallMoveXOffset = 0; 29 | private float maxMoveXOffset; 30 | 31 | private Interpolator mAccelerateInterpolator = new AccelerateInterpolator(); 32 | private Interpolator mDecelerateInterpolator = new DecelerateInterpolator(); 33 | 34 | private static final float DEFAULT_BALL_RADIUS = 5.0f; 35 | private static final float MAX_MOVE_OFFSET = 50.0f; 36 | 37 | public CircleCollisionIndicator(Context context, int indicatorColor, int indicatorSpeed) { 38 | Log.d(TAG, "CircleCollisionIndicator: "); 39 | this.indicatorColor = indicatorColor; 40 | this.indicatorSpeed = indicatorSpeed; 41 | if (indicatorSpeed <= 0) { 42 | this.indicatorSpeed = 2000; 43 | } 44 | 45 | init(context); 46 | } 47 | 48 | @Override 49 | protected void init(Context context) { 50 | Log.d(TAG, "init: "); 51 | mPaint.setAntiAlias(true); 52 | mPaint.setStyle(Paint.Style.FILL); 53 | mPaint.setStrokeWidth(dip2px(context, 1.0f)); 54 | mPaint.setColor(indicatorColor); 55 | 56 | maxMoveXOffset = dip2px(context, 30.0f); 57 | } 58 | 59 | @Override 60 | protected ArrayList getAnimation() { 61 | 62 | ArrayList list = new ArrayList<>(); 63 | 64 | ValueAnimator valueAnimator = ValueAnimator.ofFloat(0.0f, 1.0f); 65 | valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 66 | @Override 67 | public void onAnimationUpdate(ValueAnimator valueAnimator) { 68 | compute((float) valueAnimator.getAnimatedValue()); 69 | invalidateSelf(); 70 | } 71 | }); 72 | 73 | valueAnimator.setInterpolator(new LinearInterpolator()); 74 | valueAnimator.setRepeatCount(ValueAnimator.INFINITE); 75 | valueAnimator.setDuration(indicatorSpeed); 76 | list.add(valueAnimator); 77 | 78 | return list; 79 | } 80 | 81 | @Override 82 | protected void draw(Canvas canvas, Paint paint) { 83 | canvas.save(); 84 | 85 | // paint.setShader(new LinearGradient(ballOffsetX, 0, getWidth() - ballOffsetX, 0 86 | // , new int[]{Color.parseColor("#EE4000"), Color.parseColor("#FF7F00")} 87 | // , null, LinearGradient.TileMode.CLAMP)); 88 | 89 | drawBall(canvas, paint); 90 | canvas.restore(); 91 | } 92 | 93 | private void drawBall(Canvas canvas, Paint paint) { 94 | 95 | float radius = getWidth() / 25; 96 | 97 | float ballOffsetX = (getWidth() - (mCount - 2) * radius * 2) / 2; 98 | float ballCenterY = getHeight() / 2; 99 | 100 | for (int i = 1; i < mCount - 1; i++) { 101 | canvas.drawCircle(ballOffsetX + radius * (i * 2 - 1), 102 | ballCenterY, radius, paint); 103 | } 104 | 105 | // the first ball 106 | canvas.drawCircle(ballOffsetX - radius - leftBallMoveXOffset, 107 | ballCenterY, radius, paint); 108 | 109 | // the last ball 110 | canvas.drawCircle(ballOffsetX + (mCount - 2) * radius * 2 + radius + rightBallMoveXOffset, 111 | ballCenterY, radius, paint); 112 | } 113 | 114 | private void compute(float progress) { 115 | if (progress <= 0.25f) {// 0 ~ 25% 116 | rightBallMoveXOffset = 0; 117 | computeLeft(progress); 118 | } else if (progress <= 0.5f) {// 25% ~ 50% 119 | rightBallMoveXOffset = 0; 120 | computeLeft(0.5f - progress); 121 | } else if (progress <= 0.75f) {// 50% ~ 75% 122 | leftBallMoveXOffset = 0; 123 | computeRight(progress - 0.5f); 124 | } else if (progress <= 1.0f) {// 75% ~ 100% 125 | leftBallMoveXOffset = 0; 126 | computeRight(1.0f - progress); 127 | } 128 | } 129 | 130 | private void computeLeft(float progress) { 131 | rightBallMoveXOffset = 0; 132 | leftBallMoveXOffset = progress * maxMoveXOffset; 133 | } 134 | 135 | private void computeRight(float progress) { 136 | leftBallMoveXOffset = 0; 137 | rightBallMoveXOffset = progress * maxMoveXOffset; 138 | } 139 | 140 | } 141 | -------------------------------------------------------------------------------- /library/src/main/java/com/example/mzy/indicators/Rect/ParallelogramIndicator.java: -------------------------------------------------------------------------------- 1 | package com.example.mzy.indicators.Rect; 2 | 3 | import android.animation.Animator; 4 | import android.animation.ValueAnimator; 5 | import android.content.Context; 6 | import android.graphics.Canvas; 7 | import android.graphics.Color; 8 | import android.graphics.Paint; 9 | import android.graphics.Path; 10 | import android.util.Log; 11 | 12 | import com.example.mzy.indicators.IndicatorDrawable; 13 | 14 | import java.util.ArrayList; 15 | 16 | /** 17 | * Created by mazhengyang on 18-10-11. 18 | */ 19 | 20 | public class ParallelogramIndicator extends IndicatorDrawable { 21 | 22 | private final String TAG = ParallelogramIndicator.class.getSimpleName(); 23 | 24 | private Path path = new Path(); 25 | 26 | private final int mCount = 3; 27 | private float space;//相邻平行四边形间距 28 | private float leftPadding; 29 | 30 | private float offsetWidth; //平行四边形凸出部分宽度 31 | private float paraWidth; //平行四边形宽度 32 | private float paraHeight; //平行四边形高度 33 | private boolean drawAssist = false; 34 | 35 | private float[] mAnimatedValue = new float[]{ 36 | 1.0f, 1.0f, 1.0f 37 | }; 38 | 39 | public ParallelogramIndicator(Context context, int indicatorColor, int indicatorSpeed) { 40 | Log.d(TAG, "ParallelogramIndicator: "); 41 | this.indicatorColor = indicatorColor; 42 | this.indicatorSpeed = indicatorSpeed; 43 | if (indicatorSpeed <= 0) { 44 | this.indicatorSpeed = 1000; 45 | } 46 | 47 | init(context); 48 | } 49 | 50 | @Override 51 | protected void init(Context context) { 52 | Log.d(TAG, "init: "); 53 | mPaint.setAntiAlias(true); 54 | mPaint.setStyle(Paint.Style.FILL); 55 | mPaint.setStrokeWidth(dip2px(context, 1.0f)); 56 | mPaint.setColor(indicatorColor); 57 | 58 | space = dip2px(context, 5.0f); 59 | } 60 | 61 | @Override 62 | protected ArrayList getAnimation() { 63 | int[] delay = new int[]{100, 200, 300}; 64 | 65 | ArrayList list = new ArrayList<>(); 66 | 67 | for (int i = 0; i < mCount; i++) { 68 | final int index = i; 69 | ValueAnimator valueAnimator = ValueAnimator.ofFloat(1.0f, 0.3f, 1.0f); 70 | valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 71 | @Override 72 | public void onAnimationUpdate(ValueAnimator valueAnimator) { 73 | mAnimatedValue[index] = ((float) valueAnimator.getAnimatedValue()); 74 | invalidateSelf(); 75 | } 76 | }); 77 | 78 | valueAnimator.setRepeatCount(ValueAnimator.INFINITE); 79 | valueAnimator.setDuration(indicatorSpeed); 80 | valueAnimator.setStartDelay(delay[i]); 81 | list.add(valueAnimator); 82 | } 83 | 84 | return list; 85 | } 86 | 87 | 88 | @Override 89 | protected void draw(Canvas canvas, Paint paint) { 90 | 91 | if (leftPadding == 0) { 92 | 93 | paraWidth = getWidth() / 20; 94 | paraHeight = getHeight() / 12; 95 | offsetWidth = paraWidth / 2; 96 | 97 | //第一个四边形左下点坐标 98 | leftPadding = (getWidth() - ((paraWidth + offsetWidth) * mCount + space * (mCount - 1))) / 2; 99 | } 100 | 101 | drawAssist(canvas, paint); 102 | drawParallelogram(canvas, paint); 103 | } 104 | 105 | private void drawAssist(Canvas canvas, Paint paint) { 106 | 107 | if (drawAssist) { 108 | canvas.drawColor(Color.GRAY); 109 | canvas.drawLine(0, getHeight() / 2, getWidth(), getHeight() / 2, paint); 110 | canvas.drawLine(getWidth() / 2, 0, getWidth() / 2, getHeight(), paint); 111 | } 112 | } 113 | 114 | 115 | private void drawParallelogram(Canvas canvas, Paint paint) { 116 | 117 | for (int i = 0; i < mCount; i++) { 118 | canvas.save(); 119 | 120 | float x1 = leftPadding + offsetWidth * (i + 1) + (paraWidth + space) * i; 121 | float y1 = getHeight() / 2 - paraHeight / 2; 122 | float x2 = x1 + paraWidth; 123 | float y2 = y1 + paraHeight; 124 | 125 | //对角线交点坐标,分别为左上点,右上点对应轴坐标相加一半 126 | float centerX = (x1 + x2) / 2; 127 | float centerY = (y1 + y2) / 2; 128 | 129 | //将画布移动到对角线交点 130 | canvas.translate(centerX, centerY); 131 | canvas.scale(mAnimatedValue[i], mAnimatedValue[i]); 132 | 133 | path.reset();//重置路径 134 | //此时画布起始坐标位于对角线交点,四边形各角坐标需相对此交点 135 | path.moveTo(-(centerX - x1), -paraHeight / 2);//左上点 136 | path.lineTo(-(centerX - x1) - offsetWidth, paraHeight / 2);//左下点 137 | path.lineTo(-(centerX - x1) - offsetWidth + paraWidth, paraHeight / 2);//右下点 138 | path.lineTo(-(centerX - x1) + paraWidth, -paraHeight / 2);//右上点 139 | path.close(); 140 | 141 | canvas.drawPath(path, paint); 142 | // canvas.clipPath(path);//截取路径所绘制的图形, ?? clipPath会出现锯齿 143 | // canvas.drawColor(Color.WHITE); 144 | 145 | canvas.restore(); 146 | } 147 | } 148 | } 149 | -------------------------------------------------------------------------------- /library/src/main/java/com/example/mzy/indicators/Circle/TrackIndicator.java: -------------------------------------------------------------------------------- 1 | package com.example.mzy.indicators.Circle; 2 | 3 | import android.animation.Animator; 4 | import android.animation.AnimatorSet; 5 | import android.animation.ValueAnimator; 6 | import android.content.Context; 7 | import android.graphics.Canvas; 8 | import android.graphics.Color; 9 | import android.graphics.Paint; 10 | import android.util.Log; 11 | import android.view.animation.LinearInterpolator; 12 | 13 | import com.example.mzy.indicators.IndicatorDrawable; 14 | 15 | import java.util.ArrayList; 16 | 17 | /** 18 | * Created by mazhengyang on 18-10-24. 19 | */ 20 | 21 | public class TrackIndicator extends IndicatorDrawable { 22 | 23 | private final String TAG = TrackIndicator.class.getSimpleName(); 24 | 25 | private final int mCount = 3; 26 | 27 | private float radius = 0; 28 | private float moveDistance = 0;//相对于中心点的可移动距离,这里设置为view宽度四分之一 29 | 30 | private float[][] translationX_Array = new float[][]{ 31 | {-0.5f, -1.0f, -0.5f, 0.0f, 0.5f, 1.0f, 0.5f, 0.0f, -0.5f}, 32 | {0.0f, 0.5f, 1.0f, 0.5f, 0.0f, -0.5f, -1.0f, -0.5f, 0.0f}, 33 | {0.5f, 0.0f, -0.5f, -1.0f, -0.5f, 0.0f, 0.5f, 1.0f, 0.5f} 34 | }; 35 | 36 | private float[][] scaleXY_Array = new float[][]{ 37 | {0.5f, 1.0f, 1.5f, 1.0f, 0.5f, 1.0f, 1.5f, 1.0f, 0.5f}, 38 | {1.0f, 0.5f, 1.0f, 1.5f, 1.0f, 0.5f, 1.0f, 1.5f, 1.0f}, 39 | {1.5f, 1.0f, 0.5f, 1.0f, 1.5f, 1.0f, 0.5f, 1.0f, 1.5f} 40 | }; 41 | 42 | private float[] translationXValue = new float[]{ 43 | 1.0f, 1.0f, 1.0f 44 | }; 45 | private float[] scaleXYValue = new float[]{ 46 | 1.0f, 1.0f, 1.0f 47 | }; 48 | 49 | private int[] color = new int[]{ 50 | Color.RED, Color.GREEN, Color.BLUE 51 | }; 52 | 53 | private boolean drawAssist = false; 54 | 55 | public TrackIndicator(Context context, int indicatorColor, int indicatorSpeed) { 56 | Log.d(TAG, "TrackIndicator: "); 57 | this.indicatorColor = indicatorColor; 58 | this.indicatorSpeed = indicatorSpeed; 59 | if (indicatorSpeed <= 0) { 60 | this.indicatorSpeed = 2000; 61 | } 62 | 63 | init(context); 64 | } 65 | 66 | @Override 67 | protected void init(Context context) { 68 | Log.d(TAG, "init: "); 69 | mPaint.setAntiAlias(true); 70 | mPaint.setStyle(Paint.Style.FILL); 71 | mPaint.setStrokeWidth(dip2px(context, 1.0f)); 72 | mPaint.setColor(indicatorColor); 73 | } 74 | 75 | @Override 76 | protected ArrayList getAnimation() { 77 | 78 | ArrayList list = new ArrayList<>(); 79 | 80 | for (int i = 0; i < mCount; i++) { 81 | final int index = i; 82 | ValueAnimator translationX = ValueAnimator.ofFloat(translationX_Array[i]); 83 | translationX.setRepeatCount(ValueAnimator.INFINITE); 84 | translationX.setDuration(indicatorSpeed); 85 | translationX.setInterpolator(new LinearInterpolator()); 86 | 87 | ValueAnimator scaleXY = ValueAnimator.ofFloat(scaleXY_Array[i]); 88 | scaleXY.setRepeatCount(ValueAnimator.INFINITE); 89 | scaleXY.setDuration(indicatorSpeed); 90 | translationX.setInterpolator(new LinearInterpolator()); 91 | 92 | translationX.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 93 | @Override 94 | public void onAnimationUpdate(ValueAnimator animation) { 95 | translationXValue[index] = ((float) animation.getAnimatedValue()); 96 | } 97 | }); 98 | 99 | scaleXY.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 100 | @Override 101 | public void onAnimationUpdate(ValueAnimator animation) { 102 | scaleXYValue[index] = ((float) animation.getAnimatedValue()); 103 | invalidateSelf(); 104 | } 105 | }); 106 | 107 | AnimatorSet animatorSet = new AnimatorSet(); 108 | animatorSet.playTogether(translationX, scaleXY); 109 | 110 | list.add(animatorSet); 111 | } 112 | return list; 113 | } 114 | 115 | @Override 116 | protected void draw(Canvas canvas, Paint paint) { 117 | 118 | if (moveDistance == 0) { 119 | moveDistance = getWidth() / 4; 120 | radius = getWidth() / 25; 121 | } 122 | 123 | drawAssist(canvas, paint); 124 | drawBall(canvas, paint); 125 | } 126 | 127 | 128 | private void drawAssist(Canvas canvas, Paint paint) { 129 | if (drawAssist) { 130 | canvas.drawColor(Color.RED); 131 | 132 | canvas.drawLine(getWidth() / 2, 0, getWidth() / 2, getHeight(), paint); 133 | canvas.drawLine(getWidth() / 4, 0, getWidth() / 4, getHeight(), paint); 134 | canvas.drawLine(getWidth() / 4 * 3, 0, getWidth() / 4 * 3, getHeight(), paint); 135 | } 136 | } 137 | 138 | private void drawBall(Canvas canvas, Paint paint) { 139 | for (int i = 0; i < mCount; i++) { 140 | float x = getWidth() / 2 + translationXValue[i] * moveDistance; 141 | // paint.setColor(color[i]); 142 | canvas.drawCircle(x, getHeight() / 2, scaleXYValue[i] * radius, paint); 143 | } 144 | } 145 | 146 | } 147 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /library/src/main/java/com/example/mzy/indicators/Star/StarIndicator.java: -------------------------------------------------------------------------------- 1 | package com.example.mzy.indicators.Star; 2 | 3 | import android.animation.Animator; 4 | import android.animation.ValueAnimator; 5 | import android.content.Context; 6 | import android.graphics.Canvas; 7 | import android.graphics.Color; 8 | import android.graphics.CornerPathEffect; 9 | import android.graphics.Paint; 10 | import android.graphics.Path; 11 | import android.graphics.RectF; 12 | import android.util.Log; 13 | import android.view.animation.DecelerateInterpolator; 14 | 15 | import com.example.mzy.indicators.IndicatorDrawable; 16 | 17 | import java.util.ArrayList; 18 | 19 | /** 20 | * Created by mzy on 2018/9/22. 21 | */ 22 | 23 | public class StarIndicator extends IndicatorDrawable { 24 | 25 | private static final float THICKNESS = 0.7f; //星的胖度系数 26 | private final String TAG = StarIndicator.class.getSimpleName(); 27 | 28 | //正多边形每个内角相等,度数为(n-2)*180/n,n为边数 29 | private float starHeight; 30 | private StarModel mStarModel = new StarModel(THICKNESS); 31 | private CornerPathEffect pathEffect = new CornerPathEffect(30); 32 | 33 | private float mAnimatedValue; 34 | private RectF mShadowRect = new RectF(); 35 | private float mShadowWidth; 36 | 37 | public StarIndicator(Context context, int indicatorColor, int indicatorSpeed) { 38 | Log.d(TAG, "StarIndicator: "); 39 | this.indicatorColor = indicatorColor; 40 | this.indicatorSpeed = indicatorSpeed; 41 | if (indicatorSpeed <= 0) { 42 | this.indicatorSpeed = 2000; 43 | } 44 | 45 | init(context); 46 | } 47 | 48 | @Override 49 | protected void init(Context context) { 50 | Log.d(TAG, "init: "); 51 | mPaint.setAntiAlias(true); 52 | mPaint.setStyle(Paint.Style.FILL); 53 | mPaint.setStrokeWidth(dip2px(context, 1.0f)); 54 | mPaint.setColor(indicatorColor); 55 | 56 | // starHeight = dip2px(context, 20.0f); 57 | // mStarModel.setDrawingOuterRect(0, 0, starHeight); 58 | // 59 | // mShadowWidth = dip2px(context, 10.0f); 60 | } 61 | 62 | @Override 63 | protected ArrayList getAnimation() { 64 | 65 | ArrayList list = new ArrayList<>(); 66 | 67 | ValueAnimator valueAnimator = ValueAnimator.ofFloat(0.0f, 1.0f); 68 | valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 69 | @Override 70 | public void onAnimationUpdate(ValueAnimator valueAnimator) { 71 | mAnimatedValue = ((float) valueAnimator.getAnimatedValue()); 72 | invalidateSelf(); 73 | } 74 | }); 75 | 76 | valueAnimator.setInterpolator(new DecelerateInterpolator()); 77 | valueAnimator.setRepeatCount(ValueAnimator.INFINITE); 78 | valueAnimator.setDuration(indicatorSpeed); 79 | list.add(valueAnimator); 80 | 81 | return list; 82 | } 83 | 84 | @Override 85 | protected void draw(Canvas canvas, Paint paint) { 86 | 87 | if (starHeight == 0) { 88 | starHeight = getWidth() / 5; 89 | mStarModel.setDrawingOuterRect(0, 0, starHeight); 90 | 91 | mShadowWidth = getWidth() / 5; 92 | } 93 | 94 | canvas.save(); 95 | 96 | float x = getWidth() / 2 - starHeight / 2; 97 | float value; 98 | if (mAnimatedValue <= 0.5) {//下落 99 | value = mAnimatedValue; 100 | } else {//弹起 101 | value = 1 - mAnimatedValue; 102 | } 103 | canvas.translate(x, getHeight() / 4 + value * starHeight); 104 | 105 | //以五角星中心位置为旋转原点 106 | canvas.rotate(360 * mAnimatedValue, starHeight / 2, starHeight / 2); 107 | drawStar(canvas, paint); 108 | 109 | canvas.restore(); 110 | 111 | //恢复画布后再画阴影,否则阴影也会旋转 112 | drawShadow(canvas, paint); 113 | } 114 | 115 | private void drawStar(Canvas canvas, Paint paint) { 116 | paint.setStyle(Paint.Style.FILL_AND_STROKE); 117 | paint.setPathEffect(pathEffect); 118 | paint.setColor(indicatorColor); 119 | 120 | VertexF prev = mStarModel.getVertex(1); 121 | Path path = new Path(); 122 | 123 | for (int i = 0; i < 5; i++) { 124 | path.rewind(); 125 | path.moveTo(prev.x, prev.y); 126 | 127 | VertexF next = prev.next; 128 | 129 | path.lineTo(next.x, next.y); 130 | path.lineTo(next.next.x, next.next.y); 131 | canvas.drawPath(path, paint); 132 | 133 | prev = next.next; 134 | } 135 | 136 | // fill the middle hole. use +1.0 +1.5 because the path-API will leave 1px gap. 137 | path.rewind(); 138 | prev = mStarModel.getVertex(1); 139 | path.moveTo(prev.x - 1f, prev.y - 1f); 140 | prev = prev.next.next; 141 | path.lineTo(prev.x + 1.5f, prev.y - 0.5f); 142 | prev = prev.next.next; 143 | path.lineTo(prev.x + 1.5f, prev.y + 1f); 144 | prev = prev.next.next; 145 | path.lineTo(prev.x, prev.y + 1f); 146 | prev = prev.next.next; 147 | path.lineTo(prev.x - 1f, prev.y + 1f); 148 | 149 | paint.setPathEffect(null); 150 | canvas.drawPath(path, paint); 151 | } 152 | 153 | private void drawShadow(Canvas canvas, Paint paint) { 154 | 155 | paint.setColor(Color.GRAY); 156 | 157 | float value;//0 ~ 0.5 158 | if (mAnimatedValue <= 0.5) {//下落 159 | value = mAnimatedValue; 160 | } else {//弹起 161 | value = 1 - mAnimatedValue; 162 | } 163 | 164 | if (value < 0.1) { 165 | return; 166 | } 167 | 168 | float cut = mShadowWidth * value * 0.7f; 169 | 170 | //getHeight() / 4 + 0.5f * starHeight为星的top那个角的y坐标 171 | float y = getHeight() / 4 + 0.5f * starHeight + starHeight; 172 | 173 | mShadowRect.set(getWidth() / 2 - cut, 174 | y + mShadowWidth / 8, 175 | getWidth() / 2 + cut, 176 | y + mShadowWidth / 4); 177 | 178 | canvas.drawOval(mShadowRect, paint); 179 | } 180 | } 181 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 15 | 16 | 20 | 21 | 26 | 27 | 32 | 33 | 38 | 39 | 44 | 45 | 46 | 47 | 51 | 52 | 57 | 58 | 63 | 64 | 69 | 70 | 75 | 76 | 77 | 78 | 82 | 83 | 88 | 89 | 94 | 95 | 100 | 101 | 106 | 107 | 108 | 109 | 110 | 114 | 115 | 120 | 121 | 126 | 127 | 132 | 133 | 138 | 139 | 140 | 141 | 145 | 146 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | -------------------------------------------------------------------------------- /library/src/main/java/com/example/mzy/indicators/Rect/ChartRectIndicator2.java: -------------------------------------------------------------------------------- 1 | package com.example.mzy.indicators.Rect; 2 | 3 | import android.animation.Animator; 4 | import android.animation.ValueAnimator; 5 | import android.content.Context; 6 | import android.graphics.Canvas; 7 | import android.graphics.Paint; 8 | import android.graphics.RectF; 9 | import android.util.Log; 10 | 11 | import com.example.mzy.indicators.IndicatorDrawable; 12 | 13 | import java.util.ArrayList; 14 | 15 | /** 16 | * Created by mazhengyang on 18-9-20. 17 | */ 18 | 19 | public class ChartRectIndicator2 extends IndicatorDrawable { 20 | 21 | private final String TAG = ChartRectIndicator2.class.getSimpleName(); 22 | 23 | private final int mCount = 5; 24 | private float rectMax; 25 | private int mCurrAnimatorState = 0; 26 | 27 | private float mAnimatedValue; 28 | private RectF rectF = new RectF(); 29 | boolean repeatRunned = false; 30 | 31 | public ChartRectIndicator2(Context context, int indicatorColor, int indicatorSpeed) { 32 | Log.d(TAG, "ChartRectIndicator2: "); 33 | this.indicatorColor = indicatorColor; 34 | this.indicatorSpeed = indicatorSpeed; 35 | if (indicatorSpeed <= 0) { 36 | this.indicatorSpeed = 1000; 37 | } 38 | 39 | init(context); 40 | } 41 | 42 | @Override 43 | protected void init(Context context) { 44 | Log.d(TAG, "init: "); 45 | mPaint.setAntiAlias(true); 46 | mPaint.setStyle(Paint.Style.FILL); 47 | mPaint.setStrokeWidth(dip2px(context, 1.0f)); 48 | mPaint.setColor(indicatorColor); 49 | 50 | rectMax = dip2px(context, 10.0f); 51 | } 52 | 53 | @Override 54 | protected ArrayList getAnimation() { 55 | 56 | ArrayList list = new ArrayList<>(); 57 | 58 | ValueAnimator valueAnimator = ValueAnimator.ofFloat(0.0f, 1.0f); 59 | valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 60 | @Override 61 | public void onAnimationUpdate(ValueAnimator valueAnimator) { 62 | mAnimatedValue = ((float) valueAnimator.getAnimatedValue()); 63 | Log.d(TAG, "onAnimationUpdate: mAnimatedValue=" + mAnimatedValue); 64 | invalidateSelf(); 65 | } 66 | }); 67 | 68 | valueAnimator.addListener(new Animator.AnimatorListener() { 69 | 70 | @Override 71 | public void onAnimationStart(Animator animation) { 72 | Log.d(TAG, "onAnimationStart: "); 73 | } 74 | 75 | @Override 76 | public void onAnimationEnd(Animator animation) { 77 | Log.d(TAG, "onAnimationEnd: "); 78 | } 79 | 80 | @Override 81 | public void onAnimationCancel(Animator animation) { 82 | Log.d(TAG, "onAnimationCancel: "); 83 | } 84 | 85 | @Override 86 | public void onAnimationRepeat(Animator animation) { 87 | Log.d(TAG, "onAnimationRepeat: "); 88 | 89 | repeatRunned = true; 90 | 91 | // mAnimatedValue = 0; 92 | // mCurrAnimatorState++; 93 | // Log.d(TAG, "onAnimationRepeat: mCurrAnimatorState=" + mCurrAnimatorState); 94 | // if (mCurrAnimatorState > mCount + 1) { 95 | // Log.d(TAG, "onAnimationRepeat: set mCurrAnimatorState to 0"); 96 | // mCurrAnimatorState = 0; 97 | // } 98 | 99 | } 100 | }); 101 | 102 | valueAnimator.setRepeatCount(ValueAnimator.INFINITE); 103 | valueAnimator.setDuration(indicatorSpeed); 104 | list.add(valueAnimator); 105 | 106 | return list; 107 | } 108 | 109 | /** 110 | * 会出现onAnimationRepeat的执行先于mAnimatedValue设置1.0, 111 | * 导致状态改变后的mCurrAnimatorState,对应的mAnimatedValue初始值就是1.0,开始绘制阶段出现闪烁现象 112 | *

113 | * 09-21 13:59:30.594 8977 8977 D ChartRectIndicator2: onAnimationUpdate: mAnimatedValue=0.9992871 114 | * 09-21 13:59:30.594 8977 8977 D ChartRectIndicator2: draw: 0, 0.9992871, 145.3547 115 | * 09-21 13:59:30.609 8977 8977 D ChartRectIndicator2: onAnimationRepeat: 116 | * 09-21 13:59:30.609 8977 8977 D ChartRectIndicator2: onAnimationRepeat: mCurrAnimatorState=1 117 | * 09-21 13:59:30.609 8977 8977 D ChartRectIndicator2: onAnimationUpdate: mAnimatedValue=1.0 118 | * 09-21 13:59:30.610 8977 8977 D ChartRectIndicator2: draw: 1, 1.0, 115.33333 119 | * 09-21 13:59:30.626 8977 8977 D ChartRectIndicator2: onAnimationUpdate: mAnimatedValue=7.1290135E-4 120 | * 09-21 13:59:30.626 8977 8977 D ChartRectIndicator2: draw: 1, 7.1290135E-4, 175.29056 121 | * 09-21 13:59:30.642 8977 8977 D ChartRectIndicator2: onAnimationUpdate: mAnimatedValue=0.0026845932 122 | * 09-21 13:59:30.643 8977 8977 D ChartRectIndicator2: draw: 1, 0.0026845932, 175.17226 123 | */ 124 | private void changeState() { 125 | if (repeatRunned) { 126 | if (mAnimatedValue > 0.9f) { 127 | //do nothing 128 | } else { 129 | repeatRunned = false; 130 | 131 | mCurrAnimatorState++; 132 | Log.d(TAG, "onAnimationRepeat: mCurrAnimatorState=" + mCurrAnimatorState); 133 | if (mCurrAnimatorState > mCount + 1) { 134 | Log.d(TAG, "onAnimationRepeat: set mCurrAnimatorState to 0"); 135 | mCurrAnimatorState = 0; 136 | } 137 | } 138 | } 139 | } 140 | 141 | @Override 142 | protected void draw(Canvas canvas, Paint paint) { 143 | 144 | changeState(); 145 | 146 | float rectWidth = getWidth() / 25; 147 | float rectSpace = rectWidth; 148 | float startX = (getWidth() - (rectWidth * mCount + rectSpace * (mCount - 1))) / 2; 149 | float bottomY = getHeight() / 1.5f; 150 | 151 | for (int i = 0; i < mCount; i++) { 152 | 153 | //mCurrAnimatorState [0, mCount+1] 154 | // =0 不显示第2 3 4 5条 155 | // =1 不显示第3 4 5条 156 | // =2 不显示第4 5条 157 | // =3 不显示第5条 158 | // >= 4 全显示 159 | if (i > mCurrAnimatorState) { 160 | break; 161 | } 162 | 163 | canvas.save(); 164 | 165 | //mAnimatedValue 0 ~ 0.5 ~ 1 166 | //range 0 ~ 0.5 ~ 0 167 | float range = (0.5f - Math.abs(mAnimatedValue - 0.5f)); 168 | float offsetHeight = range * rectMax; 169 | 170 | int j = i % 3;//3条一显示周期 171 | rectF.setEmpty(); 172 | if (i == mCurrAnimatorState) { 173 | //当前,从无到显示 174 | Log.d(TAG, "draw: " + i + ", " + mAnimatedValue + ", " + (bottomY - (j + 1) * rectMax * mAnimatedValue)); 175 | rectF.set(startX + i * (rectWidth + rectSpace), 176 | bottomY - (j + 1) * rectMax * mAnimatedValue, 177 | startX + i * (rectWidth + rectSpace) + rectWidth, 178 | bottomY); 179 | } else { 180 | //其他,抖动效果 181 | rectF.set(startX + i * (rectWidth + rectSpace), 182 | bottomY - (j + 1) * rectMax - offsetHeight, 183 | startX + i * (rectWidth + rectSpace) + rectWidth, 184 | bottomY); 185 | } 186 | canvas.drawRect(rectF, paint); 187 | canvas.restore(); 188 | } 189 | 190 | 191 | } 192 | } 193 | -------------------------------------------------------------------------------- /library/src/main/java/com/example/mzy/indicators/Rect/RectJumpMoveIndicator.java: -------------------------------------------------------------------------------- 1 | package com.example.mzy.indicators.Rect; 2 | 3 | import android.animation.Animator; 4 | import android.animation.ValueAnimator; 5 | import android.content.Context; 6 | import android.graphics.Canvas; 7 | import android.graphics.Color; 8 | import android.graphics.Paint; 9 | import android.graphics.RectF; 10 | import android.util.Log; 11 | import android.view.animation.LinearInterpolator; 12 | 13 | import com.example.mzy.indicators.IndicatorDrawable; 14 | 15 | import java.util.ArrayList; 16 | 17 | /** 18 | * Created by mazhengyang on 18-12-7. 19 | */ 20 | 21 | public class RectJumpMoveIndicator extends IndicatorDrawable { 22 | 23 | //TODO 暂未解决向右移动,倒数第二个方块伸缩效果,向左移动,顺数第二个方块伸缩效果 24 | 25 | private final String TAG = RectJumpMoveIndicator.class.getSimpleName(); 26 | 27 | private final int mCount = 5; 28 | 29 | private int mState = 0;//0静止,1向右移动,2向左移动 30 | private float mPreviousAnimatedValue = 0.0f; 31 | private float mAnimatedValue = 0.0f; 32 | 33 | private RectF rectF = new RectF(); 34 | 35 | private boolean drawAssist = false; 36 | 37 | private int currentJumpIndex = 0; 38 | 39 | public RectJumpMoveIndicator(Context context, int indicatorColor, int indicatorSpeed) { 40 | Log.d(TAG, "RectJumpMoveIndicator: "); 41 | this.indicatorColor = indicatorColor; 42 | this.indicatorSpeed = indicatorSpeed; 43 | if (indicatorSpeed <= 0) { 44 | this.indicatorSpeed = 2000; 45 | } 46 | 47 | init(context); 48 | } 49 | 50 | @Override 51 | protected void init(Context context) { 52 | Log.d(TAG, "init: "); 53 | mPaint.setAntiAlias(true); 54 | mPaint.setStyle(Paint.Style.FILL); 55 | mPaint.setStrokeWidth(dip2px(context, 1.0f)); 56 | mPaint.setColor(indicatorColor); 57 | } 58 | 59 | @Override 60 | protected ArrayList getAnimation() { 61 | 62 | ArrayList list = new ArrayList<>(); 63 | 64 | ValueAnimator valueAnimator = ValueAnimator.ofFloat(0.0f, 0.0f, 1.0f, 1.0f); 65 | valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 66 | @Override 67 | public void onAnimationUpdate(ValueAnimator valueAnimator) { 68 | mAnimatedValue = ((float) valueAnimator.getAnimatedValue()); 69 | // Log.d(TAG, "onAnimationUpdate: mAnimatedValue=" + mAnimatedValue); 70 | 71 | if (mAnimatedValue - mPreviousAnimatedValue > 0) { 72 | mState = 1; 73 | } else if (mAnimatedValue - mPreviousAnimatedValue < 0) { 74 | mState = 2; 75 | } else { 76 | mState = 0; 77 | } 78 | mPreviousAnimatedValue = mAnimatedValue; 79 | 80 | invalidateSelf(); 81 | } 82 | }); 83 | 84 | valueAnimator.setInterpolator(new LinearInterpolator()); 85 | valueAnimator.setRepeatMode(ValueAnimator.REVERSE); 86 | valueAnimator.setRepeatCount(ValueAnimator.INFINITE); 87 | valueAnimator.setDuration(indicatorSpeed); 88 | list.add(valueAnimator); 89 | 90 | return list; 91 | } 92 | 93 | private void drawAssist(Canvas canvas, Paint paint) { 94 | if (drawAssist) { 95 | canvas.drawColor(Color.RED); 96 | 97 | canvas.drawLine(getWidth() / 2, 0, getWidth() / 2, getHeight(), paint); 98 | canvas.drawLine(0, getHeight() / 2, getWidth(), getHeight() / 2, paint); 99 | } 100 | } 101 | 102 | @Override 103 | protected void draw(Canvas canvas, Paint paint) { 104 | canvas.save(); 105 | drawAssist(canvas, paint); 106 | drawRect(canvas, paint); 107 | canvas.restore(); 108 | } 109 | 110 | private void drawRect(Canvas canvas, Paint paint) { 111 | 112 | float rectWidth = getWidth() / 15; 113 | float rectSpace = getWidth() / 30; 114 | float canMoveMax = (rectWidth + rectSpace) * (mCount - 1); 115 | float startX = (getWidth() - (canMoveMax + rectWidth)) / 2; 116 | 117 | if (drawAssist) { 118 | for (int i = 0; i < mCount; i++) { 119 | float left_i = startX + i * (rectWidth + rectSpace); //第i个方块的left 120 | canvas.drawLine(left_i, 100, left_i, getHeight() - 100, paint); 121 | } 122 | } 123 | 124 | //静止状态,直接画5个方块 125 | if (mState == 0) { 126 | for (int i = 0; i < mCount; i++) { 127 | float left_i = startX + i * (rectWidth + rectSpace); 128 | float top = getHeight() / 2 - rectWidth / 2; 129 | rectF.setEmpty(); 130 | rectF.set(left_i, top, 131 | left_i + rectWidth, 132 | getHeight() / 2 + rectWidth / 2); 133 | canvas.drawRoundRect(rectF, 5, 5, paint); 134 | 135 | } 136 | return; 137 | } 138 | 139 | //运动状态 140 | 141 | float movedRectX = startX + canMoveMax * mAnimatedValue;//横向移动的方块,目前移动的x轴距离 142 | float moved_ = (canMoveMax * mAnimatedValue) % (rectWidth + rectSpace); 143 | float percent = moved_ / (rectWidth + rectSpace);//当前移动百分比(相对相邻两方块距离d而言) 144 | 145 | //横向移动的方块 146 | rectF.setEmpty(); 147 | rectF.set(movedRectX, 148 | getHeight() / 2 - rectWidth / 2, 149 | movedRectX + rectWidth, 150 | getHeight() / 2 + rectWidth / 2); 151 | canvas.drawRoundRect(rectF, 5, 5, paint); 152 | 153 | //当前移动的方块 154 | int currentMoveIndex = 0; 155 | 156 | //当前跳动的方块 157 | for (int i = 0; i < mCount; i++) { 158 | 159 | float left_i = startX + i * (rectWidth + rectSpace); 160 | float left_next_i = startX + (i + 1) * (rectWidth + rectSpace); 161 | 162 | if (movedRectX >= left_i && movedRectX <= left_next_i) { 163 | 164 | /** 165 | * A B 166 | * o___o___o___o___o 167 | * | d | 168 | * 169 | * 相对相邻两方块距离 d = (B方块left - A方块left,即 rectWidth + rectSpace) 170 | * A目前的移动距离 moved_(相对相邻两方块距离d而言) / d = B目前逆时针旋转的角度 degree / 180 171 | * 172 | * degree = moved_ * 180 / d 173 | * 174 | * 其他情况类似推导 175 | */ 176 | 177 | int degree = -(int) (moved_ * 180 / (rectWidth + rectSpace)); 178 | float radius = rectWidth / 2 + rectSpace / 2;//跳动半径 179 | double angle = degree * Math.PI / 180; 180 | float x = radius * (float) Math.cos(angle); 181 | float y = radius * (float) Math.sin(angle); 182 | 183 | float centerX = left_i + rectWidth + rectSpace / 2;//两方块中心点 184 | 185 | float l = centerX + x - rectWidth / 2; 186 | float t = getHeight() / 2 - rectWidth / 2 + y; 187 | float r = l + rectWidth; 188 | float b = t + rectWidth; 189 | 190 | rectF.setEmpty(); 191 | rectF.set(l, t, r, b); 192 | 193 | if (mState == 1) { 194 | currentJumpIndex = i + 1; 195 | currentMoveIndex = i; 196 | } else if (mState == 2) { 197 | currentJumpIndex = i; 198 | currentMoveIndex = i + 1; 199 | } 200 | 201 | canvas.drawRoundRect(rectF, 5, 5, paint); 202 | break; 203 | } 204 | } 205 | 206 | //其他方块 207 | for (int i = 0; i < mCount; i++) { 208 | 209 | if (i == currentJumpIndex 210 | || i == currentMoveIndex) { 211 | continue; 212 | } 213 | 214 | float left_i = startX + i * (rectWidth + rectSpace); 215 | 216 | float top = getHeight() / 2 - rectWidth / 2; 217 | 218 | int shakeIndex = 0; 219 | if (mState == 1) { 220 | shakeIndex = currentJumpIndex - 2; 221 | } else if (mState == 2) { 222 | shakeIndex = currentJumpIndex + 2; 223 | } 224 | 225 | if (i == shakeIndex) { 226 | if (percent <= 0.5) {//下压状态 227 | top += (rectWidth * percent); 228 | } else if (percent > 0.5 && percent <= 1.0) {//弹起状态 229 | top += (rectWidth * (1 - percent)); 230 | } 231 | } 232 | 233 | rectF.setEmpty(); 234 | rectF.set(left_i, top, 235 | left_i + rectWidth, 236 | getHeight() / 2 + rectWidth / 2); 237 | canvas.drawRoundRect(rectF, 5, 5, paint); 238 | } 239 | } 240 | 241 | } 242 | -------------------------------------------------------------------------------- /library/src/main/java/com/example/mzy/indicators/Star/StarModel.java: -------------------------------------------------------------------------------- 1 | package com.example.mzy.indicators.Star; 2 | 3 | import android.graphics.RectF; 4 | 5 | /** 6 | * Holds all vertexes (x,y) and bounds (outerRect) info about a drawing Star. 7 | *

8 | *

[Based Idea or Concept]

9 | *

10 | * ## Standard Coordinate:
11 | * The coordinate is —— toward right for x+ ,toward up for y+ . 12 | *

13 | * ## 5 outer vertexes
14 | * The outer circle's (means "circumcircle") radius is 1f, original point O is the star's center, 15 | * so, the 5 vertexes at 5 outer corner is (from top A, at clockwise order): 16 | *

17 | *

  • A(0,1)
  • 18 | *
  • B(cos18°,sin18°)
  • 19 | *
  • C(cos54°,-sin54°)
  • 20 | *
  • D(-cos54°,-sin54°)
  • 21 | *
  • E(-cos18°,sin18°)
  • 22 | */ 23 | class StarModel { 24 | 25 | private static final String TAG = "StarModel"; 26 | public static final float DEFAULT_THICKNESS = 0.5f; 27 | public static final float MIN_THICKNESS = 0.3f; 28 | public static final float MAX_THICKNESS = 0.9f; 29 | public static final float DEFAULT_SCALE_FACTOR = 0.9511f; 30 | private float currentScaleFactor = DEFAULT_SCALE_FACTOR; 31 | private RectF outerRect = new RectF(); 32 | private float currentThicknessFactor = DEFAULT_THICKNESS; 33 | 34 | /** 35 | * @param thicknessFactor see {@link #setThickness(float)} 36 | */ 37 | public StarModel(float thicknessFactor) { 38 | reset(thicknessFactor); 39 | } 40 | 41 | public StarModel() { 42 | this(DEFAULT_THICKNESS); 43 | } 44 | 45 | /** 46 | * Reset all vertexes values to based on radius-1f, will call adjustCoordinate() automatically, 47 | * So after reset() the Coordinate is match with Android. 48 | * 49 | * @param thickness {@link #setThicknessOnStandardCoordinate } 50 | */ 51 | private void reset(float thickness) { 52 | currentScaleFactor = DEFAULT_SCALE_FACTOR; 53 | initAllVertexesToStandard(); 54 | updateOuterRect(); 55 | setThicknessOnStandardCoordinate(thickness); 56 | adjustCoordinate(); 57 | } 58 | 59 | public void setDrawingOuterRect(float left, float top, float height) { 60 | // ScaleFactor=1f means width is 1f 61 | float resizeFactor = height / aspectRatio; 62 | offsetStar(-outerRect.left, -outerRect.top); 63 | changeScaleFactor(resizeFactor); 64 | offsetStar(left, top); 65 | updateOuterRect(); 66 | } 67 | 68 | public void moveStarTo(float left, float top) { 69 | float offsetX = left - outerRect.left; 70 | float offsetY = left - outerRect.top; 71 | offsetStar(offsetX, offsetY); 72 | updateOuterRect(); 73 | } 74 | 75 | // region vertexes fields 76 | 77 | /** 78 | * 10 float values for star's 5 vertex's (x,y) —— outer circle's radius is 1f ( 79 | * NOTE: In the "Standard Coordinate".) , first vertex is for top corner, in clockwise order. 80 | */ 81 | private static final float[] starVertexes = new float[]{ 82 | -0.9511f, 0.3090f, // E (left) 83 | 0.0000f, 1.0000f, // A (top vertex) 84 | 0.9511f, 0.3090f, // B (right) 85 | 0.5878f, -0.8090f, // C (bottom right) 86 | -0.5878f, -0.8090f, // D (bottom left) 87 | }; 88 | 89 | /** 90 | * ratio = height / width. 91 | * width is think as 1f, because the star's width is lager. 92 | * NOTE: In the "Standard Coordinate" 93 | */ 94 | private static final float aspectRatio 95 | = (starVertexes[3] - starVertexes[7]) / (starVertexes[4] - starVertexes[0]); 96 | 97 | /** 98 | * firstVertex is vertex: E (very left one) 99 | * 100 | * @see StarModel 101 | */ 102 | private VertexF firstVertex; 103 | 104 | /** 105 | * All star vertexes, from the most left one. then clockwise. 106 | *

    107 | * NOTE: init or update by {@link #initAllVertexesToStandard() } 108 | * 109 | * @see #firstVertex 110 | * @see #starVertexes 111 | */ 112 | private VertexF[] vertexes; 113 | 114 | // endregion 115 | 116 | private void initAllVertexesToStandard() { 117 | if (firstVertex == null) { 118 | firstVertex = new VertexF(starVertexes[0], starVertexes[1]); 119 | } else { 120 | firstVertex.x = starVertexes[0]; 121 | firstVertex.y = starVertexes[1]; 122 | } 123 | 124 | // create all 10 vertexes into #vertexes 125 | if (vertexes == null) { 126 | vertexes = new VertexF[10]; 127 | vertexes[0] = firstVertex; 128 | 129 | for (int i = 1; i < 10; i++) { 130 | vertexes[i] = new VertexF(); 131 | vertexes[i - 1].next = vertexes[i]; 132 | } 133 | 134 | // link tail and head 135 | vertexes[9].next = vertexes[0]; 136 | } 137 | 138 | // update all 5 outer vertexes. 139 | VertexF current = firstVertex; 140 | for (int i = 0; i < 5; i++) { 141 | current.x = starVertexes[i * 2]; 142 | current.y = starVertexes[i * 2 + 1]; 143 | 144 | current = current.next.next; 145 | } 146 | 147 | // update all 5 inner vertexes. 148 | VertexF prevOuter = firstVertex; 149 | for (int i = 0; i < 5; i++) { 150 | VertexF innerV = prevOuter.next; 151 | 152 | innerV.x = (prevOuter.x + innerV.next.x) / 2f; 153 | innerV.y = (prevOuter.y + innerV.next.y) / 2f; 154 | 155 | prevOuter = innerV.next; 156 | } 157 | } 158 | 159 | /** 160 | * Get vertex at index in {@link #vertexes} 161 | * 162 | * @param index see {@link #vertexes} 163 | */ 164 | public VertexF getVertex(int index) { 165 | return vertexes[index]; 166 | } 167 | 168 | public RectF getOuterRect() { 169 | return new RectF(outerRect); 170 | } 171 | 172 | /** 173 | * Keep the star's outer bounds exactly. 174 | * NOTE: call this after any vertex value changed. 175 | */ 176 | private void updateOuterRect() { 177 | outerRect.top = vertexes[2].y; 178 | outerRect.right = vertexes[4].x; 179 | outerRect.bottom = vertexes[8].y; 180 | outerRect.left = vertexes[0].x; 181 | } 182 | 183 | private void offsetStar(float left, float top) { 184 | for (int i = 0; i < vertexes.length; i++) { 185 | vertexes[i].x += left; 186 | vertexes[i].y += top; 187 | } 188 | } 189 | 190 | private void changeScaleFactor(float newFactor) { 191 | float scale = newFactor / currentScaleFactor; 192 | if (scale == 1f) return; 193 | for (int i = 0; i < vertexes.length; i++) { 194 | vertexes[i].x *= scale; 195 | vertexes[i].y *= scale; 196 | } 197 | currentScaleFactor = newFactor; 198 | } 199 | 200 | /** 201 | * change the thickness of star. 202 | * value {@link #DEFAULT_THICKNESS}is about to make a standard star. 203 | * 204 | * @param factor between {@link #MIN_THICKNESS} and {@link #MAX_THICKNESS}. 205 | */ 206 | public void setThickness(float factor) { 207 | if (currentThicknessFactor == factor) return; 208 | float oldScale = currentScaleFactor; 209 | float left = outerRect.left; 210 | float top = outerRect.top; 211 | 212 | reset(factor); 213 | 214 | changeScaleFactor(oldScale); 215 | moveStarTo(left, top); 216 | } 217 | 218 | private void setThicknessOnStandardCoordinate(float thicknessFactor) { 219 | if (thicknessFactor < MIN_THICKNESS) { 220 | thicknessFactor = MIN_THICKNESS; 221 | } else if (thicknessFactor > MAX_THICKNESS) { 222 | thicknessFactor = MAX_THICKNESS; 223 | } 224 | 225 | for (int i = 1; i < vertexes.length; i += 2) { 226 | vertexes[i].x *= thicknessFactor; 227 | vertexes[i].y *= thicknessFactor; 228 | } 229 | 230 | currentThicknessFactor = thicknessFactor; 231 | } 232 | 233 | /** 234 | * reverse Y, and move to y=0 235 | */ 236 | private void adjustCoordinate() { 237 | float offsetX = -outerRect.left; 238 | float offsetY = outerRect.top; 239 | 240 | for (int i = 0; i < vertexes.length; i++) { 241 | vertexes[i].y = -vertexes[i].y + offsetY; 242 | vertexes[i].x += offsetX; 243 | 244 | // standard value is in radius = 1f, so.. 245 | vertexes[i].x /= 2f; 246 | vertexes[i].y /= 2f; 247 | } 248 | 249 | updateOuterRect(); 250 | } 251 | 252 | /** 253 | * ratio = height / width. width is think as 1f, because the star's width is lager. 254 | * NOTE: In the "Standard Coordinate" 255 | * 256 | * @return ratio = height / width. 257 | */ 258 | public static float getOuterRectAspectRatio() { 259 | return aspectRatio; 260 | } 261 | 262 | public static float getStarWidth(float starHeight) { 263 | return starHeight / getOuterRectAspectRatio(); 264 | } 265 | } 266 | -------------------------------------------------------------------------------- /library/src/main/java/com/example/mzy/indicators/LoadingIndicator.java: -------------------------------------------------------------------------------- 1 | package com.example.mzy.indicators; 2 | 3 | import android.content.Context; 4 | import android.content.res.TypedArray; 5 | import android.graphics.Canvas; 6 | import android.graphics.Color; 7 | import android.graphics.Rect; 8 | import android.graphics.drawable.Drawable; 9 | import android.text.TextUtils; 10 | import android.util.AttributeSet; 11 | import android.util.Log; 12 | import android.view.View; 13 | 14 | import com.example.mzy.indicators.Circle.ArcRotateIndicator; 15 | import com.example.mzy.indicators.Circle.ArcRotateScaleIndicator; 16 | import com.example.mzy.indicators.Circle.BasketBallIndicator; 17 | import com.example.mzy.indicators.Circle.CircleCollisionIndicator; 18 | import com.example.mzy.indicators.Circle.CircleJumpIndicator; 19 | import com.example.mzy.indicators.Circle.CircleRotateIndicator; 20 | import com.example.mzy.indicators.Circle.CircleRotateScaleIndicator; 21 | import com.example.mzy.indicators.Circle.CircleScaleIndicator; 22 | import com.example.mzy.indicators.Circle.CircleTriangleIndicator; 23 | import com.example.mzy.indicators.Circle.CircleWaveIndicator; 24 | import com.example.mzy.indicators.Circle.DropIndicator; 25 | import com.example.mzy.indicators.Circle.TrackIndicator; 26 | import com.example.mzy.indicators.Rect.ChartRectIndicator1; 27 | import com.example.mzy.indicators.Rect.ChartRectIndicator2; 28 | import com.example.mzy.indicators.Rect.ParallelogramIndicator; 29 | import com.example.mzy.indicators.Rect.RectJumpMoveIndicator; 30 | import com.example.mzy.indicators.Star.StarIndicator; 31 | 32 | /** 33 | * Created by mazhengyang on 18-9-18. 34 | */ 35 | 36 | public class LoadingIndicator extends View { 37 | 38 | private final String TAG = LoadingIndicator.class.getSimpleName(); 39 | 40 | private int mMinWidth; 41 | private int mMaxWidth; 42 | private int mMinHeight; 43 | private int mMaxHeight; 44 | private String indicatorName; 45 | private int indicatorColor; 46 | private int indicatorSpeed; 47 | 48 | private IndicatorDrawable mIndicator; 49 | 50 | public LoadingIndicator(Context context) { 51 | super(context); 52 | init(context, null, 0, 0); 53 | } 54 | 55 | public LoadingIndicator(Context context, AttributeSet attrs) { 56 | super(context, attrs); 57 | init(context, attrs, 0, R.style.LoadingIndicator); 58 | } 59 | 60 | public LoadingIndicator(Context context, AttributeSet attrs, int defStyleAttr) { 61 | super(context, attrs, defStyleAttr); 62 | init(context, attrs, defStyleAttr, R.style.LoadingIndicator); 63 | } 64 | 65 | private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 66 | 67 | TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.LoadingIndicator, defStyleAttr, defStyleRes); 68 | mMinWidth = ta.getDimensionPixelSize(R.styleable.LoadingIndicator_minWidth, 60); 69 | mMaxWidth = ta.getDimensionPixelSize(R.styleable.LoadingIndicator_maxWidth, 60); 70 | mMinHeight = ta.getDimensionPixelSize(R.styleable.LoadingIndicator_minHeight, 60); 71 | mMaxHeight = ta.getDimensionPixelSize(R.styleable.LoadingIndicator_maxHeight, 60); 72 | indicatorName = ta.getString(R.styleable.LoadingIndicator_indicatorName); 73 | indicatorColor = ta.getColor(R.styleable.LoadingIndicator_indicatorColor, Color.WHITE); 74 | indicatorSpeed = ta.getInteger(R.styleable.LoadingIndicator_indicatorSpeed, 0); 75 | ta.recycle(); 76 | 77 | Log.d(TAG, "init: density=" + context.getResources().getDisplayMetrics().density); 78 | Log.d(TAG, "init: mMinWidth=" + mMinWidth + ", mMaxWidth=" + mMaxWidth); 79 | Log.d(TAG, "init: mMinHeight=" + mMinHeight + ", mMaxHeight=" + mMaxHeight); 80 | Log.d(TAG, "init: indicatorName=" + indicatorName); 81 | Log.d(TAG, "init: indicatorColor=" + indicatorColor); 82 | Log.d(TAG, "init: indicatorSpeed=" + indicatorSpeed); 83 | 84 | IndicatorDrawable indicatorDrawable = getIndicator(indicatorName, context); 85 | // if (indicatorDrawable == null) { 86 | // Log.e(TAG, "init: indicatorDrawable is null, set default: BasketBallIndicator"); 87 | // indicatorDrawable = new BasketBallIndicator(context, indicatorColor); 88 | // } 89 | indicatorDrawable.setCallback(this); 90 | mIndicator = indicatorDrawable; 91 | } 92 | 93 | public IndicatorDrawable getIndicator(String indicatorName, Context context) { 94 | if (TextUtils.isEmpty(indicatorName)) { 95 | return null; 96 | } 97 | 98 | if ("BasketBallIndicator".equals(indicatorName)) { 99 | return new BasketBallIndicator(context, indicatorColor, indicatorSpeed); 100 | } else if ("StarIndicator".equals(indicatorName)) { 101 | return new StarIndicator(context, indicatorColor, indicatorSpeed); 102 | } else if ("CircleScaleIndicator".equals(indicatorName)) { 103 | return new CircleScaleIndicator(context, indicatorColor, indicatorSpeed); 104 | } else if ("CircleWaveIndicator".equals(indicatorName)) { 105 | return new CircleWaveIndicator(context, indicatorColor, indicatorSpeed); 106 | } else if ("CircleJumpIndicator".equals(indicatorName)) { 107 | return new CircleJumpIndicator(context, indicatorColor, indicatorSpeed); 108 | } else if ("CircleCollisionIndicator".equals(indicatorName)) { 109 | return new CircleCollisionIndicator(context, indicatorColor, indicatorSpeed); 110 | } else if ("DropIndicator".equals(indicatorName)) { 111 | return new DropIndicator(context, indicatorColor, indicatorSpeed); 112 | } else if ("TrackIndicator".equals(indicatorName)) { 113 | return new TrackIndicator(context, indicatorColor, indicatorSpeed); 114 | } else if ("CircleRotateScaleIndicator".equals(indicatorName)) { 115 | return new CircleRotateScaleIndicator(context, indicatorColor, indicatorSpeed); 116 | } else if ("CircleTriangleIndicator".equals(indicatorName)) { 117 | return new CircleTriangleIndicator(context, indicatorColor, indicatorSpeed); 118 | } else if ("ChartRectIndicator1".equals(indicatorName)) { 119 | return new ChartRectIndicator1(context, indicatorColor, indicatorSpeed); 120 | } else if ("ChartRectIndicator2".equals(indicatorName)) { 121 | return new ChartRectIndicator2(context, indicatorColor, indicatorSpeed); 122 | } else if ("ArcRotateIndicator".equals(indicatorName)) { 123 | return new ArcRotateIndicator(context, indicatorColor, indicatorSpeed); 124 | } else if ("RectJumpMoveIndicator".equals(indicatorName)) { 125 | return new RectJumpMoveIndicator(context, indicatorColor, indicatorSpeed); 126 | } else if ("ArcRotateScaleIndicator".equals(indicatorName)) { 127 | return new ArcRotateScaleIndicator(context, indicatorColor, indicatorSpeed); 128 | } else if ("ParallelogramIndicator".equals(indicatorName)) { 129 | return new ParallelogramIndicator(context, indicatorColor, indicatorSpeed); 130 | } else if ("CircleRotateIndicator".equals(indicatorName)) { 131 | return new CircleRotateIndicator(context, indicatorColor, indicatorSpeed); 132 | } 133 | return null; 134 | } 135 | 136 | @Override 137 | protected boolean verifyDrawable(Drawable who) { 138 | return who == mIndicator || super.verifyDrawable(who); 139 | } 140 | 141 | @Override 142 | public void invalidateDrawable(Drawable dr) { 143 | if (verifyDrawable(dr)) { 144 | Rect dirty = dr.getBounds(); 145 | int scrollX = getScrollX() + getPaddingLeft(); 146 | int scrollY = getScrollY() + getPaddingTop(); 147 | 148 | invalidate(dirty.left + scrollX, dirty.top + scrollY, 149 | dirty.right + scrollX, dirty.bottom + scrollY); 150 | } else { 151 | super.invalidateDrawable(dr); 152 | } 153 | } 154 | 155 | @Override 156 | protected void onDraw(Canvas canvas) { 157 | super.onDraw(canvas); 158 | 159 | int saveCount = canvas.save(); 160 | mIndicator.draw(canvas); 161 | canvas.restoreToCount(saveCount); 162 | } 163 | 164 | @Override 165 | protected void onSizeChanged(int w, int h, int oldw, int oldh) { 166 | super.onSizeChanged(w, h, oldw, oldh); 167 | updateDrawableBounds(w, h); 168 | } 169 | 170 | private void updateDrawableBounds(int w, int h) { 171 | 172 | w = w - (getPaddingRight() + getPaddingLeft()); 173 | h = h - (getPaddingTop() + getPaddingBottom()); 174 | 175 | Log.d(TAG, "updateDrawableBounds: w=" + w + ", h=" + h); 176 | 177 | int left = 0; 178 | int top = 0; 179 | int right = w; 180 | int bottom = h; 181 | 182 | if (mIndicator != null) { 183 | int intrinsicWidth = mIndicator.getIntrinsicWidth(); 184 | int intrinsicHeight = mIndicator.getIntrinsicHeight(); 185 | float intrinsicAspect = (float) intrinsicWidth / intrinsicHeight; 186 | float boundAspect = (float) w / h; 187 | if (intrinsicAspect != boundAspect) { 188 | if (boundAspect > intrinsicAspect) { 189 | // New width is larger. Make it smaller to match height. 190 | final int width = (int) (h * intrinsicAspect); 191 | left = (w - width) / 2; 192 | right = left + width; 193 | } else { 194 | // New height is larger. Make it smaller to match width. 195 | final int height = (int) (w * (1 / intrinsicAspect)); 196 | top = (h - height) / 2; 197 | bottom = top + height; 198 | } 199 | } 200 | Log.d(TAG, "updateDrawableBounds: left=" + left + ", top=" + top + ", right=" 201 | + right + ", bottom=" + bottom); 202 | mIndicator.setBounds(left, top, right, bottom); 203 | } 204 | } 205 | 206 | @Override 207 | protected synchronized void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 208 | int dw = 0; 209 | int dh = 0; 210 | 211 | final Drawable d = mIndicator; 212 | if (d != null) { 213 | Log.d(TAG, "onMeasure: d.getIntrinsicWidth()=" + d.getIntrinsicWidth()); 214 | Log.d(TAG, "onMeasure: d.getIntrinsicHeight()=" + d.getIntrinsicHeight()); 215 | 216 | dw = Math.max(mMinWidth, Math.min(mMaxWidth, d.getIntrinsicWidth())); 217 | dh = Math.max(mMinHeight, Math.min(mMaxHeight, d.getIntrinsicHeight())); 218 | } 219 | 220 | dw = dw + (getPaddingLeft() + getPaddingRight()); 221 | dh = dh + (getPaddingTop() + getPaddingBottom()); 222 | 223 | final int measuredWidth = resolveSizeAndState(dw, widthMeasureSpec, 0); 224 | final int measuredHeight = resolveSizeAndState(dh, heightMeasureSpec, 0); 225 | setMeasuredDimension(measuredWidth, measuredHeight); 226 | } 227 | 228 | @Override 229 | protected void onAttachedToWindow() { 230 | super.onAttachedToWindow(); 231 | startAnimation(); 232 | } 233 | 234 | @Override 235 | protected void onDetachedFromWindow() { 236 | super.onDetachedFromWindow(); 237 | stopAnimation(); 238 | } 239 | // 240 | // @Override 241 | // protected void onVisibilityChanged(@NonNull View changedView, int visibility) { 242 | // super.onVisibilityChanged(changedView, visibility); 243 | // if (visibility == View.VISIBLE) { 244 | // startAnimation(); 245 | // } else { 246 | // stopAnimation(); 247 | // } 248 | // } 249 | 250 | private void startAnimation() { 251 | if (getVisibility() != VISIBLE) { 252 | return; 253 | } 254 | Log.d(TAG, "startAnimation: "); 255 | mIndicator.start(); 256 | postInvalidate(); 257 | } 258 | 259 | private void stopAnimation() { 260 | Log.d(TAG, "stopAnimation: "); 261 | mIndicator.stop(); 262 | postInvalidate(); 263 | } 264 | 265 | } 266 | --------------------------------------------------------------------------------