├── .gitignore ├── LICENSE ├── README.md └── ScaleView ├── .gitignore ├── .idea ├── .gitignore ├── .name ├── codeStyles │ ├── Project.xml │ └── codeStyleConfig.xml ├── compiler.xml ├── gradle.xml ├── jarRepositories.xml ├── misc.xml └── runConfigurations.xml ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── mrr │ │ └── scaleview │ │ └── ExampleInstrumentedTest.kt │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── mrr │ │ │ └── scaleview │ │ │ └── MainActivity.kt │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable-xxhdpi │ │ ├── brightness.png │ │ ├── lollipop.png │ │ └── night_brightness.png │ │ ├── drawable │ │ ├── bottom_rectangle.xml │ │ ├── ic_launcher_background.xml │ │ ├── left_rectangle.xml │ │ ├── right_rectangle.xml │ │ └── up_rectangle.xml │ │ ├── layout │ │ └── activity_main.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── values-night │ │ └── themes.xml │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── themes.xml │ └── test │ └── java │ └── com │ └── mrr │ └── scaleview │ └── ExampleUnitTest.kt ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── libScaleView ├── .gitignore ├── build.gradle ├── consumer-rules.pro ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── mrr │ │ └── libscaleview │ │ └── ExampleInstrumentedTest.kt │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── mrr │ │ │ └── libscaleview │ │ │ ├── ScaleView.kt │ │ │ ├── attr │ │ │ └── ScaleViewAttr.kt │ │ │ ├── builder │ │ │ └── ScaleBuilder.kt │ │ │ ├── enum │ │ │ └── ScaleAttrEnum.kt │ │ │ ├── rectf │ │ │ ├── CursorRectF.kt │ │ │ └── ScaleTextRectF.kt │ │ │ ├── util │ │ │ └── UnitConversion.kt │ │ │ └── view │ │ │ ├── BaseScaleView.kt │ │ │ ├── CircleScaleView.kt │ │ │ ├── HorizontalScaleView.kt │ │ │ └── VerticalScaleView.kt │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable-xxhdpi │ │ ├── brightness.png │ │ ├── lollipop.png │ │ └── night_brightness.png │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── attr.xml │ │ ├── colors.xml │ │ └── strings.xml │ └── test │ └── java │ └── com │ └── mrr │ └── libscaleview │ └── ExampleUnitTest.kt └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.aar 4 | *.ap_ 5 | *.aab 6 | 7 | # Files for the ART/Dalvik VM 8 | *.dex 9 | 10 | # Java class files 11 | *.class 12 | 13 | # Generated files 14 | bin/ 15 | gen/ 16 | out/ 17 | # Uncomment the following line in case you need and you don't have the release build type files in your app 18 | # release/ 19 | 20 | # Gradle files 21 | .gradle/ 22 | build/ 23 | 24 | # Local configuration file (sdk path, etc) 25 | local.properties 26 | 27 | # Proguard folder generated by Eclipse 28 | proguard/ 29 | 30 | # Log Files 31 | *.log 32 | 33 | # Android Studio Navigation editor temp files 34 | .navigation/ 35 | 36 | # Android Studio captures folder 37 | captures/ 38 | 39 | # IntelliJ 40 | *.iml 41 | .idea/workspace.xml 42 | .idea/tasks.xml 43 | .idea/gradle.xml 44 | .idea/assetWizardSettings.xml 45 | .idea/dictionaries 46 | .idea/libraries 47 | # Android Studio 3 in .gitignore file. 48 | .idea/caches 49 | .idea/modules.xml 50 | # Comment next line if keeping position of elements in Navigation Editor is relevant for you 51 | .idea/navEditor.xml 52 | 53 | # Keystore files 54 | # Uncomment the following lines if you do not want to check your keystore files in. 55 | #*.jks 56 | #*.keystore 57 | 58 | # External native build folder generated in Android Studio 2.2 and later 59 | .externalNativeBuild 60 | .cxx/ 61 | 62 | # Google Services (e.g. APIs or Firebase) 63 | # google-services.json 64 | 65 | # Freeline 66 | freeline.py 67 | freeline/ 68 | freeline_project_description.json 69 | 70 | # fastlane 71 | fastlane/report.xml 72 | fastlane/Preview.html 73 | fastlane/screenshots 74 | fastlane/test_output 75 | fastlane/readme.md 76 | 77 | # Version control 78 | vcs.xml 79 | 80 | # lint 81 | lint/intermediates/ 82 | lint/generated/ 83 | lint/outputs/ 84 | lint/tmp/ 85 | # lint/reports/ 86 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | ## ScaleView 3 | > 刻度尺组件,可实现圆形表盘效果 4 | 5 | ### 主要功能介绍 6 | 最开始是想做一横向的刻度尺效果,后来实现的时候发现竖向以及圆形刻度尺(表盘效果)实现代码有很大的相同之处,索性全部做出效果. 7 | 8 | - [x] 实现横向,竖向,圆形刻度效果 9 | - [x] 游标可自由设置图片,大小以及与刻度的距离 10 | - [x] 可自定义刻度默认颜色和进度颜色 11 | - [x] 刻度线宽度使用scaleNodeWidth,scaleWidth(占用整个组件大小比例)已经padding来控制 12 | - [x] 游标图片不设置,就不会绘制游标,从而达到控制游标时候显示的效果 13 | - [x] 刻度Text可不设置 14 | - [x] 圆形游标跟随弧度旋转 15 | 16 | ### 效果图 17 | 更多效果运行demo查看 18 | 19 | ![device-2021-04-16-152444](https://user-images.githubusercontent.com/10650866/115175361-6bc25500-a0fd-11eb-9279-f42aa19f4c6f.png) 20 | 21 | 22 | ## Attributes属性 23 | >在ScaleView布局文件中调用 24 | 下面的属性并不是每个指示器都用得到,所以使用时要注意! 25 | 26 | |Attributes|format|describe 27 | |---|---|---| 28 | |scaleWidth|float|刻度线的宽度占用组件大小的比例 29 | |scaleNodeWidth|float|节点刻度线宽度占用组件大小的比例 30 | |scaleLineWidth|float|刻度线的线条粗细 31 | |scaleDirect|enum|线性组件方向:horizontal(默认) or vertical 32 | |progressDirect|enum|暂无效果,后续逐渐完善 33 | |scaleStyle|enum|组件样式 线性:line(默认) 圆形:circle 34 | |cursorDrawable|reference|游标图片 35 | |cursorSeat|enum|游标相对组件的位置 线性使用:left,top,right,bottom 圆形使用:inside,outside 36 | |cursorWidth|dimension|游标是按照一个正方形来绘制的,指定游标宽度,相当于同时指定游标大小 37 | |cursorGap|dimension|游标距离刻度线的距离 38 | |scaleTextSeat|enum|刻度Text对组件的位置 线性使用:left,top,right,bottom 圆形使用:inside,outside 39 | |scaleTextColor|color|刻度Text字体颜色 40 | |scaleTextSize|dimension|刻度Text字体大小 41 | |scaleTextGap|dimension|刻度Text距离刻度线的距离 42 | |totalProgress|integer|刻度总进度 43 | |unitScale|integer|刻度单元格 44 | |defaultColor|color|刻度线默认颜色 45 | |progressColor|color|刻度线进度颜色 46 | 47 | 48 | ## 使用示例 49 | 50 | #### 示例 1.横向刻度 51 | 52 | ```xml 53 | 76 | ``` 77 | 78 | #### 示例 2.竖向刻度 79 | 80 | ```xml 81 | 105 | ``` 106 | 107 | #### 示例 3.圆形刻度 108 | 109 | ```xml 110 | 135 | ``` 136 | 137 | ## 存在的问题 138 | 139 | * 目前还未支持gradle方式引入工程,后续会提供 140 | 141 | `感觉此工程还未达到一个完善的地步,等到完善后上传maven仓库,目前可使用下载源码,或者生成aar的形式引用工程` 142 | 143 | * 不支持代码设置属性生效,后续会提供 144 | 145 | `只有在使用Builder初始化的时候会生效配置,没有提供代码设置属性的功能,后续逐步完善,xml的形式集成感觉已经够用` 146 | 147 | 148 | * 刻度不支持设置进度方向,圆形刻度不支持设置起点,后续会提供 149 | 150 | * 刻度Text目前不能根据进度改变颜色,后续会提供 151 | 152 | 153 | -------------------------------------------------------------------------------- /ScaleView/.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/caches 5 | /.idea/libraries 6 | /.idea/modules.xml 7 | /.idea/workspace.xml 8 | /.idea/navEditor.xml 9 | /.idea/assetWizardSettings.xml 10 | .DS_Store 11 | /build 12 | /captures 13 | .externalNativeBuild 14 | .cxx 15 | local.properties 16 | -------------------------------------------------------------------------------- /ScaleView/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | -------------------------------------------------------------------------------- /ScaleView/.idea/.name: -------------------------------------------------------------------------------- 1 | ScaleView -------------------------------------------------------------------------------- /ScaleView/.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 20 | 22 | 23 | 135 | 136 | 138 | 139 | -------------------------------------------------------------------------------- /ScaleView/.idea/codeStyles/codeStyleConfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /ScaleView/.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /ScaleView/.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 21 | 22 | -------------------------------------------------------------------------------- /ScaleView/.idea/jarRepositories.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 9 | 10 | 14 | 15 | 19 | 20 | 24 | 25 | 29 | 30 | 34 | 35 | -------------------------------------------------------------------------------- /ScaleView/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 9 | -------------------------------------------------------------------------------- /ScaleView/.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | -------------------------------------------------------------------------------- /ScaleView/app/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /ScaleView/app/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'com.android.application' 3 | id 'kotlin-android' 4 | } 5 | 6 | android { 7 | compileSdkVersion 30 8 | buildToolsVersion "30.0.0" 9 | 10 | defaultConfig { 11 | applicationId "com.mrr.calibrationview" 12 | minSdkVersion 28 13 | targetSdkVersion 30 14 | versionCode 1 15 | versionName "1.0" 16 | 17 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 18 | } 19 | 20 | buildTypes { 21 | release { 22 | minifyEnabled false 23 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 24 | } 25 | } 26 | compileOptions { 27 | sourceCompatibility JavaVersion.VERSION_1_8 28 | targetCompatibility JavaVersion.VERSION_1_8 29 | } 30 | kotlinOptions { 31 | jvmTarget = '1.8' 32 | } 33 | } 34 | 35 | dependencies { 36 | 37 | implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" 38 | implementation 'androidx.core:core-ktx:1.3.2' 39 | implementation 'androidx.appcompat:appcompat:1.2.0' 40 | implementation 'com.google.android.material:material:1.3.0' 41 | implementation 'androidx.constraintlayout:constraintlayout:2.0.4' 42 | implementation project(path: ':libScaleView') 43 | testImplementation 'junit:junit:4.+' 44 | androidTestImplementation 'androidx.test.ext:junit:1.1.2' 45 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' 46 | } -------------------------------------------------------------------------------- /ScaleView/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 -------------------------------------------------------------------------------- /ScaleView/app/src/androidTest/java/com/mrr/scaleview/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package com.mrr.scaleview 2 | 3 | import androidx.test.platform.app.InstrumentationRegistry 4 | import androidx.test.ext.junit.runners.AndroidJUnit4 5 | 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | 9 | import org.junit.Assert.* 10 | 11 | /** 12 | * Instrumented test, which will execute on an Android device. 13 | * 14 | * See [testing documentation](http://d.android.com/tools/testing). 15 | */ 16 | @RunWith(AndroidJUnit4::class) 17 | class ExampleInstrumentedTest { 18 | @Test 19 | fun useAppContext() { 20 | // Context of the app under test. 21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext 22 | assertEquals("com.mrr.calibrationview", appContext.packageName) 23 | } 24 | } -------------------------------------------------------------------------------- /ScaleView/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /ScaleView/app/src/main/java/com/mrr/scaleview/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.mrr.scaleview 2 | 3 | import androidx.appcompat.app.AppCompatActivity 4 | import android.os.Bundle 5 | import android.util.Log 6 | import com.mrr.libscaleview.ScaleView 7 | 8 | class MainActivity : AppCompatActivity() { 9 | private val TAG = "MainActivity" 10 | 11 | override fun onCreate(savedInstanceState: Bundle?) { 12 | super.onCreate(savedInstanceState) 13 | 14 | setContentView(R.layout.activity_main) 15 | 16 | } 17 | 18 | inner class progress : ScaleView.ProgressChangeListener { 19 | 20 | override fun progressChange(progress: Float) { 21 | 22 | Log.d(TAG, "progressChange: progress $progress") 23 | 24 | } 25 | 26 | } 27 | } -------------------------------------------------------------------------------- /ScaleView/app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 15 | 18 | 21 | 22 | 23 | 24 | 30 | -------------------------------------------------------------------------------- /ScaleView/app/src/main/res/drawable-xxhdpi/brightness.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrR0990/ScaleView/b9d4e25c075d746722305ac6086c3fa82cadc8ba/ScaleView/app/src/main/res/drawable-xxhdpi/brightness.png -------------------------------------------------------------------------------- /ScaleView/app/src/main/res/drawable-xxhdpi/lollipop.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrR0990/ScaleView/b9d4e25c075d746722305ac6086c3fa82cadc8ba/ScaleView/app/src/main/res/drawable-xxhdpi/lollipop.png -------------------------------------------------------------------------------- /ScaleView/app/src/main/res/drawable-xxhdpi/night_brightness.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrR0990/ScaleView/b9d4e25c075d746722305ac6086c3fa82cadc8ba/ScaleView/app/src/main/res/drawable-xxhdpi/night_brightness.png -------------------------------------------------------------------------------- /ScaleView/app/src/main/res/drawable/bottom_rectangle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /ScaleView/app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /ScaleView/app/src/main/res/drawable/left_rectangle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /ScaleView/app/src/main/res/drawable/right_rectangle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /ScaleView/app/src/main/res/drawable/up_rectangle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /ScaleView/app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 33 | 34 | 35 | 57 | 58 | 83 | 84 | 108 | 109 | 133 | 134 | 135 | 158 | 159 | 160 | 166 | 167 | 168 | 175 | 176 | 182 | 183 | 189 | 190 | -------------------------------------------------------------------------------- /ScaleView/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /ScaleView/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /ScaleView/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrR0990/ScaleView/b9d4e25c075d746722305ac6086c3fa82cadc8ba/ScaleView/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /ScaleView/app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrR0990/ScaleView/b9d4e25c075d746722305ac6086c3fa82cadc8ba/ScaleView/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /ScaleView/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrR0990/ScaleView/b9d4e25c075d746722305ac6086c3fa82cadc8ba/ScaleView/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /ScaleView/app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrR0990/ScaleView/b9d4e25c075d746722305ac6086c3fa82cadc8ba/ScaleView/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /ScaleView/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrR0990/ScaleView/b9d4e25c075d746722305ac6086c3fa82cadc8ba/ScaleView/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /ScaleView/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrR0990/ScaleView/b9d4e25c075d746722305ac6086c3fa82cadc8ba/ScaleView/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /ScaleView/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrR0990/ScaleView/b9d4e25c075d746722305ac6086c3fa82cadc8ba/ScaleView/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /ScaleView/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrR0990/ScaleView/b9d4e25c075d746722305ac6086c3fa82cadc8ba/ScaleView/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /ScaleView/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrR0990/ScaleView/b9d4e25c075d746722305ac6086c3fa82cadc8ba/ScaleView/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /ScaleView/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrR0990/ScaleView/b9d4e25c075d746722305ac6086c3fa82cadc8ba/ScaleView/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /ScaleView/app/src/main/res/values-night/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16 | -------------------------------------------------------------------------------- /ScaleView/app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #FFBB86FC 4 | #FF6200EE 5 | #FF3700B3 6 | #FF03DAC5 7 | #FF018786 8 | #FF000000 9 | #FFFFFFFF 10 | #FFEB3B 11 | #9C9898 12 | -------------------------------------------------------------------------------- /ScaleView/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | ScaleView 3 | -------------------------------------------------------------------------------- /ScaleView/app/src/main/res/values/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16 | -------------------------------------------------------------------------------- /ScaleView/app/src/test/java/com/mrr/scaleview/ExampleUnitTest.kt: -------------------------------------------------------------------------------- 1 | package com.mrr.scaleview 2 | 3 | import org.junit.Test 4 | 5 | import org.junit.Assert.* 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * See [testing documentation](http://d.android.com/tools/testing). 11 | */ 12 | class ExampleUnitTest { 13 | @Test 14 | fun addition_isCorrect() { 15 | assertEquals(4, 2 + 2) 16 | } 17 | } -------------------------------------------------------------------------------- /ScaleView/build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | buildscript { 3 | ext.kotlin_version = "1.4.32" 4 | repositories { 5 | google() 6 | jcenter() 7 | } 8 | dependencies { 9 | classpath 'com.android.tools.build:gradle:4.2.0' 10 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 11 | 12 | // NOTE: Do not place your application dependencies here; they belong 13 | // in the individual module build.gradle files 14 | } 15 | } 16 | 17 | allprojects { 18 | repositories { 19 | google() 20 | jcenter() 21 | } 22 | } 23 | 24 | task clean(type: Delete) { 25 | delete rootProject.buildDir 26 | } -------------------------------------------------------------------------------- /ScaleView/gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | # AndroidX package structure to make it clearer which packages are bundled with the 15 | # Android operating system, and which are packaged with your app"s APK 16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn 17 | android.useAndroidX=true 18 | # Automatically convert third-party libraries to use AndroidX 19 | android.enableJetifier=true 20 | # Kotlin code style for this project: "official" or "obsolete": 21 | kotlin.code.style=official -------------------------------------------------------------------------------- /ScaleView/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrR0990/ScaleView/b9d4e25c075d746722305ac6086c3fa82cadc8ba/ScaleView/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /ScaleView/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Fri Apr 16 14:16:28 CST 2021 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-6.7.1-all.zip 7 | -------------------------------------------------------------------------------- /ScaleView/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /ScaleView/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /ScaleView/libScaleView/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /ScaleView/libScaleView/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'com.android.library' 3 | id 'kotlin-android' 4 | } 5 | 6 | android { 7 | compileSdkVersion 30 8 | buildToolsVersion "30.0.0" 9 | 10 | defaultConfig { 11 | minSdkVersion 28 12 | targetSdkVersion 30 13 | versionCode 1 14 | versionName "1.0" 15 | 16 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 17 | consumerProguardFiles "consumer-rules.pro" 18 | } 19 | 20 | buildTypes { 21 | release { 22 | minifyEnabled false 23 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 24 | } 25 | } 26 | compileOptions { 27 | sourceCompatibility JavaVersion.VERSION_1_8 28 | targetCompatibility JavaVersion.VERSION_1_8 29 | } 30 | kotlinOptions { 31 | jvmTarget = '1.8' 32 | } 33 | } 34 | 35 | dependencies { 36 | 37 | implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" 38 | implementation 'androidx.core:core-ktx:1.3.2' 39 | } -------------------------------------------------------------------------------- /ScaleView/libScaleView/consumer-rules.pro: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrR0990/ScaleView/b9d4e25c075d746722305ac6086c3fa82cadc8ba/ScaleView/libScaleView/consumer-rules.pro -------------------------------------------------------------------------------- /ScaleView/libScaleView/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 -------------------------------------------------------------------------------- /ScaleView/libScaleView/src/androidTest/java/com/mrr/libscaleview/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package com.mrr.libscaleview 2 | 3 | import androidx.test.platform.app.InstrumentationRegistry 4 | import androidx.test.ext.junit.runners.AndroidJUnit4 5 | 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | 9 | import org.junit.Assert.* 10 | 11 | /** 12 | * Instrumented test, which will execute on an Android device. 13 | * 14 | * See [testing documentation](http://d.android.com/tools/testing). 15 | */ 16 | @RunWith(AndroidJUnit4::class) 17 | class ExampleInstrumentedTest { 18 | @Test 19 | fun useAppContext() { 20 | // Context of the app under test. 21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext 22 | assertEquals("com.mrr.libscaleview.test", appContext.packageName) 23 | } 24 | } -------------------------------------------------------------------------------- /ScaleView/libScaleView/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | -------------------------------------------------------------------------------- /ScaleView/libScaleView/src/main/java/com/mrr/libscaleview/ScaleView.kt: -------------------------------------------------------------------------------- 1 | package com.mrr.libscaleview 2 | 3 | import android.content.Context 4 | import android.graphics.* 5 | import android.util.AttributeSet 6 | import android.view.MotionEvent 7 | import android.view.View 8 | import com.mrr.libscaleview.attr.ScaleViewAttr 9 | import com.mrr.libscaleview.enum.ScaleAttrEnum 10 | import com.mrr.libscaleview.view.BaseScaleView 11 | import com.mrr.libscaleview.view.CircleScaleView 12 | import com.mrr.libscaleview.view.HorizontalScaleView 13 | import com.mrr.libscaleview.view.VerticalScaleView 14 | import java.util.function.Consumer 15 | import com.mrr.libscaleview.R 16 | 17 | class ScaleView : View { 18 | val TAG = "ScaleView" 19 | 20 | var mContext: Context? = null 21 | 22 | var mAttr = ScaleViewAttr(); 23 | 24 | lateinit var mScaleView: BaseScaleView 25 | 26 | var mProgressChangeListener: ProgressChangeListener? = null 27 | set(value) { 28 | 29 | if (this::mScaleView.isInitialized) { 30 | mScaleView?.mProgressChangeListener = value 31 | } 32 | 33 | } 34 | 35 | /** 36 | * 是否已经初始化画笔 37 | */ 38 | private var isInit = false 39 | 40 | var mWidth = 0f 41 | var mHeight = 0f 42 | 43 | var mTouchX = 0f; 44 | var mTouchY = 0f; 45 | 46 | 47 | constructor(context: Context?) : this(context, null) 48 | 49 | constructor(context: Context?, attrs: AttributeSet?) : this(context, attrs, 0) 50 | 51 | constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super( 52 | context, 53 | attrs, 54 | defStyleAttr 55 | ) { 56 | 57 | 58 | this.mContext = context 59 | var typeArray = context?.obtainStyledAttributes(attrs, R.styleable.scaleView) 60 | mAttr.initAttr(typeArray, mContext) 61 | 62 | when { 63 | (mAttr.mScaleStyle == ScaleAttrEnum.LINE && mAttr.mScaleDirect == ScaleAttrEnum.VERTICAL) -> { 64 | mScaleView = VerticalScaleView(mAttr) 65 | } 66 | (mAttr.mScaleStyle == ScaleAttrEnum.LINE && mAttr.mScaleDirect == ScaleAttrEnum.HORIZONTAL) -> { 67 | mScaleView = HorizontalScaleView(mAttr) 68 | } 69 | (mAttr.mScaleStyle == ScaleAttrEnum.CIRCLE) -> { 70 | mScaleView = CircleScaleView(mAttr) 71 | } 72 | } 73 | 74 | typeArray?.recycle() 75 | } 76 | 77 | 78 | override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { 79 | super.onMeasure(widthMeasureSpec, heightMeasureSpec) 80 | 81 | if (isInit) { 82 | return 83 | } 84 | 85 | mWidth = MeasureSpec.getSize(widthMeasureSpec).toFloat() 86 | mHeight = MeasureSpec.getSize(heightMeasureSpec).toFloat() 87 | 88 | mAttr.mWidth = mWidth 89 | mAttr.mHeight = mHeight 90 | 91 | setMeasuredDimension(mWidth.toInt(), mHeight.toInt()) 92 | 93 | mAttr.mPaddingLeft = mPaddingLeft 94 | mAttr.mPaddingRight = mPaddingRight 95 | mAttr.mPaddingTop = mPaddingTop 96 | mAttr.mPaddingBottom = mPaddingBottom 97 | 98 | 99 | 100 | mScaleView.onMeasure(widthMeasureSpec, heightMeasureSpec) 101 | mScaleView.initTouchXY( 102 | Consumer { t -> mTouchX = t }, 103 | Consumer { t -> mTouchY = t } 104 | ) 105 | isInit = true 106 | 107 | } 108 | 109 | 110 | override fun onDraw(canvas: Canvas?) { 111 | super.onDraw(canvas) 112 | mScaleView.onDraw(canvas, mTouchX, mTouchY) 113 | } 114 | 115 | 116 | override fun onTouchEvent(event: MotionEvent?): Boolean { 117 | 118 | when (event?.action) { 119 | MotionEvent.ACTION_DOWN, MotionEvent.ACTION_MOVE, MotionEvent.ACTION_UP -> { 120 | 121 | mTouchX = event.x 122 | mTouchY = event.y 123 | 124 | if (mTouchX < paddingLeft) { 125 | mTouchX = paddingLeft.toFloat() 126 | } 127 | 128 | if (mTouchX > mWidth - paddingRight) { 129 | mTouchX = mWidth - paddingRight 130 | } 131 | 132 | if (mTouchY < paddingTop) { 133 | mTouchY = paddingTop.toFloat() 134 | } 135 | 136 | if (mTouchY > mHeight - paddingBottom) { 137 | mTouchY = mHeight - paddingBottom 138 | } 139 | 140 | } 141 | } 142 | 143 | invalidate() 144 | 145 | return true 146 | } 147 | 148 | interface ProgressChangeListener { 149 | 150 | fun progressChange(progress: Float) 151 | } 152 | } -------------------------------------------------------------------------------- /ScaleView/libScaleView/src/main/java/com/mrr/libscaleview/attr/ScaleViewAttr.kt: -------------------------------------------------------------------------------- 1 | package com.mrr.libscaleview.attr 2 | 3 | import android.content.Context 4 | import android.content.res.TypedArray 5 | import android.graphics.Bitmap 6 | import android.graphics.BitmapFactory 7 | import android.graphics.Color 8 | import com.mrr.libscaleview.R 9 | import com.mrr.libscaleview.enum.ScaleAttrEnum 10 | 11 | class ScaleViewAttr { 12 | 13 | var context: Context? = null 14 | 15 | //基本属性 16 | var mWidth = 0f 17 | var mHeight = 0f 18 | var mPaddingLeft = 0 19 | var mPaddingRight = 0 20 | var mPaddingTop = 0 21 | var mPaddingBottom = 0 22 | 23 | /** 24 | * 普通刻度占组件减去padding之后的宽度/高度的比例 25 | */ 26 | var mScaleWidth = 0.5f 27 | 28 | /** 29 | * 刻度节点占组件减去padding之后的宽度/高度的比例 30 | */ 31 | var mScaleNodeWidth = 0.7f 32 | 33 | /** 34 | * 刻度线线条宽度 35 | */ 36 | var mScaleLineWidth = 5f 37 | 38 | 39 | /** 40 | * 刻度样式,默认为线性样式 41 | */ 42 | var mScaleStyle = ScaleAttrEnum.LINE 43 | 44 | /** 45 | * 线性刻度的方向 46 | * HORIZONTAL 47 | * VERTICAL 48 | */ 49 | var mScaleDirect = ScaleAttrEnum.HORIZONTAL 50 | 51 | /** 52 | * 游标位置 53 | * 54 | * LEFT : 线性刻度的左侧 55 | * RIGHT:线性刻度的右侧 56 | * INSIDE:圆形刻度的内侧 57 | * OUTSIDE:圆形刻度的外侧 58 | * 59 | */ 60 | var mCursorSeat = ScaleAttrEnum.NONE 61 | 62 | var mScaleTextSeat = ScaleAttrEnum.NONE 63 | 64 | /** 65 | * 游标的宽度 66 | * 67 | * 配置的时候需要注意游标和组件宽度之间的关系,留足够的空间 68 | */ 69 | var mCursorWidth = 20f 70 | 71 | /** 72 | * 游标和刻度之间的间隙 73 | */ 74 | var mCursorGap = 0f 75 | 76 | /** 77 | * 总刻度 78 | */ 79 | var mTotalProgress = 50 80 | 81 | /** 82 | * 单位刻度,主要是用来控制节点刻度 83 | */ 84 | var mUnitScale = 1 85 | 86 | /** 87 | * 刻度默认颜色 88 | */ 89 | var mDefaultColor = Color.parseColor("#999999"); 90 | 91 | /** 92 | * 已走过刻度颜色 93 | */ 94 | var mProgressColor = Color.parseColor("#999999"); 95 | 96 | 97 | var mProgressListener: ProgressListener? = null 98 | 99 | var mScaleMarkSize = 0f 100 | 101 | var mCursorBitmap: Bitmap? = null 102 | 103 | var mScaleTextColor = Color.parseColor("#999999"); 104 | 105 | var mScaleTextSize = 0f 106 | 107 | var mScaleTextGap = 0f 108 | 109 | 110 | fun initAttr(typeArray: TypedArray?, context: Context) { 111 | 112 | mScaleWidth = 113 | typeArray!!.getFloat(R.styleable.scaleView_scaleWidth, 0.5f) 114 | 115 | 116 | mScaleNodeWidth = 117 | typeArray!!.getFloat(R.styleable.scaleView_scaleNodeWidth, 0.7f) 118 | 119 | mScaleLineWidth = 120 | typeArray!!.getDimension(R.styleable.scaleView_scaleLineWidth, 5f) 121 | 122 | var cursorDrawableID = typeArray!!.getResourceId(R.styleable.scaleView_cursorDrawable, 0) 123 | 124 | if (cursorDrawableID > 0) { 125 | mCursorBitmap = BitmapFactory.decodeResource(context.resources, cursorDrawableID) 126 | } 127 | 128 | var style = typeArray!!.getInt(R.styleable.scaleView_scaleStyle, -1) 129 | mScaleStyle = 130 | ScaleAttrEnum.get(style) 131 | 132 | var direct = 133 | typeArray!!.getInt(R.styleable.scaleView_scaleDirect, -1) 134 | mScaleDirect = ScaleAttrEnum.get(direct) 135 | 136 | 137 | var cursorSeat = 138 | typeArray!!.getInt(R.styleable.scaleView_cursorSeat, -1) 139 | mCursorSeat = ScaleAttrEnum.get(cursorSeat) 140 | 141 | var scaleTextSeat = 142 | typeArray!!.getInt(R.styleable.scaleView_scaleTextSeat, -1) 143 | mScaleTextSeat = ScaleAttrEnum.get(scaleTextSeat) 144 | 145 | mCursorWidth = 146 | typeArray!!.getDimension(R.styleable.scaleView_cursorWidth, 20f) 147 | 148 | mCursorGap = 149 | typeArray!!.getDimension(R.styleable.scaleView_cursorGap, 5f) 150 | 151 | mTotalProgress = 152 | typeArray!!.getInt(R.styleable.scaleView_totalProgress, 60) 153 | 154 | mUnitScale = 155 | typeArray!!.getInt(R.styleable.scaleView_unitScale, 10) 156 | 157 | mDefaultColor = 158 | typeArray!!.getColor(R.styleable.scaleView_defaultColor, Color.DKGRAY) 159 | 160 | mProgressColor = 161 | typeArray!!.getColor(R.styleable.scaleView_progressColor, Color.DKGRAY) 162 | 163 | mScaleTextColor = 164 | typeArray!!.getColor(R.styleable.scaleView_scaleTextColor, Color.DKGRAY) 165 | 166 | mScaleTextSize = typeArray!!.getDimension(R.styleable.scaleView_scaleTextSize, 5f) 167 | 168 | mScaleTextGap = typeArray!!.getDimension(R.styleable.scaleView_scaleTextGap, 0f) 169 | } 170 | 171 | fun apply(viewAttr: ScaleViewAttr) { 172 | viewAttr.context = this.context 173 | viewAttr.mScaleWidth = this.mScaleWidth 174 | viewAttr.mScaleLineWidth = this.mScaleLineWidth 175 | viewAttr.mScaleNodeWidth = this.mScaleNodeWidth 176 | viewAttr.mScaleStyle = this.mScaleStyle 177 | viewAttr.mScaleDirect = this.mScaleDirect 178 | viewAttr.mCursorSeat = this.mCursorSeat 179 | viewAttr.mCursorWidth = this.mCursorWidth 180 | viewAttr.mCursorGap = this.mCursorGap 181 | viewAttr.mTotalProgress = this.mTotalProgress 182 | viewAttr.mUnitScale = this.mUnitScale 183 | viewAttr.mDefaultColor = this.mDefaultColor 184 | viewAttr.mProgressColor = this.mProgressColor 185 | viewAttr.mScaleMarkSize = this.mScaleMarkSize 186 | viewAttr.mCursorBitmap = this.mCursorBitmap 187 | viewAttr.mScaleTextColor = this.mScaleTextColor 188 | viewAttr.mScaleTextSize = this.mScaleTextSize 189 | viewAttr.mScaleTextGap = this.mScaleTextGap 190 | 191 | 192 | 193 | 194 | viewAttr.mProgressListener = this.mProgressListener 195 | } 196 | 197 | 198 | interface ProgressListener { 199 | fun progressChanged(progress: Float) 200 | } 201 | } -------------------------------------------------------------------------------- /ScaleView/libScaleView/src/main/java/com/mrr/libscaleview/builder/ScaleBuilder.kt: -------------------------------------------------------------------------------- 1 | package com.mrr.libscaleview.builder 2 | 3 | import android.content.Context 4 | import com.mrr.libscaleview.ScaleView 5 | import com.mrr.libscaleview.attr.ScaleViewAttr 6 | import com.mrr.libscaleview.enum.ScaleAttrEnum 7 | import kotlin.jvm.internal.Intrinsics 8 | 9 | class ScaleBuilder { 10 | 11 | var p: ScaleViewAttr; 12 | 13 | constructor(context: Context) { 14 | p = ScaleViewAttr() 15 | p.context = context 16 | } 17 | 18 | 19 | fun setCalibrationWidth(var1: Float): ScaleBuilder { 20 | p.mScaleWidth = var1 21 | return this 22 | } 23 | 24 | 25 | fun setCalibrationNodeWidth(var1: Float): ScaleBuilder { 26 | p.mScaleNodeWidth = var1 27 | return this 28 | } 29 | 30 | 31 | fun setCalibrationStyle(var1: ScaleAttrEnum): ScaleBuilder { 32 | Intrinsics.checkNotNullParameter(var1, "") 33 | p.mScaleStyle = var1 34 | return this 35 | } 36 | 37 | 38 | fun setCalibrationDirect(var1: ScaleAttrEnum): ScaleBuilder { 39 | Intrinsics.checkNotNullParameter(var1, "") 40 | p.mScaleDirect = var1 41 | return this 42 | } 43 | 44 | 45 | fun setCursorLoc(var1: ScaleAttrEnum): ScaleBuilder { 46 | Intrinsics.checkNotNullParameter(var1, "") 47 | p.mCursorSeat = var1 48 | return this 49 | } 50 | 51 | 52 | fun setCursorWidth(var1: Float): ScaleBuilder { 53 | p.mCursorWidth = var1 54 | return this 55 | } 56 | 57 | 58 | fun setCursorGap(var1: Float): ScaleBuilder { 59 | p.mCursorGap = var1 60 | return this 61 | } 62 | 63 | 64 | fun setTotalCalibration(var1: Int): ScaleBuilder { 65 | p.mTotalProgress = var1 66 | return this 67 | } 68 | 69 | 70 | fun setUnitCalibration(var1: Int): ScaleBuilder { 71 | p.mUnitScale = var1 72 | return this 73 | } 74 | 75 | 76 | fun setDefaultColor(var1: Int): ScaleBuilder { 77 | p.mDefaultColor = var1 78 | return this 79 | } 80 | 81 | 82 | fun setProgressColor(var1: Int): ScaleBuilder { 83 | p.mProgressColor = var1 84 | return this 85 | } 86 | 87 | fun setProgressListener(var1: ScaleViewAttr.ProgressListener): ScaleBuilder { 88 | p.mProgressListener = var1 89 | return this 90 | } 91 | 92 | 93 | fun setScaleTextColor(var1: Int): ScaleBuilder { 94 | p.mScaleTextColor = var1 95 | return this 96 | } 97 | 98 | fun setScaleTextSize(var1: Float): ScaleBuilder { 99 | p.mScaleTextSize = var1 100 | return this 101 | } 102 | 103 | fun setScaleTextGap(var1: Float): ScaleBuilder { 104 | p.mScaleTextGap = var1 105 | return this 106 | } 107 | 108 | fun create(): ScaleView { 109 | val view = ScaleView(p.context); 110 | p.apply(view.mAttr) 111 | return view; 112 | } 113 | 114 | 115 | } -------------------------------------------------------------------------------- /ScaleView/libScaleView/src/main/java/com/mrr/libscaleview/enum/ScaleAttrEnum.kt: -------------------------------------------------------------------------------- 1 | package com.mrr.libscaleview.enum 2 | 3 | /** 4 | * 刻度样式的配置 5 | */ 6 | enum class ScaleAttrEnum(val value: Int) { 7 | 8 | NONE(-1), 9 | 10 | /** 11 | * 线性刻度使用,是横向绘制还是竖向绘制 12 | */ 13 | HORIZONTAL(0), 14 | VERTICAL(1), 15 | 16 | /** 17 | * 线性刻度 18 | */ 19 | LINE(2), 20 | 21 | /** 22 | * 圆形刻度,类似手表 23 | */ 24 | CIRCLE(3), 25 | 26 | /** 27 | * 游标位置 28 | * 29 | * LEFT : 线性刻度的左侧 30 | * RIGHT:线性刻度的右侧 31 | * INSIDE:圆形刻度的内侧 32 | * OUTSIDE:圆形刻度的外侧 33 | * 34 | */ 35 | LEFT(4), 36 | RIGHT(5), 37 | TOP(6), 38 | BOTTOM(7), 39 | INSIDE(8), 40 | OUTSIDE(9), 41 | 42 | /** 43 | * 线性刻度方向 44 | */ 45 | LEFT_TO_RIGHT(11), 46 | RIGHT_TO_LEFT(12), 47 | TOP_TO_BOTTOM(13), 48 | BOTTOM_TO_TOP(14), 49 | 50 | /** 51 | * 圆形刻度方向 52 | */ 53 | CLOCK_WISE(15), 54 | COUNTER_CLOCKWISE(16); 55 | 56 | 57 | companion object {// 包裹范围内 属于静态方法 58 | 59 | fun get(value: Int): ScaleAttrEnum { 60 | when (value) { 61 | NONE.value -> return NONE 62 | HORIZONTAL.value -> return HORIZONTAL 63 | VERTICAL.value -> return VERTICAL 64 | LINE.value -> return LINE 65 | CIRCLE.value -> return CIRCLE 66 | LEFT.value -> return LEFT 67 | RIGHT.value -> return RIGHT 68 | TOP.value -> return TOP 69 | BOTTOM.value -> return BOTTOM 70 | INSIDE.value -> return INSIDE 71 | OUTSIDE.value -> return OUTSIDE 72 | LEFT_TO_RIGHT.value -> return LEFT_TO_RIGHT 73 | RIGHT_TO_LEFT.value -> return RIGHT_TO_LEFT 74 | TOP_TO_BOTTOM.value -> return TOP_TO_BOTTOM 75 | BOTTOM_TO_TOP.value -> return BOTTOM_TO_TOP 76 | CLOCK_WISE.value -> return CLOCK_WISE 77 | COUNTER_CLOCKWISE.value -> return COUNTER_CLOCKWISE 78 | } 79 | return NONE 80 | } 81 | } 82 | 83 | 84 | } -------------------------------------------------------------------------------- /ScaleView/libScaleView/src/main/java/com/mrr/libscaleview/rectf/CursorRectF.kt: -------------------------------------------------------------------------------- 1 | package com.mrr.libscaleview.rectf 2 | 3 | import android.graphics.Matrix 4 | import com.mrr.libscaleview.attr.ScaleViewAttr 5 | import com.mrr.libscaleview.enum.ScaleAttrEnum 6 | import com.mrr.libscaleview.util.UnitConversion.Companion.px 7 | 8 | /** 9 | * 游标方位属性 10 | */ 11 | class CursorRectF(var mAngelChangeListener: AngelChangeListener?) { 12 | 13 | private val TAG = "CursorRectF" 14 | 15 | /** 16 | * 游标变换的各个维度 17 | */ 18 | var mScaleX = 0f; 19 | var mScaleY = 0f; 20 | var mTransX = 0f; 21 | var mTransY = 0f; 22 | var mRoutateCenterX = 0f; 23 | var mRoutateCenterY = 0f; 24 | var mRoutateDegress = 0f; 25 | 26 | 27 | private var tx = 0f; 28 | private var ty = 0f; 29 | private var t_length = 0.0; 30 | private var angle = 0.0//弧度 31 | private var degress = 0.0//角度 32 | private var diff = 0f; 33 | private var cursorCircleRadius = 0f 34 | private val mCursorMatrix = Matrix() 35 | 36 | /** 37 | * 计算圆形游标的各个属性 38 | */ 39 | fun calculateAttributes( 40 | touchX: Float, 41 | touchY: Float, 42 | centerX: Float, 43 | centerY: Float, 44 | circleRadius: Float, 45 | p: ScaleViewAttr, 46 | ) { 47 | 48 | tx = Math.abs(touchX - centerX) 49 | ty = Math.abs(touchY - centerY) 50 | t_length = Math.sqrt((tx * tx + ty * ty).toDouble()) 51 | 52 | angle = 0.0//弧度 53 | degress = 0.0//角度 54 | 55 | diff = 56 | ((circleRadius * p.mScaleNodeWidth) - (circleRadius * p.mScaleWidth)) / 2 57 | 58 | cursorCircleRadius = 0f 59 | 60 | 61 | if (p.mCursorSeat == ScaleAttrEnum.INSIDE) { 62 | 63 | cursorCircleRadius = 64 | circleRadius - circleRadius * p.mScaleWidth - diff - p.mCursorWidth.px / 2//游标绘制时候的半径 65 | 66 | } else if (p.mCursorSeat == ScaleAttrEnum.OUTSIDE) { 67 | 68 | cursorCircleRadius = 69 | circleRadius - diff + p.mCursorWidth.px / 2//游标绘制时候的半径 70 | } 71 | 72 | 73 | //处理各个象限以及数轴 74 | when { 75 | (touchX > centerX && touchY < centerY) -> //第一象限 76 | angle = Math.PI * 2 - Math.acos(tx / t_length) 77 | 78 | (touchX < centerX && touchY < centerY) -> //第二象限 79 | angle = Math.PI + Math.acos(tx / t_length) 80 | 81 | (touchX < centerX && touchY > centerY) -> //第三象限 82 | angle = Math.PI - Math.acos(tx / t_length) 83 | 84 | (touchX > centerX && touchY > centerY) -> //第四象限 85 | angle = Math.acos(tx / t_length) 86 | 87 | (touchX > centerX && touchY == centerY) -> //X轴正方向 88 | angle = 0.0 89 | 90 | (touchX == centerX && touchY > centerY) -> //Y轴正方向 91 | angle = Math.PI / 2 92 | 93 | (touchX < centerX && touchY == centerY) -> //X轴反方向 94 | angle = Math.PI 95 | 96 | (touchX == centerX && touchY < centerY) -> //Y轴反方向 97 | angle = Math.PI * 2 - Math.PI / 2 98 | 99 | } 100 | 101 | mRoutateCenterX = 102 | (centerX + cursorCircleRadius 103 | * Math.cos(angle)).toFloat() 104 | 105 | mRoutateCenterY = 106 | (centerY + cursorCircleRadius 107 | * Math.sin(angle)).toFloat() 108 | 109 | mTransX = mRoutateCenterX - p.mCursorWidth.px / 2 110 | mTransY = mRoutateCenterY - p.mCursorWidth.px / 2 111 | 112 | 113 | if (p.mCursorSeat == ScaleAttrEnum.INSIDE) { 114 | 115 | mRoutateDegress = Math.toDegrees(angle - Math.PI / 2).toFloat() 116 | 117 | } else if (p.mCursorSeat == ScaleAttrEnum.OUTSIDE) { 118 | 119 | mRoutateDegress = Math.toDegrees(angle + Math.PI / 2).toFloat() 120 | } 121 | 122 | 123 | mAngelChangeListener?.angelChange(angle) 124 | } 125 | 126 | interface AngelChangeListener { 127 | 128 | fun angelChange(curAngel: Double) 129 | } 130 | 131 | } -------------------------------------------------------------------------------- /ScaleView/libScaleView/src/main/java/com/mrr/libscaleview/rectf/ScaleTextRectF.kt: -------------------------------------------------------------------------------- 1 | package com.mrr.libscaleview.rectf 2 | 3 | import com.mrr.libscaleview.enum.ScaleAttrEnum 4 | import com.mrr.libscaleview.util.UnitConversion.Companion.px 5 | import com.mrr.libscaleview.view.BaseScaleView 6 | 7 | /** 8 | * 绘制刻度数字 9 | */ 10 | class ScaleTextRectF { 11 | 12 | private val TAG = "ScaleTextRectF" 13 | 14 | var x = 0f 15 | var baseLine = 0f 16 | 17 | private var letterCenterY = 0f 18 | private var dy = 0f 19 | private var textWidth = 0f 20 | private var textHeight = 0f 21 | 22 | private var lengthDiff = 0f 23 | private var textCenterX = 0f 24 | private var textCenterY = 0f 25 | private var textCircleRadius = 0f 26 | 27 | var init = false 28 | 29 | fun initLineTextSeat(letter: String, attr: BaseScaleView) { 30 | init = false 31 | 32 | 33 | dy = 34 | (attr.fontMetrics!!.bottom - attr.fontMetrics!!.top) / 2 - attr.fontMetrics!!.bottom 35 | textWidth = attr.textPaint.measureText(letter) 36 | textHeight = -attr.fontMetrics!!.ascent + attr.fontMetrics!!.descent 37 | 38 | if (attr.mAttr.mScaleTextSeat == ScaleAttrEnum.LEFT) { 39 | letterCenterY = attr.startY 40 | x = attr.nodeStartX - textWidth - attr.mAttr.mScaleTextGap.px 41 | init = true 42 | } else if (attr.mAttr.mScaleTextSeat == ScaleAttrEnum.RIGHT) { 43 | letterCenterY = attr.startY 44 | x = attr.nodeStopX + attr.mAttr.mScaleTextGap.px 45 | init = true 46 | } else if (attr.mAttr.mScaleTextSeat == ScaleAttrEnum.TOP) { 47 | letterCenterY = 48 | attr.nodeStartY - textHeight / 2 - attr.mAttr.mScaleTextGap.px 49 | x = attr.nodeStartX - textWidth / 2 50 | init = true 51 | } else if (attr.mAttr.mScaleTextSeat == ScaleAttrEnum.BOTTOM) { 52 | letterCenterY = 53 | attr.nodeStopY + textHeight / 2 + attr.mAttr.mScaleTextGap.px 54 | 55 | x = attr.nodeStopX - textWidth / 2 56 | init = true 57 | } else { 58 | init = false 59 | } 60 | 61 | baseLine = letterCenterY + dy 62 | 63 | } 64 | 65 | fun initCircleTextSeat(letter: String, angle: Double, attr: BaseScaleView) { 66 | init = false 67 | 68 | dy = 69 | (attr.fontMetrics!!.bottom - attr.fontMetrics!!.top) / 2 - attr.fontMetrics!!.bottom 70 | textWidth = attr.textPaint.measureText(letter) 71 | textHeight = -attr.fontMetrics!!.ascent + attr.fontMetrics!!.descent 72 | 73 | 74 | if (attr.mAttr.mScaleTextSeat == ScaleAttrEnum.INSIDE) { 75 | 76 | textCircleRadius = 77 | attr.circleRadius - attr.circleRadius * attr.mAttr.mScaleNodeWidth - Math.min( 78 | textWidth, 79 | textHeight 80 | ) / 2 - attr.mAttr.mScaleTextGap.px 81 | init = true 82 | 83 | } else if (attr.mAttr.mScaleTextSeat == ScaleAttrEnum.OUTSIDE) { 84 | 85 | textCircleRadius = attr.circleRadius + Math.min( 86 | textWidth, 87 | textHeight 88 | ) / 2 + attr.mAttr.mScaleTextGap.px 89 | init = true 90 | } 91 | 92 | 93 | textCenterX = 94 | (attr.centerX + textCircleRadius 95 | * Math.cos(angle)).toFloat() 96 | 97 | textCenterY = 98 | (attr.centerY + textCircleRadius 99 | * Math.sin(angle)).toFloat() 100 | 101 | x = textCenterX - textWidth / 2 102 | 103 | baseLine = textCenterY + dy 104 | } 105 | } -------------------------------------------------------------------------------- /ScaleView/libScaleView/src/main/java/com/mrr/libscaleview/util/UnitConversion.kt: -------------------------------------------------------------------------------- 1 | package com.mrr.libscaleview.util 2 | 3 | import android.content.res.Resources 4 | 5 | /** 6 | * 单位转换 7 | */ 8 | class UnitConversion { 9 | 10 | companion object { 11 | 12 | val Float.dp: Float 13 | get() = (this / Resources.getSystem().displayMetrics.density) 14 | val Float.px: Float 15 | get() = (this * Resources.getSystem().displayMetrics.density) 16 | 17 | val Float.sp2px: Float 18 | get() = (this * Resources.getSystem().getDisplayMetrics().scaledDensity) 19 | } 20 | 21 | } -------------------------------------------------------------------------------- /ScaleView/libScaleView/src/main/java/com/mrr/libscaleview/view/BaseScaleView.kt: -------------------------------------------------------------------------------- 1 | package com.mrr.libscaleview.view 2 | 3 | import android.graphics.Canvas 4 | import android.graphics.Matrix 5 | import android.graphics.Paint 6 | import android.graphics.RectF 7 | import com.mrr.libscaleview.ScaleView 8 | import com.mrr.libscaleview.attr.ScaleViewAttr 9 | import com.mrr.libscaleview.rectf.CursorRectF 10 | import com.mrr.libscaleview.util.UnitConversion.Companion.px 11 | import com.mrr.libscaleview.util.UnitConversion.Companion.sp2px 12 | import java.util.function.Consumer 13 | 14 | abstract class BaseScaleView : CursorRectF.AngelChangeListener, ScaleView.ProgressChangeListener { 15 | 16 | var mAttr: ScaleViewAttr 17 | 18 | var mProgressChangeListener: ScaleView.ProgressChangeListener? = null 19 | 20 | 21 | /** 22 | * 刻度线一半的宽度 23 | */ 24 | var halfCalibration = 0f; 25 | 26 | /** 27 | * 圆形刻度之间的角度 28 | */ 29 | var preDegrees = 0f 30 | 31 | /** 32 | * 圆形刻度的半径 33 | */ 34 | var circleRadius = 0f 35 | 36 | /** 37 | * 每一个刻度最长可绘制的空间 38 | */ 39 | var interval = 0f 40 | 41 | var drawSpace = 0f 42 | 43 | /** 44 | * 刻度之间的间距 45 | */ 46 | var perInterval = 0f 47 | 48 | //第一个节点是一个刻度节点/节点刻度的宽度/高度 49 | var nodeLength = 0f 50 | 51 | //普通刻度占组件减去padding之后的宽度/高度 52 | var linelength = 0f 53 | 54 | var circleProgressAngel = 0.0 55 | 56 | var clipProgress = 0f 57 | 58 | var nodeStartX = 0f 59 | var nodeStopX = 0f 60 | 61 | var nodeStartY = 0f 62 | var nodeStopY = 0f 63 | 64 | var startX = 0f 65 | var stopX = 0f 66 | 67 | var startY = 0f 68 | var stopY = 0f 69 | 70 | // 屏幕最中心的位置 71 | var centerX = 0f 72 | var centerY = 0f 73 | 74 | 75 | /** 76 | * 线性刻度切割canvas使用 77 | */ 78 | var clipRect: RectF 79 | 80 | var cursorRectF: CursorRectF 81 | 82 | var cursorMatrix: Matrix 83 | 84 | /** 85 | *画笔 86 | */ 87 | var originColorPaint: Paint 88 | var changeColorPaint: Paint 89 | var cursorPaint: Paint 90 | var textPaint: Paint 91 | 92 | var fontMetrics: Paint.FontMetrics? = null 93 | 94 | constructor(mAttr: ScaleViewAttr) { 95 | this.mAttr = mAttr 96 | 97 | clipRect = RectF() 98 | cursorRectF = CursorRectF(this) 99 | cursorMatrix = Matrix() 100 | 101 | halfCalibration = mAttr.mScaleLineWidth / 2 102 | 103 | if (null != mAttr.mCursorBitmap) { 104 | cursorRectF?.mScaleX = mAttr.mCursorWidth.px / mAttr.mCursorBitmap!!.width 105 | cursorRectF?.mScaleY = mAttr.mCursorWidth.px / mAttr.mCursorBitmap!!.height 106 | } 107 | 108 | originColorPaint = Paint() 109 | changeColorPaint = Paint() 110 | cursorPaint = Paint() 111 | textPaint = Paint() 112 | initPaint() 113 | fontMetrics = textPaint.fontMetrics 114 | } 115 | 116 | 117 | abstract fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) 118 | abstract fun onDraw(canvas: Canvas?, touchX: Float, touchY: Float) 119 | abstract fun initTouchXY( 120 | touchXCon: Consumer, 121 | touchYCon: Consumer 122 | );//初始化触摸位置,也就是游标初始位置 123 | 124 | 125 | private fun initPaint() { 126 | originColorPaint.isAntiAlias = true 127 | originColorPaint.style = Paint.Style.STROKE 128 | originColorPaint.color = mAttr.mDefaultColor 129 | originColorPaint.strokeWidth = mAttr.mScaleLineWidth 130 | 131 | changeColorPaint.isAntiAlias = true 132 | changeColorPaint.style = Paint.Style.STROKE 133 | changeColorPaint.color = mAttr.mProgressColor 134 | changeColorPaint.strokeWidth = mAttr.mScaleLineWidth 135 | 136 | 137 | cursorPaint.isAntiAlias = true 138 | cursorPaint.style = Paint.Style.STROKE 139 | cursorPaint.strokeWidth = 1f 140 | 141 | textPaint.isAntiAlias = true 142 | textPaint.style = Paint.Style.FILL 143 | textPaint.color = mAttr.mScaleTextColor 144 | textPaint.textSize = mAttr.mScaleTextSize.sp2px 145 | } 146 | 147 | override fun angelChange(curAngel: Double) { 148 | TODO("Not yet implemented") 149 | } 150 | 151 | override fun progressChange(progress: Float) { 152 | mProgressChangeListener?.progressChange(progress) 153 | } 154 | } -------------------------------------------------------------------------------- /ScaleView/libScaleView/src/main/java/com/mrr/libscaleview/view/CircleScaleView.kt: -------------------------------------------------------------------------------- 1 | package com.mrr.libscaleview.view 2 | 3 | import android.graphics.Canvas 4 | import android.graphics.Paint 5 | import android.util.Log 6 | import com.mrr.libscaleview.attr.ScaleViewAttr 7 | import com.mrr.libscaleview.rectf.ScaleTextRectF 8 | import java.util.function.Consumer 9 | 10 | class CircleScaleView : BaseScaleView { 11 | 12 | private val TAG = "CircleScaleView" 13 | 14 | private var letter = "" 15 | private var lengthDiff = 0f 16 | var angle = 0.0 17 | 18 | var scaleTextRectF: ScaleTextRectF? = null 19 | 20 | constructor(attr: ScaleViewAttr) : super(attr) { 21 | scaleTextRectF = ScaleTextRectF() 22 | 23 | } 24 | 25 | 26 | override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { 27 | preDegrees = (Math.PI * 2 / mAttr.mTotalProgress).toFloat() 28 | circleRadius = 29 | Math.min( 30 | mAttr.mWidth - mAttr.mPaddingLeft - mAttr.mPaddingRight, 31 | mAttr.mHeight - mAttr.mPaddingTop - mAttr.mPaddingBottom 32 | ) / 2 33 | centerX = mAttr.mWidth / 2 34 | centerY = mAttr.mHeight / 2 35 | } 36 | 37 | override fun onDraw(canvas: Canvas?, touchX: Float, touchY: Float) { 38 | 39 | drawCircleScale(canvas, originColorPaint, Math.PI * 2) 40 | drawCursor(canvas, touchX, touchY) 41 | drawCircleScale( 42 | canvas, 43 | changeColorPaint, 44 | circleProgressAngel 45 | ) 46 | progressChange((mAttr.mTotalProgress * circleProgressAngel / (Math.PI * 2)).toFloat()) 47 | 48 | } 49 | 50 | 51 | override fun initTouchXY(touchXCon: Consumer, touchYCon: Consumer) { 52 | touchXCon.accept(centerX + circleRadius) 53 | touchYCon.accept(centerY) 54 | } 55 | 56 | 57 | private fun drawCircleScale(canvas: Canvas?, paint: Paint, maxDegress: Double) { 58 | 59 | if (maxDegress == 0.0) { 60 | return 61 | } 62 | 63 | // canvas?.drawCircle(mAttr.mWidth / 2, mAttr.mHeight / 2, circleRadius, cursorPaint) 64 | 65 | //节点刻度和普通刻度的长度差 66 | lengthDiff = 67 | ((circleRadius * mAttr.mScaleNodeWidth) - (circleRadius * mAttr.mScaleWidth)) / 2 68 | 69 | 70 | for (index in 0..mAttr.mTotalProgress - 1) { 71 | // 初始角度 + 当前旋转的角度 72 | angle = (index * preDegrees).toDouble() 73 | letter = index.toString() 74 | 75 | if (angle > maxDegress) { 76 | return 77 | } 78 | 79 | //从外往内绘制 80 | if (index % mAttr.mUnitScale == 0) { 81 | 82 | startX = (centerX + circleRadius * Math.cos(angle)).toFloat() 83 | startY = (centerY + circleRadius * Math.sin(angle)).toFloat() 84 | stopX = (centerX + (circleRadius - circleRadius * mAttr.mScaleNodeWidth) 85 | * Math.cos(angle)).toFloat() 86 | stopY = (centerY + (circleRadius - circleRadius * mAttr.mScaleNodeWidth) 87 | * Math.sin(angle)).toFloat() 88 | 89 | scaleTextRectF?.initCircleTextSeat(letter, angle, this) 90 | if (scaleTextRectF!!.init) { 91 | canvas?.drawText( 92 | letter, 93 | scaleTextRectF!!.x, 94 | scaleTextRectF!!.baseLine, 95 | textPaint 96 | ) 97 | } 98 | 99 | } else { 100 | startX = (centerX + (circleRadius - lengthDiff) 101 | * Math.cos(angle)).toFloat() 102 | startY = (centerY + (circleRadius - lengthDiff) * Math.sin(angle)).toFloat() 103 | stopX = 104 | (centerX + (circleRadius - circleRadius * mAttr.mScaleWidth - lengthDiff) 105 | * Math.cos(angle)).toFloat() 106 | stopY = 107 | (centerY + (circleRadius - circleRadius * mAttr.mScaleWidth - lengthDiff) 108 | * Math.sin(angle)).toFloat() 109 | } 110 | 111 | 112 | 113 | canvas!!.drawLine( 114 | startX, startY, stopX, stopY, 115 | paint 116 | ) 117 | 118 | } 119 | } 120 | 121 | /** 122 | * 绘制游标 123 | * 124 | */ 125 | private fun drawCursor(canvas: Canvas?, touchX: Float, touchY: Float) { 126 | 127 | if (null == mAttr.mCursorBitmap) { 128 | return 129 | } 130 | 131 | cursorRectF.calculateAttributes( 132 | touchX, 133 | touchY, 134 | centerX, 135 | centerY, 136 | circleRadius, 137 | mAttr 138 | ) 139 | 140 | cursorMatrix.reset() 141 | // 创建操作图片用的 Matrix 对象 142 | cursorMatrix.postScale( 143 | cursorRectF.mScaleX, cursorRectF.mScaleY 144 | ); 145 | cursorMatrix.postTranslate( 146 | cursorRectF.mTransX, 147 | cursorRectF.mTransY 148 | ); 149 | 150 | cursorMatrix.postRotate( 151 | cursorRectF.mRoutateDegress, 152 | cursorRectF.mRoutateCenterX, 153 | cursorRectF.mRoutateCenterY 154 | ) 155 | 156 | canvas?.drawBitmap(mAttr.mCursorBitmap, cursorMatrix, null) 157 | 158 | } 159 | 160 | override fun angelChange(curAngel: Double) { 161 | circleProgressAngel = curAngel 162 | } 163 | 164 | 165 | } -------------------------------------------------------------------------------- /ScaleView/libScaleView/src/main/java/com/mrr/libscaleview/view/HorizontalScaleView.kt: -------------------------------------------------------------------------------- 1 | package com.mrr.libscaleview.view 2 | 3 | import android.graphics.Canvas 4 | import android.graphics.Paint 5 | import android.graphics.RectF 6 | import com.mrr.libscaleview.attr.ScaleViewAttr 7 | import com.mrr.libscaleview.enum.ScaleAttrEnum 8 | import com.mrr.libscaleview.rectf.ScaleTextRectF 9 | import com.mrr.libscaleview.util.UnitConversion.Companion.px 10 | import java.util.function.Consumer 11 | 12 | class HorizontalScaleView : BaseScaleView { 13 | 14 | 15 | var letter: String = "" 16 | var scaleTextRectF: ScaleTextRectF? = null 17 | 18 | constructor(attr: ScaleViewAttr) : super(attr) { 19 | scaleTextRectF = ScaleTextRectF() 20 | } 21 | 22 | 23 | override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { 24 | 25 | //刻度线本身占用的空间 26 | var calibrationSpace = mAttr.mScaleLineWidth * (mAttr.mTotalProgress + 1) 27 | 28 | drawSpace = mAttr.mWidth - mAttr.mPaddingLeft - mAttr.mPaddingRight 29 | //刻度之间的缝隙大小 30 | perInterval = (drawSpace - calibrationSpace) / mAttr.mTotalProgress 31 | //每个一个刻度最长可绘制的空间 32 | interval = mAttr.mHeight - mAttr.mPaddingTop - mAttr.mPaddingBottom 33 | nodeLength = interval * mAttr.mScaleNodeWidth 34 | linelength = interval * mAttr.mScaleWidth 35 | 36 | clipRect = RectF() 37 | } 38 | 39 | override fun onDraw(canvas: Canvas?, touchX: Float, touchY: Float) { 40 | 41 | clipProgress = drawSpace * (touchX - mAttr.mPaddingLeft) / drawSpace 42 | 43 | clipRect?.set(0f, 0f, touchX, mAttr.mHeight) 44 | drawLineScale(canvas, changeColorPaint, clipRect) 45 | progressChange(mAttr.mTotalProgress * (touchX - mAttr.mPaddingLeft) / drawSpace) 46 | 47 | clipRect?.set(touchX, 0f, mAttr.mWidth, mAttr.mHeight) 48 | 49 | drawLineScale(canvas, originColorPaint, clipRect) 50 | 51 | drawCursor(canvas, touchX, touchY) 52 | } 53 | 54 | 55 | override fun initTouchXY(touchXCon: Consumer, touchYCon: Consumer) { 56 | touchXCon.accept(mAttr.mPaddingLeft.toFloat()) 57 | } 58 | 59 | 60 | /** 61 | * 画线性的刻度 62 | */ 63 | private fun drawLineScale(canvas: Canvas?, paint: Paint, clipRectF: RectF) { 64 | 65 | 66 | canvas!!.save() 67 | canvas.clipRect(clipRectF) 68 | 69 | 70 | nodeStartX = mAttr.mPaddingLeft + halfCalibration 71 | nodeStopX = nodeStartX 72 | 73 | nodeStartY = mAttr.mPaddingTop + (interval - nodeLength) / 2 74 | nodeStopY = nodeStartY + nodeLength 75 | 76 | startY = mAttr.mPaddingTop + (interval - linelength) / 2 77 | stopY = startY + linelength 78 | 79 | for (index in 0..mAttr.mTotalProgress) { 80 | 81 | canvas?.drawLine( 82 | nodeStartX, 83 | if (index % mAttr.mUnitScale == 0) nodeStartY.toFloat() else startY, 84 | nodeStopX, 85 | if (index % mAttr.mUnitScale == 0) nodeStopY.toFloat() else stopY, 86 | paint 87 | ) 88 | 89 | if ((index % mAttr.mUnitScale == 0)) { 90 | 91 | letter = index.toString() 92 | scaleTextRectF?.initLineTextSeat(letter, this) 93 | 94 | if (scaleTextRectF?.init == true) { 95 | 96 | canvas.drawText( 97 | letter, 98 | scaleTextRectF!!.x, 99 | scaleTextRectF!!.baseLine, 100 | textPaint 101 | ) 102 | } 103 | } 104 | 105 | nodeStartX += (perInterval + mAttr.mScaleLineWidth) 106 | nodeStopX += (perInterval + mAttr.mScaleLineWidth) 107 | } 108 | 109 | 110 | 111 | canvas.restore() 112 | 113 | } 114 | 115 | 116 | /** 117 | * 绘制游标 118 | * 119 | */ 120 | private fun drawCursor(canvas: Canvas?, touchX: Float, touchY: Float) { 121 | 122 | if (null == mAttr.mCursorBitmap) { 123 | return 124 | } 125 | 126 | when (mAttr.mCursorSeat) { 127 | ScaleAttrEnum.TOP -> { 128 | if (mAttr.mScaleStyle != ScaleAttrEnum.LINE) { 129 | return 130 | } 131 | 132 | cursorRectF.mTransX = touchX - mAttr.mCursorWidth.px / 2 133 | 134 | cursorRectF.mTransY = 135 | mAttr.mPaddingTop + (interval - linelength) / 2 - mAttr.mCursorGap.px - mAttr.mCursorWidth.px 136 | } 137 | ScaleAttrEnum.BOTTOM -> { 138 | if (mAttr.mScaleStyle != ScaleAttrEnum.LINE) { 139 | return 140 | } 141 | 142 | cursorRectF.mTransX = touchX - mAttr.mCursorWidth.px / 2 143 | 144 | cursorRectF.mTransY = 145 | mAttr.mPaddingTop + (interval - linelength) / 2 + linelength + mAttr.mCursorGap.px 146 | 147 | } 148 | 149 | 150 | } 151 | 152 | 153 | cursorMatrix.reset() 154 | // 创建操作图片用的 Matrix 对象 155 | cursorMatrix.postScale( 156 | cursorRectF.mScaleX, cursorRectF.mScaleY 157 | ); 158 | cursorMatrix.postTranslate( 159 | cursorRectF.mTransX, 160 | cursorRectF.mTransY 161 | ); 162 | 163 | canvas?.drawBitmap(mAttr.mCursorBitmap, cursorMatrix, null) 164 | 165 | } 166 | 167 | 168 | } -------------------------------------------------------------------------------- /ScaleView/libScaleView/src/main/java/com/mrr/libscaleview/view/VerticalScaleView.kt: -------------------------------------------------------------------------------- 1 | package com.mrr.libscaleview.view 2 | 3 | import android.graphics.Canvas 4 | import android.graphics.Paint 5 | import android.graphics.RectF 6 | import android.util.Log 7 | import com.mrr.libscaleview.attr.ScaleViewAttr 8 | import com.mrr.libscaleview.enum.ScaleAttrEnum 9 | import com.mrr.libscaleview.rectf.ScaleTextRectF 10 | import com.mrr.libscaleview.util.UnitConversion.Companion.px 11 | import java.util.function.Consumer 12 | 13 | class VerticalScaleView : BaseScaleView { 14 | 15 | private val TAG = "VerticalScaleView" 16 | 17 | 18 | var letter: String = "" 19 | var scaleTextRectF: ScaleTextRectF? = null 20 | 21 | constructor(attr: ScaleViewAttr) : super(attr) { 22 | scaleTextRectF = ScaleTextRectF() 23 | 24 | } 25 | 26 | override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { 27 | 28 | //刻度线本身占用的空间 29 | var calibrationSpace = mAttr.mScaleLineWidth * (mAttr.mTotalProgress + 1) 30 | 31 | drawSpace = mAttr.mHeight - mAttr.mPaddingTop - mAttr.mPaddingBottom 32 | //刻度之间的缝隙大小 33 | perInterval = (drawSpace - calibrationSpace) / mAttr.mTotalProgress 34 | //每个一个刻度最长可绘制的空间 35 | interval = mAttr.mWidth - mAttr.mPaddingLeft - mAttr.mPaddingRight 36 | nodeLength = interval * mAttr.mScaleNodeWidth 37 | linelength = interval * mAttr.mScaleWidth 38 | 39 | clipRect = RectF() 40 | 41 | } 42 | 43 | override fun onDraw(canvas: Canvas?, touchX: Float, touchY: Float) { 44 | 45 | clipProgress = drawSpace * (touchY - mAttr.mPaddingTop) / drawSpace 46 | 47 | clipRect?.set(0f, 0f, mAttr.mWidth, touchY) 48 | drawLineScale(canvas, changeColorPaint, clipRect) 49 | 50 | progressChange(mAttr.mTotalProgress * (touchY - mAttr.mPaddingTop) / drawSpace) 51 | clipRect?.set(0f, touchY, mAttr.mWidth, mAttr.mHeight) 52 | 53 | drawLineScale(canvas, originColorPaint, clipRect) 54 | 55 | drawCursor(canvas, touchX, touchY) 56 | } 57 | 58 | override fun initTouchXY(touchXCon: Consumer, touchYCon: Consumer) { 59 | touchYCon.accept(mAttr.mPaddingTop.toFloat()) 60 | } 61 | 62 | 63 | /** 64 | * 画线性的刻度 65 | */ 66 | private fun drawLineScale(canvas: Canvas?, paint: Paint, clipRectF: RectF) { 67 | 68 | 69 | canvas!!.save() 70 | canvas.clipRect(clipRectF) 71 | 72 | nodeStartX = mAttr.mPaddingLeft + (interval - nodeLength) / 2 73 | nodeStopX = nodeStartX + nodeLength 74 | 75 | startX = mAttr.mPaddingLeft + (interval - linelength) / 2 76 | stopX = startX + linelength 77 | 78 | startY = mAttr.mPaddingTop + halfCalibration 79 | stopY = startY 80 | 81 | 82 | for (index in 0..mAttr.mTotalProgress) { 83 | 84 | canvas?.drawLine( 85 | if (index % mAttr.mUnitScale == 0) nodeStartX.toFloat() else startX, 86 | startY.toFloat(), 87 | if (index % mAttr.mUnitScale == 0) nodeStopX.toFloat() else stopX, 88 | stopY.toFloat(), 89 | paint 90 | ) 91 | 92 | 93 | if ((index % mAttr.mUnitScale == 0)) { 94 | 95 | letter = index.toString() 96 | scaleTextRectF?.initLineTextSeat(letter, this) 97 | 98 | if (scaleTextRectF?.init == true) { 99 | 100 | canvas.drawText( 101 | letter, 102 | scaleTextRectF!!.x, 103 | scaleTextRectF!!.baseLine, 104 | textPaint 105 | ) 106 | } 107 | 108 | 109 | } 110 | 111 | startY += (perInterval + mAttr.mScaleLineWidth) 112 | stopY += (perInterval + mAttr.mScaleLineWidth) 113 | } 114 | canvas.restore() 115 | 116 | } 117 | 118 | 119 | /** 120 | * 绘制游标 121 | * 122 | */ 123 | private fun drawCursor(canvas: Canvas?, touchX: Float, touchY: Float) { 124 | 125 | if (null == mAttr.mCursorBitmap || mAttr.mScaleStyle != ScaleAttrEnum.LINE) { 126 | return 127 | } 128 | 129 | when (mAttr.mCursorSeat) { 130 | ScaleAttrEnum.LEFT -> { 131 | cursorRectF.mTransX = 132 | mAttr.mPaddingLeft + (interval - linelength) / 2 - mAttr.mCursorGap.px - mAttr.mCursorWidth.px 133 | cursorRectF.mTransY = touchY - mAttr.mCursorWidth.px / 2 134 | 135 | } 136 | ScaleAttrEnum.RIGHT -> { 137 | cursorRectF.mTransX = 138 | mAttr.mPaddingLeft + (interval - linelength) / 2 + linelength + mAttr.mCursorGap.px 139 | cursorRectF.mTransY = touchY - mAttr.mCursorWidth.px / 2 140 | 141 | } 142 | } 143 | 144 | cursorMatrix.reset() 145 | // 创建操作图片用的 Matrix 对象 146 | cursorMatrix.postScale( 147 | cursorRectF.mScaleX, cursorRectF.mScaleY 148 | ); 149 | cursorMatrix.postTranslate( 150 | cursorRectF.mTransX, 151 | cursorRectF.mTransY 152 | ); 153 | 154 | 155 | canvas?.drawBitmap(mAttr.mCursorBitmap, cursorMatrix, null) 156 | 157 | } 158 | 159 | } -------------------------------------------------------------------------------- /ScaleView/libScaleView/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 15 | 18 | 21 | 22 | 23 | 24 | 30 | -------------------------------------------------------------------------------- /ScaleView/libScaleView/src/main/res/drawable-xxhdpi/brightness.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrR0990/ScaleView/b9d4e25c075d746722305ac6086c3fa82cadc8ba/ScaleView/libScaleView/src/main/res/drawable-xxhdpi/brightness.png -------------------------------------------------------------------------------- /ScaleView/libScaleView/src/main/res/drawable-xxhdpi/lollipop.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrR0990/ScaleView/b9d4e25c075d746722305ac6086c3fa82cadc8ba/ScaleView/libScaleView/src/main/res/drawable-xxhdpi/lollipop.png -------------------------------------------------------------------------------- /ScaleView/libScaleView/src/main/res/drawable-xxhdpi/night_brightness.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrR0990/ScaleView/b9d4e25c075d746722305ac6086c3fa82cadc8ba/ScaleView/libScaleView/src/main/res/drawable-xxhdpi/night_brightness.png -------------------------------------------------------------------------------- /ScaleView/libScaleView/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrR0990/ScaleView/b9d4e25c075d746722305ac6086c3fa82cadc8ba/ScaleView/libScaleView/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /ScaleView/libScaleView/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrR0990/ScaleView/b9d4e25c075d746722305ac6086c3fa82cadc8ba/ScaleView/libScaleView/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /ScaleView/libScaleView/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrR0990/ScaleView/b9d4e25c075d746722305ac6086c3fa82cadc8ba/ScaleView/libScaleView/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /ScaleView/libScaleView/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrR0990/ScaleView/b9d4e25c075d746722305ac6086c3fa82cadc8ba/ScaleView/libScaleView/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /ScaleView/libScaleView/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrR0990/ScaleView/b9d4e25c075d746722305ac6086c3fa82cadc8ba/ScaleView/libScaleView/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /ScaleView/libScaleView/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrR0990/ScaleView/b9d4e25c075d746722305ac6086c3fa82cadc8ba/ScaleView/libScaleView/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /ScaleView/libScaleView/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrR0990/ScaleView/b9d4e25c075d746722305ac6086c3fa82cadc8ba/ScaleView/libScaleView/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /ScaleView/libScaleView/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrR0990/ScaleView/b9d4e25c075d746722305ac6086c3fa82cadc8ba/ScaleView/libScaleView/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /ScaleView/libScaleView/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrR0990/ScaleView/b9d4e25c075d746722305ac6086c3fa82cadc8ba/ScaleView/libScaleView/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /ScaleView/libScaleView/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrR0990/ScaleView/b9d4e25c075d746722305ac6086c3fa82cadc8ba/ScaleView/libScaleView/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /ScaleView/libScaleView/src/main/res/values/attr.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /ScaleView/libScaleView/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #FFBB86FC 4 | #FF6200EE 5 | #FF3700B3 6 | #FF03DAC5 7 | #FF018786 8 | #FF000000 9 | #FFFFFFFF 10 | #FFEB3B 11 | #9C9898 12 | -------------------------------------------------------------------------------- /ScaleView/libScaleView/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | ScaleView 3 | -------------------------------------------------------------------------------- /ScaleView/libScaleView/src/test/java/com/mrr/libscaleview/ExampleUnitTest.kt: -------------------------------------------------------------------------------- 1 | package com.mrr.libscaleview 2 | 3 | import org.junit.Test 4 | 5 | import org.junit.Assert.* 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * See [testing documentation](http://d.android.com/tools/testing). 11 | */ 12 | class ExampleUnitTest { 13 | @Test 14 | fun addition_isCorrect() { 15 | assertEquals(4, 2 + 2) 16 | } 17 | } -------------------------------------------------------------------------------- /ScaleView/settings.gradle: -------------------------------------------------------------------------------- 1 | include ':libScaleView' 2 | include ':app' 3 | rootProject.name = "ScaleView" --------------------------------------------------------------------------------