├── .gitignore
├── LICENSE
├── README.md
├── build.gradle
├── dependencies.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── press
├── colorblindclick_launcher.png
├── demo.gif
└── myprevention_launcher.png
├── settings.gradle
├── verticalseekbar-example
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── ic_launcher-web.png
│ ├── kotlin
│ └── com
│ │ └── lukelorusso
│ │ └── verticalseekbarsample
│ │ ├── AppCompatActivityExtension.kt
│ │ └── MainActivity.kt
│ └── res
│ ├── drawable
│ ├── ic_battery_charging_full.xml
│ ├── ic_battery_full.xml
│ ├── ic_battery_low.xml
│ ├── ic_launcher_background.xml
│ ├── max_placeholder.xml
│ ├── min_placeholder.xml
│ └── thumb_placeholder.xml
│ ├── font
│ └── roboto_italic.ttf
│ ├── layout
│ └── activity_main.xml
│ ├── mipmap-anydpi-v26
│ ├── ic_launcher.xml
│ └── ic_launcher_round.xml
│ ├── mipmap-hdpi
│ ├── ic_launcher.png
│ ├── ic_launcher_foreground.png
│ └── ic_launcher_round.png
│ ├── mipmap-mdpi
│ ├── ic_launcher.png
│ ├── ic_launcher_foreground.png
│ └── ic_launcher_round.png
│ ├── mipmap-xhdpi
│ ├── ic_launcher.png
│ ├── ic_launcher_foreground.png
│ └── ic_launcher_round.png
│ ├── mipmap-xxhdpi
│ ├── ic_launcher.png
│ ├── ic_launcher_foreground.png
│ └── ic_launcher_round.png
│ ├── mipmap-xxxhdpi
│ ├── ic_launcher.png
│ ├── ic_launcher_foreground.png
│ └── ic_launcher_round.png
│ └── values
│ ├── colors.xml
│ ├── strings.xml
│ └── styles.xml
└── verticalseekbar
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
└── main
├── AndroidManifest.xml
├── kotlin
└── com
│ └── lukelorusso
│ └── verticalseekbar
│ └── VerticalSeekBar.kt
└── res
├── layout
└── layout_verticalseekbar.xml
└── values
└── attr.xml
/.gitignore:
--------------------------------------------------------------------------------
1 | # GENERATED
2 | *build
3 | buildsystem
4 | .externalNativeBuild
5 | .gradle
6 | .DS_Store
7 |
8 | # LOCAL
9 | local.properties
10 |
11 | # IDEA
12 | *.idea
13 | *.iml
14 | *.apk
--------------------------------------------------------------------------------
/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 2019 LUCA LORUSSO
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.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | VerticalSeekBar
2 | ===============
3 |
4 | [](https://opensource.org/licenses/Apache-2.0) [](http://developer.android.com/index.html) [](https://android-arsenal.com/api?level=16) [](https://jitpack.io/#lukelorusso/VerticalSeekBar) [](https://androidweekly.net/issues/issue-377)
5 |
6 | ## Presentation ##
7 |
8 | 
9 |
10 | This is the source code of an Android library: `-=:[ VerticalSeekBar ]:=-`
11 |
12 | 📃 Check also the [**Medium article**](https://blog.usejournal.com/android-a-custom-vertical-seekbar-how-to-reinvent-the-wheel-c07f28960f8f?source=friends_link&sk=eb8917b7f046a2152066ce8b58c81c7b) about it!
13 |
14 | - - -
15 |
16 | ## Why would you need it? ##
17 |
18 | *"Reinventing the wheel is, most of the time, a bad idea."*
19 | If you've ever tried to make a vertical SeekBar work properly, you know this is not the case. 😏
20 | From the moment you apply that `android:rotation="270"` all start to get messy: you cannot set the proper height for the drawable; the width of the bar distorts the width of your drawable; even customizing your interaction with the bar is kind of tricky.
21 | I've been through all of this and suddenly I've had enough.
22 |
23 | **Introducing a nicer, redesigned and highly customizable VerticalSeekBar.**
24 |
25 | What you got:
26 | - custom progress drawable: apply resources or color gradients
27 | - custom thumb: chose your size, background color, corner radius or even to completely hide it
28 | - view width and drawable width completely separated
29 | - choose how to set your progress (just sliding the thumb, clicking around, or both)
30 | - min and max placeholders
31 | - much more!
32 |
33 | - - -
34 |
35 | ## How to use it? ##
36 |
37 | Step 1. add the JitPack repository to your ROOT build.gradle at the end of repositories:
38 |
39 | ```groovy
40 | allprojects {
41 | repositories {
42 | ...
43 | maven { url 'https://jitpack.io' }
44 | }
45 | }
46 | ```
47 |
48 | Step 2. add the dependency:
49 |
50 | ```groovy
51 | implementation 'com.github.lukelorusso:VerticalSeekBar:1.2.7'
52 | ```
53 |
54 | That's it!
55 |
56 | Now you can add the view to your layout:
57 | ```xml
58 |
61 | ```
62 |
63 | maybe add some attributes... here you got some, we'll discuss them later
64 | ```
65 | ...
66 | app:vsb_click_to_set_progress="false"
67 | app:vsb_bar_corner_radius="15dp"
68 | app:vsb_bar_width="60dp"
69 | app:vsb_bar_background="#eeeeee"
70 | app:vsb_bar_progress_gradient_end="#4dd0e1"
71 | app:vsb_bar_progress_gradient_start="#03a2ba"
72 | app:vsb_max_placeholder_position="inside"
73 | app:vsb_max_placeholder_src="@drawable/max_placeholder"
74 | app:vsb_min_placeholder_position="inside"
75 | app:vsb_min_placeholder_src="@drawable/min_placeholder"
76 | app:vsb_progress="50"
77 | app:vsb_show_thumb="true"
78 | app:vsb_thumb_container_corner_radius="5dp"
79 | app:vsb_thumb_container_tint="@color/placeholderBackground"
80 | app:vsb_thumb_placeholder_src="@drawable/thumb_placeholder"
81 | app:vsb_use_thumb_to_set_progress="true"
82 | ...
83 | ```
84 |
85 | All of them can be also set programmatically.
86 |
87 | (Please note: it's strongly recommended to avoid pre-1.2.0 versions due to inconsistencies compared to this guide)
88 |
89 | ## For Java projects ##
90 |
91 | Someone experienced this `InflateException`. For those guys, it's worth noticing that this is a KOTLIN library! The reason why you're getting an `InvocationTargetException` is because, in case you're still on Java, you also have to specify:
92 |
93 | ```gradle
94 | implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.3.+'
95 | // or one of the -jre7, -jre8 stdlib depending on your config
96 | // put the most up-to-date version
97 | ```
98 |
99 | on your app module's `build.gradle`.
100 |
101 | Another solution is just to... migrate to Kotlin guys!
102 |
103 | - - -
104 |
105 | # Attributes #
106 |
107 | ## Background and Progress ##
108 |
109 | To set your progress value programmatically:
110 | ```kotlin
111 | mainVerticalSeekBar.progress = 75
112 | ```
113 |
114 | Do you need a smaller or bigger range? You can change `maxValue` like this:
115 | ```kotlin
116 | mainVerticalSeekBar.maxValue = 70 // "progress" will be automagically reduced!
117 | ```
118 |
119 | Let's put some color on this view, shall we?
120 | You can set a drawable for the background and a drawable for the progress. If you don't, default colors will be applied.
121 |
122 | For both **background** and **progress** you have 3 choices:
123 | - set a start color and an end color, the view will create a gradient for you
124 | - set a drawable resource or color (REMEMBER: this choice has priority on the one before)
125 | - just don't choose (it's still a choice anyway 😉)
126 |
127 | Example for the first choice: apply a gradient
128 | ```kotlin
129 | mainVerticalSeekBar.barBackgroundStartColor = ContextCompat.getColor(this, R.color.my_background_start_color)
130 | mainVerticalSeekBar.barBackgroundEndColor = ContextCompat.getColor(this, R.color.my_background_end_color)
131 | mainVerticalSeekBar.barProgressStartColor = ContextCompat.getColor(this, R.color.my_progress_start_color)
132 | mainVerticalSeekBar.barProgressEndColor = ContextCompat.getColor(this, R.color.my_progress_end_color)
133 | ```
134 |
135 | Example for the second choice: apply a resource (will eventually override the first one)
136 | ```kotlin
137 | mainVerticalSeekBar.barBackgroundDrawable = getDrawable(R.color.my_background_color)
138 | mainVerticalSeekBar.barProgressDrawable = getDrawable(R.drawable.my_progress)
139 | ```
140 |
141 | Your bar can also have rounded corners...
142 | ```kotlin
143 | mainVerticalSeekBar.barCornerRadius = 40 // those are pixels
144 | ```
145 |
146 | ...and a proper independent width
147 | ```kotlin
148 | mainVerticalSeekBar.barWidth = 30 // those are pixels
149 | ```
150 |
151 | ## Placeholders ##
152 |
153 | To set minimum and/or maximum placeholders (`null` is a possible value to remove them):
154 | ```kotlin
155 | mainVerticalSeekBar.minPlaceholderDrawable = getDrawable(R.drawable.my_min_placeholder)
156 | mainVerticalSeekBar.maxPlaceholderDrawable = getDrawable(R.drawable.my_max_placeholder)
157 | ```
158 |
159 | Since v1.1.4 you can also choose placeholders' position
160 | You can choose between `{"inside", "outside", "middle"}` (`"middle"` by default)
161 | Programmatically, it will be:
162 | ```kotlin
163 | mainVerticalSeekBar.minPlaceholderPosition = VerticalSeekBar.Placeholder.INSIDE
164 | mainVerticalSeekBar.maxPlaceholderPosition = VerticalSeekBar.Placeholder.OUTSIDE
165 | ```
166 |
167 | Now about the thumb placeholder 👆
168 | It is child of a `androidx.cardview.widget.CardView`. You can choose the color tint and the corner radius of the CardView:
169 | ```kotlin
170 | mainVerticalSeekBar.thumbContainerColor = ContextCompat.getColor(this, R.color.my_thumb_background_color)
171 | mainVerticalSeekBar.thumbContainerCornerRadius = 15 // those are pixels
172 | ```
173 |
174 | You can set your thumb drawable like this:
175 | ```kotlin
176 | mainVerticalSeekBar.thumbPlaceholderDrawable = getDrawable(R.drawable.my_thumb_placeholder)
177 | ```
178 |
179 | If you just don't want to see it:
180 | ```kotlin
181 | mainVerticalSeekBar.showThumb = false
182 | ```
183 |
184 | ## Interaction ##
185 |
186 | You can interact with your VerticalSeekBar in two ways:
187 | - sliding the thumb
188 | - tapping on the bar
189 |
190 | Both those interactions can be disabled if you like (they are `true` by default).
191 | For instance, It can be useful to disable sliding in case you need to put the VerticalSeekBar on a ScrollView.
192 | To do so:
193 | ```kotlin
194 | mainVerticalSeekBar.useThumbToSetProgress = false
195 | mainVerticalSeekBar.clickToSetProgress = true
196 | ```
197 |
198 | Try to change those booleans too see other possibilities!
199 |
200 | ## Listeners ##
201 |
202 | You have the possibility to set a listener for progress changes:
203 |
204 | ```kotlin
205 | mainVerticalSeekBar.setOnProgressChangeListener { progressValue ->
206 | Log.d("VerticalSeekBar", "PROGRESS CHANGED at value: $progressValue")
207 | }
208 |
209 | mainVerticalSeekBar.setOnPressListener { progressValue ->
210 | Log.d("VerticalSeekBar", "PRESSED at value: $progressValue")
211 | } // since v.1.2.2 thanks to https://github.com/ModischFabrications
212 |
213 | mainVerticalSeekBar.setOnReleaseListener { progressValue ->
214 | Log.d("VerticalSeekBar", "RELEASED at value: $progressValue")
215 | } // since v.1.2.2 thanks to https://github.com/ModischFabrications
216 | ```
217 |
218 | This is how it will look like using **Java**:
219 | ```java
220 | VerticalSeekBar mainVerticalSeekBar = findViewById(R.id.mainVerticalSeekBar);
221 | mainVerticalSeekBar.setOnProgressChangeListener(
222 | new Function1() {
223 | @Override
224 | public Unit invoke(Integer progressValue) {
225 | Log.d("VerticalSeekBar", "PROGRESS CHANGED at value: " + progressValue);
226 | return null;
227 | }
228 | }
229 | );
230 | mainVerticalSeekBar.setOnPressListener(
231 | new Function1() {
232 | @Override
233 | public Unit invoke(Integer progressValue) {
234 | Log.d("VerticalSeekBar", "PRESSED at value: " + progressValue);
235 | return null;
236 | }
237 | }
238 | );
239 | mainVerticalSeekBar.setOnReleaseListener(
240 | new Function1() {
241 | @Override
242 | public Unit invoke(Integer progressValue) {
243 | Log.d("VerticalSeekBar", "RELEASED at value: " + progressValue);
244 | return null;
245 | }
246 | }
247 | );
248 | // Too much verbose for you? Time to migrate to Kotlin!
249 | ```
250 |
251 | ## Still want more? ##
252 |
253 | If this level of customization is not enough, I have one last good news for you: the seekbar layout is ENTIRELY CUSTOMIZABLE!
254 |
255 | You can pick the original [**layout_verticalseekbar.xml**](/verticalseekbar/src/main/res/layout/layout_verticalseekbar.xml) and put it in your project's `res/layout` folder.
256 |
257 | Now you can modify it as you wish; just remember to keep all the original ids! 😉 (`thumbCardView` and `thumbPlaceholder` can be safely removed)
258 |
259 | - - -
260 |
261 | # Explore! #
262 |
263 | Feel free to checkout and launch the example app 🎡
264 |
265 | Also, see where using this library has been the perfect choice:
266 |
267 | [](https://play.google.com/store/apps/details?id=com.lukelorusso.colorblindclick)
268 | [**ColorBlindClick**](https://play.google.com/store/apps/details?id=com.lukelorusso.colorblindclick)
269 |
270 |
271 | [](https://play.google.com/store/apps/details?id=fr.siaci.myprevention)
272 | [**MyPrevention**](https://play.google.com/store/apps/details?id=fr.siaci.myprevention)
273 |
274 | - - -
275 |
276 | # Copyright #
277 |
278 | Make with 💚 by [Luca Lorusso](http://lukelorusso.com), licensed under [Apache License 2.0](http://www.apache.org/licenses/LICENSE-2.0)
279 | Thanks for the help to [Lopez Mikhael](http://mikhaellopez.com/)
280 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 | apply from: 'dependencies.gradle'
3 |
4 | buildscript {
5 | ext.gradle_version = '4.2.0'
6 | ext.kotlin_version = '1.5.0'
7 | repositories {
8 | google()
9 | mavenCentral()
10 | gradlePluginPortal()
11 | }
12 | dependencies {
13 | classpath "com.android.tools.build:gradle:$gradle_version"
14 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
15 | classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"
16 | classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
17 | classpath 'com.github.ben-manes:gradle-versions-plugin:0.38.0'
18 | }
19 | }
20 |
21 | task clean(type: Delete) {
22 | delete rootProject.buildDir
23 | }
24 |
--------------------------------------------------------------------------------
/dependencies.gradle:
--------------------------------------------------------------------------------
1 | allprojects {
2 | repositories {
3 | google()
4 | mavenCentral()
5 | gradlePluginPortal()
6 | }
7 | }
8 |
9 | ext {
10 |
11 | // APP VERSION
12 | androidVersionCode = 17
13 | androidVersionName = '1.2.7' // REMEMBER: also update README.md
14 |
15 | // ANDROID VERSION
16 | androidMinSdkVersion = 16
17 | androidTargetSdkVersion = 30
18 |
19 | // KOTLIN
20 | kotlinStdlibGroupId = "org.jetbrains.kotlin"
21 | kotlinStdlibArtifactId = "kotlin-stdlib"
22 | kotlinStdlibVersion = ext.kotlin_version
23 | kotlinStdlib = "$kotlinStdlibGroupId:$kotlinStdlibArtifactId:$kotlinStdlibVersion"
24 |
25 | // ANDROID LIB
26 | androidXAppCompat = "androidx.appcompat:appcompat:1.2.0"
27 | cardViewGroupId = "androidx.cardview"
28 | cardViewArtifactId = "cardview"
29 | cardViewVersion = '1.0.0'
30 | cardView = "$cardViewGroupId:$cardViewArtifactId:$cardViewVersion"
31 |
32 | // DEPENDENCY CHECK STRATEGY
33 | dependencyUpdatesStrategy = {
34 | componentSelection { rules ->
35 | rules.all { ComponentSelection selection ->
36 | boolean rejected = ['alpha', 'beta', 'rc', 'cr', 'm'].any { qualifier ->
37 | selection.candidate.version ==~ /(?i).*[.-]${qualifier}[.\d-]*/
38 | }
39 | if (rejected) {
40 | selection.reject('Release candidate')
41 | }
42 | }
43 | }
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lukelorusso/VerticalSeekBar/5d19d0259fc1147a10978d2d391adc21d3560a48/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon May 17 21:09:57 CEST 2021
2 | distributionBase=GRADLE_USER_HOME
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip
4 | distributionPath=wrapper/dists
5 | zipStorePath=wrapper/dists
6 | zipStoreBase=GRADLE_USER_HOME
7 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/press/colorblindclick_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lukelorusso/VerticalSeekBar/5d19d0259fc1147a10978d2d391adc21d3560a48/press/colorblindclick_launcher.png
--------------------------------------------------------------------------------
/press/demo.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lukelorusso/VerticalSeekBar/5d19d0259fc1147a10978d2d391adc21d3560a48/press/demo.gif
--------------------------------------------------------------------------------
/press/myprevention_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lukelorusso/VerticalSeekBar/5d19d0259fc1147a10978d2d391adc21d3560a48/press/myprevention_launcher.png
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':verticalseekbar', ':verticalseekbar-example'
2 |
--------------------------------------------------------------------------------
/verticalseekbar-example/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/verticalseekbar-example/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'kotlin-android'
3 | apply plugin: 'com.github.ben-manes.versions'
4 |
5 | android {
6 | compileSdkVersion androidTargetSdkVersion
7 |
8 | buildFeatures {
9 | viewBinding true
10 | }
11 |
12 | defaultConfig {
13 | applicationId "com.lukelorusso.verticalseekbarsample"
14 | minSdkVersion androidMinSdkVersion
15 | targetSdkVersion androidTargetSdkVersion
16 | versionCode androidVersionCode
17 | versionName androidVersionName
18 | }
19 | buildTypes {
20 | release {
21 | minifyEnabled false
22 | }
23 | }
24 | sourceSets {
25 | androidTest.java.srcDirs += 'src/androidTest/kotlin'
26 | main.java.srcDirs += 'src/main/kotlin'
27 | test.java.srcDirs += 'src/test/kotlin'
28 | }
29 | }
30 |
31 | dependencies {
32 | implementation project(':verticalseekbar')
33 | implementation kotlinStdlib
34 | implementation androidXAppCompat
35 |
36 | // DEPENDENCY CHECK STRATEGY
37 | dependencyUpdates.resolutionStrategy dependencyUpdatesStrategy
38 | }
39 |
--------------------------------------------------------------------------------
/verticalseekbar-example/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 |
--------------------------------------------------------------------------------
/verticalseekbar-example/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/verticalseekbar-example/src/main/ic_launcher-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lukelorusso/VerticalSeekBar/5d19d0259fc1147a10978d2d391adc21d3560a48/verticalseekbar-example/src/main/ic_launcher-web.png
--------------------------------------------------------------------------------
/verticalseekbar-example/src/main/kotlin/com/lukelorusso/verticalseekbarsample/AppCompatActivityExtension.kt:
--------------------------------------------------------------------------------
1 | package com.lukelorusso.verticalseekbarsample
2 |
3 | import android.view.LayoutInflater
4 | import androidx.appcompat.app.AppCompatActivity
5 | import androidx.viewbinding.ViewBinding
6 |
7 | inline fun AppCompatActivity.viewBinding(
8 | crossinline bindingInflater: (LayoutInflater) -> T
9 | ) = lazy(LazyThreadSafetyMode.NONE) {
10 | bindingInflater.invoke(layoutInflater)
11 | }
12 |
--------------------------------------------------------------------------------
/verticalseekbar-example/src/main/kotlin/com/lukelorusso/verticalseekbarsample/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.lukelorusso.verticalseekbarsample
2 |
3 | import android.os.Bundle
4 | import android.util.Log
5 | import androidx.appcompat.app.AppCompatActivity
6 | import com.lukelorusso.verticalseekbarsample.databinding.ActivityMainBinding
7 |
8 | class MainActivity : AppCompatActivity() {
9 |
10 | private val binding by viewBinding(ActivityMainBinding::inflate)
11 |
12 | override fun onCreate(savedInstanceState: Bundle?) {
13 | super.onCreate(savedInstanceState)
14 | setContentView(binding.root)
15 |
16 | binding.mainVerticalSeekBar.apply {
17 | progress = 75
18 |
19 | setOnProgressChangeListener { progressValue ->
20 | Log.d("VerticalSeekBar", "PROGRESS CHANGED at value: $progressValue")
21 | binding.mainProgressValue.text = progressValue.toString()
22 | }
23 |
24 | setOnPressListener { progressValue ->
25 | Log.d("VerticalSeekBar", "PRESSED at value: $progressValue")
26 | }
27 |
28 | setOnReleaseListener { progressValue ->
29 | Log.d("VerticalSeekBar", "RELEASED at value: $progressValue")
30 | }
31 | }
32 |
33 | binding.mainProgressValue.text = binding.mainVerticalSeekBar.progress.toString()
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/verticalseekbar-example/src/main/res/drawable/ic_battery_charging_full.xml:
--------------------------------------------------------------------------------
1 |
7 |
10 |
11 |
--------------------------------------------------------------------------------
/verticalseekbar-example/src/main/res/drawable/ic_battery_full.xml:
--------------------------------------------------------------------------------
1 |
7 |
10 |
11 |
--------------------------------------------------------------------------------
/verticalseekbar-example/src/main/res/drawable/ic_battery_low.xml:
--------------------------------------------------------------------------------
1 |
7 |
10 |
14 |
15 |
--------------------------------------------------------------------------------
/verticalseekbar-example/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
10 |
12 |
14 |
16 |
18 |
20 |
22 |
24 |
26 |
28 |
30 |
32 |
34 |
36 |
38 |
40 |
42 |
44 |
46 |
48 |
50 |
52 |
54 |
56 |
58 |
60 |
62 |
64 |
66 |
68 |
70 |
72 |
74 |
75 |
--------------------------------------------------------------------------------
/verticalseekbar-example/src/main/res/drawable/max_placeholder.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | -
4 |
5 |
8 |
9 |
10 |
11 |
12 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/verticalseekbar-example/src/main/res/drawable/min_placeholder.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | -
4 |
5 |
8 |
9 |
10 |
11 |
12 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/verticalseekbar-example/src/main/res/drawable/thumb_placeholder.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/verticalseekbar-example/src/main/res/font/roboto_italic.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lukelorusso/VerticalSeekBar/5d19d0259fc1147a10978d2d391adc21d3560a48/verticalseekbar-example/src/main/res/font/roboto_italic.ttf
--------------------------------------------------------------------------------
/verticalseekbar-example/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
18 |
19 |
39 |
40 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/verticalseekbar-example/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/verticalseekbar-example/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/verticalseekbar-example/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lukelorusso/VerticalSeekBar/5d19d0259fc1147a10978d2d391adc21d3560a48/verticalseekbar-example/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/verticalseekbar-example/src/main/res/mipmap-hdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lukelorusso/VerticalSeekBar/5d19d0259fc1147a10978d2d391adc21d3560a48/verticalseekbar-example/src/main/res/mipmap-hdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/verticalseekbar-example/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lukelorusso/VerticalSeekBar/5d19d0259fc1147a10978d2d391adc21d3560a48/verticalseekbar-example/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/verticalseekbar-example/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lukelorusso/VerticalSeekBar/5d19d0259fc1147a10978d2d391adc21d3560a48/verticalseekbar-example/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/verticalseekbar-example/src/main/res/mipmap-mdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lukelorusso/VerticalSeekBar/5d19d0259fc1147a10978d2d391adc21d3560a48/verticalseekbar-example/src/main/res/mipmap-mdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/verticalseekbar-example/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lukelorusso/VerticalSeekBar/5d19d0259fc1147a10978d2d391adc21d3560a48/verticalseekbar-example/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/verticalseekbar-example/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lukelorusso/VerticalSeekBar/5d19d0259fc1147a10978d2d391adc21d3560a48/verticalseekbar-example/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/verticalseekbar-example/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lukelorusso/VerticalSeekBar/5d19d0259fc1147a10978d2d391adc21d3560a48/verticalseekbar-example/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/verticalseekbar-example/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lukelorusso/VerticalSeekBar/5d19d0259fc1147a10978d2d391adc21d3560a48/verticalseekbar-example/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/verticalseekbar-example/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lukelorusso/VerticalSeekBar/5d19d0259fc1147a10978d2d391adc21d3560a48/verticalseekbar-example/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/verticalseekbar-example/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lukelorusso/VerticalSeekBar/5d19d0259fc1147a10978d2d391adc21d3560a48/verticalseekbar-example/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/verticalseekbar-example/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lukelorusso/VerticalSeekBar/5d19d0259fc1147a10978d2d391adc21d3560a48/verticalseekbar-example/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/verticalseekbar-example/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lukelorusso/VerticalSeekBar/5d19d0259fc1147a10978d2d391adc21d3560a48/verticalseekbar-example/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/verticalseekbar-example/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lukelorusso/VerticalSeekBar/5d19d0259fc1147a10978d2d391adc21d3560a48/verticalseekbar-example/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/verticalseekbar-example/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lukelorusso/VerticalSeekBar/5d19d0259fc1147a10978d2d391adc21d3560a48/verticalseekbar-example/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/verticalseekbar-example/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #017500
4 | #015A00
5 | #ff7301
6 | #FFEBDC
7 |
8 |
--------------------------------------------------------------------------------
/verticalseekbar-example/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | VerticalSeekBar
3 | Here\'s a vertical seek bar:
4 |
5 |
--------------------------------------------------------------------------------
/verticalseekbar-example/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/verticalseekbar/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/verticalseekbar/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'kotlin-android'
3 | apply plugin: 'kotlin-android-extensions'
4 | apply plugin: 'com.github.dcendents.android-maven'
5 | apply plugin: 'com.github.ben-manes.versions'
6 |
7 | group = 'com.github.lukelorusso'
8 |
9 | android {
10 | compileSdkVersion androidTargetSdkVersion
11 | defaultConfig {
12 | minSdkVersion androidMinSdkVersion
13 | targetSdkVersion androidTargetSdkVersion
14 | versionCode androidVersionCode
15 | versionName androidVersionName
16 | }
17 | buildTypes {
18 | release {
19 | minifyEnabled false
20 | }
21 | }
22 | sourceSets {
23 | androidTest.java.srcDirs += 'src/androidTest/kotlin'
24 | main.java.srcDirs += 'src/main/kotlin'
25 | test.java.srcDirs += 'src/test/kotlin'
26 | }
27 | }
28 |
29 | dependencies {
30 | implementation kotlinStdlib
31 | implementation androidXAppCompat
32 | api cardView
33 |
34 | // DEPENDENCY CHECK STRATEGY
35 | dependencyUpdates.resolutionStrategy dependencyUpdatesStrategy
36 | }
37 |
--------------------------------------------------------------------------------
/verticalseekbar/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 |
--------------------------------------------------------------------------------
/verticalseekbar/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/verticalseekbar/src/main/kotlin/com/lukelorusso/verticalseekbar/VerticalSeekBar.kt:
--------------------------------------------------------------------------------
1 | @file:Suppress("unused", "MemberVisibilityCanBePrivate")
2 |
3 | package com.lukelorusso.verticalseekbar
4 |
5 | import android.content.Context
6 | import android.content.res.ColorStateList
7 | import android.graphics.Color
8 | import android.graphics.drawable.Drawable
9 | import android.graphics.drawable.GradientDrawable
10 | import android.util.AttributeSet
11 | import android.util.DisplayMetrics
12 | import android.view.MotionEvent
13 | import android.view.View
14 | import android.widget.FrameLayout
15 | import android.widget.ImageView
16 | import androidx.cardview.widget.CardView
17 | import androidx.core.view.ViewCompat
18 | import kotlinx.android.synthetic.main.layout_verticalseekbar.view.*
19 | import kotlin.math.max
20 | import kotlin.math.roundToInt
21 |
22 | /**
23 | * A nicer, redesigned and vertical SeekBar
24 | */
25 | open class VerticalSeekBar @JvmOverloads constructor(
26 | context: Context,
27 | attrs: AttributeSet? = null,
28 | defStyleAttr: Int = 0
29 | ) : FrameLayout(context, attrs, defStyleAttr) {
30 |
31 | companion object {
32 | private const val DEFAULT_MAX_VALUE = 100
33 | private const val DEFAULT_PROGRESS = 50
34 | private const val DEFAULT_DRAWABLE_BACKGROUND: String = "#f6f6f6"
35 | private const val DEFAULT_DRAWABLE_PROGRESS_START: String = "#4D88E1"
36 | private const val DEFAULT_DRAWABLE_PROGRESS_END: String = "#7BA1DB"
37 | }
38 |
39 | enum class Placeholder {
40 | OUTSIDE,
41 | INSIDE,
42 | MIDDLE
43 | }
44 |
45 | private var onProgressChangeListener: ((Int) -> Unit)? = null
46 | private var onPressListener: ((Int) -> Unit)? = null
47 | private var onReleaseListener: ((Int) -> Unit)? = null
48 |
49 | var clickToSetProgress = true
50 | set(value) {
51 | field = value
52 | applyAttributes()
53 | }
54 | var barCornerRadius: Int = 0
55 | set(value) {
56 | field = value
57 | applyAttributes()
58 | }
59 | var barBackgroundDrawable: Drawable? = null
60 | set(value) {
61 | field = value
62 | applyAttributes()
63 | }
64 | var barBackgroundStartColor: Int = Color.parseColor(DEFAULT_DRAWABLE_BACKGROUND)
65 | set(value) {
66 | field = value
67 | barBackgroundDrawable = null
68 | applyAttributes()
69 | }
70 | var barBackgroundEndColor: Int = Color.parseColor(DEFAULT_DRAWABLE_BACKGROUND)
71 | set(value) {
72 | field = value
73 | barBackgroundDrawable = null
74 | applyAttributes()
75 | }
76 | var barProgressDrawable: Drawable? = null
77 | set(value) {
78 | field = value
79 | applyAttributes()
80 | }
81 | var barProgressStartColor: Int = Color.parseColor(DEFAULT_DRAWABLE_PROGRESS_START)
82 | set(value) {
83 | field = value
84 | barProgressDrawable = null
85 | applyAttributes()
86 | }
87 | var barProgressEndColor: Int = Color.parseColor(DEFAULT_DRAWABLE_PROGRESS_END)
88 | set(value) {
89 | field = value
90 | barProgressDrawable = null
91 | applyAttributes()
92 | }
93 | var barWidth: Int? = null
94 | set(value) {
95 | field = value
96 | applyAttributes()
97 | }
98 | var minLayoutWidth: Int = 0
99 | set(value) {
100 | field = value
101 | applyAttributes()
102 | }
103 | var minLayoutHeight: Int = 0
104 | set(value) {
105 | field = value
106 | applyAttributes()
107 | }
108 | var maxPlaceholderDrawable: Drawable? = null
109 | set(value) {
110 | field = value
111 | applyAttributes()
112 | }
113 | var maxPlaceholderPosition = Placeholder.MIDDLE
114 | set(value) {
115 | field = value
116 | applyAttributes()
117 | }
118 | var minPlaceholderDrawable: Drawable? = null
119 | set(value) {
120 | field = value
121 | applyAttributes()
122 | }
123 | var minPlaceholderPosition = Placeholder.MIDDLE
124 | set(value) {
125 | field = value
126 | applyAttributes()
127 | }
128 | var showThumb = true
129 | set(value) {
130 | field = value
131 | applyAttributes()
132 | }
133 | var thumbContainerColor: Int = Color.WHITE
134 | set(value) {
135 | field = value
136 | applyAttributes()
137 | }
138 | var thumbContainerCornerRadius: Int = 0
139 | set(value) {
140 | field = value
141 | applyAttributes()
142 | }
143 | var thumbPlaceholderDrawable: Drawable? = null
144 | set(value) {
145 | field = value
146 | applyAttributes()
147 | }
148 | var useThumbToSetProgress = true
149 | set(value) {
150 | field = value
151 | applyAttributes()
152 | }
153 | var maxValue = DEFAULT_MAX_VALUE
154 | set(value) {
155 | val newValue = when {
156 | value < 1 -> 1
157 | else -> value
158 | }
159 | if (progress > newValue) progress = newValue
160 | field = newValue
161 | updateViews()
162 | }
163 | var progress: Int = DEFAULT_PROGRESS
164 | set(value) {
165 | val newValue = when {
166 | value < 0 -> 0
167 | value > maxValue -> maxValue
168 | else -> value
169 | }
170 | if (field != newValue) {
171 | onProgressChangeListener?.invoke(newValue)
172 | }
173 | field = newValue
174 | updateViews()
175 | }
176 | private var yDelta: Int = 0
177 | private var initEnded =
178 | false // if true allows the view to be updated after setting an attribute programmatically
179 |
180 | init {
181 | init(context, attrs)
182 | }
183 |
184 | private fun init(context: Context, attrs: AttributeSet?) {
185 | inflate(context, R.layout.layout_verticalseekbar, this)
186 |
187 | if (attrs != null) {
188 | val attributes =
189 | context.obtainStyledAttributes(attrs, R.styleable.VerticalSeekBar, 0, 0)
190 | try {
191 | clickToSetProgress =
192 | attributes.getBoolean(
193 | R.styleable.VerticalSeekBar_vsb_click_to_set_progress,
194 | clickToSetProgress
195 | )
196 | barCornerRadius = attributes.getLayoutDimension(
197 | R.styleable.VerticalSeekBar_vsb_bar_corner_radius,
198 | barCornerRadius
199 | )
200 | barBackgroundStartColor =
201 | attributes.getColor(
202 | R.styleable.VerticalSeekBar_vsb_bar_background_gradient_start,
203 | barBackgroundStartColor
204 | )
205 | barBackgroundEndColor =
206 | attributes.getColor(
207 | R.styleable.VerticalSeekBar_vsb_bar_background_gradient_end,
208 | barBackgroundEndColor
209 | )
210 | attributes.getDrawable(R.styleable.VerticalSeekBar_vsb_bar_background)?.also {
211 | barBackgroundDrawable = it
212 | }
213 | barProgressStartColor =
214 | attributes.getColor(
215 | R.styleable.VerticalSeekBar_vsb_bar_progress_gradient_start,
216 | barProgressStartColor
217 | )
218 | barProgressEndColor =
219 | attributes.getColor(
220 | R.styleable.VerticalSeekBar_vsb_bar_progress_gradient_end,
221 | barProgressEndColor
222 | )
223 | attributes.getDrawable(R.styleable.VerticalSeekBar_vsb_bar_progress).also {
224 | barProgressDrawable = it
225 | }
226 | barWidth = attributes.getDimensionPixelSize(
227 | R.styleable.VerticalSeekBar_vsb_bar_width,
228 | barWidth ?: container.layoutParams.width
229 | )
230 | attributes.getLayoutDimension(
231 | R.styleable.VerticalSeekBar_android_layout_width,
232 | minLayoutWidth
233 | ).also {
234 | container.layoutParams.width =
235 | if (it != -1 && it < minLayoutWidth) minLayoutWidth // wrap_content
236 | else it
237 | }
238 | attributes.getLayoutDimension(
239 | R.styleable.VerticalSeekBar_android_layout_height,
240 | minLayoutHeight
241 | ).also {
242 | container.layoutParams.height =
243 | if (it != -1 && it < minLayoutHeight) minLayoutHeight // wrap_content
244 | else it
245 | }
246 | attributes.getDrawable(R.styleable.VerticalSeekBar_vsb_max_placeholder_src).also {
247 | maxPlaceholderDrawable = it
248 | }
249 | maxPlaceholderPosition = Placeholder.values()[attributes.getInt(
250 | R.styleable.VerticalSeekBar_vsb_max_placeholder_position,
251 | maxPlaceholderPosition.ordinal
252 | )]
253 | attributes.getDrawable(R.styleable.VerticalSeekBar_vsb_min_placeholder_src).also {
254 | minPlaceholderDrawable = it
255 | }
256 | minPlaceholderPosition = Placeholder.values()[attributes.getInt(
257 | R.styleable.VerticalSeekBar_vsb_min_placeholder_position,
258 | minPlaceholderPosition.ordinal
259 | )]
260 | showThumb =
261 | attributes.getBoolean(R.styleable.VerticalSeekBar_vsb_show_thumb, showThumb)
262 | thumbContainerColor =
263 | attributes.getColor(
264 | R.styleable.VerticalSeekBar_vsb_thumb_container_tint,
265 | thumbContainerColor
266 | )
267 | thumbContainerCornerRadius = attributes.getLayoutDimension(
268 | R.styleable.VerticalSeekBar_vsb_thumb_container_corner_radius,
269 | thumbContainerCornerRadius
270 | )
271 | attributes.getDrawable(R.styleable.VerticalSeekBar_vsb_thumb_placeholder_src).also {
272 | thumbPlaceholderDrawable = it
273 | }
274 | attributes.getInt(R.styleable.VerticalSeekBar_vsb_max_value, maxValue).also {
275 | maxValue = it
276 | }
277 | attributes.getInt(R.styleable.VerticalSeekBar_vsb_progress, progress).also {
278 | progress = it
279 | }
280 | useThumbToSetProgress =
281 | attributes.getBoolean(
282 | R.styleable.VerticalSeekBar_vsb_use_thumb_to_set_progress,
283 | useThumbToSetProgress
284 | )
285 |
286 | } finally {
287 | attributes.recycle()
288 | }
289 | }
290 |
291 | initEnded = true
292 | applyAttributes()
293 | }
294 |
295 | fun setOnProgressChangeListener(listener: ((Int) -> Unit)?) {
296 | this.onProgressChangeListener = listener
297 | }
298 |
299 | fun setOnPressListener(listener: ((Int) -> Unit)?) {
300 | this.onPressListener = listener
301 | }
302 |
303 | fun setOnReleaseListener(listener: ((Int) -> Unit)?) {
304 | this.onReleaseListener = listener
305 | }
306 |
307 | //region PROTECTED METHODS
308 | protected fun Context.dpToPixel(dp: Float): Float =
309 | dp * (resources.displayMetrics.densityDpi.toFloat() / DisplayMetrics.DENSITY_DEFAULT)
310 |
311 | protected fun Context.pixelToDp(px: Float): Float =
312 | px / (resources.displayMetrics.densityDpi.toFloat() / DisplayMetrics.DENSITY_DEFAULT)
313 | //endregion
314 |
315 | private fun applyAttributes() {
316 | if (initEnded) {
317 | initEnded = false // will be released at the end
318 |
319 | var thumbCardView: CardView? = null // nullable for customization
320 | try {
321 | thumbCardView = thumb.findViewById(R.id.thumbCardView)
322 | } catch (ignored: NoSuchFieldError) {
323 | }
324 |
325 |
326 | var thumbPlaceholder: ImageView? = null // nullable for customization
327 | try {
328 | thumbPlaceholder = thumb.findViewById(R.id.thumbPlaceholder)
329 | } catch (ignored: NoSuchFieldError) {
330 | }
331 |
332 |
333 | // Customizing drawableCardView
334 | barCardView.layoutParams.width = barWidth ?: 0
335 |
336 | // Customizing drawableBackground
337 | if (barBackgroundDrawable == null) barBackgroundDrawable = GradientDrawable(
338 | GradientDrawable.Orientation.TOP_BOTTOM,
339 | intArrayOf(barBackgroundStartColor, barBackgroundEndColor)
340 | ).apply { cornerRadius = 0f }
341 | barBackground.background = barBackgroundDrawable
342 |
343 | // Customizing drawableProgress
344 | if (barProgressDrawable == null) barProgressDrawable = GradientDrawable(
345 | GradientDrawable.Orientation.TOP_BOTTOM,
346 | intArrayOf(barProgressStartColor, barProgressEndColor)
347 | ).apply { cornerRadius = 0f }
348 | barProgress.background = barProgressDrawable
349 |
350 | // Applying card corner radius
351 | barCardView.radius = barCornerRadius.toFloat()
352 | thumbCardView?.radius = thumbContainerCornerRadius.toFloat()
353 |
354 | // Applying custom placeholders
355 | maxPlaceholder.setImageDrawable(maxPlaceholderDrawable) // can also be null
356 | minPlaceholder.setImageDrawable(minPlaceholderDrawable) // can also be null
357 |
358 | // Let's shape the thumb
359 | val thumbMeasureIncrease =
360 | if (thumbCardView != null) (ViewCompat.getElevation(thumbCardView)
361 | + context.dpToPixel(1F)).roundToInt()
362 | else 0
363 | if (showThumb) {
364 | thumbPlaceholderDrawable?.also { thumbPlaceholder?.setImageDrawable(it) } // CANNOT be null
365 | thumb.visibility = View.VISIBLE
366 | val states = arrayOf(
367 | intArrayOf(android.R.attr.state_enabled), // enabled
368 | intArrayOf(-android.R.attr.state_enabled), // disabled
369 | intArrayOf(-android.R.attr.state_checked), // unchecked
370 | intArrayOf(android.R.attr.state_pressed) // pressed
371 | )
372 | val colors = arrayOf(
373 | thumbContainerColor,
374 | thumbContainerColor,
375 | thumbContainerColor,
376 | thumbContainerColor
377 | ).toIntArray()
378 |
379 | if (thumbCardView != null)
380 | ViewCompat.setBackgroundTintList(thumbCardView, ColorStateList(states, colors))
381 | thumb.measure(0, 0)
382 | thumb.layoutParams = (thumb.layoutParams as LayoutParams).apply {
383 | width = thumb.measuredWidth + thumbMeasureIncrease
384 | height = thumb.measuredHeight + thumbMeasureIncrease
385 | thumbCardView?.layoutParams =
386 | (thumbCardView?.layoutParams as LayoutParams).apply {
387 | topMargin = thumbMeasureIncrease / 2
388 | }
389 | }
390 | } else thumb.visibility = View.GONE
391 |
392 | // Adding some margin to drawableCardView, maxPlaceholder and minPlaceholder
393 | val maxPlaceholderLayoutParams = (maxPlaceholder.layoutParams as LayoutParams)
394 | val minPlaceholderLayoutParams = (minPlaceholder.layoutParams as LayoutParams)
395 | barCardView.layoutParams = (barCardView.layoutParams as LayoutParams).apply {
396 | val thumbHalfHeight =
397 | if (showThumb) thumb.measuredHeight / 2
398 | else 0
399 |
400 | val maxPlaceholderHalfHeight = (maxPlaceholder.drawable?.intrinsicHeight ?: 0) / 2
401 | when (maxPlaceholderPosition) {
402 | Placeholder.INSIDE -> {
403 | topMargin = thumbHalfHeight
404 | maxPlaceholderLayoutParams.topMargin = topMargin
405 | }
406 | Placeholder.OUTSIDE -> {
407 | topMargin = maxPlaceholder.drawable.intrinsicHeight +
408 | if (thumbHalfHeight > maxPlaceholder.drawable.intrinsicHeight)
409 | thumbHalfHeight - maxPlaceholder.drawable.intrinsicHeight
410 | else 0
411 | maxPlaceholderLayoutParams.topMargin =
412 | topMargin - maxPlaceholder.drawable.intrinsicHeight
413 | }
414 | else -> {
415 | topMargin = max(thumbHalfHeight, maxPlaceholderHalfHeight)
416 | maxPlaceholderLayoutParams.topMargin = topMargin - maxPlaceholderHalfHeight
417 | }
418 | }
419 | maxPlaceholderLayoutParams.bottomMargin = maxPlaceholderLayoutParams.topMargin
420 | maxPlaceholder.layoutParams = maxPlaceholderLayoutParams
421 |
422 | val minPlaceholderHalfHeight = (minPlaceholder.drawable?.intrinsicHeight ?: 0) / 2
423 | when (minPlaceholderPosition) {
424 | Placeholder.INSIDE -> {
425 | bottomMargin = thumbHalfHeight
426 | minPlaceholderLayoutParams.bottomMargin = bottomMargin
427 | }
428 | Placeholder.OUTSIDE -> {
429 | bottomMargin = minPlaceholder.drawable.intrinsicHeight +
430 | if (thumbHalfHeight > minPlaceholder.drawable.intrinsicHeight)
431 | thumbHalfHeight - minPlaceholder.drawable.intrinsicHeight
432 | else 0
433 | minPlaceholderLayoutParams.bottomMargin =
434 | bottomMargin - minPlaceholder.drawable.intrinsicHeight
435 | }
436 | else -> {
437 | bottomMargin = max(thumbHalfHeight, minPlaceholderHalfHeight)
438 | minPlaceholderLayoutParams.bottomMargin =
439 | bottomMargin - minPlaceholderHalfHeight
440 | }
441 | }
442 | bottomMargin += thumbMeasureIncrease
443 | minPlaceholderLayoutParams.bottomMargin += thumbMeasureIncrease
444 | minPlaceholderLayoutParams.topMargin = maxPlaceholderLayoutParams.bottomMargin
445 | minPlaceholder.layoutParams = minPlaceholderLayoutParams
446 | }
447 |
448 | // here we intercept the click on the thumb
449 | if (showThumb && useThumbToSetProgress) thumb.setOnTouchListener { thumb, event ->
450 | val rawY = event.rawY.roundToInt()
451 | when (event.action and MotionEvent.ACTION_MASK) {
452 |
453 | MotionEvent.ACTION_DOWN -> { // here we get the max top y coordinate (yDelta)
454 | yDelta = rawY +
455 | (barCardView.layoutParams as LayoutParams).topMargin -
456 | (thumb.layoutParams as LayoutParams).topMargin -
457 | thumb.measuredHeight / 2
458 | onPressListener?.invoke(progress)
459 | }
460 |
461 | MotionEvent.ACTION_MOVE -> {
462 | val positionY = rawY - yDelta // here we calculate the displacement
463 | val fillHeight = barCardView.measuredHeight
464 | when { // here we update progress
465 | positionY in 1 until fillHeight -> {
466 | val newValue =
467 | maxValue - (positionY.toFloat() * maxValue / fillHeight)
468 | progress = newValue.roundToInt()
469 | }
470 | positionY <= 0 -> progress = maxValue
471 | positionY >= fillHeight -> progress = 0
472 | }
473 | }
474 |
475 | MotionEvent.ACTION_UP -> onReleaseListener?.invoke(progress)
476 |
477 | }
478 | true
479 | } else thumb.setOnTouchListener(null)
480 |
481 | // here we intercept the click on the bar
482 | if (clickToSetProgress) barCardView.setOnTouchListener { bar, event ->
483 | val positionY = event.y.roundToInt()
484 | val action = {
485 | val fillHeight = bar.measuredHeight
486 | when { // here we update progress
487 | positionY in 1 until fillHeight -> {
488 | val newValue = maxValue - (positionY.toFloat() * maxValue / fillHeight)
489 | progress = newValue.roundToInt()
490 | }
491 | positionY <= 0 -> progress = maxValue
492 | positionY >= fillHeight -> progress = 0
493 | }
494 | }
495 | when (event.action and MotionEvent.ACTION_MASK) {
496 |
497 | MotionEvent.ACTION_DOWN -> {
498 | action.invoke()
499 | onPressListener?.invoke(progress)
500 | }
501 |
502 | MotionEvent.ACTION_MOVE -> if (useThumbToSetProgress) action.invoke()
503 |
504 | MotionEvent.ACTION_UP -> onReleaseListener?.invoke(progress)
505 |
506 | }
507 | true
508 | } else barCardView.setOnTouchListener(null)
509 |
510 | initEnded = true
511 |
512 | updateViews()
513 | }
514 | }
515 |
516 | /**
517 | * Inside here the views are repositioned based on the new value
518 | */
519 | private fun updateViews() {
520 | if (initEnded) post {
521 | val barCardViewLayoutParams = barCardView.layoutParams as LayoutParams
522 | val fillHeight =
523 | height - barCardViewLayoutParams.topMargin - barCardViewLayoutParams.bottomMargin
524 | val marginByProgress = fillHeight - (progress * fillHeight / maxValue)
525 | thumb.layoutParams = (thumb.layoutParams as LayoutParams).apply {
526 | topMargin = marginByProgress
527 | val thumbHalfHeight = if (showThumb) thumb.measuredHeight / 2 else 0
528 | if (barCardViewLayoutParams.topMargin > thumbHalfHeight) {
529 | val displacement = barCardViewLayoutParams.topMargin - thumbHalfHeight
530 | topMargin += displacement
531 | }
532 | }
533 | barProgress.translationY =
534 | (barBackground.height * (maxValue - progress) / maxValue).toFloat()
535 | invalidate()
536 | }
537 | }
538 |
539 | }
540 |
--------------------------------------------------------------------------------
/verticalseekbar/src/main/res/layout/layout_verticalseekbar.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
14 |
15 |
19 |
20 |
24 |
25 |
26 |
27 |
32 |
33 |
39 |
40 |
41 |
42 |
47 |
48 |
54 |
55 |
56 |
57 |
62 |
63 |
69 |
70 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
--------------------------------------------------------------------------------
/verticalseekbar/src/main/res/values/attr.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------