11 |
12 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # StepViewAndroid
2 | An Android library written in kotlin to display steps (without any max-min limits) along with the status/description. It also supports some really cool features.
3 |
4 | ## Custom Views Tutorial
5 | For any information on how to create custom views you can refer to the link below.
6 | https://medium.com/mindorks/how-to-create-custom-views-141dc0570e57
7 |
8 | ## Setup
9 |
10 | ```
11 | implementation 'com.params.stepview:stepview:1.0.2'
12 | ```
13 |
14 | ## Usage
15 |
16 | ### A customised StepView
17 |
18 | 
19 |
20 | * Set step count and current count.
21 |
22 | * Set different dimensions for circle radius, line length, line gap, stroke width, line width, text size of label (step count).
23 |
24 | * Set status data using ```android:entries```
25 |
26 | * Chose a color mode i.e fill, stroke or both using ```circleColorType```
27 |
28 | * Stroke color (circle), fill color (circle), line color & label text color can be set differently for completed, current & incomplete states.
29 |
30 | ```XML
31 |
54 | ```
55 |
56 | ### Some more customisations
57 |
58 | 
59 |
60 | * Set a zoom value to your current step
61 | * Set different drawables for completed, current & incomplete states.
62 |
63 | ```XML
64 | app:currentStepZoom="0.5"
65 | app:completeDrawable="@drawable/ic_satisfied_black_24dp"
66 | app:currentDrawable="@drawable/ic_dissatisfied_black_24dp"
67 | app:incompleteDrawable="@drawable/ic_very_dissatisfied_black_24dp"
68 | ```
69 |
70 | ### Step status customisations
71 |
72 | 
73 |
74 | * Multiline Text Support: View automatically adjusts line length to make sure words or alphabets from one line do not crossover to next line.
75 | However, If you want to strictly obey line length set ```app:strictObeyLineLength= "true"```.
76 | * To add font to status simply refer to the font file from res/font directory.
77 | * Ensure a minimum margin between status texts in case they are too close.
78 | * Set top margin of a status text from its corresponding circle.
79 | * Align all status at the same level in case, a zoom level is set to current step.
80 | * Set text color to status.
81 |
82 | ```XML
83 | app:currentStepZoom="0.3"
84 | app:statusFont="@font/lekton_r"
85 | app:statusTopMargin="15dp"
86 | app:minStatusAdjacentMargin="5dp"
87 | app:alignStatusWithCurrent="true"
88 | app:textColorStatus="#000000"
89 | ```
90 |
91 | ### Scrolling property
92 |
93 | 
94 |
95 | * The view can be scrolled if the content exceeds the available width.
96 | * You can also scroll to a particular step by calling ```statusViewScroller.scrollToStep(stepCount)```
97 |
98 | ### Changing properties at runtime
99 |
100 | * You can also easily change any property at runtime as described below.
101 | ```
102 | statusViewScroller.statusView.run {
103 | currentCount = 2
104 | circleFillColorCurrent = Color.RED
105 | }
106 | ```
107 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | apply plugin: 'kotlin-android'
4 |
5 | apply plugin: 'kotlin-android-extensions'
6 |
7 | android {
8 | compileSdkVersion versions.compileSdk
9 | defaultConfig {
10 | applicationId "params.com.statusView"
11 | minSdkVersion versions.minSdk
12 | targetSdkVersion versions.targetSdk
13 | versionCode 1
14 | versionName "1.0"
15 |
16 | }
17 | buildTypes {
18 | release {
19 | minifyEnabled false
20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
21 | }
22 | }
23 | }
24 |
25 | dependencies {
26 | implementation fileTree(dir: 'libs', include: ['*.jar'])
27 | implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$versions.kotlin_version"
28 | implementation "com.android.support:appcompat-v7:$versions.supportLibrary"
29 | implementation 'com.android.support.constraint:constraint-layout:1.1.2'
30 | implementation project(":stepview")
31 | }
32 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/java/params/com/statusView/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package params.com.statusView
2 |
3 | import android.graphics.Color
4 | import android.os.Bundle
5 | import android.support.v7.app.AppCompatActivity
6 | import kotlinx.android.synthetic.main.activity_main.*
7 |
8 | class MainActivity : AppCompatActivity() {
9 |
10 | override fun onCreate(savedInstanceState: Bundle?) {
11 | super.onCreate(savedInstanceState)
12 | setContentView(R.layout.activity_main)
13 | statusViewScroller.statusView.run {
14 | currentCount = 2
15 | circleFillColorCurrent = Color.RED
16 | }
17 |
18 |
19 | }
20 |
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_done_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_tag_faces_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/font/montserrat_r.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/params-ing/StepViewAndroid/722ccb391100881ea32e695edc33aa3025176a5e/app/src/main/res/font/montserrat_r.ttf
--------------------------------------------------------------------------------
/app/src/main/res/font/roboto_r.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/params-ing/StepViewAndroid/722ccb391100881ea32e695edc33aa3025176a5e/app/src/main/res/font/roboto_r.ttf
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
11 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/params-ing/StepViewAndroid/722ccb391100881ea32e695edc33aa3025176a5e/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/params-ing/StepViewAndroid/722ccb391100881ea32e695edc33aa3025176a5e/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/params-ing/StepViewAndroid/722ccb391100881ea32e695edc33aa3025176a5e/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/params-ing/StepViewAndroid/722ccb391100881ea32e695edc33aa3025176a5e/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/params-ing/StepViewAndroid/722ccb391100881ea32e695edc33aa3025176a5e/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/params-ing/StepViewAndroid/722ccb391100881ea32e695edc33aa3025176a5e/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/params-ing/StepViewAndroid/722ccb391100881ea32e695edc33aa3025176a5e/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/params-ing/StepViewAndroid/722ccb391100881ea32e695edc33aa3025176a5e/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/params-ing/StepViewAndroid/722ccb391100881ea32e695edc33aa3025176a5e/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/params-ing/StepViewAndroid/722ccb391100881ea32e695edc33aa3025176a5e/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 16dp
5 | 16dp
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Step View
3 |
4 |
5 |
6 | Confirmed
7 | Dispatched
8 | Arrived
9 | Delivered
10 | Reviewed
11 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | ext.versions = [
5 | 'compileSdk' : 27,
6 | 'minSdk' : 15,
7 | 'targetSdk' : 27,
8 | 'supportLibrary': '27.1.0',
9 | 'kotlin_version' : '1.2.31'
10 | ]
11 | repositories {
12 | google()
13 | jcenter()
14 | }
15 | dependencies {
16 | classpath 'com.android.tools.build:gradle:3.1.3'
17 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$versions.kotlin_version"
18 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
19 | classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'
20 |
21 | // NOTE: Do not place your application dependencies here; they belong
22 | // in the individual module build.gradle files
23 | }
24 | }
25 |
26 | allprojects {
27 | repositories {
28 | google()
29 | jcenter()
30 | }
31 | }
32 |
33 | task clean(type: Delete) {
34 | delete rootProject.buildDir
35 | }
36 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/params-ing/StepViewAndroid/722ccb391100881ea32e695edc33aa3025176a5e/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Jun 12 16:47:46 IST 2018
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
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 |
--------------------------------------------------------------------------------
/screenshots/android_stepview.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/params-ing/StepViewAndroid/722ccb391100881ea32e695edc33aa3025176a5e/screenshots/android_stepview.png
--------------------------------------------------------------------------------
/screenshots/basic_stepview.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/params-ing/StepViewAndroid/722ccb391100881ea32e695edc33aa3025176a5e/screenshots/basic_stepview.png
--------------------------------------------------------------------------------
/screenshots/colors_stepview.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/params-ing/StepViewAndroid/722ccb391100881ea32e695edc33aa3025176a5e/screenshots/colors_stepview.png
--------------------------------------------------------------------------------
/screenshots/drawable_zoom_stepview.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/params-ing/StepViewAndroid/722ccb391100881ea32e695edc33aa3025176a5e/screenshots/drawable_zoom_stepview.png
--------------------------------------------------------------------------------
/screenshots/fragment_scroll_stepview.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/params-ing/StepViewAndroid/722ccb391100881ea32e695edc33aa3025176a5e/screenshots/fragment_scroll_stepview.gif
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':stepview'
2 |
--------------------------------------------------------------------------------
/stepview/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/stepview/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'kotlin-android'
3 |
4 | ext {
5 | bintrayRepo = 'maven'
6 | bintrayName = 'StepViewAndroid'
7 |
8 | publishedGroupId = 'com.params.stepview'
9 | libraryName = 'stepView'
10 | artifact = 'stepview'
11 | libraryVersion = '1.0.2'
12 | libraryDescription = 'An Android library written in kotlin to display steps (without any max-min limits) along with the status/description.'
13 |
14 | siteUrl = 'https://github.com/params-ing/StepViewAndroid'
15 | gitUrl = 'https://github.com/params-ing/StepViewAndroid.git'
16 |
17 | developerId = 'params-ing'
18 | developerName = 'Parminder Singh'
19 | developerEmail = 'pisingh02@gmail.com'
20 |
21 | licenseName = 'The Apache Software License, Version 2.0'
22 | licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
23 | allLicenses = ["Apache-2.0"]
24 | }
25 |
26 |
27 | android {
28 | compileSdkVersion versions.compileSdk
29 |
30 |
31 |
32 | defaultConfig {
33 | minSdkVersion versions.minSdk
34 | targetSdkVersion versions.targetSdk
35 | versionCode 2
36 | versionName "1.0.2"
37 | }
38 |
39 | buildTypes {
40 | release {
41 | minifyEnabled false
42 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
43 | }
44 | }
45 |
46 | }
47 |
48 | dependencies {
49 | implementation fileTree(dir: 'libs', include: ['*.jar'])
50 | implementation "com.android.support:appcompat-v7:$versions.supportLibrary"
51 | implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$versions.kotlin_version"
52 | }
53 |
54 | tasks.withType(Javadoc) {
55 | enabled = false
56 | }
57 |
58 | apply from: 'https://raw.githubusercontent.com/params-ing/JCenter/master/installv1.gradle'
59 | apply from: 'https://raw.githubusercontent.com/params-ing/JCenter/master/bintrayv1.gradle'
--------------------------------------------------------------------------------
/stepview/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 |
--------------------------------------------------------------------------------
/stepview/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/stepview/src/main/java/params/com/stepview/StatusView.kt:
--------------------------------------------------------------------------------
1 | package params.com.stepview
2 |
3 | import android.content.Context
4 | import android.graphics.*
5 | import android.graphics.drawable.Drawable
6 | import android.support.annotation.FloatRange
7 | import android.support.v4.content.res.ResourcesCompat
8 | import android.support.v4.view.ViewCompat
9 | import android.text.Layout
10 | import android.text.StaticLayout
11 | import android.text.TextPaint
12 | import android.util.AttributeSet
13 | import android.util.TypedValue
14 | import android.view.View
15 | import android.widget.HorizontalScrollView
16 | import kotlin.properties.Delegates
17 | import kotlin.reflect.KProperty
18 |
19 | class StatusViewScroller @JvmOverloads constructor(
20 | context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
21 | ) : HorizontalScrollView(context, attrs, defStyleAttr) {
22 |
23 | var statusView: StatusView = StatusView(context, attrs)
24 |
25 | init {
26 | addView(statusView)
27 | }
28 |
29 | fun scrollToStep(stepCount: Int) {
30 | scrollTo(statusView.getScrollPosForStep(stepCount), scrollY)
31 | }
32 |
33 | fun smoothScrollToStep(stepCount: Int) {
34 | smoothScrollTo(statusView.getScrollPosForStep(stepCount), scrollY)
35 | }
36 | }
37 |
38 | /**
39 | * Created by Parminder Saini on 12/06/18.
40 | */
41 | class StatusView @JvmOverloads constructor(
42 | context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
43 | ) : View(context, attrs, defStyleAttr) {
44 |
45 |
46 | companion object {
47 | const val CIRCLE_COLOR_TYPE_FILL = 1
48 | const val CIRCLE_COLOR_TYPE_STROKE = 2
49 | const val INVALID_STATUS_COUNT = -1
50 | }
51 |
52 | /**
53 | * Circle stroke paints for incomplete & complete status
54 | */
55 | private var mCircleStrokePaint: Paint? = null
56 | private var mCircleStrokePaintIncomplete: Paint? = null
57 | private var mCircleStrokePaintCurrent: Paint? = null
58 |
59 | private var mCircleFillPaint: Paint? = null
60 | private var mCircleFillPaintIncomplete: Paint? = null
61 | private var mCircleFillPaintCurrent: Paint? = null
62 |
63 | private lateinit var mLinePaint: Paint
64 | private lateinit var mLinePaintIncomplete: Paint
65 | private lateinit var mLinePaintCurrent: Paint
66 | private lateinit var mTextPaintStatus: TextPaint
67 | private lateinit var mTextPaintLabelsIncomplete: TextPaint
68 | private lateinit var mTextPaintLabelCurrent: TextPaint
69 | private lateinit var mTextPaintLabels: TextPaint
70 |
71 |
72 | /**
73 | * Magnification value for current Circle
74 | */
75 | @setparam:FloatRange(from = 0.0, to = 1.0)
76 | var currentStatusZoom: Float = 0.0f
77 | set(value) {
78 | require(value in 0..1) { "Zoom should be in between 0 to 1, but was $value." }
79 |
80 | currentStatusRadius = circleRadius * (1 + value)
81 | }
82 |
83 | /**
84 | * A min margin that there should be between every adjacent status Text
85 | * Note# This only applies if strictObeyLineLength is set to false
86 | */
87 | var minStatusAdjacentMargin: Float by OnLayoutProp(5.0f.pxValue())
88 |
89 | /**
90 | * Set true to obey Status Text i.e alphabets or words belonging to one line would not cross
91 | * to the other line so the line length between circles would be increased as per if needed.
92 | *
93 | * Set false to strictly obey line length.
94 | *
95 | *
96 | */
97 | var strictObeyLineLength: Boolean by OnLayoutProp(false)
98 |
99 |
100 | /**
101 | * The total number of statuses to be displayed
102 | */
103 | var stepCount: Int by OnLayoutProp(4)
104 |
105 | /*
106 | The count up to which status has been completed
107 | */
108 | var currentCount: Int by OnLayoutProp(INVALID_STATUS_COUNT){
109 | initCirclePaints()
110 | }
111 |
112 |
113 | /*
114 | Radius of each circle to be drawn
115 | #Note: This does not include stroke width
116 | */
117 |
118 | var circleRadius: Float by OnLayoutProp(20.0f.pxValue()) //dp
119 |
120 |
121 | /**
122 | * Length of line to be drawn between circles
123 | * #Note: This does not include line gap
124 | */
125 | var lineLength: Float by OnLayoutProp(30.0f.pxValue()) //dp
126 |
127 | /**
128 | * Stroke width of each circle to be drawn
129 | */
130 | var circleStrokeWidth: Float by OnLayoutProp(2.0f.pxValue()) //dp
131 |
132 |
133 | /**
134 | * Margin or gap on each side of circle.
135 | * Note: This does not apply for extreme sides.
136 | */
137 | var lineGap by OnLayoutProp(0.0f)
138 |
139 |
140 | /**
141 | * Top Margin of Status from circle
142 | */
143 | var statusTopMargin by OnLayoutProp(4.0f.pxValue())
144 |
145 | /**
146 | * set true to align all status to align same as current Status y-pos
147 | *
148 | */
149 | var alignStatusWithCurrent by OnValidateProp(false) {
150 | setDrawingDimensions()
151 | }
152 |
153 | /**
154 | * Stroke width of the line between circles (dp)
155 | */
156 | var lineWidth: Float by OnValidateProp(1.5f.pxValue()) {
157 | mLinePaint.strokeWidth = lineWidth
158 | mLinePaintIncomplete.strokeWidth = lineWidth
159 | mLinePaintCurrent.strokeWidth = lineWidth
160 | }
161 |
162 | /**
163 | * Color of line between circles
164 | */
165 | var lineColor: Int by OnValidateProp(Color.BLACK) {
166 | mLinePaint.color = lineColor
167 | }
168 |
169 | /**
170 | * Color of line between circles for incomplete statuses
171 | */
172 | var lineColorIncomplete: Int by OnValidateProp(Color.BLACK) {
173 | mLinePaintIncomplete.color = lineColorIncomplete
174 | }
175 |
176 | /**
177 | * Color of line adjacent to circles for current status
178 | */
179 | var lineColorCurrent: Int by OnValidateProp(Color.BLACK) {
180 | mLinePaintCurrent.color = lineColorCurrent
181 | }
182 |
183 | /**
184 | * Fill Color of circles for complete statuses
185 | */
186 | var circleFillColor: Int by OnValidateProp(Color.CYAN) {
187 | mCircleFillPaint?.color = circleFillColor
188 |
189 | }
190 | /**
191 | * Fill Color of circles for incomplete statuses
192 | */
193 | var circleFillColorIncomplete: Int by OnValidateProp(Color.CYAN) {
194 | mCircleFillPaintIncomplete?.color = circleFillColorIncomplete
195 |
196 | }
197 | /**
198 | * Fill Color of circles for current status
199 | */
200 | var circleFillColorCurrent: Int by OnValidateProp(Color.CYAN) {
201 | mCircleFillPaintCurrent?.color = circleFillColorCurrent
202 |
203 | }
204 | /**
205 | * Stroke Color of circles for complete statuses
206 | */
207 | var circleStrokeColor: Int by OnValidateProp(Color.BLACK) {
208 | mCircleStrokePaint?.color = circleStrokeColor
209 |
210 | }
211 | /**
212 | * Stroke Color of circles for incomplete statuses
213 | */
214 | var circleStrokeColorIncomplete: Int by OnValidateProp(Color.BLACK) {
215 | mCircleStrokePaintIncomplete?.color = circleStrokeColorIncomplete
216 | }
217 |
218 | /**
219 | * Stroke Color of circles for current Status
220 | */
221 | var circleStrokeColorCurrent: Int by OnValidateProp(Color.BLACK) {
222 | mCircleStrokePaintCurrent?.color = circleStrokeColorCurrent
223 | }
224 | /**
225 | * Text Color of labels
226 | *
227 | */
228 | var textColorLabels: Int by OnValidateProp(Color.BLACK) {
229 | mTextPaintLabels.color = textColorLabels
230 | }
231 |
232 | /**
233 | * Text Color of labels Incomplete
234 | */
235 | var textColorLabelsIncomplete: Int by OnValidateProp(Color.BLACK) {
236 | mTextPaintLabelsIncomplete.color = textColorLabelsIncomplete
237 | }
238 |
239 | /**
240 | * Text Color of labels Current
241 | */
242 | var textColorLabelCurrent: Int by OnValidateProp(Color.BLACK) {
243 | mTextPaintLabelCurrent.color = textColorLabelCurrent
244 | }
245 |
246 | /**
247 | * Text Size of Labels
248 | */
249 | var textSizeLabels: Float by OnValidateProp(15.0f.pxValue(TypedValue.COMPLEX_UNIT_SP)) {
250 | //sp
251 | mTextPaintLabels.textSize = textSizeLabels
252 | mTextPaintLabelsIncomplete.textSize = textSizeLabels
253 |
254 | }
255 |
256 | /**
257 | * Text Color of Statuses
258 | */
259 | var textColorStatus: Int by OnValidateProp(Color.BLACK) {
260 | mTextPaintStatus.color = textColorStatus
261 | for (item in statusData) {
262 | item.staticLayout?.paint?.color = textColorStatus
263 | }
264 | }
265 |
266 | /**
267 | * Text Size of statuses
268 | */
269 |
270 | var textSizeStatus: Float by OnLayoutProp(14.0f.pxValue(TypedValue.COMPLEX_UNIT_SP)) {
271 | mTextPaintStatus.textSize = textSizeStatus
272 | }
273 |
274 | /**
275 | * Text Font of statuses
276 | */
277 |
278 | var statusTypeface: Typeface? by OnLayoutProp(null) {
279 | statusTypeface?.run {
280 | mTextPaintStatus.typeface = this
281 | }
282 |
283 | }
284 |
285 | /**
286 | * Text Font of Labels
287 | */
288 |
289 | var labelsTypeface: Typeface? by OnLayoutProp(null) {
290 | labelsTypeface?.run {
291 | mTextPaintLabels.typeface = this
292 | mTextPaintLabelsIncomplete.typeface = this
293 | mTextPaintLabelCurrent.typeface = this
294 | }
295 |
296 | }
297 |
298 | /**
299 | * A boolean which decides if to draw labels or not
300 | */
301 |
302 | var drawLabels: Boolean by OnValidateProp(false) {
303 | setDrawingDimensions()
304 | }
305 |
306 | /**
307 | * A drawable for complete status
308 | * #Note: If this is set then it would be given preference over the labels.
309 | */
310 | var completeDrawable: Drawable? by OnValidateProp(null) {
311 | setDrawingDimensions()
312 | }
313 |
314 | /**
315 | * A drawable for current Status
316 | * #Note: If this is set then it would be given preference over the labels.
317 | */
318 | var currentDrawable: Drawable? by OnValidateProp(null) {
319 | setDrawingDimensions()
320 | }
321 |
322 | /**
323 | * A drawable for incomplete statuses
324 | * #Note: If this is set then it would be given preference over the labels.
325 | */
326 | var incompleteDrawable: Drawable? by OnValidateProp(null) {
327 | setDrawingDimensions()
328 | }
329 |
330 | /**
331 | * circle fill type. Has been set to fill by default.
332 | *
333 | * To change pass a single flag
334 | * To set both the flags i.e (fill & stroke) pass (CIRCLE_COLOR_TYPE_FILL | CIRCLE_COLOR_TYPE_STROKE)
335 | *
336 | */
337 | var circleColorType: Int by Delegates.observable(CIRCLE_COLOR_TYPE_FILL)
338 | { prop, old, new ->
339 | if (ViewCompat.isLaidOut(this)) {
340 |
341 |
342 | initCirclePaints()
343 | val oldHadStrokeFlagSet = containsFlag(old, CIRCLE_COLOR_TYPE_STROKE)
344 | val newHasStrokeFlagSet = containsFlag(new, CIRCLE_COLOR_TYPE_STROKE)
345 |
346 | if ((oldHadStrokeFlagSet && !newHasStrokeFlagSet) || (!oldHadStrokeFlagSet && newHasStrokeFlagSet)) {
347 | requestLayout()
348 |
349 | } else {
350 | setDrawingDimensions()
351 | invalidate()
352 | }
353 | }
354 | }
355 |
356 |
357 | /**
358 | * This contains list of LabelInfo which stores static layout and text.
359 | * To the caller. It is a list of string and custom getter setters have been made accordingly
360 | *
361 | */
362 | private var statusData: MutableList by OnLayoutProp(mutableListOf())
363 |
364 | /**
365 | * Extracts List from List and returns back to the caller
366 | */
367 | fun getStatusList(): List = statusData.map { it.text }
368 |
369 | /**
370 | * Creates List from List by passing default values.
371 | * #Note: It trims any extra statuses (if size is greater than stepCount)
372 | */
373 | fun setStatusList(list: List) {
374 | //to make sure original list is not modified convert to mutableList
375 | val input = list.toMutableList()
376 | if (stepCount > 0 && list.size - stepCount > 0) {
377 | input.dropLast(list.size - stepCount)
378 | }
379 |
380 |
381 | statusData = (input.map { StatusInfo(it) }).toMutableList()
382 |
383 |
384 | }
385 |
386 |
387 | /**
388 | * Stores all the drawing data that is used while drawing on canvas
389 | */
390 | private var drawingData = mutableListOf()
391 | private var currentStatusRadius: Float by OnLayoutProp(circleRadius)
392 | private var lineLengthComputed = 0.0f //actual linelength that is calculated and set
393 |
394 |
395 | //To store the data of each circle
396 | private class Item(val textData: LabelItemText?, val circleItem: CircleItem, val lineItem: LineItem?, val labelData: StatusItemText? = null)
397 |
398 | //Stores drawing data about labels to be drawn inside circles i.e the count of step
399 | private class LabelItemText(val text: String? = null, val paint: Paint? = null, val x: Float = 0.0f, val y: Float = 0.0f, val drawableItem: DrawableItem? = null)
400 |
401 | //Stores drawing data for statuses to be drawn below the circle
402 | private class StatusItemText(val x: Float = 0.0f, val y: Float = 0.0f, val staticLayout: StaticLayout? = null)
403 |
404 | //Stores drawing data for every circle
405 | private class CircleItem(val center: PointF, val radius: Float, val strokePaint: Paint?, val fillPaint: Paint?)
406 |
407 | //Stores drawing data for every line to be drawn between circles
408 | private class LineItem(val start: PointF, val end: PointF, val paint: Paint)
409 |
410 | //Stores drawable draw info
411 | private class DrawableItem(val rect: Rect, val drawable: Drawable)
412 |
413 | //Stores information about every status text and its dimension properties
414 | private class StatusInfo(val text: String, var width: Float = 0.0f, var height: Float = 0.0f, var staticLayout: StaticLayout? = null)
415 |
416 | private var propsIntialisedOnce = false
417 |
418 | init {
419 |
420 | id = ViewCompat.generateViewId()//as the same attrs are being passed this view would have the same id as scroller.
421 |
422 | val a = context.theme.obtainStyledAttributes(attrs, R.styleable.StatusViewScroller, 0, 0)
423 |
424 | try {
425 |
426 | stepCount = a.getInt(R.styleable.StatusViewScroller_stepCount, stepCount)
427 | currentCount = a.getInt(R.styleable.StatusViewScroller_currentCount, INVALID_STATUS_COUNT)
428 | circleRadius = a.getDimension(R.styleable.StatusViewScroller_circleRadius, circleRadius)
429 | lineLength = a.getDimension(R.styleable.StatusViewScroller_lineLength, lineLength)
430 | circleStrokeWidth = a.getDimension(R.styleable.StatusViewScroller_circleStrokeWidth, circleStrokeWidth)
431 | lineWidth = a.getDimension(R.styleable.StatusViewScroller_lineWidth, lineWidth)
432 | completeDrawable = a.getDrawable(R.styleable.StatusViewScroller_completeDrawable)
433 | incompleteDrawable = a.getDrawable(R.styleable.StatusViewScroller_incompleteDrawable)
434 | currentDrawable = a.getDrawable(R.styleable.StatusViewScroller_currentDrawable)
435 | drawLabels = a.getBoolean(R.styleable.StatusViewScroller_drawLabels, drawLabels)
436 | strictObeyLineLength = a.getBoolean(R.styleable.StatusViewScroller_strictObeyLineLength, strictObeyLineLength)
437 | lineGap = a.getDimension(R.styleable.StatusViewScroller_lineGap, lineGap)
438 | minStatusAdjacentMargin = a.getDimension(R.styleable.StatusViewScroller_minStatusAdjacentMargin, minStatusAdjacentMargin)
439 | statusTopMargin = a.getDimension(R.styleable.StatusViewScroller_statusTopMargin, statusTopMargin)
440 | lineColor = a.getColor(R.styleable.StatusViewScroller_lineColor, lineColor)
441 | circleFillColor = a.getColor(R.styleable.StatusViewScroller_circleColor, circleFillColor)
442 | circleStrokeColor = a.getColor(R.styleable.StatusViewScroller_circleStrokeColor, circleStrokeColor)
443 | textColorStatus = a.getColor(R.styleable.StatusViewScroller_textColorStatus, textColorStatus)
444 | textColorLabels = a.getColor(R.styleable.StatusViewScroller_textColorLabels, textColorLabels)
445 | textSizeStatus = a.getDimension(R.styleable.StatusViewScroller_textSizeStatus, textSizeStatus)
446 | textSizeLabels = a.getDimension(R.styleable.StatusViewScroller_textSizeLabels, textSizeLabels)
447 | circleColorType = a.getInteger(R.styleable.StatusViewScroller_circleColorType, circleColorType)
448 | textColorLabelsIncomplete = a.getColor(R.styleable.StatusViewScroller_textColorLabelsIncomplete, textColorLabels)
449 | textColorLabelCurrent = a.getColor(R.styleable.StatusViewScroller_textColorLabelsCurrent, textColorLabelsIncomplete)
450 | lineColorIncomplete = a.getColor(R.styleable.StatusViewScroller_lineColorIncomplete, lineColor)
451 | lineColorCurrent = a.getColor(R.styleable.StatusViewScroller_lineColorCurrent, lineColorIncomplete)
452 | circleFillColorIncomplete = a.getColor(R.styleable.StatusViewScroller_circleColorIncomplete, circleFillColor)
453 | circleStrokeColorIncomplete = a.getColor(R.styleable.StatusViewScroller_circleStrokeColorIncomplete, circleStrokeColor)
454 | circleStrokeColorCurrent = a.getColor(R.styleable.StatusViewScroller_circleStrokeColorCurrent, circleStrokeColorIncomplete)
455 | circleFillColorCurrent = a.getColor(R.styleable.StatusViewScroller_circleColorCurrent, circleFillColorIncomplete)
456 | currentStatusZoom = a.getFloat(R.styleable.StatusViewScroller_currentStepZoom, currentStatusZoom)
457 | alignStatusWithCurrent = a.getBoolean(R.styleable.StatusViewScroller_alignStatusWithCurrent, alignStatusWithCurrent)
458 |
459 | val entries = a.getTextArray(R.styleable.StatusViewScroller_android_entries)
460 | if (entries != null) {
461 | for (entry in entries) {
462 | statusData.add(StatusInfo(entry.toString()))
463 | }
464 | }
465 |
466 | try {
467 | val resource: Int = a.getResourceId(R.styleable.StatusViewScroller_statusFont, -1)
468 | if (resource != -1) {
469 | statusTypeface = ResourcesCompat.getFont(getContext(), resource)
470 | }
471 | } catch (e: Exception) {
472 | e.printStackTrace()
473 | }
474 |
475 | try {
476 | val resource: Int = a.getResourceId(R.styleable.StatusViewScroller_labelFont, -1)
477 | if (resource != -1) {
478 | labelsTypeface = ResourcesCompat.getFont(getContext(), resource)
479 | }
480 | } catch (e: Exception) {
481 | e.printStackTrace()
482 | }
483 |
484 |
485 | } finally {
486 | a.recycle()
487 | }
488 |
489 |
490 |
491 |
492 | initCirclePaints()
493 |
494 |
495 | mLinePaint = Paint(Paint.ANTI_ALIAS_FLAG)
496 | mLinePaint.style = Paint.Style.STROKE
497 | mLinePaint.strokeWidth = lineWidth
498 | mLinePaint.color = lineColor
499 |
500 |
501 | mTextPaintStatus = TextPaint(Paint.ANTI_ALIAS_FLAG)
502 | mTextPaintStatus.style = Paint.Style.FILL
503 | mTextPaintStatus.textAlign = Paint.Align.CENTER
504 | mTextPaintStatus.color = textColorStatus
505 | mTextPaintStatus.textSize = textSizeStatus
506 | statusTypeface?.run {
507 | mTextPaintStatus.typeface = this
508 | }
509 |
510 | mLinePaintIncomplete = Paint(mLinePaint)
511 | mLinePaintIncomplete.color = lineColorIncomplete
512 |
513 | mLinePaintCurrent = Paint(mLinePaint)
514 | mLinePaintCurrent.color = lineColorCurrent
515 |
516 | mTextPaintLabels = TextPaint(Paint.ANTI_ALIAS_FLAG)
517 | mTextPaintLabels.style = Paint.Style.FILL
518 | mTextPaintLabels.textAlign = Paint.Align.CENTER
519 | mTextPaintLabels.textSize = textSizeLabels
520 | mTextPaintLabels.color = textColorLabels
521 |
522 |
523 | mTextPaintLabelsIncomplete = TextPaint(mTextPaintLabels)
524 | mTextPaintLabelsIncomplete.color = textColorLabelsIncomplete
525 |
526 | mTextPaintLabelCurrent = TextPaint(mTextPaintLabels)
527 | mTextPaintLabelCurrent.color = textColorLabelCurrent
528 |
529 | labelsTypeface?.run {
530 | mTextPaintLabels.typeface = this
531 | mTextPaintLabelsIncomplete.typeface = this
532 | mTextPaintLabelCurrent.typeface = this
533 | }
534 |
535 | propsIntialisedOnce = true
536 | }
537 |
538 | private fun initCirclePaints() {
539 | if (containsFlag(circleColorType, CIRCLE_COLOR_TYPE_STROKE)) {
540 | if (mCircleStrokePaint == null) {
541 |
542 | mCircleStrokePaint = Paint(Paint.ANTI_ALIAS_FLAG)
543 | mCircleStrokePaint?.style = Paint.Style.STROKE
544 | mCircleStrokePaint?.strokeWidth = circleStrokeWidth
545 | mCircleStrokePaint?.color = circleStrokeColor
546 | }
547 |
548 | if (isShowingIncompleteStatus()) {
549 | if (mCircleStrokePaintIncomplete == null) {
550 | mCircleStrokePaintIncomplete = Paint(mCircleStrokePaint)
551 | mCircleStrokePaintIncomplete?.color = circleStrokeColorIncomplete
552 | }
553 | }
554 |
555 | if (isShowingCurrentStatus()) {
556 | if (mCircleStrokePaintCurrent == null) {
557 | mCircleStrokePaintCurrent = Paint(mCircleStrokePaint)
558 | mCircleStrokePaintCurrent?.color = circleStrokeColorCurrent
559 | }
560 | }
561 |
562 | } else {
563 | circleStrokeWidth = 0.0f
564 | mCircleStrokePaint = null
565 | mCircleStrokePaintIncomplete = null
566 | mCircleStrokePaintCurrent = null
567 | }
568 |
569 | if (containsFlag(circleColorType, CIRCLE_COLOR_TYPE_FILL)) {
570 | if (mCircleFillPaint == null) {
571 | mCircleFillPaint = Paint(Paint.ANTI_ALIAS_FLAG)
572 | mCircleFillPaint?.style = Paint.Style.FILL
573 | mCircleFillPaint?.color = circleFillColor
574 | }
575 | if (isShowingIncompleteStatus()) {
576 | if (mCircleFillPaintIncomplete == null) {
577 | mCircleFillPaintIncomplete = Paint(mCircleFillPaint)
578 | mCircleFillPaintIncomplete?.color = circleFillColorIncomplete
579 | }
580 | }
581 |
582 | if (isShowingCurrentStatus()) {
583 | if (mCircleFillPaintCurrent == null) {
584 | mCircleFillPaintCurrent = Paint(mCircleFillPaint)
585 | mCircleFillPaintCurrent?.color = circleFillColorCurrent
586 | }
587 | }
588 | } else {
589 | mCircleFillPaint = null
590 | mCircleFillPaintIncomplete = null
591 | mCircleFillPaintCurrent = null
592 | }
593 | }
594 |
595 |
596 | private fun isShowingIncompleteStatus() =
597 | currentCount > INVALID_STATUS_COUNT && currentCount < stepCount
598 |
599 | private fun isShowingCurrentStatus() =
600 | currentCount in 1..stepCount
601 |
602 |
603 | override fun getSuggestedMinimumWidth(): Int {
604 |
605 |
606 | if (stepCount <= 0) {
607 | return 0
608 | }
609 |
610 |
611 | lineLengthComputed = lineLength
612 | var extraWidth = if (strictObeyLineLength) {// extra width required by status at extreme positions
613 | setWidthDataForObeyingLineLength()
614 | } else {
615 | setWidthDataForObeyingStatusText()
616 | }
617 |
618 | if (stepCount == 1) {
619 | extraWidth *= 2
620 | }
621 |
622 | if (isShowingCurrentStatus()) {
623 | extraWidth += (currentStatusRadius - circleRadius) * 2
624 | }
625 |
626 |
627 | return ((stepCount * (2 * (circleRadius + (circleStrokeWidth / 2)))) +
628 | ((stepCount - 1) * (lineLengthComputed + (lineGap * 2))) + extraWidth).toInt()
629 | }
630 |
631 |
632 | override fun getSuggestedMinimumHeight(): Int {
633 | if (stepCount <= 0) {
634 | return 0
635 | }
636 |
637 | var maxLabelHeight = 0.0f
638 |
639 | for (item in statusData) {
640 | maxLabelHeight = Math.max(maxLabelHeight, setLabelsHeight(mTextPaintStatus, item))
641 | }
642 |
643 | val circleAndStatusTextHeight = if (isShowingCurrentStatus()) {
644 | val topRadius = currentStatusRadius
645 | val labelHeightCurrentStatus = if (statusData.size > 0 && currentCountIndex() in 0..(statusData.size-1)) {
646 | statusData[currentCountIndex()].height
647 | } else {
648 | 0.0f
649 | }
650 |
651 | val bottomRadiusAndText = Math.max(currentStatusRadius + labelHeightCurrentStatus, circleRadius + maxLabelHeight)
652 |
653 | topRadius + bottomRadiusAndText
654 |
655 | } else {
656 | circleRadius * 2 + maxLabelHeight
657 | }
658 |
659 | val statusTopMargin = if (statusData.size > 0) {
660 | statusTopMargin
661 | } else {
662 | 0.0f
663 | }
664 |
665 | return (circleAndStatusTextHeight + circleStrokeWidth + statusTopMargin).toInt()
666 | }
667 |
668 |
669 | override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
670 | val desiredWidth = paddingLeft + paddingRight + suggestedMinimumWidth
671 | val desiredHeight = paddingTop + paddingBottom + suggestedMinimumHeight
672 |
673 | val measuredWidth = resolveSize(desiredWidth, widthMeasureSpec)
674 | val measuredHeight = resolveSize(desiredHeight, heightMeasureSpec)
675 |
676 | setMeasuredDimension(measuredWidth, measuredHeight)
677 | }
678 |
679 | override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
680 | setDrawingDimensions()
681 | }
682 |
683 | override fun onDraw(canvas: Canvas?) {
684 | super.onDraw(canvas)
685 | for (item in drawingData) {
686 |
687 | if (item.circleItem.fillPaint != null) {
688 | canvas?.drawCircle(item.circleItem.center.x, item.circleItem.center.y, item.circleItem.radius, item.circleItem.fillPaint)
689 |
690 | }
691 | if (item.circleItem.strokePaint != null) {
692 | canvas?.drawCircle(item.circleItem.center.x, item.circleItem.center.y, item.circleItem.radius, item.circleItem.strokePaint)
693 |
694 | }
695 | if (item.textData != null) {
696 |
697 | if (item.textData.drawableItem != null) {
698 | val drawableItem: DrawableItem = item.textData.drawableItem
699 | drawableItem.drawable.bounds = drawableItem.rect
700 | item.textData.drawableItem.drawable.draw(canvas)
701 |
702 | } else if (item.textData.text != null && item.textData.paint != null) {
703 |
704 | canvas?.drawText(item.textData.text, item.textData.x, item.textData.y, item.textData.paint)
705 |
706 | }
707 |
708 | }
709 | if (item.labelData != null) {
710 |
711 | if (item.labelData.staticLayout != null) {
712 |
713 | canvas?.save()
714 | canvas?.translate(item.labelData.x, item.labelData.y)
715 | item.labelData.staticLayout.draw(canvas)
716 | canvas?.restore()
717 |
718 | }
719 |
720 | }
721 | if (item.lineItem != null) {
722 | canvas?.drawLine(item.lineItem.start.x, item.lineItem.start.y,
723 | item.lineItem.end.x, item.lineItem.end.y, item.lineItem.paint)
724 | }
725 |
726 |
727 | }
728 | }
729 |
730 |
731 | /**
732 | * Sets data in DrawingData class that is to be drawn by Canvas
733 | */
734 | private fun setDrawingDimensions() {
735 |
736 |
737 | val lastPoint = PointF()//For keeping reference where last point was drawn
738 | lastPoint.x = paddingLeft.toFloat() + (circleStrokeWidth / 2)
739 | lastPoint.y = paddingTop.toFloat() + (circleRadius + (circleStrokeWidth / 2))
740 | if (isShowingCurrentStatus()) lastPoint.y += currentStatusRadius - circleRadius
741 | for (pos in 0 until stepCount) {
742 |
743 | var circleStrokePaint: Paint?
744 | var circleFillPaint: Paint?
745 | var textPaintLabel: TextPaint
746 | var linePaint: Paint
747 | var itemDrawable: Drawable?
748 |
749 | var circleRadius = this.circleRadius
750 | if (isShowingCurrentStatus() && pos == (currentCount - 1)) {
751 | circleRadius = currentStatusRadius
752 | circleStrokePaint = mCircleStrokePaintCurrent
753 | circleFillPaint = mCircleFillPaintCurrent
754 | textPaintLabel = mTextPaintLabelCurrent
755 | linePaint = mLinePaintCurrent
756 | itemDrawable = currentDrawable
757 | } else if (isShowingIncompleteStatus() && pos in (currentCount)..stepCount) {
758 | circleStrokePaint = mCircleStrokePaintIncomplete
759 | circleFillPaint = mCircleFillPaintIncomplete
760 | textPaintLabel = mTextPaintLabelsIncomplete
761 | linePaint = mLinePaintIncomplete
762 | itemDrawable = incompleteDrawable
763 |
764 | } else {
765 |
766 | circleStrokePaint = this.mCircleStrokePaint
767 | circleFillPaint = this.mCircleFillPaint
768 | textPaintLabel = this.mTextPaintLabels
769 | linePaint = this.mLinePaint
770 | itemDrawable = completeDrawable
771 | }
772 |
773 |
774 | var lineItem: LineItem? = null
775 | var statusItemText: LabelItemText? = null
776 | var labelItemText: StatusItemText? = null
777 |
778 |
779 | if (pos == 0) {
780 | if (statusData.size > 0) {
781 | lastPoint.x += Math.max(0.0f, (statusData[0].width - minStatusWidthExtremes(pos)) / 2)
782 | }
783 | } else {
784 | lastPoint.x += lineGap
785 | lineItem = LineItem(PointF(lastPoint.x, lastPoint.y), PointF(lastPoint.x + lineLengthComputed, lastPoint.y), linePaint)
786 | lastPoint.x = lineItem.end.x + lineGap + (circleStrokeWidth / 2)
787 | }
788 |
789 |
790 | val circleItem = CircleItem(PointF((lastPoint.x + circleRadius), lastPoint.y), circleRadius, circleStrokePaint, circleFillPaint)
791 | lastPoint.x += ((circleRadius) * 2.0f) + (circleStrokeWidth / 2)
792 |
793 | if (pos < statusData.size) {
794 | val radii = if (isShowingCurrentStatus() && alignStatusWithCurrent) currentStatusRadius else circleRadius
795 | labelItemText = StatusItemText(circleItem.center.x, circleItem.center.y + radii + circleStrokeWidth / 2 + statusTopMargin, statusData[pos].staticLayout)
796 | }
797 |
798 |
799 |
800 | if (itemDrawable != null) {
801 | val width = itemDrawable.intrinsicWidth
802 | val height = itemDrawable.intrinsicHeight
803 | val xPos = circleItem.center.x.toInt()
804 | val yPos = circleItem.center.y.toInt()
805 | val drawableRect = Rect(xPos - width / 2, yPos - height / 2, xPos + width / 2, yPos + height / 2)
806 | statusItemText = LabelItemText(drawableItem = DrawableItem(drawableRect, itemDrawable))
807 |
808 | } else if (drawLabels) {
809 | val text: String = (pos + 1).toString()
810 | val measuringRect = Rect()
811 | textPaintLabel.getTextBounds(text, 0, text.length, measuringRect)
812 | statusItemText = LabelItemText(text, textPaintLabel, circleItem.center.x, circleItem.center.y - measuringRect.exactCenterY())
813 |
814 | }
815 |
816 | drawingData.add(Item(statusItemText, circleItem, lineItem, labelItemText))
817 |
818 | }
819 |
820 |
821 | }
822 |
823 |
824 | /**
825 | *
826 | For non-extreme statuses:
827 | * Function sets the width value to minStatusWidth
828 | *
829 | * For extreme statuses:
830 | * It calculates min of extreme width required in bounds of lineLength as
831 | * directly adding minStatusWidth may end up adding extra padding to view
832 | */
833 | private fun setWidthDataForObeyingLineLength(): Float {
834 | var adjacentExtraWidthForView = 0.0f
835 |
836 | for (pos in 0 until statusData.size) {
837 |
838 | val item = statusData[pos]
839 | when (pos) {
840 | 0, stepCountIndex() -> {
841 |
842 | val minStatusWidthExtremes = minStatusWidthExtremes(pos)
843 | val minStatusWidth = minStatusWidth(pos)
844 | val statusWidth = getTextWidth(mTextPaintStatus, item.text)
845 | var extraExtremeWidth = 0.0f
846 |
847 | if (statusWidth > minStatusWidthExtremes) {
848 | extraExtremeWidth = Math.min(minStatusWidth - minStatusWidthExtremes, statusWidth - minStatusWidthExtremes) / 2
849 | }
850 |
851 | item.width = minStatusWidthExtremes + 2 * extraExtremeWidth
852 | adjacentExtraWidthForView += extraExtremeWidth
853 |
854 |
855 | }
856 | else -> item.width = minStatusWidth(pos)
857 |
858 | }
859 | }
860 | return adjacentExtraWidthForView
861 | }
862 |
863 |
864 | /**
865 | * Sets required width in status data for every status
866 | * This method increases linelength if required i.e
867 | * it makes sure every line of status word does not cross over to next line
868 | *
869 | */
870 | private fun setWidthDataForObeyingStatusText(): Float {
871 | var extraWidth = 0.0f
872 | if (statusData.size == 0) return extraWidth
873 |
874 | val widestLineData: StatusTextWidthInfo = getStatusTextWidthInfo(statusData.map { it.text }, mTextPaintStatus)
875 |
876 | val minStatusWidthWidestPos = minStatusWidth(widestLineData.widestStatus.pos)
877 | if (widestLineData.widestStatus.width > minStatusWidthWidestPos) {
878 | lineLengthComputed += widestLineData.widestStatus.width - minStatusWidthWidestPos
879 |
880 | }
881 |
882 | widestLineData.subordinateWidestStatus?.run {
883 | //in case increasing linelength as per widest Status does not satisfy statusWidth for second widest
884 | //This can occur if widestStatus belongs to currentStatus and has a zoomed radius
885 | val minStatusWidth = minStatusWidth(pos)
886 |
887 | if (width > minStatusWidth) {
888 | lineLengthComputed += width - minStatusWidth
889 | }
890 | }
891 |
892 |
893 | var addMinStatusMargin = false
894 | for (pos in 0 until statusData.size) {
895 | val item = statusData[pos]
896 | when (pos) {
897 | 0, stepCountIndex() -> {
898 |
899 | item.width = if (pos == 0) {
900 | widestLineData.extremeLeftStatusWidth
901 | } else {
902 | widestLineData.extremeRightStatusWidth
903 | }
904 |
905 | val extraExtremesWidth = (item.width - minStatusWidthExtremes(pos)) / 2
906 |
907 | if (extraExtremesWidth > 0) {
908 | extraWidth += extraExtremesWidth
909 | }
910 |
911 | }
912 | else -> item.width = widestLineData.widestStatus.width
913 | }
914 |
915 | if (minStatusAdjacentMargin > 0 && !addMinStatusMargin && pos in 1 until statusData.size) {
916 | if (minStatusWidth(pos) + minStatusWidth(pos - 1) - (item.width + statusData[pos - 1].width) < minStatusAdjacentMargin) {
917 | addMinStatusMargin = true
918 | }
919 |
920 | }
921 | }
922 | if (addMinStatusMargin) {
923 | //add additional padding only if it is required
924 | lineLengthComputed += minStatusAdjacentMargin
925 | }
926 | return extraWidth
927 | }
928 |
929 |
930 | private fun minStatusWidth(pos: Int): Float {
931 |
932 | var circleRadius = this.circleRadius
933 | val lineWidth = (lineLengthComputed + lineGap * 2)
934 |
935 | if (isShowingCurrentStatus() && pos == currentCountIndex()) {
936 | circleRadius = currentStatusRadius
937 | }
938 |
939 | return (2 * circleRadius + circleStrokeWidth) + lineWidth
940 | }
941 |
942 | private fun minStatusWidthExtremes(pos: Int): Float {
943 | var circleRadius = this.circleRadius
944 |
945 | if (isShowingCurrentStatus() && pos == currentCountIndex()) {
946 | circleRadius = currentStatusRadius
947 | }
948 | return (2 * circleRadius + circleStrokeWidth)
949 | }
950 |
951 | /**
952 | * Maximum width that a text would need to be drawn
953 | */
954 | private fun getTextWidth(paint: Paint, text: String): Float {
955 | return paint.measureText(text)
956 | }
957 |
958 |
959 | /**
960 | * @param textPaint textPaint to be set on Labels
961 | * @param labelInfo LabelInfo which contains width and text
962 | * @return Height that the label would require
963 | */
964 | private fun setLabelsHeight(textPaint: TextPaint, labelInfo: StatusInfo): Float {
965 | val staticLayoutHeight = getStaticLayout(labelInfo.text, textPaint, labelInfo.width)
966 | labelInfo.staticLayout = staticLayoutHeight
967 | labelInfo.height = staticLayoutHeight.height.toFloat()
968 | return labelInfo.height
969 | }
970 |
971 |
972 | /**
973 | * @param text text to be shown
974 | * @param textPaint textPaint to be set on text
975 | * @param width available width
976 | * @return Static Layout which decides the height and auto-adjusts multiline text
977 | */
978 | private fun getStaticLayout(text: String, textPaint: TextPaint, width: Float): StaticLayout {
979 | val alignment = Layout.Alignment.ALIGN_NORMAL
980 | val spacingMultiplier = 1f
981 | val spacingAddition = 0f
982 | val includePadding = false
983 | return StaticLayout(text, textPaint, width.toInt(), alignment, spacingMultiplier, spacingAddition, includePadding)
984 | }
985 |
986 |
987 | /**
988 | * This class stores info for widest Status info length which helps in deciding correct line length of StatusView
989 | * @param widestStatus (widest line in all the texts)
990 | * @param subordinateWidestStatus second Widest Status this is only set if widest status belongs to currentStatus
991 | * @param extremeLeftStatusWidth Widest line in status at extreme left
992 | * @param extremeRightStatusWidth Widest line in status at extreme right
993 | */
994 | class StatusTextWidthInfo(var widestStatus: StatusWidth, var subordinateWidestStatus: StatusWidth? = null,
995 | var extremeLeftStatusWidth: Float = 0.0f, var extremeRightStatusWidth: Float = 0.0f)
996 |
997 | /**
998 | * Stores Status Width Data
999 | * @param width widestStatus
1000 | * @param pos Status position
1001 | */
1002 | class StatusWidth(var width: Float = 0.0f, var pos: Int = -1)
1003 |
1004 | /**
1005 | * Calculates parameters described in StatusTextWidthInfo
1006 | * @param list List of string for all statuses
1007 | * @param paint Paint required to draw the statuses
1008 | *
1009 | */
1010 | private fun getStatusTextWidthInfo(list: List, paint: TextPaint): StatusTextWidthInfo {
1011 |
1012 | val widestStatus = StatusWidth()
1013 | var subordinateWidestStatus: StatusWidth? = null
1014 | val statusWidthInfo = StatusTextWidthInfo(widestStatus)
1015 |
1016 |
1017 | for (pos in 0 until list.size) {
1018 |
1019 | val result = getStatusWidth(list[pos], paint)
1020 |
1021 | if (isShowingCurrentStatus() && pos == (currentCountIndex()) && result > widestStatus.width) {
1022 |
1023 | subordinateWidestStatus = StatusWidth(widestStatus.width, widestStatus.pos)
1024 | widestStatus.width = result
1025 | widestStatus.pos = pos
1026 |
1027 | } else if (result > widestStatus.width) {
1028 |
1029 | widestStatus.width = result
1030 | widestStatus.pos = pos
1031 | subordinateWidestStatus = null
1032 |
1033 | } else if (subordinateWidestStatus != null && result > subordinateWidestStatus.width) {
1034 |
1035 | subordinateWidestStatus.width = result
1036 | subordinateWidestStatus.pos = pos
1037 | }
1038 |
1039 | when (pos) {
1040 | 0 -> statusWidthInfo.extremeLeftStatusWidth = result
1041 | stepCountIndex() -> statusWidthInfo.extremeRightStatusWidth = result
1042 | }
1043 |
1044 | }
1045 |
1046 | statusWidthInfo.widestStatus = widestStatus
1047 | statusWidthInfo.subordinateWidestStatus = subordinateWidestStatus
1048 |
1049 | return statusWidthInfo
1050 |
1051 | }
1052 |
1053 | /**
1054 | * @param text Status Text
1055 | * @param paint Text paint for the text
1056 | * @return widest line in a particular status
1057 | */
1058 | private fun getStatusWidth(text: String, paint: TextPaint): Float {
1059 |
1060 | val arr: List = text.split('\n')
1061 | var result = 0.0f
1062 | for (sub in arr) {
1063 | val subWidth = paint.measureText(sub)
1064 | result = if (subWidth > result) subWidth else result
1065 | }
1066 |
1067 | return result
1068 |
1069 |
1070 | }
1071 |
1072 |
1073 | /**
1074 | * checks if a flagSet contains a flag
1075 | *
1076 | */
1077 |
1078 | private fun containsFlag(flagSet: Int, flag: Int): Boolean {
1079 | return flagSet or flag == flagSet
1080 | }
1081 |
1082 |
1083 | /**
1084 | * actual position in list for currentCount
1085 | */
1086 | private fun currentCountIndex() = currentCount - 1
1087 |
1088 | /**
1089 | * actual position in list for stepCount
1090 | */
1091 | private fun stepCountIndex() = stepCount - 1
1092 |
1093 |
1094 | /**
1095 | * Delegate property used to requestLayout on value set after executing a custom function
1096 | */
1097 | inner class OnLayoutProp(private var field: T, private inline var func: () -> Unit = {}) {
1098 | operator fun setValue(thisRef: Any?, p: KProperty<*>, v: T) {
1099 | field = v
1100 | if (propsIntialisedOnce) {
1101 | drawingData.clear()
1102 | func()
1103 | requestLayout()
1104 |
1105 | }
1106 |
1107 | }
1108 |
1109 | operator fun getValue(thisRef: Any?, p: KProperty<*>): T {
1110 | return field
1111 | }
1112 |
1113 | }
1114 |
1115 | /**
1116 | * Delegate Property used to invalidate on value set after executing a custom function
1117 | */
1118 | inner class OnValidateProp(private var field: T, private inline var func: () -> Unit = {}) {
1119 | operator fun setValue(thisRef: Any?, p: KProperty<*>, v: T) {
1120 | field = v
1121 | if (propsIntialisedOnce) {
1122 | func()
1123 | invalidate()
1124 |
1125 | }
1126 |
1127 | }
1128 |
1129 | operator fun getValue(thisRef: Any?, p: KProperty<*>): T {
1130 | return field
1131 | }
1132 |
1133 | }
1134 |
1135 | private fun Float.pxValue(unit: Int = TypedValue.COMPLEX_UNIT_DIP): Float {
1136 | return TypedValue.applyDimension(unit, this, resources.displayMetrics)
1137 | }
1138 |
1139 | fun getScrollPosForStep(count: Int): Int {
1140 | val posIndex = count - 1
1141 | return if (posIndex > 0 && posIndex < drawingData.size) {
1142 | drawingData[posIndex].circleItem.center.x.toInt()
1143 | } else {
1144 | 0
1145 | }
1146 | }
1147 |
1148 | }
--------------------------------------------------------------------------------
/stepview/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/stepview/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | stepview
3 |
4 |
--------------------------------------------------------------------------------