├── .gitignore ├── README.md ├── art └── screenshot.gif ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── library ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── cn │ │ └── refactor │ │ └── smileyloadingview │ │ └── lib │ │ └── SmileyLoadingView.java │ └── res │ └── values │ ├── attrs.xml │ └── strings.xml ├── sample ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── cn │ │ └── refactor │ │ └── smileyloadingview │ │ ├── header │ │ └── SmileyLoadingViewHeader.java │ │ └── ui │ │ ├── MainActivity.java │ │ ├── PullToRefreshActivity.java │ │ ├── RecyclerViewDivider.java │ │ ├── SampleActivity.java │ │ └── SamplePtrFrameLayout.java │ └── res │ ├── layout │ ├── activity_list.xml │ ├── activity_main.xml │ ├── activity_sample.xml │ ├── header_loading.xml │ └── list_item.xml │ ├── mipmap-hdpi │ └── ic_launcher.png │ ├── mipmap-mdpi │ └── ic_launcher.png │ ├── mipmap-xhdpi │ └── ic_launcher.png │ ├── mipmap-xxhdpi │ └── ic_launcher.png │ ├── mipmap-xxxhdpi │ └── ic_launcher.png │ ├── values-w820dp │ └── dimens.xml │ └── values │ ├── colors.xml │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | # OSX 2 | *.DS_Store 3 | 4 | # Gradle files 5 | build/ 6 | .gradle/ 7 | */build/ 8 | 9 | # IDEA 10 | *.iml 11 | .idea/ 12 | 13 | # Built application files 14 | *.apk 15 | *.ap_ 16 | 17 | # Files for the Dalvik VM 18 | *.dex 19 | 20 | # Java class files 21 | *.class 22 | 23 | # Local configuration file (sdk path, etc) 24 | local.properties 25 | 26 | # Log Files 27 | *.log -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | #SmileyLoadingView 2 | 3 | [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-SmileyLoadingView-green.svg?style=true)](https://android-arsenal.com/details/1/4234) 4 | 5 | A custom loading view, just like alipay. 6 | 7 | ![](https://github.com/andyxialm/SmileyLoadingView/blob/master/art/screenshot.gif?raw=true) 8 | ### Usage 9 | 10 | ##### Edit your layout XML: 11 | 12 | ~~~ xml 13 | 20 | ~~~ 21 | 22 | ### License 23 | 24 | Copyright 2016 andy 25 | 26 | Licensed under the Apache License, Version 2.0 (the "License"); 27 | you may not use this file except in compliance with the License. 28 | You may obtain a copy of the License at 29 | 30 | http://www.apache.org/licenses/LICENSE-2.0 31 | 32 | Unless required by applicable law or agreed to in writing, software 33 | distributed under the License is distributed on an "AS IS" BASIS, 34 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 35 | See the License for the specific language governing permissions and 36 | limitations under the License. -------------------------------------------------------------------------------- /art/screenshot.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andyxialm/SmileyLoadingView/c55864b06c2dd7d8caf8d1be711e0b27369ce06f/art/screenshot.gif -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:2.1.3' 9 | 10 | // NOTE: Do not place your application dependencies here; they belong 11 | // in the individual module build.gradle files 12 | } 13 | } 14 | 15 | allprojects { 16 | repositories { 17 | jcenter() 18 | } 19 | } 20 | 21 | task clean(type: Delete) { 22 | delete rootProject.buildDir 23 | } 24 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andyxialm/SmileyLoadingView/c55864b06c2dd7d8caf8d1be711e0b27369ce06f/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Thu Aug 18 10:05:06 CST 2016 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # 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 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /library/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | *.iml -------------------------------------------------------------------------------- /library/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion "24.0.0" 6 | 7 | defaultConfig { 8 | minSdkVersion 14 9 | targetSdkVersion 23 10 | versionCode 1 11 | versionName "1.0" 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 17 | } 18 | } 19 | } 20 | 21 | dependencies { 22 | compile fileTree(dir: 'libs', include: ['*.jar']) 23 | } 24 | -------------------------------------------------------------------------------- /library/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/andy/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /library/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /library/src/main/java/cn/refactor/smileyloadingview/lib/SmileyLoadingView.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2016 andy 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package cn.refactor.smileyloadingview.lib; 18 | 19 | import android.animation.Animator; 20 | import android.animation.ValueAnimator; 21 | import android.annotation.TargetApi; 22 | import android.content.Context; 23 | import android.content.res.TypedArray; 24 | import android.graphics.Canvas; 25 | import android.graphics.Color; 26 | import android.graphics.Paint; 27 | import android.graphics.Path; 28 | import android.graphics.PathMeasure; 29 | import android.graphics.RectF; 30 | import android.os.Build; 31 | import android.util.AttributeSet; 32 | import android.view.View; 33 | import android.view.animation.LinearInterpolator; 34 | 35 | /** 36 | * Create by andy (https://github.com/andyxialm) 37 | * Create time: 16/8/18 10:17 38 | * Description : SmileyLoadingView 39 | */ 40 | public class SmileyLoadingView extends View { 41 | 42 | private static final int DEFAULT_WIDTH = 30; 43 | private static final int DEFAULT_HEIGHT = 30; 44 | private static final int DEFAULT_PAINT_WIDTH = 5; 45 | 46 | private static final int DEFAULT_ANIM_DURATION = 2000; 47 | private static final int DEFAULT_PAINT_COLOR = Color.parseColor("#b3d8f3"); 48 | private static final int ROTATE_OFFSET = 90; 49 | 50 | private Paint mArcPaint, mCirclePaint; 51 | private Path mCirclePath, mArcPath; 52 | private RectF mRectF; 53 | 54 | private float[] mCenterPos, mLeftEyePos, mRightEyePos; 55 | private float mStartAngle, mSweepAngle; 56 | private float mEyeCircleRadius; 57 | 58 | private int mStrokeColor; 59 | private int mAnimDuration; 60 | private int mAnimRepeatCount; 61 | 62 | private int mStrokeWidth; 63 | private boolean mRunning; 64 | private boolean mStopping; 65 | 66 | private boolean mFirstStep; 67 | private boolean mShowLeftEye, mShowRightEye; 68 | private boolean mStopUntilAnimationPerformCompleted; 69 | 70 | private OnAnimPerformCompletedListener mOnAnimPerformCompletedListener; 71 | private ValueAnimator mValueAnimator; 72 | 73 | public SmileyLoadingView(Context context) { 74 | this(context, null); 75 | } 76 | 77 | public SmileyLoadingView(Context context, AttributeSet attrs) { 78 | this(context, attrs, 0); 79 | } 80 | 81 | public SmileyLoadingView(Context context, AttributeSet attrs, int defStyleAttr) { 82 | super(context, attrs, defStyleAttr); 83 | init(attrs); 84 | } 85 | 86 | @TargetApi(Build.VERSION_CODES.LOLLIPOP) 87 | public SmileyLoadingView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 88 | super(context, attrs, defStyleAttr, defStyleRes); 89 | init(attrs); 90 | } 91 | 92 | private void init(AttributeSet attrs) { 93 | 94 | // get attrs 95 | TypedArray ta = getContext().obtainStyledAttributes(attrs, R.styleable.SmileyLoadingView); 96 | mStrokeColor = ta.getColor(R.styleable.SmileyLoadingView_strokeColor, DEFAULT_PAINT_COLOR); 97 | mStrokeWidth = ta.getDimensionPixelSize(R.styleable.SmileyLoadingView_strokeWidth, dp2px(DEFAULT_PAINT_WIDTH)); 98 | mAnimDuration = ta.getInt(R.styleable.SmileyLoadingView_duration, DEFAULT_ANIM_DURATION); 99 | mAnimRepeatCount = ta.getInt(R.styleable.SmileyLoadingView_animRepeatCount, ValueAnimator.INFINITE); 100 | ta.recycle(); 101 | 102 | mSweepAngle = 180; // init sweepAngle, the mouth line sweep angle 103 | mCirclePath = new Path(); 104 | mArcPath = new Path(); 105 | 106 | mArcPaint = new Paint(Paint.ANTI_ALIAS_FLAG); 107 | mArcPaint.setStyle(Paint.Style.STROKE); 108 | mArcPaint.setStrokeCap(Paint.Cap.ROUND); 109 | mArcPaint.setStrokeJoin(Paint.Join.ROUND); 110 | mArcPaint.setStrokeWidth(mStrokeWidth); 111 | mArcPaint.setColor(mStrokeColor); 112 | 113 | mCirclePaint = new Paint(Paint.ANTI_ALIAS_FLAG); 114 | mCirclePaint.setStyle(Paint.Style.STROKE); 115 | mCirclePaint.setStrokeCap(Paint.Cap.ROUND); 116 | mCirclePaint.setStrokeJoin(Paint.Join.ROUND); 117 | mCirclePaint.setStyle(Paint.Style.FILL); 118 | mCirclePaint.setColor(mStrokeColor); 119 | 120 | mCenterPos = new float[2]; 121 | mLeftEyePos = new float[2]; 122 | mRightEyePos = new float[2]; 123 | } 124 | 125 | @Override 126 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 127 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); 128 | setMeasuredDimension(measureWidthSize(widthMeasureSpec), measureHeightSize(heightMeasureSpec)); 129 | } 130 | 131 | @Override 132 | protected void onDraw(Canvas canvas) { 133 | if (mRunning) { 134 | if (mShowLeftEye) { 135 | canvas.drawCircle(mLeftEyePos[0], mLeftEyePos[1], mEyeCircleRadius, mCirclePaint); 136 | } 137 | 138 | if (mShowRightEye) { 139 | canvas.drawCircle(mRightEyePos[0], mRightEyePos[1], mEyeCircleRadius, mCirclePaint); 140 | } 141 | 142 | if (mFirstStep) { 143 | mArcPath.reset(); 144 | mArcPath.addArc(mRectF, mStartAngle, mSweepAngle); 145 | canvas.drawPath(mArcPath, mArcPaint); 146 | } else { 147 | mArcPath.reset(); 148 | mArcPath.addArc(mRectF, mStartAngle, mSweepAngle); 149 | canvas.drawPath(mArcPath, mArcPaint); 150 | } 151 | } else { 152 | canvas.drawCircle(mLeftEyePos[0], mLeftEyePos[1], mEyeCircleRadius, mCirclePaint); 153 | canvas.drawCircle(mRightEyePos[0], mRightEyePos[1], mEyeCircleRadius, mCirclePaint); 154 | 155 | mArcPath.reset(); 156 | mArcPath.addArc(mRectF, mStartAngle, mSweepAngle); 157 | canvas.drawPath(mArcPath, mArcPaint); 158 | } 159 | } 160 | 161 | /** 162 | * measure width 163 | * @param measureSpec spec 164 | * @return width 165 | */ 166 | private int measureWidthSize(int measureSpec) { 167 | int defSize = dp2px(DEFAULT_WIDTH); 168 | int specSize = MeasureSpec.getSize(measureSpec); 169 | int specMode = MeasureSpec.getMode(measureSpec); 170 | 171 | int result = 0; 172 | switch (specMode) { 173 | case MeasureSpec.UNSPECIFIED: 174 | case MeasureSpec.AT_MOST: 175 | result = Math.min(defSize, specSize); 176 | break; 177 | case MeasureSpec.EXACTLY: 178 | result = specSize; 179 | break; 180 | } 181 | return result; 182 | } 183 | 184 | /** 185 | * measure height 186 | * @param measureSpec spec 187 | * @return height 188 | */ 189 | private int measureHeightSize(int measureSpec) { 190 | int defSize = dp2px(DEFAULT_HEIGHT); 191 | int specSize = MeasureSpec.getSize(measureSpec); 192 | int specMode = MeasureSpec.getMode(measureSpec); 193 | 194 | int result = 0; 195 | switch (specMode) { 196 | case MeasureSpec.UNSPECIFIED: 197 | case MeasureSpec.AT_MOST: 198 | result = Math.min(defSize, specSize); 199 | break; 200 | case MeasureSpec.EXACTLY: 201 | result = specSize; 202 | break; 203 | } 204 | return result; 205 | } 206 | 207 | @Override 208 | protected void onSizeChanged(int w, int h, int oldw, int oldh) { 209 | super.onSizeChanged(w, h, oldw, oldh); 210 | int paddingLeft = getPaddingLeft(); 211 | int paddingRight = getPaddingRight(); 212 | int paddingTop = getPaddingTop(); 213 | int paddingBottom = getPaddingBottom(); 214 | 215 | int width = getWidth(); 216 | int height = getHeight(); 217 | mCenterPos[0] = (width - paddingRight + paddingLeft) >> 1; 218 | mCenterPos[1] = (height - paddingBottom + paddingTop) >> 1; 219 | 220 | 221 | float radiusX = (width - paddingRight - paddingLeft - mStrokeWidth) >> 1; 222 | float radiusY = (height - paddingTop - paddingBottom - mStrokeWidth) >> 1; 223 | float radius = Math.min(radiusX, radiusY); 224 | mEyeCircleRadius = mStrokeWidth / 2; 225 | 226 | mRectF = new RectF(paddingLeft + mStrokeWidth, paddingTop + mStrokeWidth, 227 | width - mStrokeWidth - paddingRight, height - mStrokeWidth - paddingBottom); 228 | 229 | mArcPath.arcTo(mRectF, 0, 180); 230 | mCirclePath.addCircle(mCenterPos[0], mCenterPos[1], radius, Path.Direction.CW); 231 | PathMeasure circlePathMeasure = new PathMeasure(mCirclePath, true); 232 | 233 | circlePathMeasure.getPosTan(circlePathMeasure.getLength() / 8 * 5, mLeftEyePos, null); 234 | circlePathMeasure.getPosTan(circlePathMeasure.getLength() / 8 * 7, mRightEyePos, null); 235 | mLeftEyePos[0] += mStrokeWidth >> 2; 236 | mLeftEyePos[1] += mStrokeWidth >> 1; 237 | mRightEyePos[0] -= mStrokeWidth >> 2; 238 | mRightEyePos[1] += mStrokeWidth >> 1; 239 | } 240 | 241 | @Override 242 | protected void onDetachedFromWindow() { 243 | super.onDetachedFromWindow(); 244 | if (mValueAnimator != null && mValueAnimator.isRunning()) { 245 | mValueAnimator.end(); 246 | } 247 | } 248 | 249 | /** 250 | * Set paint color alpha 251 | * @param alpha alpha 252 | */ 253 | public void setPaintAlpha(int alpha) { 254 | mArcPaint.setAlpha(alpha); 255 | mCirclePaint.setAlpha(alpha); 256 | invalidate(); 257 | } 258 | 259 | /** 260 | * Set paint stroke color 261 | * @param color color 262 | */ 263 | public void setStrokeColor(int color) { 264 | mStrokeColor = color; 265 | invalidate(); 266 | } 267 | 268 | /** 269 | * Set paint stroke width 270 | * @param width px 271 | */ 272 | public void setStrokeWidth(int width) { 273 | mStrokeWidth = width; 274 | } 275 | 276 | /** 277 | * Set animation running duration 278 | * @param duration duration 279 | */ 280 | @SuppressWarnings("unused") 281 | public void setAnimDuration(int duration) { 282 | mAnimDuration = duration; 283 | } 284 | 285 | /** 286 | * Set animation repeat count, ValueAnimator.INFINITE(-1) means cycle 287 | * @param repeatCount repeat count 288 | */ 289 | @SuppressWarnings("unused") 290 | public void setAnimRepeatCount(int repeatCount) { 291 | mAnimRepeatCount = repeatCount; 292 | } 293 | 294 | /** 295 | * set anim repeat count 296 | * @param animRepeatCount anim repeat count 297 | * value: -1 (INFINITE) 298 | */ 299 | public void start(int animRepeatCount) { 300 | mAnimRepeatCount = animRepeatCount; 301 | 302 | mFirstStep = true; 303 | 304 | mValueAnimator = ValueAnimator.ofFloat(ROTATE_OFFSET, 720.0f + 2 * ROTATE_OFFSET); 305 | mValueAnimator.setDuration(mAnimDuration); 306 | mValueAnimator.setInterpolator(new LinearInterpolator()); 307 | mValueAnimator.setRepeatCount(mAnimRepeatCount); 308 | mValueAnimator.setRepeatMode(ValueAnimator.RESTART); 309 | mValueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 310 | @Override 311 | public void onAnimationUpdate(ValueAnimator animation) { 312 | if (!animation.isRunning()) { 313 | return; 314 | } 315 | float animatedValue = (float) animation.getAnimatedValue(); 316 | mFirstStep = animatedValue / 360.0f <= 1; 317 | if (mFirstStep) { 318 | mShowLeftEye = animatedValue % 360 > 225.0f; 319 | mShowRightEye = animatedValue % 360 > 315.0f; 320 | 321 | // set arc sweep angle when the step is first, set value: 0.1f similar to a circle 322 | mSweepAngle = 0.1f; 323 | mStartAngle = (float) animation.getAnimatedValue(); 324 | } else { 325 | mShowLeftEye = (animatedValue / 360.0f <= 2) && animatedValue % 360 <= 225.0f; 326 | mShowRightEye = (animatedValue / 360.0f <= 2) && animatedValue % 360 <= 315.0f; 327 | if (animatedValue >= (720.0f + ROTATE_OFFSET)) { 328 | mStartAngle = (animatedValue - (720.0f + ROTATE_OFFSET)); 329 | mSweepAngle = ROTATE_OFFSET - mStartAngle; 330 | } else { 331 | mStartAngle = (animatedValue / 360.0f <= 1.625) ? 0 : animatedValue - mSweepAngle - 360; 332 | mSweepAngle = (animatedValue / 360.0f <= 1.625) ? animatedValue % 360 : 225 - (animatedValue - 225 - 360) / 5 * 3; 333 | } 334 | } 335 | invalidate(); 336 | } 337 | }); 338 | mValueAnimator.addListener(new Animator.AnimatorListener() { 339 | @Override 340 | public void onAnimationStart(Animator animation) { 341 | mRunning = true; 342 | } 343 | 344 | @Override 345 | public void onAnimationEnd(Animator animation) { 346 | mRunning = false; 347 | mStopping = false; 348 | if (mOnAnimPerformCompletedListener != null) { 349 | mOnAnimPerformCompletedListener.onCompleted(); 350 | } 351 | reset(); 352 | } 353 | 354 | @Override 355 | public void onAnimationCancel(Animator animation) { 356 | mRunning = false; 357 | mStopping = false; 358 | if (mOnAnimPerformCompletedListener != null) { 359 | mOnAnimPerformCompletedListener.onCompleted(); 360 | } 361 | reset(); 362 | } 363 | 364 | @Override 365 | public void onAnimationRepeat(Animator animation) { 366 | if (mStopUntilAnimationPerformCompleted) { 367 | animation.cancel(); 368 | mStopUntilAnimationPerformCompleted = false; 369 | } 370 | } 371 | }); 372 | mValueAnimator.start(); 373 | } 374 | 375 | /** 376 | * Start animation 377 | */ 378 | public void start() { 379 | start(ValueAnimator.INFINITE); 380 | } 381 | 382 | /** 383 | * Stop animation 384 | */ 385 | public void stop() { 386 | stop(true); 387 | } 388 | 389 | /** 390 | * stop it after animation perform completed 391 | * @param stopUntilAnimationPerformCompleted boolean 392 | */ 393 | public void stop(boolean stopUntilAnimationPerformCompleted) { 394 | if (mStopping || mValueAnimator == null || !mValueAnimator.isRunning()) { 395 | return; 396 | } 397 | mStopping = stopUntilAnimationPerformCompleted; 398 | 399 | mStopUntilAnimationPerformCompleted = stopUntilAnimationPerformCompleted; 400 | if (mValueAnimator != null && mValueAnimator.isRunning()) { 401 | if (!stopUntilAnimationPerformCompleted) { 402 | mValueAnimator.end(); 403 | } 404 | } else { 405 | mStopping = false; 406 | if (mOnAnimPerformCompletedListener != null) { 407 | mOnAnimPerformCompletedListener.onCompleted(); 408 | } 409 | } 410 | } 411 | 412 | /** 413 | * set status changed listener 414 | * @param l OnStatusChangedListener 415 | */ 416 | public void setOnAnimPerformCompletedListener(OnAnimPerformCompletedListener l) { 417 | mOnAnimPerformCompletedListener = l; 418 | } 419 | 420 | /** 421 | * reset UI 422 | */ 423 | private void reset() { 424 | mStartAngle = 0; 425 | mSweepAngle = 180; 426 | invalidate(); 427 | } 428 | 429 | /** 430 | * dp to px 431 | * @param dpValue dp 432 | * @return px 433 | */ 434 | private int dp2px(float dpValue) { 435 | final float scale = getContext().getResources().getDisplayMetrics().density; 436 | return (int) (dpValue * scale + 0.5f); 437 | } 438 | 439 | /** 440 | * Callback 441 | */ 442 | public interface OnAnimPerformCompletedListener { 443 | void onCompleted(); 444 | } 445 | } 446 | -------------------------------------------------------------------------------- /library/src/main/res/values/attrs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /library/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | library 3 | 4 | -------------------------------------------------------------------------------- /sample/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | *.iml -------------------------------------------------------------------------------- /sample/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion "23.0.2" 6 | 7 | defaultConfig { 8 | applicationId "cn.refactor.smileyloadingview" 9 | minSdkVersion 14 10 | targetSdkVersion 23 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(dir: 'libs', include: ['*.jar']) 24 | testCompile 'junit:junit:4.12' 25 | compile 'com.android.support:appcompat-v7:23.4.0' 26 | compile 'in.srain.cube:ultra-ptr:1.0.11' 27 | compile project(':library') 28 | compile 'com.android.support:recyclerview-v7:23.4.0' 29 | } 30 | -------------------------------------------------------------------------------- /sample/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/andy/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /sample/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /sample/src/main/java/cn/refactor/smileyloadingview/header/SmileyLoadingViewHeader.java: -------------------------------------------------------------------------------- 1 | package cn.refactor.smileyloadingview.header; 2 | 3 | import android.annotation.TargetApi; 4 | import android.content.Context; 5 | import android.os.Build; 6 | import android.util.AttributeSet; 7 | import android.view.View; 8 | import android.view.animation.AccelerateInterpolator; 9 | import android.view.animation.AlphaAnimation; 10 | import android.widget.FrameLayout; 11 | 12 | import cn.refactor.smileyloadingview.R; 13 | import cn.refactor.smileyloadingview.lib.SmileyLoadingView; 14 | import in.srain.cube.views.ptr.PtrFrameLayout; 15 | import in.srain.cube.views.ptr.PtrUIHandler; 16 | import in.srain.cube.views.ptr.indicator.PtrIndicator; 17 | 18 | /** 19 | * Create by andy (https://github.com/andyxialm) 20 | * Create time: 16/8/22 10:37 21 | * Description : SmileyLoadingViewHeader 22 | */ 23 | public class SmileyLoadingViewHeader extends FrameLayout implements PtrUIHandler { 24 | 25 | private SmileyLoadingView mLoadingView; 26 | 27 | public SmileyLoadingViewHeader(Context context) { 28 | this(context, null); 29 | } 30 | 31 | public SmileyLoadingViewHeader(Context context, AttributeSet attrs) { 32 | this(context, attrs, 0); 33 | } 34 | 35 | public SmileyLoadingViewHeader(Context context, AttributeSet attrs, int defStyleAttr) { 36 | super(context, attrs, defStyleAttr); 37 | init(); 38 | } 39 | 40 | @TargetApi(Build.VERSION_CODES.LOLLIPOP) 41 | public SmileyLoadingViewHeader(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 42 | super(context, attrs, defStyleAttr, defStyleRes); 43 | init(); 44 | } 45 | 46 | private void init() { 47 | View contentView = View.inflate(getContext(), R.layout.header_loading, null); 48 | mLoadingView = (SmileyLoadingView) contentView.findViewById(R.id.loading_view); 49 | addView(contentView); 50 | } 51 | 52 | @Override 53 | public void onUIReset(PtrFrameLayout frame) { 54 | mLoadingView.setVisibility(VISIBLE); 55 | } 56 | 57 | @Override 58 | public void onUIRefreshPrepare(PtrFrameLayout frame) { 59 | mLoadingView.setVisibility(VISIBLE); 60 | } 61 | 62 | @Override 63 | public void onUIRefreshBegin(PtrFrameLayout frame) { 64 | mLoadingView.start(); 65 | } 66 | 67 | @Override 68 | public void onUIRefreshComplete(final PtrFrameLayout frame) { 69 | mLoadingView.stop(); 70 | mLoadingView.setOnAnimPerformCompletedListener(new SmileyLoadingView.OnAnimPerformCompletedListener() { 71 | @Override 72 | public void onCompleted() { 73 | mLoadingView.setPaintAlpha(0x0); 74 | } 75 | }); 76 | } 77 | 78 | @Override 79 | public void onUIPositionChange(PtrFrameLayout frame, boolean isUnderTouch, byte status, PtrIndicator ptrIndicator) { 80 | mLoadingView.setPaintAlpha(ptrIndicator.getCurrentPercent() >= 1 ? 0xFF : (int) (ptrIndicator.getCurrentPercent() * 0xFF)); 81 | } 82 | 83 | @SuppressWarnings("unused") 84 | private void executeLoadingViewAnim() { 85 | AlphaAnimation alphaAnimation = new AlphaAnimation(0.0f, 1.0f); 86 | alphaAnimation.setInterpolator(new AccelerateInterpolator()); 87 | alphaAnimation.setDuration(150); 88 | alphaAnimation.setFillAfter(true); 89 | mLoadingView.startAnimation(alphaAnimation); 90 | } 91 | 92 | } 93 | -------------------------------------------------------------------------------- /sample/src/main/java/cn/refactor/smileyloadingview/ui/MainActivity.java: -------------------------------------------------------------------------------- 1 | package cn.refactor.smileyloadingview.ui; 2 | 3 | import android.content.Intent; 4 | import android.os.Bundle; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.view.View; 7 | 8 | import cn.refactor.smileyloadingview.R; 9 | 10 | /** 11 | * Create by andy (https://github.com/andyxialm) 12 | * Create time: 16/8/24 10:30 13 | * Description : Sample: SmileyLoadingView in pull to refresh 14 | */ 15 | public class MainActivity extends AppCompatActivity { 16 | 17 | @Override 18 | protected void onCreate(Bundle savedInstanceState) { 19 | super.onCreate(savedInstanceState); 20 | setContentView(R.layout.activity_main); 21 | } 22 | 23 | public void gotoSample(View v) { 24 | startActivity(new Intent(this, SampleActivity.class)); 25 | } 26 | 27 | public void gotoPullToRefresh(View v) { 28 | startActivity(new Intent(this, PullToRefreshActivity.class)); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /sample/src/main/java/cn/refactor/smileyloadingview/ui/PullToRefreshActivity.java: -------------------------------------------------------------------------------- 1 | package cn.refactor.smileyloadingview.ui; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.support.v7.widget.LinearLayoutManager; 7 | import android.support.v7.widget.RecyclerView; 8 | import android.view.LayoutInflater; 9 | import android.view.View; 10 | import android.view.ViewGroup; 11 | import android.widget.TextView; 12 | 13 | import java.util.ArrayList; 14 | import java.util.List; 15 | 16 | import cn.refactor.smileyloadingview.R; 17 | import in.srain.cube.views.ptr.PtrDefaultHandler; 18 | import in.srain.cube.views.ptr.PtrFrameLayout; 19 | import in.srain.cube.views.ptr.PtrHandler; 20 | 21 | /** 22 | * Create by andy (https://github.com/andyxialm) 23 | * Create time: 16/8/24 09:41 24 | * Description : Sample: SmileyLoadingView in pull to refresh 25 | */ 26 | public class PullToRefreshActivity extends AppCompatActivity { 27 | 28 | private RecyclerView mRecyclerView; 29 | private SamplePtrFrameLayout mPtrFrameLayout; 30 | private SampleListAdapter mListAdapter; 31 | 32 | private List mDataList; 33 | 34 | @Override 35 | protected void onCreate(@Nullable Bundle savedInstanceState) { 36 | super.onCreate(savedInstanceState); 37 | setContentView(R.layout.activity_list); 38 | setupViews(); 39 | autoRefresh(); 40 | } 41 | 42 | private void setupViews() { 43 | mPtrFrameLayout = (SamplePtrFrameLayout) findViewById(R.id.ptr_frame_layout); 44 | mPtrFrameLayout.setPtrHandler(new PtrHandler() { 45 | @Override 46 | public boolean checkCanDoRefresh(PtrFrameLayout frame, View content, View header) { 47 | return PtrDefaultHandler.checkContentCanBePulledDown(mPtrFrameLayout, mRecyclerView, header); 48 | } 49 | 50 | @Override 51 | public void onRefreshBegin(PtrFrameLayout frame) { 52 | refresh(); 53 | } 54 | }); 55 | 56 | mListAdapter = new SampleListAdapter(); 57 | mRecyclerView = (RecyclerView) findViewById(R.id.rv); 58 | RecyclerViewDivider divider = new RecyclerViewDivider(this, LinearLayoutManager.HORIZONTAL, 59 | 1, getResources().getColor(android.R.color.darker_gray)); 60 | mRecyclerView.addItemDecoration(divider); 61 | mRecyclerView.setAdapter(mListAdapter); 62 | } 63 | 64 | private void autoRefresh() { 65 | mPtrFrameLayout.postDelayed(new Runnable() { 66 | @Override 67 | public void run() { 68 | mPtrFrameLayout.autoRefresh(); 69 | } 70 | }, 500); 71 | } 72 | 73 | private void refresh() { 74 | mPtrFrameLayout.postDelayed(new Runnable() { 75 | @Override 76 | public void run() { 77 | if (mDataList == null) { 78 | mDataList = new ArrayList<>(); 79 | } else { 80 | mDataList.clear(); 81 | mListAdapter.notifyDataSetChanged(); 82 | } 83 | 84 | for (int i = 0; i < 15; i ++) { 85 | mDataList.add(String.valueOf(i)); 86 | } 87 | mListAdapter.notifyItemRangeChanged(0, mDataList.size() - 1); 88 | mPtrFrameLayout.refreshComplete(); 89 | } 90 | }, 3000); 91 | } 92 | 93 | private class SampleListAdapter extends RecyclerView.Adapter { 94 | 95 | @Override 96 | public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 97 | View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item, parent, false); 98 | return new ViewHolder(v); 99 | } 100 | 101 | @Override 102 | public void onBindViewHolder(ViewHolder holder, int position) { 103 | holder.bind(mDataList.get(position)); 104 | } 105 | 106 | @Override 107 | public int getItemCount() { 108 | return mDataList == null ? 0 : mDataList.size(); 109 | } 110 | 111 | class ViewHolder extends RecyclerView.ViewHolder { 112 | 113 | TextView mTextTv; 114 | 115 | public ViewHolder(View itemView) { 116 | super(itemView); 117 | mTextTv = (TextView) itemView.findViewById(R.id.tv_text); 118 | } 119 | 120 | public void bind(String text) { 121 | mTextTv.setText(text); 122 | } 123 | } 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /sample/src/main/java/cn/refactor/smileyloadingview/ui/RecyclerViewDivider.java: -------------------------------------------------------------------------------- 1 | package cn.refactor.smileyloadingview.ui; 2 | 3 | import android.content.Context; 4 | import android.content.res.TypedArray; 5 | import android.graphics.Canvas; 6 | import android.graphics.Paint; 7 | import android.graphics.Rect; 8 | import android.graphics.drawable.Drawable; 9 | import android.support.v4.content.ContextCompat; 10 | import android.support.v7.widget.LinearLayoutManager; 11 | import android.support.v7.widget.RecyclerView; 12 | import android.view.View; 13 | 14 | public class RecyclerViewDivider extends RecyclerView.ItemDecoration { 15 | 16 | private Paint mPaint; 17 | private Drawable mDivider; 18 | private int mDividerHeight = 2;//分割线高度,默认为1px 19 | private int mOrientation;//列表的方向:LinearLayoutManager.VERTICAL或LinearLayoutManager.HORIZONTAL 20 | private static final int[] ATTRS = new int[]{android.R.attr.listDivider}; 21 | 22 | /** 23 | * 默认分割线:高度为2px,颜色为灰色 24 | * 25 | * @param context context 26 | * @param orientation 列表方向 27 | */ 28 | public RecyclerViewDivider(Context context, int orientation) { 29 | if (orientation != LinearLayoutManager.VERTICAL && orientation != LinearLayoutManager.HORIZONTAL) { 30 | throw new IllegalArgumentException("请输入正确的参数!"); 31 | } 32 | mOrientation = orientation; 33 | 34 | final TypedArray a = context.obtainStyledAttributes(ATTRS); 35 | mDivider = a.getDrawable(0); 36 | a.recycle(); 37 | } 38 | 39 | /** 40 | * 自定义分割线 41 | * 42 | * @param context context 43 | * @param orientation 列表方向 44 | * @param drawableId 分割线图片 45 | */ 46 | public RecyclerViewDivider(Context context, int orientation, int drawableId) { 47 | this(context, orientation); 48 | mDivider = ContextCompat.getDrawable(context, drawableId); 49 | mDividerHeight = mDivider.getIntrinsicHeight(); 50 | } 51 | 52 | /** 53 | * 自定义分割线 54 | * 55 | * @param context context 56 | * @param orientation 列表方向 57 | * @param dividerHeight 分割线高度 58 | * @param dividerColor 分割线颜色 59 | */ 60 | public RecyclerViewDivider(Context context, int orientation, int dividerHeight, int dividerColor) { 61 | this(context, orientation); 62 | mDividerHeight = dividerHeight; 63 | mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); 64 | mPaint.setColor(dividerColor); 65 | mPaint.setStyle(Paint.Style.FILL); 66 | } 67 | 68 | 69 | //获取分割线尺寸 70 | @Override 71 | public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { 72 | super.getItemOffsets(outRect, view, parent, state); 73 | } 74 | 75 | @Override 76 | public void getItemOffsets(Rect outRect, int itemPosition, RecyclerView parent) { 77 | super.getItemOffsets(outRect, itemPosition, parent); 78 | if (itemPosition < parent.getAdapter().getItemCount() - 1) { 79 | outRect.set(0, 0, 0, mDividerHeight); 80 | } 81 | } 82 | 83 | //绘制分割线 84 | @Override 85 | public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) { 86 | super.onDraw(c, parent, state); 87 | if (mOrientation == LinearLayoutManager.VERTICAL) { 88 | drawVertical(c, parent); 89 | } else { 90 | drawHorizontal(c, parent); 91 | } 92 | } 93 | 94 | //绘制横向 item 分割线 95 | private void drawHorizontal(Canvas canvas, RecyclerView parent) { 96 | final int left = parent.getPaddingLeft(); 97 | final int right = parent.getMeasuredWidth() - parent.getPaddingRight(); 98 | final int childSize = parent.getChildCount(); 99 | for (int i = 0; i < childSize; i++) { 100 | final View child = parent.getChildAt(i); 101 | RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) child.getLayoutParams(); 102 | final int top = child.getBottom() + layoutParams.bottomMargin; 103 | final int bottom = top + mDividerHeight; 104 | if (mDivider != null) { 105 | mDivider.setBounds(left, top, right, bottom); 106 | mDivider.draw(canvas); 107 | } 108 | if (mPaint != null) { 109 | canvas.drawRect(left, top, right, bottom, mPaint); 110 | } 111 | } 112 | } 113 | 114 | //绘制纵向 item 分割线 115 | private void drawVertical(Canvas canvas, RecyclerView parent) { 116 | final int top = parent.getPaddingTop(); 117 | final int bottom = parent.getMeasuredHeight() - parent.getPaddingBottom(); 118 | final int childSize = parent.getChildCount(); 119 | for (int i = 0; i < childSize; i++) { 120 | final View child = parent.getChildAt(i); 121 | RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) child.getLayoutParams(); 122 | final int left = child.getRight() + layoutParams.rightMargin; 123 | final int right = left + mDividerHeight; 124 | if (mDivider != null) { 125 | mDivider.setBounds(left, top, right, bottom); 126 | mDivider.draw(canvas); 127 | } 128 | if (mPaint != null) { 129 | canvas.drawRect(left, top, right, bottom, mPaint); 130 | } 131 | } 132 | } 133 | 134 | } -------------------------------------------------------------------------------- /sample/src/main/java/cn/refactor/smileyloadingview/ui/SampleActivity.java: -------------------------------------------------------------------------------- 1 | package cn.refactor.smileyloadingview.ui; 2 | 3 | import android.support.v7.app.AppCompatActivity; 4 | import android.os.Bundle; 5 | import android.view.View; 6 | import android.widget.SeekBar; 7 | 8 | import cn.refactor.smileyloadingview.R; 9 | import cn.refactor.smileyloadingview.lib.SmileyLoadingView; 10 | 11 | /** 12 | * Create by andy (https://github.com/andyxialm) 13 | * Create time: 16/8/24 10:34 14 | * Description : Sample: SmileyLoadingView in pull to refresh 15 | */ 16 | public class SampleActivity extends AppCompatActivity { 17 | 18 | private SmileyLoadingView mSmileyLoadingView; 19 | 20 | @Override 21 | protected void onCreate(Bundle savedInstanceState) { 22 | super.onCreate(savedInstanceState); 23 | setContentView(R.layout.activity_sample); 24 | 25 | mSmileyLoadingView = (SmileyLoadingView) findViewById(R.id.loading_view); 26 | mSmileyLoadingView.setOnAnimPerformCompletedListener(new SmileyLoadingView.OnAnimPerformCompletedListener() { 27 | @Override 28 | public void onCompleted() { 29 | mSmileyLoadingView.setVisibility(View.INVISIBLE); 30 | } 31 | }); 32 | 33 | SeekBar seekBar = (SeekBar) findViewById(R.id.seek_bar); 34 | seekBar.setMax(0xFF); 35 | seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { 36 | @Override 37 | public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { 38 | mSmileyLoadingView.setPaintAlpha(progress); 39 | } 40 | 41 | @Override 42 | public void onStartTrackingTouch(SeekBar seekBar) { 43 | 44 | } 45 | 46 | @Override 47 | public void onStopTrackingTouch(SeekBar seekBar) { 48 | 49 | } 50 | }); 51 | seekBar.setProgress(0xFF); 52 | 53 | } 54 | 55 | public void showView(View v) { 56 | mSmileyLoadingView.setVisibility(View.VISIBLE); 57 | } 58 | 59 | public void start(View v) { 60 | mSmileyLoadingView.start(); 61 | } 62 | 63 | public void stop(View v) { 64 | mSmileyLoadingView.stop(false); 65 | } 66 | 67 | public void stopUtilAnimationCompleted(View v) { 68 | mSmileyLoadingView.stop(); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /sample/src/main/java/cn/refactor/smileyloadingview/ui/SamplePtrFrameLayout.java: -------------------------------------------------------------------------------- 1 | package cn.refactor.smileyloadingview.ui; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | 6 | import cn.refactor.smileyloadingview.header.SmileyLoadingViewHeader; 7 | import in.srain.cube.views.ptr.PtrFrameLayout; 8 | 9 | /** 10 | * Create by andy (https://github.com/andyxialm) 11 | * Create time: 16/8/24 10:11 12 | * Description : Sample: PtrFrameLayout with SmileyLoadingView 13 | */ 14 | public class SamplePtrFrameLayout extends PtrFrameLayout { 15 | public SamplePtrFrameLayout(Context context) { 16 | this(context, null); 17 | } 18 | 19 | public SamplePtrFrameLayout(Context context, AttributeSet attrs) { 20 | this(context, attrs, 0); 21 | } 22 | 23 | public SamplePtrFrameLayout(Context context, AttributeSet attrs, int defStyle) { 24 | super(context, attrs, defStyle); 25 | setupViews(); 26 | } 27 | 28 | private void setupViews() { 29 | SmileyLoadingViewHeader mHeaderView = new SmileyLoadingViewHeader(getContext()); 30 | setResistance(1.7f); 31 | setLoadingMinTime(1000); 32 | setDurationToCloseHeader(500); 33 | setRatioOfHeaderHeightToRefresh(1.0f); 34 | setKeepHeaderWhenRefresh(true); 35 | setHeaderView(mHeaderView); 36 | addPtrUIHandler(mHeaderView); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/activity_list.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 17 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 |