Skip to content
Merged
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 @@ -20,6 +20,7 @@
import android.graphics.Point;
import android.hardware.display.DisplayManager;
import android.hardware.display.VirtualDisplay;
import android.util.DisplayMetrics;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.car.app.AppManager;
Expand Down Expand Up @@ -62,6 +63,7 @@ public abstract class AndroidAutoBaseScreen extends Screen
protected GoogleMap mGoogleMap;
protected boolean mNavigationInitialized = false;
private MapViewController mMapViewController;
private float mDisplayDensity = 1f;

private boolean mAndroidAutoModuleInitialized = false;
private boolean mNavModuleInitialized = false;
Expand Down Expand Up @@ -163,6 +165,11 @@ private void unRegisterControllersForAndroidAutoModule() {
}
}

/** Returns the density of the Android Auto surface currently used. */
public float getDisplayDensity() {
return mDisplayDensity;
}

private boolean isSurfaceReady(SurfaceContainer surfaceContainer) {
return surfaceContainer.getSurface() != null
&& surfaceContainer.getDpi() != 0
Expand All @@ -175,6 +182,7 @@ public void onSurfaceAvailable(@NonNull SurfaceContainer surfaceContainer) {
if (!isSurfaceReady(surfaceContainer)) {
return;
}
mDisplayDensity = surfaceContainer.getDpi() / (float) DisplayMetrics.DENSITY_DEFAULT;
mVirtualDisplay =
getCarContext()
.getSystemService(DisplayManager.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import com.facebook.react.bridge.UiThreadUtil;
import com.facebook.react.bridge.WritableArray;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.uimanager.PixelUtil;
import com.google.android.gms.maps.UiSettings;
import com.google.android.gms.maps.model.CameraPosition;
import com.google.android.gms.maps.model.Circle;
Expand Down Expand Up @@ -620,20 +619,28 @@ public void isAutoScreenAvailable(final Promise promise) {

@Override
public void setMapPadding(double top, double left, double bottom, double right) {
int topInt = Math.round(PixelUtil.toPixelFromDIP(top));
int leftInt = Math.round(PixelUtil.toPixelFromDIP(left));
int bottomInt = Math.round(PixelUtil.toPixelFromDIP(bottom));
int rightInt = Math.round(PixelUtil.toPixelFromDIP(right));
UiThreadUtil.runOnUiThread(
() -> {
if (mMapViewController == null) {
return;
}

mMapViewController.setPadding(topInt, leftInt, bottomInt, rightInt);
float density = getAutoDisplayDensity();
mMapViewController.setPadding(
Math.round((float) (top * density)),
Math.round((float) (left * density)),
Math.round((float) (bottom * density)),
Math.round((float) (right * density)));
});
}

private float getAutoDisplayDensity() {
if (mAutoScreen != null) {
return mAutoScreen.getDisplayDensity();
}
return reactContext.getResources().getDisplayMetrics().density;
}

@Override
public void getMarkers(final Promise promise) {
UiThreadUtil.runOnUiThread(
Expand Down
Loading