Skip to content

Commit 88ccdea

Browse files
authored
HmsMaps: Modify the Snapshot method (#3200)
1 parent de94027 commit 88ccdea

3 files changed

Lines changed: 16 additions & 7 deletions

File tree

play-services-maps/core/hms/src/main/java/com/google/android/gms/maps/internal/CreatorImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import com.google.android.gms.maps.StreetViewPanoramaOptions;
2020
import com.google.android.gms.maps.model.internal.IBitmapDescriptorFactoryDelegate;
2121

22-
import com.huawei.hms.maps.MapsInitializer;
2322
import org.microg.gms.maps.hms.CameraUpdateFactoryImpl;
2423
import org.microg.gms.maps.hms.MapFragmentImpl;
2524
import org.microg.gms.maps.hms.MapViewImpl;
@@ -30,6 +29,7 @@
3029
@Keep
3130
public class CreatorImpl extends ICreator.Stub {
3231
private static final String TAG = "GmsMapCreator";
32+
public static volatile int VERSION = Integer.MAX_VALUE;
3333

3434
@Override
3535
public void init(IObjectWrapper resources) {
@@ -59,6 +59,7 @@ public IBitmapDescriptorFactoryDelegate newBitmapDescriptorFactoryDelegate() {
5959
@Override
6060
public void initV2(IObjectWrapper resources, int flags) {
6161
BitmapDescriptorFactoryImpl.INSTANCE.initialize(ObjectWrapper.unwrapTyped(resources, Resources.class));
62+
VERSION = flags;
6263
//ResourcesContainer.set((Resources) ObjectWrapper.unwrap(resources));
6364
Log.d(TAG, "initV2 " + flags);
6465
}

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import androidx.annotation.IdRes
2222
import androidx.annotation.Keep
2323
import androidx.collection.LongSparseArray
2424
import com.google.android.gms.dynamic.IObjectWrapper
25+
import com.google.android.gms.dynamic.ObjectWrapper
2526
import com.google.android.gms.dynamic.unwrap
2627
import com.google.android.gms.maps.GoogleMap.MAP_TYPE_TERRAIN
2728
import com.google.android.gms.maps.GoogleMapOptions
@@ -588,10 +589,18 @@ class GoogleMapImpl(private val context: Context, var options: GoogleMapOptions)
588589
}
589590

590591
override fun snapshot(callback: ISnapshotReadyCallback, bitmap: IObjectWrapper?) = afterInitialize {
591-
Log.d(TAG, "snapshot")
592-
val hmsBitmap = bitmap.unwrap<Bitmap>() ?: return@afterInitialize
593-
val hmsCallback = HuaweiMap.SnapshotReadyCallback { p0 -> callback.onBitmapReady(p0) }
594-
it.snapshot(hmsCallback, hmsBitmap)
592+
Log.d(TAG, "taking snapshot now")
593+
val hmsBitmap = bitmap.unwrap<Bitmap>()
594+
Log.d(TAG, "provided bitmap. $hmsBitmap")
595+
val hmsCallback = HuaweiMap.SnapshotReadyCallback { result ->
596+
runOnMainLooper {
597+
Log.d(TAG, "take snapshot end. $result")
598+
if (CreatorImpl.VERSION < SNAPSHOT_OLD_VERSION_CODE) {
599+
callback.onBitmapReady(result)
600+
} else callback.onBitmapWrappedReady(ObjectWrapper.wrap(result))
601+
}
602+
}
603+
if (hmsBitmap != null) it.snapshot(hmsCallback, hmsBitmap) else it.snapshot(hmsCallback)
595604
}
596605

597606
override fun snapshotForTest(callback: ISnapshotReadyCallback) = afterInitialize {
@@ -984,6 +993,7 @@ class GoogleMapImpl(private val context: Context, var options: GoogleMapOptions)
984993

985994
companion object {
986995
private const val TAG = "GmsGoogleMap"
996+
private const val SNAPSHOT_OLD_VERSION_CODE = 4000000
987997

988998
private const val TAG_LOGO = "fakeWatermark"
989999
private const val ON_MAP_CALLBACK_DELAY = 300L

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@ import android.util.Log
1212
import com.google.android.gms.dynamic.IObjectWrapper
1313
import com.google.android.gms.dynamic.ObjectWrapper
1414
import com.google.android.gms.maps.model.internal.IBitmapDescriptorFactoryDelegate
15-
import com.huawei.hms.maps.HuaweiMap
1615
import com.huawei.hms.maps.model.BitmapDescriptorFactory
1716

18-
1917
object BitmapDescriptorFactoryImpl : IBitmapDescriptorFactoryDelegate.Stub() {
2018
private val TAG = "GmsMapBitmap"
2119
private var resources: Resources? = null

0 commit comments

Comments
 (0)