├── .gitignore ├── .idea ├── codeStyles │ └── Project.xml ├── gradle.xml ├── misc.xml ├── runConfigurations.xml └── vcs.xml ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── mario │ │ └── shapeloading │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── mario │ │ │ └── shapeloading │ │ │ └── MainActivity.java │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ └── ic_launcher_background.xml │ │ ├── layout │ │ └── activity_main.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.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 │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── mario │ └── shapeloading │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── library ├── .gitignore ├── build.gradle ├── consumer-rules.pro ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── mario │ │ └── library │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── mario │ │ │ └── library │ │ │ ├── drawable │ │ │ ├── DouYinLoadingDrawable.java │ │ │ ├── ShapeLoadingDrawable.java │ │ │ └── ThreeBallsLoadingDrawable.java │ │ │ └── view │ │ │ ├── LoadArrowView.java │ │ │ └── LoadingCircleView.java │ └── res │ │ ├── drawable │ │ └── arrow.jpg │ │ └── values │ │ └── strings.xml │ └── test │ └── java │ └── com │ └── mario │ └── library │ └── ExampleUnitTest.java └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/caches 5 | /.idea/libraries 6 | /.idea/modules.xml 7 | /.idea/workspace.xml 8 | /.idea/navEditor.xml 9 | /.idea/assetWizardSettings.xml 10 | .DS_Store 11 | /build 12 | /captures 13 | .externalNativeBuild 14 | .cxx 15 | -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 |
7 | 8 | 9 | 10 | xmlns:android 11 | 12 | ^$ 13 | 14 | 15 | 16 |
17 |
18 | 19 | 20 | 21 | xmlns:.* 22 | 23 | ^$ 24 | 25 | 26 | BY_NAME 27 | 28 |
29 |
30 | 31 | 32 | 33 | .*:id 34 | 35 | http://schemas.android.com/apk/res/android 36 | 37 | 38 | 39 |
40 |
41 | 42 | 43 | 44 | .*:name 45 | 46 | http://schemas.android.com/apk/res/android 47 | 48 | 49 | 50 |
51 |
52 | 53 | 54 | 55 | name 56 | 57 | ^$ 58 | 59 | 60 | 61 |
62 |
63 | 64 | 65 | 66 | style 67 | 68 | ^$ 69 | 70 | 71 | 72 |
73 |
74 | 75 | 76 | 77 | .* 78 | 79 | ^$ 80 | 81 | 82 | BY_NAME 83 | 84 |
85 |
86 | 87 | 88 | 89 | .* 90 | 91 | http://schemas.android.com/apk/res/android 92 | 93 | 94 | ANDROID_ATTRIBUTE_ORDER 95 | 96 |
97 |
98 | 99 | 100 | 101 | .* 102 | 103 | .* 104 | 105 | 106 | BY_NAME 107 | 108 |
109 |
110 |
111 |
112 |
113 |
-------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 15 | 16 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 14 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ShapeLoading 2 | 3 | ### 效果图 4 | 5 | #### ShapeLoadingDrawable 6 | ![](https://upload-images.jianshu.io/upload_images/20061149-76a60334b2d9594b.gif) 7 | 8 | #### ThreeBallsLoadingDrawable 9 | ![](https://upload-images.jianshu.io/upload_images/20061149-f4e7b18ef3831240.gif) 10 | 11 | #### DouYinLoadingDrawable 12 | ![](https://upload-images.jianshu.io/upload_images/20061149-db8f1fd660dedcab.gif) 13 | 14 | #### LoadingCircleView 15 | ![](https://upload-images.jianshu.io/upload_images/20061149-24b9c8287cc1d2cb.gif) 16 | 17 | #### LoadingArrowView 18 | ![](https://upload-images.jianshu.io/upload_images/20061149-a1f543f06a66b8f0.gif) 19 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 29 5 | buildToolsVersion "30.0.1" 6 | defaultConfig { 7 | applicationId "com.mario.shapeloading" 8 | minSdkVersion 21 9 | targetSdkVersion 29 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | implementation fileTree(dir: 'libs', include: ['*.jar']) 24 | implementation 'androidx.appcompat:appcompat:1.2.0' 25 | implementation 'androidx.constraintlayout:constraintlayout:2.0.2' 26 | testImplementation 'junit:junit:4.12' 27 | androidTestImplementation 'androidx.test.ext:junit:1.1.2' 28 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' 29 | implementation project(path: ':library') 30 | } 31 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/mario/shapeloading/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.mario.shapeloading; 2 | 3 | import android.content.Context; 4 | 5 | import androidx.test.platform.app.InstrumentationRegistry; 6 | import androidx.test.ext.junit.runners.AndroidJUnit4; 7 | 8 | import org.junit.Test; 9 | import org.junit.runner.RunWith; 10 | 11 | import static org.junit.Assert.*; 12 | 13 | /** 14 | * Instrumented test, which will execute on an Android device. 15 | * 16 | * @see Testing documentation 17 | */ 18 | @RunWith(AndroidJUnit4.class) 19 | public class ExampleInstrumentedTest { 20 | @Test 21 | public void useAppContext() { 22 | // Context of the app under test. 23 | Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); 24 | 25 | assertEquals("com.mario.shapeloading", appContext.getPackageName()); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/java/com/mario/shapeloading/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.mario.shapeloading; 2 | 3 | import androidx.appcompat.app.AppCompatActivity; 4 | 5 | import android.os.Bundle; 6 | import android.widget.ImageView; 7 | 8 | import com.mario.library.drawable.DouYinLoadingDrawable; 9 | import com.mario.library.drawable.ShapeLoadingDrawable; 10 | import com.mario.library.drawable.ThreeBallsLoadingDrawable; 11 | 12 | public class MainActivity extends AppCompatActivity { 13 | 14 | @Override 15 | protected void onCreate(Bundle savedInstanceState) { 16 | super.onCreate(savedInstanceState); 17 | setContentView(R.layout.activity_main); 18 | ImageView imageView = findViewById(R.id.iv_shape_loading); 19 | 20 | // ShapeLoadingDrawable shapeLoadingDrawable = new ShapeLoadingDrawable(); 21 | // imageView.setImageDrawable(shapeLoadingDrawable); 22 | // shapeLoadingDrawable.start(); 23 | 24 | // ThreeBallsLoadingDrawable threeBallsLoadingDrawable = new ThreeBallsLoadingDrawable(); 25 | // imageView.setImageDrawable(threeBallsLoadingDrawable); 26 | // threeBallsLoadingDrawable.start(); 27 | 28 | DouYinLoadingDrawable douYinLoadingDrawable = new DouYinLoadingDrawable(); 29 | imageView.setImageDrawable(douYinLoadingDrawable); 30 | douYinLoadingDrawable.start(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /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 | 8 | 9 | 17 | 18 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mariolu0605/ShapeLoading/80b34a9f9d7befec3271b92e43a9f98f3092a942/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mariolu0605/ShapeLoading/80b34a9f9d7befec3271b92e43a9f98f3092a942/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mariolu0605/ShapeLoading/80b34a9f9d7befec3271b92e43a9f98f3092a942/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mariolu0605/ShapeLoading/80b34a9f9d7befec3271b92e43a9f98f3092a942/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mariolu0605/ShapeLoading/80b34a9f9d7befec3271b92e43a9f98f3092a942/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mariolu0605/ShapeLoading/80b34a9f9d7befec3271b92e43a9f98f3092a942/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mariolu0605/ShapeLoading/80b34a9f9d7befec3271b92e43a9f98f3092a942/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mariolu0605/ShapeLoading/80b34a9f9d7befec3271b92e43a9f98f3092a942/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mariolu0605/ShapeLoading/80b34a9f9d7befec3271b92e43a9f98f3092a942/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mariolu0605/ShapeLoading/80b34a9f9d7befec3271b92e43a9f98f3092a942/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #008577 4 | #00574B 5 | #D81B60 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | ShapeLoading 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/test/java/com/mario/shapeloading/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.mario.shapeloading; 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() { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | google() 6 | jcenter() 7 | 8 | } 9 | dependencies { 10 | classpath 'com.android.tools.build:gradle:3.5.3' 11 | 12 | // NOTE: Do not place your application dependencies here; they belong 13 | // in the individual module build.gradle files 14 | } 15 | } 16 | 17 | allprojects { 18 | repositories { 19 | google() 20 | jcenter() 21 | 22 | } 23 | } 24 | 25 | task clean(type: Delete) { 26 | delete rootProject.buildDir 27 | } 28 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx1536m 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | # AndroidX package structure to make it clearer which packages are bundled with the 15 | # Android operating system, and which are packaged with your app's APK 16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn 17 | android.useAndroidX=true 18 | # Automatically convert third-party libraries to use AndroidX 19 | android.enableJetifier=true 20 | 21 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mariolu0605/ShapeLoading/80b34a9f9d7befec3271b92e43a9f98f3092a942/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Oct 14 13:57:11 CST 2020 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-5.4.1-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /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 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 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 Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /library/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /library/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion 29 5 | buildToolsVersion "30.0.1" 6 | 7 | 8 | defaultConfig { 9 | minSdkVersion 21 10 | targetSdkVersion 29 11 | versionCode 1 12 | versionName "1.0" 13 | 14 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 15 | consumerProguardFiles 'consumer-rules.pro' 16 | } 17 | 18 | buildTypes { 19 | release { 20 | minifyEnabled false 21 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 22 | } 23 | } 24 | 25 | } 26 | 27 | dependencies { 28 | implementation fileTree(dir: 'libs', include: ['*.jar']) 29 | 30 | implementation 'androidx.appcompat:appcompat:1.2.0' 31 | testImplementation 'junit:junit:4.12' 32 | androidTestImplementation 'androidx.test.ext:junit:1.1.2' 33 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' 34 | } 35 | -------------------------------------------------------------------------------- /library/consumer-rules.pro: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mariolu0605/ShapeLoading/80b34a9f9d7befec3271b92e43a9f98f3092a942/library/consumer-rules.pro -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /library/src/androidTest/java/com/mario/library/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.mario.library; 2 | 3 | import android.content.Context; 4 | 5 | import androidx.test.platform.app.InstrumentationRegistry; 6 | import androidx.test.ext.junit.runners.AndroidJUnit4; 7 | 8 | import org.junit.Test; 9 | import org.junit.runner.RunWith; 10 | 11 | import static org.junit.Assert.*; 12 | 13 | /** 14 | * Instrumented test, which will execute on an Android device. 15 | * 16 | * @see Testing documentation 17 | */ 18 | @RunWith(AndroidJUnit4.class) 19 | public class ExampleInstrumentedTest { 20 | @Test 21 | public void useAppContext() { 22 | // Context of the app under test. 23 | Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); 24 | 25 | assertEquals("com.mario.library.test", appContext.getPackageName()); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /library/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | -------------------------------------------------------------------------------- /library/src/main/java/com/mario/library/drawable/DouYinLoadingDrawable.java: -------------------------------------------------------------------------------- 1 | package com.mario.library.drawable; 2 | 3 | import android.animation.Animator; 4 | import android.animation.AnimatorListenerAdapter; 5 | import android.animation.AnimatorSet; 6 | import android.animation.ValueAnimator; 7 | import android.annotation.SuppressLint; 8 | import android.graphics.Canvas; 9 | import android.graphics.Color; 10 | import android.graphics.ColorFilter; 11 | import android.graphics.Paint; 12 | import android.graphics.Path; 13 | import android.graphics.PixelFormat; 14 | import android.graphics.Rect; 15 | import android.graphics.drawable.Animatable; 16 | import android.graphics.drawable.Drawable; 17 | import android.view.animation.AccelerateDecelerateInterpolator; 18 | 19 | import androidx.annotation.NonNull; 20 | import androidx.annotation.Nullable; 21 | 22 | public class DouYinLoadingDrawable extends Drawable implements Animatable { 23 | 24 | private Paint leftBallPaint, rightBallPaint, coincideBallPaint; 25 | 26 | private Path leftBallPath, rightBallPath, coincideBallPath; 27 | 28 | private float translate, scale; 29 | 30 | private Direction mCurrentDirection; 31 | 32 | private AnimatorSet animatorSet; 33 | 34 | private float mWidth, mHeight; 35 | private float centerX, centerY; 36 | private float radius = 20f; 37 | 38 | public DouYinLoadingDrawable() { 39 | leftBallPaint = new Paint(Paint.ANTI_ALIAS_FLAG); 40 | leftBallPaint.setAntiAlias(true); 41 | leftBallPaint.setColor(Color.parseColor("#FF00EEEE")); 42 | leftBallPaint.setStyle(Paint.Style.FILL); 43 | 44 | rightBallPaint = new Paint(Paint.ANTI_ALIAS_FLAG); 45 | rightBallPaint.setAntiAlias(true); 46 | rightBallPaint.setColor(Color.parseColor("#FFFF4040")); 47 | rightBallPaint.setStyle(Paint.Style.FILL); 48 | 49 | coincideBallPaint = new Paint(Paint.ANTI_ALIAS_FLAG); 50 | coincideBallPaint.setAntiAlias(true); 51 | coincideBallPaint.setColor(Color.BLACK); 52 | coincideBallPaint.setStyle(Paint.Style.FILL); 53 | 54 | leftBallPath = new Path(); 55 | rightBallPath = new Path(); 56 | coincideBallPath = new Path(); 57 | 58 | mCurrentDirection = Direction.LEFT; 59 | } 60 | 61 | 62 | @Override 63 | public void start() { 64 | startAnimation(); 65 | } 66 | 67 | @Override 68 | public void stop() { 69 | if (animatorSet != null && animatorSet.isRunning()) { 70 | animatorSet.end(); 71 | } 72 | } 73 | 74 | @Override 75 | public boolean isRunning() { 76 | return animatorSet.isRunning(); 77 | } 78 | 79 | @Override 80 | public void draw(@NonNull Canvas canvas) { 81 | if (mCurrentDirection == Direction.LEFT) { 82 | canvas.save(); 83 | leftBallPath.reset(); 84 | leftBallPath.addCircle(centerX - radius + translate, centerY, radius, Path.Direction.CCW); 85 | canvas.drawPath(leftBallPath, leftBallPaint); 86 | canvas.restore(); 87 | 88 | 89 | canvas.save(); 90 | rightBallPath.reset(); 91 | rightBallPath.addCircle(centerX + radius - translate, centerY, radius * scale, Path.Direction.CCW); 92 | canvas.drawPath(rightBallPath, rightBallPaint); 93 | canvas.restore(); 94 | 95 | canvas.save(); 96 | coincideBallPath.reset(); 97 | coincideBallPath.op(leftBallPath, rightBallPath, Path.Op.INTERSECT); 98 | canvas.drawPath(coincideBallPath, coincideBallPaint); 99 | canvas.restore(); 100 | } else if (mCurrentDirection == Direction.RIGHT) { 101 | canvas.save(); 102 | rightBallPath.reset(); 103 | rightBallPath.addCircle(centerX - radius + translate, centerY, 20, Path.Direction.CCW); 104 | canvas.drawPath(rightBallPath, rightBallPaint); 105 | canvas.restore(); 106 | 107 | canvas.save(); 108 | leftBallPath.reset(); 109 | leftBallPath.addCircle(centerX + radius - translate, centerY, 20 * scale, Path.Direction.CCW); 110 | canvas.drawPath(leftBallPath, leftBallPaint); 111 | canvas.restore(); 112 | 113 | canvas.save(); 114 | coincideBallPath.reset(); 115 | coincideBallPath.op(leftBallPath, rightBallPath, Path.Op.INTERSECT); 116 | canvas.drawPath(coincideBallPath, coincideBallPaint); 117 | canvas.restore(); 118 | } 119 | 120 | 121 | } 122 | 123 | @Override 124 | public void setAlpha(int alpha) { 125 | 126 | } 127 | 128 | @Override 129 | public void setColorFilter(@Nullable ColorFilter colorFilter) { 130 | 131 | } 132 | 133 | @SuppressLint("WrongConstant") 134 | @Override 135 | public int getOpacity() { 136 | return PixelFormat.RGBA_8888; 137 | } 138 | 139 | @Override 140 | protected void onBoundsChange(Rect bounds) { 141 | super.onBoundsChange(bounds); 142 | mWidth = bounds.width(); 143 | mHeight = bounds.height(); 144 | centerX = mWidth / 2; 145 | centerY = mHeight / 2; 146 | } 147 | 148 | private void startAnimation() { 149 | leftAnimation(); 150 | } 151 | 152 | 153 | private void leftAnimation() { 154 | final ValueAnimator translateAnimator = ValueAnimator.ofFloat(0, 2 * radius); 155 | translateAnimator.setStartDelay(200); 156 | translateAnimator.setDuration(350); 157 | translateAnimator.setInterpolator(new AccelerateDecelerateInterpolator()); 158 | translateAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 159 | @Override 160 | public void onAnimationUpdate(ValueAnimator animation) { 161 | translate = (float) translateAnimator.getAnimatedValue(); 162 | invalidateSelf(); 163 | } 164 | }); 165 | 166 | final ValueAnimator scaleAnimator = ValueAnimator.ofFloat(1, 0.5f, 1); 167 | scaleAnimator.setStartDelay(200); 168 | scaleAnimator.setDuration(350); 169 | scaleAnimator.setInterpolator(new AccelerateDecelerateInterpolator()); 170 | scaleAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 171 | @Override 172 | public void onAnimationUpdate(ValueAnimator animation) { 173 | scale = (float) scaleAnimator.getAnimatedValue(); 174 | invalidateSelf(); 175 | } 176 | }); 177 | 178 | translateAnimator.addListener(new AnimatorListenerAdapter() { 179 | @Override 180 | public void onAnimationEnd(Animator animation) { 181 | if (mCurrentDirection == Direction.LEFT) 182 | mCurrentDirection = Direction.RIGHT; 183 | else 184 | mCurrentDirection = Direction.LEFT; 185 | translate = 0; 186 | leftAnimation(); 187 | } 188 | }); 189 | 190 | animatorSet = new AnimatorSet(); 191 | animatorSet.playTogether(translateAnimator, scaleAnimator); 192 | animatorSet.start(); 193 | 194 | } 195 | 196 | public enum Direction { 197 | LEFT, 198 | RIGHT 199 | } 200 | 201 | 202 | } 203 | -------------------------------------------------------------------------------- /library/src/main/java/com/mario/library/drawable/ShapeLoadingDrawable.java: -------------------------------------------------------------------------------- 1 | package com.mario.library.drawable; 2 | 3 | import android.animation.Animator; 4 | import android.animation.AnimatorListenerAdapter; 5 | import android.animation.AnimatorSet; 6 | import android.animation.ValueAnimator; 7 | import android.annotation.SuppressLint; 8 | import android.graphics.Canvas; 9 | import android.graphics.Color; 10 | import android.graphics.ColorFilter; 11 | import android.graphics.Paint; 12 | import android.graphics.Path; 13 | import android.graphics.PixelFormat; 14 | import android.graphics.Rect; 15 | import android.graphics.drawable.Animatable; 16 | import android.graphics.drawable.Drawable; 17 | import android.view.animation.DecelerateInterpolator; 18 | 19 | import androidx.annotation.NonNull; 20 | import androidx.annotation.Nullable; 21 | 22 | public class ShapeLoadingDrawable extends Drawable implements Animatable { 23 | 24 | private Shape mCurrentShape; 25 | 26 | private Paint mPaint; 27 | 28 | private int mHeight, mWidth; 29 | 30 | private float translateY; 31 | private float scale, rotateRect, rotateTriangle; 32 | 33 | private AnimatorSet upAnimatorSet, downAnimatorSet; 34 | 35 | private int rectLength = 100; 36 | private int radius = rectLength/2; 37 | public ShapeLoadingDrawable() { 38 | initData(); 39 | } 40 | 41 | private void initData() { 42 | mPaint = new Paint(); 43 | mPaint.setAntiAlias(true); 44 | mCurrentShape = Shape.SHAPE_CIRCLE; 45 | } 46 | 47 | @Override 48 | public void start() { 49 | startAnimation(); 50 | } 51 | 52 | @Override 53 | public void stop() { 54 | stopAnimation(); 55 | } 56 | 57 | @Override 58 | public boolean isRunning() { 59 | return upAnimatorSet.isRunning() || downAnimatorSet.isRunning(); 60 | } 61 | 62 | @Override 63 | public void draw(@NonNull Canvas canvas) { 64 | canvas.save(); 65 | drawLoading(canvas); 66 | canvas.restore(); 67 | 68 | canvas.save(); 69 | drawShadow(canvas); 70 | canvas.restore(); 71 | 72 | canvas.save(); 73 | drawText(canvas); 74 | canvas.restore(); 75 | } 76 | 77 | 78 | 79 | @Override 80 | public void setAlpha(int alpha) { 81 | 82 | } 83 | 84 | @Override 85 | public void setColorFilter(@Nullable ColorFilter colorFilter) { 86 | 87 | } 88 | 89 | @SuppressLint("WrongConstant") 90 | @Override 91 | public int getOpacity() { 92 | return PixelFormat.RGBA_8888; 93 | } 94 | 95 | @Override 96 | protected void onBoundsChange(Rect bounds) { 97 | super.onBoundsChange(bounds); 98 | mWidth = bounds.width(); 99 | mHeight = bounds.height(); 100 | } 101 | 102 | private void drawLoading(Canvas canvas) { 103 | //上抛下落 平移 104 | canvas.translate(0, translateY); 105 | //三角形的旋转中心和正方形有所区别 106 | if (mCurrentShape == Shape.SHAPE_TRIANGLE) 107 | canvas.rotate(rotateTriangle, mWidth / 2, mHeight / 2 - rectLength/2 + (200 / 3)); 108 | else 109 | canvas.rotate(rotateRect, mWidth / 2, mHeight / 2); 110 | switch (mCurrentShape) { 111 | case SHAPE_CIRCLE: 112 | drawCircle(canvas); 113 | break; 114 | case SHAPE_RECT: 115 | drawRect(canvas); 116 | break; 117 | case SHAPE_TRIANGLE: 118 | drawTriangle(canvas); 119 | break; 120 | } 121 | } 122 | 123 | 124 | //画圆 125 | private void drawCircle(Canvas canvas) { 126 | mPaint.setColor(Color.parseColor("#aa738ffe")); 127 | canvas.drawCircle(mWidth / 2, mHeight / 2, radius, mPaint); 128 | } 129 | 130 | 131 | //画正方形 132 | private void drawRect(Canvas canvas) { 133 | mPaint.setColor(Color.parseColor("#aae84e49")); 134 | canvas.drawRect(mWidth / 2 -rectLength/2, mHeight / 2 - rectLength/2, mWidth / 2 + rectLength/2, mHeight / 2 + rectLength/2, mPaint); 135 | } 136 | 137 | 138 | //画三角形(正三角形) 139 | private void drawTriangle(Canvas canvas) { 140 | mPaint.setColor(Color.parseColor("#aa72d572")); 141 | Path path = new Path(); 142 | path.moveTo(mWidth / 2, mHeight / 2 - rectLength/2); 143 | path.lineTo((float) (mWidth / 2 - Math.sqrt(Math.pow(rectLength,2) / 3)), mHeight / 2 + rectLength/2); 144 | path.lineTo((float) (mWidth / 2 + Math.sqrt(Math.pow(rectLength,2) / 3)), mHeight / 2 + rectLength/2); 145 | path.close(); 146 | canvas.drawPath(path, mPaint); 147 | } 148 | 149 | 150 | //画阴影部分椭圆 151 | private void drawShadow(Canvas canvas) { 152 | mPaint.setColor(Color.parseColor("#25808080")); 153 | //椭圆缩放 154 | canvas.scale(scale, scale, mWidth / 2, mHeight / 2 + 90); 155 | canvas.drawArc(mWidth / 2 - rectLength/2, mHeight / 2 + 80, mWidth / 2 + 50, mHeight / 2 + 100, 0, 360, false, mPaint); 156 | } 157 | 158 | 159 | //写文字 160 | private void drawText(Canvas canvas) { 161 | mPaint.setTextSize(45); 162 | mPaint.setColor(Color.DKGRAY); 163 | mPaint.setTextAlign(Paint.Align.CENTER); 164 | canvas.drawText("玩命加载中…", mWidth / 2, mHeight / 2 + 170, mPaint); 165 | } 166 | 167 | 168 | //形状的枚举 169 | public enum Shape { 170 | // 三角 171 | SHAPE_TRIANGLE, 172 | // 四边形 173 | SHAPE_RECT, 174 | // 圆形 175 | SHAPE_CIRCLE 176 | } 177 | 178 | 179 | private void exchangeDraw() { 180 | switch (mCurrentShape) { 181 | case SHAPE_CIRCLE: 182 | mCurrentShape = Shape.SHAPE_RECT; 183 | break; 184 | case SHAPE_RECT: 185 | mCurrentShape = Shape.SHAPE_TRIANGLE; 186 | break; 187 | case SHAPE_TRIANGLE: 188 | mCurrentShape = Shape.SHAPE_CIRCLE; 189 | break; 190 | } 191 | } 192 | 193 | /** 194 | * 上抛动画 195 | */ 196 | private void upAnimation() { 197 | final ValueAnimator upAnimation = ValueAnimator.ofFloat(0, -200); 198 | upAnimation.setInterpolator(new DecelerateInterpolator(1.2f)); 199 | upAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 200 | @Override 201 | public void onAnimationUpdate(ValueAnimator animation) { 202 | translateY = (float) upAnimation.getAnimatedValue(); 203 | invalidateSelf(); 204 | } 205 | }); 206 | 207 | upAnimation.addListener(new AnimatorListenerAdapter() { 208 | @Override 209 | public void onAnimationEnd(Animator animation) { 210 | downAnimation(); 211 | } 212 | }); 213 | 214 | 215 | final ValueAnimator scaleAnimation = ValueAnimator.ofFloat(1, 0.3f); 216 | scaleAnimation.setInterpolator(new DecelerateInterpolator(1.2f)); 217 | scaleAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 218 | @Override 219 | public void onAnimationUpdate(ValueAnimator animation) { 220 | scale = (float) scaleAnimation.getAnimatedValue(); 221 | } 222 | }); 223 | 224 | 225 | final ValueAnimator rotateTriangleAnimation = ValueAnimator.ofFloat(0, 120); 226 | rotateTriangleAnimation.setInterpolator(new DecelerateInterpolator(1.2f)); 227 | rotateTriangleAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 228 | @Override 229 | public void onAnimationUpdate(ValueAnimator animation) { 230 | rotateTriangle = (float) rotateTriangleAnimation.getAnimatedValue(); 231 | } 232 | }); 233 | 234 | final ValueAnimator rotateRectAnimation = ValueAnimator.ofFloat(0, 180); 235 | rotateRectAnimation.setInterpolator(new DecelerateInterpolator(1.2f)); 236 | rotateRectAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 237 | @Override 238 | public void onAnimationUpdate(ValueAnimator animation) { 239 | rotateRect = (float) rotateRectAnimation.getAnimatedValue(); 240 | } 241 | }); 242 | 243 | 244 | upAnimatorSet = new AnimatorSet(); 245 | upAnimatorSet.setDuration(300); 246 | upAnimatorSet.playTogether(upAnimation, scaleAnimation, rotateTriangleAnimation, rotateRectAnimation); 247 | upAnimatorSet.start(); 248 | 249 | } 250 | 251 | /** 252 | * 下落动画 253 | */ 254 | private void downAnimation() { 255 | final ValueAnimator downAnimation = ValueAnimator.ofFloat(-200, 0); 256 | downAnimation.setInterpolator(new DecelerateInterpolator(1.2f)); 257 | downAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 258 | @Override 259 | public void onAnimationUpdate(ValueAnimator animation) { 260 | translateY = (float) downAnimation.getAnimatedValue(); 261 | invalidateSelf(); 262 | } 263 | }); 264 | 265 | downAnimation.addListener(new AnimatorListenerAdapter() { 266 | @Override 267 | public void onAnimationEnd(Animator animation) { 268 | upAnimation(); 269 | exchangeDraw(); 270 | } 271 | }); 272 | 273 | 274 | final ValueAnimator scaleAnimation = ValueAnimator.ofFloat(0.3f, 1); 275 | scaleAnimation.setInterpolator(new DecelerateInterpolator(1.2f)); 276 | scaleAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 277 | @Override 278 | public void onAnimationUpdate(ValueAnimator animation) { 279 | scale = (float) scaleAnimation.getAnimatedValue(); 280 | } 281 | }); 282 | 283 | 284 | downAnimatorSet = new AnimatorSet(); 285 | downAnimatorSet.setDuration(500); 286 | downAnimatorSet.playTogether(downAnimation, scaleAnimation); 287 | downAnimatorSet.start(); 288 | 289 | } 290 | 291 | 292 | private void startAnimation() { 293 | upAnimation(); 294 | } 295 | 296 | private void stopAnimation() { 297 | if (upAnimatorSet != null && upAnimatorSet.isStarted()) { 298 | upAnimatorSet.end(); 299 | } 300 | if (downAnimatorSet != null && downAnimatorSet.isStarted()) { 301 | downAnimatorSet.end(); 302 | } 303 | } 304 | } 305 | -------------------------------------------------------------------------------- /library/src/main/java/com/mario/library/drawable/ThreeBallsLoadingDrawable.java: -------------------------------------------------------------------------------- 1 | package com.mario.library.drawable; 2 | 3 | import android.animation.Animator; 4 | import android.animation.AnimatorListenerAdapter; 5 | import android.animation.ValueAnimator; 6 | import android.annotation.SuppressLint; 7 | import android.graphics.Canvas; 8 | import android.graphics.Color; 9 | import android.graphics.ColorFilter; 10 | import android.graphics.Paint; 11 | import android.graphics.PixelFormat; 12 | import android.graphics.Rect; 13 | import android.graphics.drawable.Animatable; 14 | import android.graphics.drawable.Drawable; 15 | import android.view.animation.AccelerateInterpolator; 16 | import android.view.animation.DecelerateInterpolator; 17 | 18 | import androidx.annotation.NonNull; 19 | import androidx.annotation.Nullable; 20 | 21 | public class ThreeBallsLoadingDrawable extends Drawable implements Animatable { 22 | 23 | 24 | private Paint mLeftPaint,mMiddlePaint,mRightPaint; 25 | 26 | 27 | private int mWidth,mHeight; 28 | 29 | private final static int RADIUS = 30; 30 | private final long ANIMATION_DURATION = 1000; 31 | 32 | private float translateX; 33 | 34 | public ThreeBallsLoadingDrawable(){ 35 | mLeftPaint = new Paint(Paint.ANTI_ALIAS_FLAG); 36 | mLeftPaint.setColor(Color.BLUE); 37 | mLeftPaint.setAntiAlias(true); 38 | mLeftPaint.setDither(true); 39 | 40 | mMiddlePaint = new Paint(Paint.ANTI_ALIAS_FLAG); 41 | mMiddlePaint.setColor(Color.RED); 42 | mMiddlePaint.setAntiAlias(true); 43 | mMiddlePaint.setDither(true); 44 | 45 | mRightPaint = new Paint(Paint.ANTI_ALIAS_FLAG); 46 | mRightPaint.setColor(Color.GREEN); 47 | mRightPaint.setAntiAlias(true); 48 | mRightPaint.setDither(true); 49 | } 50 | 51 | @Override 52 | public void start() { 53 | startAnimation(); 54 | } 55 | 56 | 57 | 58 | @Override 59 | public void stop() { 60 | 61 | } 62 | 63 | @Override 64 | public boolean isRunning() { 65 | return false; 66 | } 67 | 68 | @Override 69 | public void draw(@NonNull Canvas canvas) { 70 | 71 | canvas.save(); 72 | canvas.translate(translateX,0); 73 | canvas.drawCircle(RADIUS,mHeight/2,RADIUS,mLeftPaint); 74 | canvas.restore(); 75 | 76 | canvas.save(); 77 | canvas.drawCircle(mWidth/2,mHeight/2,RADIUS,mMiddlePaint); 78 | canvas.restore(); 79 | 80 | canvas.save(); 81 | canvas.translate(-translateX,0); 82 | canvas.drawCircle(mWidth-RADIUS,mHeight/2,RADIUS,mRightPaint); 83 | canvas.restore(); 84 | 85 | } 86 | 87 | @Override 88 | public void setAlpha(int alpha) { 89 | 90 | } 91 | 92 | @Override 93 | public void setColorFilter(@Nullable ColorFilter colorFilter) { 94 | 95 | } 96 | 97 | @SuppressLint("WrongConstant") 98 | @Override 99 | public int getOpacity() { 100 | return PixelFormat.RGBA_8888; 101 | } 102 | 103 | 104 | @Override 105 | protected void onBoundsChange(Rect bounds) { 106 | super.onBoundsChange(bounds); 107 | mHeight = bounds.height(); 108 | mWidth = bounds.width(); 109 | } 110 | 111 | private void startAnimation() { 112 | innerMove(); 113 | } 114 | 115 | 116 | /** 117 | * 变换颜色方法 118 | */ 119 | private void exchangeColor(){ 120 | int mLeftPaintColor = mLeftPaint.getColor(); 121 | int mRightPaintColor = mRightPaint.getColor(); 122 | int mMiddlePaintColor = mMiddlePaint.getColor(); 123 | mLeftPaint.setColor(mRightPaintColor); 124 | mRightPaint.setColor(mMiddlePaintColor); 125 | mMiddlePaint.setColor(mLeftPaintColor); 126 | } 127 | 128 | 129 | /** 130 | * 向内平移 131 | */ 132 | private void innerMove() { 133 | final ValueAnimator translateXInnerAnimation = ValueAnimator.ofFloat(0,170); 134 | translateXInnerAnimation.setDuration(ANIMATION_DURATION); 135 | translateXInnerAnimation.setInterpolator(new AccelerateInterpolator()); 136 | translateXInnerAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 137 | @Override 138 | public void onAnimationUpdate(ValueAnimator animation) { 139 | translateX = (float) translateXInnerAnimation.getAnimatedValue(); 140 | invalidateSelf(); 141 | } 142 | }); 143 | 144 | 145 | translateXInnerAnimation.addListener(new AnimatorListenerAdapter() { 146 | @Override 147 | public void onAnimationEnd(Animator animation) { 148 | super.onAnimationEnd(animation); 149 | //变换颜色 150 | exchangeColor(); 151 | expendMove(); 152 | } 153 | }); 154 | 155 | translateXInnerAnimation.start(); 156 | } 157 | 158 | 159 | /** 160 | * 向外平移 161 | */ 162 | private void expendMove(){ 163 | final ValueAnimator translateXExpendAnimation = ValueAnimator.ofFloat(170,0); 164 | translateXExpendAnimation.setDuration(ANIMATION_DURATION); 165 | translateXExpendAnimation.setInterpolator(new DecelerateInterpolator()); 166 | translateXExpendAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 167 | @Override 168 | public void onAnimationUpdate(ValueAnimator animation) { 169 | translateX = (float) translateXExpendAnimation.getAnimatedValue(); 170 | invalidateSelf(); 171 | } 172 | }); 173 | 174 | 175 | translateXExpendAnimation.addListener(new AnimatorListenerAdapter() { 176 | @Override 177 | public void onAnimationEnd(Animator animation) { 178 | super.onAnimationEnd(animation); 179 | innerMove(); 180 | } 181 | }); 182 | 183 | translateXExpendAnimation.start(); 184 | } 185 | 186 | } 187 | -------------------------------------------------------------------------------- /library/src/main/java/com/mario/library/view/LoadArrowView.java: -------------------------------------------------------------------------------- 1 | package com.mario.library.view; 2 | 3 | import android.animation.ValueAnimator; 4 | import android.content.Context; 5 | import android.graphics.Bitmap; 6 | import android.graphics.BitmapFactory; 7 | import android.graphics.Canvas; 8 | import android.graphics.Color; 9 | import android.graphics.Matrix; 10 | import android.graphics.Paint; 11 | import android.graphics.Path; 12 | import android.graphics.PathMeasure; 13 | import android.util.AttributeSet; 14 | import android.view.View; 15 | import android.view.animation.LinearInterpolator; 16 | 17 | 18 | import com.mario.library.R; 19 | 20 | import androidx.annotation.Nullable; 21 | 22 | public class LoadArrowView extends View { 23 | 24 | 25 | private float[] pos; // 当前点的实际位置 26 | private float[] tan; // 当前点的tangent值,用于计算图片所需旋转的角度 27 | private Bitmap mBitmap; // 箭头图片 28 | private Matrix mMatrix; // 矩阵,用于对图片进行一些操作 29 | private Paint mDefaultPaint; 30 | private int mViewWidth; 31 | private int mViewHeight; 32 | private Paint mPaint; 33 | private Path path; 34 | private PathMeasure pathMeasure; 35 | private float mAnimatorValue; 36 | public LoadArrowView(Context context) { 37 | this(context, null); 38 | } 39 | 40 | public LoadArrowView(Context context, @Nullable AttributeSet attrs) { 41 | this(context, attrs, 0); 42 | } 43 | 44 | public LoadArrowView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { 45 | super(context, attrs, defStyleAttr); 46 | init(context); 47 | } 48 | 49 | private void init(Context context) { 50 | pos = new float[2]; 51 | tan = new float[2]; 52 | BitmapFactory.Options options = new BitmapFactory.Options(); 53 | options.inSampleSize = 8; // 缩放图片 54 | mBitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.arrow, options); 55 | mMatrix = new Matrix(); 56 | 57 | mDefaultPaint = new Paint(); 58 | mDefaultPaint.setColor(Color.RED); 59 | mDefaultPaint.setStrokeWidth(5); 60 | mDefaultPaint.setStyle(Paint.Style.STROKE); 61 | 62 | mPaint = new Paint(); 63 | mPaint.setColor(Color.DKGRAY); 64 | mPaint.setStrokeWidth(20); 65 | mPaint.setStyle(Paint.Style.STROKE); 66 | path = new Path(); 67 | } 68 | 69 | protected void onSizeChanged(int w, int h, int oldw, int oldh) { 70 | super.onSizeChanged(w, h, oldw, oldh); 71 | mViewWidth = w; 72 | mViewHeight = h; 73 | path.addCircle(mViewWidth / 2, mViewHeight / 2, 200, Path.Direction.CW); 74 | pathMeasure = new PathMeasure(path, false); 75 | 76 | ValueAnimator valueAnimator = ValueAnimator.ofFloat(0, 1); 77 | valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 78 | @Override 79 | public void onAnimationUpdate(ValueAnimator animation) { 80 | // 获取动画进行的百分比 81 | mAnimatorValue = (float) animation.getAnimatedValue(); 82 | postInvalidate(); // 更新界面 83 | } 84 | }); 85 | // 设置动画的属性 86 | valueAnimator.setDuration(3000); 87 | valueAnimator.setRepeatCount(1000); 88 | valueAnimator.setInterpolator(new LinearInterpolator()); 89 | valueAnimator.setRepeatMode(ValueAnimator.RESTART); 90 | valueAnimator.start(); 91 | 92 | 93 | } 94 | 95 | @Override 96 | protected void onDraw(Canvas canvas) { 97 | super.onDraw(canvas); 98 | 99 | canvas.drawColor(Color.WHITE); 100 | 101 | pathMeasure.getPosTan(pathMeasure.getLength() * mAnimatorValue, pos, tan); 102 | //Path.Direction.CW顺时针方向 103 | 104 | float angle = (float) (Math.atan2(tan[1], tan[0]) * 180 / Math.PI); 105 | mMatrix.reset(); 106 | mMatrix.postRotate(angle,mBitmap.getWidth()/2,mBitmap.getHeight()/2); 107 | 108 | mMatrix.postTranslate(pos[0] - mBitmap.getWidth() / 2,pos[1] - mBitmap.getHeight() / 2); 109 | 110 | canvas.drawPath(path,mDefaultPaint); 111 | 112 | canvas.drawBitmap(mBitmap,mMatrix,mPaint); 113 | 114 | 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /library/src/main/java/com/mario/library/view/LoadingCircleView.java: -------------------------------------------------------------------------------- 1 | package com.mario.library.view; 2 | 3 | import android.animation.ValueAnimator; 4 | import android.content.Context; 5 | import android.graphics.Canvas; 6 | import android.graphics.Paint; 7 | import android.graphics.Path; 8 | import android.graphics.PathMeasure; 9 | import android.util.AttributeSet; 10 | import android.util.TypedValue; 11 | import android.view.View; 12 | 13 | public class LoadingCircleView extends View { 14 | 15 | private Path path; 16 | private PathMeasure pathMeasure; 17 | 18 | private Path dst; // 被截取的路径 19 | 20 | private Paint mPaint; // 画笔 21 | 22 | // View的宽高 23 | private int height; 24 | private int width; 25 | 26 | private float radius; // 空心圆的半径 27 | private float mLength; // path路径的长度 28 | 29 | ValueAnimator valueAnimator; // 属性动画 30 | private float mAnimatorValue; // 属性动画返回的百分比 31 | 32 | private float stop; // 截取路径时的stopD值 33 | private float start; // 截取路径时的startD值 34 | 35 | public LoadingCircleView(Context context) { 36 | this(context,null); 37 | } 38 | 39 | public LoadingCircleView(Context context, AttributeSet attrs) { 40 | this(context, attrs,0); 41 | } 42 | 43 | public LoadingCircleView(Context context, AttributeSet attrs, int defStyleAttr) { 44 | super(context, attrs, defStyleAttr); 45 | init(); 46 | } 47 | 48 | private void init() { 49 | radius = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 21, getContext().getResources().getDisplayMetrics()); // 初始化半径 50 | path = new Path(); 51 | dst = new Path(); 52 | mPaint = new Paint(); 53 | pathMeasure = new PathMeasure(); 54 | 55 | // 设置画笔属性 56 | mPaint.setAntiAlias(true); 57 | mPaint.setColor(0xbfe46d32); 58 | mPaint.setStyle(Paint.Style.STROKE); 59 | mPaint.setStrokeCap(Paint.Cap.ROUND); 60 | mPaint.setStrokeWidth(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 3.5f, getContext().getResources().getDisplayMetrics())); 61 | 62 | } 63 | 64 | @Override 65 | protected void onSizeChanged(int w, int h, int oldw, int oldh) { 66 | super.onSizeChanged(w, h, oldw, oldh); 67 | 68 | width = w; 69 | height = h; 70 | 71 | // 勾勒空心圆 72 | path.reset(); 73 | path.addCircle(width / 2, height / 2, radius, Path.Direction.CW); 74 | // 生成pathMeasure对象 75 | pathMeasure.setPath(path, true); 76 | 77 | // 获取path的长度 78 | mLength = pathMeasure.getLength(); 79 | 80 | // 通过属性动画取得百分比值,并更新View 81 | valueAnimator = ValueAnimator.ofFloat(0, 1); 82 | valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 83 | @Override 84 | public void onAnimationUpdate(ValueAnimator animation) { 85 | // 获取动画进行的百分比 86 | mAnimatorValue = (float) animation.getAnimatedValue(); 87 | postInvalidate(); // 更新界面 88 | } 89 | }); 90 | // 设置动画的属性 91 | valueAnimator.setDuration(2100); 92 | valueAnimator.setRepeatCount(1000); 93 | valueAnimator.setRepeatMode(ValueAnimator.RESTART); 94 | valueAnimator.start(); 95 | } 96 | 97 | 98 | @Override 99 | protected void onDraw(Canvas canvas) { 100 | super.onDraw(canvas); 101 | 102 | //为加强动画效果,每次对画布旋转不同角度 103 | canvas.rotate(360.0f * mAnimatorValue - 45.0f, width / 2, height / 2); 104 | //初始化截取的路径 105 | dst.reset(); 106 | dst.lineTo(0, 0); // 消除硬件加速的影响 107 | // 更新截取的开始值和结束值:当mAnimatorValue为0或1时,两个值相等 108 | stop = mAnimatorValue * mLength; 109 | start = (float) (stop - ((0.5 - Math.abs(mAnimatorValue - 0.5)) * mLength)); 110 | // 截取路径后,并绘制路径 111 | pathMeasure.getSegment(start, stop, dst, true); 112 | canvas.drawPath(dst, mPaint); 113 | // canvas.translate(width/2,height/2); 114 | // Path mPath = new Path(); 115 | // Path mDst = new Path(); 116 | // PathMeasure mPathMeasure = new PathMeasure(); 117 | //// 顺时针画 半径为400px的圆 118 | // mPath.addCircle(0,0, 400, Path.Direction.CW); 119 | // mPathMeasure.setPath(mPath, false); 120 | // 121 | //// 画直线 122 | // mDst.moveTo(110, 0); 123 | // mDst.lineTo(200, 300); 124 | // 125 | //// 截取 0.25 到 0.5 距离的圆弧放置dst中 126 | // mPathMeasure.getSegment(mPathMeasure.getLength() * 0.25f, 127 | // mPathMeasure.getLength() * 0.5f, 128 | // mDst, 129 | // true); 130 | 131 | // canvas.drawPath(mDst, paint); 132 | } 133 | } 134 | -------------------------------------------------------------------------------- /library/src/main/res/drawable/arrow.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mariolu0605/ShapeLoading/80b34a9f9d7befec3271b92e43a9f98f3092a942/library/src/main/res/drawable/arrow.jpg -------------------------------------------------------------------------------- /library/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Library 3 | 4 | -------------------------------------------------------------------------------- /library/src/test/java/com/mario/library/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.mario.library; 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() { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':library' 2 | rootProject.name='ShapeLoading' 3 | --------------------------------------------------------------------------------