Skip to content
Open
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 @@ -58,7 +58,7 @@ public IBitmapDescriptorFactoryDelegate newBitmapDescriptorFactoryDelegate() {

@Override
public void initV2(IObjectWrapper resources, int flags) {
BitmapDescriptorFactoryImpl.INSTANCE.initialize(ObjectWrapper.unwrapTyped(resources, Resources.class));
BitmapDescriptorFactoryImpl.INSTANCE.initialize(ObjectWrapper.unwrapTyped(resources, Resources.class), flags);
//ResourcesContainer.set((Resources) ObjectWrapper.unwrap(resources));
Log.d(TAG, "initV2 " + flags);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ 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.ObjectWrapper
import com.google.android.gms.dynamic.unwrap
import com.google.android.gms.maps.GoogleMap.MAP_TYPE_TERRAIN
import com.google.android.gms.maps.GoogleMapOptions
Expand Down Expand Up @@ -588,10 +589,18 @@ class GoogleMapImpl(private val context: Context, var options: GoogleMapOptions)
}

override fun snapshot(callback: ISnapshotReadyCallback, bitmap: IObjectWrapper?) = afterInitialize {
Log.d(TAG, "snapshot")
val hmsBitmap = bitmap.unwrap<Bitmap>() ?: return@afterInitialize
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should not ignore bitmap if it's provided. Only if bitmap is null or its dimensions (width + height) don't actually match the map view dimensions, you can ignore it, otherwise for performance reason, please use the bitmap provided.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed

val hmsCallback = HuaweiMap.SnapshotReadyCallback { p0 -> callback.onBitmapReady(p0) }
it.snapshot(hmsCallback, hmsBitmap)
Log.d(TAG, "taking snapshot now")
val hmsBitmap = bitmap.unwrap<Bitmap>()
Log.d(TAG, "provided bitmap. $hmsBitmap")
val hmsCallback = HuaweiMap.SnapshotReadyCallback { result ->
runOnMainLooper {
Log.d(TAG, "take snapshot end. $result")
if (BitmapDescriptorFactoryImpl.isOldVersion()) {
callback.onBitmapReady(result)
} else callback.onBitmapWrappedReady(ObjectWrapper.wrap(result))
}
}
if (hmsBitmap != null) it.snapshot(hmsCallback, hmsBitmap) else it.snapshot(hmsCallback)
}

override fun snapshotForTest(callback: ISnapshotReadyCallback) = afterInitialize {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,25 @@ import android.util.Log
import com.google.android.gms.dynamic.IObjectWrapper
import com.google.android.gms.dynamic.ObjectWrapper
import com.google.android.gms.maps.model.internal.IBitmapDescriptorFactoryDelegate
import com.huawei.hms.maps.HuaweiMap
import com.huawei.hms.maps.model.BitmapDescriptorFactory


object BitmapDescriptorFactoryImpl : IBitmapDescriptorFactoryDelegate.Stub() {
private const val OLD_VERSION_CODE = 4000000
private val TAG = "GmsMapBitmap"
private var resources: Resources? = null
private var version: Int = Int.MAX_VALUE

fun initialize(resources: Resources?) {
BitmapDescriptorFactoryImpl.resources = resources ?: BitmapDescriptorFactoryImpl.resources
}

fun initialize(resources: Resources?, version: Int) {
BitmapDescriptorFactoryImpl.resources = resources ?: BitmapDescriptorFactoryImpl.resources
BitmapDescriptorFactoryImpl.version = version
}

fun isOldVersion() = version < OLD_VERSION_CODE

override fun fromResource(resourceId: Int): IObjectWrapper? {
return BitmapFactory.decodeResource(resources, resourceId)?.let {
ObjectWrapper.wrap(BitmapDescriptorFactory.fromBitmap(it))
Expand Down