Skip to content
Merged
Show file tree
Hide file tree
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 @@ -15,6 +15,9 @@ import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import android.widget.LinearLayout
import android.widget.RelativeLayout
import androidx.annotation.IdRes
import androidx.annotation.Keep
import androidx.collection.LongSparseArray
import com.google.android.gms.dynamic.IObjectWrapper
import com.google.android.gms.dynamic.unwrap
Expand Down Expand Up @@ -97,7 +100,69 @@ class GoogleMapImpl(private val context: Context, var options: GoogleMapOptions)
MapsInitializer.setApiKey(BuildConfig.HMSMAP_KEY)
}

this.view = object : FrameLayout(mapContext) {}
this.view = object : FrameLayout(mapContext) {
private val fakeWatermark = View(mapContext).apply {
tag = "GoogleWatermark"
visibility = GONE
}
private val fakeCompass = View(mapContext).apply {
tag = "GoogleMapCompass"
visibility = GONE
}
private val fakeZoomInButton = View(mapContext).apply {
tag = "GoogleMapZoomInButton"
visibility = GONE
}

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

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

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

@Keep
fun <T : View> findViewTraversal(@IdRes id: Int): T? {
return null
}

@Keep
fun <T : View> findViewWithTagTraversal(tag: Any): T? {
if ("GoogleWatermark" == tag) {
return try {
@Suppress("UNCHECKED_CAST")
fakeWatermark as T
} catch (e: ClassCastException) {
null
}
}
if ("GoogleMapCompass" == tag) {
return try {
@Suppress("UNCHECKED_CAST")
fakeCompass as T
} catch (e: ClassCastException) {
null
}
}
if ("GoogleMapZoomInButton" == tag) {
return try {
@Suppress("UNCHECKED_CAST")
fakeZoomInButton as T
} catch (e: ClassCastException) {
null
}
}
return null
}
}
}

override fun getCameraPosition(): CameraPosition {
Expand Down Expand Up @@ -601,7 +666,7 @@ class GoogleMapImpl(private val context: Context, var options: GoogleMapOptions)
}

private fun initMap(map: HuaweiMap) {
if (this.map != null) return
if (this.map != null && initialized) return

loaded = true
this.map = map
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class MapFragmentImpl(private val activity: Activity) : IMapFragmentDelegate.Stu
if (options == null) {
options = GoogleMapOptions()
}
Log.d(TAG, "onCreate: $options")
Log.d(TAG, "onCreate $this : $options ")
map = GoogleMapImpl(activity, options ?: GoogleMapOptions())
}

Expand All @@ -47,7 +47,7 @@ class MapFragmentImpl(private val activity: Activity) : IMapFragmentDelegate.Stu
if (map == null) {
map = GoogleMapImpl(activity, options ?: GoogleMapOptions())
}
Log.d(TAG, "onCreateView: $options")
Log.d(TAG, "onCreateView $this : $options")
map!!.onCreate(savedInstanceState)
val view = map!!.view
val parent = view.parent as ViewGroup?
Expand All @@ -67,10 +67,15 @@ class MapFragmentImpl(private val activity: Activity) : IMapFragmentDelegate.Stu
override fun getMapAsync(callback: IOnMapReadyCallback) = map?.getMapAsync(callback) ?: Unit

override fun onDestroyView() {
map?.onDestroy()
Log.d(TAG, "onDestroyView: $this : $options")
if (options?.useViewLifecycleInFragment == true) {
map?.onDestroy()
map = null
}
}

override fun onDestroy() {
Log.d(TAG, "onDestroy: $this")
map?.onDestroy()
map = null
options = null
Expand Down
Loading