├── .gitignore ├── README.md ├── art └── easing.gif ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── library ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── github │ │ └── r21nomi │ │ └── androidrpinterpolator │ │ └── ApplicationTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── github │ │ │ └── r21nomi │ │ │ └── androidrpinterpolator │ │ │ ├── Easing.java │ │ │ └── RPInterpolator.java │ └── res │ │ └── values │ │ └── strings.xml │ └── test │ └── java │ └── com │ └── github │ └── r21nomi │ └── androidrpinterpolator │ └── ExampleUnitTest.java ├── sample ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── github │ │ └── r21nomi │ │ └── sample │ │ └── ApplicationTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── github │ │ │ └── r21nomi │ │ │ └── sample │ │ │ └── androidrpinterpolator │ │ │ └── MainActivity.java │ └── res │ │ ├── drawable │ │ └── circle.xml │ │ ├── layout │ │ ├── activity_main.xml │ │ └── 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 │ └── test │ └── java │ └── com │ └── github │ └── r21nomi │ └── androidrpinterpolator │ └── ExampleUnitTest.java └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea 6 | .DS_Store 7 | /build 8 | /captures 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AndroidRPInterpolator 2 | [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-AndroidRPInterpolator-green.svg?style=true)](https://android-arsenal.com/details/1/3223) 3 | 4 | AndroidRPInterpolator is the interpolator library using [Rovert Penner's Easing Functions](http://robertpenner.com/easing/). 5 | 6 | ![easing.gif](art/easing.gif) 7 | 8 | ## Getting Started 9 | ```groovy 10 | dependencies { 11 | compile 'com.github.r21nomi:androidrpinterpolator:1.0.0' 12 | } 13 | ``` 14 | 15 | ## Usage 16 | ```java 17 | ObjectAnimator animator = ObjectAnimator.ofFloat(mTargetView, "translationX", 0, 300); 18 | animator.setInterpolator(new RPInterpolator(Easing.SINE_IN_OUT)); 19 | animator.start(); 20 | ``` 21 | 22 | ## License 23 | ``` 24 | Copyright 2016 Ryota Niinomi (r21nomi) 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. 37 | ``` 38 | -------------------------------------------------------------------------------- /art/easing.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/r21nomi/AndroidRPInterpolator/9ad29b7851e6f24ec12e96c5e9af307fbba71321/art/easing.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:1.5.0' 9 | classpath 'com.novoda:bintray-release:0.3.4' 10 | } 11 | } 12 | 13 | allprojects { 14 | repositories { 15 | jcenter() 16 | } 17 | } 18 | 19 | task clean(type: Delete) { 20 | delete rootProject.buildDir 21 | } 22 | -------------------------------------------------------------------------------- /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/r21nomi/AndroidRPInterpolator/9ad29b7851e6f24ec12e96c5e9af307fbba71321/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Oct 21 11:34:03 PDT 2015 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.8-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # 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 | -------------------------------------------------------------------------------- /library/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'com.novoda.bintray-release' 3 | 4 | android { 5 | compileSdkVersion 23 6 | buildToolsVersion "23.0.2" 7 | 8 | defaultConfig { 9 | minSdkVersion 15 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.1.1' 26 | } 27 | 28 | publish { 29 | userOrg = 'r21nomi' 30 | groupId = 'com.github.r21nomi' 31 | artifactId = 'androidrpinterpolator' 32 | publishVersion = '1.0.0' 33 | desc = 'AndroidRPInterpolator is the interpolator library using Rovert Penner\'s Easing Functions.' 34 | website = 'https://github.com/r21nomi/AndroidRPInterpolator' 35 | } -------------------------------------------------------------------------------- /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/a12690/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/androidTest/java/com/github/r21nomi/androidrpinterpolator/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.github.r21nomi.androidrpinterpolator; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /library/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /library/src/main/java/com/github/r21nomi/androidrpinterpolator/Easing.java: -------------------------------------------------------------------------------- 1 | package com.github.r21nomi.androidrpinterpolator; 2 | 3 | /** 4 | * Created by Ryota Niinomi on 16/02/28. 5 | */ 6 | public enum Easing { 7 | LINEAR, 8 | SINE_IN, 9 | SINE_OUT, 10 | SINE_IN_OUT, 11 | QUAD_IN, 12 | QUAD_OUT, 13 | QUAD_IN_OUT, 14 | CUBIC_IN, 15 | CUBIC_OUT, 16 | CUBIC_IN_OUT, 17 | QUART_IN, 18 | QUART_OUT, 19 | QUART_IN_OUT, 20 | QUINT_IN, 21 | QUINT_OUT, 22 | QUINT_IN_OUT, 23 | EXPO_IN, 24 | EXPO_OUT, 25 | EXPO_IN_OUT, 26 | CIRC_IN, 27 | CIRC_OUT, 28 | CIRC_IN_OUT, 29 | BACK_IN, 30 | BACK_OUT, 31 | BACK_IN_OUT, 32 | ELASTIC_IN, 33 | ELASTIC_OUT, 34 | ELASTIC_IN_OUT, 35 | BOUNCE_IN, 36 | BOUNCE_OUT, 37 | BOUNCE_IN_OUT 38 | } 39 | -------------------------------------------------------------------------------- /library/src/main/java/com/github/r21nomi/androidrpinterpolator/RPInterpolator.java: -------------------------------------------------------------------------------- 1 | package com.github.r21nomi.androidrpinterpolator; 2 | 3 | import android.view.animation.Interpolator; 4 | 5 | /** 6 | * Created by Ryota Niinomi on 16/02/21. 7 | * 8 | * This interpolator use Rebert Penner's Easing Functions. 9 | * @see http://robertpenner.com/easing/ 10 | */ 11 | public class RPInterpolator implements Interpolator { 12 | 13 | private Easing mEasing; 14 | 15 | public RPInterpolator() { 16 | mEasing = Easing.LINEAR; 17 | } 18 | 19 | public RPInterpolator(Easing easing) { 20 | mEasing = easing; 21 | } 22 | 23 | @Override 24 | public float getInterpolation(float elapsedTimeRate) { 25 | switch (mEasing) { 26 | case LINEAR: 27 | return elapsedTimeRate; 28 | 29 | case SINE_IN: 30 | return (float) (1f - Math.cos(elapsedTimeRate * Math.PI / 2f)); 31 | 32 | case SINE_OUT: 33 | return (float) Math.sin(elapsedTimeRate * Math.PI / 2f); 34 | 35 | case SINE_IN_OUT: 36 | return (float) (-0.5f * (Math.cos(Math.PI * elapsedTimeRate) - 1f)); 37 | 38 | case QUAD_IN: 39 | return getPowIn(elapsedTimeRate, 2); 40 | 41 | case QUAD_OUT: 42 | return getPowOut(elapsedTimeRate, 2); 43 | 44 | case QUAD_IN_OUT: 45 | return getPowInOut(elapsedTimeRate, 2); 46 | 47 | case CUBIC_IN: 48 | return getPowIn(elapsedTimeRate, 3); 49 | 50 | case CUBIC_OUT: 51 | return getPowOut(elapsedTimeRate, 3); 52 | 53 | case CUBIC_IN_OUT: 54 | return getPowInOut(elapsedTimeRate, 3); 55 | 56 | case QUART_IN: 57 | return getPowIn(elapsedTimeRate, 4); 58 | 59 | case QUART_OUT: 60 | return getPowOut(elapsedTimeRate, 4); 61 | 62 | case QUART_IN_OUT: 63 | return getPowInOut(elapsedTimeRate, 4); 64 | 65 | case QUINT_IN: 66 | return getPowIn(elapsedTimeRate, 5); 67 | 68 | case QUINT_OUT: 69 | return getPowOut(elapsedTimeRate, 5); 70 | 71 | case QUINT_IN_OUT: 72 | return getPowInOut(elapsedTimeRate, 5); 73 | 74 | case BACK_IN: 75 | return (float) (elapsedTimeRate * elapsedTimeRate * ((1.7 + 1f) * elapsedTimeRate - 1.7)); 76 | 77 | case BACK_OUT: 78 | return (float) (--elapsedTimeRate * elapsedTimeRate * ((1.7 + 1f) * elapsedTimeRate + 1.7) + 1f); 79 | 80 | case BACK_IN_OUT: 81 | return getBackInOut(elapsedTimeRate, 1.7f); 82 | 83 | case EXPO_IN: 84 | return (elapsedTimeRate == 0) ? 0 : (float) Math.pow(2, 10 * (elapsedTimeRate - 1)); 85 | 86 | case EXPO_OUT: 87 | return (elapsedTimeRate == 1) ? 1 : (-(float)Math.pow(2, -10 * elapsedTimeRate) + 1); 88 | 89 | case EXPO_IN_OUT: 90 | if (elapsedTimeRate == 0) { 91 | return 0; 92 | 93 | } else if (elapsedTimeRate == 1) { 94 | return 1; 95 | 96 | } else if ((elapsedTimeRate /= 0.5f) < 1) { 97 | return 0.5f * (float)Math.pow(2, 10 * (elapsedTimeRate - 1)); 98 | 99 | } else { 100 | return 0.5f * (-(float) Math.pow(2, -10 * --elapsedTimeRate) + 2); 101 | } 102 | 103 | case CIRC_IN: 104 | return (float) -(Math.sqrt(1f - elapsedTimeRate * elapsedTimeRate) - 1); 105 | 106 | case CIRC_OUT: 107 | return (float) Math.sqrt(1f - (--elapsedTimeRate) * elapsedTimeRate); 108 | 109 | case CIRC_IN_OUT: 110 | if ((elapsedTimeRate *= 2f) < 1f) { 111 | return (float) (-0.5f * (Math.sqrt(1f - elapsedTimeRate * elapsedTimeRate) - 1f)); 112 | } 113 | return (float) (0.5f * (Math.sqrt(1f - (elapsedTimeRate -= 2f) * elapsedTimeRate) + 1f)); 114 | 115 | case ELASTIC_IN: 116 | return getElasticIn(elapsedTimeRate, 1, 0.3); 117 | 118 | case ELASTIC_OUT: 119 | return getElasticOut(elapsedTimeRate, 1, 0.3); 120 | 121 | case ELASTIC_IN_OUT: 122 | return getElasticInOut(elapsedTimeRate, 1, 0.45); 123 | 124 | case BOUNCE_IN: 125 | return getBounceIn(elapsedTimeRate); 126 | 127 | case BOUNCE_OUT: 128 | return getBounceOut(elapsedTimeRate); 129 | 130 | case BOUNCE_IN_OUT: 131 | if (elapsedTimeRate < 0.5f) { 132 | return getBounceIn(elapsedTimeRate * 2f) * 0.5f; 133 | } 134 | return getBounceOut(elapsedTimeRate * 2f - 1f) * 0.5f + 0.5f; 135 | 136 | default: 137 | return 1f; 138 | 139 | } 140 | } 141 | 142 | private float getPowIn(float elapsedTimeRate, double pow) { 143 | return (float) Math.pow(elapsedTimeRate, pow); 144 | } 145 | 146 | private float getPowOut(float elapsedTimeRate, double pow) { 147 | return (float) ((float) 1 - Math.pow(1 - elapsedTimeRate, pow)); 148 | } 149 | 150 | private float getPowInOut(float elapsedTimeRate, double pow) { 151 | if ((elapsedTimeRate *= 2) < 1) { 152 | return (float) (0.5 * Math.pow(elapsedTimeRate, pow)); 153 | } 154 | 155 | return (float) (1 - 0.5 * Math.abs(Math.pow(2 - elapsedTimeRate, pow))); 156 | } 157 | 158 | private float getBackInOut(float elapsedTimeRate, float amount) { 159 | amount *= 1.525; 160 | if ((elapsedTimeRate *= 2) < 1) { 161 | return (float) (0.5 * (elapsedTimeRate * elapsedTimeRate * ((amount + 1) * elapsedTimeRate - amount))); 162 | } 163 | 164 | return (float) (0.5 * ((elapsedTimeRate -= 2) * elapsedTimeRate * ((amount + 1) * elapsedTimeRate + amount) + 2)); 165 | } 166 | 167 | private float getBounceIn(float elapsedTimeRate) { 168 | return 1f - getBounceOut(1f - elapsedTimeRate); 169 | } 170 | 171 | private float getBounceOut(float elapsedTimeRate) { 172 | if (elapsedTimeRate < 1 / 2.75) { 173 | return (float) (7.5625 * elapsedTimeRate * elapsedTimeRate); 174 | 175 | } else if (elapsedTimeRate < 2 / 2.75) { 176 | return (float) (7.5625 * (elapsedTimeRate -= 1.5 / 2.75) * elapsedTimeRate + 0.75); 177 | 178 | } else if (elapsedTimeRate < 2.5 / 2.75) { 179 | return (float) (7.5625 * (elapsedTimeRate -= 2.25 / 2.75) * elapsedTimeRate + 0.9375); 180 | 181 | } else { 182 | return (float) (7.5625 * (elapsedTimeRate -= 2.625 / 2.75) * elapsedTimeRate + 0.984375); 183 | } 184 | } 185 | 186 | private float getElasticIn(float elapsedTimeRate, double amplitude, double period) { 187 | if (elapsedTimeRate == 0 || elapsedTimeRate == 1) return elapsedTimeRate; 188 | double pi2 = Math.PI * 2; 189 | double s = period / pi2 * Math.asin(1 / amplitude); 190 | 191 | return (float) -(amplitude * Math.pow(2f, 10f * (elapsedTimeRate -= 1f)) * Math.sin((elapsedTimeRate - s) * pi2 / period)); 192 | } 193 | 194 | private float getElasticOut(float elapsedTimeRate, double amplitude, double period) { 195 | if (elapsedTimeRate == 0 || elapsedTimeRate == 1) return elapsedTimeRate; 196 | 197 | double pi2 = Math.PI * 2; 198 | double s = period / pi2 * Math.asin(1 / amplitude); 199 | 200 | return (float) (amplitude * Math.pow(2, -10 * elapsedTimeRate) * Math.sin((elapsedTimeRate - s) * pi2 / period) + 1); 201 | } 202 | 203 | private float getElasticInOut(float elapsedTimeRate, double amplitude, double period) { 204 | double pi2 = Math.PI * 2; 205 | 206 | double s = period / pi2 * Math.asin(1 / amplitude); 207 | if ((elapsedTimeRate *= 2) < 1) { 208 | return (float) (-0.5f * (amplitude * Math.pow(2, 10 * (elapsedTimeRate -= 1f)) * Math.sin((elapsedTimeRate - s) * pi2 / period))); 209 | } 210 | 211 | return (float) (amplitude * Math.pow(2, -10 * (elapsedTimeRate -= 1)) * Math.sin((elapsedTimeRate - s) * pi2 / period) * 0.5 + 1); 212 | } 213 | } 214 | -------------------------------------------------------------------------------- /library/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Library 3 | 4 | -------------------------------------------------------------------------------- /library/src/test/java/com/github/r21nomi/androidrpinterpolator/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.github.r21nomi.androidrpinterpolator; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * To work on unit tests, switch the Test Artifact in the Build Variants view. 9 | */ 10 | public class ExampleUnitTest { 11 | @Test 12 | public void addition_isCorrect() throws Exception { 13 | assertEquals(4, 2 + 2); 14 | } 15 | } -------------------------------------------------------------------------------- /sample/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /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 "com.github.r21nomi.androidrpinterpolator" 9 | minSdkVersion 15 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.1.1' 26 | compile project(':library') 27 | } 28 | -------------------------------------------------------------------------------- /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/a12690/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/androidTest/java/com/github/r21nomi/sample/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.github.r21nomi.sample; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /sample/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /sample/src/main/java/com/github/r21nomi/sample/androidrpinterpolator/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.github.r21nomi.sample.androidrpinterpolator; 2 | 3 | import android.animation.ObjectAnimator; 4 | import android.content.Context; 5 | import android.graphics.Point; 6 | import android.os.Bundle; 7 | import android.support.v7.app.AppCompatActivity; 8 | import android.view.Display; 9 | import android.view.View; 10 | import android.view.WindowManager; 11 | import android.widget.LinearLayout; 12 | import android.widget.TextView; 13 | 14 | import com.github.r21nomi.androidrpinterpolator.Easing; 15 | import com.github.r21nomi.androidrpinterpolator.RPInterpolator; 16 | import com.github.r21nomi.sample.R; 17 | 18 | import java.util.HashMap; 19 | import java.util.Map; 20 | 21 | public class MainActivity extends AppCompatActivity { 22 | 23 | private static final long ANIMATE_DURATION = 1000; 24 | private Map mAnimateTargetSets = new HashMap<>(); 25 | 26 | @Override 27 | protected void onCreate(Bundle savedInstanceState) { 28 | super.onCreate(savedInstanceState); 29 | setContentView(R.layout.activity_main); 30 | 31 | setAnimateTargetViews(); 32 | startAnimation(); 33 | } 34 | 35 | private void setAnimateTargetViews() { 36 | for (Easing easing : Easing.values()) { 37 | View view = getLayoutInflater().inflate(R.layout.item, null); 38 | view.setOnClickListener(new View.OnClickListener() { 39 | @Override 40 | public void onClick(View v) { 41 | startAnimation(); 42 | } 43 | }); 44 | ((TextView)view.findViewWithTag("name")) 45 | .setText(easing.toString()); 46 | ((LinearLayout)findViewById(R.id.root)).addView(view); 47 | 48 | mAnimateTargetSets.put(easing, view); 49 | } 50 | } 51 | 52 | private void startAnimation() { 53 | Display display = getDisplay(getApplication()); 54 | Point size = new Point(); 55 | display.getSize(size); 56 | 57 | float x = size.x - 600; 58 | 59 | for (Easing easing : mAnimateTargetSets.keySet()) { 60 | ObjectAnimator animator = ObjectAnimator.ofFloat( 61 | mAnimateTargetSets.get(easing).findViewWithTag("target"), "translationX", 0, x); 62 | animator.setDuration(ANIMATE_DURATION); 63 | animator.setInterpolator(new RPInterpolator(easing)); 64 | animator.start(); 65 | } 66 | } 67 | 68 | private Display getDisplay(final Context context) { 69 | return ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /sample/src/main/res/drawable/circle.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/item.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 16 | 17 | 23 | -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/r21nomi/AndroidRPInterpolator/9ad29b7851e6f24ec12e96c5e9af307fbba71321/sample/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/r21nomi/AndroidRPInterpolator/9ad29b7851e6f24ec12e96c5e9af307fbba71321/sample/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/r21nomi/AndroidRPInterpolator/9ad29b7851e6f24ec12e96c5e9af307fbba71321/sample/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/r21nomi/AndroidRPInterpolator/9ad29b7851e6f24ec12e96c5e9af307fbba71321/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/r21nomi/AndroidRPInterpolator/9ad29b7851e6f24ec12e96c5e9af307fbba71321/sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /sample/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /sample/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /sample/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | AndroidRPInterpolator 3 | 4 | -------------------------------------------------------------------------------- /sample/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /sample/src/test/java/com/github/r21nomi/androidrpinterpolator/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.github.r21nomi.sample; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * To work on unit tests, switch the Test Artifact in the Build Variants view. 9 | */ 10 | public class ExampleUnitTest { 11 | @Test 12 | public void addition_isCorrect() throws Exception { 13 | assertEquals(4, 2 + 2); 14 | } 15 | } -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':sample', ':library' 2 | --------------------------------------------------------------------------------