Skip to content

HMS Maps: Add fake widgets for better compatibility #2899

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 1, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import android.util.Log
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.RelativeLayout
import androidx.annotation.IdRes
Expand Down Expand Up @@ -100,7 +101,7 @@ class GoogleMapImpl(private val context: Context, var options: GoogleMapOptions)
}

this.view = object : FrameLayout(mapContext) {
private val fakeWatermark = View(mapContext).apply {
private val fakeWatermark = ImageView(mapContext).apply {
tag = "GoogleWatermark"
visibility = GONE
}
Expand All @@ -112,20 +113,37 @@ class GoogleMapImpl(private val context: Context, var options: GoogleMapOptions)
tag = "GoogleMapZoomInButton"
visibility = GONE
}
private val fakeZoomOutButton = View(mapContext).apply {
tag = "GoogleMapZoomOutButton"
visibility = GONE
}
private val fakeMyLocationButton = View(mapContext).apply {
tag = "GoogleMapMyLocationButton"
visibility = GONE
}

private val zoomInButtonRoot = RelativeLayout(mapContext).apply {
private val fakeZoomButtonRoot = LinearLayout(mapContext).apply {
addView(fakeZoomInButton)
addView(fakeZoomOutButton)
visibility = GONE
}

private val mapButtonRoot = RelativeLayout(mapContext).apply {
addView(fakeZoomButtonRoot)
addView(fakeMyLocationButton)
addView(fakeCompass)
addView(fakeWatermark)
visibility = GONE
}

override fun onAttachedToWindow() {
super.onAttachedToWindow()
addView(zoomInButtonRoot)
addView(mapButtonRoot)
}

override fun onDetachedFromWindow() {
super.onDetachedFromWindow()
removeView(zoomInButtonRoot)
removeView(mapButtonRoot)
}

@Keep
Expand Down Expand Up @@ -159,6 +177,22 @@ class GoogleMapImpl(private val context: Context, var options: GoogleMapOptions)
null
}
}
if ("GoogleMapZoomOutButton" == tag) {
return try {
@Suppress("UNCHECKED_CAST")
fakeZoomOutButton as T
} catch (e: ClassCastException) {
null
}
}
if ("GoogleMapMyLocationButton" == tag) {
return try {
@Suppress("UNCHECKED_CAST")
fakeMyLocationButton as T
} catch (e: ClassCastException) {
null
}
}
return null
}
}
Expand Down