├── .github
└── workflows
│ ├── docs.yml
│ └── sdk-test.yml
├── .gitignore
├── README.md
├── app
├── .gitignore
├── agconnect-services.json
├── build.gradle
├── google-services.json
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── idroid
│ │ └── android
│ │ └── mapkit
│ │ └── ExampleInstrumentedTest.kt
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── idroid
│ │ │ └── android
│ │ │ └── mapkit
│ │ │ ├── Application.kt
│ │ │ └── MainActivity.kt
│ └── res
│ │ ├── drawable-v24
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable
│ │ └── ic_launcher_background.xml
│ │ ├── layout
│ │ └── activity_main.xml
│ │ ├── mipmap-anydpi-v26
│ │ ├── ic_launcher.xml
│ │ └── ic_launcher_round.xml
│ │ ├── mipmap-hdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ └── values
│ │ ├── colors.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── idroid
│ └── android
│ └── mapkit
│ └── ExampleUnitTest.kt
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── mapskit
├── .gitignore
├── build.gradle
├── consumer-rules.pro
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── idroid
│ │ └── android
│ │ └── mapskit
│ │ └── ExampleInstrumentedTest.kt
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── idroid
│ │ │ └── android
│ │ │ └── mapskit
│ │ │ ├── factory
│ │ │ ├── BaseMaps.kt
│ │ │ ├── GoogleMapsImpl.kt
│ │ │ ├── HuaweiMapsImpl.kt
│ │ │ ├── MapFactory.kt
│ │ │ ├── Maps.kt
│ │ │ ├── MapsLifeCycle.kt
│ │ │ └── UISettings.kt
│ │ │ ├── listener
│ │ │ ├── OnMapMarkerClickListener.kt
│ │ │ └── OnMapReadyListener.kt
│ │ │ ├── model
│ │ │ ├── CommonCap.kt
│ │ │ ├── CommonCircle.kt
│ │ │ ├── CommonJointType.kt
│ │ │ ├── CommonMarker.kt
│ │ │ ├── CommonMarkerOptions.kt
│ │ │ ├── CommonPolygon.kt
│ │ │ ├── CommonPolygonOptions.kt
│ │ │ ├── CommonPolyline.kt
│ │ │ ├── CommonPolylineOptions.kt
│ │ │ ├── CommonProjection.kt
│ │ │ ├── CommonProjectionImpl.kt
│ │ │ └── CommonVisibleRegion.kt
│ │ │ ├── ui
│ │ │ ├── HuaweiGoogleMapView.kt
│ │ │ └── HuaweiGoogleSupportMapFragment.kt
│ │ │ └── utils
│ │ │ ├── CheckServiceAvaiable.kt
│ │ │ ├── DistributeType.kt
│ │ │ ├── MapExtensions.kt
│ │ │ └── MapType.kt
│ └── res
│ │ ├── layout
│ │ ├── huawei_google_map_view.xml
│ │ └── huawei_google_support_map_fragment.xml
│ │ └── values
│ │ └── strings.xml
│ └── test
│ └── java
│ └── idroid
│ └── android
│ └── mapskit
│ └── ExampleUnitTest.kt
└── settings.gradle
/.github/workflows/docs.yml:
--------------------------------------------------------------------------------
1 | name: Docs Generator
2 |
3 | on:
4 | push:
5 | branches:
6 | - master
7 |
8 | jobs:
9 | generate-docs:
10 | runs-on: ubuntu-latest
11 | steps:
12 | - name: Checkout code 🛎️
13 | uses: actions/checkout@v2
14 | with:
15 | submodules: false
16 | fetch-depth: 0
17 | - uses: actions/cache@v2
18 | with:
19 | path: |
20 | ~/.gradle/caches
21 | ~/.gradle/wrapper
22 | key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
23 | restore-keys: |
24 | ${{ runner.os }}-gradle-
25 | - name: Run dokka 📝
26 | id: test
27 | run: bash ./gradlew :mapskit:dokkaHtml
28 | - name: Add redirect 🔁
29 | id: redirection
30 | run: |
31 | touch index.html
32 | echo '
Redirecting...
' > index.html
33 | - name: Deploy 🚀
34 | uses: JamesIves/github-pages-deploy-action@4.1.0
35 | with:
36 | BRANCH: gh-pages
37 | FOLDER: mapskit/build/dokka/
38 |
--------------------------------------------------------------------------------
/.github/workflows/sdk-test.yml:
--------------------------------------------------------------------------------
1 | name: SDK Test
2 |
3 | on: [ push, pull_request ]
4 |
5 | jobs:
6 | update_release_draft:
7 | runs-on: ubuntu-latest
8 | steps:
9 | - name: Checkout code
10 | uses: actions/checkout@v2
11 | - uses: actions/cache@v2
12 | with:
13 | path: |
14 | ~/.gradle/caches
15 | ~/.gradle/wrapper
16 | key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
17 | restore-keys: |
18 | ${{ runner.os }}-gradle-
19 | - name: Run tests
20 | id: test
21 | run: bash ./gradlew mapskit:test
22 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.aar
4 | *.ap_
5 | *.aab
6 |
7 | # Files for the ART/Dalvik VM
8 | *.dex
9 |
10 | # Java class files
11 | *.class
12 |
13 | # Generated files
14 | bin/
15 | gen/
16 | out/
17 | # Uncomment the following line in case you need and you don't have the release build type files in your app
18 | # release/
19 |
20 | # Gradle files
21 | .gradle/
22 | build/
23 |
24 | # Local configuration file (sdk path, etc)
25 | local.properties
26 |
27 | # Proguard folder generated by Eclipse
28 | proguard/
29 |
30 | # Log Files
31 | *.log
32 |
33 | # Android Studio Navigation editor temp files
34 | .navigation/
35 |
36 | # Android Studio captures folder
37 | captures/
38 |
39 | # IntelliJ
40 | *.iml
41 | .idea
42 |
43 | # Keystore files
44 | # Uncomment the following lines if you do not want to check your keystore files in.
45 | #*.jks
46 | #*.keystore
47 |
48 | # External native build folder generated in Android Studio 2.2 and later
49 | .externalNativeBuild
50 | .cxx/
51 |
52 | # Google Services (e.g. APIs or Firebase)
53 | # google-services.json
54 |
55 | # Freeline
56 | freeline.py
57 | freeline/
58 | freeline_project_description.json
59 |
60 | # fastlane
61 | fastlane/report.xml
62 | fastlane/Preview.html
63 | fastlane/screenshots
64 | fastlane/test_output
65 | fastlane/readme.md
66 |
67 | # Version control
68 | vcs.xml
69 |
70 | # lint
71 | lint/intermediates/
72 | lint/generated/
73 | lint/outputs/
74 | lint/tmp/
75 | # lint/reports/
76 | /.idea/
77 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # MapKit SDK
2 |
3 | This SDK includes Google Map and Huawei Map enhancements.Recently, with the release of Huawei App Gallery, many
4 | applications are performing map integration.
5 |
6 | ## Releases
7 |
8 | [](https://jitpack.io/#iDroidDev/MapKit)
9 | [](https://github.com/iDroidDev/MapKit/actions/workflows/sdk-test.yml)
10 |
11 | ### ArnyminerZ ([Github](https://github.com/ArnyminerZ/MapKit))
12 |
13 | [](https://jitpack.io/#ArnyminerZ/MapKit)
14 | [](https://github.com/ArnyminerZ/MapKit/actions/workflows/sdk-test.yml)
15 |
16 | ### Our main goal now aims to solve your map related problems. You will have completed both integrations using only our libraries.
17 |
18 | ## Installing
19 |
20 | Add the code block to your project build.gradle file: (Ex: build.gradle(Project:XXX)
21 |
22 | ```groovy
23 | maven { url 'https://developer.huawei.com/repo/' }
24 | ```
25 |
26 | Add the dependency to your project build.gradle file: (Ex: build.gradle(Project:XXX)
27 |
28 | ```groovy
29 | classpath 'com.huawei.agconnect:agcp:1.2.0.300'
30 | classpath 'com.google.gms:google-services:4.3.8'
31 | ```
32 |
33 | Add the allprojects to your project build.gradle file: (Ex: build.gradle(Project:XXX)
34 |
35 | ```groovy
36 | maven { url 'https://developer.huawei.com/repo/' }
37 | ```
38 |
39 | Sample Build Gradle Preview
40 |
41 | ```groovy
42 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
43 | buildscript {
44 | ext.kotlin_version = '1.4.32'
45 | repositories {
46 | google()
47 | jcenter()
48 | maven { url 'https://developer.huawei.com/repo/' }
49 |
50 | }
51 | dependencies {
52 | classpath 'com.android.tools.build:gradle:4.0.0'
53 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
54 | classpath 'com.huawei.agconnect:agcp:1.2.0.300'
55 | classpath 'com.google.gms:google-services:4.3.8'
56 | // NOTE: Do not place your application dependencies here; they belong
57 | // in the individual module build.gradle files
58 | }
59 | }
60 |
61 | allprojects {
62 | repositories {
63 | google()
64 | jcenter()
65 | maven { url 'https://jitpack.io' }
66 | maven { url 'https://developer.huawei.com/repo/' }
67 | }
68 | }
69 |
70 | task clean(type: Delete) {
71 | delete rootProject.buildDir
72 | }
73 | ```
74 |
75 | ### Add this plugin into your project build.gradle file: (Ex: build.gradle(app:XXX)
76 |
77 | ```groovy
78 | apply plugin: 'com.huawei.agconnect'
79 |
80 | apply plugin: 'com.google.gms.google-services'
81 | ```
82 |
83 | ### Add the dependency to your project build.gradle file:
84 |
85 | ```groovy
86 | implementation 'com.github.iDroidDev:MapKit:1.0.1'
87 | ```
88 |
89 | ## Usage
90 | ### Add Custom MapKit into XML file
91 |
92 | ```xml
93 |
94 |
98 | ```
99 |
100 | ### Configure map in your class
101 |
102 | ```kotlin
103 | mapView.onCreate(mapViewBundle)
104 | mapView.getMapAsync {
105 | it.addMarker("Marker", "Snippet", 41.000000F, 29.00000F)
106 | it.moveCamera(41.000000F, 29.00000F, 20f)
107 | }
108 | ```
109 |
110 | ### Don't Forget this code block
111 |
112 | ```kotlin
113 | override fun onStart() {
114 | super.onStart()
115 | mapView.onStart()
116 | }
117 |
118 | override fun onDestroy() {
119 | super.onDestroy()
120 | mapView.onDestroy()
121 | }
122 |
123 | override fun onPause() {
124 | super.onPause()
125 | mapView.onPause()
126 | }
127 |
128 | override fun onLowMemory() {
129 | super.onLowMemory()
130 | mapView.onLowMemory()
131 | }
132 |
133 | override fun onStop() {
134 | super.onStop()
135 | mapView.onStop()
136 | }
137 | ```
138 |
139 | **Our LocationKit SDK link:** www.github.com/iDroidDev/LocationKit
140 |
141 | # Documentation
142 |
143 | [](https://arnyminerz.github.io/MapKit/html/)
144 |
145 | # Authors
146 |
147 | * **Kaan KÜN** - *Mobile Application Developer*
148 | * **Mahmut YETİŞİR** - *Mobile Application Developer*
149 |
150 | ## Contributors
151 |
152 | * **Arnau Mora** (*~ArnyminerZ*) - [Github](https://github.com/ArnyminerZ)
153 |
154 | ## Don't worry
155 |
156 | You can always contact us.
157 |
158 | * **Kaan KÜN** Email : kaanforum4@gmail.com
159 | * **Mahmut YETİŞİR** Email : mahmutyetisir03@gmail.com
160 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/agconnect-services.json:
--------------------------------------------------------------------------------
1 | {
2 | "client": "Your services.json"
3 | }
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | apply plugin: 'kotlin-android'
4 |
5 | apply plugin: 'kotlin-android-extensions'
6 |
7 | apply plugin: 'com.huawei.agconnect'
8 |
9 | apply plugin: 'com.google.gms.google-services'
10 |
11 | android {
12 | compileSdkVersion 29
13 | buildToolsVersion "29.0.2"
14 | defaultConfig {
15 | applicationId "idroid.android.mapkit"
16 | minSdkVersion 21
17 | targetSdkVersion 29
18 | versionCode 1
19 | versionName "1.0"
20 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
21 | }
22 | buildTypes {
23 | release {
24 | minifyEnabled false
25 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
26 | }
27 | }
28 | }
29 |
30 | dependencies {
31 | implementation fileTree(dir: 'libs', include: ['*.jar'])
32 | implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
33 | implementation 'androidx.appcompat:appcompat:1.1.0'
34 | implementation 'androidx.core:core-ktx:1.2.0'
35 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
36 | testImplementation 'junit:junit:4.12'
37 | androidTestImplementation 'androidx.test.ext:junit:1.1.1'
38 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
39 |
40 | implementation project(path: ':mapskit')
41 | }
42 |
--------------------------------------------------------------------------------
/app/google-services.json:
--------------------------------------------------------------------------------
1 | {
2 | "project_info": "Your services.json"
3 | }
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/idroid/android/mapkit/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package idroid.android.mapkit
2 |
3 | import androidx.test.platform.app.InstrumentationRegistry
4 | import androidx.test.ext.junit.runners.AndroidJUnit4
5 |
6 | import org.junit.Test
7 | import org.junit.runner.RunWith
8 |
9 | import org.junit.Assert.*
10 |
11 | /**
12 | * Instrumented test, which will execute on an Android device.
13 | *
14 | * See [testing documentation](http://d.android.com/tools/testing).
15 | */
16 | @RunWith(AndroidJUnit4::class)
17 | class ExampleInstrumentedTest {
18 | @Test
19 | fun useAppContext() {
20 | // Context of the app under test.
21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22 | assertEquals("idroid.android.mapkit", appContext.packageName)
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
24 |
25 |
28 |
29 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/app/src/main/java/idroid/android/mapkit/Application.kt:
--------------------------------------------------------------------------------
1 | package idroid.android.mapkit
2 |
3 |
4 | import android.app.Application
5 |
6 | class Application : Application() {
7 | override fun onCreate() {
8 | super.onCreate()
9 | }
10 |
11 |
12 | }
--------------------------------------------------------------------------------
/app/src/main/java/idroid/android/mapkit/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package idroid.android.mapkit
2 |
3 | import android.os.Bundle
4 | import androidx.appcompat.app.AppCompatActivity
5 | import kotlinx.android.synthetic.main.activity_main.*
6 |
7 |
8 | class MainActivity : AppCompatActivity() {
9 |
10 | override fun onCreate(savedInstanceState: Bundle?) {
11 | super.onCreate(savedInstanceState)
12 | setContentView(R.layout.activity_main)
13 | var mapViewBundle = savedInstanceState?.getBundle("MapViewBundleKey")
14 | if (mapViewBundle == null) {
15 | mapViewBundle = Bundle()
16 | savedInstanceState?.putBundle("MapViewBundleKey", mapViewBundle)
17 | }
18 |
19 | mapView.onCreate(mapViewBundle)
20 | mapView.getMapAsync { map ->
21 | map.addMarker("Marker", "Snippet", 41.000000, 29.00000)
22 | map.moveCamera(41.000000, 29.00000, 12f)
23 | }
24 | }
25 |
26 | override fun onStart() {
27 | super.onStart()
28 | mapView.onStart()
29 | }
30 |
31 | override fun onDestroy() {
32 | super.onDestroy()
33 | mapView.onDestroy()
34 | }
35 |
36 | override fun onPause() {
37 | super.onPause()
38 | mapView.onPause()
39 | }
40 |
41 | override fun onLowMemory() {
42 | super.onLowMemory()
43 | mapView.onLowMemory()
44 | }
45 |
46 | override fun onStop() {
47 | super.onStop()
48 | mapView.onStop()
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iDroidDev/MapKit/20b19a19755493fc31cd35329f7e89900353d6fb/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iDroidDev/MapKit/20b19a19755493fc31cd35329f7e89900353d6fb/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iDroidDev/MapKit/20b19a19755493fc31cd35329f7e89900353d6fb/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iDroidDev/MapKit/20b19a19755493fc31cd35329f7e89900353d6fb/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iDroidDev/MapKit/20b19a19755493fc31cd35329f7e89900353d6fb/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iDroidDev/MapKit/20b19a19755493fc31cd35329f7e89900353d6fb/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iDroidDev/MapKit/20b19a19755493fc31cd35329f7e89900353d6fb/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iDroidDev/MapKit/20b19a19755493fc31cd35329f7e89900353d6fb/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iDroidDev/MapKit/20b19a19755493fc31cd35329f7e89900353d6fb/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iDroidDev/MapKit/20b19a19755493fc31cd35329f7e89900353d6fb/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #008577
4 | #00574B
5 | #D81B60
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | MapKit
3 | MapViewActivity
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/app/src/test/java/idroid/android/mapkit/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package idroid.android.mapkit
2 |
3 | import org.junit.Test
4 |
5 | import org.junit.Assert.*
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * See [testing documentation](http://d.android.com/tools/testing).
11 | */
12 | class ExampleUnitTest {
13 | @Test
14 | fun addition_isCorrect() {
15 | assertEquals(4, 2 + 2)
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | ext.kotlin_version = '1.5.10'
5 | repositories {
6 | google()
7 | jcenter()
8 | maven { url 'https://developer.huawei.com/repo/' }
9 | }
10 | dependencies {
11 | classpath 'com.android.tools.build:gradle:4.0.2'
12 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
13 | classpath 'com.huawei.agconnect:agcp:1.2.0.300'
14 | classpath 'com.google.gms:google-services:4.3.8'
15 | classpath 'org.jetbrains.dokka:dokka-gradle-plugin:1.4.32'
16 | // NOTE: Do not place your application dependencies here; they belong
17 | // in the individual module build.gradle files
18 | }
19 | }
20 |
21 | allprojects {
22 | repositories {
23 | google()
24 | jcenter()
25 | maven { url 'https://developer.huawei.com/repo/' }
26 | }
27 | }
28 |
29 | task clean(type: Delete) {
30 | delete rootProject.buildDir
31 | }
32 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app's APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Automatically convert third-party libraries to use AndroidX
19 | android.enableJetifier=true
20 | # Kotlin code style for this project: "official" or "obsolete":
21 | kotlin.code.style=official
22 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iDroidDev/MapKit/20b19a19755493fc31cd35329f7e89900353d6fb/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sat Jun 05 14:15:53 CEST 2021
2 | distributionBase=GRADLE_USER_HOME
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
4 | distributionPath=wrapper/dists
5 | zipStorePath=wrapper/dists
6 | zipStoreBase=GRADLE_USER_HOME
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/mapskit/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/mapskit/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'kotlin-android'
3 | apply plugin: 'kotlin-android-extensions'
4 | apply plugin: 'org.jetbrains.dokka'
5 |
6 | android {
7 | compileSdkVersion 30
8 | buildToolsVersion "30.0.3"
9 |
10 | defaultConfig {
11 | minSdkVersion 21
12 | targetSdkVersion 30
13 | versionCode 1
14 | versionName "1.0"
15 |
16 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
17 | consumerProguardFiles 'consumer-rules.pro'
18 | }
19 |
20 | buildTypes {
21 | release {
22 | minifyEnabled false
23 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
24 | }
25 | }
26 | }
27 |
28 | tasks.named("dokkaHtml") {
29 | dokkaSourceSets {
30 | configureEach {
31 | noAndroidSdkLink.set(false)
32 | }
33 | }
34 | }
35 |
36 | dependencies {
37 | implementation fileTree(dir: 'libs', include: ['*.jar'])
38 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
39 | implementation 'androidx.appcompat:appcompat:1.3.0'
40 | implementation 'androidx.core:core-ktx:1.5.0'
41 | testImplementation 'junit:junit:4.13.2'
42 | androidTestImplementation 'androidx.test.ext:junit:1.1.2'
43 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
44 |
45 | //Huawei Services
46 | implementation 'com.huawei.hms:maps:4.0.1.302'
47 |
48 | //Google Services
49 | implementation 'com.google.android.gms:play-services-maps:17.0.1'
50 | }
51 |
--------------------------------------------------------------------------------
/mapskit/consumer-rules.pro:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iDroidDev/MapKit/20b19a19755493fc31cd35329f7e89900353d6fb/mapskit/consumer-rules.pro
--------------------------------------------------------------------------------
/mapskit/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/mapskit/src/androidTest/java/idroid/android/mapskit/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package idroid.android.mapskit
2 |
3 | import androidx.test.platform.app.InstrumentationRegistry
4 | import androidx.test.ext.junit.runners.AndroidJUnit4
5 |
6 | import org.junit.Test
7 | import org.junit.runner.RunWith
8 |
9 | import org.junit.Assert.*
10 |
11 | /**
12 | * Instrumented test, which will execute on an Android device.
13 | *
14 | * See [testing documentation](http://d.android.com/tools/testing).
15 | */
16 | @RunWith(AndroidJUnit4::class)
17 | class ExampleInstrumentedTest {
18 | @Test
19 | fun useAppContext() {
20 | // Context of the app under test.
21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22 | assertEquals("idroid.android.mapskit.test", appContext.packageName)
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/mapskit/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/mapskit/src/main/java/idroid/android/mapskit/factory/BaseMaps.kt:
--------------------------------------------------------------------------------
1 | package idroid.android.mapskit.factory
2 |
3 | import android.content.Context
4 | import android.content.ContextWrapper
5 | import androidx.fragment.app.Fragment
6 | import androidx.fragment.app.FragmentActivity
7 | import idroid.android.mapskit.utils.MapType
8 |
9 | abstract class BaseMaps(private val context: Context, val mapType: MapType) : Maps,
10 | UISettings, MapsLifeCycle {
11 |
12 | private fun getActivity(): FragmentActivity? {
13 | var context: Context? = this.context
14 | while (context is ContextWrapper) {
15 | if (context is FragmentActivity) {
16 | return context
17 | }
18 | context = context.baseContext
19 | }
20 | return null
21 | }
22 |
23 | fun replaceFragment(fragment: Fragment?) {
24 | getActivity()?.let { fragmentActivity ->
25 | fragment?.let {
26 | fragmentActivity.supportFragmentManager.beginTransaction()
27 | .add(idroid.android.mapskit.R.id.flRootHuaweiGoogleSupportMapFragment, it)
28 | .commit()
29 | }
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/mapskit/src/main/java/idroid/android/mapskit/factory/GoogleMapsImpl.kt:
--------------------------------------------------------------------------------
1 | package idroid.android.mapskit.factory
2 |
3 | import android.annotation.SuppressLint
4 | import android.content.Context
5 | import android.graphics.Bitmap
6 | import android.location.Location
7 | import android.os.Bundle
8 | import android.view.View
9 | import com.google.android.gms.maps.*
10 | import com.google.android.gms.maps.model.*
11 | import idroid.android.mapskit.model.*
12 | import idroid.android.mapskit.utils.*
13 |
14 |
15 | class GoogleMapsImpl(context: Context, mapType: MapType = MapType.MAP_VIEW) : BaseMaps(
16 | context,
17 | mapType
18 | ), OnMapReadyCallback {
19 |
20 | private var mapView: MapView? = null
21 | private var mapFragment: SupportMapFragment? = null
22 | private lateinit var map: GoogleMap
23 | private lateinit var onMapReadyListener: ((map: Maps) -> Unit)
24 |
25 | init {
26 | if (mapType == MapType.MAP_FRAGMENT) {
27 | mapFragment = SupportMapFragment.newInstance()
28 | replaceFragment(mapFragment)
29 | } else if (mapType == MapType.MAP_VIEW) {
30 | mapView = MapView(context)
31 | }
32 | }
33 |
34 | override fun getMapView(): View? = mapView
35 |
36 | override fun onCreate(bundle: Bundle?) {
37 | mapView?.onCreate(bundle)
38 | mapFragment?.onCreate(bundle)
39 | }
40 |
41 | override fun getMapAsync(onMapReadyListener: (map: Maps) -> Unit) {
42 | this.onMapReadyListener = onMapReadyListener
43 | if (mapType == MapType.MAP_VIEW) mapView?.getMapAsync(this)
44 | else if (mapType == MapType.MAP_FRAGMENT) mapFragment?.getMapAsync(this)
45 | }
46 |
47 | override fun onMapReady(googleMap: GoogleMap) {
48 | map = googleMap
49 | if (this::onMapReadyListener.isInitialized)
50 | onMapReadyListener(this)
51 | }
52 |
53 | override fun addMarker(
54 | title: String,
55 | snippet: String,
56 | latitude: Double?,
57 | longitude: Double?
58 | ): CommonMarker {
59 | val nyGoogle = latitude?.let { lat ->
60 | longitude?.let { long ->
61 | LatLng(lat, long)
62 | }
63 | }
64 | val markerOptionsGoogle = nyGoogle?.let { MarkerOptions().position(it) }
65 | if (title.isNotEmpty()) markerOptionsGoogle?.title(title)
66 | if (snippet.isNotEmpty()) markerOptionsGoogle?.snippet(snippet)
67 | return map.addMarker(markerOptionsGoogle).toHesMarker()
68 | }
69 |
70 | override fun addMarker(icon: Bitmap, latLng: LatLng, title: String): CommonMarker {
71 | return map.addMarker(
72 | MarkerOptions()
73 | .icon(BitmapDescriptorFactory.fromBitmap(icon))
74 | .position(latLng)
75 | .title(title)
76 | ).toHesMarker()
77 | }
78 |
79 | override fun addMarker(icon: Bitmap, latLng: LatLng, zIndex: Float): CommonMarker {
80 | return map.addMarker(
81 | MarkerOptions()
82 | .icon(BitmapDescriptorFactory.fromBitmap(icon))
83 | .position(latLng)
84 | .zIndex(zIndex)
85 | ).toHesMarker()
86 | }
87 |
88 | override fun addMarker(icon: Bitmap, latLng: LatLng): CommonMarker {
89 | return map.addMarker(
90 | MarkerOptions()
91 | .icon(BitmapDescriptorFactory.fromBitmap(icon))
92 | .position(latLng)
93 | ).toHesMarker()
94 | }
95 |
96 | override fun addMarker(commonMarkerOptions: CommonMarkerOptions): CommonMarker {
97 | return map.addMarker(
98 | MarkerOptions()
99 | .icon(BitmapDescriptorFactory.fromBitmap(commonMarkerOptions.icon))
100 | .position(commonMarkerOptions.latLng)
101 | .title(commonMarkerOptions.title)
102 | ).toHesMarker()
103 | }
104 |
105 | override fun moveCamera(latitude: Double, longitude: Double, zoomRatio: Float) {
106 | val nyGoogle = LatLng(latitude, longitude)
107 | map.moveCamera(
108 | CameraUpdateFactory.newCameraPosition(
109 | CameraPosition(
110 | nyGoogle,
111 | zoomRatio,
112 | 0f,
113 | 0f
114 | )
115 | )
116 | )
117 | }
118 |
119 | override fun moveCamera(latLng: LatLng, zoomRatio: Float, v1: Int, v2: Int) {
120 | map.moveCamera(
121 | CameraUpdateFactory.newCameraPosition(
122 | CameraPosition(
123 | latLng,
124 | zoomRatio,
125 | v1.toFloat(),
126 | v2.toFloat()
127 | )
128 | )
129 | )
130 | }
131 |
132 | override fun moveCamera(latLng: LatLng, zoomRatio: Double) {
133 | map.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, zoomRatio.toFloat()))
134 | }
135 |
136 | override fun moveCamera(latLng: LatLng, zoomRatio: Float) {
137 | map.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, zoomRatio))
138 | }
139 |
140 | override fun moveCamera(latLngBounds: LatLngBounds, padding: Int) {
141 | map.moveCamera(CameraUpdateFactory.newLatLngBounds(latLngBounds, padding))
142 | }
143 |
144 | override fun moveCamera(zoomRatio: Float) {
145 | map.moveCamera(CameraUpdateFactory.zoomTo(zoomRatio))
146 | }
147 |
148 | override fun animateCamera(latitude: Double, longitude: Double, zoomRatio: Float) {
149 | map.animateCamera(
150 | CameraUpdateFactory.newLatLngZoom(
151 | LatLng(
152 | latitude,
153 | longitude
154 | ), zoomRatio
155 | )
156 | )
157 | }
158 |
159 | override fun animateCamera(zoomRatio: Float) {
160 | map.animateCamera(CameraUpdateFactory.zoomTo(zoomRatio))
161 | }
162 |
163 | override fun animateCamera(latLng: LatLng, zoomRatio: Float) {
164 | val position = CameraPosition.Builder()
165 | .target(latLng)
166 | .zoom(zoomRatio).build()
167 | map.animateCamera(CameraUpdateFactory.newCameraPosition(position))
168 | }
169 |
170 | override fun animateCamera(latLngBounds: LatLngBounds, padding: Int) {
171 | map.animateCamera(CameraUpdateFactory.newLatLngBounds(latLngBounds, padding))
172 | }
173 |
174 | override fun animateCamera(latLng: LatLng, zoomRatio: Float, duration: Int) {
175 | map.animateCamera(
176 | CameraUpdateFactory.newLatLngZoom(latLng, zoomRatio),
177 | duration,
178 | object : GoogleMap.CancelableCallback {
179 | override fun onFinish() {}
180 | override fun onCancel() {}
181 | })
182 | }
183 |
184 | override fun animateCamera(location: Location, zoomRatio: Float, bearing: Float, tilt: Float) {
185 | val position = CameraPosition.Builder()
186 | .target(LatLng(location.latitude, location.longitude))
187 | .zoom(zoomRatio)
188 | .bearing(getCameraPosition().bearing)
189 | .tilt(getCameraPosition().tilt)
190 | .build()
191 | map.animateCamera(CameraUpdateFactory.newCameraPosition(position))
192 | }
193 |
194 | override fun setInfoWindowAdapter(infoWindowAdapter: (marker: CommonMarker) -> View) {
195 | map.setInfoWindowAdapter(object : GoogleMap.InfoWindowAdapter {
196 | override fun getInfoWindow(marker: Marker): View? {
197 | infoWindowAdapter(marker.toHesMarker())
198 | return null
199 | }
200 |
201 | override fun getInfoContents(marker: Marker): View? = null
202 | })
203 | }
204 |
205 | override fun addCircle(circleOptions: CircleOptions): CommonCircle =
206 | map.addCircle(circleOptions).toHesCircle()
207 |
208 | override fun addPolyline(options: CommonPolylineOptions): CommonPolyline {
209 | val polylineOptions = PolylineOptions()
210 | polylineOptions.addAll(options.getLatLngs())
211 | polylineOptions.width(options.getWidth())
212 | polylineOptions.color(options.getColor())
213 |
214 | options.getStartCap()?.googleCap()?.let {
215 | polylineOptions.startCap(it)
216 | }
217 | options.getEndCap()?.googleCap()?.let {
218 | polylineOptions.endCap(it)
219 | }
220 |
221 | options.getJointType()?.google()?.let {
222 | polylineOptions.jointType(it)
223 | }
224 |
225 | val polyline: Polyline = map.addPolyline(polylineOptions)
226 | return polyline.toHesPolyline()
227 | }
228 |
229 | override fun addPolygon(options: CommonPolygonOptions): CommonPolygon {
230 | val polygonOptions = PolygonOptions()
231 | polygonOptions.points.addAll(options.points)
232 | if (options.holes != null)
233 | polygonOptions.holes.addAll(options.holes)
234 |
235 | polygonOptions.fillColor(options.fillColor)
236 | polygonOptions.strokeColor(options.strokeColor)
237 |
238 | polygonOptions.strokeWidth(options.strokeWidth)
239 | options.strokeJointType?.let {
240 | polygonOptions.strokeJointType(it.hms())
241 | }
242 |
243 | polygonOptions.clickable(options.clickable)
244 | polygonOptions.geodesic(options.geodesic)
245 | polygonOptions.visible(options.visible)
246 |
247 | val polygon = map.addPolygon(polygonOptions)
248 | return polygon.toHesPolygon()
249 | }
250 |
251 | override fun addTileOverlay(tileOverlayOptions: Any) {
252 | map.addTileOverlay(tileOverlayOptions as TileOverlayOptions)
253 | }
254 |
255 | override fun setMaxZoomPreference(zoomRatio: Float) {
256 | map.setMaxZoomPreference(zoomRatio)
257 | }
258 |
259 | override fun setMinZoomPreference(zoomRatio: Float) {
260 | map.setMinZoomPreference(zoomRatio)
261 | }
262 |
263 | override fun zoomIn() {
264 | map.animateCamera(CameraUpdateFactory.zoomIn())
265 | }
266 |
267 | override fun zoomOut() {
268 | map.animateCamera(CameraUpdateFactory.zoomIn())
269 | }
270 |
271 | @SuppressLint("MissingPermission")
272 | override fun setMyLocationEnabled(myLocationEnabled: Boolean) {
273 | map.isMyLocationEnabled = myLocationEnabled
274 | }
275 |
276 | override fun setMapType(mapType: Maps.Type) {
277 | if (Maps.Type.SATALLITE === mapType) map.mapType =
278 | GoogleMap.MAP_TYPE_SATELLITE else map.mapType = GoogleMap.MAP_TYPE_NORMAL
279 | }
280 |
281 | override fun setBuildings(b: Boolean) {
282 | map.isBuildingsEnabled = b
283 | }
284 |
285 | override fun getCameraPosition(): CameraPosition {
286 | return map.cameraPosition
287 | }
288 |
289 | override fun getProjection(): CommonProjection {
290 | return HesProjectionImpl.getProjection(map.projection)!!
291 | }
292 |
293 | override fun setOnMarkerClickListener(onMapMarkerClickListener: (marker: CommonMarker) -> Boolean) {
294 | map.setOnMarkerClickListener { marker -> onMapMarkerClickListener(marker.toHesMarker()) }
295 | }
296 |
297 | override fun setOnInfoWindowClickListener(onInfoWindowClickListener: (marker: CommonMarker) -> Unit) {
298 | map.setOnInfoWindowClickListener { marker -> onInfoWindowClickListener(marker.toHesMarker()) }
299 | }
300 |
301 | override fun setOnMapLongClickListener(mapLongClickListener: (point: LatLng) -> Unit) {
302 | map.setOnMapLongClickListener { latLng -> mapLongClickListener(latLng) }
303 | }
304 |
305 | override fun setOnMapClickListener(mapClickListener: (point: LatLng) -> Unit) {
306 | map.setOnMapClickListener { latLng -> mapClickListener(latLng) }
307 | }
308 |
309 | override fun setOnMapLoadedCallback(mapLoadedListener: () -> Unit) {
310 | map.setOnMapLoadedCallback { mapLoadedListener() }
311 | }
312 |
313 | override fun setOnCameraIdleListener(cameraIdleListener: () -> Unit) {
314 | map.setOnCameraIdleListener { cameraIdleListener.invoke() }
315 | }
316 |
317 | override fun setOnCameraMoveListener(cameraMoveListener: (position: LatLng) -> Unit) {
318 | map.setOnCameraMoveListener { cameraMoveListener.invoke(getCameraPosition().target) }
319 | }
320 |
321 | override fun snapshot(snapshotReadyListener: (_bitmap: Bitmap?) -> Unit) {
322 | map.snapshot { bitmap -> snapshotReadyListener(bitmap) }
323 | }
324 |
325 | override fun clear() {
326 | map.clear()
327 | }
328 |
329 | override fun onSaveInstanceState(bundle: Bundle) {
330 | mapView?.onSaveInstanceState(bundle)
331 | mapFragment?.onSaveInstanceState(bundle)
332 | }
333 |
334 | override fun onStart() {
335 | mapView?.onStart()
336 | mapFragment?.onStart()
337 | }
338 |
339 | override fun onResume() {
340 | mapView?.onResume()
341 | mapFragment?.onResume()
342 | }
343 |
344 | override fun onPause() {
345 | mapView?.onPause()
346 | mapFragment?.onPause()
347 | }
348 |
349 | override fun onStop() {
350 | mapView?.onStop()
351 | mapFragment?.onStop()
352 | }
353 |
354 | override fun onDestroy() {
355 | mapView?.onDestroy()
356 | mapFragment?.onDestroy()
357 | }
358 |
359 | override fun onLowMemory() {
360 | mapView?.onLowMemory()
361 | mapFragment?.onLowMemory()
362 | }
363 |
364 |
365 | override fun isCompassEnabled(): Boolean {
366 | return map.uiSettings.isCompassEnabled
367 | }
368 |
369 | override fun setCompassEnabled(compassEnabled: Boolean?) {
370 | map.uiSettings.isCompassEnabled = compassEnabled!!
371 | }
372 |
373 | override fun isIndoorLevelPickerEnabled(): Boolean {
374 | return map.uiSettings.isIndoorLevelPickerEnabled
375 | }
376 |
377 | override fun setIndoorLevelPickerEnabled(indoorLevelPickerEnabled: Boolean?) {
378 | map.uiSettings.isIndoorLevelPickerEnabled = indoorLevelPickerEnabled!!
379 | }
380 |
381 | override fun isMapToolbarEnabled(): Boolean {
382 | return map.uiSettings.isMapToolbarEnabled
383 | }
384 |
385 | override fun setMapToolbarEnabled(mapToolbarEnabled: Boolean?) {
386 | map.uiSettings.isMapToolbarEnabled = mapToolbarEnabled!!
387 | }
388 |
389 | override fun isMyLocationButtonEnabled(): Boolean {
390 | return map.uiSettings.isMyLocationButtonEnabled
391 | }
392 |
393 | override fun setMyLocationButtonEnabled(myLocationButtonEnabled: Boolean?) {
394 | myLocationButtonEnabled?.let {
395 | map.uiSettings.isMyLocationButtonEnabled = it
396 | }
397 | }
398 |
399 | override fun isRotateGesturesEnabled(): Boolean {
400 | return map.uiSettings.isRotateGesturesEnabled
401 | }
402 |
403 | override fun setRotateGesturesEnabled(rotateGesturesEnabled: Boolean?) {
404 | map.uiSettings.isRotateGesturesEnabled = rotateGesturesEnabled!!
405 | }
406 |
407 | override fun isScrollGesturesEnabled(): Boolean {
408 | return map.uiSettings.isScrollGesturesEnabled
409 | }
410 |
411 | override fun setScrollGesturesEnabled(scrollGesturesEnabled: Boolean?) {
412 | map.uiSettings.isScrollGesturesEnabledDuringRotateOrZoom = scrollGesturesEnabled!!
413 | }
414 |
415 | override fun isScrollGesturesEnabledDuringRotateOrZoom(): Boolean {
416 | return map.uiSettings.isScrollGesturesEnabledDuringRotateOrZoom
417 | }
418 |
419 | override fun setScrollGesturesEnabledDuringRotateOrZoom(scrollGesturesEnabledDuringRotateOrZoom: Boolean?) {
420 | map.uiSettings.isScrollGesturesEnabledDuringRotateOrZoom =
421 | scrollGesturesEnabledDuringRotateOrZoom!!
422 | }
423 |
424 | override fun isTiltGesturesEnabled(): Boolean {
425 | return map.uiSettings.isTiltGesturesEnabled
426 | }
427 |
428 | override fun setTiltGesturesEnabled(tiltGesturesEnabled: Boolean?) {
429 | map.uiSettings.isTiltGesturesEnabled = tiltGesturesEnabled!!
430 | }
431 |
432 | override fun isZoomControlsEnabled(): Boolean {
433 | return map.uiSettings.isZoomControlsEnabled
434 | }
435 |
436 | override fun setZoomControlsEnabled(zoomControlsEnabled: Boolean?) {
437 | map.uiSettings.isZoomControlsEnabled = zoomControlsEnabled!!
438 | }
439 |
440 | override fun isZoomGesturesEnabled(): Boolean {
441 | return map.uiSettings.isZoomGesturesEnabled
442 | }
443 |
444 | override fun setZoomGesturesEnabled(zoomGesturesEnabled: Boolean?) {
445 | map.uiSettings.isZoomGesturesEnabled = true
446 | }
447 |
448 | override fun setAllGesturesEnabled(allGestureEnable: Boolean?) {
449 | map.uiSettings.setAllGesturesEnabled(allGestureEnable!!)
450 | }
451 |
452 | override fun onEnterAmbient(bundle: Bundle?) {
453 | mapView?.onEnterAmbient(bundle)
454 | mapFragment?.onEnterAmbient(bundle)
455 | }
456 |
457 | }
458 |
--------------------------------------------------------------------------------
/mapskit/src/main/java/idroid/android/mapskit/factory/HuaweiMapsImpl.kt:
--------------------------------------------------------------------------------
1 | package idroid.android.mapskit.factory
2 |
3 | import android.content.Context
4 | import android.graphics.Bitmap
5 | import android.location.Location
6 | import android.os.Bundle
7 | import android.view.View
8 | import com.google.android.gms.maps.model.CircleOptions
9 | import com.google.android.gms.maps.model.LatLngBounds
10 | import com.huawei.hms.maps.*
11 | import com.huawei.hms.maps.model.*
12 | import idroid.android.mapskit.model.*
13 | import idroid.android.mapskit.utils.*
14 |
15 | class HuaweiMapsImpl(
16 | context: Context,
17 | mapType: MapType = MapType.MAP_VIEW
18 | ) : BaseMaps(context, mapType), OnMapReadyCallback {
19 |
20 | private var mapView: MapView? = null
21 | private var mapFragment: SupportMapFragment? = null
22 | private lateinit var map: HuaweiMap
23 | private lateinit var onMapReadyListener: ((map: Maps) -> Unit)
24 |
25 | init {
26 | if (mapType == MapType.MAP_FRAGMENT) {
27 | mapFragment = SupportMapFragment.newInstance()
28 | replaceFragment(mapFragment)
29 | } else if (mapType == MapType.MAP_VIEW) {
30 | mapView = MapView(context)
31 | }
32 | }
33 |
34 | override fun getMapView(): View? = mapView
35 |
36 | override fun onCreate(bundle: Bundle?) {
37 | mapView?.onCreate(bundle)
38 | mapFragment?.onCreate(bundle)
39 | }
40 |
41 | override fun getMapAsync(onMapReadyListener: ((map: Maps) -> Unit)) {
42 | this.onMapReadyListener = onMapReadyListener
43 | if (mapType == MapType.MAP_VIEW) mapView?.getMapAsync(this)
44 | else if (mapType == MapType.MAP_FRAGMENT) mapFragment?.getMapAsync(this)
45 | }
46 |
47 | override fun onMapReady(huaweiMap: HuaweiMap) {
48 | map = huaweiMap
49 | if (this::onMapReadyListener.isInitialized)
50 | this.onMapReadyListener(this)
51 | }
52 |
53 | override fun addMarker(
54 | title: String,
55 | snippet: String,
56 | latitude: Double?,
57 | longitude: Double?
58 | ): CommonMarker {
59 | val nyHuawei = latitude?.let { lat ->
60 | longitude?.let { long ->
61 | LatLng(lat, long)
62 | }
63 | }
64 | val markerOptionsGoogle = MarkerOptions().position(nyHuawei)
65 | if (title.isNotEmpty()) markerOptionsGoogle.title(title)
66 | if (snippet.isNotEmpty()) markerOptionsGoogle.snippet(snippet)
67 | return map.addMarker(markerOptionsGoogle).toHesMarker()
68 | }
69 |
70 | override fun addMarker(
71 | icon: Bitmap,
72 | latLng: com.google.android.gms.maps.model.LatLng,
73 | title: String
74 | ): CommonMarker {
75 | return map.addMarker(
76 | MarkerOptions()
77 | .icon(BitmapDescriptorFactory.fromBitmap(icon))
78 | .position(latLng.toHuaweiLatLng())
79 | .title(title)
80 | ).toHesMarker()
81 | }
82 |
83 | override fun addMarker(
84 | icon: Bitmap,
85 | latLng: com.google.android.gms.maps.model.LatLng,
86 | zIndex: Float
87 | ): CommonMarker {
88 | return map.addMarker(
89 | MarkerOptions()
90 | .icon(BitmapDescriptorFactory.fromBitmap(icon))
91 | .position(latLng.toHuaweiLatLng())
92 | .zIndex(zIndex)
93 | ).toHesMarker()
94 | }
95 |
96 | override fun addMarker(
97 | icon: Bitmap,
98 | latLng: com.google.android.gms.maps.model.LatLng
99 | ): CommonMarker {
100 | return map.addMarker(
101 | MarkerOptions()
102 | .icon(BitmapDescriptorFactory.fromBitmap(icon))
103 | .position(latLng.toHuaweiLatLng())
104 | ).toHesMarker()
105 | }
106 |
107 | override fun addMarker(commonMarkerOptions: CommonMarkerOptions): CommonMarker {
108 | return map.addMarker(
109 | MarkerOptions()
110 | .icon(BitmapDescriptorFactory.fromBitmap(commonMarkerOptions.icon))
111 | .position(commonMarkerOptions.latLng.toHuaweiLatLng())
112 | .title(commonMarkerOptions.title)
113 | ).toHesMarker()
114 | }
115 |
116 | override fun moveCamera(latitude: Double, longitude: Double, zoomRatio: Float) {
117 | map.moveCamera(
118 | CameraUpdateFactory.newCameraPosition(
119 | CameraPosition(
120 | LatLng(latitude, longitude),
121 | zoomRatio,
122 | 0f,
123 | 0f
124 | )
125 | )
126 | )
127 | }
128 |
129 | override fun moveCamera(
130 | latLng: com.google.android.gms.maps.model.LatLng,
131 | zoomRatio: Float,
132 | v1: Int,
133 | v2: Int
134 | ) {
135 | map.moveCamera(
136 | CameraUpdateFactory.newCameraPosition(
137 | CameraPosition(
138 | latLng.toHuaweiLatLng(),
139 | zoomRatio,
140 | v1.toFloat(),
141 | v2.toFloat()
142 | )
143 | )
144 | )
145 | }
146 |
147 | override fun moveCamera(latLng: com.google.android.gms.maps.model.LatLng, zoomRatio: Double) {
148 | map.moveCamera(
149 | CameraUpdateFactory.newLatLngZoom(
150 | latLng.toHuaweiLatLng(),
151 | zoomRatio.toFloat()
152 | )
153 | )
154 | }
155 |
156 | override fun moveCamera(latLng: com.google.android.gms.maps.model.LatLng, zoomRatio: Float) {
157 | map.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng.toHuaweiLatLng(), zoomRatio))
158 | }
159 |
160 | override fun moveCamera(zoomRatio: Float) {
161 | map.moveCamera(CameraUpdateFactory.zoomTo(zoomRatio))
162 | }
163 |
164 | override fun moveCamera(latLngBounds: LatLngBounds, padding: Int) {
165 | map.moveCamera(
166 | CameraUpdateFactory.newLatLngBounds(
167 | latLngBounds.toHuaweiLatLngBounds(),
168 | padding
169 | )
170 | )
171 | }
172 |
173 | override fun animateCamera(latitude: Double, longitude: Double, zoomRatio: Float) {
174 | map.animateCamera(
175 | CameraUpdateFactory.newLatLngZoom(
176 | com.google.android.gms.maps.model.LatLng(
177 | latitude,
178 | longitude
179 | ).toHuaweiLatLng(), zoomRatio
180 | )
181 | )
182 | }
183 |
184 | override fun animateCamera(zoomRatio: Float) {
185 | map.animateCamera(CameraUpdateFactory.zoomTo(zoomRatio))
186 | }
187 |
188 | override fun animateCamera(latLng: com.google.android.gms.maps.model.LatLng, zoomRatio: Float) {
189 | val position = CameraPosition.Builder()
190 | .target(latLng.toHuaweiLatLng())
191 | .zoom(zoomRatio).build()
192 | map.animateCamera(CameraUpdateFactory.newCameraPosition(position))
193 | }
194 |
195 | override fun animateCamera(latLngBounds: LatLngBounds, padding: Int) {
196 | map.animateCamera(
197 | CameraUpdateFactory.newLatLngBounds(
198 | latLngBounds.toHuaweiLatLngBounds(),
199 | padding
200 | )
201 | )
202 | }
203 |
204 | override fun animateCamera(
205 | latLng: com.google.android.gms.maps.model.LatLng,
206 | zoomRatio: Float,
207 | duration: Int
208 | ) {
209 | map.animateCamera(
210 | CameraUpdateFactory.newLatLngZoom(latLng.toHuaweiLatLng(), zoomRatio),
211 | duration,
212 | object : HuaweiMap.CancelableCallback {
213 | override fun onFinish() {}
214 | override fun onCancel() {}
215 | })
216 | }
217 |
218 | override fun animateCamera(location: Location, zoomRatio: Float, bearing: Float, tilt: Float) {
219 | val position = CameraPosition.Builder()
220 | .target(LatLng(location.latitude, location.longitude))
221 | .zoom(zoomRatio)
222 | .bearing(getCameraPosition().bearing)
223 | .tilt(getCameraPosition().tilt)
224 | .build()
225 | map.animateCamera(CameraUpdateFactory.newCameraPosition(position))
226 | }
227 |
228 | override fun setInfoWindowAdapter(infoWindowAdapter: (marker: CommonMarker) -> View) {
229 | map.setInfoWindowAdapter(object : HuaweiMap.InfoWindowAdapter {
230 | override fun getInfoWindow(marker: Marker): View? {
231 | infoWindowAdapter(marker.toHesMarker())
232 | return null
233 | }
234 |
235 | override fun getInfoContents(marker: Marker): View? {
236 | return null
237 | }
238 | })
239 | }
240 |
241 | override fun addCircle(circleOptions: CircleOptions): CommonCircle {
242 | return map.addCircle(circleOptions.toHuaweiCircleOptions()).toHesCircle()
243 | }
244 |
245 | override fun addPolyline(options: CommonPolylineOptions): CommonPolyline {
246 | val polylineOptions = PolylineOptions()
247 | polylineOptions.addAll(options.getHuaweiLatLngs())
248 | polylineOptions.width(options.getWidth())
249 | polylineOptions.color(options.getColor())
250 |
251 | options.getStartCap()?.hmsCap()?.let {
252 | polylineOptions.startCap(it)
253 | }
254 | options.getEndCap()?.hmsCap()?.let {
255 | polylineOptions.endCap(it)
256 | }
257 |
258 | options.getJointType()?.hms()?.let {
259 | polylineOptions.jointType(it)
260 | }
261 |
262 | val polyline = map.addPolyline(polylineOptions)
263 | return polyline.toHesPolyline()!!
264 | }
265 |
266 | override fun addPolygon(options: CommonPolygonOptions): CommonPolygon {
267 | val polygonOptions = PolygonOptions()
268 | polygonOptions.points.addAll(options.hmsPoints())
269 | polygonOptions.holes.addAll(options.hmsHoles())
270 |
271 | polygonOptions.fillColor(options.fillColor)
272 | polygonOptions.strokeColor(options.strokeColor)
273 |
274 | polygonOptions.strokeWidth(options.strokeWidth)
275 | options.strokeJointType?.let {
276 | polygonOptions.strokeJointType(it.hms())
277 | }
278 |
279 | polygonOptions.clickable(options.clickable)
280 | polygonOptions.geodesic(options.geodesic)
281 | polygonOptions.visible(options.visible)
282 |
283 | val polygon = map.addPolygon(polygonOptions)
284 | return polygon.toHesPolygon()
285 | }
286 |
287 | override fun addTileOverlay(tileOverlayOptions: Any) {
288 | map.addTileOverlay(tileOverlayOptions as TileOverlayOptions)
289 | }
290 |
291 | override fun setMaxZoomPreference(zoomRatio: Float) {
292 | map.setMaxZoomPreference(zoomRatio)
293 | }
294 |
295 | override fun setMinZoomPreference(zoomRatio: Float) {
296 | map.setMinZoomPreference(zoomRatio)
297 | }
298 |
299 | override fun zoomIn() {
300 | map.animateCamera(CameraUpdateFactory.zoomIn())
301 | }
302 |
303 | override fun zoomOut() {
304 | map.animateCamera(CameraUpdateFactory.zoomOut())
305 | }
306 |
307 | override fun setMyLocationEnabled(myLocationEnabled: Boolean) {
308 | map.isMyLocationEnabled = myLocationEnabled
309 | map.uiSettings.isMyLocationButtonEnabled = false
310 | }
311 |
312 | override fun setMapType(mapType: Maps.Type) {
313 | if (Maps.Type.SATALLITE === mapType) map.mapType =
314 | HuaweiMap.MAP_TYPE_SATELLITE else map.mapType = HuaweiMap.MAP_TYPE_NORMAL
315 | }
316 |
317 | override fun setBuildings(b: Boolean) {
318 | map.isBuildingsEnabled = b
319 | }
320 |
321 | override fun getCameraPosition(): com.google.android.gms.maps.model.CameraPosition {
322 | val cameraPosition = map.cameraPosition
323 | return com.google.android.gms.maps.model.CameraPosition(
324 | cameraPosition.target.toGoogleLatLng(), cameraPosition.zoom, cameraPosition.tilt, cameraPosition.bearing
325 | )
326 | }
327 |
328 | override fun getProjection(): CommonProjection {
329 | return HesProjectionImpl.getProjection(map.projection)!!
330 | }
331 |
332 | override fun setOnMarkerClickListener(onMapMarkerClickListener: (marker: CommonMarker) -> Boolean) {
333 | map.setOnMarkerClickListener { marker -> onMapMarkerClickListener(marker.toHesMarker()) }
334 | }
335 |
336 | override fun setOnInfoWindowClickListener(onInfoWindowClickListener: (marker: CommonMarker) -> Unit) {
337 | map.setOnInfoWindowClickListener { marker ->
338 | onInfoWindowClickListener(marker.toHesMarker())
339 | }
340 | }
341 |
342 | override fun setOnMapLongClickListener(mapLongClickListener: (point: com.google.android.gms.maps.model.LatLng) -> Unit) {
343 | map.setOnMapLongClickListener { latLng ->
344 | mapLongClickListener(latLng.toGoogleLatLng())
345 | }
346 | }
347 |
348 | override fun setOnMapClickListener(mapClickListener: (point: com.google.android.gms.maps.model.LatLng) -> Unit) {
349 | map.setOnMapClickListener { latLng ->
350 | mapClickListener(latLng.toGoogleLatLng())
351 | }
352 | }
353 |
354 | override fun setOnMapLoadedCallback(mapLoadedListener: () -> Unit) {
355 | map.setOnMapLoadedCallback { mapLoadedListener() }
356 | }
357 |
358 | override fun setOnCameraIdleListener(cameraIdleListener: () -> Unit) {
359 | map.setOnCameraIdleListener { cameraIdleListener.invoke() }
360 | }
361 |
362 | override fun setOnCameraMoveListener(cameraMoveListener: (position: com.google.android.gms.maps.model.LatLng) -> Unit) {
363 | map.setOnCameraMoveListener {
364 | cameraMoveListener.invoke(
365 | map.cameraPosition.target.toGoogleLatLng()
366 | )
367 | }
368 | }
369 |
370 | override fun snapshot(snapshotReadyListener: (_bitmap: Bitmap?) -> Unit) {
371 | map.snapshot { bitmap -> snapshotReadyListener(bitmap) }
372 | }
373 |
374 | override fun clear() {
375 | map.clear()
376 | }
377 |
378 | override fun onSaveInstanceState(bundle: Bundle) {
379 | mapView?.onSaveInstanceState(bundle)
380 | mapFragment?.onSaveInstanceState(bundle)
381 | }
382 |
383 | override fun onStart() {
384 | mapView?.onStart()
385 | mapFragment?.onStart()
386 | }
387 |
388 | override fun onResume() {
389 | mapView?.onResume()
390 | mapFragment?.onResume()
391 | }
392 |
393 | override fun onPause() {
394 | mapView?.onPause()
395 | mapFragment?.onPause()
396 | }
397 |
398 | override fun onStop() {
399 | mapView?.onStop()
400 | mapFragment?.onStop()
401 | }
402 |
403 | override fun onDestroy() {
404 | mapView?.onDestroy()
405 | mapFragment?.onDestroy()
406 | }
407 |
408 | override fun onLowMemory() {
409 | mapView?.onLowMemory()
410 | mapFragment?.onLowMemory()
411 | }
412 |
413 | override fun isCompassEnabled(): Boolean {
414 | return map.uiSettings.isCompassEnabled
415 | }
416 |
417 | override fun setCompassEnabled(compassEnabled: Boolean?) {
418 | map.uiSettings.isCompassEnabled = compassEnabled!!
419 | }
420 |
421 | override fun isIndoorLevelPickerEnabled(): Boolean {
422 | return map.uiSettings.isIndoorLevelPickerEnabled
423 |
424 | }
425 |
426 | override fun setIndoorLevelPickerEnabled(indoorLevelPickerEnabled: Boolean?) {
427 | map.uiSettings.isIndoorLevelPickerEnabled = indoorLevelPickerEnabled!!
428 | }
429 |
430 | override fun isMapToolbarEnabled(): Boolean {
431 | return map.uiSettings.isMapToolbarEnabled
432 | }
433 |
434 | override fun setMapToolbarEnabled(mapToolbarEnabled: Boolean?) {
435 | map.uiSettings.isMapToolbarEnabled = mapToolbarEnabled!!
436 | }
437 |
438 | override fun isMyLocationButtonEnabled(): Boolean {
439 | return map.uiSettings.isMyLocationButtonEnabled
440 | }
441 |
442 | override fun setMyLocationButtonEnabled(myLocationButtonEnabled: Boolean?) {
443 | myLocationButtonEnabled?.let {
444 | map.uiSettings.isMyLocationButtonEnabled = it
445 | }
446 | }
447 |
448 | override fun isRotateGesturesEnabled(): Boolean {
449 | return map.uiSettings.isRotateGesturesEnabled
450 | }
451 |
452 | override fun setRotateGesturesEnabled(rotateGesturesEnabled: Boolean?) {
453 | map.uiSettings.isRotateGesturesEnabled = rotateGesturesEnabled!!
454 | }
455 |
456 | override fun isScrollGesturesEnabled(): Boolean {
457 | return map.uiSettings.isScrollGesturesEnabled
458 | }
459 |
460 | override fun setScrollGesturesEnabled(scrollGesturesEnabled: Boolean?) {
461 | map.uiSettings.isScrollGesturesEnabledDuringRotateOrZoom = scrollGesturesEnabled!!
462 | }
463 |
464 | override fun isScrollGesturesEnabledDuringRotateOrZoom(): Boolean {
465 | return map.uiSettings.isScrollGesturesEnabledDuringRotateOrZoom
466 | }
467 |
468 | override fun setScrollGesturesEnabledDuringRotateOrZoom(scrollGesturesEnabledDuringRotateOrZoom: Boolean?) {
469 | map.uiSettings.isScrollGesturesEnabledDuringRotateOrZoom =
470 | scrollGesturesEnabledDuringRotateOrZoom!!
471 | }
472 |
473 | override fun isTiltGesturesEnabled(): Boolean {
474 | return map.uiSettings.isTiltGesturesEnabled
475 | }
476 |
477 | override fun setTiltGesturesEnabled(tiltGesturesEnabled: Boolean?) {
478 | map.uiSettings.isTiltGesturesEnabled = tiltGesturesEnabled!!
479 | }
480 |
481 | override fun isZoomControlsEnabled(): Boolean {
482 | return map.uiSettings.isZoomControlsEnabled
483 | }
484 |
485 | override fun setZoomControlsEnabled(zoomControlsEnabled: Boolean?) {
486 | map.uiSettings.isZoomControlsEnabled = zoomControlsEnabled!!
487 | }
488 |
489 | override fun isZoomGesturesEnabled(): Boolean {
490 | return map.uiSettings.isZoomGesturesEnabled
491 | }
492 |
493 | override fun setZoomGesturesEnabled(zoomGesturesEnabled: Boolean?) {
494 | map.uiSettings.isZoomGesturesEnabled = true
495 | }
496 |
497 | override fun setAllGesturesEnabled(allGestureEnable: Boolean?) {
498 | map.uiSettings.setAllGesturesEnabled(allGestureEnable!!)
499 | }
500 |
501 | override fun onEnterAmbient(bundle: Bundle?) {
502 | mapView?.onEnterAmbient(bundle)
503 | mapFragment?.onEnterAmbient(bundle)
504 | }
505 | }
506 |
--------------------------------------------------------------------------------
/mapskit/src/main/java/idroid/android/mapskit/factory/MapFactory.kt:
--------------------------------------------------------------------------------
1 | package idroid.android.mapskit.factory
2 |
3 | import android.content.Context
4 | import idroid.android.mapskit.utils.DistributeType
5 | import idroid.android.mapskit.utils.MapType
6 |
7 | class MapFactory {
8 | companion object {
9 | fun createAndGetMap(context: Context, type: DistributeType, mapType: MapType): Maps {
10 | return if (DistributeType.HUAWEI_SERVICES == type) {
11 | HuaweiMapsImpl(context, mapType)
12 | } else {
13 | GoogleMapsImpl(context, mapType)
14 | }
15 | }
16 | }
17 | }
--------------------------------------------------------------------------------
/mapskit/src/main/java/idroid/android/mapskit/factory/Maps.kt:
--------------------------------------------------------------------------------
1 | package idroid.android.mapskit.factory
2 |
3 | import android.graphics.Bitmap
4 | import android.location.Location
5 | import android.os.Bundle
6 | import android.view.View
7 | import androidx.annotation.RequiresPermission
8 | import com.google.android.gms.maps.model.CameraPosition
9 | import com.google.android.gms.maps.model.CircleOptions
10 | import com.google.android.gms.maps.model.LatLng
11 | import com.google.android.gms.maps.model.LatLngBounds
12 | import idroid.android.mapskit.model.*
13 |
14 |
15 | interface Maps : UISettings {
16 | fun getMapView(): View?
17 | fun onCreate(bundle: Bundle?)
18 | fun getMapAsync(onMapReadyListener: (map: Maps) -> Unit)
19 |
20 | fun addMarker(title: String, snippet: String, latitude: Double?, longitude: Double?): CommonMarker
21 | fun addMarker(icon: Bitmap, latLng: LatLng, title: String): CommonMarker
22 | fun addMarker(icon: Bitmap, latLng: LatLng, zIndex: Float): CommonMarker
23 | fun addMarker(icon: Bitmap, latLng: LatLng): CommonMarker
24 | fun addMarker(commonMarkerOptions: CommonMarkerOptions): CommonMarker
25 |
26 | fun moveCamera(latitude: Double, longitude: Double, zoomRatio: Float)
27 | fun moveCamera(zoomRatio: Float)
28 | fun moveCamera(latLng: LatLng, zoomRatio: Double)
29 | fun moveCamera(latLngBounds: LatLngBounds, padding: Int)
30 | fun moveCamera(latLng: LatLng, zoomRatio: Float, v1: Int, v2: Int)
31 | fun moveCamera(latLng: LatLng, zoomRatio: Float)
32 |
33 | fun animateCamera(latitude: Double, longitude: Double, zoomRatio: Float)
34 | fun animateCamera(zoomRatio: Float)
35 | fun animateCamera(latLng: LatLng, zoomRatio: Float)
36 | fun animateCamera(latLngBounds: LatLngBounds, padding: Int)
37 | fun animateCamera(latLng: LatLng, zoomRatio: Float, duration: Int)
38 | fun animateCamera(location: Location, zoomRatio: Float, bearing: Float, tilt: Float)
39 |
40 | fun setInfoWindowAdapter(infoWindowAdapter: (marker: CommonMarker) -> View)
41 |
42 | fun addCircle(circleOptions: CircleOptions): CommonCircle
43 | fun addPolyline(options: CommonPolylineOptions): CommonPolyline
44 | fun addPolygon(options: CommonPolygonOptions): CommonPolygon
45 | fun addTileOverlay(tileOverlayOptions: Any)
46 |
47 | fun setMaxZoomPreference(zoomRatio: Float)
48 | fun setMinZoomPreference(zoomRatio: Float)
49 | fun zoomIn()
50 | fun zoomOut()
51 |
52 | @RequiresPermission(anyOf = ["android.permission.ACCESS_COARSE_LOCATION", "android.permission.ACCESS_FINE_LOCATION"])
53 | fun setMyLocationEnabled(myLocationEnabled: Boolean)
54 | fun setMapType(mapType: Type)
55 | fun setBuildings(b: Boolean)
56 | fun getCameraPosition(): CameraPosition
57 |
58 | fun getProjection(): CommonProjection
59 |
60 | fun setOnMarkerClickListener(onMapMarkerClickListener: (marker: CommonMarker) -> Boolean)
61 | fun setOnInfoWindowClickListener(onInfoWindowClickListener: (marker: CommonMarker) -> Unit)
62 | fun setOnMapLongClickListener(mapLongClickListener: (point: LatLng) -> Unit)
63 | fun setOnMapClickListener(mapClickListener: (point: LatLng) -> Unit)
64 | fun setOnMapLoadedCallback(mapLoadedListener: () -> Unit)
65 | fun setOnCameraIdleListener(cameraIdleListener: () -> Unit)
66 | fun setOnCameraMoveListener(cameraMoveListener: (position: LatLng) -> Unit)
67 |
68 | fun snapshot(snapshotReadyListener: (_bitmap: Bitmap?) -> Unit)
69 |
70 | fun clear()
71 |
72 | enum class Type {
73 | SATALLITE, NORMAL
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/mapskit/src/main/java/idroid/android/mapskit/factory/MapsLifeCycle.kt:
--------------------------------------------------------------------------------
1 | package idroid.android.mapskit.factory
2 |
3 | import android.os.Bundle
4 |
5 | interface MapsLifeCycle {
6 | fun onEnterAmbient(bundle: Bundle?)
7 | fun onSaveInstanceState(bundle: Bundle)
8 | fun onStart()
9 | fun onResume()
10 | fun onPause()
11 | fun onStop()
12 | fun onDestroy()
13 | fun onLowMemory()
14 | }
--------------------------------------------------------------------------------
/mapskit/src/main/java/idroid/android/mapskit/factory/UISettings.kt:
--------------------------------------------------------------------------------
1 | package idroid.android.mapskit.factory
2 |
3 | interface UISettings {
4 | fun isCompassEnabled(): Boolean
5 |
6 | fun setCompassEnabled(compassEnabled: Boolean?)
7 |
8 | fun isIndoorLevelPickerEnabled(): Boolean
9 |
10 | fun setIndoorLevelPickerEnabled(indoorLevelPickerEnabled: Boolean?)
11 |
12 | fun isMapToolbarEnabled(): Boolean
13 |
14 | fun setMapToolbarEnabled(mapToolbarEnabled: Boolean?)
15 |
16 | fun isMyLocationButtonEnabled(): Boolean
17 |
18 | fun setMyLocationButtonEnabled(myLocationButtonEnabled: Boolean?)
19 |
20 | fun isRotateGesturesEnabled(): Boolean
21 |
22 | fun setRotateGesturesEnabled(rotateGesturesEnabled: Boolean?)
23 |
24 | fun isScrollGesturesEnabled(): Boolean
25 |
26 | fun setScrollGesturesEnabled(scrollGesturesEnabled: Boolean?)
27 |
28 | fun isScrollGesturesEnabledDuringRotateOrZoom(): Boolean
29 |
30 | fun setScrollGesturesEnabledDuringRotateOrZoom(scrollGesturesEnabledDuringRotateOrZoom: Boolean?)
31 |
32 | fun isTiltGesturesEnabled(): Boolean
33 |
34 | fun setTiltGesturesEnabled(tiltGesturesEnabled: Boolean?)
35 |
36 | fun isZoomControlsEnabled(): Boolean
37 |
38 | fun setZoomControlsEnabled(zoomControlsEnabled: Boolean?)
39 |
40 | fun isZoomGesturesEnabled(): Boolean
41 |
42 | fun setZoomGesturesEnabled(zoomGesturesEnabled: Boolean?)
43 |
44 | fun setAllGesturesEnabled(allGestureEnable: Boolean?)
45 | }
--------------------------------------------------------------------------------
/mapskit/src/main/java/idroid/android/mapskit/listener/OnMapMarkerClickListener.kt:
--------------------------------------------------------------------------------
1 | package idroid.android.mapskit.listener
2 |
3 | interface OnMapMarkerClickListener {
4 | fun onMarkerClick(markerTitle: String, markerSnippet: String)
5 | }
--------------------------------------------------------------------------------
/mapskit/src/main/java/idroid/android/mapskit/listener/OnMapReadyListener.kt:
--------------------------------------------------------------------------------
1 | package idroid.android.mapskit.listener
2 |
3 | import com.google.android.gms.maps.GoogleMap
4 |
5 | interface OnMapReadyListener {
6 | fun onMapReady()
7 | }
--------------------------------------------------------------------------------
/mapskit/src/main/java/idroid/android/mapskit/model/CommonCap.kt:
--------------------------------------------------------------------------------
1 | package idroid.android.mapskit.model
2 |
3 | import com.google.android.gms.maps.model.ButtCap
4 | import com.google.android.gms.maps.model.Cap
5 | import com.google.android.gms.maps.model.RoundCap
6 | import com.google.android.gms.maps.model.SquareCap
7 |
8 | /**
9 | * Represents a polyline starting and ending line cap.
10 | * TODO: Custom Caps
11 | * @author Arnau Mora
12 | * @since 20210602
13 | */
14 | enum class CommonCap {
15 | BUTT, ROUND, SQUARE;
16 |
17 | /**
18 | * Returns the [CommonCap] with the Google class implementation.
19 | * @author Arnau Mora
20 | * @since 20210602
21 | */
22 | fun googleCap(): Cap? =
23 | when {
24 | this == BUTT -> ButtCap()
25 | this == ROUND -> RoundCap()
26 | this == SQUARE -> SquareCap()
27 | else -> null
28 | }
29 |
30 | /**
31 | * Returns the [CommonCap] with the Huawei class implementation.
32 | * @author Arnau Mora
33 | * @since 20210602
34 | */
35 | fun hmsCap(): com.huawei.hms.maps.model.Cap? =
36 | when {
37 | this == BUTT -> com.huawei.hms.maps.model.ButtCap()
38 | this == ROUND -> com.huawei.hms.maps.model.RoundCap()
39 | this == SQUARE -> com.huawei.hms.maps.model.SquareCap()
40 | else -> null
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/mapskit/src/main/java/idroid/android/mapskit/model/CommonCircle.kt:
--------------------------------------------------------------------------------
1 | package idroid.android.mapskit.model
2 |
3 | import com.huawei.hms.maps.model.Circle
4 | import idroid.android.mapskit.utils.DistributeType
5 |
6 | data class CommonCircle(val type: DistributeType, val circle: Any) {
7 |
8 | fun remove() {
9 | if (DistributeType.HUAWEI_SERVICES === type) (circle as Circle).remove() else (circle as com.google.android.gms.maps.model.Circle).remove()
10 | }
11 | }
--------------------------------------------------------------------------------
/mapskit/src/main/java/idroid/android/mapskit/model/CommonJointType.kt:
--------------------------------------------------------------------------------
1 | package idroid.android.mapskit.model
2 |
3 | import com.google.android.gms.maps.model.JointType
4 |
5 | /**
6 | * Specifies a common model for setting a polyline joint type.
7 | * @author Arnau Mora
8 | * @since 20210602
9 | */
10 | enum class CommonJointType {
11 | BEVEL, DEFAULT, ROUND;
12 |
13 | /**
14 | * Returns the joint type in the Google's format.
15 | * @author Arnau Mora
16 | * @since 20210602
17 | */
18 | fun google(): Int =
19 | when {
20 | this == BEVEL -> JointType.BEVEL
21 | this == ROUND -> JointType.ROUND
22 | else -> JointType.DEFAULT
23 | }
24 |
25 | /**
26 | * Returns the joint type in the Huawei's format.
27 | * @author Arnau Mora
28 | * @since 20210602
29 | */
30 | fun hms(): Int =
31 | when {
32 | this == BEVEL -> com.huawei.hms.maps.model.JointType.BEVEL
33 | this == ROUND -> com.huawei.hms.maps.model.JointType.ROUND
34 | else -> com.huawei.hms.maps.model.JointType.DEFAULT
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/mapskit/src/main/java/idroid/android/mapskit/model/CommonMarker.kt:
--------------------------------------------------------------------------------
1 | package idroid.android.mapskit.model
2 |
3 | import android.graphics.Bitmap
4 | import com.google.android.gms.maps.model.LatLng
5 | import com.huawei.hms.maps.model.BitmapDescriptorFactory
6 | import com.huawei.hms.maps.model.Marker
7 | import idroid.android.mapskit.utils.DistributeType
8 | import idroid.android.mapskit.utils.toHuaweiLatLng
9 |
10 | data class CommonMarker(
11 | var type: DistributeType,
12 | val marker: Any,
13 | val id: String?,
14 | val alpha: Float?,
15 | val rotation: Float?,
16 | val position: LatLng,
17 | val title: String?,
18 | val snippet: String?,
19 | var tag: Any?
20 | ) {
21 |
22 | fun setIcon(icon: Bitmap) {
23 | if (DistributeType.HUAWEI_SERVICES === type) (marker as Marker).setIcon(
24 | BitmapDescriptorFactory.fromBitmap(icon)
25 | ) else (marker as com.google.android.gms.maps.model.Marker).setIcon(
26 | com.google.android.gms.maps.model.BitmapDescriptorFactory.fromBitmap(
27 | icon
28 | )
29 | )
30 | }
31 |
32 | fun remove() {
33 | if (DistributeType.HUAWEI_SERVICES === type) (marker as Marker).remove() else (marker as com.google.android.gms.maps.model.Marker).remove()
34 | }
35 |
36 | fun setPosition(latLng: LatLng) {
37 | if (DistributeType.HUAWEI_SERVICES === type) (marker as Marker).position =
38 | latLng.toHuaweiLatLng() else (marker as com.google.android.gms.maps.model.Marker).position =
39 | latLng
40 | }
41 |
42 | fun setVisibilty(isVisible: Boolean) {
43 | if (DistributeType.HUAWEI_SERVICES === type) (marker as Marker).isVisible =
44 | isVisible else (marker as com.google.android.gms.maps.model.Marker).isVisible =
45 | isVisible
46 | }
47 |
48 | fun setMarkerTag(tag: Any) {
49 | this.tag = tag
50 | if (DistributeType.HUAWEI_SERVICES === type) (marker as Marker).tag =
51 | tag else (marker as com.google.android.gms.maps.model.Marker).tag = tag
52 | }
53 |
54 | fun showInfoWindow() {
55 | if (DistributeType.HUAWEI_SERVICES === type) (marker as Marker).showInfoWindow() else (marker as com.google.android.gms.maps.model.Marker).showInfoWindow()
56 | }
57 | }
--------------------------------------------------------------------------------
/mapskit/src/main/java/idroid/android/mapskit/model/CommonMarkerOptions.kt:
--------------------------------------------------------------------------------
1 | package idroid.android.mapskit.model
2 |
3 | import android.graphics.Bitmap
4 | import com.google.android.gms.maps.model.LatLng
5 |
6 | data class CommonMarkerOptions(val latLng: LatLng, val title: String, val icon: Bitmap)
--------------------------------------------------------------------------------
/mapskit/src/main/java/idroid/android/mapskit/model/CommonPolygon.kt:
--------------------------------------------------------------------------------
1 | package idroid.android.mapskit.model
2 |
3 | import com.huawei.hms.maps.model.Polygon
4 | import idroid.android.mapskit.utils.DistributeType
5 |
6 | data class CommonPolygon(
7 | var polygon: Any? = null,
8 | val type: DistributeType
9 | ) {
10 |
11 | constructor(
12 | type: DistributeType,
13 | polygon: Any
14 | ) : this(polygon, type)
15 |
16 | fun remove() {
17 | if (DistributeType.HUAWEI_SERVICES === type) (polygon as Polygon).remove() else (polygon as com.google.android.gms.maps.model.Polygon).remove()
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/mapskit/src/main/java/idroid/android/mapskit/model/CommonPolygonOptions.kt:
--------------------------------------------------------------------------------
1 | package idroid.android.mapskit.model
2 |
3 | import com.google.android.gms.maps.model.LatLng
4 | import java.util.*
5 |
6 | class CommonPolygonOptions(
7 | val points: Collection,
8 | val holes: List>? = null,
9 | var fillColor: Int = 0,
10 | var strokeColor: Int = 0,
11 | var strokeWidth: Float = 0.5f,
12 | var strokeJointType: CommonJointType? = null,
13 | var visible: Boolean = true,
14 | var clickable: Boolean = false,
15 | var geodesic: Boolean = true
16 | ) {
17 | /**
18 | * Returns [points] as the Huawei's LatLng.
19 | * @author Arnau Mora
20 | * @since 20210602
21 | */
22 | fun hmsPoints(): List {
23 | val huaweiLatLongs: MutableList = ArrayList()
24 | for (currentLatLng in points) {
25 | huaweiLatLongs.add(
26 | com.huawei.hms.maps.model.LatLng(
27 | currentLatLng.latitude,
28 | currentLatLng.longitude
29 | )
30 | )
31 | }
32 | return huaweiLatLongs
33 | }
34 |
35 | /**
36 | * Returns [holes] as the Huawei's LatLng.
37 | * @author Arnau Mora
38 | * @since 20210602
39 | */
40 | fun hmsHoles(): List> {
41 | val holesPoints: MutableList> = ArrayList()
42 | if (holes != null)
43 | for (hole in holes) {
44 | val holePoints = arrayListOf()
45 | for (point in hole)
46 | holePoints.add(
47 | com.huawei.hms.maps.model.LatLng(
48 | point.latitude,
49 | point.longitude
50 | )
51 | )
52 | holesPoints.add(holePoints)
53 | }
54 |
55 | return holesPoints
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/mapskit/src/main/java/idroid/android/mapskit/model/CommonPolyline.kt:
--------------------------------------------------------------------------------
1 | package idroid.android.mapskit.model
2 |
3 | import com.google.android.gms.maps.model.LatLng
4 | import com.huawei.hms.maps.model.Polyline
5 | import idroid.android.mapskit.utils.DistributeType
6 |
7 | data class CommonPolyline(
8 | var polyline: Any? = null,
9 | val type: DistributeType,
10 | val width: Float?,
11 | val color: Int?,
12 | val ZIndex: Float?
13 | ) {
14 |
15 | constructor(
16 | type: DistributeType,
17 | polyline: Any,
18 | width: Float,
19 | color: Int,
20 | ZIndex: Float,
21 | points: List
22 | ) : this(polyline, type, width, color, ZIndex)
23 |
24 | constructor(
25 | type: DistributeType,
26 | polyline: Any,
27 | points: List,
28 | width: Float,
29 | color: Int,
30 | ZIndex: Float
31 | ) : this(polyline, type, width, color, ZIndex)
32 |
33 | fun remove() {
34 | if (DistributeType.HUAWEI_SERVICES === type) (polyline as Polyline).remove() else (polyline as com.google.android.gms.maps.model.Polyline).remove()
35 | }
36 | }
--------------------------------------------------------------------------------
/mapskit/src/main/java/idroid/android/mapskit/model/CommonPolylineOptions.kt:
--------------------------------------------------------------------------------
1 | package idroid.android.mapskit.model
2 |
3 | import com.google.android.gms.maps.model.LatLng
4 | import java.util.*
5 |
6 | class CommonPolylineOptions {
7 | private val latLngs: MutableList = ArrayList()
8 | private var width = 0f
9 | private var color = 0
10 | private var startCap: CommonCap? = null
11 | private var endCap: CommonCap? = null
12 | private var jointType: CommonJointType? = null
13 |
14 | fun width(width: Float): CommonPolylineOptions {
15 | this.width = width
16 | return this
17 | }
18 |
19 | fun color(color: Int): CommonPolylineOptions {
20 | this.color = color
21 | return this
22 | }
23 |
24 | fun add(llngs: Collection): CommonPolylineOptions {
25 | latLngs.addAll(llngs)
26 | return this
27 | }
28 |
29 | fun add(latLng: LatLng): CommonPolylineOptions {
30 | latLngs.add(latLng)
31 | return this
32 | }
33 |
34 | fun startCap(cap: CommonCap): CommonPolylineOptions {
35 | startCap = cap
36 | return this
37 | }
38 |
39 | fun endCap(cap: CommonCap): CommonPolylineOptions {
40 | endCap = cap
41 | return this
42 | }
43 |
44 | fun jointType(type: CommonJointType): CommonPolylineOptions {
45 | jointType = type
46 | return this
47 | }
48 |
49 | fun getLatLngs(): List = latLngs
50 |
51 | fun getHuaweiLatLngs(): List {
52 | val huaweiLatLongs: MutableList = ArrayList()
53 | for (currentLatLng in latLngs) {
54 | huaweiLatLongs.add(
55 | com.huawei.hms.maps.model.LatLng(
56 | currentLatLng.latitude,
57 | currentLatLng.longitude
58 | )
59 | )
60 | }
61 | return huaweiLatLongs
62 | }
63 |
64 | fun getWidth(): Float = width
65 |
66 | fun getColor(): Int = color
67 |
68 | fun getStartCap(): CommonCap? = startCap
69 | fun getEndCap(): CommonCap? = endCap
70 |
71 | fun getJointType(): CommonJointType? = jointType
72 | }
73 |
--------------------------------------------------------------------------------
/mapskit/src/main/java/idroid/android/mapskit/model/CommonProjection.kt:
--------------------------------------------------------------------------------
1 | package idroid.android.mapskit.model
2 |
3 | import android.graphics.Point
4 | import com.google.android.gms.maps.model.LatLng
5 |
6 | interface CommonProjection {
7 | fun fromScreenLocation(point: Point): LatLng
8 | fun toScreenLocation(latLng: LatLng): Point
9 | val visibleRegion: CommonVisibleRegion
10 | }
--------------------------------------------------------------------------------
/mapskit/src/main/java/idroid/android/mapskit/model/CommonProjectionImpl.kt:
--------------------------------------------------------------------------------
1 | package idroid.android.mapskit.model
2 |
3 | import android.graphics.Point
4 | import com.google.android.gms.maps.model.LatLng
5 | import com.huawei.hms.maps.Projection
6 | import idroid.android.mapskit.utils.toGoogleLatLng
7 | import idroid.android.mapskit.utils.toGoogleLatLngBounds
8 |
9 | class HesProjectionImpl {
10 |
11 | companion object {
12 |
13 | fun getProjection(projection: Any?): CommonProjection? {
14 | if (projection != null) {
15 | if (projection is Projection) {
16 | return HuaweiProjection(projection)
17 | } else if (projection is com.google.android.gms.maps.Projection) {
18 | return GoogleProjection(projection)
19 | }
20 | }
21 | return null
22 | }
23 | }
24 | }
25 |
26 | internal class HuaweiProjection(private val huaweiProjection: Projection) : CommonProjection {
27 |
28 | override val visibleRegion: CommonVisibleRegion
29 | get() {
30 | val visibleRegion = huaweiProjection.visibleRegion
31 | val latLngBounds = visibleRegion.latLngBounds.toGoogleLatLngBounds()
32 |
33 | return CommonVisibleRegion(
34 | latLngBounds,
35 | visibleRegion.farLeft.toGoogleLatLng(),
36 | visibleRegion.farRight.toGoogleLatLng(),
37 | visibleRegion.nearLeft.toGoogleLatLng(),
38 | visibleRegion.nearRight.toGoogleLatLng()
39 | )
40 | }
41 |
42 | override fun fromScreenLocation(point: Point): LatLng {
43 | val latLng = huaweiProjection.fromScreenLocation(point)
44 | return LatLng(latLng.latitude, latLng.longitude)
45 | }
46 |
47 | override fun toScreenLocation(latLng: LatLng): Point {
48 | return huaweiProjection.toScreenLocation(
49 | com.huawei.hms.maps.model.LatLng(
50 | latLng.latitude,
51 | latLng.longitude
52 | )
53 | )
54 | }
55 | }
56 |
57 | internal class GoogleProjection(private val googleProjection: com.google.android.gms.maps.Projection) :
58 | CommonProjection {
59 |
60 | override val visibleRegion: CommonVisibleRegion
61 | get() {
62 | val visibleRegion = googleProjection.visibleRegion
63 | return CommonVisibleRegion(
64 | visibleRegion.latLngBounds,
65 | visibleRegion.farLeft,
66 | visibleRegion.farRight,
67 | visibleRegion.nearLeft,
68 | visibleRegion.nearRight
69 | )
70 | }
71 |
72 | override fun fromScreenLocation(point: Point): LatLng {
73 | return googleProjection.fromScreenLocation(point)
74 | }
75 |
76 | override fun toScreenLocation(latLng: LatLng): Point {
77 | return googleProjection.toScreenLocation(latLng)
78 | }
79 | }
--------------------------------------------------------------------------------
/mapskit/src/main/java/idroid/android/mapskit/model/CommonVisibleRegion.kt:
--------------------------------------------------------------------------------
1 | package idroid.android.mapskit.model
2 |
3 | import com.google.android.gms.maps.model.LatLng
4 | import com.google.android.gms.maps.model.LatLngBounds
5 |
6 | data class CommonVisibleRegion(
7 | val visibleRegionBounds: LatLngBounds?,
8 | val farLeft: LatLng,
9 | val farRight: LatLng,
10 | val nearLeft: LatLng,
11 | val nearRight: LatLng
12 | )
--------------------------------------------------------------------------------
/mapskit/src/main/java/idroid/android/mapskit/ui/HuaweiGoogleMapView.kt:
--------------------------------------------------------------------------------
1 | package idroid.android.mapskit.ui
2 |
3 | import android.content.Context
4 | import android.os.Bundle
5 | import android.util.AttributeSet
6 | import android.view.View
7 | import android.widget.RelativeLayout
8 | import idroid.android.mapskit.R
9 | import idroid.android.mapskit.factory.MapFactory
10 | import idroid.android.mapskit.factory.Maps
11 | import idroid.android.mapskit.factory.MapsLifeCycle
12 | import idroid.android.mapskit.utils.CheckServiceAvaiable
13 | import idroid.android.mapskit.utils.MapType
14 | import kotlinx.android.synthetic.main.huawei_google_map_view.view.*
15 |
16 | class HuaweiGoogleMapView(context: Context, attrs: AttributeSet?) : RelativeLayout(context, attrs) {
17 | private lateinit var myMaps: Maps
18 | private val distributeType = CheckServiceAvaiable.getAvailableService(context)
19 |
20 | init {
21 | inflateLayout()
22 | }
23 |
24 | private fun inflateLayout() {
25 | View.inflate(context, R.layout.huawei_google_map_view, this)
26 | myMaps =
27 | MapFactory.createAndGetMap(context, distributeType, MapType.MAP_VIEW)
28 |
29 | myMaps.getMapView()?.layoutParams = LayoutParams(
30 | LayoutParams.MATCH_PARENT,
31 | LayoutParams.MATCH_PARENT
32 | )
33 | rlRootHuaweiGoogleMapView.addView(myMaps.getMapView())
34 | }
35 |
36 | fun onCreate(bundle: Bundle?) {
37 | myMaps.onCreate(bundle)
38 | }
39 |
40 | fun getMapAsync(onMapAsyncListener: (map: Maps) -> Unit) {
41 | myMaps.getMapAsync(onMapAsyncListener)
42 | }
43 |
44 | fun onEnterAmbient(bundle: Bundle?) {
45 | (myMaps as MapsLifeCycle).onEnterAmbient(bundle)
46 | }
47 |
48 | fun onStart() {
49 | (myMaps as MapsLifeCycle).onStart()
50 | }
51 |
52 | fun onResume() {
53 | (myMaps as MapsLifeCycle).onResume()
54 | }
55 |
56 | fun onPause() {
57 | (myMaps as MapsLifeCycle).onPause()
58 | }
59 |
60 | fun onStop() {
61 | (myMaps as MapsLifeCycle).onStop()
62 | }
63 |
64 | fun onDestroy() {
65 | (myMaps as MapsLifeCycle).onDestroy()
66 | }
67 |
68 | fun onLowMemory() {
69 | (myMaps as MapsLifeCycle).onLowMemory()
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/mapskit/src/main/java/idroid/android/mapskit/ui/HuaweiGoogleSupportMapFragment.kt:
--------------------------------------------------------------------------------
1 | package idroid.android.mapskit.ui
2 |
3 | import android.content.Context
4 | import android.os.Bundle
5 | import android.util.AttributeSet
6 | import android.view.View
7 | import android.widget.RelativeLayout
8 | import idroid.android.mapskit.R
9 | import idroid.android.mapskit.factory.MapFactory
10 | import idroid.android.mapskit.factory.Maps
11 | import idroid.android.mapskit.factory.MapsLifeCycle
12 | import idroid.android.mapskit.utils.CheckServiceAvaiable
13 | import idroid.android.mapskit.utils.MapType
14 |
15 | class HuaweiGoogleSupportMapFragment(context: Context, attrs: AttributeSet?) :
16 | RelativeLayout(context, attrs) {
17 |
18 | private lateinit var myMaps: Maps
19 | private val distributeType = CheckServiceAvaiable.getAvailableService(context)
20 |
21 | init {
22 | inflateLayout()
23 | }
24 |
25 | private fun inflateLayout() {
26 | View.inflate(context, R.layout.huawei_google_support_map_fragment, this)
27 | myMaps =
28 | MapFactory.createAndGetMap(context, distributeType, MapType.MAP_FRAGMENT)
29 | }
30 |
31 | fun onCreate(bundle: Bundle?) {
32 | myMaps.onCreate(bundle)
33 | }
34 |
35 | fun getMapAsync(onMapAsyncListener: (map: Maps) -> Unit) {
36 | myMaps.getMapAsync(onMapAsyncListener)
37 | }
38 |
39 | fun onEnterAmbient(bundle: Bundle?) {
40 | (myMaps as MapsLifeCycle).onEnterAmbient(bundle)
41 | }
42 |
43 | fun onStart() {
44 | (myMaps as MapsLifeCycle).onStart()
45 | }
46 |
47 | fun onResume() {
48 | (myMaps as MapsLifeCycle).onResume()
49 | }
50 |
51 | fun onPause() {
52 | (myMaps as MapsLifeCycle).onPause()
53 | }
54 |
55 | fun onStop() {
56 | (myMaps as MapsLifeCycle).onStop()
57 | }
58 |
59 | fun onDestroy() {
60 | (myMaps as MapsLifeCycle).onDestroy()
61 | }
62 |
63 | fun onLowMemory() {
64 | (myMaps as MapsLifeCycle).onLowMemory()
65 | }
66 |
67 | }
68 |
--------------------------------------------------------------------------------
/mapskit/src/main/java/idroid/android/mapskit/utils/CheckServiceAvaiable.kt:
--------------------------------------------------------------------------------
1 | package idroid.android.mapskit.utils
2 |
3 | import android.content.Context
4 | import com.google.android.gms.common.ConnectionResult
5 | import com.google.android.gms.common.GoogleApiAvailability
6 | import com.huawei.hms.api.HuaweiApiAvailability
7 |
8 | class CheckServiceAvaiable {
9 | companion object {
10 | var distributeType: DistributeType? = null
11 |
12 | fun getAvailableService(context: Context): DistributeType {
13 | if (distributeType == null) {
14 | distributeType = when {
15 | ConnectionResult.SUCCESS == GoogleApiAvailability.getInstance()
16 | .isGooglePlayServicesAvailable(
17 | context
18 | ) -> DistributeType.GOOGLE_SERVICES
19 | com.huawei.hms.api.ConnectionResult.SUCCESS == HuaweiApiAvailability.getInstance()
20 | .isHuaweiMobileServicesAvailable(
21 | context
22 | ) -> DistributeType.HUAWEI_SERVICES
23 | else -> DistributeType.GOOGLE_SERVICES
24 | }
25 | }
26 | return distributeType ?: DistributeType.GOOGLE_SERVICES
27 | }
28 | }
29 |
30 | }
--------------------------------------------------------------------------------
/mapskit/src/main/java/idroid/android/mapskit/utils/DistributeType.kt:
--------------------------------------------------------------------------------
1 | package idroid.android.mapskit.utils
2 |
3 | enum class DistributeType {
4 | GOOGLE_SERVICES,
5 | HUAWEI_SERVICES
6 | }
--------------------------------------------------------------------------------
/mapskit/src/main/java/idroid/android/mapskit/utils/MapExtensions.kt:
--------------------------------------------------------------------------------
1 | package idroid.android.mapskit.utils
2 |
3 | import com.google.android.gms.maps.model.*
4 | import idroid.android.mapskit.model.CommonCircle
5 | import idroid.android.mapskit.model.CommonMarker
6 | import idroid.android.mapskit.model.CommonPolygon
7 | import idroid.android.mapskit.model.CommonPolyline
8 |
9 | // Huawei Map Objects
10 | fun com.huawei.hms.maps.model.LatLng.toGoogleLatLng(): LatLng =
11 | LatLng(this.latitude, this.longitude)
12 |
13 | fun com.huawei.hms.maps.model.Marker.toHesMarker(): CommonMarker = CommonMarker(
14 | DistributeType.HUAWEI_SERVICES,
15 | this,
16 | this.id,
17 | this.alpha,
18 | this.rotation,
19 | LatLng(this.position.latitude, this.position.longitude),
20 | this.title,
21 | this.snippet,
22 | this.tag
23 | )
24 |
25 |
26 | fun com.huawei.hms.maps.model.Polyline.toHesPolyline(): CommonPolyline? = CommonPolyline(
27 | DistributeType.HUAWEI_SERVICES,
28 | this,
29 | this.width,
30 | this.color,
31 | this.zIndex,
32 | this.points
33 | )
34 |
35 | fun com.huawei.hms.maps.model.Polygon.toHesPolygon(): CommonPolygon = CommonPolygon(
36 | DistributeType.HUAWEI_SERVICES,
37 | this
38 | )
39 |
40 | fun com.huawei.hms.maps.model.LatLngBounds.toGoogleLatLngBounds(): LatLngBounds = LatLngBounds(
41 | LatLng(this.southwest.latitude, this.southwest.longitude),
42 | LatLng(this.northeast.latitude, this.northeast.longitude)
43 | )
44 |
45 | fun com.huawei.hms.maps.model.Circle.toHesCircle(): CommonCircle =
46 | CommonCircle(DistributeType.HUAWEI_SERVICES, this)
47 |
48 |
49 | // Google Map Objects
50 | fun LatLng.toHuaweiLatLng(): com.huawei.hms.maps.model.LatLng =
51 | com.huawei.hms.maps.model.LatLng(this.latitude, this.longitude)
52 |
53 | fun Marker.toHesMarker(): CommonMarker = CommonMarker(
54 | DistributeType.GOOGLE_SERVICES,
55 | this,
56 | this.id,
57 | this.alpha,
58 | this.rotation,
59 | LatLng(this.position.latitude, this.position.longitude),
60 | this.title,
61 | this.snippet,
62 | this.tag
63 | )
64 |
65 | fun Polyline.toHesPolyline(): CommonPolyline = CommonPolyline(
66 | DistributeType.GOOGLE_SERVICES,
67 | this,
68 | this.points,
69 | this.width,
70 | this.color,
71 | this.zIndex
72 | )
73 |
74 | fun Polygon.toHesPolygon(): CommonPolygon = CommonPolygon(
75 | DistributeType.GOOGLE_SERVICES,
76 | this
77 | )
78 |
79 | fun LatLngBounds.toHuaweiLatLngBounds(): com.huawei.hms.maps.model.LatLngBounds =
80 | com.huawei.hms.maps.model.LatLngBounds(
81 | LatLng(this.southwest.latitude, this.southwest.longitude).toHuaweiLatLng(),
82 | LatLng(this.northeast.latitude, this.northeast.longitude).toHuaweiLatLng()
83 | )
84 |
85 | fun Circle.toHesCircle(): CommonCircle = CommonCircle(DistributeType.GOOGLE_SERVICES, this)
86 |
87 | fun CircleOptions.toHuaweiCircleOptions(): com.huawei.hms.maps.model.CircleOptions =
88 | com.huawei.hms.maps.model.CircleOptions().radius(this.radius)
89 | .center(this.center.toHuaweiLatLng())
90 | .fillColor(this.fillColor)
91 | .strokeColor(this.strokeColor)
92 | .strokeWidth(this.strokeWidth)
93 |
--------------------------------------------------------------------------------
/mapskit/src/main/java/idroid/android/mapskit/utils/MapType.kt:
--------------------------------------------------------------------------------
1 | package idroid.android.mapskit.utils
2 |
3 | enum class MapType {
4 | MAP_VIEW,
5 | MAP_FRAGMENT
6 | }
--------------------------------------------------------------------------------
/mapskit/src/main/res/layout/huawei_google_map_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
--------------------------------------------------------------------------------
/mapskit/src/main/res/layout/huawei_google_support_map_fragment.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
--------------------------------------------------------------------------------
/mapskit/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | MapsKit
3 |
4 |
--------------------------------------------------------------------------------
/mapskit/src/test/java/idroid/android/mapskit/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package idroid.android.mapskit
2 |
3 | import org.junit.Test
4 |
5 | import org.junit.Assert.*
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * See [testing documentation](http://d.android.com/tools/testing).
11 | */
12 | class ExampleUnitTest {
13 | @Test
14 | fun addition_isCorrect() {
15 | assertEquals(4, 2 + 2)
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':mapskit'
2 | rootProject.name='MapKit'
3 |
--------------------------------------------------------------------------------