Skip to content

Commit 8e49003

Browse files
authored
HMS Maps: Add dark mode style (#2928)
1 parent f633baa commit 8e49003

4 files changed

Lines changed: 497 additions & 5 deletions

File tree

play-services-maps/core/hms/src/main/kotlin/org/microg/gms/maps/hms/GoogleMap.kt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ fun runOnMainLooper(forceQueue: Boolean = false, method: () -> Unit) {
5757

5858
class GoogleMapImpl(private val context: Context, var options: GoogleMapOptions) : IGoogleMapDelegate.Stub() {
5959

60+
internal val mapContext = MapContext(context)
61+
6062
val view: FrameLayout
6163
var map: HuaweiMap? = null
6264
private set
@@ -94,7 +96,6 @@ class GoogleMapImpl(private val context: Context, var options: GoogleMapOptions)
9496
val markers = mutableMapOf<String, MarkerImpl>()
9597

9698
init {
97-
val mapContext = MapContext(context)
9899
BitmapDescriptorFactoryImpl.initialize(context.resources)
99100
runOnMainLooper {
100101
MapsInitializer.setApiKey(BuildConfig.HMSMAP_KEY)
@@ -257,8 +258,13 @@ class GoogleMapImpl(private val context: Context, var options: GoogleMapOptions)
257258
override fun stopAnimation() = map?.stopAnimation() ?: Unit
258259

259260
override fun setMapStyle(options: MapStyleOptions?): Boolean {
260-
Log.d(TAG, "unimplemented Method: setMapStyle ${options?.getJson()}")
261-
return true
261+
Log.d(TAG, "setMapStyle: ")
262+
val bool = options?.toHms(mapContext).let {
263+
Log.d(TAG, "setMapStyle: option: ${it?.json}")
264+
map?.setMapStyle(it)
265+
}
266+
Log.d(TAG, "setMapStyle: bool: $bool")
267+
return true == bool
262268
}
263269

264270
override fun setMinZoomPreference(minZoom: Float) = afterInitialize {
@@ -652,7 +658,6 @@ class GoogleMapImpl(private val context: Context, var options: GoogleMapOptions)
652658
override fun onCreate(savedInstanceState: Bundle?) {
653659
if (!created) {
654660
Log.d(TAG_LOGO, "create: ${context.packageName},\n$options")
655-
val mapContext = MapContext(context)
656661
MapsInitializer.initialize(mapContext)
657662
val mapView = MapView(mapContext, options.toHms()).apply { visibility = View.INVISIBLE }
658663
this.mapView = mapView

play-services-maps/core/hms/src/main/kotlin/org/microg/gms/maps/hms/utils/typeConverter.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@
55

66
package org.microg.gms.maps.hms.utils
77

8+
import android.content.res.Configuration
89
import android.os.Bundle
9-
import android.util.Log
1010
import com.google.android.gms.dynamic.unwrap
1111
import com.google.android.gms.maps.GoogleMapOptions
1212
import com.google.android.gms.maps.internal.ICancelableCallback
1313
import com.huawei.hms.maps.HuaweiMap
1414
import com.huawei.hms.maps.HuaweiMapOptions
1515
import com.huawei.hms.maps.model.*
16+
import org.microg.gms.maps.hms.R
1617
import com.google.android.gms.maps.model.CameraPosition as GmsCameraPosition
1718
import com.google.android.gms.maps.model.CircleOptions as GmsCircleOptions
1819
import com.google.android.gms.maps.model.Dash as GmsDash
@@ -21,6 +22,7 @@ import com.google.android.gms.maps.model.Gap as GmsGap
2122
import com.google.android.gms.maps.model.GroundOverlayOptions as GmsGroundOverlayOptions
2223
import com.google.android.gms.maps.model.LatLng as GmsLatLng
2324
import com.google.android.gms.maps.model.LatLngBounds as GmsLatLngBounds
25+
import com.google.android.gms.maps.model.MapStyleOptions as GmsMapStyleOptions
2426
import com.google.android.gms.maps.model.MarkerOptions as GmsMarkerOptions
2527
import com.google.android.gms.maps.model.PatternItem as GmsPatternItem
2628
import com.google.android.gms.maps.model.PolygonOptions as GmsPolygonOptions
@@ -227,3 +229,11 @@ fun Bundle.toGms(): Bundle {
227229
newBundle.classLoader = oldLoader
228230
return newBundle
229231
}
232+
233+
fun GmsMapStyleOptions.toHms(context: MapContext): MapStyleOptions {
234+
val nightMode = context.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK
235+
if (nightMode == Configuration.UI_MODE_NIGHT_YES) {
236+
return MapStyleOptions.loadRawResourceStyle(context, R.raw.mapstyle_night_hms)
237+
}
238+
return MapStyleOptions.loadRawResourceStyle(context, R.raw.mapstyle_grayscale_hms)
239+
}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
[
2+
{
3+
"featureType": "all",
4+
"elementType": "geometry",
5+
"stylers": [
6+
{
7+
"color": "#f5f5f5"
8+
}
9+
]
10+
},
11+
{
12+
"featureType": "all",
13+
"elementType": "labels.icon",
14+
"stylers": [
15+
{
16+
"saturation": -100
17+
}
18+
]
19+
},
20+
{
21+
"featureType": "all",
22+
"elementType": "labels.text",
23+
"stylers": [
24+
{
25+
"saturation": -100
26+
}
27+
]
28+
},
29+
{
30+
"featureType": "poi",
31+
"elementType": "geometry",
32+
"stylers": [
33+
{
34+
"color": "#eeeeee"
35+
}
36+
]
37+
},
38+
{
39+
"featureType": "poi.park",
40+
"elementType": "geometry",
41+
"stylers": [
42+
{
43+
"color": "#e5e5e5"
44+
}
45+
]
46+
},
47+
{
48+
"featureType": "road",
49+
"elementType": "geometry",
50+
"stylers": [
51+
{
52+
"color": "#ffffff"
53+
}
54+
]
55+
},
56+
{
57+
"featureType": "road.highway",
58+
"elementType": "geometry",
59+
"stylers": [
60+
{
61+
"color": "#dadada"
62+
}
63+
]
64+
},
65+
{
66+
"featureType": "road.highway",
67+
"elementType": "labels.icon",
68+
"stylers": [
69+
{
70+
"lightness": 30
71+
}
72+
]
73+
},
74+
{
75+
"featureType": "transit.line",
76+
"elementType": "geometry",
77+
"stylers": [
78+
{
79+
"color": "#e5e5e5"
80+
}
81+
]
82+
},
83+
{
84+
"featureType": "transit.station",
85+
"elementType": "geometry",
86+
"stylers": [
87+
{
88+
"color": "#eeeeee"
89+
}
90+
]
91+
},
92+
{
93+
"featureType": "water",
94+
"elementType": "geometry",
95+
"stylers": [
96+
{
97+
"color": "#c9c9c9"
98+
}
99+
]
100+
}
101+
]

0 commit comments

Comments
 (0)