-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Retain the bitmap cache #381
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
Conversation
Use a retained fragment to retain the Renderer bitmap cache between configuration changes.
These changes are important to avoid redownloading all bitmap icons after each configuration change. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jeffdgr8 Thanks so much for this contribution, and your patience!
This looks good in general, and follows the Android guidelines for handling caches with configuration changes:
https://developer.android.com/topic/performance/graphics/cache-bitmap#config-changes
A few comments in-line (only one requires action).
One test is failing due to the transition of using activities instead of a context - KmlRendererTest.testAssignStyleMap()
Could you please fix this? I believe it should be relatively straightforward and just involve instantiating an activity in the test and passing it in (null
was previously passed as the context).
java.lang.NullPointerException: Attempt to invoke virtual method 'android.app.FragmentManager android.app.Activity.getFragmentManager()' on a null object reference
at com.google.maps.android.data.Renderer.<init>(Renderer.java:119)
at com.google.maps.android.data.kml.KmlRenderer.<init>(KmlRenderer.java:48)
at com.google.maps.android.data.kml.KmlRendererTest.testAssignStyleMap(KmlRendererTest.java:19)
at java.lang.reflect.Method.invoke(Native Method)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
at androidx.test.internal.runner.TestExecutor.execute(TestExecutor.java:56)
at androidx.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:392)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2156)
library/src/main/java/com/google/maps/android/data/Renderer.java
Outdated
Show resolved
Hide resolved
@@ -42,7 +42,7 @@ public void startDemo () { | |||
|
|||
private void retrieveFileFromResource() { | |||
try { | |||
KmlLayer kmlLayer = new KmlLayer(mMap, R.raw.campus, getApplicationContext()); | |||
KmlLayer kmlLayer = new KmlLayer(mMap, R.raw.campus, this); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that this is a breaking change for apps, as any apps passing getApplicationContext()
would need to change to passing an Activity, as shown here in the demo app.
@jpoehnelt Normally this would require a new major version release in traditional semantic versioning, but given that we're still pre v1.0 I don't know your feelings on this.
Avoids crashing in tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @jeffdgr8, this looks good to me!
@jpoehnelt I'm requesting your review on this too before merging because it includes a breaking chance in the contract with applications - instantiating KmlLayer
now requires an Activity as an argument while it previously allowed the more general Context
(see KmlDemoActivity
for an example). This is a relatively simple change to make in an app but still breaks the build for users when they update to the version that includes this PR. Normally this would require a new major version release in traditional semantic versioning, but given that we're still technically pre v1.0 I don't know your feelings on this.
Thanks for getting to this review. I opted to handle the case of a null activity argument by instantiating the |
* googleOrigin/master: (107 commits) Remove unnecessary interface method public modifiers. (googlemaps#587) Remove unnecessary primitives boxing. (googlemaps#586) Fix googlemaps#575 - Change Travis config, use matrix of API emulators (googlemaps#585) Retain the bitmap cache (googlemaps#381) Made GeoJsonParser with parseGeometry public to use the parser standalone. (googlemaps#492) Fix googlemaps#570 - Use project GitHub URL for remote KML loading demo (googlemaps#581) Bump Gradle plugin for Android Studio v3.5.2 (googlemaps#574) Fix googlemaps#575 - Use API 26 emulator instead of API 28 (googlemaps#576) Fix googlemaps#371 - Run emulator-based unit tests on Travis (googlemaps#573) Fix googlemaps#371 - Run emulator-based unit tests on Travis (googlemaps#573) Fix googlemaps#532 - Use ContextCompat to load drawable resources for scaling (googlemaps#571) Change test methods visibility (googlemaps#569) Release 0.6.2 (googlemaps#568) Demo clustering with ViewModel (googlemaps#506) Differentiate between initial start and configuration change restore (googlemaps#567) Fix wrapping around IDL (googlemaps#564) Update Gradle wrapper to 5.6.3 (googlemaps#566) Add MaxIntensity functionality for user defined intensities on HeatMapTiles (googlemaps#499) Use float zoom to calculate visible bounds (googlemaps#483) Remove apklib publishing (googlemaps#563) ... # Conflicts: # library/src/androidTest/java/com/google/maps/android/PolyUtilTest.java
Use a retained fragment to retain the Renderer bitmap cache between configuration changes.