├── .gitignore
├── .travis.yml
├── Android.mk
├── LICENSE
├── README.md
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── mapsv1-compat-osmdroid
├── build.gradle
└── src
│ └── main
│ ├── AndroidManifest.xml
│ └── java
│ ├── com
│ └── google
│ │ └── android
│ │ └── maps
│ │ ├── GeoPoint.java
│ │ ├── ItemizedOverlay.java
│ │ ├── MapActivity.java
│ │ ├── MapController.java
│ │ ├── MapView.java
│ │ ├── MyLocationOverlay.java
│ │ ├── Overlay.java
│ │ ├── OverlayItem.java
│ │ ├── OverlayList.java
│ │ ├── OverlayListIterator.java
│ │ ├── Projection.java
│ │ ├── ProjectionWrapper.java
│ │ └── TrackballGestureDetector.java
│ └── org
│ └── microg
│ ├── annotation
│ └── OriginalApi.java
│ ├── internal
│ └── R.java
│ └── osmdroid
│ ├── CustomResourceProxyImpl.java
│ ├── SafeMapTileFilesystemProvider.java
│ ├── SafeMapTileProviderBasic.java
│ ├── SafeNetworkAvailabilityCheck.java
│ └── SafeTileWriter.java
├── mapsv1-flashable
├── build.gradle
└── src
│ └── main
│ └── files
│ ├── META-INF
│ └── com
│ │ └── google
│ │ └── android
│ │ ├── update-binary
│ │ └── updater-script
│ └── system
│ ├── addon.d
│ └── 10-mapsapi.sh
│ └── etc
│ └── permissions
│ └── com.google.android.maps.xml
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | out/
2 | build/
3 | *.iml
4 | local.properties
5 | .gradle/
6 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: android
2 | sudo: false
3 | git:
4 | submodules: false
5 | before_script:
6 | - echo sdk.dir $ANDROID_HOME > local.properties
7 | - keytool -genkeypair -keyalg RSA -sigalg SHA1withRSA -alias testkey -keystore .keystore -keypass testkey -storepass testkey -dname "CN=Test"
8 | - echo sign.storeFile=$(pwd)/.keystore >> local.properties
9 | - echo sign.storePassword=testkey >> local.properties
10 | - echo sign.keyAlias=testkey >> local.properties
11 | - echo sign.keyPassword=testkey >> local.properties
12 | script:
13 | - export TERM=dumb
14 | - export JAVA_OPTS="-XX:MaxPermSize=1024m -XX:+CMSClassUnloadingEnabled -XX:+HeapDumpOnOutOfMemoryError -Xmx2048m"
15 | - ./gradlew build
16 | android:
17 | components:
18 | - platform-tools
19 | - tools
20 | - build-tools-23.0.2
21 | - android-23
22 | - extra-android-m2repository
23 | before_cache:
24 | - rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
25 | cache:
26 | directories:
27 | - $HOME/.gradle/caches/
28 | - $HOME/.gradle/wrapper/
29 |
--------------------------------------------------------------------------------
/Android.mk:
--------------------------------------------------------------------------------
1 | LOCAL_PATH := $(call my-dir)
2 |
3 | include $(CLEAR_VARS)
4 | LOCAL_MODULE := com.google.android.maps
5 | LOCAL_MODULE_TAGS := optional
6 | LOCAL_STATIC_JAVA_LIBRARIES := osmdroid-android
7 | LOCAL_SRC_FILES := $(call all-java-files-under, mapsv1-compat-osmdroid/src/main/java)
8 | LOCAL_PACKAGE_NAME := com.google.android.maps
9 | LOCAL_CERTIFICATE := platform
10 | LOCAL_SDK_VERSION := current
11 | include $(BUILD_JAVA_LIBRARY)
12 |
13 | include $(CLEAR_VARS)
14 | LOCAL_MODULE := com.google.android.maps.xml
15 | LOCAL_MODULE_TAGS := optional
16 | LOCAL_MODULE_CLASS := ETC
17 | LOCAL_MODULE_PATH := $(TARGET_OUT_ETC)/permissions
18 | LOCAL_SRC_FILES := mapsv1-flashable/src/main/files/system/etc/permissions/$(LOCAL_MODULE)
19 | include $(BUILD_PREBUILT)
20 |
21 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 |
2 | Apache License
3 | Version 2.0, January 2004
4 | http://www.apache.org/licenses/
5 |
6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7 |
8 | 1. Definitions.
9 |
10 | "License" shall mean the terms and conditions for use, reproduction,
11 | and distribution as defined by Sections 1 through 9 of this document.
12 |
13 | "Licensor" shall mean the copyright owner or entity authorized by
14 | the copyright owner that is granting the License.
15 |
16 | "Legal Entity" shall mean the union of the acting entity and all
17 | other entities that control, are controlled by, or are under common
18 | control with that entity. For the purposes of this definition,
19 | "control" means (i) the power, direct or indirect, to cause the
20 | direction or management of such entity, whether by contract or
21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
22 | outstanding shares, or (iii) beneficial ownership of such entity.
23 |
24 | "You" (or "Your") shall mean an individual or Legal Entity
25 | exercising permissions granted by this License.
26 |
27 | "Source" form shall mean the preferred form for making modifications,
28 | including but not limited to software source code, documentation
29 | source, and configuration files.
30 |
31 | "Object" form shall mean any form resulting from mechanical
32 | transformation or translation of a Source form, including but
33 | not limited to compiled object code, generated documentation,
34 | and conversions to other media types.
35 |
36 | "Work" shall mean the work of authorship, whether in Source or
37 | Object form, made available under the License, as indicated by a
38 | copyright notice that is included in or attached to the work
39 | (an example is provided in the Appendix below).
40 |
41 | "Derivative Works" shall mean any work, whether in Source or Object
42 | form, that is based on (or derived from) the Work and for which the
43 | editorial revisions, annotations, elaborations, or other modifications
44 | represent, as a whole, an original work of authorship. For the purposes
45 | of this License, Derivative Works shall not include works that remain
46 | separable from, or merely link (or bind by name) to the interfaces of,
47 | the Work and Derivative Works thereof.
48 |
49 | "Contribution" shall mean any work of authorship, including
50 | the original version of the Work and any modifications or additions
51 | to that Work or Derivative Works thereof, that is intentionally
52 | submitted to Licensor for inclusion in the Work by the copyright owner
53 | or by an individual or Legal Entity authorized to submit on behalf of
54 | the copyright owner. For the purposes of this definition, "submitted"
55 | means any form of electronic, verbal, or written communication sent
56 | to the Licensor or its representatives, including but not limited to
57 | communication on electronic mailing lists, source code control systems,
58 | and issue tracking systems that are managed by, or on behalf of, the
59 | Licensor for the purpose of discussing and improving the Work, but
60 | excluding communication that is conspicuously marked or otherwise
61 | designated in writing by the copyright owner as "Not a Contribution."
62 |
63 | "Contributor" shall mean Licensor and any individual or Legal Entity
64 | on behalf of whom a Contribution has been received by Licensor and
65 | subsequently incorporated within the Work.
66 |
67 | 2. Grant of Copyright License. Subject to the terms and conditions of
68 | this License, each Contributor hereby grants to You a perpetual,
69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70 | copyright license to reproduce, prepare Derivative Works of,
71 | publicly display, publicly perform, sublicense, and distribute the
72 | Work and such Derivative Works in Source or Object form.
73 |
74 | 3. Grant of Patent License. Subject to the terms and conditions of
75 | this License, each Contributor hereby grants to You a perpetual,
76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77 | (except as stated in this section) patent license to make, have made,
78 | use, offer to sell, sell, import, and otherwise transfer the Work,
79 | where such license applies only to those patent claims licensable
80 | by such Contributor that are necessarily infringed by their
81 | Contribution(s) alone or by combination of their Contribution(s)
82 | with the Work to which such Contribution(s) was submitted. If You
83 | institute patent litigation against any entity (including a
84 | cross-claim or counterclaim in a lawsuit) alleging that the Work
85 | or a Contribution incorporated within the Work constitutes direct
86 | or contributory patent infringement, then any patent licenses
87 | granted to You under this License for that Work shall terminate
88 | as of the date such litigation is filed.
89 |
90 | 4. Redistribution. You may reproduce and distribute copies of the
91 | Work or Derivative Works thereof in any medium, with or without
92 | modifications, and in Source or Object form, provided that You
93 | meet the following conditions:
94 |
95 | (a) You must give any other recipients of the Work or
96 | Derivative Works a copy of this License; and
97 |
98 | (b) You must cause any modified files to carry prominent notices
99 | stating that You changed the files; and
100 |
101 | (c) You must retain, in the Source form of any Derivative Works
102 | that You distribute, all copyright, patent, trademark, and
103 | attribution notices from the Source form of the Work,
104 | excluding those notices that do not pertain to any part of
105 | the Derivative Works; and
106 |
107 | (d) If the Work includes a "NOTICE" text file as part of its
108 | distribution, then any Derivative Works that You distribute must
109 | include a readable copy of the attribution notices contained
110 | within such NOTICE file, excluding those notices that do not
111 | pertain to any part of the Derivative Works, in at least one
112 | of the following places: within a NOTICE text file distributed
113 | as part of the Derivative Works; within the Source form or
114 | documentation, if provided along with the Derivative Works; or,
115 | within a display generated by the Derivative Works, if and
116 | wherever such third-party notices normally appear. The contents
117 | of the NOTICE file are for informational purposes only and
118 | do not modify the License. You may add Your own attribution
119 | notices within Derivative Works that You distribute, alongside
120 | or as an addendum to the NOTICE text from the Work, provided
121 | that such additional attribution notices cannot be construed
122 | as modifying the License.
123 |
124 | You may add Your own copyright statement to Your modifications and
125 | may provide additional or different license terms and conditions
126 | for use, reproduction, or distribution of Your modifications, or
127 | for any such Derivative Works as a whole, provided Your use,
128 | reproduction, and distribution of the Work otherwise complies with
129 | the conditions stated in this License.
130 |
131 | 5. Submission of Contributions. Unless You explicitly state otherwise,
132 | any Contribution intentionally submitted for inclusion in the Work
133 | by You to the Licensor shall be under the terms and conditions of
134 | this License, without any additional terms or conditions.
135 | Notwithstanding the above, nothing herein shall supersede or modify
136 | the terms of any separate license agreement you may have executed
137 | with Licensor regarding such Contributions.
138 |
139 | 6. Trademarks. This License does not grant permission to use the trade
140 | names, trademarks, service marks, or product names of the Licensor,
141 | except as required for reasonable and customary use in describing the
142 | origin of the Work and reproducing the content of the NOTICE file.
143 |
144 | 7. Disclaimer of Warranty. Unless required by applicable law or
145 | agreed to in writing, Licensor provides the Work (and each
146 | Contributor provides its Contributions) on an "AS IS" BASIS,
147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148 | implied, including, without limitation, any warranties or conditions
149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150 | PARTICULAR PURPOSE. You are solely responsible for determining the
151 | appropriateness of using or redistributing the Work and assume any
152 | risks associated with Your exercise of permissions under this License.
153 |
154 | 8. Limitation of Liability. In no event and under no legal theory,
155 | whether in tort (including negligence), contract, or otherwise,
156 | unless required by applicable law (such as deliberate and grossly
157 | negligent acts) or agreed to in writing, shall any Contributor be
158 | liable to You for damages, including any direct, indirect, special,
159 | incidental, or consequential damages of any character arising as a
160 | result of this License or out of the use or inability to use the
161 | Work (including but not limited to damages for loss of goodwill,
162 | work stoppage, computer failure or malfunction, or any and all
163 | other commercial damages or losses), even if such Contributor
164 | has been advised of the possibility of such damages.
165 |
166 | 9. Accepting Warranty or Additional Liability. While redistributing
167 | the Work or Derivative Works thereof, You may choose to offer,
168 | and charge a fee for, acceptance of support, warranty, indemnity,
169 | or other liability obligations and/or rights consistent with this
170 | License. However, in accepting such obligations, You may act only
171 | on Your own behalf and on Your sole responsibility, not on behalf
172 | of any other Contributor, and only if You agree to indemnify,
173 | defend, and hold each Contributor harmless for any liability
174 | incurred by, or claims asserted against, such Contributor by reason
175 | of your accepting any such warranty or additional liability.
176 |
177 | END OF TERMS AND CONDITIONS
178 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
Maps API (mapsv1)
2 | ======
3 | [](https://travis-ci.org/microg/android_frameworks_mapsv1)
4 |
5 | A system library, providing the same functionality as now deprecated Google Maps API v1.
6 |
7 | ### Please refer to the [wiki](https://github.com/microg/android_frameworks_mapsv1/wiki) for downloads and instructions
8 |
9 |
10 | Attribution
11 | -----------
12 | This won't be possible without the hard work of the guys at [osmdroid](https://github.com/osmdroid).
13 |
14 |
15 | License
16 | -------
17 | Copyright 2013-2016 microG Project Team
18 |
19 | Licensed under the Apache License, Version 2.0 (the "License");
20 | you may not use this file except in compliance with the License.
21 | You may obtain a copy of the License at
22 |
23 | http://www.apache.org/licenses/LICENSE-2.0
24 |
25 | Unless required by applicable law or agreed to in writing, software
26 | distributed under the License is distributed on an "AS IS" BASIS,
27 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
28 | See the License for the specific language governing permissions and
29 | limitations under the License.
30 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microg/android_frameworks_mapsv1/49e09748da4a50df19dae8d56cc09e10602fbe18/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Fri Jan 30 12:07:36 CET 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.6-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
46 | if $cygwin ; then
47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48 | fi
49 |
50 | # Attempt to set APP_HOME
51 | # Resolve links: $0 may be a link
52 | PRG="$0"
53 | # Need this for relative symlinks.
54 | while [ -h "$PRG" ] ; do
55 | ls=`ls -ld "$PRG"`
56 | link=`expr "$ls" : '.*-> \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
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 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/mapsv1-compat-osmdroid/build.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013-2015 microG Project Team
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | buildscript {
18 | repositories {
19 | jcenter()
20 | }
21 | dependencies {
22 | classpath 'com.android.tools.build:gradle:1.5.0'
23 | }
24 | }
25 |
26 | apply plugin: 'com.android.library'
27 |
28 | String getMyVersionName() {
29 | def stdout = new ByteArrayOutputStream()
30 | exec {
31 | commandLine 'git', 'describe', '--tags', '--always', '--dirty'
32 | standardOutput = stdout
33 | }
34 | return stdout.toString().trim()
35 | }
36 |
37 | repositories {
38 | jcenter()
39 | }
40 |
41 | dependencies {
42 | compile 'org.osmdroid:osmdroid-android:5.1'
43 | }
44 |
45 | android {
46 | compileSdkVersion 23
47 | buildToolsVersion "23.0.2"
48 |
49 | defaultConfig {
50 | versionName getMyVersionName()
51 | }
52 |
53 | compileOptions {
54 | sourceCompatibility JavaVersion.VERSION_1_6
55 | }
56 | }
57 |
58 | if (file('user.gradle').exists()) {
59 | apply from: 'user.gradle'
60 | }
61 |
--------------------------------------------------------------------------------
/mapsv1-compat-osmdroid/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/mapsv1-compat-osmdroid/src/main/java/com/google/android/maps/GeoPoint.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013-2016 microG Project Team
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.android.maps;
18 |
19 | import android.location.Location;
20 |
21 | import org.microg.annotation.OriginalApi;
22 | import org.osmdroid.api.IGeoPoint;
23 |
24 | @OriginalApi
25 | public class GeoPoint implements IGeoPoint {
26 | private final IGeoPoint wrapped;
27 |
28 | @OriginalApi
29 | public GeoPoint(int latitudeE6, int longitudeE6) {
30 | this(new org.osmdroid.util.GeoPoint(latitudeE6, longitudeE6));
31 | }
32 |
33 | public GeoPoint(IGeoPoint wrapped) {
34 | this.wrapped = wrapped;
35 | }
36 |
37 | public GeoPoint(Location location) {
38 | this((int) (location.getLatitude() * 1e6), (int) (location.getLongitude() * 1e6));
39 | }
40 |
41 | @OriginalApi
42 | @Override
43 | public boolean equals(Object other) {
44 | return other == this || (other instanceof GeoPoint) && wrapped.equals(((GeoPoint) other).wrapped);
45 | }
46 |
47 | @Override
48 | public double getLatitude() {
49 | return wrapped.getLatitude();
50 | }
51 |
52 | @OriginalApi
53 | @Override
54 | public int getLatitudeE6() {
55 | return wrapped.getLatitudeE6();
56 | }
57 |
58 | @Override
59 | public double getLongitude() {
60 | return wrapped.getLongitude();
61 | }
62 |
63 | @OriginalApi
64 | @Override
65 | public int getLongitudeE6() {
66 | return wrapped.getLongitudeE6();
67 | }
68 |
69 | @OriginalApi
70 | @Override
71 | public int hashCode() {
72 | return wrapped.hashCode();
73 | }
74 |
75 | @OriginalApi
76 | @Override
77 | public String toString() {
78 | return getLatitudeE6() + "," + getLongitudeE6();
79 | }
80 |
81 | public org.osmdroid.util.GeoPoint toOsmdroid() {
82 | if (wrapped instanceof org.osmdroid.util.GeoPoint) {
83 | return (org.osmdroid.util.GeoPoint) wrapped;
84 | } else {
85 | return new org.osmdroid.util.GeoPoint(wrapped.getLatitudeE6(), wrapped.getLongitudeE6());
86 | }
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/mapsv1-compat-osmdroid/src/main/java/com/google/android/maps/ItemizedOverlay.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013-2016 microG Project Team
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.android.maps;
18 |
19 | import android.graphics.Canvas;
20 | import android.graphics.Point;
21 | import android.graphics.drawable.Drawable;
22 | import android.util.Log;
23 | import android.view.KeyEvent;
24 | import android.view.MotionEvent;
25 |
26 | import org.microg.annotation.OriginalApi;
27 |
28 | import java.util.ArrayList;
29 | import java.util.Collections;
30 | import java.util.Comparator;
31 | import java.util.List;
32 |
33 | @OriginalApi
34 | public abstract class ItemizedOverlay- extends Overlay implements Overlay.Snappable {
35 | private static final String TAG = ItemizedOverlay.class.getName();
36 |
37 | @OriginalApi
38 | protected int mLastFocusedIndex;
39 |
40 | private final Drawable defaultMarker;
41 | private final ArrayList
- internalList = new ArrayList
- ();
42 | private int latSpanE6;
43 | private int lonSpanE6;
44 | private Item focusedItem;
45 | private GeoPoint center;
46 | private OnFocusChangeListener focusChangeListener;
47 | private boolean pendingFocusChangeEvent = false;
48 | private boolean drawFocusedItem = true;
49 | private Comparator
- latitudeComparator = new Comparator
- () {
50 | @Override
51 | public int compare(Item lhs, Item rhs) {
52 | return lhs.getPoint().getLatitudeE6() - rhs.getPoint().getLatitudeE6();
53 | }
54 | };
55 | private Comparator
- drawComparator = new Comparator
- () {
56 | @Override
57 | public int compare(Item lhs, Item rhs) {
58 | return getIndexToDraw(lhs.index) - getIndexToDraw(rhs.index);
59 | }
60 | };
61 |
62 | @OriginalApi
63 | public ItemizedOverlay(Drawable defaultMarker) {
64 | this.defaultMarker = defaultMarker;
65 | }
66 |
67 | @OriginalApi
68 | protected static Drawable boundCenter(Drawable ballon) {
69 | int width = ballon.getIntrinsicWidth();
70 | int halfWidth = width / 2;
71 | int height = ballon.getIntrinsicHeight();
72 | int halfHeight = height / 2;
73 | ballon.setBounds(-halfWidth, -halfHeight, width - halfWidth, height - halfHeight);
74 | return ballon;
75 | }
76 |
77 | @OriginalApi
78 | protected static Drawable boundCenterBottom(Drawable ballon) {
79 | int width = ballon.getIntrinsicWidth();
80 | int halfWidth = width / 2;
81 | int height = ballon.getIntrinsicHeight();
82 | ballon.setBounds(-halfWidth, 1 - height, width - halfWidth, 1);
83 | return ballon;
84 | }
85 |
86 | @OriginalApi
87 | protected abstract Item createItem(int i);
88 |
89 | @OriginalApi
90 | public void draw(Canvas canvas, MapView mapView, boolean shadow) {
91 | if (pendingFocusChangeEvent && focusChangeListener != null) {
92 | focusChangeListener.onFocusChanged(this, focusedItem);
93 | }
94 | pendingFocusChangeEvent = false;
95 |
96 | List
- sortedList = new ArrayList
- ();
97 | for (int i = 0; i < internalList.size(); i++) {
98 | sortedList.add(getItem(i));
99 | }
100 | Collections.sort(sortedList, drawComparator);
101 |
102 | Point point = new Point();
103 | for (Item item : sortedList) {
104 | if (item != null) {
105 | int state = (drawFocusedItem && (focusedItem == item) ? OverlayItem.ITEM_STATE_FOCUSED_MASK : 0);
106 | Drawable marker = item.getMarker(state);
107 | if (marker == null) {
108 | marker = defaultMarker;
109 | OverlayItem.setState(marker, state);
110 | }
111 | mapView.getProjection().toPixels(item.getPoint(), point);
112 |
113 | Overlay.drawAt(canvas, marker, point.x, point.y, shadow);
114 | }
115 | }
116 | }
117 |
118 | @OriginalApi
119 | public GeoPoint getCenter() {
120 | if (!internalList.isEmpty()) {
121 | return center;
122 | } else {
123 | return null;
124 | }
125 | }
126 |
127 | @OriginalApi
128 | public Item getFocus() {
129 | return focusedItem;
130 | }
131 |
132 | @OriginalApi
133 | public void setFocus(Item item) {
134 | pendingFocusChangeEvent = item != focusedItem;
135 | focusedItem = item;
136 | }
137 |
138 | @OriginalApi
139 | protected int getIndexToDraw(int drawingOrder) {
140 | return internalList.get(drawingOrder).sortedIndex;
141 | }
142 |
143 | @OriginalApi
144 | public Item getItem(int position) {
145 | synchronized (internalList) {
146 | if (internalList.size() > position) {
147 | return internalList.get(position);
148 | } else {
149 | return null;
150 | }
151 | }
152 | }
153 |
154 | @OriginalApi
155 | public int getLastFocusedIndex() {
156 | return mLastFocusedIndex;
157 | }
158 |
159 | @OriginalApi
160 | protected void setLastFocusedIndex(int lastFocusedIndex) {
161 | mLastFocusedIndex = lastFocusedIndex;
162 | }
163 |
164 | @OriginalApi
165 | public int getLatSpanE6() {
166 | return latSpanE6;
167 | }
168 |
169 | @OriginalApi
170 | public int getLonSpanE6() {
171 | return lonSpanE6;
172 | }
173 |
174 | @OriginalApi
175 | protected boolean hitTest(Item item, Drawable marker, int hitX, int hitY) {
176 | return marker.getBounds().contains(hitX, hitY);
177 | }
178 |
179 | @OriginalApi
180 | public Item nextFocus(boolean forwards) {
181 | if (forwards) {
182 | return mLastFocusedIndex >= internalList.size() - 1 ? null : internalList.get(mLastFocusedIndex + 1);
183 | } else {
184 | return mLastFocusedIndex <= 0 ? null : internalList.get(mLastFocusedIndex - 1);
185 | }
186 | }
187 |
188 | @OriginalApi
189 | @Override
190 | public boolean onKeyUp(int keyCode, KeyEvent event, MapView mapView) {
191 | Log.w(TAG, "Incomplete implementation of onKeyUp()");
192 | return super.onKeyUp(keyCode, event, mapView); // TODO
193 | }
194 |
195 | @OriginalApi
196 | @Override
197 | public boolean onSnapToItem(int x, int y, Point snapPoint, MapView mapView) {
198 | Log.w(TAG, "Incomplete implementation of onSnapToItem()");
199 | return false; // TODO
200 | }
201 |
202 | @OriginalApi
203 | @Override
204 | public boolean onTap(GeoPoint p, MapView mapView) {
205 | Point touchPoint = mapView.getProjection().toPixels(p, null);
206 | Point point = new Point();
207 | List
- hitItems = new ArrayList
- ();
208 | for (int i = internalList.size() - 1; i >= 0; i--) {
209 | final Item item = getItem(i);
210 | final int state = (drawFocusedItem && (focusedItem == item) ? OverlayItem.ITEM_STATE_FOCUSED_MASK : 0);
211 | Drawable marker = item.getMarker(state);
212 | if (marker == null) {
213 | marker = defaultMarker;
214 | OverlayItem.setState(marker, state);
215 | }
216 | mapView.getProjection().toPixels(item.getPoint(), point);
217 | if (hitTest(item, marker, touchPoint.x - point.x, touchPoint.y - point.y)) {
218 | hitItems.add(item);
219 | }
220 | }
221 | if (!hitItems.isEmpty()) {
222 | Item item = hitItems.get(0);
223 | for (Item hitItem : hitItems) {
224 | if (hitItem.getPoint().getLatitude() > item.getPoint().getLatitude())
225 | item = hitItem;
226 | }
227 | Log.d(TAG, "Hit " + hitItems.size() + " items, most likely " + item);
228 | boolean result = onTap(item.index);
229 | if (focusedItem != item) {
230 | focusedItem = item;
231 | mLastFocusedIndex = item.index;
232 | if (focusChangeListener != null) {
233 | focusChangeListener.onFocusChanged(this, item);
234 | }
235 | }
236 | return result;
237 | } else {
238 | focusedItem = null;
239 | return false;
240 | }
241 | }
242 |
243 | @OriginalApi
244 | protected boolean onTap(int index) {
245 | return false;
246 | }
247 |
248 | @OriginalApi
249 | @Override
250 | public boolean onTouchEvent(MotionEvent e, MapView mapView) {
251 | Log.w(TAG, "Incomplete implementation of onTouchEvent()");
252 | return super.onTouchEvent(e, mapView); // TODO
253 | }
254 |
255 | @OriginalApi
256 | @Override
257 | public boolean onTrackballEvent(MotionEvent event, MapView mapView) {
258 | Log.w(TAG, "Incomplete implementation of onTrackballEvent()");
259 | return super.onTrackballEvent(event, mapView); // TODO
260 | }
261 |
262 | @OriginalApi
263 | protected void populate() {
264 | synchronized (internalList) {
265 | int size = size();
266 | internalList.clear();
267 | internalList.ensureCapacity(size);
268 | int minLatE6 = 90000000, maxLatE6 = -90000000, minLonE6 = 180000000, maxLonE6 = -180000000;
269 | for (int i = 0; i < size; i++) {
270 | Item item = createItem(i);
271 | item.index = i;
272 | minLatE6 = Math.min(minLatE6, item.getPoint().getLatitudeE6());
273 | maxLatE6 = Math.max(maxLatE6, item.getPoint().getLatitudeE6());
274 | minLonE6 = Math.min(minLonE6, item.getPoint().getLongitudeE6());
275 | minLonE6 = Math.min(minLonE6, item.getPoint().getLongitudeE6());
276 | internalList.add(item);
277 | }
278 | List
- sortedList = new ArrayList
- (internalList);
279 | Collections.sort(sortedList, latitudeComparator);
280 | for (int i = 0; i < sortedList.size(); i++) {
281 | sortedList.get(i).sortedIndex = i;
282 | }
283 | latSpanE6 = maxLatE6 - minLatE6;
284 | lonSpanE6 = maxLonE6 - minLonE6;
285 | center = new GeoPoint(minLatE6 + latSpanE6 / 2, minLonE6 + lonSpanE6 / 2);
286 | }
287 | if (assignedMapView != null && assignedMapView.getHandler() != null) {
288 | assignedMapView.getHandler().post(new Runnable() {
289 | @Override
290 | public void run() {
291 | assignedMapView.invalidate();
292 | }
293 | });
294 | }
295 | }
296 |
297 | @OriginalApi
298 | public void setDrawFocusedItem(boolean drawFocusedItem) {
299 | this.drawFocusedItem = drawFocusedItem;
300 | }
301 |
302 | @OriginalApi
303 | public void setOnFocusChangeListener(OnFocusChangeListener l) {
304 | this.focusChangeListener = l;
305 | }
306 |
307 | @OriginalApi
308 | public abstract int size();
309 |
310 | @OriginalApi
311 | public interface OnFocusChangeListener {
312 | @OriginalApi
313 | void onFocusChanged(ItemizedOverlay overlay, OverlayItem newFocus);
314 | }
315 | }
316 |
--------------------------------------------------------------------------------
/mapsv1-compat-osmdroid/src/main/java/com/google/android/maps/MapActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013-2016 microG Project Team
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.android.maps;
18 |
19 | import android.app.Activity;
20 | import android.content.Intent;
21 | import android.os.Bundle;
22 |
23 | import org.microg.annotation.OriginalApi;
24 |
25 | @OriginalApi
26 | public class MapActivity extends Activity {
27 |
28 | @OriginalApi
29 | public MapActivity() {
30 | super();
31 | }
32 |
33 | @OriginalApi
34 | protected boolean isLocationDisplayed() {
35 | return false;
36 | }
37 |
38 | @OriginalApi
39 | protected boolean isRouteDisplayed() {
40 | return false;
41 | }
42 |
43 | @OriginalApi
44 | @Override
45 | protected void onCreate(Bundle savedInstanceState) {
46 | super.onCreate(savedInstanceState);
47 | }
48 |
49 | @OriginalApi
50 | @Override
51 | protected void onDestroy() {
52 | super.onDestroy();
53 | }
54 |
55 | @OriginalApi
56 | @Override
57 | protected void onNewIntent(Intent intent) {
58 | super.onNewIntent(intent);
59 | }
60 |
61 | @OriginalApi
62 | @Override
63 | protected void onPause() {
64 | super.onPause();
65 | }
66 |
67 | @OriginalApi
68 | @Override
69 | protected void onResume() {
70 | super.onResume();
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/mapsv1-compat-osmdroid/src/main/java/com/google/android/maps/MapController.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013-2016 microG Project Team
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.android.maps;
18 |
19 | import android.os.Message;
20 | import android.view.KeyEvent;
21 | import android.view.View;
22 |
23 | import org.microg.annotation.OriginalApi;
24 | import org.osmdroid.api.IGeoPoint;
25 | import org.osmdroid.api.IMapController;
26 |
27 | @OriginalApi
28 | public class MapController implements IMapController, View.OnKeyListener {
29 | private final IMapController wrapped;
30 |
31 | public MapController(IMapController wrapped) {
32 | this.wrapped = wrapped;
33 | }
34 |
35 | @OriginalApi
36 | public void animateTo(GeoPoint point) {
37 | wrapped.animateTo(point);
38 | }
39 |
40 | @Override
41 | public void animateTo(IGeoPoint geoPoint) {
42 | wrapped.animateTo(geoPoint);
43 | }
44 |
45 | @OriginalApi
46 | public void animateTo(GeoPoint point, Message message) {
47 | wrapped.animateTo(point);
48 | // TODO: delay message
49 | if (message != null) {
50 | message.sendToTarget();
51 | }
52 | }
53 |
54 | @OriginalApi
55 | public void animateTo(GeoPoint point, Runnable runnable) {
56 | wrapped.animateTo(point);
57 | // TODO: delay runnable
58 | runnable.run();
59 | }
60 |
61 | @OriginalApi
62 | public boolean onKey(View view, int keyCode, KeyEvent event) {
63 | // TODO: handle onKey
64 | return false;
65 | }
66 |
67 | @OriginalApi
68 | @Override
69 | public void scrollBy(int x, int y) {
70 | wrapped.scrollBy(x, y);
71 | }
72 |
73 | @OriginalApi
74 | public void setCenter(GeoPoint point) {
75 | wrapped.setCenter(point);
76 | }
77 |
78 | @Override
79 | public void setCenter(IGeoPoint point) {
80 | wrapped.setCenter(point);
81 | }
82 |
83 | @OriginalApi
84 | @Override
85 | public int setZoom(int zoomLevel) {
86 | return wrapped.setZoom(zoomLevel);
87 | }
88 |
89 | @OriginalApi
90 | @Override
91 | public void stopAnimation(boolean jumpToFinish) {
92 | wrapped.stopAnimation(jumpToFinish);
93 | }
94 |
95 | @OriginalApi
96 | @Override
97 | public void stopPanning() {
98 | wrapped.stopPanning();
99 | }
100 |
101 | @OriginalApi
102 | @Override
103 | public boolean zoomIn() {
104 | return wrapped.zoomIn();
105 | }
106 |
107 | @OriginalApi
108 | @Override
109 | public boolean zoomInFixing(int xPixel, int yPixel) {
110 | return wrapped.zoomInFixing(xPixel, yPixel);
111 | }
112 |
113 | @OriginalApi
114 | @Override
115 | public boolean zoomOut() {
116 | return wrapped.zoomOut();
117 | }
118 |
119 | @OriginalApi
120 | @Override
121 | public boolean zoomOutFixing(int xPixel, int yPixel) {
122 | return wrapped.zoomOutFixing(xPixel, yPixel);
123 | }
124 |
125 | @Override
126 | public boolean zoomTo(int zoomLevel) {
127 | return wrapped.zoomTo(zoomLevel);
128 | }
129 |
130 | @Override
131 | public boolean zoomToFixing(int zoomLevel, int xPixel, int yPixel) {
132 | return wrapped.zoomToFixing(zoomLevel, xPixel, yPixel);
133 | }
134 |
135 | @OriginalApi
136 | @Override
137 | public void zoomToSpan(int latSpanE6, int lonSpanE6) {
138 | wrapped.zoomToSpan(latSpanE6, lonSpanE6);
139 | }
140 |
141 | }
142 |
--------------------------------------------------------------------------------
/mapsv1-compat-osmdroid/src/main/java/com/google/android/maps/MapView.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013-2016 microG Project Team
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.android.maps;
18 |
19 | import android.content.Context;
20 | import android.content.res.TypedArray;
21 | import android.graphics.Canvas;
22 | import android.graphics.Rect;
23 | import android.os.Bundle;
24 | import android.os.Handler;
25 | import android.util.AttributeSet;
26 | import android.util.Log;
27 | import android.view.GestureDetector;
28 | import android.view.KeyEvent;
29 | import android.view.MotionEvent;
30 | import android.view.View;
31 | import android.view.ViewConfiguration;
32 | import android.view.ViewGroup;
33 | import android.widget.ZoomButtonsController;
34 | import android.widget.ZoomControls;
35 |
36 | import org.microg.annotation.OriginalApi;
37 | import org.microg.internal.R;
38 | import org.microg.osmdroid.CustomResourceProxyImpl;
39 | import org.microg.osmdroid.SafeMapTileProviderBasic;
40 | import org.microg.osmdroid.SafeNetworkAvailabilityCheck;
41 | import org.osmdroid.api.IMapView;
42 | import org.osmdroid.tileprovider.tilesource.ITileSource;
43 | import org.osmdroid.tileprovider.tilesource.TileSourceFactory;
44 | import org.osmdroid.tileprovider.util.SimpleRegisterReceiver;
45 |
46 | import java.util.List;
47 |
48 | /*
49 | * TODO:
50 | * - Possibly bad trackball support, but no way to test for me
51 | * - We don't draw the reticle, but it's for trackball only afaik.
52 | * - We can't show traffic and satellite maps the same moment...
53 | */
54 |
55 | @OriginalApi
56 | public class MapView extends ViewGroup implements IMapView {
57 | private static final String TAG = MapView.class.getName();
58 | private static final String KEY_CENTER_LATITUDE = MapView.class.getName() + ".centerLatitude";
59 | private static final String KEY_CENTER_LONGITUDE = MapView.class.getName() + ".centerLongitude";
60 | private static final String KEY_ZOOM_DISPLAYED = MapView.class.getName() + ".zoomDisplayed";
61 | private static final String KEY_ZOOM_LEVEL = MapView.class.getName() + ".zoomLevel";
62 |
63 | // TODO: We should read these from a setting, users might want to change it...
64 | private static final ITileSource DEFAULT = TileSourceFactory.MAPNIK;
65 | private static final ITileSource TRAFFIC = TileSourceFactory.PUBLIC_TRANSPORT;
66 | private static final ITileSource SATELLITE = TileSourceFactory.MAPQUESTAERIAL;
67 |
68 | public static Context DEFAULT_CONTEXT;
69 |
70 | private GestureDetector gestureDetector;
71 | private Handler handler = new Handler();
72 | private MapController mapController;
73 | private ReticleDrawMode reticleDrawMode;
74 | private final WrappedMapView wrapped;
75 | private boolean zoomControlsEnabled = true;
76 | private Runnable zoomControlsHideCallback;
77 | private ZoomButtonsController zoomButtonsController;
78 | private ZoomControls zoomControls;
79 | private final OverlayList.NewOverlayAttachedListener attachedListener = new OverlayList.NewOverlayAttachedListener() {
80 | @Override
81 | public void onNewOverlayAttached(Overlay overlay) {
82 | overlay.assignedMapView = MapView.this;
83 | if (getHandler() != null) {
84 | getHandler().post(new Runnable() {
85 | @Override
86 | public void run() {
87 | invalidate();
88 | }
89 | });
90 | }
91 | }
92 | };
93 |
94 | private boolean satellite = false;
95 | private boolean streetView = false;
96 | private boolean traffic = false;
97 |
98 | @OriginalApi
99 | public MapView(Context context, AttributeSet attrs) {
100 | this(context, attrs, R.attr.mapViewStyle);
101 | }
102 |
103 | @OriginalApi
104 | public MapView(Context context, AttributeSet attrs, int defStyle) {
105 | this(context, attrs, defStyle, null);
106 | }
107 |
108 | @OriginalApi
109 | public MapView(Context context, String apiKey) {
110 | this(context, null, R.attr.mapViewStyle, apiKey);
111 | }
112 |
113 | public MapView(Context context, AttributeSet attrs, int defStyle, String apiKey) {
114 | super(context, attrs, defStyle);
115 | DEFAULT_CONTEXT = context;
116 | wrapped = new WrappedMapView(context, attrs);
117 | mapController = new MapController(wrapped.getController());
118 | addView(wrapped);
119 |
120 | // Warn the developer that his usage of MapView will not work with Google's implementation.
121 |
122 | if (attrs != null) {
123 | try {
124 | TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.MapView);
125 | if (array != null) {
126 | if (apiKey == null) {
127 | apiKey = array.getString(R.styleable.MapView_apiKey);
128 | }
129 | array.recycle();
130 | }
131 | } catch (Exception e) {
132 | // This might fail, if we can't access the internal R or it's modified
133 | Log.w(TAG, e);
134 | }
135 | }
136 |
137 | if (apiKey == null) {
138 | Log.w(TAG, "MapViews must specify an API Key to be compatible with Google's implementation.");
139 | }
140 | if (!(context instanceof MapActivity)) {
141 | Log.w(TAG, "MapViews must only be created inside instances of MapActivity to be compatible with Google's implementation.");
142 | }
143 |
144 | // Set startup location as suggested from resources
145 | try {
146 | int[] latlonE6 = getResources().getIntArray(R.array.maps_starting_lat_lng);
147 | getController().setCenter(new GeoPoint(latlonE6[0], latlonE6[1]));
148 | getController().setZoom(getResources().getIntArray(R.array.maps_starting_zoom)[0]);
149 | } catch (Exception e) {
150 | // This might fail, if we can't access the internal R or it's modified
151 | Log.w(TAG, e);
152 | }
153 |
154 | // We detect gestures non-exclusively. osmdroid uses the same gesture detection,
155 | // but we can't depend on their implementation as it's not accessible from this context.
156 | gestureDetector = new GestureDetector(getContext(), new GestureDetector.SimpleOnGestureListener() {
157 | @Override
158 | public boolean onDown(MotionEvent e) {
159 | displayZoomControls(false);
160 | return false;
161 | }
162 |
163 | @Override
164 | public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
165 | displayZoomControls(false);
166 | return false;
167 | }
168 |
169 | @Override
170 | public void onLongPress(MotionEvent e) {
171 | MapView.this.performLongClick();
172 | }
173 |
174 | @Override
175 | public boolean onSingleTapConfirmed(MotionEvent e) {
176 | return MapView.this.performClick();
177 | }
178 | });
179 | //gestureDetector.setIsLongpressEnabled(false);
180 | }
181 |
182 | @OriginalApi
183 | public boolean canCoverCenter() {
184 | Log.w(TAG, "Incomplete implementation of canCoverCenter()");
185 | return true; // TODO
186 | }
187 |
188 | @OriginalApi
189 | protected boolean checkLayoutParams(ViewGroup.LayoutParams p) {
190 | return p instanceof LayoutParams;
191 | }
192 |
193 | @OriginalApi
194 | public void displayZoomControls(boolean takeFocus) {
195 | if (zoomControlsEnabled) {
196 | if ((zoomButtonsController != null) && (!zoomButtonsController.isVisible())) {
197 | zoomButtonsController.setFocusable(takeFocus);
198 | zoomButtonsController.setVisible(true);
199 | }
200 | if (zoomControls != null) {
201 | if (zoomControls.getVisibility() == View.GONE) {
202 | zoomControls.show();
203 | }
204 | if (takeFocus) {
205 | zoomControls.requestFocus();
206 | }
207 | handler.removeCallbacks(zoomControlsHideCallback);
208 | handler.postDelayed(zoomControlsHideCallback, ViewConfiguration.getZoomControlsTimeout());
209 | }
210 | }
211 | }
212 |
213 | @OriginalApi
214 | protected LayoutParams generateDefaultLayoutParams() {
215 | return new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, new GeoPoint(0, 0), LayoutParams.CENTER);
216 | }
217 |
218 | @OriginalApi
219 | @Override
220 | public ViewGroup.LayoutParams generateLayoutParams(AttributeSet attrs) {
221 | return new LayoutParams(getContext(), attrs);
222 | }
223 |
224 | @OriginalApi
225 | @Override
226 | protected ViewGroup.LayoutParams generateLayoutParams(ViewGroup.LayoutParams p) {
227 | return new LayoutParams(p);
228 | }
229 |
230 | @OriginalApi
231 | @Override
232 | public MapController getController() {
233 | return mapController;
234 | }
235 |
236 | @OriginalApi
237 | @Override
238 | public int getLatitudeSpan() {
239 | return wrapped.getLatitudeSpan();
240 | }
241 |
242 | @OriginalApi
243 | @Override
244 | public int getLongitudeSpan() {
245 | return wrapped.getLongitudeSpan();
246 | }
247 |
248 | @OriginalApi
249 | @Override
250 | public GeoPoint getMapCenter() {
251 | return new GeoPoint(wrapped.getMapCenter());
252 | }
253 |
254 | @OriginalApi
255 | @Override
256 | public int getMaxZoomLevel() {
257 | return wrapped.getMaxZoomLevel();
258 | }
259 |
260 | @OriginalApi
261 | public List getOverlays() {
262 | return new OverlayList(wrapped.getOverlays(), attachedListener);
263 | }
264 |
265 | @OriginalApi
266 | @Override
267 | public Projection getProjection() {
268 | return new ProjectionWrapper(wrapped.getProjection());
269 | }
270 |
271 | public IMapView getWrapped() {
272 | return wrapped;
273 | }
274 |
275 | @OriginalApi
276 | public ZoomButtonsController getZoomButtonsController() {
277 | return zoomButtonsController;
278 | }
279 |
280 | @OriginalApi
281 | @Deprecated
282 | public View getZoomControls() {
283 | if (zoomControls == null) {
284 | zoomControls = new ZoomControls(getContext());
285 | zoomControls.setZoomSpeed(2000);
286 | zoomControls.setOnZoomInClickListener(new OnClickListener() {
287 | @Override
288 | public void onClick(View v) {
289 | wrapped.getController().zoomIn();
290 | }
291 | });
292 | zoomControls.setOnZoomOutClickListener(new OnClickListener() {
293 | @Override
294 | public void onClick(View v) {
295 | wrapped.getController().zoomOut();
296 | }
297 | });
298 | zoomControls.setVisibility(View.GONE);
299 | zoomControlsHideCallback = new Runnable() {
300 | @Override
301 | public void run() {
302 | if (!zoomControls.hasFocus()) {
303 | zoomControls.hide();
304 | } else {
305 | handler.removeCallbacks(zoomControlsHideCallback);
306 | handler.postDelayed(zoomControlsHideCallback, ViewConfiguration.getZoomControlsTimeout());
307 | }
308 | }
309 | };
310 | }
311 | return zoomControls;
312 | }
313 |
314 | @OriginalApi
315 | @Override
316 | public int getZoomLevel() {
317 | return wrapped.getZoomLevel();
318 | }
319 |
320 | @OriginalApi
321 | public boolean isSatellite() {
322 | return satellite;
323 | }
324 |
325 | @OriginalApi
326 | public void setSatellite(boolean on) {
327 | satellite = on;
328 | wrapped.updateTileSource();
329 | }
330 |
331 | @OriginalApi
332 | public boolean isStreetView() {
333 | return streetView;
334 | }
335 |
336 | @OriginalApi
337 | public void setStreetView(boolean on) {
338 | if (on) setTraffic(false);
339 | streetView = on;
340 | }
341 |
342 | @OriginalApi
343 | public boolean isTraffic() {
344 | return traffic;
345 | }
346 |
347 | @OriginalApi
348 | public void setTraffic(boolean on) {
349 | if (on) setStreetView(false);
350 | traffic = true;
351 | }
352 |
353 | @OriginalApi
354 | @Override
355 | protected void onDetachedFromWindow() {
356 | super.onDetachedFromWindow();
357 | // Fix for bug in ZoomButtonsController
358 | if (zoomButtonsController != null) zoomButtonsController.setVisible(false);
359 | }
360 |
361 | @OriginalApi
362 | @Override
363 | protected void onDraw(Canvas canvas) {
364 | super.onDraw(canvas);
365 | }
366 |
367 | @OriginalApi
368 | @Override
369 | public void onFocusChanged(boolean hasFocus, int direction, Rect unused) {
370 | super.onFocusChanged(hasFocus, direction, unused);
371 | }
372 |
373 | @OriginalApi
374 | @Override
375 | public boolean onKeyDown(int keyCode, KeyEvent event) {
376 | return super.onKeyDown(keyCode, event);
377 | }
378 |
379 | @OriginalApi
380 | @Override
381 | public boolean onKeyUp(int keyCode, KeyEvent event) {
382 | return super.onKeyUp(keyCode, event);
383 | }
384 |
385 | @OriginalApi
386 | @Override
387 | protected void onLayout(boolean changed, int l, int t, int r, int b) {
388 | if (wrapped instanceof org.osmdroid.views.MapView) {
389 | wrapped.layout(l, t, r, b);
390 | }
391 | }
392 |
393 | @OriginalApi
394 | @Override
395 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
396 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
397 | }
398 |
399 | @OriginalApi
400 | public void onRestoreInstanceState(Bundle state) {
401 | if (state != null) {
402 | int latE6 = state.getInt(KEY_CENTER_LATITUDE, Integer.MAX_VALUE);
403 | int lonE6 = state.getInt(KEY_CENTER_LONGITUDE, Integer.MAX_VALUE);
404 | if (latE6 != Integer.MAX_VALUE && lonE6 != Integer.MAX_VALUE) {
405 | getController().setCenter(new GeoPoint(latE6, lonE6));
406 | }
407 | int zoom = state.getInt(KEY_ZOOM_LEVEL, Integer.MAX_VALUE);
408 | if (zoom != Integer.MAX_VALUE) {
409 | getController().setZoom(zoom);
410 | }
411 | if (state.getInt(KEY_ZOOM_DISPLAYED, 0) != 0) {
412 | displayZoomControls(false);
413 | }
414 | }
415 | }
416 |
417 | @OriginalApi
418 | public void onSaveInstanceState(Bundle state) {
419 | // We use the same way to store information in the bundle as Google does,
420 | // also this is not documented, there are a number of apps known to rely on it.
421 |
422 | state.putInt(KEY_CENTER_LATITUDE, getMapCenter().getLatitudeE6());
423 | state.putInt(KEY_CENTER_LONGITUDE, getMapCenter().getLongitudeE6());
424 | state.putInt(KEY_ZOOM_LEVEL, getZoomLevel());
425 | state.putInt(KEY_ZOOM_DISPLAYED, (zoomButtonsController != null) && (zoomButtonsController.isVisible()) || ((zoomControls != null) && (zoomControls.getVisibility() == View.VISIBLE)) ? 1 : 0);
426 | }
427 |
428 | @OriginalApi
429 | @Override
430 | protected void onSizeChanged(int w, int h, int oldw, int oldh) {
431 | super.onSizeChanged(w, h, oldw, oldh);
432 | }
433 |
434 | @OriginalApi
435 | @Override
436 | public boolean onTouchEvent(MotionEvent event) {
437 | // We only consume the touch event if it is used by the zoom button.
438 | // The gestures detected by us are also relevant for the underlying MapView!
439 | gestureDetector.onTouchEvent(event);
440 | return (zoomButtonsController != null && zoomButtonsController.isVisible() && zoomButtonsController.onTouch(this, event));
441 | }
442 |
443 | @OriginalApi
444 | @Override
445 | public boolean onTrackballEvent(MotionEvent event) {
446 | Log.w(TAG, "Incomplete implementation of onTrackballEvent()");
447 | // TODO we do not support trackball well, but they're kind of deprecated anyway?!
448 | return false;
449 | }
450 |
451 | @OriginalApi
452 | @Override
453 | public void onWindowFocusChanged(boolean hasFocus) {
454 | super.onWindowFocusChanged(hasFocus);
455 | }
456 |
457 | @OriginalApi
458 | public void preLoad() {
459 | Log.w(TAG, "Incomplete implementation of preLoad()");
460 | // TODO not sure what this actually does...
461 | }
462 |
463 | @OriginalApi
464 | public void setBuiltInZoomControls(boolean on) {
465 | zoomControlsEnabled = on;
466 | if (zoomButtonsController == null) {
467 | zoomButtonsController = new ZoomButtonsController(this);
468 | zoomButtonsController.setZoomSpeed(2000);
469 | zoomButtonsController.setOnZoomListener(new ZoomButtonsController.OnZoomListener() {
470 | @Override
471 | public void onVisibilityChanged(boolean visible) {
472 | if (visible) {
473 | zoomButtonsController.setZoomInEnabled(wrapped.getZoomLevel() < wrapped.getMaxZoomLevel());
474 | zoomButtonsController.setZoomOutEnabled(wrapped.getZoomLevel() > 1);
475 | } else {
476 | zoomButtonsController.setFocusable(false);
477 | }
478 | }
479 |
480 | @Override
481 | public void onZoom(boolean zoomIn) {
482 | if (zoomIn) {
483 | wrapped.getController().zoomIn();
484 | } else {
485 | wrapped.getController().zoomOut();
486 | }
487 | }
488 | });
489 | }
490 | }
491 |
492 | @OriginalApi
493 | public void setReticleDrawMode(ReticleDrawMode mode) {
494 | reticleDrawMode = mode;
495 | }
496 |
497 | @OriginalApi
498 | public static enum ReticleDrawMode {
499 | DRAW_RETICLE_OVER,
500 | DRAW_RETICLE_UNDER,
501 | DRAW_RETICLE_NEVER
502 | }
503 |
504 | @OriginalApi
505 | public static class LayoutParams extends ViewGroup.LayoutParams {
506 | @OriginalApi
507 | public static int BOTTOM = 80;
508 | @OriginalApi
509 | public static int BOTTOM_CENTER = 81;
510 | @OriginalApi
511 | public static int CENTER = 17;
512 | @OriginalApi
513 | public static int CENTER_HORIZONTAL = 1;
514 | @OriginalApi
515 | public static int CENTER_VERTICAL = 16;
516 | @OriginalApi
517 | public static int LEFT = 3;
518 | @OriginalApi
519 | public static int RIGHT = 5;
520 | @OriginalApi
521 | public static int TOP = 48;
522 | @OriginalApi
523 | public static int TOP_LEFT = 51;
524 | @OriginalApi
525 | public static int MODE_MAP = 0;
526 | @OriginalApi
527 | public static int MODE_VIEW = 1;
528 |
529 | @OriginalApi
530 | public int alignment;
531 | @OriginalApi
532 | public int mode;
533 | @OriginalApi
534 | public GeoPoint point;
535 | @OriginalApi
536 | public int x;
537 | @OriginalApi
538 | public int y;
539 |
540 | @OriginalApi
541 | public LayoutParams(Context c, AttributeSet attrs) {
542 | super(c, attrs);
543 | }
544 |
545 | @OriginalApi
546 | public LayoutParams(int width, int height, GeoPoint point, int alignment) {
547 | this(width, height, point, 0, 0, alignment);
548 | }
549 |
550 | @OriginalApi
551 | public LayoutParams(int width, int height, GeoPoint point, int x, int y, int alignment) {
552 | super(width, height);
553 | this.point = point;
554 | this.x = x;
555 | this.y = y;
556 | this.alignment = alignment;
557 |
558 | mode = MODE_MAP;
559 | }
560 |
561 | @OriginalApi
562 | public LayoutParams(int width, int height, int x, int y, int alignment) {
563 | super(width, height);
564 | this.x = x;
565 | this.y = y;
566 | this.alignment = alignment;
567 |
568 | mode = MODE_VIEW;
569 | }
570 |
571 | @OriginalApi
572 | public LayoutParams(ViewGroup.LayoutParams source) {
573 | super(source);
574 |
575 | if (source instanceof LayoutParams) {
576 | alignment = ((LayoutParams) source).alignment;
577 | mode = ((LayoutParams) source).mode;
578 | point = ((LayoutParams) source).point;
579 | x = ((LayoutParams) source).x;
580 | y = ((LayoutParams) source).y;
581 | } else if (source instanceof org.osmdroid.views.MapView.LayoutParams) {
582 | alignment = ((org.osmdroid.views.MapView.LayoutParams) source).alignment;
583 | x = ((org.osmdroid.views.MapView.LayoutParams) source).offsetX;
584 | y = ((org.osmdroid.views.MapView.LayoutParams) source).offsetY;
585 | point = new GeoPoint(((org.osmdroid.views.MapView.LayoutParams) source).geoPoint);
586 | if (point != null) {
587 | mode = MODE_MAP;
588 | } else {
589 | mode = MODE_VIEW;
590 | }
591 | } else {
592 | mode = MODE_VIEW;
593 | alignment = TOP_LEFT;
594 | }
595 | }
596 |
597 | /**
598 | * Converts the specified size to a readable String.
599 | *
600 | * Is a hidden API method from {@link android.view.ViewGroup}.
601 | *
602 | * @param size the size to convert
603 | * @return a String instance representing the supplied size
604 | */
605 | protected static String sizeToString(int size) {
606 | if (size == WRAP_CONTENT) {
607 | return "wrap-content";
608 | }
609 | if (size == MATCH_PARENT) {
610 | return "match-parent";
611 | }
612 | return String.valueOf(size);
613 | }
614 |
615 | @OriginalApi
616 | public String debug(String output) {
617 | // We use the same output format as the original Google implementation, although i doubt anybody parses it.
618 | return output + "MapView.LayoutParams={" +
619 | "width=" + sizeToString(this.width) +
620 | ", height=" + sizeToString(this.height) +
621 | " mode=" + this.mode +
622 | " lat=" + this.point.getLatitudeE6() +
623 | " lng=" + this.point.getLongitudeE6() +
624 | " x= " + this.x +
625 | " y= " + this.y +
626 | " alignment=" + this.alignment +
627 | "}";
628 | }
629 | }
630 |
631 | public class WrappedMapView extends org.osmdroid.views.MapView {
632 |
633 | public WrappedMapView(Context context, AttributeSet attrs) {
634 | super(context, new CustomResourceProxyImpl(context), new SafeMapTileProviderBasic(context,
635 | new SimpleRegisterReceiver(context), new SafeNetworkAvailabilityCheck(context),
636 | TileSourceFactory.DEFAULT_TILE_SOURCE), null, attrs);
637 | setMultiTouchControls(true);
638 | updateTileSource();
639 | }
640 |
641 | public void updateTileSource() {
642 | if (satellite) {
643 | setTileSource(SATELLITE);
644 | } else if (traffic) {
645 | setTileSource(TRAFFIC);
646 | } else {
647 | setTileSource(DEFAULT);
648 | }
649 | }
650 |
651 | @Override
652 | public boolean onTouchEvent(MotionEvent event) {
653 | return MapView.this.onTouchEvent(event) || super.onTouchEvent(event);
654 | }
655 |
656 | @Override
657 | public boolean onTrackballEvent(MotionEvent event) {
658 | return MapView.this.onTrackballEvent(event) || super.onTrackballEvent(event);
659 | }
660 |
661 | @Override
662 | public boolean onKeyUp(int keyCode, KeyEvent event) {
663 | return MapView.this.onKeyUp(keyCode, event) || super.onKeyUp(keyCode, event);
664 | }
665 |
666 | @Override
667 | public boolean onKeyDown(int keyCode, KeyEvent event) {
668 | return MapView.this.onKeyDown(keyCode, event) || super.onKeyDown(keyCode, event);
669 | }
670 |
671 | public MapView getOriginal() {
672 | return MapView.this;
673 | }
674 | }
675 | }
676 |
--------------------------------------------------------------------------------
/mapsv1-compat-osmdroid/src/main/java/com/google/android/maps/MyLocationOverlay.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013-2016 microG Project Team
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.android.maps;
18 |
19 | import android.content.Context;
20 | import android.graphics.Canvas;
21 | import android.graphics.Point;
22 | import android.hardware.SensorListener;
23 | import android.location.Location;
24 | import android.location.LocationListener;
25 | import android.os.Bundle;
26 |
27 | import org.microg.annotation.OriginalApi;
28 | import org.microg.osmdroid.CustomResourceProxyImpl;
29 | import org.osmdroid.api.IMyLocationOverlay;
30 |
31 | public class MyLocationOverlay extends Overlay implements IMyLocationOverlay, SensorListener, LocationListener, Overlay.Snappable {
32 | private final IMyLocationOverlay wrapped;
33 |
34 | @OriginalApi
35 | public MyLocationOverlay(Context context, MapView mapView) {
36 | this(new org.osmdroid.views.overlay.MyLocationOverlay(context, (org.osmdroid.views.MapView) mapView.getWrapped(), new CustomResourceProxyImpl(context)));
37 | }
38 |
39 | public MyLocationOverlay(IMyLocationOverlay wrapped) {
40 | this.wrapped = wrapped;
41 | }
42 |
43 | @OriginalApi
44 | @Override
45 | public void disableCompass() {
46 | wrapped.disableCompass();
47 | }
48 |
49 | @OriginalApi
50 | @Override
51 | public void disableMyLocation() {
52 | wrapped.disableMyLocation();
53 | }
54 |
55 | @OriginalApi
56 | protected boolean dispatchTap() {
57 | return false; // TODO
58 | }
59 |
60 | @OriginalApi
61 | @Override
62 | public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) {
63 | return super.draw(canvas, mapView, shadow, when); // TODO
64 | }
65 |
66 | @OriginalApi
67 | protected void drawCompass(Canvas canvas, float bearing) {
68 | // TODO
69 | }
70 |
71 | @OriginalApi
72 | protected void drawMyLocation(Canvas canvas, MapView mapView, Location lastFix, GeoPoint myLocation, long when) {
73 | // TODO
74 | }
75 |
76 | @OriginalApi
77 | @Override
78 | public boolean enableCompass() {
79 | return wrapped.enableCompass();
80 | }
81 |
82 | @OriginalApi
83 | @Override
84 | public boolean enableMyLocation() {
85 | return wrapped.enableMyLocation();
86 | }
87 |
88 | @OriginalApi
89 | @Override
90 | public Location getLastFix() {
91 | return wrapped.getLastFix();
92 | }
93 |
94 | @OriginalApi
95 | public GeoPoint getMyLocation() {
96 | return getLastFix() != null ? new GeoPoint(getLastFix()) : null;
97 | }
98 |
99 | @OriginalApi
100 | @Override
101 | public float getOrientation() {
102 | return wrapped.getOrientation();
103 | }
104 |
105 | @OriginalApi
106 | @Override
107 | public boolean isCompassEnabled() {
108 | return wrapped.isCompassEnabled();
109 | }
110 |
111 | @OriginalApi
112 | @Override
113 | public boolean isMyLocationEnabled() {
114 | return wrapped.isMyLocationEnabled();
115 | }
116 |
117 | @OriginalApi
118 | @Override
119 | public void onAccuracyChanged(int sensor, int accuracy) {
120 | // TODO
121 | }
122 |
123 | @OriginalApi
124 | @Override
125 | public void onLocationChanged(Location location) {
126 | // TODO
127 | }
128 |
129 | @OriginalApi
130 | @Override
131 | public void onProviderDisabled(String provider) {
132 | // TODO
133 | }
134 |
135 | @OriginalApi
136 | @Override
137 | public void onProviderEnabled(String provider) {
138 | // TODO
139 | }
140 |
141 | @OriginalApi
142 | @Override
143 | public void onSensorChanged(int sensor, float[] values) {
144 | // TODO
145 | }
146 |
147 | @OriginalApi
148 | @Override
149 | public boolean onSnapToItem(int x, int y, Point snapPoint, MapView mapView) {
150 | return false; // TODO
151 | }
152 |
153 | @OriginalApi
154 | @Override
155 | public void onStatusChanged(String provider, int status, Bundle extras) {
156 | wrapped.onStatusChanged(provider, status, extras);
157 | }
158 |
159 | @OriginalApi
160 | @Override
161 | public boolean onTap(GeoPoint p, MapView map) {
162 | return false; // TODO
163 | }
164 |
165 | @OriginalApi
166 | @Override
167 | public boolean runOnFirstFix(Runnable runnable) {
168 | return wrapped.runOnFirstFix(runnable);
169 | }
170 | }
171 |
--------------------------------------------------------------------------------
/mapsv1-compat-osmdroid/src/main/java/com/google/android/maps/Overlay.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013-2016 microG Project Team
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.android.maps;
18 |
19 | import android.graphics.Canvas;
20 | import android.graphics.Color;
21 | import android.graphics.Point;
22 | import android.graphics.PorterDuff;
23 | import android.graphics.drawable.Drawable;
24 | import android.view.KeyEvent;
25 | import android.view.MotionEvent;
26 |
27 | import org.microg.annotation.OriginalApi;
28 | import org.microg.osmdroid.CustomResourceProxyImpl;
29 |
30 | import java.util.ArrayList;
31 | import java.util.List;
32 |
33 | @OriginalApi
34 | public class Overlay extends org.osmdroid.views.overlay.Overlay {
35 |
36 | @OriginalApi
37 | protected static float SHADOW_X_SKEW = -0.9F;
38 | @OriginalApi
39 | protected static float SHADOW_Y_SCALE = 0.5F;
40 | MapView assignedMapView;
41 |
42 | @OriginalApi
43 | public Overlay() {
44 | super(MapView.DEFAULT_CONTEXT == null ? new CustomResourceProxyImpl() : new CustomResourceProxyImpl(MapView.DEFAULT_CONTEXT));
45 | }
46 |
47 | @OriginalApi
48 | protected static void drawAt(Canvas canvas, Drawable drawable, int x, int y, boolean shadow) {
49 | if (shadow) {
50 | drawable.setColorFilter(Color.argb(128, 0, 0, 0), PorterDuff.Mode.SRC_IN);
51 | }
52 | canvas.save();
53 | canvas.translate(x, y);
54 | if (shadow) {
55 | canvas.skew(SHADOW_X_SKEW, 0);
56 | canvas.scale(1, SHADOW_Y_SCALE);
57 | }
58 | drawable.draw(canvas);
59 | if (shadow) {
60 | drawable.clearColorFilter();
61 | }
62 | canvas.restore();
63 | }
64 |
65 | public static List unwrap(List overlays) {
66 | List result = new ArrayList();
67 | for (org.osmdroid.views.overlay.Overlay overlay : overlays) {
68 | Overlay unwrap = Overlay.unwrap(overlay);
69 | if (unwrap != null) {
70 | result.add(unwrap);
71 | }
72 | }
73 | return result;
74 | }
75 |
76 | public static Overlay unwrap(org.osmdroid.views.overlay.Overlay overlay) {
77 | if (overlay instanceof Overlay) {
78 | return (Overlay) overlay;
79 | } else {
80 | return null;
81 | }
82 | }
83 |
84 | @Override
85 | protected void draw(Canvas c, org.osmdroid.views.MapView osmv, boolean shadow) {
86 | draw(c, osmv instanceof MapView.WrappedMapView ? ((MapView.WrappedMapView) osmv).getOriginal() : null, shadow);
87 | }
88 |
89 | @OriginalApi
90 | public void draw(Canvas canvas, MapView mapView, boolean shadow) {
91 | // To be overridden
92 | }
93 |
94 | @OriginalApi
95 | public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) {
96 | draw(canvas, mapView, shadow);
97 | return false;
98 | }
99 |
100 | @Override
101 | public boolean onKeyDown(int keyCode, KeyEvent event, org.osmdroid.views.MapView mapView) {
102 | if (mapView instanceof MapView.WrappedMapView)
103 | return onKeyDown(keyCode, event, ((MapView.WrappedMapView) mapView).getOriginal());
104 | return false;
105 | }
106 |
107 | @OriginalApi
108 | public boolean onKeyDown(int keyCode, KeyEvent event, MapView mapView) {
109 | return false;
110 | }
111 |
112 | @Override
113 | public boolean onKeyUp(int keyCode, KeyEvent event, org.osmdroid.views.MapView mapView) {
114 | if (mapView instanceof MapView.WrappedMapView)
115 | return onKeyUp(keyCode, event, ((MapView.WrappedMapView) mapView).getOriginal());
116 | return false;
117 | }
118 |
119 | @OriginalApi
120 | public boolean onKeyUp(int keyCode, KeyEvent event, MapView mapView) {
121 | return false;
122 | }
123 |
124 | @Override
125 | public boolean onSingleTapConfirmed(MotionEvent e, org.osmdroid.views.MapView mapView) {
126 | if (mapView instanceof MapView.WrappedMapView)
127 | return onTap(new GeoPoint(mapView.getProjection().fromPixels((int) e.getX(), (int) e.getY())), ((MapView.WrappedMapView) mapView).getOriginal());
128 | return false;
129 | }
130 |
131 | @OriginalApi
132 | public boolean onTap(GeoPoint p, MapView mapView) {
133 | return false;
134 | }
135 |
136 | @Override
137 | public boolean onTouchEvent(MotionEvent event, org.osmdroid.views.MapView mapView) {
138 | if (mapView instanceof MapView.WrappedMapView)
139 | return onTouchEvent(event, ((MapView.WrappedMapView) mapView).getOriginal());
140 | return false;
141 | }
142 |
143 | @OriginalApi
144 | public boolean onTouchEvent(MotionEvent e, MapView mapView) {
145 | return false;
146 | }
147 |
148 | @Override
149 | public boolean onTrackballEvent(MotionEvent event, org.osmdroid.views.MapView mapView) {
150 | if (mapView instanceof MapView.WrappedMapView)
151 | return onTrackballEvent(event, ((MapView.WrappedMapView) mapView).getOriginal());
152 | return false;
153 | }
154 |
155 | @OriginalApi
156 | public boolean onTrackballEvent(MotionEvent event, MapView mapView) {
157 | return false;
158 | }
159 |
160 | @OriginalApi
161 | public interface Snappable {
162 | boolean onSnapToItem(int x, int y, Point snapPoint, MapView mapView);
163 | }
164 | }
165 |
--------------------------------------------------------------------------------
/mapsv1-compat-osmdroid/src/main/java/com/google/android/maps/OverlayItem.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013-2016 microG Project Team
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.android.maps;
18 |
19 | import android.graphics.drawable.Drawable;
20 |
21 | import org.microg.annotation.OriginalApi;
22 | import org.microg.internal.R;
23 |
24 | @OriginalApi
25 | public class OverlayItem {
26 | @OriginalApi
27 | public static int ITEM_STATE_FOCUSED_MASK = 4;
28 | @OriginalApi
29 | public static int ITEM_STATE_PRESSED_MASK = 1;
30 | @OriginalApi
31 | public static int ITEM_STATE_SELECTED_MASK = 2;
32 |
33 | @OriginalApi
34 | protected Drawable mMarker;
35 | @OriginalApi
36 | protected GeoPoint mPoint;
37 | @OriginalApi
38 | protected String mSnippet;
39 | @OriginalApi
40 | protected String mTitle;
41 |
42 | int index;
43 | int sortedIndex;
44 |
45 | @OriginalApi
46 | public OverlayItem(GeoPoint point, String title, String snippet) {
47 | mPoint = point;
48 | mTitle = title;
49 | mSnippet = snippet;
50 | }
51 |
52 | private static int unbitset(int bitset, int mask, int value) {
53 | return (bitset & mask) == mask ? value : -value;
54 | }
55 |
56 | @OriginalApi
57 | public static void setState(Drawable drawable, int stateBitset) {
58 | drawable.setState(new int[]{
59 | unbitset(stateBitset, ITEM_STATE_FOCUSED_MASK, R.attr.state_focused),
60 | unbitset(stateBitset, ITEM_STATE_SELECTED_MASK, R.attr.state_selected),
61 | unbitset(stateBitset, ITEM_STATE_PRESSED_MASK, R.attr.state_pressed)
62 | });
63 | }
64 |
65 | @OriginalApi
66 | public Drawable getMarker(int stateBitset) {
67 | if (mMarker != null) {
68 | setState(mMarker, stateBitset);
69 | }
70 | return mMarker;
71 | }
72 |
73 | @OriginalApi
74 | public void setMarker(Drawable marker) {
75 | mMarker = marker;
76 | }
77 |
78 | @OriginalApi
79 | public GeoPoint getPoint() {
80 | return mPoint;
81 | }
82 |
83 | @OriginalApi
84 | public String getSnippet() {
85 | return mSnippet;
86 | }
87 |
88 | @OriginalApi
89 | public String getTitle() {
90 | return mTitle;
91 | }
92 |
93 | @OriginalApi
94 | public String routableAddress() {
95 | return mPoint.getLatitudeE6() / 1e6F + ", " + mPoint.getLongitudeE6() / 1e6F;
96 | }
97 |
98 | public org.osmdroid.views.overlay.OverlayItem toOsmdroid() {
99 | return new WrappedOverlayItem();
100 | }
101 |
102 | public class WrappedOverlayItem extends org.osmdroid.views.overlay.OverlayItem {
103 | public WrappedOverlayItem() {
104 | super(OverlayItem.this.mTitle, OverlayItem.this.mSnippet, mPoint.toOsmdroid());
105 | }
106 |
107 | public OverlayItem getOriginal() {
108 | return OverlayItem.this;
109 | }
110 | }
111 | }
112 |
--------------------------------------------------------------------------------
/mapsv1-compat-osmdroid/src/main/java/com/google/android/maps/OverlayList.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013-2016 microG Project Team
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.android.maps;
18 |
19 | import java.util.Collection;
20 | import java.util.Iterator;
21 | import java.util.List;
22 | import java.util.ListIterator;
23 |
24 | public class OverlayList implements List {
25 | private final List wrapped;
26 | private final NewOverlayAttachedListener attachedListener;
27 |
28 | public OverlayList(List wrapped, NewOverlayAttachedListener attachedListener) {
29 | this.wrapped = wrapped;
30 | this.attachedListener = attachedListener;
31 | }
32 |
33 | @Override
34 | public Overlay get(int location) {
35 | return Overlay.unwrap(wrapped.get(location));
36 | }
37 |
38 | @Override
39 | public int hashCode() {
40 | return wrapped.hashCode();
41 | }
42 |
43 | @Override
44 | public int indexOf(Object object) {
45 | return wrapped.indexOf(object);
46 | }
47 |
48 | @Override
49 | public boolean isEmpty() {
50 | return wrapped.isEmpty();
51 | }
52 |
53 | @Override
54 | public Iterator iterator() {
55 | return new OverlayListIterator(wrapped.listIterator());
56 | }
57 |
58 | @Override
59 | public int lastIndexOf(Object object) {
60 | return wrapped.lastIndexOf(object);
61 | }
62 |
63 | @Override
64 | public ListIterator listIterator() {
65 | return new OverlayListIterator(wrapped.listIterator());
66 | }
67 |
68 | @Override
69 | public ListIterator listIterator(int location) {
70 | return new OverlayListIterator(wrapped.listIterator(location));
71 | }
72 |
73 | @Override
74 | public Overlay remove(int location) {
75 | return Overlay.unwrap(wrapped.remove(location));
76 | }
77 |
78 | @Override
79 | public boolean remove(Object object) {
80 | return wrapped.remove(object);
81 | }
82 |
83 | @Override
84 | public boolean removeAll(Collection> collection) {
85 | return wrapped.removeAll(collection);
86 | }
87 |
88 | @Override
89 | public boolean retainAll(Collection> collection) {
90 | return wrapped.retainAll(collection);
91 | }
92 |
93 | @Override
94 | public Overlay set(int location, Overlay object) {
95 | attachedListener.onNewOverlayAttached(object);
96 | return Overlay.unwrap(wrapped.set(location, object));
97 | }
98 |
99 | @Override
100 | public void add(int location, Overlay object) {
101 | attachedListener.onNewOverlayAttached(object);
102 | wrapped.add(location, object);
103 | }
104 |
105 | @Override
106 | public boolean add(Overlay object) {
107 | attachedListener.onNewOverlayAttached(object);
108 | return wrapped.add(object);
109 | }
110 |
111 | @Override
112 | public boolean addAll(int location, Collection extends Overlay> collection) {
113 | for (Overlay overlay : collection) {
114 | attachedListener.onNewOverlayAttached(overlay);
115 | }
116 | return wrapped.addAll(location, collection);
117 | }
118 |
119 | @Override
120 | public boolean addAll(Collection extends Overlay> collection) {
121 | for (Overlay overlay : collection) {
122 | attachedListener.onNewOverlayAttached(overlay);
123 | }
124 | return wrapped.addAll(collection);
125 | }
126 |
127 | @Override
128 | public void clear() {
129 | wrapped.clear();
130 | }
131 |
132 | @Override
133 | public boolean contains(Object object) {
134 | return wrapped.contains(object);
135 | }
136 |
137 | @Override
138 | public boolean containsAll(Collection> collection) {
139 | return wrapped.containsAll(collection);
140 | }
141 |
142 | @Override
143 | public boolean equals(Object object) {
144 | return wrapped.equals(object);
145 | }
146 |
147 | @Override
148 | public int size() {
149 | return wrapped.size();
150 | }
151 |
152 | @Override
153 | public List subList(int start, int end) {
154 | return Overlay.unwrap(wrapped.subList(start, end));
155 | }
156 |
157 | @Override
158 | public Object[] toArray() {
159 | return wrapped.toArray();
160 | }
161 |
162 | @Override
163 | public T[] toArray(T[] array) {
164 | return wrapped.toArray(array);
165 | }
166 |
167 | interface NewOverlayAttachedListener {
168 | void onNewOverlayAttached(Overlay overlay);
169 | }
170 | }
171 |
--------------------------------------------------------------------------------
/mapsv1-compat-osmdroid/src/main/java/com/google/android/maps/OverlayListIterator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013-2016 microG Project Team
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.android.maps;
18 |
19 | import java.util.ListIterator;
20 |
21 | public class OverlayListIterator implements ListIterator {
22 |
23 | private final ListIterator iterator;
24 |
25 | public OverlayListIterator(ListIterator iterator) {
26 | this.iterator = iterator;
27 | }
28 |
29 | @Override
30 | public void add(Overlay object) {
31 | iterator.add(object);
32 | }
33 |
34 | @Override
35 | public boolean hasNext() {
36 | return iterator.hasNext();
37 | }
38 |
39 | @Override
40 | public boolean hasPrevious() {
41 | return iterator.hasPrevious();
42 | }
43 |
44 | @Override
45 | public Overlay next() {
46 | return Overlay.unwrap(iterator.next());
47 | }
48 |
49 | @Override
50 | public int nextIndex() {
51 | return iterator.nextIndex();
52 | }
53 |
54 | @Override
55 | public Overlay previous() {
56 | return Overlay.unwrap(iterator.previous());
57 | }
58 |
59 | @Override
60 | public int previousIndex() {
61 | return iterator.previousIndex();
62 | }
63 |
64 | @Override
65 | public void remove() {
66 | iterator.remove();
67 | }
68 |
69 | @Override
70 | public void set(Overlay object) {
71 | iterator.set(object);
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/mapsv1-compat-osmdroid/src/main/java/com/google/android/maps/Projection.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013-2016 microG Project Team
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.android.maps;
18 |
19 | import android.graphics.Point;
20 |
21 | import org.microg.annotation.OriginalApi;
22 | import org.osmdroid.api.IProjection;
23 |
24 | public interface Projection extends IProjection {
25 | @OriginalApi
26 | GeoPoint fromPixels(int x, int y);
27 |
28 | @OriginalApi
29 | float metersToEquatorPixels(float meters);
30 |
31 | @OriginalApi
32 | Point toPixels(GeoPoint in, Point out);
33 | }
34 |
--------------------------------------------------------------------------------
/mapsv1-compat-osmdroid/src/main/java/com/google/android/maps/ProjectionWrapper.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013-2016 microG Project Team
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.android.maps;
18 |
19 | import android.graphics.Point;
20 |
21 | import org.osmdroid.api.IGeoPoint;
22 | import org.osmdroid.api.IProjection;
23 |
24 | public class ProjectionWrapper implements Projection {
25 | private final IProjection wrapped;
26 |
27 | public ProjectionWrapper(IProjection wrapped) {
28 | this.wrapped = wrapped;
29 | }
30 |
31 | @Override
32 | public Point toPixels(IGeoPoint in, Point out) {
33 | return wrapped.toPixels(in, out);
34 | }
35 |
36 | @Override
37 | public GeoPoint fromPixels(int x, int y) {
38 | return new GeoPoint(wrapped.fromPixels(x, y));
39 | }
40 |
41 | @Override
42 | public float metersToEquatorPixels(float meters) {
43 | return wrapped.metersToEquatorPixels(meters);
44 | }
45 |
46 | @Override
47 | public IGeoPoint getNorthEast() {
48 | return wrapped.getNorthEast();
49 | }
50 |
51 | @Override
52 | public IGeoPoint getSouthWest() {
53 | return wrapped.getSouthWest();
54 | }
55 |
56 | @Override
57 | public Point toPixels(GeoPoint in, Point out) {
58 | return wrapped.toPixels(in, out);
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/mapsv1-compat-osmdroid/src/main/java/com/google/android/maps/TrackballGestureDetector.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013-2016 microG Project Team
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.android.maps;
18 |
19 | import android.view.MotionEvent;
20 |
21 | import org.microg.annotation.OriginalApi;
22 |
23 | @OriginalApi
24 | public class TrackballGestureDetector {
25 |
26 | @OriginalApi
27 | public void analyze(MotionEvent ev) {
28 | // TODO
29 | }
30 |
31 | @OriginalApi
32 | public float getCurrentDownX() {
33 | return 0; // TODO
34 | }
35 |
36 | @OriginalApi
37 | public float getCurrentDownY() {
38 | return 0; // TODO
39 | }
40 |
41 | @OriginalApi
42 | public float getFirstDownX() {
43 | return 0; // TODO
44 | }
45 |
46 | @OriginalApi
47 | public float getFirstDownY() {
48 | return 0; // TODO
49 | }
50 |
51 | @OriginalApi
52 | public boolean isDoubleTap() {
53 | return false; // TODO
54 | }
55 |
56 | @OriginalApi
57 | public boolean isScroll() {
58 | return false; // TODO
59 | }
60 |
61 | @OriginalApi
62 | public boolean isTap() {
63 | return false; // TODO
64 | }
65 |
66 | @OriginalApi
67 | public void registerLongPressCallback(Runnable runnable) {
68 | // TODO
69 | }
70 |
71 | @OriginalApi
72 | public float scrollX() {
73 | return 0; // TODO
74 | }
75 |
76 | @OriginalApi
77 | public float scrollY() {
78 | return 0; // TODO
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/mapsv1-compat-osmdroid/src/main/java/org/microg/annotation/OriginalApi.java:
--------------------------------------------------------------------------------
1 | package org.microg.annotation;
2 |
3 | /**
4 | * This annotation is intended for classes and methods that are based on the documentation of an original API.
5 | *
6 | * Do not change the signature of annotated items!
7 | */
8 | public @interface OriginalApi {
9 | }
10 |
--------------------------------------------------------------------------------
/mapsv1-compat-osmdroid/src/main/java/org/microg/internal/R.java:
--------------------------------------------------------------------------------
1 | package org.microg.internal;
2 |
3 | import android.util.Log;
4 |
5 | import java.lang.reflect.Field;
6 |
7 | /**
8 | * This class is used to access com.android.internal.R
9 | *
10 | * It is used the same way as the original it uses reflection to retrieve the data.
11 | */
12 | public class R {
13 | private static final String TAG = R.class.getName();
14 |
15 | private static Field getField(String type, String name) {
16 | try {
17 | Class cls = Class.forName("com.android.internal.R$" + type);
18 | return cls.getField(name);
19 | } catch (Exception e) {
20 | Log.w(TAG, "Could not retrieve com.android.internal.R." + type + "." + name, e);
21 | return null;
22 | }
23 | }
24 |
25 | private static Object get(String type, String name) {
26 | try {
27 | Field field = getField(type, name);
28 | return field == null ? null : field.get(null);
29 | } catch (Exception e) {
30 | Log.w(TAG, "Could not retrieve com.android.internal.R." + type + "." + name, e);
31 | return null;
32 | }
33 | }
34 |
35 | private static int getInt(String type, String name) {
36 | try {
37 | Field field = getField(type, name);
38 | return field == null ? -1 : field.getInt(null);
39 | } catch (Exception e) {
40 | Log.w(TAG, "Could not retrieve com.android.internal.R." + type + "." + name, e);
41 | return -1;
42 | }
43 | }
44 |
45 | public static final class array {
46 | private static final String TYPE = "array";
47 | public static final int maps_starting_lat_lng = getInt(TYPE, "maps_starting_lat_lng");
48 | public static final int maps_starting_zoom = getInt(TYPE, "maps_starting_zoom");
49 | }
50 |
51 | public static final class attr {
52 | private static final String TYPE = "attr";
53 | public static final int mapViewStyle = getInt(TYPE, "mapViewStyle");
54 | public static final int state_focused = getInt(TYPE, "state_focused");
55 | public static final int state_pressed = getInt(TYPE, "state_pressed");
56 | public static final int state_selected = getInt(TYPE, "state_selected");
57 | }
58 |
59 | public static final class styleable {
60 | private static final String TYPE = "styleable";
61 | public static final int[] MapView = (int[]) get(TYPE, "MapView");
62 | public static final int MapView_apiKey = getInt(TYPE, "MapView_apiKey");
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/mapsv1-compat-osmdroid/src/main/java/org/microg/osmdroid/CustomResourceProxyImpl.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013-2016 microG Project Team
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.microg.osmdroid;
18 |
19 | import android.content.Context;
20 | import android.content.res.Resources;
21 | import android.graphics.Bitmap;
22 | import android.graphics.BitmapFactory;
23 | import android.graphics.drawable.BitmapDrawable;
24 | import android.graphics.drawable.Drawable;
25 | import android.util.DisplayMetrics;
26 | import android.util.Log;
27 |
28 | import com.google.android.maps.MapView;
29 |
30 | import org.osmdroid.ResourceProxy;
31 |
32 | public class CustomResourceProxyImpl implements ResourceProxy {
33 | private static final String TAG = "MapResProxy";
34 |
35 | private static Bitmap EMPTY_BITMAP;
36 |
37 | private final Resources resources;
38 | private final DisplayMetrics displayMetrics;
39 |
40 | public CustomResourceProxyImpl() {
41 | this(null, null);
42 | }
43 |
44 | public CustomResourceProxyImpl(Context context) {
45 | this(context.getResources(), null);
46 | }
47 |
48 | public CustomResourceProxyImpl(Resources resources, DisplayMetrics displayMetrics) {
49 | this.resources = resources != null ? resources : MapView.DEFAULT_CONTEXT != null ? MapView.DEFAULT_CONTEXT.getResources() : null;
50 | this.displayMetrics = displayMetrics != null ? displayMetrics : this.resources != null ? this.resources.getDisplayMetrics() : generateDisplayMetrics();
51 | }
52 |
53 | private static DisplayMetrics generateDisplayMetrics() {
54 | DisplayMetrics displayMetrics = new DisplayMetrics();
55 | displayMetrics.setToDefaults();
56 | return displayMetrics;
57 | }
58 |
59 | @Override
60 | public String getString(string pResId) {
61 | switch (pResId) {
62 | case unknown:
63 | return "Unknown";
64 | case format_distance_meters:
65 | return "%s m";
66 | case format_distance_kilometers:
67 | return "%s km";
68 | case format_distance_miles:
69 | return "%s mi";
70 | case format_distance_nautical_miles:
71 | return "%s nm";
72 | case format_distance_feet:
73 | return "%s ft";
74 | case online_mode:
75 | return "Online mode";
76 | case offline_mode:
77 | return "Offline mode";
78 | case my_location:
79 | return "My location";
80 | case compass:
81 | return "Compass";
82 | case map_mode:
83 | return "Map mode";
84 |
85 | default:
86 | Log.w(TAG, "Unknown resource string: " + pResId);
87 | return "";
88 | }
89 | }
90 |
91 | @Override
92 | public String getString(string pResId, Object... formatArgs) {
93 | return String.format(getString(pResId), formatArgs);
94 | }
95 |
96 | @Override
97 | public Bitmap getBitmap(bitmap pResId) {
98 | try {
99 | switch (pResId) {
100 | case ic_menu_compass:
101 | return BitmapFactory.decodeResource(resources, android.R.drawable.ic_menu_compass);
102 | case ic_menu_mapmode:
103 | return BitmapFactory.decodeResource(resources, android.R.drawable.ic_menu_mapmode);
104 | case ic_menu_mylocation:
105 | return BitmapFactory.decodeResource(resources, android.R.drawable.ic_menu_mylocation);
106 | case next:
107 | return BitmapFactory.decodeResource(resources, android.R.drawable.ic_media_next);
108 | case previous:
109 | return BitmapFactory.decodeResource(resources, android.R.drawable.ic_media_previous);
110 | case center:
111 | case direction_arrow:
112 | case ic_menu_offline:
113 | case marker_default:
114 | case marker_default_focused_base:
115 | case navto_small:
116 | case person:
117 | case unknown:
118 | default:
119 | Log.w(TAG, "Unknown resource bitmap: " + pResId);
120 | return generateEmptyBitmap();
121 | }
122 | } catch (Exception e) {
123 | Log.w(TAG, "Error loading resource bitmap: " + pResId, e);
124 | return generateEmptyBitmap();
125 | }
126 | }
127 |
128 | private static Bitmap generateEmptyBitmap() {
129 | if (EMPTY_BITMAP == null) {
130 | EMPTY_BITMAP = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
131 | }
132 | return EMPTY_BITMAP;
133 | }
134 |
135 | @Override
136 | public Drawable getDrawable(bitmap pResId) {
137 | return new BitmapDrawable(getBitmap(pResId));
138 | }
139 |
140 | @Override
141 | public float getDisplayMetricsDensity() {
142 | return getDisplayMetrics().density;
143 | }
144 |
145 | @Override
146 | public DisplayMetrics getDisplayMetrics() {
147 | return displayMetrics;
148 | }
149 | }
150 |
--------------------------------------------------------------------------------
/mapsv1-compat-osmdroid/src/main/java/org/microg/osmdroid/SafeMapTileFilesystemProvider.java:
--------------------------------------------------------------------------------
1 | package org.microg.osmdroid;
2 |
3 | import java.io.File;
4 | import java.io.InputStream;
5 | import java.util.concurrent.atomic.AtomicReference;
6 |
7 | import org.osmdroid.tileprovider.BitmapPool;
8 | import org.osmdroid.tileprovider.ExpirableBitmapDrawable;
9 | import org.osmdroid.tileprovider.IRegisterReceiver;
10 | import org.osmdroid.tileprovider.MapTile;
11 | import org.osmdroid.tileprovider.MapTileRequestState;
12 | import org.osmdroid.tileprovider.ReusableBitmapDrawable;
13 | import org.osmdroid.tileprovider.modules.DatabaseFileArchive;
14 | import org.osmdroid.tileprovider.modules.MapTileFileStorageProviderBase;
15 | import org.osmdroid.tileprovider.modules.MapTileModuleProviderBase;
16 | import org.osmdroid.tileprovider.tilesource.BitmapTileSourceBase.LowMemoryException;
17 | import org.osmdroid.tileprovider.tilesource.ITileSource;
18 | import org.osmdroid.tileprovider.tilesource.TileSourceFactory;
19 |
20 | import android.Manifest;
21 | import android.content.Context;
22 | import android.content.pm.PackageManager;
23 | import android.graphics.Bitmap;
24 | import android.graphics.BitmapFactory;
25 | import android.graphics.drawable.BitmapDrawable;
26 | import android.graphics.drawable.Drawable;
27 | import android.util.Log;
28 | import org.osmdroid.api.IMapView;
29 | import org.osmdroid.tileprovider.constants.OpenStreetMapTileProviderConstants;
30 |
31 | /**
32 | * Implements a file system cache and provides cached tiles. This functions as a tile provider by
33 | * serving cached tiles for the supplied tile source.
34 | *
35 | * @author Marc Kurtz
36 | * @author Nicolas Gramlich
37 | *
38 | */
39 | public class SafeMapTileFilesystemProvider extends MapTileFileStorageProviderBase {
40 |
41 | // ===========================================================
42 | // Constants
43 | // ===========================================================
44 |
45 | // ===========================================================
46 | // Fields
47 | // ===========================================================
48 |
49 | private final long mMaximumCachedFileAge;
50 | private DatabaseFileArchive databaseFileArchive;
51 | private final AtomicReference mTileSource = new AtomicReference();
52 |
53 | private final File safeTilePathBase;
54 |
55 | // ===========================================================
56 | // Constructors
57 | // ===========================================================
58 |
59 | public SafeMapTileFilesystemProvider(Context context, final IRegisterReceiver pRegisterReceiver) {
60 | this(context, pRegisterReceiver, TileSourceFactory.DEFAULT_TILE_SOURCE);
61 | }
62 |
63 | public SafeMapTileFilesystemProvider(Context context, final IRegisterReceiver pRegisterReceiver,
64 | final ITileSource aTileSource) {
65 | this(context, pRegisterReceiver, aTileSource, OpenStreetMapTileProviderConstants.DEFAULT_MAXIMUM_CACHED_FILE_AGE);
66 | }
67 |
68 | public SafeMapTileFilesystemProvider(Context context, final IRegisterReceiver pRegisterReceiver,
69 | final ITileSource pTileSource, final long pMaximumCachedFileAge) {
70 | this(context, pRegisterReceiver, pTileSource, pMaximumCachedFileAge,
71 | OpenStreetMapTileProviderConstants.NUMBER_OF_TILE_FILESYSTEM_THREADS,
72 | OpenStreetMapTileProviderConstants.TILE_FILESYSTEM_MAXIMUM_QUEUE_SIZE);
73 | }
74 |
75 | /**
76 | * Provides a file system based cache tile provider. Other providers can register and store data
77 | * in the cache.
78 | *
79 | * @param pRegisterReceiver
80 | */
81 | public SafeMapTileFilesystemProvider(Context context, final IRegisterReceiver pRegisterReceiver,
82 | final ITileSource pTileSource, final long pMaximumCachedFileAge, int pThreadPoolSize,
83 | int pPendingQueueSize) {
84 | super(pRegisterReceiver, pThreadPoolSize, pPendingQueueSize);
85 | if (context.checkCallingOrSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
86 | safeTilePathBase = OpenStreetMapTileProviderConstants.TILE_PATH_BASE;
87 | } else {
88 | safeTilePathBase = new File(context.getExternalCacheDir(), "tiles");
89 | }
90 | setTileSource(pTileSource);
91 |
92 | mMaximumCachedFileAge = pMaximumCachedFileAge;
93 | }
94 | // ===========================================================
95 | // Getter & Setter
96 | // ===========================================================
97 |
98 | // ===========================================================
99 | // Methods from SuperClass/Interfaces
100 | // ===========================================================
101 |
102 | @Override
103 | public boolean getUsesDataConnection() {
104 | return false;
105 | }
106 |
107 | @Override
108 | protected String getName() {
109 | return "File System Cache Provider";
110 | }
111 |
112 | @Override
113 | protected String getThreadGroupName() {
114 | return "filesystem";
115 | }
116 |
117 | @Override
118 | protected Runnable getTileLoader() {
119 | return new TileLoader();
120 | }
121 |
122 | @Override
123 | public int getMinimumZoomLevel() {
124 | ITileSource tileSource = mTileSource.get();
125 | return tileSource != null ? tileSource.getMinimumZoomLevel() : OpenStreetMapTileProviderConstants.MINIMUM_ZOOMLEVEL;
126 | }
127 |
128 | @Override
129 | public int getMaximumZoomLevel() {
130 | ITileSource tileSource = mTileSource.get();
131 | return tileSource != null ? tileSource.getMaximumZoomLevel()
132 | : microsoft.mappoint.TileSystem.getMaximumZoomLevel();
133 | }
134 |
135 | @Override
136 | public void setTileSource(final ITileSource pTileSource) {
137 | mTileSource.set(pTileSource);
138 | }
139 |
140 | // ===========================================================
141 | // Inner and Anonymous Classes
142 | // ===========================================================
143 |
144 | protected class TileLoader extends MapTileModuleProviderBase.TileLoader {
145 |
146 | @Override
147 | public Drawable loadTile(final MapTileRequestState pState) throws CantContinueException {
148 |
149 | ITileSource tileSource = mTileSource.get();
150 | if (tileSource == null) {
151 | return null;
152 | }
153 |
154 | final MapTile tile = pState.getMapTile();
155 |
156 | // if there's no sdcard then don't do anything
157 | if (!getSdCardAvailable()) {
158 | if (OpenStreetMapTileProviderConstants.DEBUGMODE) {
159 | Log.d(IMapView.LOGTAG,"No sdcard - do nothing for tile: " + tile);
160 | }
161 | return null;
162 | }
163 |
164 | // Check the tile source to see if its file is available and if so, then render the
165 | // drawable and return the tile
166 | final File file = new File(safeTilePathBase,
167 | tileSource.getTileRelativeFilenameString(tile) + OpenStreetMapTileProviderConstants.TILE_PATH_EXTENSION);
168 | if (file.exists()) {
169 |
170 | try {
171 | final Drawable drawable = tileSource.getDrawable(file.getPath());
172 |
173 | // Check to see if file has expired
174 | final long now = System.currentTimeMillis();
175 | final long lastModified = file.lastModified();
176 | final boolean fileExpired = lastModified < now - mMaximumCachedFileAge;
177 |
178 | if (fileExpired && drawable != null) {
179 | if (OpenStreetMapTileProviderConstants.DEBUGMODE) {
180 | Log.d(IMapView.LOGTAG,"Tile expired: " + tile);
181 | }
182 | ExpirableBitmapDrawable.setDrawableExpired(drawable);
183 | }
184 |
185 | return drawable;
186 | } catch (final LowMemoryException e) {
187 | // low memory so empty the queue
188 | Log.w(IMapView.LOGTAG,"LowMemoryException downloading MapTile: " + tile + " : " + e);
189 | throw new CantContinueException(e);
190 | }
191 | }
192 |
193 | // If we get here then there is no file in the file cache
194 | return null;
195 | }
196 | }
197 | }
198 |
--------------------------------------------------------------------------------
/mapsv1-compat-osmdroid/src/main/java/org/microg/osmdroid/SafeMapTileProviderBasic.java:
--------------------------------------------------------------------------------
1 | package org.microg.osmdroid;
2 |
3 | import android.content.Context;
4 | import org.osmdroid.tileprovider.IMapTileProviderCallback;
5 | import org.osmdroid.tileprovider.IRegisterReceiver;
6 | import org.osmdroid.tileprovider.MapTileProviderArray;
7 | import org.osmdroid.tileprovider.modules.INetworkAvailablityCheck;
8 | import org.osmdroid.tileprovider.modules.MapTileDownloader;
9 | import org.osmdroid.tileprovider.modules.NetworkAvailabliltyCheck;
10 | import org.osmdroid.tileprovider.tilesource.ITileSource;
11 | import org.osmdroid.tileprovider.tilesource.TileSourceFactory;
12 | import org.osmdroid.tileprovider.util.SimpleRegisterReceiver;
13 |
14 | /**
15 | * This version differs from the original in that it uses the Safe classes instead of the default ones.
16 | */
17 | public class SafeMapTileProviderBasic extends MapTileProviderArray implements IMapTileProviderCallback {
18 |
19 | // private static final Logger logger = LoggerFactory.getLogger(MapTileProviderBasic.class);
20 |
21 | /**
22 | * Creates a {@link SafeMapTileProviderBasic}.
23 | */
24 | public SafeMapTileProviderBasic(final Context pContext) {
25 | this(pContext, TileSourceFactory.DEFAULT_TILE_SOURCE);
26 | }
27 |
28 | /**
29 | * Creates a {@link SafeMapTileProviderBasic}.
30 | */
31 | public SafeMapTileProviderBasic(final Context pContext, final ITileSource pTileSource) {
32 | this(pContext, new SimpleRegisterReceiver(pContext), new NetworkAvailabliltyCheck(pContext),
33 | pTileSource);
34 | }
35 |
36 | /**
37 | * Creates a {@link SafeMapTileProviderBasic}.
38 | */
39 | public SafeMapTileProviderBasic(Context context, final IRegisterReceiver pRegisterReceiver,
40 | final INetworkAvailablityCheck aNetworkAvailablityCheck, final ITileSource pTileSource) {
41 | super(pTileSource, pRegisterReceiver);
42 |
43 | final SafeTileWriter tileWriter = new SafeTileWriter(context);
44 |
45 | final SafeMapTileFilesystemProvider fileSystemProvider = new SafeMapTileFilesystemProvider(context,
46 | pRegisterReceiver, pTileSource);
47 | mTileProviderList.add(fileSystemProvider);
48 |
49 | final MapTileDownloader downloaderProvider = new MapTileDownloader(pTileSource, tileWriter,
50 | aNetworkAvailablityCheck);
51 | mTileProviderList.add(downloaderProvider);
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/mapsv1-compat-osmdroid/src/main/java/org/microg/osmdroid/SafeNetworkAvailabilityCheck.java:
--------------------------------------------------------------------------------
1 | package org.microg.osmdroid;
2 |
3 | import android.Manifest;
4 | import android.content.Context;
5 | import android.content.pm.PackageManager;
6 | import org.osmdroid.tileprovider.modules.NetworkAvailabliltyCheck;
7 |
8 | /**
9 | * A straightforward network check implementation, based on the original implementation,
10 | * that assumes to be online if the permission to check is not given.
11 | */
12 | public class SafeNetworkAvailabilityCheck extends NetworkAvailabliltyCheck {
13 |
14 | private final boolean hasAccessNetworkStatePermission;
15 | private final boolean hasChangeNetworkStatePermission;
16 |
17 | public SafeNetworkAvailabilityCheck(Context context) {
18 | super(context);
19 | hasAccessNetworkStatePermission = context.checkCallingOrSelfPermission(Manifest.permission.ACCESS_NETWORK_STATE) == PackageManager.PERMISSION_GRANTED;
20 | hasChangeNetworkStatePermission = context.checkCallingOrSelfPermission(Manifest.permission.CHANGE_NETWORK_STATE) == PackageManager.PERMISSION_GRANTED;
21 | }
22 |
23 | @Override
24 | public boolean getNetworkAvailable() {
25 | return !hasAccessNetworkStatePermission || super.getNetworkAvailable();
26 | }
27 |
28 | @Override
29 | public boolean getWiFiNetworkAvailable() {
30 | return !hasAccessNetworkStatePermission || super.getWiFiNetworkAvailable();
31 | }
32 |
33 | @Override
34 | public boolean getCellularDataNetworkAvailable() {
35 | return !hasAccessNetworkStatePermission || super.getCellularDataNetworkAvailable();
36 | }
37 |
38 | @Override
39 | public boolean getRouteToPathExists(int hostAddress) {
40 | return !hasChangeNetworkStatePermission || super.getRouteToPathExists(hostAddress);
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/mapsv1-compat-osmdroid/src/main/java/org/microg/osmdroid/SafeTileWriter.java:
--------------------------------------------------------------------------------
1 | package org.microg.osmdroid;
2 |
3 | import android.Manifest;
4 | import android.content.Context;
5 | import android.content.pm.PackageManager;
6 | import android.util.Log;
7 | import java.io.BufferedOutputStream;
8 | import java.io.File;
9 | import java.io.FileOutputStream;
10 | import java.io.IOException;
11 | import java.io.InputStream;
12 | import java.util.ArrayList;
13 | import java.util.Arrays;
14 | import java.util.Comparator;
15 | import java.util.List;
16 | import java.util.NoSuchElementException;
17 | import org.osmdroid.api.IMapView;
18 |
19 | import org.osmdroid.tileprovider.MapTile;
20 | import org.osmdroid.tileprovider.constants.OpenStreetMapTileProviderConstants;
21 | import org.osmdroid.tileprovider.modules.IFilesystemCache;
22 | import org.osmdroid.tileprovider.tilesource.ITileSource;
23 | import org.osmdroid.tileprovider.util.StreamUtils;
24 |
25 | /**
26 | * An implementation of {@link IFilesystemCache}. It writes tiles to the file system cache. If the
27 | * cache exceeds 600 Mb then it will be trimmed to 500 Mb.
28 | *
29 | * This modified version checks if the default cache is accessible (by checking for the
30 | * WRITE_EXTERNAL_STORAGE-permission) and uses an app-specific cache if not.
31 | *
32 | * @author Neil Boyd
33 | *
34 | */
35 | public class SafeTileWriter implements IFilesystemCache {
36 |
37 | // ===========================================================
38 | // Constants
39 | // ===========================================================
40 |
41 |
42 | // ===========================================================
43 | // Fields
44 | // ===========================================================
45 |
46 | /** amount of disk space used by tile cache **/
47 | private static long mUsedCacheSpace;
48 |
49 | private final File safeTilePathBase;
50 |
51 | // ===========================================================
52 | // Constructors
53 | // ===========================================================
54 |
55 | public SafeTileWriter(Context context) {
56 |
57 | if (context.checkCallingOrSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
58 | safeTilePathBase = OpenStreetMapTileProviderConstants.TILE_PATH_BASE;
59 | } else {
60 | safeTilePathBase = new File(context.getExternalCacheDir(), "tiles");
61 | }
62 |
63 | // do this in the background because it takes a long time
64 | final Thread t = new Thread() {
65 | @Override
66 | public void run() {
67 | mUsedCacheSpace = 0; // because it's static
68 |
69 | calculateDirectorySize(safeTilePathBase);
70 |
71 | if (mUsedCacheSpace > OpenStreetMapTileProviderConstants.TILE_MAX_CACHE_SIZE_BYTES) {
72 | cutCurrentCache();
73 | }
74 | if (OpenStreetMapTileProviderConstants.DEBUGMODE) {
75 | Log.d(IMapView.LOGTAG,"Finished init thread");
76 | }
77 | }
78 | };
79 | t.setPriority(Thread.MIN_PRIORITY);
80 | t.start();
81 | }
82 |
83 | // ===========================================================
84 | // Getter & Setter
85 | // ===========================================================
86 |
87 | /**
88 | * Get the amount of disk space used by the tile cache. This will initially be zero since the
89 | * used space is calculated in the background.
90 | *
91 | * @return size in bytes
92 | */
93 | public static long getUsedCacheSpace() {
94 | return mUsedCacheSpace;
95 | }
96 |
97 | // ===========================================================
98 | // Methods from SuperClass/Interfaces
99 | // ===========================================================
100 |
101 | @Override
102 | public boolean saveFile(final ITileSource pTileSource, final MapTile pTile,
103 | final InputStream pStream) {
104 |
105 | final File file = new File(safeTilePathBase, pTileSource.getTileRelativeFilenameString(pTile)
106 | + OpenStreetMapTileProviderConstants.TILE_PATH_EXTENSION);
107 |
108 | final File parent = file.getParentFile();
109 | if (!parent.exists() && !createFolderAndCheckIfExists(parent)) {
110 | return false;
111 | }
112 |
113 | BufferedOutputStream outputStream = null;
114 | try {
115 | outputStream = new BufferedOutputStream(new FileOutputStream(file.getPath()),
116 | StreamUtils.IO_BUFFER_SIZE);
117 | final long length = StreamUtils.copy(pStream, outputStream);
118 |
119 | mUsedCacheSpace += length;
120 | if (mUsedCacheSpace > OpenStreetMapTileProviderConstants.TILE_MAX_CACHE_SIZE_BYTES) {
121 | cutCurrentCache(); // TODO perhaps we should do this in the background
122 | }
123 | } catch (final IOException e) {
124 | return false;
125 | } finally {
126 | if (outputStream != null) {
127 | StreamUtils.closeStream(outputStream);
128 | }
129 | }
130 | return true;
131 | }
132 |
133 | // ===========================================================
134 | // Methods
135 | // ===========================================================
136 |
137 | private boolean createFolderAndCheckIfExists(final File pFile) {
138 | if (pFile.mkdirs()) {
139 | return true;
140 | }
141 | if (OpenStreetMapTileProviderConstants.DEBUGMODE) {
142 | Log.d(IMapView.LOGTAG,"Failed to create " + pFile + " - wait and check again");
143 | }
144 |
145 | // if create failed, wait a bit in case another thread created it
146 | try {
147 | Thread.sleep(500);
148 | } catch (final InterruptedException ignore) {
149 | }
150 | // and then check again
151 | if (pFile.exists()) {
152 | if (OpenStreetMapTileProviderConstants.DEBUGMODE) {
153 | Log.d(IMapView.LOGTAG,"Seems like another thread created " + pFile);
154 | }
155 | return true;
156 | } else {
157 | if (OpenStreetMapTileProviderConstants.DEBUGMODE) {
158 | Log.d(IMapView.LOGTAG,"File still doesn't exist: " + pFile);
159 | }
160 | return false;
161 | }
162 | }
163 |
164 | private void calculateDirectorySize(final File pDirectory) {
165 | final File[] z = pDirectory.listFiles();
166 | if (z != null) {
167 | for (final File file : z) {
168 | if (file.isFile()) {
169 | mUsedCacheSpace += file.length();
170 | }
171 | if (file.isDirectory() && !isSymbolicDirectoryLink(pDirectory, file)) {
172 | calculateDirectorySize(file); // *** recurse ***
173 | }
174 | }
175 | }
176 | }
177 |
178 | /**
179 | * Checks to see if it appears that a directory is a symbolic link. It does this by comparing
180 | * the canonical path of the parent directory and the parent directory of the directory's
181 | * canonical path. If they are equal, then they come from the same true parent. If not, then
182 | * pDirectory is a symbolic link. If we get an exception, we err on the side of caution and
183 | * return "true" expecting the calculateDirectorySize to now skip further processing since
184 | * something went goofy.
185 | */
186 | private boolean isSymbolicDirectoryLink(final File pParentDirectory, final File pDirectory) {
187 | try {
188 | final String canonicalParentPath1 = pParentDirectory.getCanonicalPath();
189 | final String canonicalParentPath2 = pDirectory.getCanonicalFile().getParent();
190 | return !canonicalParentPath1.equals(canonicalParentPath2);
191 | } catch (final IOException e) {
192 | return true;
193 | } catch (final NoSuchElementException e) {
194 | // See: http://code.google.com/p/android/issues/detail?id=4961
195 | // See: http://code.google.com/p/android/issues/detail?id=5807
196 | return true;
197 | }
198 |
199 | }
200 |
201 | private List getDirectoryFileList(final File aDirectory) {
202 | final List files = new ArrayList();
203 |
204 | final File[] z = aDirectory.listFiles();
205 | if (z != null) {
206 | for (final File file : z) {
207 | if (file.isFile()) {
208 | files.add(file);
209 | }
210 | if (file.isDirectory()) {
211 | files.addAll(getDirectoryFileList(file));
212 | }
213 | }
214 | }
215 |
216 | return files;
217 | }
218 |
219 | /**
220 | * If the cache size is greater than the max then trim it down to the trim level. This method is
221 | * synchronized so that only one thread can run it at a time.
222 | */
223 | private void cutCurrentCache() {
224 |
225 | final File lock=safeTilePathBase;
226 | synchronized (lock) {
227 |
228 | if (mUsedCacheSpace > OpenStreetMapTileProviderConstants.TILE_TRIM_CACHE_SIZE_BYTES) {
229 |
230 | Log.d(IMapView.LOGTAG,"Trimming tile cache from " + mUsedCacheSpace + " to "
231 | + OpenStreetMapTileProviderConstants.TILE_TRIM_CACHE_SIZE_BYTES);
232 |
233 | final List z = getDirectoryFileList(safeTilePathBase);
234 |
235 | // order list by files day created from old to new
236 | final File[] files = z.toArray(new File[0]);
237 | Arrays.sort(files, new Comparator() {
238 | @Override
239 | public int compare(final File f1, final File f2) {
240 | return Long.valueOf(f1.lastModified()).compareTo(f2.lastModified());
241 | }
242 | });
243 |
244 | for (final File file : files) {
245 | if (mUsedCacheSpace <= OpenStreetMapTileProviderConstants.TILE_TRIM_CACHE_SIZE_BYTES) {
246 | break;
247 | }
248 |
249 | final long length = file.length();
250 | if (file.delete()) {
251 | mUsedCacheSpace -= length;
252 | }
253 | }
254 |
255 | Log.d(IMapView.LOGTAG,"Finished trimming tile cache");
256 | }
257 | }
258 | }
259 |
260 | }
261 |
--------------------------------------------------------------------------------
/mapsv1-flashable/build.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013-2015 microG Project Team
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | def BUILD_TOOLS_VERSION = "23.0.2"
18 | def ANDROID_SDK_DIR = System.env.ANDROID_HOME
19 |
20 | Properties properties = new Properties()
21 | if (file(project.rootProject.file('local.properties')).exists()) {
22 | properties.load(project.rootProject.file('local.properties').newDataInputStream())
23 | } else {
24 | println "No local.properties file found. This is likely to cause problems."
25 | }
26 |
27 | if (!ANDROID_SDK_DIR) {
28 | ANDROID_SDK_DIR = properties.getProperty('sdk.dir')
29 | }
30 | if (!ANDROID_SDK_DIR) {
31 | println "Android SDK could not be found, either set ANDROID_HOME environment variable or configure 'sdk.dir' in local.properties."
32 | }
33 | if (!file(ANDROID_SDK_DIR).exists()) {
34 | println "Android SDK not found at '$ANDROID_SDK_DIR', either set ANDROID_HOME environment variable or configure 'sdk.dir' in local.properties."
35 | }
36 | def BUILD_TOOLS_DX = "$ANDROID_SDK_DIR/build-tools/$BUILD_TOOLS_VERSION/dx"
37 | if (!file(BUILD_TOOLS_DX).exists()) {
38 | println "Could not find build tools $BUILD_TOOLS_VERSION in Android SDK."
39 | }
40 |
41 | def SIGN_STORE_FILE = properties.getProperty("sign.storeFile");
42 | def SIGN_STORE_PASS = properties.getProperty("sign.storePassword");
43 | def SIGN_KEY_ALIAS = properties.getProperty("sign.keyAlias");
44 | def SIGN_KEY_PASS = properties.getProperty("sign.keyPassword");
45 |
46 | if (!SIGN_STORE_FILE) {
47 | SIGN_STORE_FILE = System.env.HOME + '/.keystore'
48 | }
49 | if (!SIGN_STORE_FILE || !file(SIGN_STORE_FILE).exists()) {
50 | println "No key store for jarsigner defined and/or '$SIGN_STORE_FILE' does not exist. Use sign.storeFile in local.properties to define a custom key store."
51 | }
52 | if (!SIGN_STORE_PASS || !SIGN_KEY_ALIAS || !SIGN_KEY_PASS) {
53 | println "Details to access key incomplete. Make sure to define sign.storePassword, sign.keyAlias and sign.keyPassword in local.properties"
54 | }
55 |
56 | repositories {
57 | jcenter()
58 | }
59 |
60 | dependencies {
61 | project(':mapsv1-compat-osmdroid')
62 | }
63 |
64 | task prepareFrameworkDex(type: Copy, dependsOn: ':mapsv1-compat-osmdroid:assembleRelease') {
65 | project(':mapsv1-compat-osmdroid').configurations.compile.asFileTree.each {
66 | if (it.name.endsWith(".aar"))
67 | zipTree(it).each { if (it.name.equals("classes.jar")) from zipTree(it) }
68 | else
69 | from zipTree(it) }
70 | from zipTree(project(':mapsv1-compat-osmdroid').file('build/intermediates/bundles/release/classes.jar'))
71 | into 'build/intermediates/classes'
72 | exclude 'META-INF/**'
73 | include '**/*.class'
74 | } << {
75 | file('build/intermediates/bundle').mkdirs()
76 | }
77 |
78 | task frameworkDex(type: Exec, dependsOn: prepareFrameworkDex) {
79 | executable "${BUILD_TOOLS_DX}"
80 | args "--dex"
81 | args "--output="+file('build/intermediates/bundle/classes.dex').path
82 | args file('build/intermediates/classes').path
83 | }
84 |
85 | task frameworkJar(type: Jar, dependsOn: frameworkDex) {
86 | destinationDir file('build/intermediates/flashableZip/system/framework')
87 | baseName 'com.google.android.maps'
88 | from 'build/intermediates/bundle'
89 | }
90 |
91 | task signFrameworkJar(type: Exec, dependsOn: frameworkJar) {
92 | executable "jarsigner"
93 | args '-keystore', "$SIGN_STORE_FILE"
94 | args '-storepass', "$SIGN_STORE_PASS"
95 | args '-keypass', "$SIGN_KEY_PASS"
96 | args '-sigalg', 'SHA1withRSA'
97 | args '-digestalg', 'SHA1'
98 | args file('build/intermediates/flashableZip/system/framework/com.google.android.maps.jar').path
99 | args "$SIGN_KEY_ALIAS"
100 | }
101 |
102 | task flashableZip(type: Zip, dependsOn: signFrameworkJar) {
103 | destinationDir file('build/outputs')
104 | baseName 'mapsv1.flashable'
105 | from 'src/main/files/'
106 | from 'build/intermediates/flashableZip'
107 | }
108 |
109 | task signFlashableZip(type: Exec, dependsOn: flashableZip) {
110 | executable "jarsigner"
111 | args '-keystore', "$SIGN_STORE_FILE"
112 | args '-storepass', "$SIGN_STORE_PASS"
113 | args '-keypass', "$SIGN_KEY_PASS"
114 | args '-sigalg', 'SHA1withRSA'
115 | args '-digestalg', 'SHA1'
116 | args file('build/outputs/mapsv1.flashable.zip').path
117 | args "$SIGN_KEY_ALIAS"
118 | }
119 |
120 | task assembleRelease(dependsOn: signFlashableZip)
121 |
122 | task assemble(dependsOn: assembleRelease)
123 |
124 | task build(dependsOn: assemble)
125 |
126 | task clean(type: Delete) {
127 | delete 'build'
128 | }
129 |
130 | if (file('user.gradle').exists()) {
131 | apply from: 'user.gradle'
132 | }
133 |
--------------------------------------------------------------------------------
/mapsv1-flashable/src/main/files/META-INF/com/google/android/update-binary:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microg/android_frameworks_mapsv1/49e09748da4a50df19dae8d56cc09e10602fbe18/mapsv1-flashable/src/main/files/META-INF/com/google/android/update-binary
--------------------------------------------------------------------------------
/mapsv1-flashable/src/main/files/META-INF/com/google/android/updater-script:
--------------------------------------------------------------------------------
1 | show_progress(0.2, 0);
2 | ui_print("Mounting /system...");
3 | run_program("/sbin/busybox", "mount", "/system");
4 |
5 | show_progress(0.3, 0);
6 | ui_print("Extracting package...");
7 | package_extract_dir("system", "/system");
8 |
9 | show_progress(0.8, 0);
10 | ui_print("Unmounting /system...");
11 | unmount("/system");
12 |
13 | show_progress(1.0, 0);
14 | ui_print("Done");
--------------------------------------------------------------------------------
/mapsv1-flashable/src/main/files/system/addon.d/10-mapsapi.sh:
--------------------------------------------------------------------------------
1 | #!/sbin/sh
2 | #
3 | # /system/addon.d/10-mapsapi.sh
4 | #
5 | . /tmp/backuptool.functions
6 |
7 | list_files() {
8 | cat <
2 |
16 |
17 |
18 |
20 |
21 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':mapsv1-compat-osmdroid'
2 | include ':mapsv1-flashable'
3 |
--------------------------------------------------------------------------------