Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[android] Keep CompassView's state up to date when compass is enabled. (
Browse files Browse the repository at this point in the history
#15606)

* [android] Keep CompassView's state up to date when compass is enabled.

* [android] Add unit test for updating compass view.

* [android] Add change log.
  • Loading branch information
pengdev authored Sep 12, 2019
1 parent 53e5694 commit f0d3d45
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
1 change: 1 addition & 0 deletions platform/android/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Mapbox welcomes participation and contributions from everyone. If you'd like to

### Bug fixes
- Fixed constant repainting for the sources with invisible layers, caused by `RenderSource::hasFadingTiles()` returning `true` all the time. [#15600](https://github.com/mapbox/mapbox-gl-native/pull/15600)
- Fixed an issue that caused the state of CompassView not up to date when `UiSettings.setCompassEnabled()` is set to true. [#15606](https://github.com/mapbox/mapbox-gl-native/pull/15606)

## 8.4.0-alpha.2 - September 11, 2019
[Changes](https://github.com/mapbox/mapbox-gl-native/compare/android-v8.4.0-alpha.1...android-v8.4.0-alpha.2) since [Mapbox Maps SDK for Android v8.4.0](https://github.com/mapbox/mapbox-gl-native/releases/tag/android-v8.4.0-alpha.1):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,10 +417,6 @@ public Drawable getCompassImage() {
}

void update(@NonNull CameraPosition cameraPosition) {
if (!isCompassEnabled()) {
return;
}

double clockwiseBearing = -cameraPosition.bearing;
compassView.update(clockwiseBearing);
}
Expand Down Expand Up @@ -1073,6 +1069,7 @@ float getPixelRatio() {
*/
public void invalidate() {
setLogoMargins(getLogoMarginLeft(), getLogoMarginTop(), getLogoMarginRight(), getLogoMarginBottom());
setCompassEnabled(isCompassEnabled());
setCompassMargins(getCompassMarginLeft(), getCompassMarginTop(), getCompassMarginRight(), getCompassMarginBottom());
setAttributionMargins(getAttributionMarginLeft(), getAttributionMarginTop(), getAttributionMarginRight(),
getAttributionMarginBottom());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public void setEnabled(boolean enabled) {
resetAnimation();
setAlpha(1.0f);
setVisibility(View.VISIBLE);
update(rotation);
} else {
resetAnimation();
setAlpha(0.0f);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.widget.FrameLayout;
import android.widget.ImageView;

import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.maps.widgets.CompassView;

import org.junit.Before;
Expand All @@ -17,6 +18,7 @@
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.verify;

public class UiSettingsTest {

Expand Down Expand Up @@ -412,4 +414,20 @@ public void testZoomRate() {
assertEquals("Zoom rate should be 0.83f", 0.83f,
uiSettings.getZoomRate(), 0);
}

@Test
public void testUpdateWhenCompassViewNotHidden() {
CameraPosition cameraPosition = new CameraPosition.Builder(CameraPosition.DEFAULT).bearing(24.0f).build();
when(compassView.isHidden()).thenReturn(false);
uiSettings.update(cameraPosition);
verify(compassView).update(-24.0f);
}

@Test
public void testUpdateWhenCompassViewHidden() {
CameraPosition cameraPosition = new CameraPosition.Builder(CameraPosition.DEFAULT).bearing(24.0f).build();
when(compassView.isHidden()).thenReturn(true);
uiSettings.update(cameraPosition);
verify(compassView).update(-24.0f);
}
}

0 comments on commit f0d3d45

Please sign in to comment.