├── jitpack.yml ├── gradle.properties ├── settings.gradle ├── RotarySeekbar ├── gradle.properties ├── src │ └── main │ │ ├── res │ │ ├── color │ │ │ ├── sector_value_color.xml │ │ │ └── sector_range_color.xml │ │ └── values │ │ │ ├── RotarySeekbar_DefaultMaterialStyle.xml │ │ │ └── attrs.xml │ │ └── java │ │ └── no │ │ └── kapelrud │ │ └── RotarySeekbar.java └── build.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── screenshots ├── Screenshot_demo_app.png ├── Screenshot_demo_app_01.png ├── Screenshot_demo_app_02.png ├── Screenshot_demo_app_03.png └── Screenshot_demo_app_04.png ├── Examples └── Palette │ ├── app │ ├── src │ │ └── main │ │ │ ├── res │ │ │ ├── values │ │ │ │ ├── strings.xml │ │ │ │ ├── colors.xml │ │ │ │ └── styles.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 │ │ │ ├── mipmap-anydpi-v26 │ │ │ │ ├── ic_launcher.xml │ │ │ │ └── ic_launcher_round.xml │ │ │ ├── drawable-v24 │ │ │ │ └── ic_launcher_foreground.xml │ │ │ ├── drawable │ │ │ │ └── ic_launcher_background.xml │ │ │ └── layout │ │ │ │ └── activity_main.xml │ │ │ ├── java │ │ │ └── no │ │ │ │ └── kapelrud │ │ │ │ └── rotary_seekbar_demo │ │ │ │ └── MainActivity.kt │ │ │ └── AndroidManifest.xml │ ├── proguard-rules.pro │ └── build.gradle │ ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties │ ├── settings.gradle │ ├── build.gradle │ ├── gradle.properties │ ├── gradlew.bat │ └── gradlew ├── gradlew.bat ├── README.md ├── gradlew └── LICENSE /jitpack.yml: -------------------------------------------------------------------------------- 1 | jdk: 2 | - openjdk11 3 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | android.useAndroidX=true 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':RotarySeekbar' 2 | -------------------------------------------------------------------------------- /RotarySeekbar/gradle.properties: -------------------------------------------------------------------------------- 1 | android.useAndroidX=true -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akapelrud/Rotary-Seekbar/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /screenshots/Screenshot_demo_app.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akapelrud/Rotary-Seekbar/HEAD/screenshots/Screenshot_demo_app.png -------------------------------------------------------------------------------- /screenshots/Screenshot_demo_app_01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akapelrud/Rotary-Seekbar/HEAD/screenshots/Screenshot_demo_app_01.png -------------------------------------------------------------------------------- /screenshots/Screenshot_demo_app_02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akapelrud/Rotary-Seekbar/HEAD/screenshots/Screenshot_demo_app_02.png -------------------------------------------------------------------------------- /screenshots/Screenshot_demo_app_03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akapelrud/Rotary-Seekbar/HEAD/screenshots/Screenshot_demo_app_03.png -------------------------------------------------------------------------------- /screenshots/Screenshot_demo_app_04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akapelrud/Rotary-Seekbar/HEAD/screenshots/Screenshot_demo_app_04.png -------------------------------------------------------------------------------- /Examples/Palette/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Rotary-Seekbar-Demo 3 | 4 | -------------------------------------------------------------------------------- /Examples/Palette/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akapelrud/Rotary-Seekbar/HEAD/Examples/Palette/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /Examples/Palette/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akapelrud/Rotary-Seekbar/HEAD/Examples/Palette/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /Examples/Palette/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akapelrud/Rotary-Seekbar/HEAD/Examples/Palette/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /Examples/Palette/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akapelrud/Rotary-Seekbar/HEAD/Examples/Palette/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /Examples/Palette/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akapelrud/Rotary-Seekbar/HEAD/Examples/Palette/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /Examples/Palette/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akapelrud/Rotary-Seekbar/HEAD/Examples/Palette/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /Examples/Palette/app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akapelrud/Rotary-Seekbar/HEAD/Examples/Palette/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /Examples/Palette/app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akapelrud/Rotary-Seekbar/HEAD/Examples/Palette/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /Examples/Palette/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akapelrud/Rotary-Seekbar/HEAD/Examples/Palette/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /Examples/Palette/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akapelrud/Rotary-Seekbar/HEAD/Examples/Palette/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /Examples/Palette/settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | rootProject.name='Rotary-Seekbar-Demo' 3 | 4 | include 'RotarySeekbar' 5 | project(':RotarySeekbar').projectDir = file('../../RotarySeekbar') 6 | -------------------------------------------------------------------------------- /Examples/Palette/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akapelrud/Rotary-Seekbar/HEAD/Examples/Palette/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-all.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /RotarySeekbar/src/main/res/color/sector_value_color.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /RotarySeekbar/src/main/res/color/sector_range_color.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Examples/Palette/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sun Feb 02 20:12:38 CET 2020 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-all.zip 7 | -------------------------------------------------------------------------------- /Examples/Palette/app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #42a5f5 4 | #80d6ff 5 | #66bb6a 6 | #ffffff 7 | 8 | -------------------------------------------------------------------------------- /Examples/Palette/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /Examples/Palette/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /Examples/Palette/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /Examples/Palette/app/src/main/java/no/kapelrud/rotary_seekbar_demo/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package no.kapelrud.rotary_seekbar_demo 2 | 3 | import androidx.appcompat.app.AppCompatActivity 4 | import android.os.Bundle 5 | 6 | class MainActivity : AppCompatActivity() { 7 | 8 | override fun onCreate(savedInstanceState: Bundle?) { 9 | super.onCreate(savedInstanceState) 10 | setContentView(R.layout.activity_main) 11 | 12 | /* It is possible to alter the values programmatically. The value will snap to valid 13 | * steps and bounds. 14 | */ 15 | //rot01.value = 100.22f; 16 | //rot02.value = -12319.0f; 17 | //rot22.value = 47.5f; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Examples/Palette/build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | ext.kotlin_version = '1.3.71' 5 | repositories { 6 | google() 7 | jcenter() 8 | 9 | } 10 | dependencies { 11 | classpath 'com.android.tools.build:gradle:7.2.1' 12 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 13 | // NOTE: Do not place your application dependencies here; they belong 14 | // in the individual module build.gradle files 15 | } 16 | } 17 | 18 | allprojects { 19 | repositories { 20 | google() 21 | jcenter() 22 | 23 | } 24 | } 25 | 26 | task clean(type: Delete) { 27 | delete rootProject.buildDir 28 | } 29 | -------------------------------------------------------------------------------- /Examples/Palette/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /Examples/Palette/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /RotarySeekbar/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | repositories { 4 | mavenCentral() 5 | google() 6 | } 7 | 8 | dependencies { 9 | implementation fileTree(dir: 'libs', include: ['*.jar']) 10 | // 1.2 is needed for materialthemeoverlay 11 | implementation 'com.google.android.material:material:1.6.1' 12 | } 13 | 14 | ext { 15 | PUBLISH_GROUP_ID = 'no.kapelrud' 16 | PUBLISH_ARTIFACT_ID = 'RotarySeekbar' 17 | PUBLISH_VERSION = '1.2.0' 18 | } 19 | 20 | android { 21 | namespace = 'no.kapelrud' 22 | compileSdkVersion 32 23 | 24 | defaultConfig { 25 | minSdkVersion 22 26 | targetSdkVersion 32 27 | versionCode 1 28 | versionName project.PUBLISH_VERSION 29 | } 30 | 31 | /*publishing{ 32 | multipleVariants{ 33 | allVariants() 34 | withJavadocs() 35 | } 36 | }*/ 37 | } 38 | apply from: 'https://raw.githubusercontent.com/sky-uk/gradle-maven-plugin/master/gradle-mavenizer.gradle' 39 | 40 | 41 | -------------------------------------------------------------------------------- /Examples/Palette/app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'kotlin-android' 3 | apply plugin: 'kotlin-android-extensions' 4 | 5 | android { 6 | compileSdkVersion 32 7 | defaultConfig { 8 | applicationId "no.kapelrud.rotary_seekbar_demo" 9 | minSdkVersion 22 10 | targetSdkVersion 32 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | implementation fileTree(dir: 'libs', include: ['*.jar']) 24 | implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 25 | implementation 'androidx.appcompat:appcompat:1.1.0' 26 | implementation 'androidx.core:core-ktx:1.2.0' 27 | implementation 'com.google.android.material:material:1.6.1' 28 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3' 29 | implementation project(':RotarySeekbar') 30 | } 31 | -------------------------------------------------------------------------------- /Examples/Palette/gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx1536m 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | # AndroidX package structure to make it clearer which packages are bundled with the 15 | # Android operating system, and which are packaged with your app's APK 16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn 17 | android.useAndroidX=true 18 | # Automatically convert third-party libraries to use AndroidX 19 | android.enableJetifier=true 20 | # Kotlin code style for this project: "official" or "obsolete": 21 | kotlin.code.style=official 22 | -------------------------------------------------------------------------------- /RotarySeekbar/src/main/res/values/RotarySeekbar_DefaultMaterialStyle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 32 | -------------------------------------------------------------------------------- /Examples/Palette/app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /Examples/Palette/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 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem http://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 33 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 34 | 35 | @rem Find java.exe 36 | if defined JAVA_HOME goto findJavaFromJavaHome 37 | 38 | set JAVA_EXE=java.exe 39 | %JAVA_EXE% -version >NUL 2>&1 40 | if "%ERRORLEVEL%" == "0" goto init 41 | 42 | echo. 43 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 44 | echo. 45 | echo Please set the JAVA_HOME variable in your environment to match the 46 | echo location of your Java installation. 47 | 48 | goto fail 49 | 50 | :findJavaFromJavaHome 51 | set JAVA_HOME=%JAVA_HOME:"=% 52 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 53 | 54 | if exist "%JAVA_EXE%" goto init 55 | 56 | echo. 57 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 58 | echo. 59 | echo Please set the JAVA_HOME variable in your environment to match the 60 | echo location of your Java installation. 61 | 62 | goto fail 63 | 64 | :init 65 | @rem Get command-line arguments, handling Windows variants 66 | 67 | if not "%OS%" == "Windows_NT" goto win9xME_args 68 | 69 | :win9xME_args 70 | @rem Slurp the command line arguments. 71 | set CMD_LINE_ARGS= 72 | set _SKIP=2 73 | 74 | :win9xME_args_slurp 75 | if "x%~1" == "x" goto execute 76 | 77 | set CMD_LINE_ARGS=%* 78 | 79 | :execute 80 | @rem Setup the command line 81 | 82 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 83 | 84 | @rem Execute Gradle 85 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 86 | 87 | :end 88 | @rem End local scope for the variables with windows NT shell 89 | if "%ERRORLEVEL%"=="0" goto mainEnd 90 | 91 | :fail 92 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 93 | rem the _cmd.exe /c_ return code! 94 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 95 | exit /b 1 96 | 97 | :mainEnd 98 | if "%OS%"=="Windows_NT" endlocal 99 | 100 | :omega 101 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # RotarySeekbar 2 | RotarySeekbar (aka. a knob) is an interactive View for Android that upon touch enlarges the view (_overlay zooming_) thus making it easy to adjust the value of the knob while actually seeing what you are doing. The view responds to any touch within its' bounds, i.e. **not** relying on a precise touch of a tiny knob handle widget (c.f. [Fitt's law](https://en.wikipedia.org/wiki/Fitts%27s_law)). The rotation of the knob is based on amplifying the finger movement based on the distance from the center of the knob, giving the user both fine and coarse control of the value selection. The overlay zooming and movement amplification makes it possible to put compact rotary seekbars (e.g. 48dp x 48dp) in your gui, while still providing sufficient visual feedback and control granularity to the end user. 3 | 4 | [![](https://jitpack.io/v/akapelrud/Rotary-Seekbar.svg)](https://jitpack.io/#akapelrud/Rotary-Seekbar) 5 | 6 | ## Usage 7 | - Step 1. Add jitpack to your root build.gradle, at the end of the repositories list: 8 | 9 | ``` 10 | allprojects { 11 | repositories { 12 | ... 13 | maven { url 'https://jitpack.io' } 14 | } 15 | } 16 | ``` 17 | - Step 2. Add the dependency 18 | 19 | ``` 20 | dependencies { 21 | // either choose a release (TAG) from github: 22 | implementation 'com.github.akapelrud:Rotary-Seekbar:TAG' 23 | // where TAG = 'vMajor.Minor,Micro' 24 | 25 | // or use the current HEAD of a branch e.g. branch: 26 | // implementation 'com.github.akapelrud:Rotary-Seekbar:master-SNAPSHOT' 27 | // implementation 'com.github.akapelrud:Rotary-Seekbar:develop-SNAPSHOT' 28 | } 29 | ``` 30 | - Step 3. Make sure that your app theme is based on one of the material design themes, e.g. `values/styles.xml`: 31 | 32 | ``` 33 | 42 | ``` 43 | - Step 4. Add the RotarySeekbar to your layout file, c.f. [the attribute definition](../master/RotarySeekbar/src/main/res/values/attrs.xml) and the demo app's layout file: [DEMO layout](../master/Examples/Palette/app/src/main/res/layout/activity_main.xml) 44 | - Step 5. Implement the `RotarySeekbar.OnValueChangeListener` interface, and register using `setOnValueChangeListener()`. 45 | 46 | ``` 47 | public interface OnValueChangedListener { 48 | void onValueChanged(RotarySeekbar sourceSeekbar, float value); 49 | } 50 | ``` 51 | 52 | ## Example 53 | The first image shows the demo application with 16 differently styled RotarySeekbars. All of these have been customized through the `.xml` layout file. 54 | 55 | 56 | 57 | Pressing either of the widgets will enlarge the view of the component, making it easier to choose a value while still having the component visible. 58 | 59 | 60 | -------------------------------------------------------------------------------- /RotarySeekbar/src/main/res/values/attrs.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 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | -------------------------------------------------------------------------------- /Examples/Palette/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 | -------------------------------------------------------------------------------- /Examples/Palette/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 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | ## 21 | ## Gradle start up script for UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="`pwd`" 39 | cd "`dirname \"$PRG\"`/" >/dev/null 40 | APP_HOME="`pwd -P`" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="Gradle" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 84 | 85 | # Determine the Java command to use to start the JVM. 86 | if [ -n "$JAVA_HOME" ] ; then 87 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 88 | # IBM's JDK on AIX uses strange locations for the executables 89 | JAVACMD="$JAVA_HOME/jre/sh/java" 90 | else 91 | JAVACMD="$JAVA_HOME/bin/java" 92 | fi 93 | if [ ! -x "$JAVACMD" ] ; then 94 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 95 | 96 | Please set the JAVA_HOME variable in your environment to match the 97 | location of your Java installation." 98 | fi 99 | else 100 | JAVACMD="java" 101 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 102 | 103 | Please set the JAVA_HOME variable in your environment to match the 104 | location of your Java installation." 105 | fi 106 | 107 | # Increase the maximum file descriptors if we can. 108 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 109 | MAX_FD_LIMIT=`ulimit -H -n` 110 | if [ $? -eq 0 ] ; then 111 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 112 | MAX_FD="$MAX_FD_LIMIT" 113 | fi 114 | ulimit -n $MAX_FD 115 | if [ $? -ne 0 ] ; then 116 | warn "Could not set maximum file descriptor limit: $MAX_FD" 117 | fi 118 | else 119 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 120 | fi 121 | fi 122 | 123 | # For Darwin, add options to specify how the application appears in the dock 124 | if $darwin; then 125 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 126 | fi 127 | 128 | # For Cygwin, switch paths to Windows format before running java 129 | if $cygwin ; then 130 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 131 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 132 | JAVACMD=`cygpath --unix "$JAVACMD"` 133 | 134 | # We build the pattern for arguments to be converted via cygpath 135 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 136 | SEP="" 137 | for dir in $ROOTDIRSRAW ; do 138 | ROOTDIRS="$ROOTDIRS$SEP$dir" 139 | SEP="|" 140 | done 141 | OURCYGPATTERN="(^($ROOTDIRS))" 142 | # Add a user-defined pattern to the cygpath arguments 143 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 144 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 145 | fi 146 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 147 | i=0 148 | for arg in "$@" ; do 149 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 150 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 151 | 152 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 153 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 154 | else 155 | eval `echo args$i`="\"$arg\"" 156 | fi 157 | i=$((i+1)) 158 | done 159 | case $i in 160 | (0) set -- ;; 161 | (1) set -- "$args0" ;; 162 | (2) set -- "$args0" "$args1" ;; 163 | (3) set -- "$args0" "$args1" "$args2" ;; 164 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 165 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 166 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 167 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 168 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 169 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 170 | esac 171 | fi 172 | 173 | # Escape application args 174 | save () { 175 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 176 | echo " " 177 | } 178 | APP_ARGS=$(save "$@") 179 | 180 | # Collect all arguments for the java command, following the shell quoting and substitution rules 181 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 182 | 183 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 184 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 185 | cd "$(dirname "$0")" 186 | fi 187 | 188 | exec "$JAVACMD" "$@" 189 | -------------------------------------------------------------------------------- /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 | 203 | -------------------------------------------------------------------------------- /Examples/Palette/app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 28 | 29 | 47 | 48 | 67 | 68 | 88 | 89 | 111 | 112 | 133 | 134 | 158 | 159 | 182 | 183 | 202 | 203 | 222 | 223 | 241 | 242 | 263 | 264 | 284 | 285 | 306 | 307 | 328 | 329 | 351 | 352 | -------------------------------------------------------------------------------- /RotarySeekbar/src/main/java/no/kapelrud/RotarySeekbar.java: -------------------------------------------------------------------------------- 1 | package no.kapelrud; 2 | 3 | import android.content.Context; 4 | import android.content.res.ColorStateList; 5 | import android.content.res.TypedArray; 6 | import android.graphics.Canvas; 7 | import android.graphics.ColorFilter; 8 | import android.graphics.Matrix; 9 | import android.graphics.Paint; 10 | import android.graphics.Path; 11 | import android.graphics.PixelFormat; 12 | import android.graphics.PointF; 13 | import android.graphics.Rect; 14 | import android.graphics.RectF; 15 | import android.graphics.drawable.Drawable; 16 | import android.graphics.drawable.LayerDrawable; 17 | import android.os.Build; 18 | import android.os.Bundle; 19 | import android.os.Parcelable; 20 | import android.util.AttributeSet; 21 | import android.util.DisplayMetrics; 22 | import android.view.GestureDetector; 23 | import android.view.MotionEvent; 24 | import android.view.View; 25 | 26 | import androidx.annotation.NonNull; 27 | import androidx.annotation.Nullable; 28 | 29 | import static com.google.android.material.theme.overlay.MaterialThemeOverlay.wrap; 30 | 31 | import com.google.android.material.shape.CornerFamily; 32 | import com.google.android.material.shape.MaterialShapeDrawable; 33 | import com.google.android.material.shape.ShapeAppearanceModel; 34 | 35 | /** 36 | * Rotary Seekbar Widget with zoom-on-touch for Android. 37 | * Created by André on 18.02.2015. 38 | * 39 | */ 40 | public class RotarySeekbar extends View { 41 | 42 | private static final String TAG = "RotarySeekbar"; 43 | 44 | private static final int DEFAULT_STYLE_RES = R.style.RotarySeekbar_DefaultMaterialStyle; 45 | 46 | private static final int SCROLL_ANGULAR_SCALE_DP = 48; 47 | private final int OVERLAY_PADDING_DP = 12; 48 | private static final int ROTATION_SNAP_BUFFER = 30; 49 | // Used when mSectorHalfOpening is small, to prevent jumping from max to min value too quick. 50 | 51 | private final int DEFAULT_SEEKBAR_DIAMETER = 88; 52 | // 96dp allowing for the standard 4dp padding on each side. 53 | 54 | private final int OPENING_TEXT_MARGIN = dpToPx(2); 55 | private boolean mbScrolling = false; 56 | 57 | private int mNumSteps = 1; 58 | private float mMinValue = 0; 59 | private float mMaxValue = 100; 60 | private int mValueNumDigits = 1; 61 | 62 | private String mValueStr; 63 | private String mUnitStr; 64 | private float mValue = 50; 65 | private float mTextSize = spToPx(20); 66 | private float mTextWidth = 0.0f; 67 | private float mTextHeight = 0.0f; 68 | 69 | private boolean mNeedleOnTop = true; 70 | private float mKnobRadius = 0.3f; 71 | 72 | private int mSectorRotation = 0; // degrees. Extra rotation of the Seekbar. User set. 73 | private float mSectorHalfOpening = 30; // degrees 74 | private float mSectorMinRadiusScale = 0.4f; 75 | private float mSectorMajRadiusScale = 0.75f; 76 | private float mTickMinRadiusScale = 0.8f; 77 | private float mTickMajRadiusScale = 1.0f; 78 | 79 | private boolean mShowValue = true; 80 | private boolean mShowNeedle = true; 81 | private boolean mShowKnob = true; 82 | private boolean mShowTicks = true; 83 | private boolean mShowSector = true; 84 | private boolean mSubtractTicks = true; 85 | private boolean mShowUnit = true; 86 | 87 | private boolean mTrackValue = false; 88 | private float mStartScrollValue; 89 | 90 | private int mNumTicks = 2; // +1 sections 91 | 92 | private int mKnobColor = 0xff666666; 93 | private int mTextColor = 0xff000000; 94 | private int mSectorColor = 0xffdddddd; 95 | private int mValueSectorColor = 0xffaaaaaa; 96 | private int mTicksColor = 0xff006699; 97 | private int mNeedleColor = 0xff880000; 98 | 99 | private int mOverlaySurfaceColor = 0xffffffff; 100 | 101 | private float mNeedleWidth = dpToPx(4); 102 | private float mTicksWidth = dpToPx(4); 103 | private float mTicksSubtractWidth = dpToPx(2); 104 | 105 | private float mNeedleMinorRadius = 0.0f; 106 | private float mNeedleMajorRadius = 1.0f; 107 | 108 | private float mOverlayBorderMargin = dpToPx(4); 109 | private Rect mOverlayGlobalBounds = new Rect(); 110 | private float mOverlaySizeDP = 192; // size of overlay in dp-s. 111 | 112 | private enum ValuePosition { 113 | Bottom(0), 114 | Left(1), 115 | Top(2), 116 | Right(3), 117 | Center(4); 118 | 119 | int id; 120 | 121 | ValuePosition(int id) { 122 | this.id = id; 123 | } 124 | 125 | static ValuePosition fromId(int id) { 126 | for (ValuePosition vp : values()) { 127 | if (vp.id == id) 128 | return vp; 129 | } 130 | return Bottom; 131 | } 132 | } 133 | 134 | private ValuePosition mValuePosition = ValuePosition.Bottom; 135 | private float mRotation = 0.0f; 136 | private float mAccumulatedAngleChange; 137 | 138 | private RotarySeekbarDrawable mOverlaySeekbarProxy; 139 | private RotarySeekbarImpl mLayedOutSeekbar; 140 | private RotarySeekbarImpl mOverlaySeekbar; 141 | private LayerDrawable mOverlay; 142 | 143 | private Paint mSectorPaint; 144 | private Paint mValueSectorPaint; 145 | private Paint mKnobPaint; 146 | 147 | private GestureDetector mDetector; 148 | private OnValueChangedListener mListener = null; 149 | 150 | public interface OnValueChangedListener { 151 | void onValueChanged(RotarySeekbar sourceSeekbar, float value); 152 | } 153 | 154 | public RotarySeekbar(Context context) { 155 | this(context, null); 156 | } 157 | 158 | public RotarySeekbar(@NonNull Context context, AttributeSet attributeSet) 159 | { 160 | this(context, attributeSet, DEFAULT_STYLE_RES); 161 | } 162 | 163 | public RotarySeekbar(@NonNull Context context, @Nullable AttributeSet attributeSet, int defStyleAttr) { 164 | this(context, attributeSet, defStyleAttr, DEFAULT_STYLE_RES); 165 | } 166 | 167 | public RotarySeekbar(@NonNull Context context, @Nullable AttributeSet attributeSet, int defStyleAttr, int defStyleRes) { 168 | super(wrap(context, attributeSet, defStyleAttr, defStyleRes), attributeSet, defStyleAttr); 169 | context = getContext(); 170 | 171 | final TypedArray a = context.obtainStyledAttributes(attributeSet, R.styleable.RotarySeekbar, defStyleAttr, defStyleRes); 172 | try{ 173 | mShowValue = a.getBoolean(R.styleable.RotarySeekbar_showValue, mShowValue); 174 | mShowUnit = a.getBoolean(R.styleable.RotarySeekbar_showUnit, mShowUnit); 175 | mValueNumDigits = a.getInteger(R.styleable.RotarySeekbar_valueNumDigits, mValueNumDigits); 176 | mUnitStr = a.getString(R.styleable.RotarySeekbar_unit); 177 | mMinValue = a.getFloat(R.styleable.RotarySeekbar_valueMin, mMinValue); 178 | mMaxValue = a.getFloat(R.styleable.RotarySeekbar_valueMax, mMaxValue); 179 | assert(mMinValue != mMaxValue); 180 | 181 | mValue = a.getFloat(R.styleable.RotarySeekbar_value, mValue); 182 | mValuePosition = ValuePosition.fromId(a.getInt(R.styleable.RotarySeekbar_valuePosition, ValuePosition.Bottom.id)); 183 | 184 | mNumSteps = a.getInteger(R.styleable.RotarySeekbar_valueNumSteps, mNumSteps); 185 | if (mNumSteps < 1) 186 | mNumSteps = 1; 187 | 188 | mTextColor = a.getColor(R.styleable.RotarySeekbar_textColor, mTextColor); 189 | mTextSize = a.getDimension(R.styleable.RotarySeekbar_textSize, mTextSize); 190 | 191 | mTrackValue = a.getBoolean(R.styleable.RotarySeekbar_trackValue, mTrackValue); 192 | mShowKnob = a.getBoolean(R.styleable.RotarySeekbar_showKnob, mShowKnob); 193 | mKnobRadius = a.getFloat(R.styleable.RotarySeekbar_knobRadius, mKnobRadius); 194 | mKnobColor = a.getColor(R.styleable.RotarySeekbar_knobColor, mKnobColor); 195 | 196 | mOverlaySurfaceColor = a.getColor(R.styleable.RotarySeekbar_overlaySurfaceColor, mOverlaySurfaceColor); 197 | mOverlaySizeDP = a.getDimension(R.styleable.RotarySeekbar_overlaySize, mOverlaySizeDP); 198 | 199 | mShowSector = a.getBoolean(R.styleable.RotarySeekbar_showSector, mShowSector); 200 | mSectorHalfOpening = 0.5f*a.getFloat(R.styleable.RotarySeekbar_sectorOpenAngle, 2.0f*mSectorHalfOpening); 201 | mSectorRotation = a.getInt(R.styleable.RotarySeekbar_sectorRotation, mSectorRotation); 202 | mSectorMinRadiusScale = a.getFloat(R.styleable.RotarySeekbar_sectorMinorRadius, mSectorMinRadiusScale); 203 | mSectorMajRadiusScale = a.getFloat(R.styleable.RotarySeekbar_sectorMajorRadius, mSectorMajRadiusScale); 204 | mSectorColor = a.getColor(R.styleable.RotarySeekbar_sectorRangeColor, mSectorColor); 205 | mValueSectorColor = a.getColor(R.styleable.RotarySeekbar_sectorValueColor, mValueSectorColor); 206 | 207 | mShowTicks = a.getBoolean(R.styleable.RotarySeekbar_showTicks, mShowTicks); 208 | mSubtractTicks = a.getBoolean(R.styleable.RotarySeekbar_ticksSubtract, mSubtractTicks); 209 | mTickMinRadiusScale = a.getFloat(R.styleable.RotarySeekbar_ticksMinorRadius, mTickMinRadiusScale); 210 | mTickMajRadiusScale = a.getFloat(R.styleable.RotarySeekbar_ticksMajorRadius, mTickMajRadiusScale); 211 | mTicksWidth = a.getDimension(R.styleable.RotarySeekbar_ticksThickness, mTicksWidth); 212 | mTicksSubtractWidth = a.getDimension(R.styleable.RotarySeekbar_ticksSubtractionThickness, mTicksSubtractWidth); 213 | mTicksColor = a.getColor(R.styleable.RotarySeekbar_ticksColor, mTicksColor); 214 | mNumTicks = a.getInteger(R.styleable.RotarySeekbar_numTicks, mNumTicks); 215 | 216 | mShowNeedle = a.getBoolean(R.styleable.RotarySeekbar_showNeedle, mShowNeedle); 217 | mNeedleColor = a.getColor(R.styleable.RotarySeekbar_needleColor, mNeedleColor); 218 | mNeedleWidth = a.getDimension(R.styleable.RotarySeekbar_needleThickness, mNeedleWidth); 219 | mNeedleMinorRadius = a.getFloat(R.styleable.RotarySeekbar_needleMinorRadius, mNeedleMinorRadius); 220 | mNeedleMajorRadius = a.getFloat(R.styleable.RotarySeekbar_needleMajorRadius, mNeedleMajorRadius); 221 | 222 | mNeedleOnTop = a.getBoolean(R.styleable.RotarySeekbar_needleOnTop, mNeedleOnTop); 223 | 224 | mOverlayBorderMargin = a.getDimension(R.styleable.RotarySeekbar_overlayBorderMargin, mOverlayBorderMargin); 225 | 226 | } finally { 227 | a.recycle(); 228 | } 229 | 230 | if (mNeedleMinorRadius == mNeedleMajorRadius) 231 | mNeedleMinorRadius = mNeedleMajorRadius*0.999f; // sometimes the line isn't drawn if they are equal 232 | 233 | init(); 234 | } 235 | 236 | @Override 237 | protected Parcelable onSaveInstanceState() { 238 | Bundle bundle = new Bundle(); 239 | bundle.putParcelable("instanceState", super.onSaveInstanceState()); 240 | bundle.putFloat("value", mValue); 241 | 242 | return bundle; 243 | } 244 | 245 | @Override 246 | protected void onRestoreInstanceState(Parcelable state) { 247 | 248 | if(state instanceof Bundle) { 249 | Bundle bundle = (Bundle)state; 250 | state = bundle.getParcelable("instanceState"); 251 | 252 | mValue = bundle.getFloat("value"); 253 | mRotation = valueToRotation(); 254 | updateText(); 255 | } 256 | super.onRestoreInstanceState(state); 257 | } 258 | 259 | private void init() { 260 | setLayerToSW(this); 261 | 262 | mOverlaySeekbarProxy = new RotarySeekbarDrawable(); // uses mOverlaySeekbar for drawing 263 | 264 | ShapeAppearanceModel.Builder builder = ShapeAppearanceModel.builder(); 265 | builder.setAllCorners(CornerFamily.ROUNDED, dpToPx(20)); 266 | MaterialShapeDrawable materialOverlay = new MaterialShapeDrawable(builder.build()); 267 | // TODO: fix elevation shadow. It doesn't appear at all. 268 | /*materialOverlay.initializeElevationOverlay(getContext()); 269 | materialOverlay.setShadowCompatibilityMode(MaterialShapeDrawable.SHADOW_COMPAT_MODE_DEFAULT); 270 | materialOverlay.setElevation(dpToPx(4));*/ 271 | materialOverlay.setStroke(dpToPx(2), 0x66000000); 272 | materialOverlay.setFillColor(ColorStateList.valueOf(mOverlaySurfaceColor)); 273 | mOverlay = new LayerDrawable(new Drawable[]{ 274 | materialOverlay, 275 | mOverlaySeekbarProxy 276 | }); 277 | 278 | // Make space for elevation shadow. Untested; this might clip the layer anyway. 279 | /*final int pad = dpToPx(OVERLAY_PADDING_DP); 280 | mOverlay.setLayerInset(0, pad, pad, pad, pad);*/ 281 | 282 | checkValueBounds(); 283 | mValue = snapValueToSteps(mValue); 284 | mRotation = valueToRotation(); 285 | updateText(); 286 | 287 | Paint tmpTextPaint = getTextPaint(1.0f); 288 | // These sizes are needed upon measuring 289 | mTextHeight = tmpTextPaint.getTextSize(); 290 | mTextWidth = getTextWidth(tmpTextPaint); 291 | 292 | // These paints does not change between overlay and displayed widget: 293 | mSectorPaint = new Paint(Paint.ANTI_ALIAS_FLAG); 294 | mSectorPaint.setStyle(Paint.Style.FILL); 295 | mSectorPaint.setColor(mSectorColor); 296 | mValueSectorPaint = new Paint(Paint.ANTI_ALIAS_FLAG); 297 | mValueSectorPaint.setStyle(Paint.Style.FILL); 298 | mValueSectorPaint.setColor(mValueSectorColor); 299 | 300 | mKnobPaint = new Paint(Paint.ANTI_ALIAS_FLAG); 301 | mKnobPaint.setStyle(Paint.Style.FILL); 302 | mKnobPaint.setColor(mKnobColor); 303 | 304 | mDetector = new GestureDetector(RotarySeekbar.this.getContext(), new mGestureListener()); 305 | mDetector.setIsLongpressEnabled(false); 306 | } 307 | 308 | private String formatValueString(float value) { 309 | String res = String.format("%." + mValueNumDigits + "f", value); 310 | if(mShowUnit && mUnitStr != null && !mUnitStr.equals("")) 311 | res += mUnitStr; 312 | return res; 313 | } 314 | 315 | private void updateText() { 316 | mValueStr = formatValueString(mValue); 317 | } 318 | 319 | private void checkValueBounds() { 320 | if(mMaxValue < mMinValue) { 321 | float tmp = mMinValue; 322 | mMinValue = mMaxValue; 323 | mMaxValue = tmp; 324 | } 325 | 326 | if(mValue > mMaxValue) 327 | mValue = mMaxValue; 328 | else if(mValue < mMinValue) 329 | mValue = mMinValue; 330 | } 331 | 332 | public float snapValueToSteps(float value) { 333 | final float VALUE_STEP_SIZE = (mMaxValue-mMinValue)/mNumSteps; 334 | return ( mMinValue+VALUE_STEP_SIZE*Math.round( (value-mMinValue)/VALUE_STEP_SIZE )); 335 | } 336 | 337 | public void setLayerToSW(View v) { 338 | if(!v.isInEditMode()) 339 | setLayerType(View.LAYER_TYPE_SOFTWARE, null); 340 | } 341 | 342 | public void setLayerToHW(View v) { 343 | if(!v.isInEditMode()) 344 | setLayerType(View.LAYER_TYPE_HARDWARE, null); 345 | } 346 | 347 | public void setOnValueChangedListener(OnValueChangedListener listener) { 348 | mListener = listener; 349 | listener.onValueChanged(this, mValue); 350 | } 351 | 352 | public float getValue() { 353 | return mValue; 354 | } 355 | 356 | public void setValue(float value) { 357 | mValue = value; 358 | checkValueBounds(); 359 | mValue = snapValueToSteps(mValue); 360 | mRotation = valueToRotation(); 361 | updateText(); 362 | 363 | if(!mbScrolling) { 364 | if (mLayedOutSeekbar != null) 365 | mLayedOutSeekbar.recreatePaths(); 366 | invalidate(); 367 | }else { 368 | if(mOverlaySeekbar != null) 369 | mOverlaySeekbar.recreatePaths(); 370 | mOverlaySeekbarProxy.invalidateSelf(); 371 | } 372 | } 373 | 374 | public void setValueByStep(int step) { 375 | // setValue will enforce clamping of the value 376 | setValue(mMinValue+step*(mMaxValue-mMinValue)/mNumSteps); 377 | } 378 | 379 | public int getCurrentStep() { 380 | return Math.round((mValue-mMinValue)/(mMaxValue-mMinValue)*mNumSteps); 381 | } 382 | 383 | public int getNumSteps() { 384 | return mNumSteps; 385 | } 386 | 387 | public float getMinValue() { 388 | return mMinValue; 389 | } 390 | 391 | public float getMaxValue() { 392 | return mMaxValue; 393 | } 394 | 395 | @Override 396 | protected void onDraw(Canvas canvas) { 397 | super.onDraw(canvas); 398 | if(!mbScrolling) 399 | mLayedOutSeekbar.draw(canvas); 400 | } 401 | 402 | @Override 403 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) { 404 | RectF bounds = mLayedOutSeekbar.getBounds(); 405 | float aspectRatio = bounds.width()/bounds.height(); 406 | calculateOverlayBounds(aspectRatio); 407 | 408 | final int padding = dpToPx(OVERLAY_PADDING_DP); 409 | RectF overlayBounds = new RectF(0,0, 410 | mOverlayGlobalBounds.width()-2*padding, 411 | mOverlayGlobalBounds.height()-2*padding); 412 | float overlayRelativeScale = overlayBounds.width()/bounds.width(); 413 | mOverlaySeekbar = new RotarySeekbarImpl(overlayBounds, overlayRelativeScale); 414 | mOverlay.setBounds(mOverlayGlobalBounds); 415 | } 416 | 417 | @Override 418 | public void onWindowSystemUiVisibilityChanged(int visible) { 419 | super.onWindowSystemUiVisibilityChanged(visible); 420 | 421 | if (0 != (visible & 422 | (View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION 423 | | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN 424 | | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION 425 | | View.SYSTEM_UI_FLAG_FULLSCREEN)) 426 | ) { 427 | requestLayout(); 428 | /* Sometimes onLayout() isn't called when, say, the navbar is hidden. I suspect that 429 | * e.g. ConstraintLayout might move the global screen position of views without actually 430 | * calling onLayout() for the child views, as the position within the container hasn't 431 | * changed. 432 | */ 433 | } 434 | } 435 | 436 | @Override 437 | protected void onSizeChanged(int w, int h, int oldw, int oldh) { 438 | float xpad = (float)(getPaddingLeft()+getPaddingRight()); 439 | float ypad = (float)(getPaddingTop()+getPaddingBottom()); 440 | float ww = (float)w-xpad; 441 | float hh = (float)h-ypad; 442 | 443 | RectF bounds = new RectF(0, 0, ww, hh); 444 | bounds.offsetTo(getPaddingLeft(), getPaddingTop()); 445 | mLayedOutSeekbar = new RotarySeekbarImpl(bounds); 446 | 447 | // The overlay's bounds is calculated upon layout to get the proper global position of this view. 448 | } 449 | 450 | public float clampRotation(float rotation) { 451 | // TODO: should allow rotation == 360. 452 | rotation %= 360; 453 | if(rotation < 0) rotation+=360; 454 | return rotation; 455 | } 456 | 457 | public float valueToRotation() { 458 | float rotation = (270- mSectorHalfOpening -(mValue-mMinValue)/(mMaxValue-mMinValue)*(360-2* mSectorHalfOpening)); 459 | return clampRotation(rotation); 460 | } 461 | 462 | @Override 463 | protected int getSuggestedMinimumHeight() { 464 | int res = 0; 465 | switch(mValuePosition) { 466 | case Bottom: 467 | case Top: 468 | res = (int)(mShowValue?mTextHeight:0)+getSuggestedMinimumWidth(); 469 | break; 470 | case Center: 471 | case Right: 472 | case Left: 473 | res = (int)mTextHeight*2; 474 | break; 475 | } 476 | return res; 477 | } 478 | 479 | @Override 480 | protected int getSuggestedMinimumWidth() { 481 | int res = 0; 482 | switch(mValuePosition) { 483 | case Bottom: 484 | case Top: 485 | if(mShowValue) 486 | res = (int)mTextWidth; 487 | else 488 | res = getSuggestedMinimumHeight(); 489 | break; 490 | case Center: 491 | res = getSuggestedMinimumHeight(); 492 | break; 493 | case Right: 494 | case Left: 495 | res = (int)(mShowValue ? mTextWidth:0)+getSuggestedMinimumHeight(); 496 | break; 497 | } 498 | return res; 499 | } 500 | 501 | /** 502 | * Get the suggested height of this view given a determined width. 503 | * @param width View's width (without padding) 504 | * @param maxHeight Maximum allowed height 505 | * @return suggested height (without padding) 506 | */ 507 | private int getSuggestedHeight(int width, int maxHeight) { 508 | if(width<=0 || maxHeight<=0) 509 | return 0; 510 | 511 | int h = width; 512 | switch (mValuePosition) { 513 | case Center: 514 | // Do nothing, try to have same height as width 515 | break; 516 | case Bottom: 517 | case Top: 518 | if(mShowValue) 519 | h += (int) mTextHeight; 520 | break; 521 | case Right: 522 | case Left: 523 | if(mShowValue) { 524 | int rw = width - (int) mTextWidth; 525 | // real width of Seekbar 526 | h = Math.max((Math.max(rw, 0)), (int) mTextHeight); 527 | // biggest of Seekbar width or text height 528 | }else 529 | h = width; 530 | break; 531 | } 532 | if(h>maxHeight) 533 | h = maxHeight; 534 | return h; 535 | } 536 | 537 | public float getTextOffset(float textSize, float expectedRadius) { 538 | float offset = OPENING_TEXT_MARGIN+0.5f * (textSize) / (float) Math.tan(mSectorHalfOpening / 180.0d * Math.PI); 539 | 540 | final float expectedKnobRadius = mKnobRadius*expectedRadius; 541 | if(mShowKnob && offset < expectedKnobRadius) { 542 | offset = expectedKnobRadius + OPENING_TEXT_MARGIN; 543 | } 544 | 545 | if (offset > expectedRadius) 546 | offset = expectedRadius + OPENING_TEXT_MARGIN; 547 | return offset; 548 | } 549 | 550 | /** 551 | * Get the suggested width of this view given a set height. 552 | * @param height View's height (without padding) 553 | * @param maxWidth 554 | * @return suggested width (without padding) 555 | */ 556 | private int getSuggestedWidth(int height, int maxWidth) { 557 | if(height <= 0 || maxWidth <=0) 558 | return 0; 559 | 560 | int w = height; 561 | switch (mValuePosition) { 562 | case Center: 563 | // Do nothing, try to have same width as height 564 | break; 565 | case Bottom: 566 | case Top: 567 | if(mShowValue) { 568 | int rh = height - (int) mTextHeight; 569 | w = Math.max((rh > 0 ? rh : 0), (int) mTextHeight); 570 | } 571 | break; 572 | case Right: 573 | case Left: 574 | if(mShowValue) { 575 | float offset = getTextOffset(mTextSize, 0.5f*height); 576 | w += (int) (mTextWidth + offset - 0.5f*w); 577 | }else 578 | w *= 0.5f; 579 | break; 580 | } 581 | 582 | if(w>maxWidth) 583 | w = maxWidth; 584 | return w; 585 | } 586 | 587 | @Override 588 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 589 | int widthMode = MeasureSpec.getMode(widthMeasureSpec); 590 | int heightMode = MeasureSpec.getMode(heightMeasureSpec); 591 | 592 | int specWidth = MeasureSpec.getSize(widthMeasureSpec); 593 | int specHeight = MeasureSpec.getSize(heightMeasureSpec); 594 | 595 | int xPad = getPaddingLeft()+getPaddingRight(); 596 | int yPad = getPaddingTop()+getPaddingBottom(); 597 | 598 | int w=0; 599 | int h=0; 600 | 601 | switch(widthMode) { 602 | case MeasureSpec.EXACTLY: 603 | w = specWidth; 604 | switch(heightMode) { 605 | case MeasureSpec.EXACTLY: 606 | h = specHeight; 607 | break; 608 | case MeasureSpec.AT_MOST: 609 | h = getSuggestedHeight(w-xPad, specHeight-yPad)+yPad; 610 | break; 611 | case MeasureSpec.UNSPECIFIED: 612 | h = getSuggestedHeight(w-xPad, Integer.MAX_VALUE-yPad)+yPad; 613 | break; 614 | } 615 | break; 616 | case MeasureSpec.AT_MOST: 617 | switch(heightMode) { 618 | case MeasureSpec.EXACTLY: 619 | h = specHeight; 620 | w = getSuggestedWidth(h - yPad, specWidth - xPad) + xPad; 621 | break; 622 | case MeasureSpec.AT_MOST: 623 | h = dpToPx(DEFAULT_SEEKBAR_DIAMETER) + yPad; 624 | w = getSuggestedWidth(h - yPad, specWidth - xPad) + xPad; 625 | break; 626 | case MeasureSpec.UNSPECIFIED: 627 | w = specWidth; 628 | h = getSuggestedHeight(w-xPad, Integer.MAX_VALUE-yPad)+yPad; 629 | break; 630 | } 631 | break; 632 | case MeasureSpec.UNSPECIFIED: 633 | switch(heightMode) { 634 | case MeasureSpec.EXACTLY: 635 | h = specHeight; 636 | w = getSuggestedWidth(h-yPad, Integer.MAX_VALUE-xPad)+xPad; 637 | break; 638 | case MeasureSpec.AT_MOST: 639 | h = dpToPx(DEFAULT_SEEKBAR_DIAMETER) + yPad; 640 | w = getSuggestedWidth(h-yPad, Integer.MAX_VALUE-xPad)+xPad; 641 | break; 642 | case MeasureSpec.UNSPECIFIED: 643 | h = dpToPx(DEFAULT_SEEKBAR_DIAMETER)+yPad; 644 | w = getSuggestedWidth(h-yPad, Integer.MAX_VALUE-xPad)+xPad; 645 | break; 646 | } 647 | break; 648 | } 649 | 650 | setMeasuredDimension(w, h); 651 | } 652 | 653 | @Override 654 | public boolean onTouchEvent(MotionEvent event) { 655 | boolean result = mDetector.onTouchEvent(event); 656 | if(!result) { 657 | if(event.getAction() == MotionEvent.ACTION_UP) { 658 | getRootView().getOverlay().remove(mOverlay); 659 | 660 | // Make sure we are drawing correctly, once the overlay is removed. 661 | mLayedOutSeekbar.recreatePaths(); 662 | invalidate(); 663 | mbScrolling = false; 664 | 665 | if(!mTrackValue && mStartScrollValue != mValue && mListener!=null) 666 | mListener.onValueChanged(this, mValue); 667 | } 668 | } 669 | return result; 670 | } 671 | 672 | public float getSeekbarRotation() { 673 | return mRotation; 674 | } 675 | 676 | public void addRotationChange(float deltaAlpha) { 677 | mAccumulatedAngleChange += deltaAlpha; 678 | setSeekbarRotation(mRotation+mAccumulatedAngleChange); 679 | } 680 | 681 | public void setSeekbarRotation(float rotation) { 682 | rotation = clampRotation(rotation); 683 | float oldRotation = mRotation; 684 | // make sure we are working with a rotation in [0,360] deg 685 | boolean forbidden = (rotation > (270- mSectorHalfOpening) && rotation < (270+ mSectorHalfOpening)); 686 | if(mRotation <= (270- mSectorHalfOpening) && forbidden) 687 | mRotation = 270- mSectorHalfOpening; 688 | else if(mRotation >= (270+ mSectorHalfOpening) && forbidden) 689 | mRotation = 270+ mSectorHalfOpening; 690 | else 691 | mRotation = rotation; 692 | 693 | float newValue = rotationToValidValue(mRotation); 694 | final float rotDiff = oldRotation-mRotation; 695 | boolean snap = false; 696 | if(oldRotation >= 270 && oldRotation < 360 && mRotation < 270 && mRotation > 180 && mValue != mMinValue) { 697 | if(rotDiff 180 && mRotation > 270 && mRotation < 360 && mValue != mMaxValue) { 703 | if(-rotDiff 270.0f) 738 | sweep += 360.0f; 739 | return sweep; 740 | } 741 | 742 | public float rotationToValidValue(float rotation) { 743 | rotation = clampRotation(rotation); 744 | final float MAX_SWEEP = 360-2* mSectorHalfOpening; 745 | final float sweepAngle = rotationToSweep(rotation); 746 | float sweepRatio = sweepAngle / MAX_SWEEP; 747 | if(sweepRatio > 1.0f) 748 | sweepRatio = 1.0f; 749 | else if (sweepRatio < 0.0f) 750 | sweepRatio = 0.0f; 751 | 752 | return snapValueToSteps((mMaxValue - mMinValue) * sweepRatio + mMinValue); 753 | } 754 | 755 | public boolean showValue() { return mShowValue; } 756 | 757 | public void setShowValue(boolean show) { 758 | mShowValue = show; 759 | invalidate(); 760 | } 761 | 762 | private void calculateOverlayBounds(float aspectRatio) { 763 | //Log.d("calculateOverlayBounds", getResources().getResourceName(getId())); 764 | Rect visibleRect = new Rect(); 765 | getGlobalVisibleRect(visibleRect);//, globalOffset); 766 | //Log.d("calculateOverlayBounds", "getGlobalVisibleRect("+visibleRect.left+", "+visibleRect.top+")"); 767 | 768 | View root = getRootView(); 769 | int rootWidth = root.getWidth(); 770 | int rootHeight = root.getHeight(); 771 | 772 | int centerX = visibleRect.centerX() + (getPaddingLeft()-getPaddingRight()); 773 | int centerY = visibleRect.centerY() + (getPaddingTop()-getPaddingBottom()); 774 | //Log.d("calculateOverlayBounds", "center: ("+centerX+", "+centerY+")"); 775 | 776 | int overlayHeight = dpToPx((int)mOverlaySizeDP); 777 | int overlayWidth = (int)(overlayHeight*aspectRatio); 778 | // TODO: make sure overlay size is not larger than screen: 779 | //Log.d("calculateOverlayBounds", "overlayWidth, overlayHeight: "+overlayWidth+",\t"+overlayHeight); 780 | 781 | mOverlayGlobalBounds.left = mOverlayGlobalBounds.top = 0; // to avoid bugs below. 782 | mOverlayGlobalBounds.right = overlayWidth; 783 | mOverlayGlobalBounds.bottom = overlayHeight; 784 | 785 | int posX, posY; 786 | if(centerX < (overlayWidth/2+mOverlayBorderMargin)) 787 | posX = (int)mOverlayBorderMargin; // at left edge 788 | else if(centerX > (rootWidth-overlayWidth/2-mOverlayBorderMargin)) 789 | posX = rootWidth-overlayWidth-(int)mOverlayBorderMargin; // push in from right 790 | else 791 | posX = centerX-overlayWidth/2; 792 | 793 | if(centerY < (overlayHeight/2+mOverlayBorderMargin)) 794 | posY = (int)mOverlayBorderMargin; // at top edge 795 | else if(centerY > (rootHeight-overlayHeight/2-mOverlayBorderMargin)) 796 | posY = rootHeight-overlayHeight-(int)mOverlayBorderMargin; // push in from bottom 797 | else 798 | posY = centerY-overlayHeight/2; 799 | 800 | //Log.d("calculateOverlayBounds", "overlay pos("+posX+", "+posY+")\n"); 801 | mOverlayGlobalBounds.offsetTo(posX, posY); 802 | } 803 | 804 | public int dpToPx(int dp) { 805 | DisplayMetrics displayMetrics = getContext().getResources().getDisplayMetrics(); 806 | return Math.round(dp * displayMetrics.density+0.5f); 807 | } 808 | 809 | public int spToPx(int sp) { 810 | DisplayMetrics displayMetrics = getContext().getResources().getDisplayMetrics(); 811 | return Math.round(sp * displayMetrics.scaledDensity); 812 | } 813 | 814 | class RotarySeekbarDrawable extends Drawable { 815 | 816 | public RotarySeekbarDrawable() 817 | { 818 | super(); 819 | } 820 | 821 | @Override 822 | public void draw(Canvas canvas) { 823 | Rect bounds = getBounds(); 824 | canvas.translate(bounds.left, bounds.top); 825 | int padding = dpToPx(OVERLAY_PADDING_DP); 826 | canvas.translate(padding, padding); // a little padding. 827 | mOverlaySeekbar.draw(canvas); 828 | } 829 | 830 | @Override 831 | public void setAlpha(int alpha) {} 832 | 833 | @Override 834 | public void setColorFilter(ColorFilter cf) {} 835 | 836 | @Override 837 | public int getOpacity() { 838 | return PixelFormat.TRANSLUCENT; 839 | } 840 | } 841 | 842 | class mGestureListener extends GestureDetector.SimpleOnGestureListener { 843 | 844 | @Override 845 | public boolean onDown(MotionEvent e) { 846 | mbScrolling = true; 847 | mStartScrollValue = mValue; 848 | mAccumulatedAngleChange = 0.0f; 849 | invalidate(); // force redraw, where we don't draw the layed out View (this) 850 | getRootView().getOverlay().add(mOverlay); 851 | return true; // must return true for onScroll to be called (!) 852 | } 853 | 854 | @Override 855 | public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { 856 | Rect visibleRect = new Rect(); 857 | getGlobalVisibleRect(visibleRect); 858 | 859 | final float cX = mOverlayGlobalBounds.left + dpToPx(OVERLAY_PADDING_DP) + mOverlaySeekbar.center().x; 860 | final float cY = mOverlayGlobalBounds.top + dpToPx(OVERLAY_PADDING_DP) + mOverlaySeekbar.center().y; 861 | float vx = (e2.getX()+visibleRect.left) - cX; 862 | float vy = -((e2.getY()+visibleRect.top) - cY); 863 | // invert y-coordinates so that up on the screen is positive y (wrt. the overlay center). 864 | float vxPrev = vx+distanceX; 865 | float vyPrev = vy-distanceY; 866 | 867 | float deltaAlpha = (float)Math.atan2(vy, vx)-(float)Math.atan2(vyPrev, vxPrev); 868 | // Correct for -PI to PI jumps (and v.v.) in deltaAlpha: 869 | if(deltaAlpha > Math.PI) 870 | deltaAlpha-=2*Math.PI; 871 | else if(deltaAlpha < -Math.PI) 872 | deltaAlpha+=2*Math.PI; 873 | 874 | final float vLen = (float)Math.sqrt(vx*vx+vy*vy); 875 | addRotationChange(deltaAlpha/(float)Math.PI*180.0f * (vLen/dpToPx(SCROLL_ANGULAR_SCALE_DP))); 876 | //Scale angle with length from center, do give user control. 877 | // TODO: implement inverse option as selectable attribute. 878 | return true; 879 | } 880 | } 881 | 882 | /** 883 | * Helper method for translating (x,y) scroll vectors into scalar rotation of the pie. 884 | * 885 | * @param dx The x component of the current scroll vector. 886 | * @param dy The y component of the current scroll vector. 887 | * @param x The x position of the current touch, relative to the center. 888 | * @param y The y position of the current touch, relative to the center. 889 | * @return The scalar representing the change in angular position for this scroll. 890 | */ 891 | private static float vectorToScalarScroll(float dx, float dy, float x, float y) { 892 | // get the length of the vector 893 | float l = (float) Math.sqrt(dx * dx + dy * dy); 894 | 895 | // decide if the scalar should be negative or positive by finding 896 | // the dot product of the vector perpendicular to (x,y). 897 | float crossX = -y; 898 | float crossY = x; 899 | 900 | float dot = (crossX * dx + crossY * dy); 901 | float sign = Math.signum(dot); 902 | 903 | return l * sign; 904 | } 905 | 906 | public String getUnitStr() { return (mUnitStr == null ? "" : mUnitStr); } 907 | 908 | private Paint getTextPaint(float scaling) { 909 | Paint textPaint = new Paint(Paint.ANTI_ALIAS_FLAG); 910 | textPaint.setColor(mTextColor); 911 | // TODO: Fix font size for overlays 912 | if(mTextSize <= 0) 913 | mTextSize = spToPx(10); 914 | textPaint.setTextSize(mTextSize*scaling); 915 | return textPaint; 916 | } 917 | 918 | private int getTextWidth(Paint textPaint) { 919 | Rect textBounds = new Rect(); 920 | String minString = formatValueString(mMinValue); 921 | String maxString = formatValueString(mMaxValue); 922 | textPaint.getTextBounds(minString, 0, minString.length(), textBounds); 923 | int minStringWidth = textBounds.width(); 924 | textPaint.getTextBounds(maxString, 0, maxString.length(), textBounds); 925 | int maxStringWidth = textBounds.width(); 926 | return Math.max(minStringWidth, maxStringWidth); 927 | } 928 | 929 | private class RotarySeekbarImpl { 930 | private Path mSectorPath; 931 | private Path mValuePath; 932 | private float mRadius; 933 | private RectF mBounds; 934 | private PointF mSeekbarCenter; 935 | 936 | private Paint mTextPaint; 937 | private Paint mNeedlePaint; 938 | private Paint mTicksPaint; 939 | 940 | private float mTextX = 0.0f; 941 | private float mTextY = 0.0f; 942 | private float mScaling; 943 | 944 | private float mTextWidth; 945 | private float mTextHeight; 946 | 947 | public RotarySeekbarImpl( RectF bounds) { 948 | this(bounds, 1.0f); 949 | } 950 | 951 | public RotarySeekbarImpl (RectF bounds, float scaling) { 952 | mBounds = bounds; 953 | mScaling = scaling; 954 | 955 | mTextPaint = getTextPaint(mScaling); 956 | mTextHeight = mTextPaint.getTextSize(); 957 | mTextWidth = getTextWidth(mTextPaint); 958 | 959 | mNeedlePaint = new Paint(Paint.ANTI_ALIAS_FLAG); 960 | mNeedlePaint.setStyle(Paint.Style.STROKE); 961 | mNeedlePaint.setStrokeCap(Paint.Cap.ROUND); 962 | mNeedlePaint.setColor(mNeedleColor); 963 | mNeedlePaint.setStrokeWidth(mNeedleWidth*mScaling); 964 | 965 | mTicksPaint = new Paint(Paint.ANTI_ALIAS_FLAG); 966 | mTicksPaint.setStyle(Paint.Style.STROKE); 967 | mTicksPaint.setColor(mTicksColor); 968 | mTicksPaint.setStrokeWidth(mTicksWidth*mScaling); 969 | 970 | float dW = bounds.width(); 971 | float dH = bounds.height(); 972 | float cX = bounds.centerX(); 973 | float cY = bounds.centerY(); 974 | 975 | float d = Math.min(dW, dH); 976 | float offset = 0.0f; 977 | 978 | if(mShowValue) { 979 | switch (mValuePosition) { 980 | case Center: 981 | mTextPaint.setTextAlign(Paint.Align.CENTER); 982 | mTextX = cX; 983 | mTextY = cY - .5f*(mTextPaint.getFontMetrics().descent+mTextPaint.getFontMetrics().ascent); 984 | break; 985 | case Bottom: 986 | mTextPaint.setTextAlign(Paint.Align.CENTER); 987 | dH -= mTextHeight; 988 | d = Math.min(dW, dH); 989 | cY -= 0.5f * mTextHeight; 990 | mTextX = cX; 991 | mTextY = cY + 0.5f * d - (mTextPaint.getFontMetrics().descent+mTextPaint.getFontMetrics().ascent); 992 | break; 993 | case Top: 994 | mTextPaint.setTextAlign(Paint.Align.CENTER); 995 | dH -= mTextHeight; 996 | d = Math.min(dW, dH); 997 | cY += 0.5f * mTextHeight; 998 | mTextX = cX; 999 | mTextY = cY - 0.5f * d - mTextPaint.getFontMetrics().descent; 1000 | //descent is negative 1001 | break; 1002 | case Right: 1003 | mTextPaint.setTextAlign(Paint.Align.LEFT); 1004 | d = dH; 1005 | offset = getTextOffset(mTextHeight, 0.5f*d); // TODO, fix positioning of Seekbar! 1006 | cX -= 0.5f * (mTextWidth + offset - 0.5f * d); 1007 | mTextX = cX + offset; 1008 | mTextY = cY - .5f*(mTextPaint.getFontMetrics().descent+mTextPaint.getFontMetrics().ascent); 1009 | break; 1010 | case Left: 1011 | mTextPaint.setTextAlign(Paint.Align.RIGHT); 1012 | d = dH; 1013 | offset = getTextOffset(mTextHeight, 0.5f*d); 1014 | cX += 0.5f * (mTextWidth + offset - 0.5f * d); 1015 | mTextX = cX - offset; 1016 | mTextY = cY - .5f*(mTextPaint.getFontMetrics().descent+mTextPaint.getFontMetrics().ascent); 1017 | break; 1018 | } 1019 | } 1020 | 1021 | mRadius = 0.5f*d; 1022 | mSeekbarCenter = new PointF(cX, cY); 1023 | recreatePaths(); 1024 | } 1025 | 1026 | public PointF center() { return mSeekbarCenter; } 1027 | public float getRadius() { return mRadius; } 1028 | public float getTextSize() { return mTextPaint.getTextSize(); } 1029 | public RectF getBounds() { return mBounds; } 1030 | 1031 | public void draw(Canvas canvas) { 1032 | 1033 | float rot = 0.0f; 1034 | switch(mValuePosition) { 1035 | case Top: 1036 | rot = 180.0f; 1037 | break; 1038 | case Right: 1039 | rot = -90.0f; 1040 | break; 1041 | case Left: 1042 | rot = 90.0f; 1043 | break; 1044 | } 1045 | if(mSectorRotation != 0) 1046 | rot += mSectorRotation; 1047 | canvas.rotate(rot, mSeekbarCenter.x, mSeekbarCenter.y); 1048 | 1049 | if(mShowSector) { 1050 | canvas.drawPath(mSectorPath, mSectorPaint); 1051 | canvas.drawPath(mValuePath, mValueSectorPaint); 1052 | } 1053 | 1054 | if(mShowTicks && mNumTicks > 0) { 1055 | float tickAngle = (270- mSectorHalfOpening)*(float)Math.PI/180.0f; 1056 | float tickAngleIncrement = (float)Math.PI/180.0f*(360-2* mSectorHalfOpening)/(mNumTicks-1); 1057 | for(int i=0; i 0.01f; 1071 | if(mNeedleOnTop && drawKnob) 1072 | canvas.drawCircle(mSeekbarCenter.x, mSeekbarCenter.y, mRadius * mKnobRadius, mKnobPaint); 1073 | 1074 | if(mShowNeedle) { 1075 | final float needleAngle = mRotation * (float) Math.PI / 180.f; // convert to radians 1076 | final float cosNA = (float)Math.cos(needleAngle); 1077 | final float sinNA = (float)Math.sin(needleAngle); 1078 | canvas.drawLine( 1079 | mSeekbarCenter.x + mRadius * mNeedleMinorRadius * cosNA, 1080 | mSeekbarCenter.y - mRadius * mNeedleMinorRadius * sinNA, 1081 | mSeekbarCenter.x + mRadius * mNeedleMajorRadius * cosNA, 1082 | mSeekbarCenter.y - mRadius * mNeedleMajorRadius * sinNA, 1083 | mNeedlePaint 1084 | ); 1085 | } 1086 | 1087 | if(!mNeedleOnTop && drawKnob) 1088 | canvas.drawCircle(mSeekbarCenter.x, mSeekbarCenter.y, mRadius * mKnobRadius, mKnobPaint); 1089 | 1090 | canvas.rotate(-rot, mSeekbarCenter.x, mSeekbarCenter.y); 1091 | if(mShowValue) 1092 | canvas.drawText(mValueStr, mTextX, mTextY, mTextPaint); 1093 | } 1094 | 1095 | private Path createSectorPath(float sweepAngle) { 1096 | float startAngle = 90+mSectorHalfOpening; 1097 | 1098 | Path path = new Path(); 1099 | if(sweepAngle == 360) { 1100 | path.addOval(circleBounds(mSectorMajRadiusScale), Path.Direction.CCW); 1101 | path.addOval(circleBounds(mSectorMinRadiusScale), Path.Direction.CW); 1102 | }else { 1103 | path.arcTo(circleBounds(mSectorMinRadiusScale), startAngle, sweepAngle); 1104 | path.arcTo(circleBounds(mSectorMajRadiusScale), startAngle + sweepAngle, -sweepAngle); 1105 | path.close(); 1106 | } 1107 | 1108 | if(mSubtractTicks && mNumTicks > 0) { 1109 | Path tickPath = new Path(); 1110 | tickPath.addRect( 1111 | 0.0f, -0.5f*mTicksSubtractWidth*mScaling/mRadius, 1112 | 1.0f, 0.5f*mTicksSubtractWidth*mScaling/mRadius, 1113 | Path.Direction.CCW); 1114 | float tickAngle = (270- mSectorHalfOpening); 1115 | float tickAngleIncrement = (360-2*mSectorHalfOpening)/(mNumTicks-1); 1116 | Matrix tickMatrix = new Matrix(); 1117 | tickMatrix.postRotate(-tickAngle); 1118 | Path rotatedTick = new Path(); 1119 | for(int i=0; i