├── .gitignore
├── LICENSE
├── README.md
├── build.gradle
├── example
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── goodiebag
│ │ └── protractorview
│ │ └── example
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── goodiebag
│ │ │ └── protractorview
│ │ │ └── example
│ │ │ └── MainActivity.java
│ └── res
│ │ ├── layout
│ │ └── activity_main.xml
│ │ ├── mipmap-hdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxxhdpi
│ │ └── ic_launcher.png
│ │ ├── values-w820dp
│ │ └── dimens.xml
│ │ └── values
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── goodiebag
│ └── protractorview
│ └── example
│ └── ExampleUnitTest.java
├── gif
├── PVcolors.gif
└── PVgreen.gif
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── protractorview
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── goodiebag
│ │ └── protractorview
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── goodiebag
│ │ │ └── protractorview
│ │ │ └── ProtractorView.java
│ └── res
│ │ ├── drawable
│ │ ├── thumb_disabled.xml
│ │ ├── thumb_focused.xml
│ │ ├── thumb_normal.xml
│ │ ├── thumb_pressed.xml
│ │ └── thumb_selector.xml
│ │ └── values
│ │ ├── attrs.xml
│ │ ├── colors.xml
│ │ └── strings.xml
│ └── test
│ └── java
│ └── com
│ └── goodiebag
│ └── protractorview
│ └── ExampleUnitTest.java
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 | # Files for the ART/Dalvik VM
5 | *.dex
6 | # Java class files
7 | *.class
8 | # Generated files
9 | bin/
10 | gen/
11 | out/
12 | # Gradle files
13 | .gradle/
14 | build/
15 | # Local configuration file (sdk path, etc)
16 | local.properties
17 | # Proguard folder generated by Eclipse
18 | proguard/
19 | # Log Files
20 | *.log
21 | # Android Studio Navigation editor temp files
22 | .navigation/
23 | # Android Studio captures folder
24 | captures/
25 | # Intellij
26 | *.iml
27 | .idea
28 | # Keystore files
29 | *.jks
30 | # External native build folder generated in Android Studio 2.2 and later
31 | .externalNativeBuild
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2017 GoodieBag
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # ProtractorView
2 |
3 | [](https://android-arsenal.com/details/1/5421)
4 | [](https://jitpack.io/#GoodieBag/ProtractorView)
5 | [](https://android-arsenal.com/api?level=15)
6 |
7 | ProtractorView library for android :pouting_cat:
8 |
9 | A semicircular seekbar view for selecting an angle from 0° to 180.
10 |
11 |  
12 |
13 | ## Gradle Dependency
14 |
15 | Add this in your root build.gradle file at the end of repositories:
16 | ```java
17 | allprojects {
18 | repositories {
19 | ...
20 | maven { url 'https://jitpack.io' }
21 | }
22 | }
23 | ```
24 | Add the dependency :
25 | ```java
26 | dependencies {
27 | compile 'com.github.GoodieBag:ProtractorView:v1.2'
28 | }
29 | ```
30 | Sync the gradle and that's it! :+1:
31 |
32 | ## Features :
33 | * A semi-circular seekbar widget for selecting an angle from 0° to 180°.
34 | * Complete customisation facilities for changing the colors of the text, tick, progress bar and thumb.
35 | * A special highlighting mechanism has been implemented. As the thumb passes through the angles (ticks / text), it can change the tick/text colors marking them as "traversed" to give the user a visual hint.
36 | * The tick length and the interval between ticks and text can also be customised.
37 |
38 | ## Usage :
39 |
40 | ### XML :
41 | ```xml
42 |
62 | ```
63 |
64 | ### Java :
65 | To create the view programatically, you can do the following :
66 | ```java
67 | ProtractorView protractorView = new ProtractorView(this);
68 | //This can then be added to its parent layout
69 | layout.addView(protractorView);
70 | ```
71 | Or you can reference it from your XML :
72 | ```java
73 | ProtractorView protractorView = (ProtractorView) findViewById(R.id.protractorview);
74 |
75 | //use setters to style it. Every xml attribute mentioned above has a setter to support programmatical creation of the views
76 | protractorView.setTickIntervals(15);
77 | protractorView.setArcColor(getColor(R.color.colorAccent));
78 | protractorView.setProgressColor(getColor(R.color.myColor));
79 | .
80 | .
81 | .
82 | //so on
83 | ```
84 | There is an event listener which can be set up as follows :
85 | ```java
86 | protractorView.setOnProtractorViewChangeListener(new ProtractorView.OnProtractorViewChangeListener() {
87 | @Override
88 | public void onProgressChanged(ProtractorView pv, int progress, boolean b) {
89 | //protractorView's getters can be accessed using pv instance.
90 | }
91 |
92 | @Override
93 | public void onStartTrackingTouch(ProtractorView pv) {
94 |
95 | }
96 |
97 | @Override
98 | public void onStopTrackingTouch(ProtractorView pv) {
99 |
100 | }
101 | });
102 | ```
103 | ### Thanks to :
104 | Shoutout to [SeekArc](https://github.com/neild001/SeekArc).
105 | Thanks to SeekArc by [neild001](https://github.com/neild001) we were able to understand the drawing mechanism of the circular seekbar, which then helped us draw the semi-circular one.
106 |
107 |
108 | ## LICENSE
109 | ```
110 | MIT License
111 |
112 | Copyright (c) 2017 GoodieBag
113 |
114 | Permission is hereby granted, free of charge, to any person obtaining a copy
115 | of this software and associated documentation files (the "Software"), to deal
116 | in the Software without restriction, including without limitation the rights
117 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
118 | copies of the Software, and to permit persons to whom the Software is
119 | furnished to do so, subject to the following conditions:
120 |
121 | The above copyright notice and this permission notice shall be included in all
122 | copies or substantial portions of the Software.
123 |
124 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
125 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
126 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
127 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
128 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
129 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
130 | SOFTWARE.
131 | ```
132 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.2.3'
9 |
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | jcenter()
18 | }
19 | }
20 |
21 | task clean(type: Delete) {
22 | delete rootProject.buildDir
23 | }
24 |
--------------------------------------------------------------------------------
/example/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/example/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion "25.0.2"
6 | defaultConfig {
7 | applicationId "com.goodiebag.protractorview.example"
8 | minSdkVersion 15
9 | targetSdkVersion 25
10 | versionCode 1
11 | versionName "1.0"
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(include: ['*.jar'], dir: 'libs')
24 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
25 | exclude group: 'com.android.support', module: 'support-annotations'
26 | })
27 | compile 'com.android.support:appcompat-v7:25.1.0'
28 | testCompile 'junit:junit:4.12'
29 | compile project(':protractorview')
30 | }
31 |
--------------------------------------------------------------------------------
/example/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/krishanudey/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/example/src/androidTest/java/com/goodiebag/protractorview/example/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.goodiebag.protractorview.example;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.goodiebag.protractorview.example", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/example/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/example/src/main/java/com/goodiebag/protractorview/example/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.goodiebag.protractorview.example;
2 |
3 | import android.support.v7.app.AppCompatActivity;
4 | import android.os.Bundle;
5 |
6 | public class MainActivity extends AppCompatActivity {
7 |
8 | @Override
9 | protected void onCreate(Bundle savedInstanceState) {
10 | super.onCreate(savedInstanceState);
11 | setContentView(R.layout.activity_main);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/example/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
13 |
14 |
19 |
20 |
--------------------------------------------------------------------------------
/example/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GoodieBag/ProtractorView/5a6d51dc7aaa1af85967c4680883f65f65743349/example/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GoodieBag/ProtractorView/5a6d51dc7aaa1af85967c4680883f65f65743349/example/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GoodieBag/ProtractorView/5a6d51dc7aaa1af85967c4680883f65f65743349/example/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GoodieBag/ProtractorView/5a6d51dc7aaa1af85967c4680883f65f65743349/example/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GoodieBag/ProtractorView/5a6d51dc7aaa1af85967c4680883f65f65743349/example/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/example/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/example/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/example/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | ProtractorView
3 |
4 |
--------------------------------------------------------------------------------
/example/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/example/src/test/java/com/goodiebag/protractorview/example/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.goodiebag.protractorview.example;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/gif/PVcolors.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GoodieBag/ProtractorView/5a6d51dc7aaa1af85967c4680883f65f65743349/gif/PVcolors.gif
--------------------------------------------------------------------------------
/gif/PVgreen.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GoodieBag/ProtractorView/5a6d51dc7aaa1af85967c4680883f65f65743349/gif/PVgreen.gif
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GoodieBag/ProtractorView/5a6d51dc7aaa1af85967c4680883f65f65743349/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 28 10:00:20 PST 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/protractorview/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/protractorview/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion "25.0.2"
6 |
7 | defaultConfig {
8 | minSdkVersion 15
9 | targetSdkVersion 25
10 | versionCode 3
11 | versionName "1.2"
12 |
13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
14 |
15 | }
16 | buildTypes {
17 | release {
18 | minifyEnabled false
19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
20 | }
21 | }
22 | }
23 |
24 | dependencies {
25 | compile fileTree(dir: 'libs', include: ['*.jar'])
26 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
27 | exclude group: 'com.android.support', module: 'support-annotations'
28 | })
29 | compile 'com.android.support:appcompat-v7:25.1.0'
30 | testCompile 'junit:junit:4.12'
31 | }
32 |
--------------------------------------------------------------------------------
/protractorview/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/krishanudey/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/protractorview/src/androidTest/java/com/goodiebag/protractorview/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.goodiebag.protractorview;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.goodiebag.protractorview.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/protractorview/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/protractorview/src/main/java/com/goodiebag/protractorview/ProtractorView.java:
--------------------------------------------------------------------------------
1 | /*
2 | MIT License
3 | Copyright (c) 2017 GoodieBag
4 | Permission is hereby granted, free of charge, to any person obtaining a copy
5 | of this software and associated documentation files (the "Software"), to deal
6 | in the Software without restriction, including without limitation the rights
7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | copies of the Software, and to permit persons to whom the Software is
9 | furnished to do so, subject to the following conditions:
10 | The above copyright notice and this permission notice shall be included in all
11 | copies or substantial portions of the Software.
12 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
18 | SOFTWARE.
19 | */
20 |
21 | package com.goodiebag.protractorview;
22 |
23 | import android.content.Context;
24 | import android.content.res.Resources;
25 | import android.content.res.TypedArray;
26 | import android.graphics.Canvas;
27 | import android.graphics.Paint;
28 | import android.graphics.RectF;
29 | import android.graphics.drawable.Drawable;
30 | import android.support.annotation.ColorInt;
31 | import android.util.AttributeSet;
32 | import android.view.MotionEvent;
33 | import android.view.View;
34 |
35 | /**
36 | * This class implements a widget for android which is a semi-circular seekbar drawn like a protractor with ticks.
37 | * Tick angles can be defined, angle value can be drawn at a desired interval of angles.
38 | * Ticks are highlighted as the seekbar passes through the respective tick's angle.
39 | * Date : 10/01/17.
40 | *
41 | * @author Krishanu
42 | * @author Pavan
43 | * @author Koushik
44 | */
45 |
46 | public class ProtractorView extends View {
47 |
48 | private static final int MAX = 180;
49 | private final float DENSITY = getContext().getResources().getDisplayMetrics().density;
50 |
51 | /**
52 | * Private variables
53 | */
54 | //Rectangle for the arc
55 | private RectF mArcRect = new RectF();
56 |
57 | //Paints required for drawing
58 | private Paint mArcPaint;
59 | private Paint mArcProgressPaint;
60 | private Paint mTickPaint;
61 | private Paint mTickProgressPaint;
62 | private Paint mTickTextPaint;
63 | private Paint mTickTextColoredPaint;
64 |
65 | //Arc related dimens
66 | private int mArcRadius = 0;
67 | private int mArcWidth = 2;
68 | private int mArcProgressWidth = 2;
69 | private boolean mRoundedEdges = true;
70 |
71 | //Thumb Drawable
72 | private Drawable mThumb;
73 |
74 | //Thumb position related coordinates
75 | private int mTranslateX;
76 | private int mTranslateY;
77 | private int mThumbXPos;
78 | private int mThumbYPos;
79 |
80 | private int mAngleTextSize = 12;
81 |
82 | private int mTickOffset = 12;
83 | private int mTickLength = 10;
84 | private int mTickWidth = 2;
85 | private int mTickProgressWidth = 2;
86 | private int mAngle = 0;
87 | private boolean mTouchInside = true;
88 | private boolean mEnabled = true;
89 | private TicksBetweenLabel mTicksBetweenLabel = TicksBetweenLabel.TWO;
90 | private int mTickIntervals = 15;
91 | private double mTouchAngle = 0;
92 | private float mTouchIgnoreRadius;
93 |
94 | //Event listener
95 | private OnProtractorViewChangeListener mOnProtractorViewChangeListener = null;
96 |
97 |
98 | //Interface for event listener
99 | public interface OnProtractorViewChangeListener {
100 | void onProgressChanged(ProtractorView protractorView, int progress, boolean fromUser);
101 |
102 | void onStartTrackingTouch(ProtractorView protractorView);
103 |
104 | void onStopTrackingTouch(ProtractorView protractorView);
105 | }
106 |
107 | public enum TicksBetweenLabel {
108 | ZERO, ONE, TWO, THREE
109 | }
110 |
111 | public ProtractorView(Context context) {
112 | super(context);
113 | init(context, null, 0);
114 | }
115 |
116 | public ProtractorView(Context context, AttributeSet attrs) {
117 | super(context, attrs);
118 | init(context, attrs, R.attr.protractorViewStyle);
119 | }
120 |
121 | public ProtractorView(Context context, AttributeSet attrs, int defStyleAttr) {
122 | super(context, attrs, defStyleAttr);
123 | init(context, attrs, defStyleAttr);
124 | }
125 |
126 | /**
127 | * A method to initialise the attributes from the XML.
128 | * If not specified in the xml the default values are taken.
129 | *
130 | * @param context
131 | * @param attrs
132 | * @param defStyle
133 | */
134 | private void init(Context context, AttributeSet attrs, int defStyle) {
135 |
136 | final Resources res = getResources();
137 |
138 | /**
139 | * Defaults, may need to link this into theme settings
140 | */
141 | int arcColor = res.getColor(R.color.progress_gray);
142 | int arcProgressColor = res.getColor(R.color.default_blue_light);
143 | int textColor = res.getColor(R.color.progress_gray);
144 | int textProgressColor = res.getColor(R.color.default_blue_light);
145 | int tickColor = res.getColor(R.color.progress_gray);
146 | int tickProgressColor = res.getColor(R.color.default_blue_light);
147 | int thumbHalfHeight = 0;
148 | int thumbHalfWidth = 0;
149 |
150 | mThumb = res.getDrawable(R.drawable.thumb_selector);
151 |
152 | /**
153 | * Convert all default dimens to pixels for current density
154 | */
155 | mArcWidth = (int) (mArcWidth * DENSITY);
156 | mArcProgressWidth = (int) (mArcProgressWidth * DENSITY);
157 | mAngleTextSize = (int) (mAngleTextSize * DENSITY);
158 | mTickOffset = (int) (mTickOffset * DENSITY);
159 | mTickLength = (int) (mTickLength * DENSITY);
160 | mTickWidth = (int) (mTickWidth * DENSITY);
161 | mTickProgressWidth = (int) (mTickProgressWidth * DENSITY);
162 |
163 | if (attrs != null) {
164 | final TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.ProtractorView, defStyle, 0);
165 | Drawable thumb = array.getDrawable(R.styleable.ProtractorView_thumb);
166 | if (thumb != null) {
167 | mThumb = thumb;
168 | }
169 | thumbHalfHeight = mThumb.getIntrinsicHeight() / 2;
170 | thumbHalfWidth = mThumb.getIntrinsicWidth() / 2;
171 | mThumb.setBounds(-thumbHalfWidth, -thumbHalfHeight, thumbHalfWidth, thumbHalfHeight);
172 | //Dimensions
173 | mAngleTextSize = (int) array.getDimension(R.styleable.ProtractorView_angleTextSize, mAngleTextSize);
174 | mArcProgressWidth = (int) array.getDimension(R.styleable.ProtractorView_progressWidth, mArcProgressWidth);
175 | mTickOffset = (int) array.getDimension(R.styleable.ProtractorView_tickOffset, mTickOffset);
176 | mTickLength = (int) array.getDimension(R.styleable.ProtractorView_tickLength, mTickLength);
177 | mArcWidth = (int) array.getDimension(R.styleable.ProtractorView_arcWidth, mArcWidth);
178 | //Integers
179 | mAngle = array.getInteger(R.styleable.ProtractorView_angle, mAngle);
180 | mTickIntervals = array.getInt(R.styleable.ProtractorView_tickIntervals, mTickIntervals);
181 | //Colors
182 | arcColor = array.getColor(R.styleable.ProtractorView_arcColor, arcColor);
183 | arcProgressColor = array.getColor(R.styleable.ProtractorView_arcProgressColor, arcProgressColor);
184 | textColor = array.getColor(R.styleable.ProtractorView_textColor, textColor);
185 | textProgressColor = array.getColor(R.styleable.ProtractorView_textProgressColor, textProgressColor);
186 | tickColor = array.getColor(R.styleable.ProtractorView_tickColor, tickColor);
187 | tickProgressColor = array.getColor(R.styleable.ProtractorView_tickProgressColor, tickProgressColor);
188 | //Boolean
189 | mRoundedEdges = array.getBoolean(R.styleable.ProtractorView_roundEdges, mRoundedEdges);
190 | mEnabled = array.getBoolean(R.styleable.ProtractorView_enabled, mEnabled);
191 | mTouchInside = array.getBoolean(R.styleable.ProtractorView_touchInside, mTouchInside);
192 | int ordinal = array.getInt(R.styleable.ProtractorView_ticksBetweenLabel, mTicksBetweenLabel.ordinal());
193 | mTicksBetweenLabel = TicksBetweenLabel.values()[ordinal];
194 |
195 | }
196 | /**
197 | * Creating and configuring the paints as required.
198 | */
199 | mAngle = (mAngle > MAX) ? MAX : ((mAngle < 0) ? 0 : mAngle);
200 |
201 | mArcPaint = new Paint();
202 | mArcPaint.setColor(arcColor);
203 | mArcPaint.setAntiAlias(true);
204 | mArcPaint.setStyle(Paint.Style.STROKE);
205 | mArcPaint.setStrokeWidth(mArcWidth);
206 |
207 | mArcProgressPaint = new Paint();
208 | mArcProgressPaint.setColor(arcProgressColor);
209 | mArcProgressPaint.setAntiAlias(true);
210 | mArcProgressPaint.setStyle(Paint.Style.STROKE);
211 | mArcProgressPaint.setStrokeWidth(mArcProgressWidth);
212 |
213 | if (mRoundedEdges) {
214 | mArcPaint.setStrokeCap(Paint.Cap.ROUND);
215 | mArcProgressPaint.setStrokeCap(Paint.Cap.ROUND);
216 | }
217 |
218 | mTickPaint = new Paint();
219 | mTickPaint.setColor(tickColor);
220 | mTickPaint.setAntiAlias(true);
221 | mTickPaint.setStyle(Paint.Style.STROKE);
222 | mTickPaint.setStrokeWidth(mTickWidth);
223 |
224 |
225 | mTickProgressPaint = new Paint();
226 | mTickProgressPaint.setColor(tickProgressColor);
227 | mTickProgressPaint.setAntiAlias(true);
228 | mTickProgressPaint.setStyle(Paint.Style.STROKE);
229 | mTickProgressPaint.setStrokeWidth(mTickProgressWidth);
230 |
231 | mTickTextPaint = new Paint();
232 | mTickTextPaint.setColor(textColor);
233 | mTickTextPaint.setAntiAlias(true);
234 | mTickTextPaint.setStyle(Paint.Style.FILL);
235 | mTickTextPaint.setTextSize(mAngleTextSize);
236 | mTickTextPaint.setTextAlign(Paint.Align.CENTER);
237 |
238 | mTickTextColoredPaint = new Paint();
239 | mTickTextColoredPaint.setColor(textProgressColor);
240 | mTickTextColoredPaint.setAntiAlias(true);
241 | mTickTextColoredPaint.setStyle(Paint.Style.FILL);
242 | mTickTextColoredPaint.setTextSize(mAngleTextSize);
243 | mTickTextColoredPaint.setTextAlign(Paint.Align.CENTER);
244 | }
245 |
246 | @Override
247 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
248 |
249 | int height = getDefaultSize(getSuggestedMinimumHeight(),
250 | heightMeasureSpec);
251 | int width = getDefaultSize(getSuggestedMinimumWidth(),
252 | widthMeasureSpec);
253 | int min = Math.min(width, height);
254 | //width = min;
255 | height = min / 2;
256 |
257 |
258 | float top = 0;
259 | float left = 0;
260 | int arcDiameter = 0;
261 |
262 | int tickEndToArc = (mTickOffset + mTickLength);
263 |
264 | arcDiameter = min - 2 * tickEndToArc;
265 | arcDiameter = (int) (arcDiameter - 2 * 20 * DENSITY);
266 | mArcRadius = arcDiameter / 2;
267 |
268 |
269 | top = height - (mArcRadius);
270 | left = width / 2 - mArcRadius;
271 |
272 | mArcRect.set(left, top, left + arcDiameter, top + arcDiameter);
273 |
274 | mTranslateX = (int) mArcRect.centerX();
275 | mTranslateY = (int) mArcRect.centerY();
276 |
277 |
278 | int thumbAngle = mAngle;
279 | mThumbXPos = (int) (mArcRadius * Math.cos(Math.toRadians(thumbAngle)));
280 | mThumbYPos = (int) (mArcRadius * Math.sin(Math.toRadians(thumbAngle)));
281 | setTouchInside(mTouchInside);
282 | setMeasuredDimension(width, height + tickEndToArc);
283 | }
284 |
285 |
286 | @Override
287 | protected void onDraw(Canvas canvas) {
288 | canvas.save();
289 | canvas.scale(1, -1, mArcRect.centerX(), mArcRect.centerY());
290 | canvas.drawArc(mArcRect, 0, MAX, false, mArcPaint);
291 | canvas.drawArc(mArcRect, 0, mAngle, false, mArcProgressPaint);
292 |
293 | canvas.restore();
294 | double slope, startTickX, startTickY, endTickX, endTickY, midTickX, midTickY, thetaInRadians;
295 | double radiusOffset = mArcRadius + mTickOffset;
296 |
297 | //TicksBetweenLabel
298 | /**
299 | * Mechanism to draw the tick and text.
300 | * Tan(theta) gives the slope.
301 | * Formula for a straight line is y = mx + c. y is calculated for varying values of x and the ticks are drawn.
302 | */
303 |
304 | int count = mTicksBetweenLabel.ordinal();
305 | for (int i = 360; i >= 180; i -= mTickIntervals) {
306 | canvas.save();
307 | if (count == mTicksBetweenLabel.ordinal()) {
308 | //for text
309 | canvas.translate(mArcRect.centerX(), mArcRect.centerY());
310 | thetaInRadians = Math.toRadians(i);
311 | slope = Math.tan(thetaInRadians);
312 | startTickX = (radiusOffset * Math.cos(thetaInRadians));
313 | midTickX = startTickX + (((mTickLength / 2)) * Math.cos(thetaInRadians));
314 | midTickY = slope * midTickX;
315 | canvas.drawText("" + (360 - i), (float) midTickX, (float) midTickY, (mAngle <= 359 - i) ? mTickTextPaint : mTickTextColoredPaint);
316 | count = 0;
317 | } else {
318 | //for tick
319 | canvas.scale(-1, 1, mArcRect.centerX(), mArcRect.centerY());
320 | canvas.translate(mArcRect.centerX(), mArcRect.centerY());
321 | canvas.rotate(180);
322 | thetaInRadians = Math.toRadians(360 - i);
323 | slope = Math.tan(thetaInRadians);
324 | startTickX = (radiusOffset * Math.cos(thetaInRadians));
325 | startTickY = slope * startTickX;
326 | endTickX = startTickX + ((mTickLength) * Math.cos(thetaInRadians));
327 | endTickY = slope * endTickX;
328 | canvas.drawLine((float) startTickX, (float) startTickY, (float) endTickX, (float) endTickY, (mAngle <= 359 - i) ? mTickPaint : mTickProgressPaint);
329 | count++;
330 | }
331 | canvas.restore();
332 | }
333 |
334 |
335 | if (mEnabled) {
336 | // Draw the thumb nail
337 | canvas.save();
338 | canvas.scale(-1, 1, mArcRect.centerX(), mArcRect.centerY());
339 | canvas.translate(mTranslateX - mThumbXPos, mTranslateY - mThumbYPos);
340 | mThumb.draw(canvas);
341 | canvas.restore();
342 | }
343 | }
344 |
345 |
346 | @Override
347 | protected void drawableStateChanged() {
348 | super.drawableStateChanged();
349 | if (mThumb != null && mThumb.isStateful()) {
350 | int[] state = getDrawableState();
351 | mThumb.setState(state);
352 | }
353 | invalidate();
354 | }
355 |
356 |
357 | @Override
358 | public boolean onTouchEvent(MotionEvent event) {
359 | if (mEnabled) {
360 | this.getParent().requestDisallowInterceptTouchEvent(true);
361 |
362 | switch (event.getAction()) {
363 | case MotionEvent.ACTION_DOWN:
364 | if (ignoreTouch(event.getX(), event.getY())) {
365 | return false;
366 | }
367 | onStartTrackingTouch();
368 | updateOnTouch(event);
369 | break;
370 | case MotionEvent.ACTION_MOVE:
371 | updateOnTouch(event);
372 | break;
373 | case MotionEvent.ACTION_UP:
374 | onStopTrackingTouch();
375 | setPressed(false);
376 | this.getParent().requestDisallowInterceptTouchEvent(false);
377 | break;
378 | case MotionEvent.ACTION_CANCEL:
379 | onStopTrackingTouch();
380 | setPressed(false);
381 | this.getParent().requestDisallowInterceptTouchEvent(false);
382 | break;
383 | }
384 | return true;
385 | }
386 | return false;
387 | }
388 |
389 | private void onStartTrackingTouch() {
390 | if (mOnProtractorViewChangeListener != null) {
391 | mOnProtractorViewChangeListener.onStartTrackingTouch(this);
392 | }
393 | }
394 |
395 | private void onStopTrackingTouch() {
396 | if (mOnProtractorViewChangeListener != null) {
397 | mOnProtractorViewChangeListener.onStopTrackingTouch(this);
398 | }
399 | }
400 |
401 |
402 | private boolean ignoreTouch(float xPos, float yPos) {
403 | boolean ignore = false;
404 | float x = xPos - mTranslateX;
405 | float y = yPos - mTranslateY;
406 |
407 | float touchRadius = (float) Math.sqrt(((x * x) + (y * y)));
408 | if (touchRadius < mTouchIgnoreRadius || touchRadius > (mArcRadius + mTickLength + mTickOffset)) {
409 | ignore = true;
410 | }
411 | return ignore;
412 | }
413 |
414 | private void updateOnTouch(MotionEvent event) {
415 | boolean ignoreTouch = ignoreTouch(event.getX(), event.getY());
416 | if (ignoreTouch) {
417 | return;
418 | }
419 | setPressed(true);
420 | mTouchAngle = getTouchDegrees(event.getX(), event.getY());
421 | onProgressRefresh((int) mTouchAngle, true);
422 | }
423 |
424 |
425 | private double getTouchDegrees(float xPos, float yPos) {
426 | float x = xPos - mTranslateX;
427 | float y = yPos - mTranslateY;
428 | x = -x;
429 | // convert to arc Angle
430 | double angle = Math.toDegrees(Math.atan2(y, x) + (Math.PI));
431 | if (angle > 270)
432 | angle = 0;
433 | else if (angle > 180)
434 | angle = 180;
435 | return angle;
436 | }
437 |
438 | private void onProgressRefresh(int angle, boolean fromUser) {
439 | updateAngle(angle, fromUser);
440 | }
441 |
442 | private void updateAngle(int angle, boolean fromUser) {
443 | mAngle = (angle > MAX) ? MAX : (angle < 0) ? 0 : angle;
444 |
445 | if (mOnProtractorViewChangeListener != null) {
446 | mOnProtractorViewChangeListener.onProgressChanged(this, mAngle, fromUser);
447 | }
448 | updateThumbPosition();
449 | invalidate();
450 | }
451 |
452 |
453 | private void updateThumbPosition() {
454 | int thumbAngle = mAngle; //(int) (mStartAngle + mProgressSweep + mRotation + 90);
455 | mThumbXPos = (int) (mArcRadius * Math.cos(Math.toRadians(thumbAngle)));
456 | mThumbYPos = (int) (mArcRadius * Math.sin(Math.toRadians(thumbAngle)));
457 | }
458 |
459 |
460 | //*****************************************************
461 | // Setters and Getters
462 | //*****************************************************
463 |
464 | public boolean getTouchInside() {
465 | return mTouchInside;
466 | }
467 |
468 | public void setTouchInside(boolean isEnabled) {
469 | int thumbHalfheight = (int) mThumb.getIntrinsicHeight() / 2;
470 | int thumbHalfWidth = (int) mThumb.getIntrinsicWidth() / 2;
471 | mTouchInside = isEnabled;
472 | if (mTouchInside) {
473 | mTouchIgnoreRadius = (float) (mArcRadius / 1.5);
474 | } else {
475 | mTouchIgnoreRadius = mArcRadius - Math.min(thumbHalfWidth, thumbHalfheight);
476 | }
477 | }
478 |
479 | public void setOnProtractorViewChangeListener(OnProtractorViewChangeListener l) {
480 | mOnProtractorViewChangeListener = l;
481 | }
482 |
483 | public OnProtractorViewChangeListener getOnProtractorViewChangeListener() {
484 | return mOnProtractorViewChangeListener;
485 | }
486 |
487 | public int getAngle() {
488 | return mAngle;
489 | }
490 |
491 | public void setAngle(int angle) {
492 | this.mAngle = angle;
493 | onProgressRefresh(mAngle, false);
494 | }
495 |
496 | public boolean isEnabled() {
497 | return mEnabled;
498 | }
499 |
500 | public void setEnabled(boolean enabled) {
501 | this.mEnabled = enabled;
502 | invalidate();
503 | }
504 |
505 | public int getProgressColor() {
506 | return mArcProgressPaint.getColor();
507 | }
508 |
509 | public void setProgressColor(@ColorInt int color) {
510 | mArcProgressPaint.setColor(color);
511 | invalidate();
512 | }
513 |
514 | public int getArcColor() {
515 | return mArcPaint.getColor();
516 | }
517 |
518 | public void setArcColor(@ColorInt int color) {
519 | mArcPaint.setColor(color);
520 | invalidate();
521 | }
522 |
523 | public int getArcProgressWidth() {
524 | return mArcProgressWidth;
525 | }
526 |
527 | public void setArcProgressWidth(int arcProgressWidth) {
528 | this.mArcProgressWidth = arcProgressWidth;
529 | mArcProgressPaint.setStrokeWidth(arcProgressWidth);
530 | invalidate();
531 | }
532 |
533 | public int getArcWidth() {
534 | return mArcWidth;
535 | }
536 |
537 | public void setArcWidth(int arcWidth) {
538 | this.mArcWidth = arcWidth;
539 | mArcPaint.setStrokeWidth(arcWidth);
540 | invalidate();
541 | }
542 |
543 | public boolean isRoundedEdges() {
544 | return mRoundedEdges;
545 | }
546 |
547 | public void setRoundedEdges(boolean roundedEdges) {
548 | this.mRoundedEdges = roundedEdges;
549 | if (roundedEdges) {
550 | mArcPaint.setStrokeCap(Paint.Cap.ROUND);
551 | mArcProgressPaint.setStrokeCap(Paint.Cap.ROUND);
552 | } else {
553 | mArcPaint.setStrokeCap(Paint.Cap.SQUARE);
554 | mArcPaint.setStrokeCap(Paint.Cap.SQUARE);
555 | }
556 | invalidate();
557 | }
558 |
559 | public Drawable getThumb() {
560 | return mThumb;
561 | }
562 |
563 | public void setThumb(Drawable thumb) {
564 | this.mThumb = thumb;
565 | invalidate();
566 | }
567 |
568 | public int getAngleTextSize() {
569 | return mAngleTextSize;
570 | }
571 |
572 | public void setAngleTextSize(int angleTextSize) {
573 | this.mAngleTextSize = angleTextSize;
574 | invalidate();
575 | }
576 |
577 | public int getTickOffset() {
578 | return mTickOffset;
579 | }
580 |
581 | public void setTickOffset(int tickOffset) {
582 | this.mTickOffset = tickOffset;
583 | }
584 |
585 | public int getTickLength() {
586 | return mTickLength;
587 | }
588 |
589 | public void setTickLength(int tickLength) {
590 | this.mTickLength = tickLength;
591 | }
592 |
593 | public TicksBetweenLabel getTicksBetweenLabel() {
594 | return mTicksBetweenLabel;
595 | }
596 |
597 | public void setTicksBetweenLabel(TicksBetweenLabel ticksBetweenLabel) {
598 | this.mTicksBetweenLabel = mTicksBetweenLabel;
599 | invalidate();
600 | }
601 |
602 | public int getTickIntervals() {
603 | return mTickIntervals;
604 | }
605 |
606 | public void setTickIntervals(int tickIntervals) {
607 | this.mTickIntervals = tickIntervals;
608 | invalidate();
609 | }
610 | }
611 |
--------------------------------------------------------------------------------
/protractorview/src/main/res/drawable/thumb_disabled.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | -
5 |
6 |
7 |
10 |
11 |
12 |
13 | -
14 |
15 |
16 |
18 |
19 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/protractorview/src/main/res/drawable/thumb_focused.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | -
5 |
6 |
7 |
10 |
11 |
12 |
13 | -
14 |
15 |
16 |
18 |
19 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/protractorview/src/main/res/drawable/thumb_normal.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | -
5 |
6 |
7 |
10 |
11 |
12 |
13 | -
14 |
15 |
16 |
18 |
19 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/protractorview/src/main/res/drawable/thumb_pressed.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | -
5 |
6 |
7 |
8 |
11 |
12 |
13 |
14 | -
15 |
16 |
17 |
19 |
20 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/protractorview/src/main/res/drawable/thumb_selector.xml:
--------------------------------------------------------------------------------
1 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/protractorview/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 |
--------------------------------------------------------------------------------
/protractorview/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #FFD8D8D8
4 | #FF383838
5 | #FF33b5e5
6 |
7 | #80D8D8D8
8 | #80383838
9 | #8033b5e5
10 |
--------------------------------------------------------------------------------
/protractorview/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | ProtractorView
3 |
4 |
--------------------------------------------------------------------------------
/protractorview/src/test/java/com/goodiebag/protractorview/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.goodiebag.protractorview;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':example', ':protractorview'
2 |
--------------------------------------------------------------------------------