├── .github
└── workflows
│ └── publish.yml
├── .gitignore
├── LICENSE.txt
├── README.md
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── images
├── image.png
└── image_rtl.png
├── mapscaleview
├── .gitignore
├── build.gradle
├── gradle.properties
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── github
│ │ └── pengrad
│ │ └── mapscaleview
│ │ ├── Drawer.java
│ │ ├── MapScaleModel.java
│ │ ├── MapScaleView.java
│ │ ├── Scale.java
│ │ ├── Scales.java
│ │ └── ViewConfig.java
│ └── res
│ └── values
│ └── attrs.xml
├── sample
├── .gitignore
├── build.gradle
├── debug.keystore
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── github
│ │ └── pengrad
│ │ └── mapscaleview
│ │ └── sample
│ │ ├── GenericActivity.kt
│ │ ├── GoogleMapsActivity.kt
│ │ ├── MainActivity.kt
│ │ └── MapboxActivity.kt
│ └── res
│ ├── layout
│ ├── activity_googlemaps.xml
│ ├── activity_main.xml
│ ├── activity_mapbox.xml
│ └── sample_layout.xml
│ ├── mipmap-hdpi
│ └── ic_launcher.png
│ ├── mipmap-mdpi
│ └── ic_launcher.png
│ ├── mipmap-xhdpi
│ └── ic_launcher.png
│ ├── mipmap-xxhdpi
│ └── ic_launcher.png
│ ├── mipmap-xxxhdpi
│ └── ic_launcher.png
│ └── values
│ ├── colors.xml
│ ├── strings.xml
│ └── styles.xml
├── settings.gradle
└── upload-jcenter.gradle
/.github/workflows/publish.yml:
--------------------------------------------------------------------------------
1 | name: Publish Bintray
2 | on:
3 | release:
4 | types: [published]
5 |
6 | jobs:
7 | publish:
8 | runs-on: ubuntu-latest
9 |
10 | steps:
11 | - uses: actions/checkout@v1
12 |
13 | - name: Bintray Upload
14 | env:
15 | bintrayUser: ${{ secrets.BINTRAY_USER }}
16 | bintrayApiKey: ${{ secrets.BINTRAY_API_KEY }}
17 | run: ./gradlew bintrayUpload
18 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .classpath
2 | .project
3 | .settings
4 | eclipsebin
5 |
6 | bin
7 | gen
8 | build
9 | out
10 | lib
11 |
12 | .idea
13 | *.iml
14 | classes
15 |
16 | obj
17 |
18 | .DS_Store
19 |
20 | # Gradle
21 | .gradle
22 | jniLibs
23 | build
24 | local.properties
25 | reports
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
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 | # Map Scale View
2 | [  ](https://bintray.com/pengrad/maven/mapscaleview/_latestVersion)
3 | [](https://android-arsenal.com/details/1/4541)
4 |
5 | Scale view for any Android Maps SDK (not only Google Maps)
6 |
7 | 
8 |
9 | ## Contributing
10 | I encourage you to participate in this project. Feel free to open issues with bugs or ideas, fork and send pull requests.
11 | Check [list of "help wanted" issues](https://github.com/pengrad/MapScaleView/issues?q=is%3Aissue+is%3Aopen+label%3A%22help+wanted%22) to start with.
12 |
13 | ## Usage
14 | ```groovy
15 | dependencies {
16 | implementation 'com.github.pengrad:mapscaleview:1.6.0'
17 | }
18 | ```
19 |
20 | Include in layout file over map
21 | ```xml
22 |
28 |
29 |
34 |
35 |
41 |
42 | ```
43 |
44 | With miles or custom style
45 | ```xml
46 |
59 | ```
60 |
61 | Update on map changed
62 | ```kotlin
63 | val scaleView: MapScaleView = findViewById(R.id.scaleView)
64 | val cameraPosition = map.cameraPosition
65 | // need to pass zoom and latitude
66 | scaleView.update(cameraPosition.zoom, cameraPosition.target.latitude)
67 | ```
68 |
69 | Full example with subscribing to map events and updating scale view
70 | ```kotlin
71 | override fun onMapReady(googleMap: GoogleMap) {
72 | map = googleMap
73 | googleMap.setOnCameraMoveListener(this)
74 | googleMap.setOnCameraIdleListener(this)
75 | }
76 |
77 | override fun onCameraMove() {
78 | val cameraPosition = map.cameraPosition
79 | scaleView.update(cameraPosition.zoom, cameraPosition.target.latitude)
80 | }
81 |
82 | override fun onCameraIdle() {
83 | val cameraPosition = map.cameraPosition
84 | scaleView.update(cameraPosition.zoom, cameraPosition.target.latitude)
85 | }
86 | ```
87 |
88 | Refer to the sample project on how to use scale view with other Android Maps SDK (Mapbox).
89 |
90 | ## Customization
91 | ```java
92 | mapScaleView.setColor(@ColorInt int color)
93 | mapScaleView.setTextSize(float textSize)
94 | mapScaleView.setStrokeWidth(float strokeWidth)
95 | mapScaleView.setTextFont(Typeface font)
96 |
97 | // enable/disable white outline, enabled by default
98 | mapScaleView.setOutlineEnabled(false)
99 |
100 | mapScaleView.metersAndMiles() // default
101 | mapScaleView.metersOnly()
102 | mapScaleView.milesOnly()
103 |
104 | // expand scale bar from right to left, disabled by default
105 | mapScaleView.setExpandRtlEnabled(true)
106 | ```
107 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | repositories {
3 | google()
4 | jcenter()
5 | }
6 | dependencies {
7 | classpath 'com.android.tools.build:gradle:3.5.3'
8 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4'
9 | classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
10 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.61"
11 |
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | google()
18 | jcenter()
19 | }
20 | }
21 |
22 | task clean(type: Delete) {
23 | delete rootProject.buildDir
24 | }
25 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | GROUP=com.github.pengrad
2 | VERSION_NAME=1.6.0
3 |
4 | POM_DESCRIPTION=Scale bar for Android Maps
5 |
6 | POM_URL=https://github.com/pengrad/MapScaleView
7 | POM_SCM_URL=https://github.com/pengrad/MapScaleView
8 | POM_SCM_CONNECTION=scm:git:https://github.com/pengrad/MapScaleView.git
9 | POM_SCM_DEV_CONNECTION=scm:git:ssh://git@github.com/pengrad/MapScaleView.git
10 |
11 | POM_LICENCE_NAME=The Apache Software License, Version 2.0
12 | POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt
13 | POM_LICENCE_DIST=repo
14 |
15 | POM_DEVELOPER_ID=pengrad
16 | POM_DEVELOPER_NAME=Stas Parshin
17 |
18 | BINTRAY_REPO=maven
19 | BINTRAY_LICENSE=Apache-2.0
20 |
21 | IV_TOKEN="4oJ3G7Q8rfatm8uFTzN5uw=="
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pengrad/MapScaleView/426beb961858591289a0f08ef7cdfb9b3a5378d3/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | #
4 | # Copyright 2015 the original author or authors.
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # https://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | ##############################################################################
20 | ##
21 | ## Gradle start up script for UN*X
22 | ##
23 | ##############################################################################
24 |
25 | # Attempt to set APP_HOME
26 | # Resolve links: $0 may be a link
27 | PRG="$0"
28 | # Need this for relative symlinks.
29 | while [ -h "$PRG" ] ; do
30 | ls=`ls -ld "$PRG"`
31 | link=`expr "$ls" : '.*-> \(.*\)$'`
32 | if expr "$link" : '/.*' > /dev/null; then
33 | PRG="$link"
34 | else
35 | PRG=`dirname "$PRG"`"/$link"
36 | fi
37 | done
38 | SAVED="`pwd`"
39 | cd "`dirname \"$PRG\"`/" >/dev/null
40 | APP_HOME="`pwd -P`"
41 | cd "$SAVED" >/dev/null
42 |
43 | APP_NAME="Gradle"
44 | APP_BASE_NAME=`basename "$0"`
45 |
46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
48 |
49 | # Use the maximum available, or set MAX_FD != -1 to use that value.
50 | MAX_FD="maximum"
51 |
52 | warn () {
53 | echo "$*"
54 | }
55 |
56 | die () {
57 | echo
58 | echo "$*"
59 | echo
60 | exit 1
61 | }
62 |
63 | # OS specific support (must be 'true' or 'false').
64 | cygwin=false
65 | msys=false
66 | darwin=false
67 | nonstop=false
68 | case "`uname`" in
69 | CYGWIN* )
70 | cygwin=true
71 | ;;
72 | Darwin* )
73 | darwin=true
74 | ;;
75 | MINGW* )
76 | msys=true
77 | ;;
78 | NONSTOP* )
79 | nonstop=true
80 | ;;
81 | esac
82 |
83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
84 |
85 | # Determine the Java command to use to start the JVM.
86 | if [ -n "$JAVA_HOME" ] ; then
87 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
88 | # IBM's JDK on AIX uses strange locations for the executables
89 | JAVACMD="$JAVA_HOME/jre/sh/java"
90 | else
91 | JAVACMD="$JAVA_HOME/bin/java"
92 | fi
93 | if [ ! -x "$JAVACMD" ] ; then
94 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
95 |
96 | Please set the JAVA_HOME variable in your environment to match the
97 | location of your Java installation."
98 | fi
99 | else
100 | JAVACMD="java"
101 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
102 |
103 | Please set the JAVA_HOME variable in your environment to match the
104 | location of your Java installation."
105 | fi
106 |
107 | # Increase the maximum file descriptors if we can.
108 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
109 | MAX_FD_LIMIT=`ulimit -H -n`
110 | if [ $? -eq 0 ] ; then
111 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
112 | MAX_FD="$MAX_FD_LIMIT"
113 | fi
114 | ulimit -n $MAX_FD
115 | if [ $? -ne 0 ] ; then
116 | warn "Could not set maximum file descriptor limit: $MAX_FD"
117 | fi
118 | else
119 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
120 | fi
121 | fi
122 |
123 | # For Darwin, add options to specify how the application appears in the dock
124 | if $darwin; then
125 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
126 | fi
127 |
128 | # For Cygwin or MSYS, switch paths to Windows format before running java
129 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
130 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
131 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
132 | JAVACMD=`cygpath --unix "$JAVACMD"`
133 |
134 | # We build the pattern for arguments to be converted via cygpath
135 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
136 | SEP=""
137 | for dir in $ROOTDIRSRAW ; do
138 | ROOTDIRS="$ROOTDIRS$SEP$dir"
139 | SEP="|"
140 | done
141 | OURCYGPATTERN="(^($ROOTDIRS))"
142 | # Add a user-defined pattern to the cygpath arguments
143 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
144 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
145 | fi
146 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
147 | i=0
148 | for arg in "$@" ; do
149 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
150 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
151 |
152 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
153 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
154 | else
155 | eval `echo args$i`="\"$arg\""
156 | fi
157 | i=`expr $i + 1`
158 | done
159 | case $i in
160 | 0) set -- ;;
161 | 1) set -- "$args0" ;;
162 | 2) set -- "$args0" "$args1" ;;
163 | 3) set -- "$args0" "$args1" "$args2" ;;
164 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;;
165 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
166 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
167 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
168 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
169 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
170 | esac
171 | fi
172 |
173 | # Escape application args
174 | save () {
175 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
176 | echo " "
177 | }
178 | APP_ARGS=`save "$@"`
179 |
180 | # Collect all arguments for the java command, following the shell quoting and substitution rules
181 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
182 |
183 | exec "$JAVACMD" "$@"
184 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 |
17 | @if "%DEBUG%" == "" @echo off
18 | @rem ##########################################################################
19 | @rem
20 | @rem Gradle startup script for Windows
21 | @rem
22 | @rem ##########################################################################
23 |
24 | @rem Set local scope for the variables with windows NT shell
25 | if "%OS%"=="Windows_NT" setlocal
26 |
27 | set DIRNAME=%~dp0
28 | if "%DIRNAME%" == "" set DIRNAME=.
29 | set APP_BASE_NAME=%~n0
30 | set APP_HOME=%DIRNAME%
31 |
32 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
33 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
34 |
35 | @rem Find java.exe
36 | if defined JAVA_HOME goto findJavaFromJavaHome
37 |
38 | set JAVA_EXE=java.exe
39 | %JAVA_EXE% -version >NUL 2>&1
40 | if "%ERRORLEVEL%" == "0" goto init
41 |
42 | echo.
43 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
44 | echo.
45 | echo Please set the JAVA_HOME variable in your environment to match the
46 | echo location of your Java installation.
47 |
48 | goto fail
49 |
50 | :findJavaFromJavaHome
51 | set JAVA_HOME=%JAVA_HOME:"=%
52 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
53 |
54 | if exist "%JAVA_EXE%" goto init
55 |
56 | echo.
57 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
58 | echo.
59 | echo Please set the JAVA_HOME variable in your environment to match the
60 | echo location of your Java installation.
61 |
62 | goto fail
63 |
64 | :init
65 | @rem Get command-line arguments, handling Windows variants
66 |
67 | if not "%OS%" == "Windows_NT" goto win9xME_args
68 |
69 | :win9xME_args
70 | @rem Slurp the command line arguments.
71 | set CMD_LINE_ARGS=
72 | set _SKIP=2
73 |
74 | :win9xME_args_slurp
75 | if "x%~1" == "x" goto execute
76 |
77 | set CMD_LINE_ARGS=%*
78 |
79 | :execute
80 | @rem Setup the command line
81 |
82 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
83 |
84 | @rem Execute Gradle
85 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
86 |
87 | :end
88 | @rem End local scope for the variables with windows NT shell
89 | if "%ERRORLEVEL%"=="0" goto mainEnd
90 |
91 | :fail
92 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
93 | rem the _cmd.exe /c_ return code!
94 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
95 | exit /b 1
96 |
97 | :mainEnd
98 | if "%OS%"=="Windows_NT" endlocal
99 |
100 | :omega
101 |
--------------------------------------------------------------------------------
/images/image.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pengrad/MapScaleView/426beb961858591289a0f08ef7cdfb9b3a5378d3/images/image.png
--------------------------------------------------------------------------------
/images/image_rtl.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pengrad/MapScaleView/426beb961858591289a0f08ef7cdfb9b3a5378d3/images/image_rtl.png
--------------------------------------------------------------------------------
/mapscaleview/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/mapscaleview/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 28
5 |
6 | defaultConfig {
7 | minSdkVersion 9
8 | }
9 | }
10 |
11 | dependencies {
12 | compileOnly 'androidx.annotation:annotation:1.1.0'
13 | }
14 |
15 | apply from: '../upload-jcenter.gradle'
--------------------------------------------------------------------------------
/mapscaleview/gradle.properties:
--------------------------------------------------------------------------------
1 | POM_NAME=Map Scale View
2 | POM_ARTIFACT_ID=mapscaleview
3 | POM_PACKAGING=aar
--------------------------------------------------------------------------------
/mapscaleview/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/mapscaleview/src/main/java/com/github/pengrad/mapscaleview/Drawer.java:
--------------------------------------------------------------------------------
1 | package com.github.pengrad.mapscaleview;
2 |
3 | import android.graphics.Canvas;
4 | import android.graphics.Paint;
5 | import android.graphics.Path;
6 | import android.graphics.Rect;
7 | import android.graphics.Typeface;
8 |
9 | public class Drawer {
10 |
11 | private final Paint textPaint = new Paint();
12 | private final Paint strokePaint = new Paint();
13 | private final Path strokePath = new Path();
14 |
15 | private final Paint outlinePaint = new Paint();
16 | private final Path outlineDiffPath = new Path();
17 | private float outlineStrokeWidth = 2; // strokeWidth * 2
18 | private float outlineStrokeDiff = outlineStrokeWidth / 2 / 2; // strokeWidth / 2
19 | private float outlineTextStrokeWidth = 3; // density * 2
20 | private boolean outlineEnabled = true;
21 |
22 | private float textHeight;
23 | private float horizontalLineY;
24 |
25 | private boolean expandRtlEnabled;
26 | private int viewWidth;
27 |
28 | private Scales scales = new Scales(null, null);
29 |
30 | Drawer(int color, float textSize, float strokeWidth, float density, boolean outlineEnabled, boolean expandRtlEnabled) {
31 | textPaint.setAntiAlias(true);
32 | textPaint.setColor(color);
33 | textPaint.setStyle(Paint.Style.FILL);
34 | textPaint.setTextSize(textSize);
35 |
36 | strokePaint.setAntiAlias(true);
37 | strokePaint.setColor(color);
38 | strokePaint.setStyle(Paint.Style.STROKE);
39 | strokePaint.setStrokeWidth(strokeWidth);
40 |
41 | outlinePaint.set(strokePaint);
42 | outlinePaint.setARGB(255, 255, 255, 255);
43 | outlineStrokeWidth = strokeWidth * 2;
44 | outlineStrokeDiff = strokeWidth / 2;
45 | outlineTextStrokeWidth = density * 2;
46 | this.outlineEnabled = outlineEnabled;
47 | this.expandRtlEnabled = expandRtlEnabled;
48 |
49 | update();
50 | }
51 |
52 | private void update() {
53 | outlinePaint.setTextSize(textPaint.getTextSize());
54 | outlinePaint.setTypeface(textPaint.getTypeface());
55 | outlinePaint.setStrokeWidth(outlineTextStrokeWidth);
56 |
57 | Rect textRect = new Rect();
58 | Paint highestPaint = outlineEnabled ? outlinePaint : textPaint;
59 | String possibleText = "1234567890kmift";
60 | highestPaint.getTextBounds(possibleText, 0, possibleText.length(), textRect);
61 | textHeight = textRect.height();
62 |
63 | horizontalLineY = textHeight + textHeight / 2;
64 | }
65 |
66 | int getWidth() {
67 | return (int) (scales.maxLength() + strokePaint.getStrokeWidth());
68 | }
69 |
70 | int getHeight() {
71 | if (scales.bottom() != null) {
72 | return (int) (textHeight * 3 + outlineTextStrokeWidth / 2);
73 | } else {
74 | return (int) (horizontalLineY + strokePaint.getStrokeWidth());
75 | }
76 | }
77 |
78 | void setScales(Scales scales) {
79 | this.scales = scales;
80 | }
81 |
82 | void setColor(int color) {
83 | textPaint.setColor(color);
84 | strokePaint.setColor(color);
85 | }
86 |
87 | void setTextSize(float textSize) {
88 | textPaint.setTextSize(textSize);
89 | update();
90 | }
91 |
92 | void setTextFont(Typeface font) {
93 | textPaint.setTypeface(font);
94 | update();
95 | }
96 |
97 | void setStrokeWidth(float strokeWidth) {
98 | strokePaint.setStrokeWidth(strokeWidth);
99 | outlineStrokeWidth = strokeWidth * 2;
100 | outlineStrokeDiff = strokeWidth / 2;
101 | update();
102 | }
103 |
104 | void setOutlineEnabled(boolean enabled) {
105 | outlineEnabled = enabled;
106 | update();
107 | }
108 |
109 | void setExpandRtlEnabled(boolean enabled) {
110 | expandRtlEnabled = enabled;
111 | }
112 |
113 | void setViewWidth(int width) {
114 | viewWidth = width;
115 | }
116 |
117 | void draw(Canvas canvas) {
118 | Scale top = scales.top();
119 | if (top == null) {
120 | return;
121 | }
122 | if (expandRtlEnabled && viewWidth == 0) {
123 | expandRtlEnabled = false;
124 | }
125 |
126 | if (expandRtlEnabled) {
127 | outlinePaint.setTextAlign(Paint.Align.RIGHT);
128 | textPaint.setTextAlign(Paint.Align.RIGHT);
129 | } else {
130 | outlinePaint.setTextAlign(Paint.Align.LEFT);
131 | textPaint.setTextAlign(Paint.Align.LEFT);
132 | }
133 |
134 | if (outlineEnabled) {
135 | outlinePaint.setStrokeWidth(outlineTextStrokeWidth);
136 | canvas.drawText(top.text(), expandRtlEnabled ? viewWidth : 0, textHeight, outlinePaint);
137 | }
138 | canvas.drawText(top.text(), expandRtlEnabled ? viewWidth : 0, textHeight, textPaint);
139 |
140 | strokePath.rewind();
141 | strokePath.moveTo(expandRtlEnabled ? (viewWidth - outlineStrokeDiff) : outlineStrokeDiff, horizontalLineY);
142 | strokePath.lineTo(expandRtlEnabled ? (viewWidth - top.length()) : top.length(), horizontalLineY);
143 | if (outlineEnabled) {
144 | strokePath.lineTo(expandRtlEnabled ? (viewWidth - top.length()) : top.length(), textHeight + outlineStrokeDiff);
145 | } else {
146 | strokePath.lineTo(expandRtlEnabled ? (viewWidth - top.length()) : top.length(), textHeight);
147 | }
148 |
149 | Scale bottom = scales.bottom();
150 | if (bottom != null) {
151 |
152 | if (bottom.length() > top.length()) {
153 | strokePath.moveTo(expandRtlEnabled ? (viewWidth - top.length()) : top.length(), horizontalLineY);
154 | strokePath.lineTo(expandRtlEnabled ? (viewWidth - bottom.length()) : bottom.length(), horizontalLineY);
155 | } else {
156 | strokePath.moveTo(expandRtlEnabled ? (viewWidth - bottom.length()) : bottom.length(), horizontalLineY);
157 | }
158 |
159 | strokePath.lineTo(expandRtlEnabled ? (viewWidth - bottom.length()) : bottom.length(), textHeight * 2);
160 |
161 | float bottomTextY = horizontalLineY + textHeight + textHeight / 2;
162 | if (outlineEnabled) {
163 | canvas.drawText(bottom.text(), expandRtlEnabled ? viewWidth : 0, bottomTextY, outlinePaint);
164 | }
165 | canvas.drawText(bottom.text(), expandRtlEnabled ? viewWidth : 0, bottomTextY, textPaint);
166 | }
167 |
168 | if (outlineEnabled) {
169 | outlinePaint.setStrokeWidth(outlineStrokeWidth);
170 | outlineDiffPath.rewind();
171 | outlineDiffPath.moveTo(expandRtlEnabled ? viewWidth : 0, horizontalLineY);
172 | outlineDiffPath.lineTo(expandRtlEnabled ? (viewWidth - outlineStrokeDiff) : outlineStrokeDiff, horizontalLineY);
173 | outlineDiffPath.moveTo(expandRtlEnabled ? (viewWidth - top.length()) : top.length(), textHeight + outlineStrokeDiff);
174 | outlineDiffPath.lineTo(expandRtlEnabled ? (viewWidth - top.length()) : top.length(), textHeight);
175 | if (bottom != null) {
176 | outlineDiffPath.moveTo(expandRtlEnabled ? (viewWidth - bottom.length()) : bottom.length(), textHeight * 2);
177 | outlineDiffPath.lineTo(expandRtlEnabled ? (viewWidth - bottom.length()) : bottom.length(), textHeight * 2 + outlineStrokeDiff);
178 | }
179 |
180 | canvas.drawPath(outlineDiffPath, outlinePaint);
181 | canvas.drawPath(strokePath, outlinePaint);
182 | }
183 |
184 | canvas.drawPath(strokePath, strokePaint);
185 | }
186 | }
187 |
--------------------------------------------------------------------------------
/mapscaleview/src/main/java/com/github/pengrad/mapscaleview/MapScaleModel.java:
--------------------------------------------------------------------------------
1 | package com.github.pengrad.mapscaleview;
2 |
3 | class MapScaleModel {
4 |
5 | private static final double EQUATOR_LENGTH_METERS = 40075016.686;
6 | private static final double EQUATOR_LENGTH_FEET = 131479713.537;
7 |
8 | private static final int FT_IN_MILE = 5280;
9 |
10 | private static final float[] METERS = {0.2f, 0.5f, 1, 2, 5, 10, 20, 50, 100, 200, 500, 1000,
11 | 2000, 5000, 10000, 20000, 50000, 100000, 200000, 500000, 1000000, 2000000};
12 |
13 | private static final float[] FT = {1, 2, 5, 10, 20, 50, 100, 200, 500, 1000, 2000,
14 | FT_IN_MILE, 2 * FT_IN_MILE, 5 * FT_IN_MILE, 10 * FT_IN_MILE, 20 * FT_IN_MILE, 50 * FT_IN_MILE,
15 | 100 * FT_IN_MILE, 200 * FT_IN_MILE, 500 * FT_IN_MILE, 1000 * FT_IN_MILE, 2000 * FT_IN_MILE};
16 |
17 | private final float density;
18 | private int maxWidth;
19 |
20 | private float lastZoom = -1;
21 | private double lastLatitude = -100;
22 |
23 | private double tileSizeMetersAt0Zoom = EQUATOR_LENGTH_METERS / 256;
24 | private double tileSizeFeetAt0Zoom = EQUATOR_LENGTH_FEET / 256;
25 |
26 | MapScaleModel(float density) {
27 | this.density = density;
28 | }
29 |
30 | // returns true if width changed
31 | boolean updateMaxWidth(int width) {
32 | if (maxWidth != width) {
33 | maxWidth = width;
34 | return true;
35 | } else return false;
36 | }
37 |
38 | void setTileSize(int tileSize) {
39 | tileSizeMetersAt0Zoom = EQUATOR_LENGTH_METERS / tileSize;
40 | tileSizeFeetAt0Zoom = EQUATOR_LENGTH_FEET / tileSize;
41 | }
42 |
43 | void setPosition(float zoom, double latitude) {
44 | lastZoom = zoom;
45 | lastLatitude = latitude;
46 | }
47 |
48 | /**
49 | * See http://wiki.openstreetmap.org/wiki/Slippy_map_tilenames#Resolution_and_Scale
50 | */
51 | Scale update(boolean meters) {
52 | float zoom = lastZoom;
53 | double latitude = lastLatitude;
54 | if (zoom < 0 || Math.abs(latitude) > 90) return null;
55 |
56 | double tileSizeAtZoom0 = meters ? tileSizeMetersAt0Zoom : tileSizeFeetAt0Zoom;
57 | float[] distances = meters ? METERS : FT;
58 |
59 | final double resolution = tileSizeAtZoom0 / density * Math.cos(latitude * Math.PI / 180) / Math.pow(2, zoom);
60 |
61 | float distance = 0;
62 | int distanceIndex = distances.length;
63 | double screenDistance = maxWidth + 1;
64 |
65 | while (screenDistance > maxWidth && distanceIndex > 0) {
66 | distance = distances[--distanceIndex];
67 | screenDistance = Math.abs(distance / resolution);
68 | }
69 |
70 | lastZoom = zoom;
71 | lastLatitude = latitude;
72 | return new Scale(text(distance, meters), (float) screenDistance);
73 | }
74 |
75 | private String text(float distance, boolean meters) {
76 | if (meters) {
77 | if (distance < 1) return (int) (distance * 100) + " cm";
78 | if (distance < 1000) return (int) distance + " m";
79 | else return (int) distance / 1000 + " km";
80 | } else {
81 | if (distance < FT_IN_MILE) return (int) distance + " ft";
82 | else return (int) distance / FT_IN_MILE + " mi";
83 | }
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/mapscaleview/src/main/java/com/github/pengrad/mapscaleview/MapScaleView.java:
--------------------------------------------------------------------------------
1 | package com.github.pengrad.mapscaleview;
2 |
3 | import android.content.Context;
4 | import android.graphics.Canvas;
5 | import android.graphics.Typeface;
6 | import android.util.AttributeSet;
7 | import android.view.View;
8 |
9 | import androidx.annotation.ColorInt;
10 |
11 | public class MapScaleView extends View {
12 |
13 | private final MapScaleModel mapScaleModel;
14 | private final Drawer drawer;
15 |
16 | private final int maxWidth;
17 |
18 | private ScaleType scaleType = ScaleType.BOTH;
19 |
20 | private enum ScaleType {
21 | METERS_ONLY, MILES_ONLY, BOTH
22 | }
23 |
24 | public MapScaleView(Context context) {
25 | this(context, null);
26 | }
27 |
28 | public MapScaleView(Context context, AttributeSet attrs) {
29 | this(context, attrs, 0);
30 | }
31 |
32 | public MapScaleView(Context context, AttributeSet attrs, int defStyleAttr) {
33 | super(context, attrs, defStyleAttr);
34 |
35 | float density = getResources().getDisplayMetrics().density;
36 | mapScaleModel = new MapScaleModel(density);
37 |
38 | ViewConfig viewConfig = new ViewConfig(context, attrs);
39 | drawer = new Drawer(viewConfig.color, viewConfig.textSize, viewConfig.strokeWidth, density, viewConfig.outline, viewConfig.expandRtl);
40 |
41 | maxWidth = viewConfig.maxWidth;
42 |
43 | if (viewConfig.isMiles) {
44 | scaleType = ScaleType.MILES_ONLY;
45 | }
46 | }
47 |
48 | public void setTileSize(int tileSize) {
49 | mapScaleModel.setTileSize(tileSize);
50 | updateScales();
51 | }
52 |
53 | public void setColor(@ColorInt int color) {
54 | drawer.setColor(color);
55 | invalidate();
56 | }
57 |
58 | public void setTextSize(float textSize) {
59 | drawer.setTextSize(textSize);
60 | invalidate();
61 | requestLayout();
62 | }
63 |
64 | public void setTextFont(Typeface font) {
65 | drawer.setTextFont(font);
66 | invalidate();
67 | requestLayout();
68 | }
69 |
70 | public void setStrokeWidth(float strokeWidth) {
71 | drawer.setStrokeWidth(strokeWidth);
72 | invalidate();
73 | requestLayout();
74 | }
75 |
76 | public void setOutlineEnabled(boolean enabled) {
77 | drawer.setOutlineEnabled(enabled);
78 | invalidate();
79 | }
80 |
81 | public void setExpandRtlEnabled(boolean enabled) {
82 | drawer.setExpandRtlEnabled(enabled);
83 | invalidate();
84 | }
85 |
86 | /**
87 | * @deprecated Use milesOnly()
88 | */
89 | @Deprecated
90 | public void setIsMiles(boolean miles) {
91 | if (miles) milesOnly();
92 | else metersAndMiles();
93 | }
94 |
95 | public void metersOnly() {
96 | scaleType = ScaleType.METERS_ONLY;
97 | updateScales();
98 | }
99 |
100 | public void milesOnly() {
101 | scaleType = ScaleType.MILES_ONLY;
102 | updateScales();
103 | }
104 |
105 | public void metersAndMiles() {
106 | scaleType = ScaleType.BOTH;
107 | updateScales();
108 | }
109 |
110 | public void update(float zoom, double latitude) {
111 | mapScaleModel.setPosition(zoom, latitude);
112 | updateScales();
113 | }
114 |
115 | private void updateScales() {
116 | Scale top, bottom = null;
117 |
118 | if (scaleType == ScaleType.MILES_ONLY) {
119 | top = mapScaleModel.update(false);
120 | } else {
121 | top = mapScaleModel.update(true);
122 | if (scaleType == ScaleType.BOTH) {
123 | bottom = mapScaleModel.update(false);
124 | }
125 | }
126 |
127 | drawer.setScales(new Scales(top, bottom));
128 | invalidate();
129 | requestLayout();
130 | }
131 |
132 | @Override
133 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
134 | int width = measureDimension(desiredWidth(), widthMeasureSpec);
135 | int height = measureDimension(desiredHeight(), heightMeasureSpec);
136 |
137 | if (mapScaleModel.updateMaxWidth(width)) {
138 | updateScales();
139 | }
140 |
141 | if (MeasureSpec.getMode(widthMeasureSpec) != MeasureSpec.EXACTLY) {
142 | width = drawer.getWidth();
143 | }
144 |
145 | drawer.setViewWidth(width);
146 | setMeasuredDimension(width, height);
147 | }
148 |
149 | private int desiredWidth() {
150 | return maxWidth;
151 | }
152 |
153 | private int desiredHeight() {
154 | return drawer.getHeight();
155 | }
156 |
157 | private int measureDimension(int desiredSize, int measureSpec) {
158 | int mode = View.MeasureSpec.getMode(measureSpec);
159 | int size = View.MeasureSpec.getSize(measureSpec);
160 |
161 | if (mode == View.MeasureSpec.EXACTLY) {
162 | return size;
163 | } else if (mode == View.MeasureSpec.AT_MOST) {
164 | return Math.min(desiredSize, size);
165 | } else {
166 | return desiredSize;
167 | }
168 | }
169 |
170 | @Override
171 | public void onDraw(Canvas canvas) {
172 | drawer.draw(canvas);
173 | }
174 | }
175 |
--------------------------------------------------------------------------------
/mapscaleview/src/main/java/com/github/pengrad/mapscaleview/Scale.java:
--------------------------------------------------------------------------------
1 | package com.github.pengrad.mapscaleview;
2 |
3 | class Scale {
4 |
5 | private final String text;
6 | private final float length;
7 |
8 | Scale(String text, float length) {
9 | this.text = text;
10 | this.length = length;
11 | }
12 |
13 | public String text() {
14 | return text;
15 | }
16 |
17 | public float length() {
18 | return length;
19 | }
20 | }
--------------------------------------------------------------------------------
/mapscaleview/src/main/java/com/github/pengrad/mapscaleview/Scales.java:
--------------------------------------------------------------------------------
1 | package com.github.pengrad.mapscaleview;
2 |
3 | import androidx.annotation.Nullable;
4 |
5 | class Scales {
6 | private final Scale top, bottom;
7 |
8 | Scales(Scale top, Scale bottom) {
9 | this.top = top;
10 | this.bottom = bottom;
11 | }
12 |
13 | @Nullable
14 | Scale top() {
15 | return top;
16 | }
17 |
18 | @Nullable
19 | Scale bottom() {
20 | return bottom;
21 | }
22 |
23 | float maxLength() {
24 | return Math.max(top != null ? top.length() : 0, bottom != null ? bottom.length() : 0);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/mapscaleview/src/main/java/com/github/pengrad/mapscaleview/ViewConfig.java:
--------------------------------------------------------------------------------
1 | package com.github.pengrad.mapscaleview;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.graphics.Color;
6 | import android.util.AttributeSet;
7 |
8 | class ViewConfig {
9 |
10 | final int maxWidth;
11 | final int color;
12 | final float textSize;
13 | final float strokeWidth;
14 | final boolean isMiles;
15 | final boolean outline;
16 | final boolean expandRtl;
17 |
18 | ViewConfig(Context context, AttributeSet attrs) {
19 | // float fontScale = context.getResources().getDisplayMetrics().scaledDensity;
20 | float density = context.getResources().getDisplayMetrics().density;
21 |
22 | TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.MapScaleView, 0, 0);
23 | try {
24 | maxWidth = a.getDimensionPixelSize(R.styleable.MapScaleView_scale_maxWidth, (int) (100 * density));
25 | color = a.getColor(R.styleable.MapScaleView_scale_color, Color.parseColor("#333333"));
26 | textSize = a.getDimension(R.styleable.MapScaleView_scale_textSize, 12 * density);
27 | strokeWidth = a.getDimension(R.styleable.MapScaleView_scale_strokeWidth, 1.5f * density);
28 | isMiles = a.getBoolean(R.styleable.MapScaleView_scale_miles, false);
29 | outline = a.getBoolean(R.styleable.MapScaleView_scale_outline, true);
30 | expandRtl = a.getBoolean(R.styleable.MapScaleView_scale_expandRtl, false);
31 | } finally {
32 | a.recycle();
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/mapscaleview/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/sample/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/sample/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'kotlin-android'
3 |
4 | android {
5 | compileSdkVersion 29
6 | defaultConfig {
7 | minSdkVersion 14
8 | targetSdkVersion 29
9 | versionCode 1
10 | versionName "1.0"
11 | }
12 | signingConfigs {
13 | debug { storeFile file("debug.keystore") }
14 | }
15 | buildTypes {
16 | debug {
17 | signingConfig signingConfigs.debug
18 | buildConfigField 'String', "iv", IV_TOKEN
19 | }
20 | }
21 | }
22 |
23 | dependencies {
24 | implementation project(':mapscaleview')
25 | implementation 'androidx.appcompat:appcompat:1.1.0'
26 | implementation 'com.google.android.gms:play-services-maps:17.0.0'
27 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
28 | implementation "androidx.constraintlayout:constraintlayout:2.0.0-rc1"
29 | implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:9.2.1'
30 | }
31 |
--------------------------------------------------------------------------------
/sample/debug.keystore:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pengrad/MapScaleView/426beb961858591289a0f08ef7cdfb9b3a5378d3/sample/debug.keystore
--------------------------------------------------------------------------------
/sample/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/github/pengrad/mapscaleview/sample/GenericActivity.kt:
--------------------------------------------------------------------------------
1 | package com.github.pengrad.mapscaleview.sample
2 |
3 | import android.graphics.Color
4 | import android.graphics.Typeface
5 | import android.view.View
6 | import androidx.appcompat.app.AppCompatActivity
7 | import com.github.pengrad.mapscaleview.MapScaleView
8 | import com.mapbox.mapboxsdk.camera.CameraPosition
9 | import kotlin.random.Random
10 |
11 | open class GenericActivity : AppCompatActivity() {
12 | private val scales by lazy {
13 | listOf(
14 | findViewById(R.id.scaleView),
15 | findViewById(R.id.scaleViewMiles),
16 | findViewById(R.id.scaleViewRtl),
17 | findViewById(R.id.scaleViewBg),
18 | findViewById(R.id.scaleViewBgFixed)
19 | )
20 | }
21 | private val scaleView get() = scales[0]
22 | private val density by lazy { resources.displayMetrics.density }
23 | fun update(cameraPosition: CameraPosition) {
24 | for (scale in scales) {
25 | scale.update(cameraPosition.zoom.toFloat(), cameraPosition.target.latitude)
26 | }
27 | }
28 |
29 | fun update(cameraPosition: com.google.android.gms.maps.model.CameraPosition) {
30 | for (scale in scales) {
31 | scale.update(cameraPosition.zoom, cameraPosition.target.latitude)
32 | }
33 | }
34 |
35 | fun changeColor(view: View) {
36 | val getColor = { Color.rgb(Random.nextInt(255), Random.nextInt(255), Random.nextInt(255)) }
37 | scales.forEach { it.setColor(getColor()) }
38 | }
39 |
40 | fun changeTextSize(view: View) {
41 | scales.forEach { it.setTextSize((Random.nextInt(10) + 12) * density) }
42 | }
43 |
44 | fun changeStrokeWidth(view: View) {
45 | scales.forEach { it.setStrokeWidth((Random.nextInt(3) + 0.5f) * density) }
46 | }
47 |
48 | fun changeMiles(view: View) {
49 | scaleView.milesOnly()
50 | }
51 |
52 | private var isMeters = false
53 | fun changeMeters(view: View) {
54 | isMeters = !isMeters
55 | if (isMeters) scales.forEach { it.metersOnly() }
56 | else scales.forEach { it.metersAndMiles() }
57 | }
58 |
59 | fun changeSize(view: View) {
60 | scaleView.layoutParams.width = Random.nextInt(200) + 200
61 | scaleView.requestLayout()
62 | }
63 |
64 | private var isDefaultFont = true
65 | fun changeFont(view: View) {
66 | isDefaultFont = if (isDefaultFont) {
67 | scales.forEach { it.setTextFont(Typeface.DEFAULT) }
68 | false
69 | } else {
70 | scales.forEach { it.setTextFont(Typeface.DEFAULT_BOLD) }
71 | true
72 | }
73 | }
74 |
75 | private var outline = true
76 | fun changeOutline(view: View) {
77 | outline = !outline
78 | scales.forEach { it.setOutlineEnabled(outline) }
79 | }
80 |
81 | private var direction = false
82 | fun changeDirection(view: View) {
83 | direction = !direction
84 | scales.forEach { it.setExpandRtlEnabled(direction) }
85 | }
86 |
87 | private var largeTiles: Boolean = false
88 | fun changeTileSize(view: View) {
89 | largeTiles = !largeTiles
90 | scales.forEach { it.setTileSize(if (largeTiles) 512 else 256) }
91 | }
92 | }
--------------------------------------------------------------------------------
/sample/src/main/java/com/github/pengrad/mapscaleview/sample/GoogleMapsActivity.kt:
--------------------------------------------------------------------------------
1 | package com.github.pengrad.mapscaleview.sample
2 |
3 | import android.os.Bundle
4 | import com.google.android.gms.maps.CameraUpdateFactory
5 | import com.google.android.gms.maps.GoogleMap
6 | import com.google.android.gms.maps.GoogleMap.OnCameraIdleListener
7 | import com.google.android.gms.maps.GoogleMap.OnCameraMoveListener
8 | import com.google.android.gms.maps.OnMapReadyCallback
9 | import com.google.android.gms.maps.SupportMapFragment
10 | import com.google.android.gms.maps.model.LatLng
11 |
12 | class GoogleMapsActivity : GenericActivity(), OnMapReadyCallback, OnCameraMoveListener, OnCameraIdleListener {
13 |
14 | private lateinit var map: GoogleMap
15 |
16 | override fun onCreate(savedInstanceState: Bundle?) {
17 | super.onCreate(savedInstanceState)
18 | setContentView(R.layout.activity_googlemaps)
19 | val mapFragment = supportFragmentManager.findFragmentById(R.id.mapFragment) as SupportMapFragment
20 | mapFragment.getMapAsync(this)
21 | }
22 |
23 | override fun onMapReady(googleMap: GoogleMap) {
24 | map = googleMap
25 | googleMap.setOnCameraMoveListener(this)
26 | googleMap.setOnCameraIdleListener(this)
27 | googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(LatLng(37.07770360532252, -94.76820822805165), 12f))
28 | }
29 |
30 | override fun onCameraMove() {
31 | update(map.cameraPosition)
32 | }
33 |
34 | override fun onCameraIdle() {
35 | update(map.cameraPosition)
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/github/pengrad/mapscaleview/sample/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.github.pengrad.mapscaleview.sample
2 |
3 | import android.content.Intent
4 | import android.os.Bundle
5 | import android.widget.Button
6 | import androidx.appcompat.app.AppCompatActivity
7 |
8 | class MainActivity : AppCompatActivity() {
9 | override fun onCreate(savedInstanceState: Bundle?) {
10 | super.onCreate(savedInstanceState)
11 | setContentView(R.layout.activity_main)
12 | setOnClickListeners()
13 | }
14 |
15 | private fun setOnClickListeners() {
16 | findViewById