[android-auto] Fix activity recreation when [dis]connecting to car

Signed-off-by: Andrei Shkrob <github@shkrob.dev>
This commit is contained in:
Andrei Shkrob
2025-09-20 17:28:21 +02:00
committed by x7z4w
parent 832273f928
commit 707415a788
12 changed files with 314 additions and 97 deletions

View File

@@ -280,7 +280,7 @@ public final class Map
return mSurfaceCreated;
}
public void onScroll(double distanceX, double distanceY)
public static void onScroll(double distanceX, double distanceY)
{
Map.nativeOnScroll(distanceX, distanceY);
}
@@ -329,6 +329,11 @@ public final class Map
nativeExecuteMapApiRequest();
}
public DisplayType getDisplayType()
{
return mDisplayType;
}
private void setupWidgets(final Context context, int width, int height)
{
mHeight = height;

View File

@@ -9,9 +9,13 @@ import app.organicmaps.sdk.util.log.Logger;
public class MapController implements DefaultLifecycleObserver
{
private static final String TAG = MapController.class.getSimpleName();
private static final String TAG_PEFRIX = MapController.class.getSimpleName();
@NonNull
private final String TAG;
@NonNull
private final MapView mMapView;
@NonNull
private final Map mMap;
@Nullable
@@ -19,7 +23,7 @@ public class MapController implements DefaultLifecycleObserver
public MapController(@NonNull MapView mapView, @NonNull LocationHelper locationHelper,
@NonNull MapRenderingListener mapRenderingListener,
@NonNull Map.CallbackUnsupported callbackUnsupported, boolean launchByDeepLink)
@Nullable Map.CallbackUnsupported callbackUnsupported, boolean launchByDeepLink)
{
mMapView = mapView;
mMap = mMapView.getMap();
@@ -27,6 +31,7 @@ public class MapController implements DefaultLifecycleObserver
mMap.setLocationHelper(locationHelper);
mMap.setMapRenderingListener(mapRenderingListener);
mMap.setCallbackUnsupported(callbackUnsupported);
TAG = TAG_PEFRIX + "[" + mMap.getDisplayType() + "]";
}
public MapView getView()

View File

@@ -51,7 +51,12 @@ public class MapView extends SurfaceView
public MapView(Context context)
{
this(context, null);
this(context, null, 0);
}
public MapView(Context context, DisplayType displayType)
{
this(context, null, 0, 0, displayType);
}
public MapView(Context context, AttributeSet attrs)
@@ -65,9 +70,15 @@ public class MapView extends SurfaceView
}
public MapView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)
{
this(context, attrs, defStyleAttr, defStyleRes, DisplayType.Device);
}
private MapView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes,
@NonNull DisplayType displayType)
{
super(context, attrs, defStyleAttr, defStyleRes);
mMap = new Map(DisplayType.Device);
mMap = new Map(displayType);
getHolder().addCallback(new SurfaceHolderCallback());
}