[android-auto] Remove OMController
and move checkbox creator functions to the Screen classes
Signed-off-by: Andrew Shkrob <andrew.shkrob.social@yandex.by>
This commit is contained in:
parent
90662aed81
commit
05a1411862
10 changed files with 148 additions and 222 deletions
|
@ -4,23 +4,14 @@ import android.content.Intent;
|
|||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.car.app.CarToast;
|
||||
import androidx.car.app.Screen;
|
||||
import androidx.car.app.ScreenManager;
|
||||
import androidx.car.app.Session;
|
||||
import androidx.car.app.model.Action;
|
||||
import androidx.car.app.model.ActionStrip;
|
||||
import androidx.car.app.model.CarIcon;
|
||||
import androidx.car.app.navigation.model.MapController;
|
||||
import androidx.core.graphics.drawable.IconCompat;
|
||||
import androidx.lifecycle.DefaultLifecycleObserver;
|
||||
import androidx.lifecycle.LifecycleOwner;
|
||||
|
||||
import app.organicmaps.MwmApplication;
|
||||
import app.organicmaps.R;
|
||||
import app.organicmaps.car.screens.ErrorScreen;
|
||||
import app.organicmaps.car.screens.NavigationScreen;
|
||||
import app.organicmaps.car.screens.settings.SettingsScreen;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
@ -28,13 +19,13 @@ public final class NavigationSession extends Session implements DefaultLifecycle
|
|||
{
|
||||
private static final String TAG = NavigationSession.class.getSimpleName();
|
||||
|
||||
private OMController mMapController;
|
||||
|
||||
boolean mInitFailed = false;
|
||||
private final SurfaceRenderer mSurfaceRenderer;
|
||||
private boolean mInitFailed = false;
|
||||
|
||||
public NavigationSession()
|
||||
{
|
||||
getLifecycle().addObserver(this);
|
||||
mSurfaceRenderer = new SurfaceRenderer(getCarContext(), getLifecycle());
|
||||
}
|
||||
|
||||
@NonNull
|
||||
|
@ -45,8 +36,7 @@ public final class NavigationSession extends Session implements DefaultLifecycle
|
|||
if (mInitFailed)
|
||||
return new ErrorScreen(getCarContext());
|
||||
|
||||
createMapController();
|
||||
return new NavigationScreen(getCarContext(), mMapController);
|
||||
return new NavigationScreen(getCarContext(), mSurfaceRenderer);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -76,46 +66,4 @@ public final class NavigationSession extends Session implements DefaultLifecycle
|
|||
Log.e(TAG, "Failed to initialize the app.");
|
||||
}
|
||||
}
|
||||
|
||||
private void createMapController()
|
||||
{
|
||||
final CarIcon iconPlus = new CarIcon.Builder(IconCompat.createWithResource(getCarContext(), R.drawable.ic_plus)).build();
|
||||
final CarIcon iconMinus = new CarIcon.Builder(IconCompat.createWithResource(getCarContext(), R.drawable.ic_minus)).build();
|
||||
final CarIcon iconLocation = new CarIcon.Builder(IconCompat.createWithResource(getCarContext(), R.drawable.ic_not_follow)).build();
|
||||
final CarIcon iconSettings = new CarIcon.Builder(IconCompat.createWithResource(getCarContext(), R.drawable.ic_settings)).build();
|
||||
|
||||
SurfaceRenderer surfaceRenderer = new SurfaceRenderer(getCarContext(), getLifecycle());
|
||||
|
||||
Action panAction = new Action.Builder(Action.PAN).build();
|
||||
Action location = new Action.Builder().setIcon(iconLocation).setOnClickListener(this::location).build();
|
||||
Action zoomIn = new Action.Builder().setIcon(iconPlus).setOnClickListener(this::zoomIn).build();
|
||||
Action zoomOut = new Action.Builder().setIcon(iconMinus).setOnClickListener(this::zoomOut).build();
|
||||
ActionStrip mapActionStrip = new ActionStrip.Builder().addAction(location).addAction(zoomIn).addAction(zoomOut).addAction(panAction).build();
|
||||
MapController mapController = new MapController.Builder().setMapActionStrip(mapActionStrip).build();
|
||||
|
||||
Action settings = new Action.Builder().setIcon(iconSettings).setOnClickListener(this::openSettings).build();
|
||||
ActionStrip actionStrip = new ActionStrip.Builder().addAction(settings).build();
|
||||
|
||||
mMapController = new OMController(surfaceRenderer, mapController, actionStrip);
|
||||
}
|
||||
|
||||
private void location()
|
||||
{
|
||||
CarToast.makeText(getCarContext(), "Location", CarToast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
private void zoomOut()
|
||||
{
|
||||
mMapController.getSurfaceRenderer().onZoomOut();
|
||||
}
|
||||
|
||||
private void zoomIn()
|
||||
{
|
||||
mMapController.getSurfaceRenderer().onZoomIn();
|
||||
}
|
||||
|
||||
private void openSettings()
|
||||
{
|
||||
getCarContext().getCarService(ScreenManager.class).push(new SettingsScreen(getCarContext(), mMapController));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,40 +0,0 @@
|
|||
package app.organicmaps.car;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.car.app.model.ActionStrip;
|
||||
import androidx.car.app.navigation.model.MapController;
|
||||
|
||||
public class OMController
|
||||
{
|
||||
@NonNull
|
||||
private final SurfaceRenderer mSurfaceRenderer;
|
||||
@NonNull
|
||||
private final MapController mMapController;
|
||||
@NonNull
|
||||
private final ActionStrip mActionStrip;
|
||||
|
||||
public OMController(@NonNull SurfaceRenderer surfaceRenderer, @NonNull MapController mapController, @NonNull ActionStrip actionStrip)
|
||||
{
|
||||
mSurfaceRenderer = surfaceRenderer;
|
||||
mMapController = mapController;
|
||||
mActionStrip = actionStrip;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public SurfaceRenderer getSurfaceRenderer()
|
||||
{
|
||||
return mSurfaceRenderer;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public MapController getMapController()
|
||||
{
|
||||
return mMapController;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public ActionStrip getActionStrip()
|
||||
{
|
||||
return mActionStrip;
|
||||
}
|
||||
}
|
|
@ -1,75 +1,47 @@
|
|||
package app.organicmaps.car;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.StringRes;
|
||||
import androidx.car.app.CarContext;
|
||||
import androidx.car.app.CarToast;
|
||||
import androidx.car.app.ScreenManager;
|
||||
import androidx.car.app.model.Action;
|
||||
import androidx.car.app.model.ActionStrip;
|
||||
import androidx.car.app.model.CarIcon;
|
||||
import androidx.car.app.model.Row;
|
||||
import androidx.car.app.navigation.model.MapController;
|
||||
import androidx.core.graphics.drawable.IconCompat;
|
||||
|
||||
import app.organicmaps.R;
|
||||
import app.organicmaps.routing.RoutingOptions;
|
||||
import app.organicmaps.settings.RoadType;
|
||||
import app.organicmaps.car.screens.settings.SettingsScreen;
|
||||
|
||||
public final class UiHelpers
|
||||
{
|
||||
public interface PrefsGetter
|
||||
public static ActionStrip createSettingsActionStrip(@NonNull CarContext context, @NonNull SurfaceRenderer surfaceRenderer)
|
||||
{
|
||||
boolean get();
|
||||
final CarIcon iconSettings = new CarIcon.Builder(IconCompat.createWithResource(context, R.drawable.ic_settings)).build();
|
||||
final Action settings = new Action.Builder().setIcon(iconSettings).setOnClickListener(
|
||||
() -> context.getCarService(ScreenManager.class).push(new SettingsScreen(context, surfaceRenderer))
|
||||
).build();
|
||||
return new ActionStrip.Builder().addAction(settings).build();
|
||||
}
|
||||
|
||||
public interface PrefsSetter
|
||||
public static MapController createMapController(@NonNull CarContext context, @NonNull SurfaceRenderer surfaceRenderer)
|
||||
{
|
||||
void set(boolean newValue);
|
||||
}
|
||||
final CarIcon iconPlus = new CarIcon.Builder(IconCompat.createWithResource(context, R.drawable.ic_plus)).build();
|
||||
final CarIcon iconMinus = new CarIcon.Builder(IconCompat.createWithResource(context, R.drawable.ic_minus)).build();
|
||||
final CarIcon iconLocation = new CarIcon.Builder(IconCompat.createWithResource(context, R.drawable.ic_not_follow)).build();
|
||||
|
||||
@Nullable
|
||||
private static CarIcon mCheckboxIcon;
|
||||
@Nullable
|
||||
private static CarIcon mCheckboxSelectedIcon;
|
||||
|
||||
@NonNull
|
||||
public static Row createSharedPrefsCheckbox(
|
||||
@NonNull CarContext context, @StringRes int titleRes, PrefsGetter getter, PrefsSetter setter)
|
||||
{
|
||||
final boolean getterValue = getter.get();
|
||||
|
||||
if (mCheckboxIcon == null || mCheckboxSelectedIcon == null)
|
||||
initCheckboxIcons(context);
|
||||
Row.Builder builder = new Row.Builder();
|
||||
builder.setTitle(context.getString(titleRes));
|
||||
builder.setOnClickListener(() -> {
|
||||
setter.set(!getterValue);
|
||||
context.getCarService(ScreenManager.class).getTop().invalidate();
|
||||
});
|
||||
builder.setImage(getterValue ? mCheckboxSelectedIcon : mCheckboxIcon);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static Row createDrivingOptionCheckbox(
|
||||
@NonNull CarContext context, RoadType roadType, @StringRes int titleRes)
|
||||
{
|
||||
if (mCheckboxIcon == null || mCheckboxSelectedIcon == null)
|
||||
initCheckboxIcons(context);
|
||||
Row.Builder builder = new Row.Builder();
|
||||
builder.setTitle(context.getString(titleRes));
|
||||
builder.setOnClickListener(() -> {
|
||||
if (RoutingOptions.hasOption(roadType))
|
||||
RoutingOptions.removeOption(roadType);
|
||||
else
|
||||
RoutingOptions.addOption(roadType);
|
||||
context.getCarService(ScreenManager.class).getTop().invalidate();
|
||||
});
|
||||
builder.setImage(RoutingOptions.hasOption(roadType) ? mCheckboxSelectedIcon : mCheckboxIcon);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
private static void initCheckboxIcons(@NonNull CarContext context)
|
||||
{
|
||||
mCheckboxIcon = new CarIcon.Builder(IconCompat.createWithResource(context, R.drawable.ic_check_box)).build();
|
||||
mCheckboxSelectedIcon = new CarIcon.Builder(IconCompat.createWithResource(context, R.drawable.ic_check_box_checked)).build();
|
||||
final Action panAction = new Action.Builder(Action.PAN).build();
|
||||
final Action location = new Action.Builder().setIcon(iconLocation).setOnClickListener(
|
||||
() -> CarToast.makeText(context, "Location", CarToast.LENGTH_LONG).show()
|
||||
).build();
|
||||
final Action zoomIn = new Action.Builder().setIcon(iconPlus).setOnClickListener(surfaceRenderer::onZoomIn).build();
|
||||
final Action zoomOut = new Action.Builder().setIcon(iconMinus).setOnClickListener(surfaceRenderer::onZoomOut).build();
|
||||
final ActionStrip mapActionStrip = new ActionStrip.Builder()
|
||||
.addAction(location)
|
||||
.addAction(zoomIn)
|
||||
.addAction(zoomOut)
|
||||
.addAction(panAction)
|
||||
.build();
|
||||
return new MapController.Builder().setMapActionStrip(mapActionStrip).build();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,8 @@ import app.organicmaps.R;
|
|||
import app.organicmaps.bookmarks.data.BookmarkCategory;
|
||||
import app.organicmaps.bookmarks.data.BookmarkInfo;
|
||||
import app.organicmaps.bookmarks.data.BookmarkManager;
|
||||
import app.organicmaps.car.OMController;
|
||||
import app.organicmaps.car.SurfaceRenderer;
|
||||
import app.organicmaps.car.UiHelpers;
|
||||
import app.organicmaps.util.Graphics;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -32,16 +33,16 @@ public class BookmarksScreen extends MapScreen
|
|||
@Nullable
|
||||
private BookmarkCategory mBookmarkCategory;
|
||||
|
||||
public BookmarksScreen(@NonNull CarContext carContext, @NonNull OMController mapController)
|
||||
public BookmarksScreen(@NonNull CarContext carContext, @NonNull SurfaceRenderer surfaceRenderer)
|
||||
{
|
||||
super(carContext, mapController);
|
||||
super(carContext, surfaceRenderer);
|
||||
final ConstraintManager constraintManager = getCarContext().getCarService(ConstraintManager.class);
|
||||
MAX_CATEGORIES_SIZE = constraintManager.getContentLimit(ConstraintManager.CONTENT_LIMIT_TYPE_LIST);
|
||||
}
|
||||
|
||||
private BookmarksScreen(@NonNull CarContext carContext, @NonNull OMController mapController, @NonNull BookmarkCategory bookmarkCategory)
|
||||
private BookmarksScreen(@NonNull CarContext carContext, @NonNull SurfaceRenderer surfaceRenderer, @NonNull BookmarkCategory bookmarkCategory)
|
||||
{
|
||||
this(carContext, mapController);
|
||||
this(carContext, surfaceRenderer);
|
||||
mBookmarkCategory = bookmarkCategory;
|
||||
}
|
||||
|
||||
|
@ -51,8 +52,8 @@ public class BookmarksScreen extends MapScreen
|
|||
{
|
||||
MapTemplate.Builder builder = new MapTemplate.Builder();
|
||||
builder.setHeader(createHeader());
|
||||
builder.setMapController(getMapController());
|
||||
builder.setActionStrip(getActionStrip());
|
||||
builder.setMapController(UiHelpers.createMapController(getCarContext(), getSurfaceRenderer()));
|
||||
builder.setActionStrip(UiHelpers.createSettingsActionStrip(getCarContext(), getSurfaceRenderer()));
|
||||
builder.setItemList(mBookmarkCategory == null ? createBookmarkCategoriesList() : createBookmarksList());
|
||||
return builder.build();
|
||||
}
|
||||
|
@ -80,7 +81,7 @@ public class BookmarksScreen extends MapScreen
|
|||
Row.Builder itemBuilder = new Row.Builder();
|
||||
itemBuilder.setTitle(bookmarkCategory.getName());
|
||||
itemBuilder.addText(bookmarkCategory.getDescription());
|
||||
itemBuilder.setOnClickListener(() -> getScreenManager().push(new BookmarksScreen(getCarContext(), getOMController(), bookmarkCategory)));
|
||||
itemBuilder.setOnClickListener(() -> getScreenManager().push(new BookmarksScreen(getCarContext(), getSurfaceRenderer(), bookmarkCategory)));
|
||||
itemBuilder.setBrowsable(true);
|
||||
builder.addItem(itemBuilder.build());
|
||||
}
|
||||
|
@ -99,7 +100,7 @@ public class BookmarksScreen extends MapScreen
|
|||
final long bookmarkId = BookmarkManager.INSTANCE.getBookmarkIdByPosition(bookmarkCategoryId, i);
|
||||
final BookmarkInfo bookmarkInfo = new BookmarkInfo(bookmarkCategoryId, bookmarkId);
|
||||
|
||||
Row.Builder itemBuilder = new Row.Builder();
|
||||
final Row.Builder itemBuilder = new Row.Builder();
|
||||
itemBuilder.setTitle(bookmarkInfo.getName());
|
||||
if (!bookmarkInfo.getAddress().isEmpty())
|
||||
itemBuilder.addText(bookmarkInfo.getAddress());
|
||||
|
@ -119,9 +120,9 @@ public class BookmarksScreen extends MapScreen
|
|||
@NonNull
|
||||
private static List<BookmarkCategory> getBookmarks()
|
||||
{
|
||||
List<BookmarkCategory> bookmarkCategories = new ArrayList<>(BookmarkManager.INSTANCE.getCategories());
|
||||
final List<BookmarkCategory> bookmarkCategories = new ArrayList<>(BookmarkManager.INSTANCE.getCategories());
|
||||
|
||||
List<BookmarkCategory> toRemove = new ArrayList<>();
|
||||
final List<BookmarkCategory> toRemove = new ArrayList<>();
|
||||
for (BookmarkCategory bookmarkCategory : bookmarkCategories)
|
||||
{
|
||||
if (bookmarkCategory.getBookmarksCount() == 0)
|
||||
|
|
|
@ -15,7 +15,8 @@ import androidx.car.app.navigation.model.MapTemplate;
|
|||
import androidx.core.graphics.drawable.IconCompat;
|
||||
|
||||
import app.organicmaps.R;
|
||||
import app.organicmaps.car.OMController;
|
||||
import app.organicmaps.car.SurfaceRenderer;
|
||||
import app.organicmaps.car.UiHelpers;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
@ -49,10 +50,11 @@ public class CategoriesScreen extends MapScreen
|
|||
|
||||
private final int MAX_CATEGORIES_SIZE;
|
||||
|
||||
public CategoriesScreen(@NonNull CarContext carContext, @NonNull OMController mapController)
|
||||
public CategoriesScreen(@NonNull CarContext carContext, @NonNull SurfaceRenderer surfaceRenderer)
|
||||
{
|
||||
super(carContext, mapController);
|
||||
MAX_CATEGORIES_SIZE = getCarContext().getCarService(ConstraintManager.class).getContentLimit(ConstraintManager.CONTENT_LIMIT_TYPE_LIST);
|
||||
super(carContext, surfaceRenderer);
|
||||
final ConstraintManager constraintManager = getCarContext().getCarService(ConstraintManager.class);
|
||||
MAX_CATEGORIES_SIZE = constraintManager.getContentLimit(ConstraintManager.CONTENT_LIMIT_TYPE_LIST);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
|
@ -61,8 +63,8 @@ public class CategoriesScreen extends MapScreen
|
|||
{
|
||||
MapTemplate.Builder builder = new MapTemplate.Builder();
|
||||
builder.setHeader(createHeader());
|
||||
builder.setMapController(getMapController());
|
||||
builder.setActionStrip(getActionStrip());
|
||||
builder.setMapController(UiHelpers.createMapController(getCarContext(), getSurfaceRenderer()));
|
||||
builder.setActionStrip(UiHelpers.createSettingsActionStrip(getCarContext(), getSurfaceRenderer()));
|
||||
builder.setItemList(createCategoriesList());
|
||||
return builder.build();
|
||||
}
|
||||
|
|
|
@ -3,44 +3,23 @@ package app.organicmaps.car.screens;
|
|||
import androidx.annotation.NonNull;
|
||||
import androidx.car.app.CarContext;
|
||||
import androidx.car.app.Screen;
|
||||
import androidx.car.app.model.ActionStrip;
|
||||
import androidx.car.app.navigation.model.MapController;
|
||||
|
||||
import app.organicmaps.car.OMController;
|
||||
import app.organicmaps.car.SurfaceRenderer;
|
||||
|
||||
public abstract class MapScreen extends Screen
|
||||
{
|
||||
@NonNull
|
||||
private final OMController mMapController;
|
||||
private final SurfaceRenderer mSurfaceRenderer;
|
||||
|
||||
public MapScreen(@NonNull CarContext carContext, @NonNull OMController mapController)
|
||||
public MapScreen(@NonNull CarContext carContext, @NonNull SurfaceRenderer surfaceRenderer)
|
||||
{
|
||||
super(carContext);
|
||||
mMapController = mapController;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public OMController getOMController()
|
||||
{
|
||||
return mMapController;
|
||||
mSurfaceRenderer = surfaceRenderer;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public SurfaceRenderer getSurfaceRenderer()
|
||||
{
|
||||
return mMapController.getSurfaceRenderer();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public MapController getMapController()
|
||||
{
|
||||
return mMapController.getMapController();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public ActionStrip getActionStrip()
|
||||
{
|
||||
return mMapController.getActionStrip();
|
||||
return mSurfaceRenderer;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,13 +13,14 @@ import androidx.car.app.navigation.model.MapTemplate;
|
|||
import androidx.core.graphics.drawable.IconCompat;
|
||||
|
||||
import app.organicmaps.R;
|
||||
import app.organicmaps.car.OMController;
|
||||
import app.organicmaps.car.SurfaceRenderer;
|
||||
import app.organicmaps.car.UiHelpers;
|
||||
|
||||
public class NavigationScreen extends MapScreen
|
||||
{
|
||||
public NavigationScreen(@NonNull CarContext carContext, @NonNull OMController mapController)
|
||||
public NavigationScreen(@NonNull CarContext carContext, @NonNull SurfaceRenderer surfaceRenderer)
|
||||
{
|
||||
super(carContext, mapController);
|
||||
super(carContext, surfaceRenderer);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
|
@ -28,8 +29,8 @@ public class NavigationScreen extends MapScreen
|
|||
{
|
||||
MapTemplate.Builder builder = new MapTemplate.Builder();
|
||||
builder.setHeader(createHeader());
|
||||
builder.setMapController(getMapController());
|
||||
builder.setActionStrip(getActionStrip());
|
||||
builder.setMapController(UiHelpers.createMapController(getCarContext(), getSurfaceRenderer()));
|
||||
builder.setActionStrip(UiHelpers.createSettingsActionStrip(getCarContext(), getSurfaceRenderer()));
|
||||
builder.setItemList(createList());
|
||||
return builder.build();
|
||||
}
|
||||
|
@ -93,11 +94,11 @@ public class NavigationScreen extends MapScreen
|
|||
|
||||
private void openCategories()
|
||||
{
|
||||
getScreenManager().push(new CategoriesScreen(getCarContext(), getOMController()));
|
||||
getScreenManager().push(new CategoriesScreen(getCarContext(), getSurfaceRenderer()));
|
||||
}
|
||||
|
||||
private void openBookmarks()
|
||||
{
|
||||
getScreenManager().push(new BookmarksScreen(getCarContext(), getOMController()));
|
||||
getScreenManager().push(new BookmarksScreen(getCarContext(), getSurfaceRenderer()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,24 +1,36 @@
|
|||
package app.organicmaps.car.screens.settings;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.StringRes;
|
||||
import androidx.car.app.CarContext;
|
||||
import androidx.car.app.model.Action;
|
||||
import androidx.car.app.model.CarIcon;
|
||||
import androidx.car.app.model.Header;
|
||||
import androidx.car.app.model.ItemList;
|
||||
import androidx.car.app.model.Row;
|
||||
import androidx.car.app.model.Template;
|
||||
import androidx.car.app.navigation.model.MapTemplate;
|
||||
import androidx.core.graphics.drawable.IconCompat;
|
||||
|
||||
import app.organicmaps.R;
|
||||
import app.organicmaps.car.OMController;
|
||||
import app.organicmaps.car.SurfaceRenderer;
|
||||
import app.organicmaps.car.UiHelpers;
|
||||
import app.organicmaps.car.screens.MapScreen;
|
||||
import app.organicmaps.routing.RoutingOptions;
|
||||
import app.organicmaps.settings.RoadType;
|
||||
|
||||
public class DrivingOptionsScreen extends MapScreen
|
||||
{
|
||||
public DrivingOptionsScreen(@NonNull CarContext carContext, @NonNull OMController mapController)
|
||||
@NonNull
|
||||
private final CarIcon mCheckboxIcon;
|
||||
@NonNull
|
||||
private final CarIcon mCheckboxSelectedIcon;
|
||||
|
||||
public DrivingOptionsScreen(@NonNull CarContext carContext, @NonNull SurfaceRenderer surfaceRenderer)
|
||||
{
|
||||
super(carContext, mapController);
|
||||
super(carContext, surfaceRenderer);
|
||||
mCheckboxIcon = new CarIcon.Builder(IconCompat.createWithResource(carContext, R.drawable.ic_check_box)).build();
|
||||
mCheckboxSelectedIcon = new CarIcon.Builder(IconCompat.createWithResource(carContext, R.drawable.ic_check_box_checked)).build();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
|
@ -27,7 +39,7 @@ public class DrivingOptionsScreen extends MapScreen
|
|||
{
|
||||
MapTemplate.Builder builder = new MapTemplate.Builder();
|
||||
builder.setHeader(createHeader());
|
||||
builder.setMapController(getMapController());
|
||||
builder.setMapController(UiHelpers.createMapController(getCarContext(), getSurfaceRenderer()));
|
||||
builder.setItemList(createDrivingOptionsList());
|
||||
return builder.build();
|
||||
}
|
||||
|
@ -45,10 +57,26 @@ public class DrivingOptionsScreen extends MapScreen
|
|||
private ItemList createDrivingOptionsList()
|
||||
{
|
||||
ItemList.Builder builder = new ItemList.Builder();
|
||||
builder.addItem(UiHelpers.createDrivingOptionCheckbox(getCarContext(), RoadType.Toll, R.string.avoid_tolls));
|
||||
builder.addItem(UiHelpers.createDrivingOptionCheckbox(getCarContext(), RoadType.Dirty, R.string.avoid_unpaved));
|
||||
builder.addItem(UiHelpers.createDrivingOptionCheckbox(getCarContext(), RoadType.Ferry, R.string.avoid_ferry));
|
||||
builder.addItem(UiHelpers.createDrivingOptionCheckbox(getCarContext(), RoadType.Motorway, R.string.avoid_motorways));
|
||||
builder.addItem(createDrivingOptionCheckbox(RoadType.Toll, R.string.avoid_tolls));
|
||||
builder.addItem(createDrivingOptionCheckbox(RoadType.Dirty, R.string.avoid_unpaved));
|
||||
builder.addItem(createDrivingOptionCheckbox(RoadType.Ferry, R.string.avoid_ferry));
|
||||
builder.addItem(createDrivingOptionCheckbox(RoadType.Motorway, R.string.avoid_motorways));
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private Row createDrivingOptionCheckbox(RoadType roadType, @StringRes int titleRes)
|
||||
{
|
||||
Row.Builder builder = new Row.Builder();
|
||||
builder.setTitle(getCarContext().getString(titleRes));
|
||||
builder.setOnClickListener(() -> {
|
||||
if (RoutingOptions.hasOption(roadType))
|
||||
RoutingOptions.removeOption(roadType);
|
||||
else
|
||||
RoutingOptions.addOption(roadType);
|
||||
DrivingOptionsScreen.this.invalidate();
|
||||
});
|
||||
builder.setImage(RoutingOptions.hasOption(roadType) ? mCheckboxSelectedIcon : mCheckboxIcon);
|
||||
return builder.build();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,15 +13,16 @@ import androidx.car.app.navigation.model.MapTemplate;
|
|||
import app.organicmaps.BuildConfig;
|
||||
import app.organicmaps.Framework;
|
||||
import app.organicmaps.R;
|
||||
import app.organicmaps.car.OMController;
|
||||
import app.organicmaps.car.SurfaceRenderer;
|
||||
import app.organicmaps.car.UiHelpers;
|
||||
import app.organicmaps.car.screens.MapScreen;
|
||||
import app.organicmaps.util.DateUtils;
|
||||
|
||||
public class HelpScreen extends MapScreen
|
||||
{
|
||||
public HelpScreen(@NonNull CarContext carContext, @NonNull OMController mapController)
|
||||
public HelpScreen(@NonNull CarContext carContext, @NonNull SurfaceRenderer surfaceRenderer)
|
||||
{
|
||||
super(carContext, mapController);
|
||||
super(carContext, surfaceRenderer);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
|
@ -30,7 +31,7 @@ public class HelpScreen extends MapScreen
|
|||
{
|
||||
MapTemplate.Builder builder = new MapTemplate.Builder();
|
||||
builder.setHeader(createHeader());
|
||||
builder.setMapController(getMapController());
|
||||
builder.setMapController(UiHelpers.createMapController(getCarContext(), getSurfaceRenderer()));
|
||||
builder.setItemList(createSettingsList());
|
||||
return builder.build();
|
||||
}
|
||||
|
|
|
@ -1,27 +1,46 @@
|
|||
package app.organicmaps.car.screens.settings;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.StringRes;
|
||||
import androidx.car.app.CarContext;
|
||||
import androidx.car.app.model.Action;
|
||||
import androidx.car.app.model.CarIcon;
|
||||
import androidx.car.app.model.Header;
|
||||
import androidx.car.app.model.Item;
|
||||
import androidx.car.app.model.ItemList;
|
||||
import androidx.car.app.model.Row;
|
||||
import androidx.car.app.model.Template;
|
||||
import androidx.car.app.navigation.model.MapTemplate;
|
||||
import androidx.core.graphics.drawable.IconCompat;
|
||||
|
||||
import app.organicmaps.R;
|
||||
import app.organicmaps.car.OMController;
|
||||
import app.organicmaps.car.SurfaceRenderer;
|
||||
import app.organicmaps.car.UiHelpers;
|
||||
import app.organicmaps.car.screens.MapScreen;
|
||||
import app.organicmaps.util.Config;
|
||||
|
||||
public class SettingsScreen extends MapScreen
|
||||
{
|
||||
|
||||
public SettingsScreen(@NonNull CarContext carContext, @NonNull OMController mapController)
|
||||
private interface PrefsGetter
|
||||
{
|
||||
super(carContext, mapController);
|
||||
boolean get();
|
||||
}
|
||||
|
||||
private interface PrefsSetter
|
||||
{
|
||||
void set(boolean newValue);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private final CarIcon mCheckboxIcon;
|
||||
@NonNull
|
||||
private final CarIcon mCheckboxSelectedIcon;
|
||||
|
||||
public SettingsScreen(@NonNull CarContext carContext, @NonNull SurfaceRenderer surfaceRenderer)
|
||||
{
|
||||
super(carContext, surfaceRenderer);
|
||||
mCheckboxIcon = new CarIcon.Builder(IconCompat.createWithResource(carContext, R.drawable.ic_check_box)).build();
|
||||
mCheckboxSelectedIcon = new CarIcon.Builder(IconCompat.createWithResource(carContext, R.drawable.ic_check_box_checked)).build();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
|
@ -30,7 +49,7 @@ public class SettingsScreen extends MapScreen
|
|||
{
|
||||
MapTemplate.Builder builder = new MapTemplate.Builder();
|
||||
builder.setHeader(createHeader());
|
||||
builder.setMapController(getMapController());
|
||||
builder.setMapController(UiHelpers.createMapController(getCarContext(), getSurfaceRenderer()));
|
||||
builder.setItemList(createSettingsList());
|
||||
return builder.build();
|
||||
}
|
||||
|
@ -49,8 +68,8 @@ public class SettingsScreen extends MapScreen
|
|||
{
|
||||
ItemList.Builder builder = new ItemList.Builder();
|
||||
builder.addItem(createRoutingOptionsItem());
|
||||
builder.addItem(UiHelpers.createSharedPrefsCheckbox(getCarContext(), R.string.big_font, Config::isLargeFontsSize, Config::setLargeFontsSize));
|
||||
builder.addItem(UiHelpers.createSharedPrefsCheckbox(getCarContext(), R.string.transliteration_title, Config::isTransliteration, Config::setTransliteration));
|
||||
builder.addItem(createSharedPrefsCheckbox(R.string.big_font, Config::isLargeFontsSize, Config::setLargeFontsSize));
|
||||
builder.addItem(createSharedPrefsCheckbox(R.string.transliteration_title, Config::isTransliteration, Config::setTransliteration));
|
||||
builder.addItem(createHelpItem());
|
||||
return builder.build();
|
||||
}
|
||||
|
@ -60,7 +79,7 @@ public class SettingsScreen extends MapScreen
|
|||
{
|
||||
Row.Builder builder = new Row.Builder();
|
||||
builder.setTitle(getCarContext().getString(R.string.driving_options_title));
|
||||
builder.setOnClickListener(() -> getScreenManager().push(new DrivingOptionsScreen(getCarContext(), getOMController())));
|
||||
builder.setOnClickListener(() -> getScreenManager().push(new DrivingOptionsScreen(getCarContext(), getSurfaceRenderer())));
|
||||
builder.setBrowsable(true);
|
||||
return builder.build();
|
||||
}
|
||||
|
@ -70,8 +89,23 @@ public class SettingsScreen extends MapScreen
|
|||
{
|
||||
Row.Builder builder = new Row.Builder();
|
||||
builder.setTitle(getCarContext().getString(R.string.help));
|
||||
builder.setOnClickListener(() -> getScreenManager().push(new HelpScreen(getCarContext(), getOMController())));
|
||||
builder.setOnClickListener(() -> getScreenManager().push(new HelpScreen(getCarContext(), getSurfaceRenderer())));
|
||||
builder.setBrowsable(true);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private Row createSharedPrefsCheckbox(@StringRes int titleRes, PrefsGetter getter, PrefsSetter setter)
|
||||
{
|
||||
final boolean getterValue = getter.get();
|
||||
|
||||
Row.Builder builder = new Row.Builder();
|
||||
builder.setTitle(getCarContext().getString(titleRes));
|
||||
builder.setOnClickListener(() -> {
|
||||
setter.set(!getterValue);
|
||||
SettingsScreen.this.invalidate();
|
||||
});
|
||||
builder.setImage(getterValue ? mCheckboxSelectedIcon : mCheckboxIcon);
|
||||
return builder.build();
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue