Skip to content

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

Merged
merged 12 commits into from
Nov 21, 2019
Merged

Conversation

jeffdgr8
Copy link
Contributor

Use a retained fragment to retain the Renderer bitmap cache between configuration changes.

Use a retained fragment to retain the Renderer bitmap cache between
configuration changes.
@jeffdgr8
Copy link
Contributor Author

jeffdgr8 commented Nov 2, 2018

These changes are important to avoid redownloading all bitmap icons after each configuration change.

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Sep 20, 2019
@jpoehnelt jpoehnelt added the triage me I really want to be triaged. label Oct 14, 2019
Copy link
Collaborator

@barbeau barbeau left a 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)

@@ -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);
Copy link
Collaborator

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.

@barbeau barbeau added priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. and removed triage me I really want to be triaged. labels Nov 7, 2019
Copy link
Collaborator

@barbeau barbeau left a 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.

@barbeau barbeau requested a review from jpoehnelt November 14, 2019 21:17
@jeffdgr8
Copy link
Contributor Author

Thanks for getting to this review. I opted to handle the case of a null activity argument by instantiating the LruCache without a retained fragment in this case. Getting an activity for that test case would require adding a dependency, test rule, and test activity, which was easier to avoid by just handling the null.

@jpoehnelt jpoehnelt added the semver: major Hint for users that this is an API breaking change. label Nov 21, 2019
@barbeau barbeau merged commit 5dd9738 into googlemaps:master Nov 21, 2019
@jeffdgr8 jeffdgr8 deleted the retain-bitmap-cache branch November 22, 2019 23:22
pauminku added a commit to pauminku/android-maps-utils that referenced this pull request Nov 26, 2019
* 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
@arriolac arriolac added this to the 1.0 milestone Feb 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement. priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. semver: major Hint for users that this is an API breaking change.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants