├── .gitignore ├── .idea ├── caches │ ├── build_file_checksums.ser │ └── gradle_models.ser ├── codeStyles │ └── Project.xml ├── encodings.xml ├── gradle.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml └── vcs.xml ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── rulerview │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── rulerview │ │ │ └── MainActivity.java │ └── res │ │ ├── layout │ │ └── activity_main.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 │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── rulerview │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── myres ├── 2.webp ├── rulerview.apk └── rulerview.gif ├── rulerlibrary ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── example │ │ └── rulerlibrary │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── rulerlibrary │ │ │ ├── DensityUtil.java │ │ │ ├── RulerView.java │ │ │ └── SizeViewValueChangeListener.java │ └── res │ │ └── values │ │ ├── attrs.xml │ │ └── strings.xml │ └── test │ └── java │ └── com │ └── example │ └── rulerlibrary │ └── ExampleUnitTest.java └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | /.idea/modules.xml 11 | 12 | -------------------------------------------------------------------------------- /.idea/caches/build_file_checksums.ser: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hnsycsxhzcsh/RulerView/c1ea6a29bcb8fc0b5a81dc3d88c4a24c5b63e941/.idea/caches/build_file_checksums.ser -------------------------------------------------------------------------------- /.idea/caches/gradle_models.ser: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hnsycsxhzcsh/RulerView/c1ea6a29bcb8fc0b5a81dc3d88c4a24c5b63e941/.idea/caches/gradle_models.ser -------------------------------------------------------------------------------- /.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/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 20 | 21 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 24 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | Android > Lint > Internationalization 51 | 52 | 53 | Internationalization issues 54 | 55 | 56 | Internationalization issuesJava 57 | 58 | 59 | Java 60 | 61 | 62 | 63 | 64 | Android 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 76 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # RulerView 2 | Android custom control RulerView, imitation only products will height, weight and other rulers, size control, slide to modify the scale value
3 | 自定义控件,身高、体重等标尺控件 4 | 5 | Download Apk 6 | 7 | Rendering
8 | 效果图 9 | 10 | 11 | 12 | The method referenced in the project:
13 | 项目中引用的方法: 14 | 15 | ### Step 1. Add the JitPack repository to your build file
16 | 步骤1.将JitPack存储库添加到构建文件中
17 | 项目的根build.gradle中添加以下代码: 18 | ```Java 19 | allprojects { 20 | repositories { 21 | ... 22 | maven { url 'https://jitpack.io' } 23 | } 24 | } 25 | ``` 26 | ### Step 2. Add the dependency
27 | 步骤2.build.gradle添加依赖项 28 | ```Java 29 | dependencies { 30 | implementation 'com.github.hnsycsxhzcsh:RulerView:v1.3' 31 | } 32 | ``` 33 | ### Step 3. Reference control in layout
34 | 步骤3. 布局中引用控件 35 | ```Java 36 | 45 | ``` 46 | ### Step 4. Add listener to the activity 47 | 步骤4. activity中添加监听 48 | ```Java 49 | mSizeViewKg = findViewById(R.id.sizeview_kg); 50 | 51 | //设置初始化值 52 | mSizeViewKg.setCurrentValue(89); 53 | 54 | mSizeViewKg.setOnValueChangeListener(new SizeViewValueChangeListener() { 55 | @Override 56 | public void onValueChange(int value) { 57 | //获取现在的值 58 | } 59 | }); 60 | ``` 61 | 我的博客地址:https://blog.csdn.net/m0_38074457/article/details/85305237 62 | 63 | If my control helps you, please help click on the top right corner, thank you!
64 | ### 如果有帮助到大家希望点下右上角Star,谢谢! 65 | 66 | 67 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 23 5 | defaultConfig { 6 | applicationId "com.rulerview" 7 | minSdkVersion 17 8 | targetSdkVersion 23 9 | versionCode 1 10 | versionName "1.0" 11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 17 | } 18 | } 19 | } 20 | 21 | dependencies { 22 | implementation fileTree(include: ['*.jar'], dir: 'libs') 23 | implementation 'com.android.support:appcompat-v7:23.1.0' 24 | implementation 'com.android.support.constraint:constraint-layout:1.1.3' 25 | testImplementation 'junit:junit:4.12' 26 | androidTestImplementation 'com.android.support.test:runner:1.0.1' 27 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' 28 | implementation project(':rulerlibrary') 29 | } 30 | -------------------------------------------------------------------------------- /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/rulerview/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.rulerview; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.rulerview", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /app/src/main/java/com/rulerview/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.rulerview; 2 | 3 | import android.support.v7.app.AppCompatActivity; 4 | import android.os.Bundle; 5 | import android.view.View; 6 | 7 | import com.rulerlibrary.RulerView; 8 | import com.rulerlibrary.SizeViewValueChangeListener; 9 | 10 | public class MainActivity extends AppCompatActivity { 11 | 12 | private RulerView mSizeViewKg; 13 | private RulerView mSizeViewCm; 14 | 15 | @Override 16 | protected void onCreate(Bundle savedInstanceState) { 17 | super.onCreate(savedInstanceState); 18 | setContentView(R.layout.activity_main); 19 | 20 | mSizeViewKg = (RulerView) findViewById(R.id.sizeview_kg); 21 | mSizeViewCm = (RulerView) findViewById(R.id.sizeview_cm); 22 | 23 | mSizeViewKg.setCurrentValue(90); 24 | 25 | mSizeViewKg.setOnValueChangeListener(new SizeViewValueChangeListener() { 26 | @Override 27 | public void onValueChange(int value) { 28 | 29 | } 30 | }); 31 | 32 | mSizeViewCm.setOnValueChangeListener(new SizeViewValueChangeListener() { 33 | @Override 34 | public void onValueChange(int value) { 35 | 36 | } 37 | }); 38 | 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 19 | 20 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hnsycsxhzcsh/RulerView/c1ea6a29bcb8fc0b5a81dc3d88c4a24c5b63e941/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hnsycsxhzcsh/RulerView/c1ea6a29bcb8fc0b5a81dc3d88c4a24c5b63e941/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hnsycsxhzcsh/RulerView/c1ea6a29bcb8fc0b5a81dc3d88c4a24c5b63e941/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hnsycsxhzcsh/RulerView/c1ea6a29bcb8fc0b5a81dc3d88c4a24c5b63e941/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hnsycsxhzcsh/RulerView/c1ea6a29bcb8fc0b5a81dc3d88c4a24c5b63e941/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | RulerView 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/test/java/com/rulerview/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.rulerview; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | 5 | repositories { 6 | maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/'} 7 | google() 8 | jcenter() 9 | } 10 | dependencies { 11 | classpath 'com.android.tools.build:gradle:3.0.1' 12 | 13 | 14 | // NOTE: Do not place your application dependencies here; they belong 15 | // in the individual module build.gradle files 16 | } 17 | } 18 | 19 | allprojects { 20 | repositories { 21 | maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/'} 22 | google() 23 | jcenter() 24 | } 25 | } 26 | 27 | task clean(type: Delete) { 28 | delete rootProject.buildDir 29 | } 30 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | org.gradle.jvmargs=-Xmx1536m 13 | 14 | # When configured, Gradle will run in incubating parallel mode. 15 | # This option should only be used with decoupled projects. More details, visit 16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 17 | # org.gradle.parallel=true 18 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hnsycsxhzcsh/RulerView/c1ea6a29bcb8fc0b5a81dc3d88c4a24c5b63e941/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Dec 26 21:42:00 CST 2018 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip 7 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /myres/2.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hnsycsxhzcsh/RulerView/c1ea6a29bcb8fc0b5a81dc3d88c4a24c5b63e941/myres/2.webp -------------------------------------------------------------------------------- /myres/rulerview.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hnsycsxhzcsh/RulerView/c1ea6a29bcb8fc0b5a81dc3d88c4a24c5b63e941/myres/rulerview.apk -------------------------------------------------------------------------------- /myres/rulerview.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hnsycsxhzcsh/RulerView/c1ea6a29bcb8fc0b5a81dc3d88c4a24c5b63e941/myres/rulerview.gif -------------------------------------------------------------------------------- /rulerlibrary/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /rulerlibrary/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion 23 5 | 6 | defaultConfig { 7 | minSdkVersion 17 8 | targetSdkVersion 23 9 | versionCode 1 10 | versionName "1.0" 11 | 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 13 | 14 | } 15 | 16 | buildTypes { 17 | release { 18 | minifyEnabled false 19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 20 | } 21 | } 22 | 23 | } 24 | 25 | dependencies { 26 | implementation fileTree(dir: 'libs', include: ['*.jar']) 27 | 28 | implementation 'com.android.support:appcompat-v7:23.1.0' 29 | testImplementation 'junit:junit:4.12' 30 | androidTestImplementation 'com.android.support.test:runner:1.0.1' 31 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' 32 | } 33 | -------------------------------------------------------------------------------- /rulerlibrary/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 | -------------------------------------------------------------------------------- /rulerlibrary/src/androidTest/java/com/example/rulerlibrary/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.example.rulerlibrary; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.example.rulerlibrary.test", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /rulerlibrary/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | -------------------------------------------------------------------------------- /rulerlibrary/src/main/java/com/rulerlibrary/DensityUtil.java: -------------------------------------------------------------------------------- 1 | package com.rulerlibrary; 2 | 3 | import android.content.Context; 4 | import android.util.TypedValue; 5 | 6 | public class DensityUtil { 7 | 8 | public static int dip2px(Context context, float dpValue) { 9 | final float scale = context.getResources().getDisplayMetrics().density; 10 | return (int) (dpValue * scale + 0.5f); 11 | } 12 | 13 | public static int px2dip(Context context, float pxValue) { 14 | final float scale = context.getResources().getDisplayMetrics().density; 15 | return (int) (pxValue / scale + 0.5f); 16 | } 17 | 18 | public static int dipToPix(Context context, int dip) { 19 | int size = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dip, context.getResources().getDisplayMetrics()); 20 | return size; 21 | } 22 | 23 | 24 | } 25 | -------------------------------------------------------------------------------- /rulerlibrary/src/main/java/com/rulerlibrary/RulerView.java: -------------------------------------------------------------------------------- 1 | package com.rulerlibrary; 2 | 3 | import android.animation.ValueAnimator; 4 | import android.annotation.SuppressLint; 5 | import android.content.Context; 6 | import android.content.res.TypedArray; 7 | import android.graphics.Canvas; 8 | import android.graphics.Color; 9 | import android.graphics.Paint; 10 | import android.graphics.Path; 11 | import android.graphics.Rect; 12 | import android.graphics.RectF; 13 | import android.graphics.Region; 14 | import android.graphics.RegionIterator; 15 | import android.support.v4.view.GestureDetectorCompat; 16 | import android.text.TextUtils; 17 | import android.util.AttributeSet; 18 | import android.view.GestureDetector; 19 | import android.view.MotionEvent; 20 | import android.view.View; 21 | 22 | /** 23 | * Created by HARRY on 2018/12/26. 24 | */ 25 | 26 | public class RulerView extends View { 27 | 28 | //控件宽 29 | private int mMeasuredWidth = 0; 30 | //控件高 31 | private int mMeasuredHeight = 0; 32 | //标尺宽 33 | private int mRulerWid; 34 | //标尺高 35 | private int mRulerHei; 36 | //标尺的左侧离控件的左侧的距离 37 | private int mLeft; 38 | //标尺的右侧离控件左侧的距离 39 | private int mRight; 40 | //标尺顶部离控件顶部距离 41 | private int mTop; 42 | //标尺底部离控件顶部的距离 43 | private int mBottom; 44 | //标题 45 | private String mTitleName; 46 | //画笔 47 | private Paint mPaint = new Paint(); 48 | //目前设置刻度值默认显示6个单位值,打个比方初始显示可见的值是20-80,那么mLineOffset的值就是,标尺的宽除以6 49 | private int mLineOffset; 50 | //标尺刻度的长度 51 | private int mLineLong; 52 | //标尺指示器的长度 53 | private int mIndicatorLong; 54 | //最大刻度值 55 | private int mMaxValue; 56 | //最小刻度值 57 | private int mMinValue; 58 | //现在的刻度值 59 | private float mCurrentValue; 60 | //平均单位值下占有的px值 61 | private float mAverage; 62 | //标尺中间坐标x值 63 | private int mRulerMiddleX; 64 | //标尺刻度值y坐标 65 | private int mValueY; 66 | //实时手指移动时候的x坐标 67 | private float mCurrentDownX; 68 | //点击标尺时候记录下的点击y坐标 69 | private float mStartClickY; 70 | //点击标尺时候记录下的点击x坐标 71 | private float mStartClickX; 72 | //标尺单位名 73 | private String mUnitName; 74 | //滑动监听 75 | private SizeViewValueChangeListener listener; 76 | private GestureDetectorCompat mDetector; 77 | private ValueAnimator animator; 78 | private Path mPath = new Path(); //标尺裁剪线 79 | private float mCornor; //标尺圆角 80 | private RectF mRectFLeftTop; 81 | private RectF mRectFLeftBottom; 82 | private RectF mRectFRightTop; 83 | private RectF mRectFRightBottom; 84 | private int mRulerStokeWidth = 3;//刻度尺边框宽度 85 | 86 | public RulerView(Context context) { 87 | this(context, null); 88 | } 89 | 90 | public RulerView(Context context, AttributeSet attrs) { 91 | this(context, attrs, 0); 92 | } 93 | 94 | public RulerView(Context context, AttributeSet attrs, int defStyleAttr) { 95 | super(context, attrs, defStyleAttr); 96 | initView(context, attrs); 97 | } 98 | 99 | private void initView(Context context, AttributeSet attrs) { 100 | mDetector = new GestureDetectorCompat(context, new RulerGestureListener()); 101 | mCornor = DensityUtil.dip2px(getContext(), 6); 102 | 103 | TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.RulerView); 104 | if (array != null) { 105 | String titleName = array.getString(R.styleable.RulerView_titleName); 106 | String unitName = array.getString(R.styleable.RulerView_unitName); 107 | int minValue = array.getInt(R.styleable.RulerView_minValue, 30); 108 | int maxValue = array.getInt(R.styleable.RulerView_maxValue, 120); 109 | int currentValue = array.getInt(R.styleable.RulerView_currentValue, 70); 110 | 111 | if (TextUtils.isEmpty(titleName)) { 112 | mTitleName = "体重"; 113 | } else { 114 | mTitleName = titleName; 115 | } 116 | if (TextUtils.isEmpty(unitName)) { 117 | mUnitName = "kg"; 118 | } else { 119 | mUnitName = unitName; 120 | } 121 | mMaxValue = maxValue; 122 | mMinValue = minValue; 123 | //默认让标尺距离左侧为100 124 | mLeft = 100; 125 | //默认让标尺距离顶部距离为100 126 | mTop = 100; 127 | setCurrentValue(currentValue); 128 | array.recycle(); 129 | } 130 | } 131 | 132 | @Override 133 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 134 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); 135 | int modeHei = MeasureSpec.getMode(heightMeasureSpec); 136 | mMeasuredWidth = getMeasuredWidth(); 137 | if (modeHei == MeasureSpec.AT_MOST || modeHei == MeasureSpec.UNSPECIFIED) { 138 | //不确定控件高度情况下设置一个默认值 139 | int heiDefault = DensityUtil.dip2px(getContext(), 140); 140 | setMeasuredDimension(mMeasuredWidth, heiDefault); 141 | } else if (modeHei == MeasureSpec.EXACTLY) { 142 | //确切值不做任何操作 143 | } 144 | mMeasuredHeight = getMeasuredHeight(); 145 | //设置标尺宽度 146 | mRulerWid = mMeasuredWidth - 2 * mLeft; 147 | 148 | mRight = mLeft + mRulerWid; 149 | //默认让标尺可见的范围内可以显示6个单位的刻度 150 | mLineOffset = mRulerWid / 6; 151 | mRulerHei = mMeasuredHeight - 2 * mTop; 152 | mBottom = mRulerHei + mTop; 153 | //使刻度线的长度为标尺高度的1/3 154 | mLineLong = mRulerHei / 3; 155 | //标尺的指示器的长度为标尺高度的1/2 156 | mIndicatorLong = mRulerHei / 2; 157 | 158 | //单位刻度下占有的屏幕宽度 159 | mAverage = mLineOffset / 10; 160 | //标尺中间的位置的x坐标 161 | mRulerMiddleX = mMeasuredWidth / 2; 162 | //标尺刻度值的y坐标位置 163 | mValueY = mTop + mLineLong + 100; 164 | 165 | //计算剪辑路径 166 | measureClipPath(); 167 | } 168 | 169 | @Override 170 | protected void onDraw(Canvas canvas) { 171 | super.onDraw(canvas); 172 | //画整体背景为白色 173 | initDraw(canvas); 174 | //画标尺 175 | drawRuler(canvas); 176 | //画标题 177 | drawTitle(canvas); 178 | //画实时刻度值 179 | drawRulerValue(canvas, (int) mCurrentValue); 180 | //剪辑 181 | canvas.clipPath(mPath, Region.Op.DIFFERENCE); 182 | canvas.drawColor(Color.WHITE); 183 | } 184 | 185 | /** 186 | * 计算剪辑路径 187 | */ 188 | private void measureClipPath() { 189 | int left = mLeft - 2; 190 | int top = mTop - 2; 191 | int right = mRight + 2; 192 | int bottom = mBottom + 2; 193 | 194 | mRectFLeftTop = new RectF(left, top, left + 2 * mCornor, top + 2 * mCornor); 195 | mRectFRightTop = new RectF(right - 2 * mCornor, top, right, top + 2 * mCornor); 196 | mRectFRightBottom = new RectF(right - 2 * mCornor, bottom - 2 * mCornor, right, bottom); 197 | mRectFLeftBottom = new RectF(left, bottom - 2 * mCornor, left + 2 * mCornor, bottom); 198 | 199 | int left2 = mLeft - mRulerStokeWidth; 200 | int top2 = mTop - mRulerStokeWidth; 201 | int right2 = mRight + mRulerStokeWidth; 202 | int bottom2 = mBottom + mRulerStokeWidth; 203 | 204 | mPath.moveTo(left2 + mCornor, top2); 205 | mPath.lineTo(right - mCornor, top2); 206 | mPath.arcTo(mRectFRightTop, 270f, 90f, false); 207 | mPath.lineTo(right2, bottom2 - mCornor); 208 | mPath.arcTo(mRectFRightBottom, 0f, 90f, false); 209 | mPath.lineTo(left2 + mCornor, bottom2); 210 | mPath.arcTo(mRectFLeftBottom, 90f, 90f, false); 211 | mPath.lineTo(left2, top2 + mCornor); 212 | mPath.arcTo(mRectFLeftTop, 180f, 90f, false); 213 | } 214 | 215 | private void drawTitle(Canvas canvas) { 216 | setTitlePaint(); 217 | //画标题,使标题底部正好在标尺顶部,baseLineY的实现原理这里不讲了,大家百度下 218 | Paint.FontMetricsInt fm = mPaint.getFontMetricsInt(); 219 | int baseLineY = mTop - fm.bottom; 220 | canvas.drawText(mTitleName, mMeasuredWidth / 2, baseLineY - 10, mPaint); 221 | } 222 | 223 | private void initDraw(Canvas canvas) { 224 | mPaint.setColor(Color.parseColor("#FFFFFF")); 225 | mPaint.setStyle(Paint.Style.FILL); 226 | 227 | RectF rect = new RectF(0, 0, mMeasuredWidth, mMeasuredHeight); 228 | canvas.drawRect(rect, mPaint); 229 | } 230 | 231 | private void setTitlePaint() { 232 | mPaint.setColor(Color.BLACK); 233 | mPaint.setTextSize(40); 234 | mPaint.setStyle(Paint.Style.FILL); 235 | mPaint.setTextAlign(Paint.Align.CENTER); 236 | } 237 | 238 | private void drawRuler(Canvas canvas) { 239 | RectF rulerRect = new RectF(); 240 | rulerRect.set(mLeft, mTop, mRight, mBottom); 241 | 242 | //画标尺的背景 243 | setRulerBackgroundPaint(); 244 | int cornor = DensityUtil.dip2px(getContext(), 6); 245 | canvas.drawRoundRect(rulerRect, cornor, cornor, mPaint); 246 | 247 | //画标尺的刻度线和刻度 248 | drawRulerLine(canvas, (int) mCurrentValue); 249 | 250 | //画标尺的指示器线 251 | setIndicatorLinePaint(); 252 | canvas.drawLine(mMeasuredWidth / 2, mTop, mMeasuredWidth / 2, mTop + mIndicatorLong, mPaint); 253 | 254 | //画标尺的背景边框 255 | setRulerStrokePaint(); 256 | canvas.drawRoundRect(rulerRect, cornor, cornor, mPaint); 257 | } 258 | 259 | private void drawRulerValue(Canvas canvas, int indicatorValue) { 260 | setIndicatorValuePaint(); 261 | //计算出baseLine位置,使文字正好在标尺的下面,具体原理这里就不讲了,大家百度 262 | Paint.FontMetricsInt fm = mPaint.getFontMetricsInt(); 263 | int baseLineY = mBottom - fm.top; 264 | canvas.drawText(indicatorValue + " " + mUnitName, mRulerMiddleX, baseLineY, mPaint); 265 | } 266 | 267 | private void drawRulerLine(Canvas canvas, int indicatorValue) { 268 | setTitlePaint(); 269 | //目前标尺值十位数字值 270 | int remainder = indicatorValue % 10; 271 | 272 | setRulerLinePaint(); 273 | //画右侧长线 274 | int startXRl = (int) (mRulerMiddleX + mAverage * (10 - remainder)); 275 | int endXRl = startXRl; 276 | int startYRl = mTop; 277 | int endYRl = mTop + mLineLong; 278 | int valueRl = (indicatorValue / 10 + 1) * 10; 279 | while (startXRl <= mRight && valueRl <= mMaxValue) { 280 | canvas.drawLine(startXRl, startYRl, endXRl, endYRl, mPaint); 281 | canvas.drawText("" + valueRl, startXRl, mValueY, mPaint); 282 | startXRl = startXRl + mLineOffset; 283 | endXRl = startXRl; 284 | valueRl = valueRl + 10; 285 | } 286 | 287 | //画右侧短线 288 | int startYRs = mTop; 289 | int endYRs = mTop + mLineLong / 2; 290 | int valueRs = 0; 291 | int startXRs = 0; 292 | if (remainder > 5) { 293 | valueRs = (indicatorValue / 10 + 1) * 10 + 5; 294 | startXRs = (int) (mRulerMiddleX + mAverage * (10 - remainder + 5)); 295 | } else { 296 | valueRs = (indicatorValue / 10) * 10 + 5; 297 | startXRs = (int) (mRulerMiddleX + mAverage * (5 - remainder)); 298 | } 299 | int endXRs = startXRs; 300 | while (startXRs <= mRight && valueRs <= mMaxValue) { 301 | canvas.drawLine(startXRs, startYRs, endXRs, endYRs, mPaint); 302 | startXRs = startXRs + mLineOffset; 303 | endXRs = startXRs; 304 | valueRs = valueRs + 10; 305 | } 306 | 307 | //画左侧长线 308 | int startXLl = (int) (mRulerMiddleX - mAverage * remainder); 309 | int endXLl = startXLl; 310 | int startYLl = mTop; 311 | int endYLl = mTop + mLineLong; 312 | int valueLl = (indicatorValue / 10) * 10; 313 | while (startXLl >= mLeft && valueLl >= mMinValue) { 314 | canvas.drawLine(startXLl, startYLl, endXLl, endYLl, mPaint); 315 | canvas.drawText("" + valueLl, startXLl, mValueY, mPaint); 316 | startXLl = startXLl - mLineOffset; 317 | endXLl = startXLl; 318 | valueLl = valueLl - 10; 319 | } 320 | 321 | //画左侧短线 322 | int startYLs = mTop; 323 | int endYLs = mTop + mLineLong / 2; 324 | int startXLs = 0; 325 | int valueLs = 0; 326 | if (remainder > 5) { 327 | valueLs = (indicatorValue / 10) * 10 + 5; 328 | startXLs = (int) (mRulerMiddleX - mAverage * (remainder - 5)); 329 | } else { 330 | valueLs = (indicatorValue / 10 - 1) * 10 + 5; 331 | startXLs = (int) (mRulerMiddleX - mAverage * (remainder + 5)); 332 | } 333 | int endXLs = startXLs; 334 | while (startXLs >= mLeft && valueLs >= mMinValue) { 335 | canvas.drawLine(startXLs, startYLs, endXLs, endYLs, mPaint); 336 | startXLs = startXLs - mLineOffset; 337 | endXLs = startXLs; 338 | valueLs = valueLs - 10; 339 | } 340 | } 341 | 342 | @Override 343 | public boolean onTouchEvent(MotionEvent event) { 344 | return mDetector.onTouchEvent(event); 345 | } 346 | 347 | private class RulerGestureListener extends GestureDetector.SimpleOnGestureListener { 348 | @Override 349 | public boolean onDown(MotionEvent e) { 350 | if (animator != null) { 351 | animator.cancel(); 352 | } 353 | mCurrentDownX = e.getX(); 354 | //记录用户点击屏幕时候的坐标点 355 | mStartClickX = mCurrentDownX; 356 | mStartClickY = e.getY(); 357 | return true; 358 | } 359 | 360 | @Override 361 | public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { 362 | System.out.println("onScroll"); 363 | if (mStartClickX >= mLeft && mStartClickX <= mRight && 364 | mStartClickY >= mTop && mStartClickY < mBottom) { 365 | float value = mCurrentValue + distanceX / mAverage; 366 | setCurrentValue(value); 367 | invalidate(); 368 | if (listener != null) { 369 | listener.onValueChange((int) mCurrentValue); 370 | } 371 | } 372 | return true; 373 | } 374 | 375 | @Override 376 | public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { 377 | System.out.println("onFling"); 378 | if (mStartClickX >= mLeft && mStartClickX <= mRight && 379 | mStartClickY >= mTop && mStartClickY < mBottom) { 380 | animator = ValueAnimator.ofFloat(velocityX, 0); 381 | animator.setDuration(1000); 382 | // animator.setInterpolator(new LinearInterpolator()); 383 | animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 384 | @Override 385 | public void onAnimationUpdate(ValueAnimator animation) { 386 | float animatedValue = (float) animation.getAnimatedValue(); 387 | float value = mCurrentValue - (animatedValue * (float) 0.005) / mAverage; 388 | setCurrentValue(value); 389 | invalidate(); 390 | if (listener != null) { 391 | listener.onValueChange((int) mCurrentValue); 392 | } 393 | } 394 | }); 395 | animator.start(); 396 | } 397 | return true; 398 | } 399 | } 400 | 401 | public void setCurrentValue(float value) { 402 | mCurrentValue = value; 403 | if (mCurrentValue < mMinValue) { 404 | mCurrentValue = mMinValue; 405 | } else if (mCurrentValue > mMaxValue) { 406 | mCurrentValue = mMaxValue; 407 | } 408 | } 409 | 410 | private void setIndicatorValuePaint() { 411 | mPaint.setColor(Color.RED); 412 | mPaint.setStyle(Paint.Style.FILL); 413 | mPaint.setTextSize(60); 414 | //使文字居中显示 415 | mPaint.setTextAlign(Paint.Align.CENTER); 416 | } 417 | 418 | private void setIndicatorLinePaint() { 419 | mPaint.setColor(Color.parseColor("#FF0000")); 420 | mPaint.setStrokeWidth(3); 421 | } 422 | 423 | private void setRulerLinePaint() { 424 | // mPaint.setColor(Color.parseColor("#E2E2E2")); 425 | mPaint.setColor(Color.parseColor("#000000")); 426 | mPaint.setStrokeWidth(3); 427 | } 428 | 429 | private void setRulerBackgroundPaint() { 430 | mPaint.setStyle(Paint.Style.FILL); 431 | mPaint.setColor(Color.parseColor("#F8F8F8")); 432 | } 433 | 434 | private void setRulerStrokePaint() { 435 | mPaint.setStyle(Paint.Style.STROKE); 436 | // mPaint.setColor(Color.parseColor("#E2E2E2")); 437 | mPaint.setColor(Color.parseColor("#000000")); 438 | mPaint.setStrokeWidth(mRulerStokeWidth); 439 | } 440 | 441 | public void setOnValueChangeListener(SizeViewValueChangeListener listener) { 442 | this.listener = listener; 443 | } 444 | 445 | 446 | } 447 | -------------------------------------------------------------------------------- /rulerlibrary/src/main/java/com/rulerlibrary/SizeViewValueChangeListener.java: -------------------------------------------------------------------------------- 1 | package com.rulerlibrary; 2 | 3 | /** 4 | * Created by HARRY on 2018/12/25. 5 | */ 6 | 7 | public interface SizeViewValueChangeListener { 8 | void onValueChange(int value); 9 | } 10 | -------------------------------------------------------------------------------- /rulerlibrary/src/main/res/values/attrs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /rulerlibrary/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | RulerLibrary 3 | 4 | -------------------------------------------------------------------------------- /rulerlibrary/src/test/java/com/example/rulerlibrary/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.example.rulerlibrary; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':rulerlibrary' 2 | --------------------------------------------------------------------------------