Android auto #2994

Merged
shankarpriyank merged 31 commits from Android_Auto into android_auto 2022-09-08 18:28:30 +00:00
5 changed files with 262 additions and 7 deletions

View file

@ -808,8 +808,8 @@
<meta-data android:name="com.google.android.gms.car.application"
android:resource="@xml/automotive_app_desc"/>
<service
android:name="com.androidAuto.HelloWorldService"
<service
android:name="com.androidAuto.AndroidAutoService"
android:exported="true">
<intent-filter>
<action android:name="androidx.car.app.CarAppService" />

View file

@ -0,0 +1,51 @@
package com.androidAuto;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.car.app.CarAppService;
import androidx.car.app.Screen;
import androidx.car.app.Session;
import androidx.car.app.validation.HostValidator;
public final class AndroidAutoService extends CarAppService
{
public AndroidAutoService()
{
// Exported services must have an empty public constructor.
}
@Override
@NonNull
public Session onCreateSession()
{
return new Session()
{
@Override
@NonNull
public Screen onCreateScreen(@Nullable Intent intent)
{
return new MainScreen(getCarContext());
}
};
}
@NonNull
@Override
public HostValidator createHostValidator()
{
if ((getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0)
{
return HostValidator.ALLOW_ALL_HOSTS_VALIDATOR;
}
else
{
return new HostValidator.Builder(getApplicationContext())
.addAllowedHosts(androidx.car.app.R.array.hosts_allowlist_sample)
.build();
}
}
}

View file

@ -0,0 +1,197 @@
package com.androidAuto;
import android.content.Context;
import android.graphics.Rect;
import android.util.Log;
import android.view.Surface;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.car.app.AppManager;
import androidx.car.app.CarContext;
import androidx.car.app.Screen;
import androidx.car.app.SurfaceCallback;
import androidx.car.app.SurfaceContainer;
import androidx.car.app.model.Action;
import androidx.car.app.model.ActionStrip;
import androidx.car.app.model.CarIcon;
import androidx.car.app.model.Template;
import androidx.car.app.navigation.NavigationManager;
import androidx.car.app.navigation.model.NavigationTemplate;
import androidx.core.graphics.drawable.IconCompat;
import com.mapswithme.maps.BuildConfig;
import com.mapswithme.maps.MapFragment;
import com.mapswithme.maps.MwmApplication;
import com.mapswithme.maps.R;
import java.io.IOException;
public class MainScreen extends Screen implements SurfaceCallback
{
private static final String TAG = MainScreen.class.getSimpleName();
@Nullable
private MapFragment mMapFragment;
private SurfaceCallback mSurfaceCallback;
public MainScreen(@NonNull CarContext carContext)
{
super(carContext);
MwmApplication cat = MwmApplication.from(carContext);
try
{
cat.init();
}
catch (IOException e)
{
e.printStackTrace();
return;
}
carContext.getCarService(AppManager.class).setSurfaceCallback(this);
}
@NonNull
@Override
public Template onGetTemplate()
{
Log.e("Show Up", "Shows Up");
NavigationTemplate.Builder builder = new NavigationTemplate.Builder();
ActionStrip.Builder actionStripBuilder = new ActionStrip.Builder();
actionStripBuilder.addAction(new Action.Builder().setTitle("Exit")
.setOnClickListener(this::exit)
.build());
Action panAction = new Action.Builder(Action.PAN).build();
Action zoomIn = new Action.Builder().setIcon(new CarIcon.Builder(IconCompat.createWithResource(getCarContext(), R.drawable.ic_zoom_in)).build())
.setOnClickListener(this::zoomIn)
.build();
Action zoomOut = new Action.Builder().setIcon(new CarIcon.Builder(IconCompat.createWithResource(getCarContext(), R.drawable.ic_zoom_out)).build())
.setOnClickListener(this::zoomOut)
.build();
Action openMic = new Action.Builder().setIcon(new CarIcon.Builder(IconCompat.createWithResource(getCarContext(), R.drawable.ic_booking)).build())
.setOnClickListener(this::zoomOut)
.build();
ActionStrip mapActionStrip = new ActionStrip.Builder().addAction(zoomIn)
.addAction(zoomOut)
.addAction(panAction).addAction(openMic)
.build();
builder.setMapActionStrip(mapActionStrip);
builder.setActionStrip(actionStripBuilder.build());
NavigationManager navigationManager = getCarContext().getCarService(NavigationManager.class);
return builder.build();
}
private void zoomOut()
{
MapFragment.nativeScaleMinus();
}
private void zoomIn()
{
MapFragment.nativeScalePlus();
}
private void exit()
{
getCarContext().finishCarApp();
MapFragment.nativeDetachSurface(true);
}
@Override
public void onSurfaceAvailable(@NonNull SurfaceContainer surfaceContainer)
{
Log.i(TAG, "Surface available " + surfaceContainer);
final Surface surface = surfaceContainer.getSurface();
if (surface == null)
{
Log.e(TAG, "Surface is NULL");
return;
}
if (MapFragment.nativeIsEngineCreated()){
MapFragment.nativeDetachSurface(true);
}
if (MapFragment.nativeIsEngineCreated())
{
if (!MapFragment.nativeAttachSurface(surface))
{
reportUnsupported();
return;
}
MapFragment.nativeResumeSurfaceRendering();
return;
}
final int WIDGET_COPYRIGHT = 0x04;
MapFragment.nativeSetupWidget(WIDGET_COPYRIGHT, 0.0f, 0.0f, 0);
if (!MapFragment.nativeCreateEngine(surface, surfaceContainer.getDpi(), true, false, BuildConfig.VERSION_CODE))
{
reportUnsupported();
return;
}
MapFragment.nativeResumeSurfaceRendering();
}
@Override
public void onVisibleAreaChanged(@NonNull Rect visibleArea)
{
SurfaceCallback.super.onVisibleAreaChanged(visibleArea);
Log.e("Something", "Lets see");
}
@Override
public void onStableAreaChanged(@NonNull Rect stableArea)
{
SurfaceCallback.super.onStableAreaChanged(stableArea);
}
@Override
public void onSurfaceDestroyed(@NonNull SurfaceContainer surfaceContainer)
{
SurfaceCallback.super.onSurfaceDestroyed(surfaceContainer);
MapFragment.nativeDetachSurface(true);
Log.i(TAG, "Surface destroyed");
}
@Override
public void onScroll(float distanceX, float distanceY)
{
SurfaceCallback.super.onScroll(distanceX, distanceY);
Log.i("Scroll", "Scrolled ");
}
@Override
public void onFling(float velocityX, float velocityY)
{
SurfaceCallback.super.onFling(velocityX, velocityY);
Log.i("Fling", "Flinged");
}
@Override
public void onScale(float focusX, float focusY, float scaleFactor)
{
SurfaceCallback.super.onScale(focusX, focusY, scaleFactor);
}
@Override
public void onClick(float x, float y)
{
SurfaceCallback.super.onClick(x, y);
}
private void reportUnsupported()
{
final Context context = getCarContext();
Log.e(TAG, context.getString(R.string.unsupported_phone));
}
}

View file

@ -5,6 +5,7 @@ import android.content.DialogInterface;
import android.graphics.Rect;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.Surface;
@ -153,7 +154,12 @@ public class MapFragment extends BaseMwmFragment
@Override
public void surfaceCreated(SurfaceHolder surfaceHolder)
{
/*
if (MapFragment.nativeIsEngineCreated())
{
nativeDetachSurface(true);
}
if (isThemeChangingProcess())
{
Logger.d(TAG, "Activity is being recreated due theme changing, skip 'surfaceCreated' callback");
@ -209,7 +215,6 @@ public class MapFragment extends BaseMwmFragment
nativeResumeSurfaceRendering();
if (mMapRenderingListener != null)
mMapRenderingListener.onRenderingCreated();
*/
}
@Override
@ -335,6 +340,7 @@ public class MapFragment extends BaseMwmFragment
@Override
public boolean onTouch(View view, MotionEvent event)
{
Log.i("MOTION EVENT",event.toString());
final int count = event.getPointerCount();
if (count == 0)
@ -386,8 +392,8 @@ public class MapFragment extends BaseMwmFragment
}
static native void nativeCompassUpdated(double north, boolean forceRedraw);
static native void nativeScalePlus();
static native void nativeScaleMinus();
public static native void nativeScalePlus();
public static native void nativeScaleMinus();
public static native boolean nativeShowMapForUrl(String url);
public static native boolean nativeIsEngineCreated();
static native boolean nativeDestroySurfaceOnDetach();
@ -396,7 +402,7 @@ public class MapFragment extends BaseMwmFragment
boolean isLaunchByDeepLink,
int appVersionCode);
public static native boolean nativeAttachSurface(Surface surface);
private static native void nativeDetachSurface(boolean destroySurface);
public static native void nativeDetachSurface(boolean destroySurface);
private static native void nativePauseSurfaceRendering();
public static native void nativeResumeSurfaceRendering();
private static native void nativeSurfaceChanged(Surface surface, int w, int h);

View file

@ -106,6 +106,7 @@ public class MwmApplication extends Application implements AppBackgroundTracker.
Logger.i(TAG, "Initializing application");
LogsManager.INSTANCE.initFileLogging(this);
// Set configuration directory as early as possible.
// Other methods may explicitly use Config, which requires settingsDir to be set.
final String settingsPath = StorageUtils.getSettingsPath(this);