Compare commits

..

3 Commits

Author SHA1 Message Date
x7z4w
abe97b2ce0 [fdroid] Release version 2025.10.08-3
Signed-off-by: x7z4w <x7z4w@noreply.codeberg.org>
2025-10-09 11:10:18 +00:00
eisa01
2e91e64056 [android] Fix Metadata IntRange
Discovered while debugging issue #2078

Signed-off-by: eisa01 <eisa01@gmail.com>
2025-10-09 11:10:18 +00:00
Jean-Baptiste
d1bac84c7a [android] Fix crash on the place page
Signed-off-by: Jean-Baptiste <jeanbaptiste.charron@outlook.fr>
2025-10-09 11:10:18 +00:00
611 changed files with 4273 additions and 15628 deletions

View File

@@ -1,9 +0,0 @@
• Vylepšena viditelnost a uživatelské rozhraní pokynů v navigaci
• Přidána možnost vynechat kroky
• Vylepšeno vyhledávání ve více jazycích
• Přidána specifická ikona pro autobusové zastávky
• Opraveny problémy s Android Auto (prostřednictvím projektu OM)
• Vylepšen editor a opraveny drobné problémy
• Vylepšeny styly map (prostřednictvím projektu OM)
• Vylepšeny překlady aplikace
Další změny najdete v našich poznámkách k vydání Codeberg!

View File

@@ -1,9 +1,10 @@
Verbesserte Sichtbarkeit & Benutzeroberfläche für Navigationsanweisungen
Option um Treppen zu vermeiden
Verbesserte Suche in mehreren Sprachen
Spezifisches Symbol für Busbahnöfe hinzugefügt
Probleme mit Android Auto behoben (via OM)
Verbesserter Editor mit kleinere Bugfixes
Kartenstile verbessert (via OM)
Verbesserte Übersetzungen
Für weitere Änderungen siehe Codeberg-Versionshinweise
Karten-Daten vom 6. September
Zeitstrafen für Radrouting
Farbige POI-Beschriftungen in Autonavigation
POI-Suche nach Filialnamen
Abspannportale, Sicherheitskabinen & Büros hinzugefügt
Aktualisierte Symbole für Türme, Nachtclubs, Apotheken und Fahnenmasten
Lesezeichen-Farbe in GPX-Exporten
Farbfüllung von Fußgängerbereiche auf Plätzen
• Android Auto: Anzeige Ausfahrtsnummern in Kreisverkehren
Weitere Änderungen in Codeberg-Versionshinweisen!

View File

@@ -1,9 +1,10 @@
Improved visibility and UI of instructions in navigation
Added option to avoid steps
Improved search in multiple languages
Added specific icon for bus stations
Fixed Android Auto issues (via OM project)
Improved editor and fix minor issues
Improved map styles (via OM project)
Improved app translations
OpenStreetMap data as of September 6
Turn penalties for bicycle routing
Colored POI labels for car navigation map style
Search POIs by branch name
Added power portals, security booths and offices
Update icons for towers, nightclubs, chemists, flagpoles
Save bookmark color to GPX exports
Color fill pedestrian parts of squares
• Android Auto: display roundabout exit numbers
Check our Codeberg release notes for more changes!

View File

@@ -1,8 +1,10 @@
Mejora de la visibilidad y la interfaz de usuario de las instrucciones de navegación
Se ha añadido la opción de evitar escaleras
Mejora de la búsqueda en varios idiomas como ES
Se ha añadido un icono específico para las estaciones de autobús
Se han solucionado los problemas de Android Auto (a través del proyecto OM)
Se ha mejorado el editor y se han solucionado pequeños problemas
Se han mejorado los estilos de los mapas (a través del proyecto OM)
Datos a 6 de septiembre
Penalizaciones de giros en rutas de bici
Etiquetas de puntos de interés en color en navegación
Buscar por nombre de sucursal
Añadir portales de energía, cabinas de seguridad y oficinas
Nuevos iconos: torres, discotecas, parafarmacias y mástiles
Guardar color en exportaciones GPX
• Colorear áreas peatonales de plazas
• Android Auto: mostrar números de salida de rotondas
Más detalles en Codeberg

View File

@@ -1,9 +1,9 @@
Interface utilisateur et visibilité des instructions en navigation améliorée
Option pour éviter les escaliers ajoutée
Recherche améliorée dans différents languages
Icône pour les gares routières ajoutée
Corrections de bugs liées à Android Auto (via OM)
Editeur amélioré et corrections de bugs
Style de la carte amélioré (via OM)
Traductions améliorées
Données OSM du 06 septembre
Pénalités dans les calculs d'itinéraires vélos
Ajout de labels colorés en mode navigation
Support du tag branch dans la recherche
Ajout des portiques électriques, postes de sécurité
Mise à jour des icônes de tours, boîtes de nuits, chimiste et mat
Enregistrement de la couleur des signets dans les exports GPX
Android Auto: Affichage du numéro de sortie des ronds-points
Plus d'informations sur notre Codeberg

View File

@@ -1,32 +0,0 @@
Aplikasi peta gratis & sumber terbuka yang dipimpin komunitas, berbasis data OpenStreetMap dan diperkuat dengan komitmen terhadap transparansi, privasi, serta non-profit. CoMaps adalah turunan dari Organic Maps, yang merupakan turunan dari Maps.ME.
Baca lebih lanjut tentang alasan proyek ini dan arahnya di <b><i>codeberg.org/comaps</i></b>.
Bergabunglah dengan komunitas dan bantu menjadikan aplikasi peta terbaik
• Gunakan aplikasi ini dan sebarkan
• Beri masukan dan laporkan masalah
• Perbarui data peta di aplikasi atau di situs OpenStreetMap
‣ <b>Fokus Offline</b>: Rencanakan dan navigasikan perjalananmu di luar negeri tanpa perlu layanan seluler, cari titik saat hiking jauh, dll. Semua fungsi aplikasi dirancang untuk bekerja offline.
‣ <b>Menghormati Privasi</b>: Aplikasi ini dirancang dengan privasi sebagai prioritas tidak mengidentifikasi orang, tidak melacak, dan tidak mengumpulkan informasi pribadi. Bebas iklan.
‣ <b>Sederhana dan Rapi</b>: fitur penting yang mudah digunakan dan langsung berfungsi.
‣ <b>Hemat Baterai dan Ruang</b>: Tidak menguras baterai seperti aplikasi navigasi lain. Peta ringkas menghemat ruang berharga di ponselmu.
‣ <b>Gratis dan Dibangun oleh Komunitas</b>: Orang seperti kamu membantu membangun aplikasi ini dengan menambahkan tempat ke OpenStreetMap, menguji serta memberi masukan fitur, dan menyumbangkan keterampilan pengembangan maupun dana.
‣ <b>Terbuka dan Transparan</b>: Pengambilan keputusan dan keuangan transparan, non-profit, dan sepenuhnya sumber terbuka.
<b>Fitur Utama</b>:
• Peta detail yang bisa diunduh, dengan tempat yang tidak ada di Google Maps
• Mode outdoor dengan sorotan jalur hiking, area berkemah, sumber air, puncak, garis kontur, dll
• Jalur pejalan kaki dan jalur sepeda
• Titik menarik seperti restoran, SPBU, hotel, toko, tempat wisata, dan banyak lagi
• Pencarian berdasarkan nama, alamat, atau kategori titik menarik
• Navigasi dengan suara untuk berjalan, bersepeda, atau berkendara
• Tandai tempat favoritmu dengan sekali tap
• Artikel Wikipedia offline
• Layer dan rute transportasi subway
• Rekaman jejak
• Ekspor dan impor bookmark serta jejak dalam format KML, KMZ, GPX
• Mode gelap untuk digunakan saat malam
• Tingkatkan data peta untuk semua orang dengan editor bawaan sederhana
<b>Kebebasan Ada di Sini</b>
Temukan perjalananmu, jelajahi dunia dengan privasi dan komunitas di garis depan!

View File

@@ -1 +0,0 @@
Navigasi peta mudah Temukan lebih banyak Didukung oleh komunitas

View File

@@ -0,0 +1,10 @@
• OpenStreetMap aggiornato al 6 Settembre
• Bici: miglior stima del tempo di percorrenza
• Auto: punti d'interesse colorati
• Cerca i punti d'interesse tramite filiale
• Aggiunte strutture alta tensione, cabine di sicurezza e uffici
• Aggiornate le icone per torri, discoteche, farmacie e aste per bandiere
• Salva il colore dei Preferiti nel GPX
• Evidenziate le aree pedonali nelle piazze
• AndroidAuto: aggiunto il numero dell'uscita nelle rotonde
Visita Codeberg per ulteriori dettagli

View File

@@ -1 +1 @@
Enkel kartnavigering - Opplev mere på din reise - Drevet av felleskapet
Lett kart navigasjon - Opplev mere på din reise - Drevet av felleskapet

View File

@@ -1 +1 @@
CoMaps - Gå, sykle, kjøre offline med personvern
CoMaps - Gå tur, sykkel, kjør - med personvern

View File

@@ -1 +1 @@
Łatwa nawigacja po mapie - Odkryj więcej z podróży - Wspierane przez społeczność
Łatwa nawigacja Odkryj więcej ze swojej podróży Wspierane przez społeczność

View File

@@ -1,9 +1,10 @@
Visibilidade e interface do usuário aprimoradas para instruções na navegação
Opção adicionada para evitar degraus
Busca aprimorada em vários idiomas
Adição de ícone específico para rodoviárias
Problemas corrigidos no Android Auto (via projeto OM)
Editor aprimorado e correção de problemas menores
Estilos de mapa aprimorados (via projeto OM)
Traduções aprimoradas
Confira nossas notas de lançamento do Codeberg para mais mudanças!
Dados OSM de 6/09
Penalidades de conversão para bicicleta
Etiquetas de POI coloridas para o estilo do mapa de navegação de carros
Busca de POIs por nome de filial
Adição de portais de energia, guaritas e escritórios
Atualização de ícones para torres, discotecas, farmácias e mastros
Salva a cor dos favoritos nas exportações GPX
Preenchimento de praças pavimentadas
• Android Auto: exibe números de saída de rotatória
Confira nossas notas de lançamento do Codeberg para mais mudanças

View File

@@ -1,9 +1,10 @@
Лучшая видимость и интерфейс при навигации
Добавлена возможность пропускать шаги
Улучшен поиск на нескольких языках
Новый значок автостанций
Исправлены проблемы с Android Auto (через OM)
Улучшен редактор и исправлены мелкие недочёты
Улучшены стили карт (через OM)
Улучшены переводы приложения
Ознакомьтесь с примечаниями к выпуску Codeberg, чтобы узнать изменениях!
Данные на 6 сентября
Предупреждения на веломаршруте
Цветные метки POI при автонавигации
Поиск POI по названию ветки
Добавлены высоковольтные опоры, помещения охраны и офисы
Обновлены значки башен,вышек,мачт,ночных клубов,аптек
Сохранение цвета закладок при экспорте в GPX (через OM)
Отображение цветом пешеходных зон
• Android Auto: отображение номеров съездов на кольцевых развязках
Посмотрите примечания к выпуску Codeberg, чтобы узнать о других изменениях!

View File

@@ -1 +1 @@
version: 2025.03.02-7-FDroid+25030207
version: 2025.10.08-3-FDroid+25100803

View File

@@ -1 +0,0 @@
Navigasi peta mudah Temukan lebih banyak Didukung oleh komunitas

View File

@@ -1 +0,0 @@
CoMaps - Jelajah dengan Privat

View File

@@ -1 +0,0 @@
Enkel kartnavigering - Opplev mere på din reise - Drevet av felleskapet

View File

@@ -1 +0,0 @@
CoMaps -Naviger med personvern

View File

@@ -1 +0,0 @@
Łatwa nawigacja po mapie - Odkryj więcej z podróży - Wspierane przez społeczność

View File

@@ -89,7 +89,6 @@
<!-- Allows for config and orientation change without killing/restarting main activity -->
<activity
android:name="app.organicmaps.SplashActivity"
android:theme="@style/MwmTheme.Splash"
android:configChanges="orientation|screenSize|smallestScreenSize|density|screenLayout|uiMode|keyboard|keyboardHidden|navigation"
android:screenOrientation="fullUser"
android:exported="true">
@@ -350,7 +349,6 @@
<activity
android:name="app.organicmaps.DownloadResourcesLegacyActivity"
android:theme="@style/MwmTheme.DownloadResourcesLegacy"
android:configChanges="orientation|screenLayout|screenSize"
android:screenOrientation="fullUser"/>
@@ -367,7 +365,6 @@
<activity
android:name="app.organicmaps.MwmActivity"
android:theme="@style/MwmTheme.MainActivity"
android:launchMode="singleTask"
android:configChanges="uiMode"
android:screenOrientation="fullUser"
@@ -389,7 +386,6 @@
<activity
android:name="app.organicmaps.search.SearchActivity"
android:theme="@style/MwmTheme.CardBg"
android:configChanges="orientation|screenLayout|screenSize"
android:screenOrientation="fullUser"
android:label="@string/search_map"
@@ -416,7 +412,6 @@
<activity
android:name="app.organicmaps.bookmarks.BookmarkCategoriesActivity"
android:theme="@style/MwmTheme.WindowBg"
android:configChanges="orientation|screenLayout|screenSize"
android:screenOrientation="fullUser"
android:label="@string/bookmarks_and_tracks"
@@ -425,7 +420,6 @@
<activity
android:name="app.organicmaps.bookmarks.BookmarkListActivity"
android:theme="@style/MwmTheme.CardBg"
android:configChanges="orientation|screenLayout|screenSize"
android:screenOrientation="fullUser"
android:label="@string/bookmarks"
@@ -500,13 +494,6 @@
android:stopWithTask="false"
/>
<service android:name=".location.LocationSharingService"
android:foregroundServiceType="location"
android:exported="false"
android:enabled="true"
android:stopWithTask="false"
/>
<service
android:name=".downloader.DownloaderService"
android:foregroundServiceType="dataSync"

View File

@@ -24,6 +24,7 @@ import androidx.annotation.CallSuper;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
import androidx.annotation.StyleRes;
import androidx.core.view.ViewCompat;
import app.organicmaps.base.BaseMwmFragmentActivity;
import app.organicmaps.downloader.MapManagerHelper;
@@ -437,4 +438,11 @@ public class DownloadResourcesLegacyActivity extends BaseMwmFragmentActivity
.setOnDismissListener(dialog -> mAlertDialog = null)
.show();
}
@Override
@StyleRes
public int getThemeResourceId(@NonNull String theme)
{
return R.style.MwmTheme_DownloadResourcesLegacy;
}
}

View File

@@ -0,0 +1,210 @@
package app.organicmaps;
import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.res.ConfigurationHelper;
import app.organicmaps.base.BaseMwmFragment;
import app.organicmaps.sdk.Map;
import app.organicmaps.sdk.MapRenderingListener;
import app.organicmaps.sdk.display.DisplayType;
import app.organicmaps.sdk.util.log.Logger;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
public class MapFragment extends BaseMwmFragment implements View.OnTouchListener, SurfaceHolder.Callback
{
private static final String TAG = MapFragment.class.getSimpleName();
@NonNull
private final Map mMap = new Map(DisplayType.Device);
public void updateCompassOffset(int offsetX, int offsetY)
{
mMap.updateCompassOffset(requireContext(), offsetX, offsetY, true);
}
public void updateBottomWidgetsOffset(int offsetX, int offsetY)
{
mMap.updateBottomWidgetsOffset(requireContext(), offsetX, offsetY);
}
public void updateMyPositionRoutingOffset(int offsetY)
{
mMap.updateMyPositionRoutingOffset(offsetY);
}
public void destroySurface(boolean activityIsChangingConfigurations)
{
mMap.onSurfaceDestroyed(activityIsChangingConfigurations, isAdded());
}
public boolean isContextCreated()
{
return mMap.isContextCreated();
}
@Override
public void surfaceCreated(@NonNull SurfaceHolder surfaceHolder)
{
Logger.d(TAG);
int densityDpi;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R)
densityDpi = ConfigurationHelper.getDensityDpi(requireContext().getResources());
else
densityDpi = getDensityDpiOld();
mMap.onSurfaceCreated(requireContext(), surfaceHolder.getSurface(), surfaceHolder.getSurfaceFrame(), densityDpi);
}
@Override
public void surfaceChanged(SurfaceHolder surfaceHolder, int format, int width, int height)
{
Logger.d(TAG);
mMap.onSurfaceChanged(requireContext(), surfaceHolder.getSurface(), surfaceHolder.getSurfaceFrame(),
surfaceHolder.isCreating());
}
@Override
public void surfaceDestroyed(@NonNull SurfaceHolder surfaceHolder)
{
Logger.d(TAG);
mMap.onSurfaceDestroyed(requireActivity().isChangingConfigurations(), true);
}
@Override
public void onAttach(Context context)
{
Logger.d(TAG);
super.onAttach(context);
mMap.setLocationHelper(MwmApplication.from(requireContext()).getLocationHelper());
mMap.setMapRenderingListener((MapRenderingListener) context);
mMap.setCallbackUnsupported(this::reportUnsupported);
}
@Override
public void onDetach()
{
Logger.d(TAG);
super.onDetach();
mMap.setMapRenderingListener(null);
mMap.setCallbackUnsupported(null);
}
@Override
public void onCreate(Bundle b)
{
Logger.d(TAG);
super.onCreate(b);
setRetainInstance(true);
boolean launchByDeepLink = false;
Bundle args = getArguments();
if (args != null)
launchByDeepLink = args.getBoolean(Map.ARG_LAUNCH_BY_DEEP_LINK);
mMap.onCreate(launchByDeepLink);
}
@Override
public void onStart()
{
Logger.d(TAG);
super.onStart();
mMap.onStart();
}
@Override
public void onStop()
{
Logger.d(TAG);
super.onStop();
mMap.onStop();
}
@Override
public void onPause()
{
Logger.d(TAG);
super.onPause();
mMap.onPause(requireContext());
}
@Override
public void onResume()
{
Logger.d(TAG);
super.onResume();
mMap.onResume();
}
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)
{
Logger.d(TAG);
final View view = inflater.inflate(R.layout.fragment_map, container, false);
final SurfaceView mSurfaceView = view.findViewById(R.id.map_surfaceview);
mSurfaceView.getHolder().addCallback(this);
return view;
}
@Override
public boolean onTouch(View view, MotionEvent event)
{
int action = event.getActionMasked();
int pointerIndex = event.getActionIndex();
switch (action)
{
case MotionEvent.ACTION_POINTER_UP -> action = Map.NATIVE_ACTION_UP;
case MotionEvent.ACTION_UP ->
{
action = Map.NATIVE_ACTION_UP;
pointerIndex = 0;
}
case MotionEvent.ACTION_POINTER_DOWN -> action = Map.NATIVE_ACTION_DOWN;
case MotionEvent.ACTION_DOWN ->
{
action = Map.NATIVE_ACTION_DOWN;
pointerIndex = 0;
}
case MotionEvent.ACTION_MOVE ->
{
action = Map.NATIVE_ACTION_MOVE;
pointerIndex = Map.INVALID_POINTER_MASK;
}
case MotionEvent.ACTION_CANCEL -> action = Map.NATIVE_ACTION_CANCEL;
}
Map.onTouch(action, event, pointerIndex);
return true;
}
public void notifyOnSurfaceDestroyed(@NonNull Runnable task)
{
mMap.onSurfaceDestroyed(false, true);
task.run();
}
private void reportUnsupported()
{
new MaterialAlertDialogBuilder(requireContext(), R.style.MwmTheme_AlertDialog)
.setMessage(R.string.unsupported_phone)
.setCancelable(false)
.setPositiveButton(R.string.close, (dlg, which) -> requireActivity().moveTaskToBack(true))
.show();
}
private int getDensityDpiOld()
{
final DisplayMetrics metrics = new DisplayMetrics();
requireActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics);
return metrics.densityDpi;
}
}

View File

@@ -42,6 +42,7 @@ import androidx.annotation.CallSuper;
import androidx.annotation.Keep;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.StyleRes;
import androidx.annotation.UiThread;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
@@ -84,7 +85,6 @@ import app.organicmaps.routing.RoutingPlanInplaceController;
import app.organicmaps.sdk.ChoosePositionMode;
import app.organicmaps.sdk.Framework;
import app.organicmaps.sdk.Map;
import app.organicmaps.sdk.MapController;
import app.organicmaps.sdk.MapRenderingListener;
import app.organicmaps.sdk.PlacePageActivationListener;
import app.organicmaps.sdk.Router;
@@ -138,10 +138,10 @@ import java.util.ArrayList;
import java.util.Objects;
public class MwmActivity extends BaseMwmFragmentActivity
implements PlacePageActivationListener, MapRenderingListener, RoutingController.Container, LocationListener,
SensorListener, LocationState.ModeChangeListener, RoutingPlanInplaceController.RoutingPlanListener,
RoutingBottomMenuListener, BookmarkManager.BookmarksLoadingListener,
FloatingSearchToolbarController.SearchToolbarListener,
implements PlacePageActivationListener, View.OnTouchListener, MapRenderingListener, RoutingController.Container,
LocationListener, SensorListener, LocationState.ModeChangeListener,
RoutingPlanInplaceController.RoutingPlanListener, RoutingBottomMenuListener,
BookmarkManager.BookmarksLoadingListener, FloatingSearchToolbarController.SearchToolbarListener,
MenuBottomSheetFragment.MenuBottomSheetInterfaceWithHeader,
PlacePageController.PlacePageRouteSettingsListener, MapButtonsController.MapButtonClickListener,
DisplayChangedListener
@@ -171,9 +171,8 @@ public class MwmActivity extends BaseMwmFragmentActivity
private static final String POWER_SAVE_DISCLAIMER_SHOWN = "POWER_SAVE_DISCLAIMER_SHOWN";
@SuppressWarnings("NotNullFieldNotInitialized")
@NonNull
private MapController mMapController;
@Nullable
private MapFragment mMapFragment;
private View mPointChooser;
private MaterialToolbar mPointChooserToolbar;
@@ -246,7 +245,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
ManageRouteBottomSheet mManageRouteBottomSheet;
private boolean mRemoveDisplayListener = true;
private static int mLastUiMode = Configuration.UI_MODE_TYPE_UNDEFINED;
private int mLastUiMode = Configuration.UI_MODE_TYPE_UNDEFINED;
public interface LeftAnimationTrackListener
{
@@ -426,32 +425,19 @@ public class MwmActivity extends BaseMwmFragmentActivity
private void shareMyLocation()
{
final Location loc = MwmApplication.from(this).getLocationHelper().getSavedLocation();
if (loc == null)
if (loc != null)
{
dismissLocationErrorDialog();
mLocationErrorDialog = new MaterialAlertDialogBuilder(MwmActivity.this, R.style.MwmTheme_AlertDialog)
.setMessage(R.string.unknown_current_position)
.setCancelable(true)
.setPositiveButton(R.string.ok, null)
.setOnDismissListener(dialog -> mLocationErrorDialog = null)
.show();
SharingUtils.shareLocation(this, loc);
return;
}
SharingUtils.shareLocation(this, loc);
}
public void onLocationSharingStateChanged(boolean isSharing)
{
mMapButtonsViewModel.setLocationSharingState(isSharing);
MapButtonsController mapButtonsController =
(MapButtonsController) getSupportFragmentManager().findFragmentById(R.id.map_buttons);
if (mapButtonsController != null)
mapButtonsController.updateMenuBadge();
// Update share location button color in navigation menu
if (mNavigationController != null)
mNavigationController.refreshShareLocationColor();
dismissLocationErrorDialog();
mLocationErrorDialog = new MaterialAlertDialogBuilder(MwmActivity.this, R.style.MwmTheme_AlertDialog)
.setMessage(R.string.unknown_current_position)
.setCancelable(true)
.setPositiveButton(R.string.ok, null)
.setOnDismissListener(dialog -> mLocationErrorDialog = null)
.show();
}
private void showDownloader(boolean openDownloaded)
@@ -469,12 +455,25 @@ public class MwmActivity extends BaseMwmFragmentActivity
}
}
@Override
@StyleRes
protected int getThemeResourceId(@NonNull String theme)
{
if (Config.UiTheme.isDefault(theme))
return R.style.MwmTheme_MainActivity;
if (Config.UiTheme.isNight(theme))
return R.style.MwmTheme_Night_MainActivity;
return super.getThemeResourceId(theme);
}
@Override
public void onDisplayChangedToCar(@NonNull Runnable onTaskFinishedCallback)
{
mRemoveDisplayListener = false;
startActivity(new Intent(this, MapPlaceholderActivity.class));
mMapController.setOnDestroyListener(onTaskFinishedCallback);
Objects.requireNonNull(mMapFragment).notifyOnSurfaceDestroyed(onTaskFinishedCallback);
finish();
}
@@ -483,15 +482,13 @@ public class MwmActivity extends BaseMwmFragmentActivity
{
super.onConfigurationChanged(newConfig);
final int newType = newConfig.uiMode & Configuration.UI_MODE_TYPE_MASK;
final int oldType = mLastUiMode & Configuration.UI_MODE_TYPE_MASK;
final int newUiMode = newConfig.uiMode & Configuration.UI_MODE_TYPE_MASK;
final boolean newUiModeIsCarConnected = newUiMode == Configuration.UI_MODE_TYPE_CAR;
final boolean newUiModeIsCarDisconnected =
mLastUiMode == Configuration.UI_MODE_TYPE_CAR && newUiMode == Configuration.UI_MODE_TYPE_NORMAL;
mLastUiMode = newUiMode;
mLastUiMode = newConfig.uiMode;
final boolean carModeChanged =
newType != oldType && (newType == Configuration.UI_MODE_TYPE_CAR || oldType == Configuration.UI_MODE_TYPE_CAR);
if (carModeChanged)
if (newUiModeIsCarConnected || newUiModeIsCarDisconnected)
return;
makeNavigationBarTransparentInLightMode();
@@ -553,7 +550,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
updateViewsInsets();
if (getIntent().getBooleanExtra(EXTRA_UPDATE_THEME, false))
ThemeSwitcher.INSTANCE.restart(mMapController.isRenderingActive());
ThemeSwitcher.INSTANCE.restart(isMapRendererActive());
/*
* onRenderingInitializationFinished() hook is not called when MwmActivity is recreated with the already
@@ -621,10 +618,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
private void initViews(boolean isLaunchByDeeplink)
{
mMapController = new MapController(findViewById(R.id.map), MwmApplication.from(this).getLocationHelper(), this,
this::reportUnsupported, isLaunchByDeeplink);
getLifecycle().addObserver(mMapController);
initMap(isLaunchByDeeplink);
initNavigationButtons();
if (!mIsTabletLayout)
@@ -738,7 +732,16 @@ public class MwmActivity extends BaseMwmFragmentActivity
private void showPositionChooser(ChoosePositionMode mode, boolean isBusiness, boolean applyPosition)
{
closeFloatingToolbarsAndPanels(false);
if (mMapFragment != null)
{
final View mapView = mMapFragment.getView();
if (mapView != null)
{
int width = mapView.getWidth();
int height = mapView.getHeight();
Framework.nativeSetVisibleRect(0, 0, width, height);
}
}
UiUtils.show(mPointChooser);
mMapButtonsViewModel.setButtonsHidden(true);
ChoosePositionMode.set(mode, isBusiness, applyPosition);
@@ -757,6 +760,29 @@ public class MwmActivity extends BaseMwmFragmentActivity
finish();
}
private void initMap(boolean isLaunchByDeepLink)
{
final FragmentManager manager = getSupportFragmentManager();
mMapFragment = (MapFragment) manager.findFragmentByTag(MapFragment.class.getName());
if (mMapFragment == null)
{
Bundle args = new Bundle();
args.putBoolean(Map.ARG_LAUNCH_BY_DEEP_LINK, isLaunchByDeepLink);
final FragmentFactory factory = manager.getFragmentFactory();
mMapFragment = (MapFragment) factory.instantiate(getClassLoader(), MapFragment.class.getName());
mMapFragment.setArguments(args);
manager.beginTransaction()
.replace(R.id.map_fragment_container, mMapFragment, MapFragment.class.getName())
.commit();
}
View container = findViewById(R.id.map_fragment_container);
if (container != null)
{
container.setOnTouchListener(this);
}
}
private void initNavigationButtons()
{
prepareNavigationButtons();
@@ -1185,7 +1211,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
{
setIntent(intent);
super.onNewIntent(intent);
if (mMapController.isRenderingActive())
if (isMapRendererActive())
processIntent();
if (intent.getAction() != null && intent.getAction().equals(TrackRecordingService.STOP_TRACK_RECORDING))
{
@@ -1195,12 +1221,17 @@ public class MwmActivity extends BaseMwmFragmentActivity
}
}
private boolean isMapRendererActive()
{
return mMapFragment != null && Map.isEngineCreated() && mMapFragment.isContextCreated();
}
@CallSuper
@Override
protected void onResume()
{
super.onResume();
ThemeSwitcher.INSTANCE.restart(mMapController.isRenderingActive());
ThemeSwitcher.INSTANCE.restart(isMapRendererActive());
refreshSearchToolbar();
setFullscreen(isFullscreen());
makeNavigationBarTransparentInLightMode();
@@ -1218,6 +1249,15 @@ public class MwmActivity extends BaseMwmFragmentActivity
MwmApplication.from(this).getSensorHelper().addListener(this);
}
@Override
public void recreate()
{
// Explicitly destroy surface before activity recreation.
if (mMapFragment != null)
mMapFragment.destroySurface(true);
super.recreate();
}
@Override
protected void onResumeFragments()
{
@@ -1419,6 +1459,12 @@ public class MwmActivity extends BaseMwmFragmentActivity
return super.onGenericMotionEvent(event);
}
@Override
public boolean onTouch(View view, MotionEvent event)
{
return mMapFragment != null && mMapFragment.onTouch(view, event);
}
public void customOnNavigateUp()
{
if (removeCurrentFragment(true))
@@ -1434,7 +1480,10 @@ public class MwmActivity extends BaseMwmFragmentActivity
void updateCompassOffset(int offsetY, int offsetX)
{
mMapController.updateCompassOffset(offsetX, offsetY);
if (mMapFragment == null || !mMapFragment.isAdded())
return;
mMapFragment.updateCompassOffset(offsetX, offsetY);
final double north = MwmApplication.from(this).getSensorHelper().getSavedNorth();
if (!Double.isNaN(north))
@@ -1453,6 +1502,9 @@ public class MwmActivity extends BaseMwmFragmentActivity
public void updateBottomWidgetsOffset(int offsetX)
{
if (mMapFragment == null || !mMapFragment.isAdded())
return;
int offsetY = mNavBarHeight;
final Float bottomButtonHeight = mMapButtonsViewModel.getBottomButtonsHeight().getValue();
if (bottomButtonHeight != null)
@@ -1467,8 +1519,8 @@ public class MwmActivity extends BaseMwmFragmentActivity
if (mDisplayManager.isDeviceDisplayUsed())
{
mMapController.updateBottomWidgetsOffset(offsetX, offsetY);
mMapController.updateMyPositionRoutingOffset(offsetY);
mMapFragment.updateBottomWidgetsOffset(offsetX, offsetY);
mMapFragment.updateMyPositionRoutingOffset(offsetY);
}
}
@@ -1686,7 +1738,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
public void onNavigationCancelled()
{
closeFloatingToolbarsAndPanels(true);
ThemeSwitcher.INSTANCE.restart(mMapController.isRenderingActive());
ThemeSwitcher.INSTANCE.restart(isMapRendererActive());
if (mRoutingPlanInplaceController == null)
return;
@@ -1696,20 +1748,13 @@ public class MwmActivity extends BaseMwmFragmentActivity
mMapButtonsViewModel.setLayoutMode(MapButtonsController.LayoutMode.regular);
refreshLightStatusBar();
Utils.keepScreenOn(Config.isKeepScreenOnEnabled(), getWindow());
// Stop location sharing when navigation ends
if (app.organicmaps.location.LocationSharingManager.getInstance().isSharing())
{
app.organicmaps.location.LocationSharingManager.getInstance().stopSharing();
onLocationSharingStateChanged(false);
}
}
@Override
public void onNavigationStarted()
{
closeFloatingToolbarsAndPanels(true);
ThemeSwitcher.INSTANCE.restart(mMapController.isRenderingActive());
ThemeSwitcher.INSTANCE.restart(isMapRendererActive());
mMapButtonsViewModel.setLayoutMode(MapButtonsController.LayoutMode.navigation);
refreshLightStatusBar();
@@ -1745,7 +1790,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
public void onResetToPlanningState()
{
closeFloatingToolbarsAndPanels(true);
ThemeSwitcher.INSTANCE.restart(mMapController.isRenderingActive());
ThemeSwitcher.INSTANCE.restart(isMapRendererActive());
NavigationService.stopService(this);
mMapButtonsViewModel.setSearchOption(null);
mMapButtonsViewModel.setLayoutMode(MapButtonsController.LayoutMode.planning);
@@ -2574,13 +2619,4 @@ public class MwmActivity extends BaseMwmFragmentActivity
window.setNavigationBarContrastEnforced(false);
}
}
private void reportUnsupported()
{
new MaterialAlertDialogBuilder(this, R.style.MwmTheme_AlertDialog)
.setMessage(R.string.unsupported_phone)
.setCancelable(false)
.setPositiveButton(R.string.close, (dlg, which) -> this.moveTaskToBack(true))
.show();
}
}

View File

@@ -56,6 +56,15 @@ public class SplashActivity extends AppCompatActivity
protected void onCreate(@Nullable Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
final String theme = Config.UiTheme.getCurrent();
if (Config.UiTheme.isDefault(theme))
setTheme(R.style.MwmTheme_Splash);
else if (Config.UiTheme.isNight(theme))
setTheme(R.style.MwmTheme_Night_Splash);
else
throw new IllegalArgumentException("Attempt to apply unsupported theme: " + theme);
UiThread.cancelDelayedTasks(mInitCoreDelayedTask);
setContentView(R.layout.activity_splash);

View File

@@ -1,200 +0,0 @@
package app.organicmaps.api;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import app.organicmaps.sdk.util.log.Logger;
import java.io.IOException;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
/**
* HTTP API client for location sharing server.
* Sends encrypted location updates to the server.
*/
public class LocationSharingApiClient
{
private static final String TAG = LocationSharingApiClient.class.getSimpleName();
private static final int CONNECT_TIMEOUT_MS = 10000;
private static final int READ_TIMEOUT_MS = 10000;
private final String mServerBaseUrl;
private final String mSessionId;
private final Executor mExecutor;
public interface Callback
{
void onSuccess();
void onFailure(@NonNull String error);
}
public LocationSharingApiClient(@NonNull String serverBaseUrl, @NonNull String sessionId)
{
mServerBaseUrl = serverBaseUrl.endsWith("/") ? serverBaseUrl : serverBaseUrl + "/";
mSessionId = sessionId;
mExecutor = Executors.newSingleThreadExecutor();
}
/**
* Create a new session on the server.
* @param callback Result callback
*/
public void createSession(@Nullable Callback callback)
{
mExecutor.execute(() -> {
try
{
String url = mServerBaseUrl + "api/v1/session";
String requestBody = "{\"sessionId\":\"" + mSessionId + "\"}";
int responseCode = postJson(url, requestBody);
if (responseCode >= 200 && responseCode < 300)
{
Logger.d(TAG, "Session created successfully: " + mSessionId);
if (callback != null)
callback.onSuccess();
}
else
{
String error = "Server returned error: " + responseCode;
Logger.w(TAG, error);
if (callback != null)
callback.onFailure(error);
}
}
catch (IOException e)
{
Logger.e(TAG, "Failed to create session", e);
if (callback != null)
callback.onFailure(e.getMessage());
}
});
}
/**
* Update location on the server with encrypted payload.
* @param encryptedPayloadJson Encrypted payload JSON (from native code)
* @param callback Result callback
*/
public void updateLocation(@NonNull String encryptedPayloadJson, @Nullable Callback callback)
{
mExecutor.execute(() -> {
try
{
String url = mServerBaseUrl + "api/v1/location/" + mSessionId;
int responseCode = postJson(url, encryptedPayloadJson);
if (responseCode >= 200 && responseCode < 300)
{
Logger.d(TAG, "Location updated successfully");
if (callback != null)
callback.onSuccess();
}
else
{
String error = "Server returned error: " + responseCode;
Logger.w(TAG, error);
if (callback != null)
callback.onFailure(error);
}
}
catch (IOException e)
{
Logger.e(TAG, "Failed to update location", e);
if (callback != null)
callback.onFailure(e.getMessage());
}
});
}
/**
* End the session on the server.
*/
public void endSession()
{
mExecutor.execute(() -> {
try
{
String url = mServerBaseUrl + "api/v1/session/" + mSessionId;
deleteRequest(url);
Logger.d(TAG, "Session ended: " + mSessionId);
}
catch (IOException e)
{
Logger.e(TAG, "Failed to end session", e);
}
});
}
/**
* Send a POST request with JSON body.
* @param urlString URL to send request to
* @param jsonBody JSON request body
* @return HTTP response code
* @throws IOException on network error
*/
private int postJson(@NonNull String urlString, @NonNull String jsonBody) throws IOException
{
URL url = new URL(urlString);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
try
{
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
connection.setRequestProperty("Accept", "application/json");
connection.setConnectTimeout(CONNECT_TIMEOUT_MS);
connection.setReadTimeout(READ_TIMEOUT_MS);
connection.setDoOutput(true);
// Write body
byte[] bodyBytes = jsonBody.getBytes(StandardCharsets.UTF_8);
connection.setFixedLengthStreamingMode(bodyBytes.length);
try (OutputStream os = connection.getOutputStream())
{
os.write(bodyBytes);
os.flush();
}
return connection.getResponseCode();
}
finally
{
connection.disconnect();
}
}
/**
* Send a DELETE request.
* @param urlString URL to send request to
* @return HTTP response code
* @throws IOException on network error
*/
private int deleteRequest(@NonNull String urlString) throws IOException
{
URL url = new URL(urlString);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
try
{
connection.setRequestMethod("DELETE");
connection.setConnectTimeout(CONNECT_TIMEOUT_MS);
connection.setReadTimeout(READ_TIMEOUT_MS);
return connection.getResponseCode();
}
finally
{
connection.disconnect();
}
}
}

View File

@@ -8,13 +8,14 @@ import androidx.annotation.Nullable;
import androidx.annotation.StyleRes;
import androidx.fragment.app.DialogFragment;
import app.organicmaps.R;
import app.organicmaps.util.ThemeUtils;
public class BaseMwmDialogFragment extends DialogFragment
{
@StyleRes
protected final int getFullscreenTheme()
{
return R.style.MwmTheme_DialogFragment_Fullscreen;
return ThemeUtils.isNightTheme() ? getFullscreenDarkTheme() : getFullscreenLightTheme();
}
protected int getStyle()
@@ -22,8 +23,7 @@ public class BaseMwmDialogFragment extends DialogFragment
return STYLE_NORMAL;
}
@StyleRes
protected int getCustomTheme()
protected @StyleRes int getCustomTheme()
{
return 0;
}
@@ -40,6 +40,18 @@ public class BaseMwmDialogFragment extends DialogFragment
setStyle(style, theme);
}
@StyleRes
protected int getFullscreenLightTheme()
{
return R.style.MwmTheme_DialogFragment_Fullscreen;
}
@StyleRes
protected int getFullscreenDarkTheme()
{
return R.style.MwmTheme_DialogFragment_Fullscreen_Night;
}
@NonNull
protected Application getAppContextOrThrow()
{

View File

@@ -11,6 +11,7 @@ import androidx.activity.SystemBarStyle;
import androidx.annotation.CallSuper;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.StyleRes;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentFactory;
@@ -19,6 +20,7 @@ import app.organicmaps.MwmApplication;
import app.organicmaps.R;
import app.organicmaps.SplashActivity;
import app.organicmaps.sdk.util.Config;
import app.organicmaps.sdk.util.concurrency.UiThread;
import app.organicmaps.sdk.util.log.Logger;
import app.organicmaps.util.RtlUtils;
import com.google.android.material.appbar.MaterialToolbar;
@@ -30,9 +32,24 @@ public abstract class BaseMwmFragmentActivity extends AppCompatActivity
private boolean mSafeCreated;
@NonNull
private String mThemeName;
@StyleRes
protected int getThemeResourceId(@NonNull String theme)
{
if (Config.UiTheme.isDefault(theme))
return R.style.MwmTheme;
if (Config.UiTheme.isNight(theme))
return R.style.MwmTheme_Night;
throw new IllegalArgumentException("Attempt to apply unsupported theme: " + theme);
}
/**
* Shows splash screen and initializes the core in case when it was not initialized.
* <p>
*
* Do not override this method!
* Use {@link #onSafeCreate(Bundle savedInstanceState)}
*/
@@ -41,6 +58,8 @@ public abstract class BaseMwmFragmentActivity extends AppCompatActivity
protected final void onCreate(@Nullable Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
mThemeName = Config.UiTheme.getCurrent();
setTheme(getThemeResourceId(mThemeName));
EdgeToEdge.enable(this, SystemBarStyle.dark(Color.TRANSPARENT));
RtlUtils.manageRtl(this);
if (!MwmApplication.from(this).getOrganicMaps().arePlatformAndCoreInitialized())
@@ -94,6 +113,18 @@ public abstract class BaseMwmFragmentActivity extends AppCompatActivity
mSafeCreated = false;
}
@CallSuper
@Override
public void onPostResume()
{
super.onPostResume();
if (!mThemeName.equals(Config.UiTheme.getCurrent()))
{
// Workaround described in https://code.google.com/p/android/issues/detail?id=93731
UiThread.runLater(this::recreate);
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item)
{

View File

@@ -6,11 +6,13 @@ import android.os.Bundle;
import androidx.annotation.CallSuper;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.StyleRes;
import androidx.fragment.app.Fragment;
import app.organicmaps.R;
import app.organicmaps.base.BaseToolbarActivity;
import app.organicmaps.sdk.bookmarks.data.BookmarkCategory;
import app.organicmaps.sdk.bookmarks.data.BookmarkManager;
import app.organicmaps.util.ThemeUtils;
public class BookmarkCategoriesActivity extends BaseToolbarActivity
{
@@ -36,6 +38,13 @@ public class BookmarkCategoriesActivity extends BaseToolbarActivity
super.onPause();
}
@Override
@StyleRes
public int getThemeResourceId(@NonNull String theme)
{
return ThemeUtils.getWindowBgThemeResourceId(theme);
}
@Override
protected Class<? extends Fragment> getFragmentClass()
{

View File

@@ -54,6 +54,7 @@ public class BookmarkCategorySettingsFragment extends BaseMwmToolbarFragment
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)
{
View root = inflater.inflate(R.layout.fragment_bookmark_category_settings, container, false);
setHasOptionsMenu(true);
initViews(root);
return root;
}
@@ -84,7 +85,7 @@ public class BookmarkCategorySettingsFragment extends BaseMwmToolbarFragment
});
mEditDescView = root.findViewById(R.id.edit_description);
mEditDescView.setText(mCategory.getDescription());
mSaveView = root.findViewById(R.id.save);
mSaveView = root.findViewById(R.id.done);
mSaveView.setOnClickListener(v -> onEditDoneClicked());
}

View File

@@ -5,11 +5,13 @@ import android.os.Bundle;
import androidx.activity.result.ActivityResultLauncher;
import androidx.annotation.CallSuper;
import androidx.annotation.NonNull;
import androidx.annotation.StyleRes;
import androidx.fragment.app.Fragment;
import app.organicmaps.R;
import app.organicmaps.base.BaseToolbarActivity;
import app.organicmaps.sdk.bookmarks.data.BookmarkCategory;
import app.organicmaps.sdk.bookmarks.data.BookmarkManager;
import app.organicmaps.util.ThemeUtils;
public class BookmarkListActivity extends BaseToolbarActivity
{
@@ -35,6 +37,13 @@ public class BookmarkListActivity extends BaseToolbarActivity
super.onPause();
}
@Override
@StyleRes
public int getThemeResourceId(@NonNull String theme)
{
return ThemeUtils.getCardBgThemeResourceId(theme);
}
@Override
protected Class<? extends Fragment> getFragmentClass()
{

View File

@@ -12,12 +12,9 @@ import androidx.lifecycle.DefaultLifecycleObserver;
import androidx.lifecycle.LifecycleOwner;
import app.organicmaps.MwmApplication;
import app.organicmaps.R;
import app.organicmaps.car.renderer.Renderer;
import app.organicmaps.car.renderer.RendererFactory;
import app.organicmaps.car.screens.ErrorScreen;
import app.organicmaps.car.screens.MapPlaceholderScreen;
import app.organicmaps.car.screens.MapScreen;
import app.organicmaps.car.screens.NavigationScreen;
import app.organicmaps.car.screens.PlaceScreen;
import app.organicmaps.car.screens.base.BaseMapScreen;
import app.organicmaps.car.screens.download.DownloadMapsScreen;
@@ -52,9 +49,8 @@ public final class CarAppSession extends Session implements DefaultLifecycleObse
@Nullable
private final SessionInfo mSessionInfo;
@SuppressWarnings("NotNullFieldNotInitialized")
@NonNull
private Renderer mSurfaceRenderer;
private final SurfaceRenderer mSurfaceRenderer;
@NonNull
private final ScreenManager mScreenManager;
@SuppressWarnings("NotNullFieldNotInitialized")
@@ -71,6 +67,7 @@ public final class CarAppSession extends Session implements DefaultLifecycleObse
{
getLifecycle().addObserver(this);
mSessionInfo = sessionInfo;
mSurfaceRenderer = new SurfaceRenderer(getCarContext(), getLifecycle());
mScreenManager = getCarContext().getCarService(ScreenManager.class);
mCurrentCountryChangedListener = new CurrentCountryChangedListener();
}
@@ -117,8 +114,6 @@ public final class CarAppSession extends Session implements DefaultLifecycleObse
mSensorsManager = new CarSensorsManager(getCarContext());
mDisplayManager = MwmApplication.from(getCarContext()).getDisplayManager();
mDisplayManager.addListener(DisplayType.Car, this);
mSurfaceRenderer = RendererFactory.create(getCarContext(), mDisplayManager,
MwmApplication.from(getCarContext()).getLocationHelper(), this);
init();
}
@@ -286,19 +281,7 @@ public final class CarAppSession extends Session implements DefaultLifecycleObse
private void restoreRoute()
{
final RoutingController routingController = RoutingController.get();
final boolean isNavigating = routingController.isNavigating();
final boolean hasNavigatingScreen = hasNavigationScreenInStack();
if (!isNavigating && hasNavigatingScreen)
mScreenManager.popToRoot();
if (isNavigating && routingController.getLastRouterType() == PlaceScreen.ROUTER && hasNavigatingScreen)
{
mScreenManager.popTo(NavigationScreen.MARKER);
return;
}
if (routingController.isPlanning() || isNavigating || routingController.hasSavedRoute())
if (routingController.isPlanning() || routingController.isNavigating() || routingController.hasSavedRoute())
{
final PlaceScreen placeScreen = new PlaceScreen.Builder(getCarContext(), mSurfaceRenderer)
.setMapObject(routingController.getEndPoint())
@@ -307,14 +290,4 @@ public final class CarAppSession extends Session implements DefaultLifecycleObse
mScreenManager.push(placeScreen);
}
}
private boolean hasNavigationScreenInStack()
{
for (final Screen screen : mScreenManager.getScreenStack())
{
if (NavigationScreen.MARKER.equals(screen.getMarker()))
return true;
}
return false;
}
}

View File

@@ -0,0 +1,244 @@
package app.organicmaps.car;
import static app.organicmaps.sdk.display.DisplayType.Car;
import android.graphics.Rect;
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.CarToast;
import androidx.car.app.SurfaceCallback;
import androidx.car.app.SurfaceContainer;
import androidx.lifecycle.DefaultLifecycleObserver;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleOwner;
import app.organicmaps.MwmApplication;
import app.organicmaps.R;
import app.organicmaps.sdk.Framework;
import app.organicmaps.sdk.Map;
import app.organicmaps.sdk.MapRenderingListener;
import app.organicmaps.sdk.settings.UnitLocale;
import app.organicmaps.sdk.util.concurrency.UiThread;
import app.organicmaps.sdk.util.log.Logger;
public class SurfaceRenderer implements DefaultLifecycleObserver, SurfaceCallback, MapRenderingListener
{
private static final String TAG = SurfaceRenderer.class.getSimpleName();
@NonNull
private final CarContext mCarContext;
@NonNull
private final Map mMap = new Map(Car);
@NonNull
private Rect mVisibleArea = new Rect();
@Nullable
private Surface mSurface = null;
private boolean mIsRunning;
public SurfaceRenderer(@NonNull CarContext carContext, @NonNull Lifecycle lifecycle)
{
Logger.d(TAG, "SurfaceRenderer()");
mCarContext = carContext;
mIsRunning = true;
lifecycle.addObserver(this);
mMap.setMapRenderingListener(this);
}
@Override
public void onSurfaceAvailable(@NonNull SurfaceContainer surfaceContainer)
{
Logger.d(TAG, "Surface available " + surfaceContainer);
if (mSurface != null)
mSurface.release();
mSurface = surfaceContainer.getSurface();
mMap.setLocationHelper(MwmApplication.from(mCarContext).getLocationHelper());
mMap.onSurfaceCreated(mCarContext, mSurface,
new Rect(0, 0, surfaceContainer.getWidth(), surfaceContainer.getHeight()),
surfaceContainer.getDpi());
mMap.updateBottomWidgetsOffset(mCarContext, -1, -1);
}
@Override
public void onVisibleAreaChanged(@NonNull Rect visibleArea)
{
Logger.d(TAG, "Visible area changed. visibleArea: " + visibleArea);
mVisibleArea = visibleArea;
if (!mVisibleArea.isEmpty())
Framework.nativeSetVisibleRect(mVisibleArea.left, mVisibleArea.top, mVisibleArea.right, mVisibleArea.bottom);
}
@Override
public void onStableAreaChanged(@NonNull Rect stableArea)
{
Logger.d(TAG, "Stable area changed. stableArea: " + stableArea);
if (!stableArea.isEmpty())
Framework.nativeSetVisibleRect(stableArea.left, stableArea.top, stableArea.right, stableArea.bottom);
else if (!mVisibleArea.isEmpty())
Framework.nativeSetVisibleRect(mVisibleArea.left, mVisibleArea.top, mVisibleArea.right, mVisibleArea.bottom);
}
@Override
public void onSurfaceDestroyed(@NonNull SurfaceContainer surfaceContainer)
{
Logger.d(TAG, "Surface destroyed");
if (mSurface != null)
{
mSurface.release();
mSurface = null;
}
mMap.onSurfaceDestroyed(false, true);
}
@Override
public void onCreate(@NonNull LifecycleOwner owner)
{
Logger.d(TAG);
mCarContext.getCarService(AppManager.class).setSurfaceCallback(this);
mMap.onCreate(false);
}
@Override
public void onStart(@NonNull LifecycleOwner owner)
{
Logger.d(TAG);
mMap.onStart();
mMap.setCallbackUnsupported(this::reportUnsupported);
}
@Override
public void onResume(@NonNull LifecycleOwner owner)
{
Logger.d(TAG);
mMap.onResume();
if (MwmApplication.from(mCarContext).getDisplayManager().isCarDisplayUsed())
UiThread.runLater(() -> mMap.updateMyPositionRoutingOffset(0));
}
@Override
public void onPause(@NonNull LifecycleOwner owner)
{
Logger.d(TAG);
mMap.onPause(mCarContext);
}
@Override
public void onStop(@NonNull LifecycleOwner owner)
{
Logger.d(TAG);
mMap.onStop();
mMap.setCallbackUnsupported(null);
}
@Override
public void onScroll(float distanceX, float distanceY)
{
Logger.d(TAG, "distanceX: " + distanceX + ", distanceY: " + distanceY);
mMap.onScroll(distanceX, distanceY);
}
@Override
public void onFling(float velocityX, float velocityY)
{
Logger.d(TAG, "velocityX: " + velocityX + ", velocityY: " + velocityY);
}
public void onZoomIn()
{
Map.zoomIn();
}
public void onZoomOut()
{
Map.zoomOut();
}
@Override
public void onScale(float focusX, float focusY, float scaleFactor)
{
Logger.d(TAG, "focusX: " + focusX + ", focusY: " + focusY + ", scaleFactor: " + scaleFactor);
float x = focusX;
float y = focusY;
if (!mVisibleArea.isEmpty())
{
// If a focal point value is negative, use the center point of the visible area.
if (x < 0)
x = mVisibleArea.centerX();
if (y < 0)
y = mVisibleArea.centerY();
}
final boolean animated = Float.compare(scaleFactor, 2f) == 0;
Map.onScale(scaleFactor, x, y, animated);
}
@Override
public void onClick(float x, float y)
{
Logger.d(TAG, "x: " + x + ", y: " + y);
Map.onClick(x, y);
}
public void disable()
{
if (!mIsRunning)
{
Logger.d(TAG, "Already disabled");
return;
}
mCarContext.getCarService(AppManager.class).setSurfaceCallback(null);
mMap.onSurfaceDestroyed(false, true);
mMap.onStop();
mMap.setCallbackUnsupported(null);
mMap.setMapRenderingListener(null);
mIsRunning = false;
}
public void enable()
{
if (mIsRunning)
{
Logger.d(TAG, "Already enabled");
return;
}
mCarContext.getCarService(AppManager.class).setSurfaceCallback(this);
mMap.onStart();
mMap.setCallbackUnsupported(this::reportUnsupported);
mMap.setMapRenderingListener(this);
UiThread.runLater(() -> mMap.updateMyPositionRoutingOffset(0));
mIsRunning = true;
}
public boolean isRenderingActive()
{
return mIsRunning;
}
private void reportUnsupported()
{
String message = mCarContext.getString(R.string.unsupported_phone);
Logger.e(TAG, message);
CarToast.makeText(mCarContext, message, CarToast.LENGTH_LONG).show();
}
@Override
public void onRenderingCreated()
{
UnitLocale.initializeCurrentUnits();
}
}

View File

@@ -1,130 +0,0 @@
package app.organicmaps.car.renderer;
import androidx.annotation.CallSuper;
import androidx.annotation.NonNull;
import androidx.car.app.AppManager;
import androidx.car.app.CarContext;
import androidx.car.app.SurfaceCallback;
import androidx.lifecycle.DefaultLifecycleObserver;
import androidx.lifecycle.LifecycleOwner;
import app.organicmaps.sdk.Map;
import app.organicmaps.sdk.MapRenderingListener;
import app.organicmaps.sdk.display.DisplayManager;
import app.organicmaps.sdk.location.LocationHelper;
import app.organicmaps.sdk.settings.UnitLocale;
import app.organicmaps.sdk.util.log.Logger;
public abstract class Renderer implements DefaultLifecycleObserver
{
@NonNull
private final String TAG;
private SurfaceCallback mSurfaceCallback;
private boolean mIsRunning;
@NonNull
protected final CarContext mCarContext;
@NonNull
protected final DisplayManager mDisplayManager;
@NonNull
protected final LocationHelper mLocationHelper;
@NonNull
protected final LifecycleOwner mLifecycleOwner;
@NonNull
private final MapRenderingListener mMapRenderingListener = new MapRenderingListener() {
@Override
public void onRenderingCreated()
{
UnitLocale.initializeCurrentUnits();
}
};
public Renderer(@NonNull CarContext carContext, @NonNull DisplayManager displayManager,
@NonNull LocationHelper locationHelper, @NonNull LifecycleOwner lifecycleOwner)
{
TAG = getClass().getSimpleName();
Logger.d(TAG, "SurfaceRenderer()");
mIsRunning = true;
mCarContext = carContext;
mDisplayManager = displayManager;
mLocationHelper = locationHelper;
mLifecycleOwner = lifecycleOwner;
mLifecycleOwner.getLifecycle().addObserver(this);
}
protected void setSurfaceCallback(@NonNull SurfaceCallback surfaceCallback)
{
mSurfaceCallback = surfaceCallback;
}
public boolean isRenderingActive()
{
return mIsRunning;
}
protected MapRenderingListener getMapRenderingListener()
{
return mMapRenderingListener;
}
@CallSuper
@Override
public void onCreate(@NonNull LifecycleOwner owner)
{
Logger.d(TAG);
if (mSurfaceCallback == null)
throw new IllegalStateException("SurfaceCallback must be set before onCreate()");
mCarContext.getCarService(AppManager.class).setSurfaceCallback(mSurfaceCallback);
}
@CallSuper
@Override
public void onDestroy(@NonNull LifecycleOwner owner)
{
Logger.d(TAG);
mCarContext.getCarService(AppManager.class).setSurfaceCallback(null);
}
@CallSuper
public void enable()
{
if (isRenderingActive())
{
Logger.d(TAG, "Already enabled");
return;
}
if (mSurfaceCallback == null)
throw new IllegalStateException("SurfaceCallback must be set before enable()");
mCarContext.getCarService(AppManager.class).setSurfaceCallback(mSurfaceCallback);
mIsRunning = true;
}
@CallSuper
public void disable()
{
if (!isRenderingActive())
{
Logger.d(TAG, "Already disabled");
return;
}
mCarContext.getCarService(AppManager.class).setSurfaceCallback(null);
mIsRunning = false;
}
public void onZoomIn()
{
Map.zoomIn();
}
public void onZoomOut()
{
Map.zoomOut();
}
}

View File

@@ -1,20 +0,0 @@
package app.organicmaps.car.renderer;
import androidx.annotation.NonNull;
import androidx.car.app.CarContext;
import androidx.lifecycle.LifecycleOwner;
import app.organicmaps.sdk.display.DisplayManager;
import app.organicmaps.sdk.location.LocationHelper;
public final class RendererFactory
{
@NonNull
public static Renderer create(@NonNull CarContext carContext, @NonNull DisplayManager displayManager,
@NonNull LocationHelper locationHelper, @NonNull LifecycleOwner lifecycleOwner)
{
if (android.os.Build.VERSION.SDK_INT >= 23)
return new SurfaceRenderer(carContext, displayManager, locationHelper, lifecycleOwner);
else
return new SurfaceRendererLegacy(carContext, displayManager, locationHelper, lifecycleOwner);
}
}

View File

@@ -1,100 +0,0 @@
package app.organicmaps.car.renderer;
import android.app.Presentation;
import android.hardware.display.DisplayManager;
import android.hardware.display.VirtualDisplay;
import android.view.SurfaceHolder;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.widget.FrameLayout;
import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.car.app.CarContext;
import androidx.car.app.SurfaceContainer;
import app.organicmaps.sdk.MapController;
import app.organicmaps.sdk.util.log.Logger;
@RequiresApi(23)
class SurfaceCallback extends SurfaceCallbackBase
{
private static final String TAG = SurfaceCallback.class.getSimpleName();
private static final String VIRTUAL_DISPLAY_NAME = "OM_Android_Auto_Display";
@NonNull
private final MapController mMapController;
private VirtualDisplay mVirtualDisplay;
private Presentation mPresentation;
public SurfaceCallback(@NonNull CarContext carContext, @NonNull MapController mapController)
{
super(carContext);
mMapController = mapController;
mMapController.getView().getHolder().addCallback(new SurfaceHolder.Callback() {
@Override
public void surfaceChanged(@NonNull SurfaceHolder holder, int format, int width, int height)
{
mMapController.updateMyPositionRoutingOffset(0);
}
@Override
public void surfaceCreated(@NonNull SurfaceHolder holder)
{
mMapController.updateMyPositionRoutingOffset(0);
}
@Override
public void surfaceDestroyed(@NonNull SurfaceHolder holder)
{}
});
}
@Override
public void onSurfaceAvailable(@NonNull SurfaceContainer surfaceContainer)
{
Logger.d(TAG, "Surface available " + surfaceContainer);
mVirtualDisplay =
mCarContext.getSystemService(DisplayManager.class)
.createVirtualDisplay(VIRTUAL_DISPLAY_NAME, surfaceContainer.getWidth(), surfaceContainer.getHeight(),
surfaceContainer.getDpi(), surfaceContainer.getSurface(), 0);
mPresentation = new Presentation(mCarContext, mVirtualDisplay.getDisplay());
mPresentation.setContentView(prepareViewForPresentation(mMapController.getView()));
mPresentation.show();
}
@Override
public void onSurfaceDestroyed(@NonNull SurfaceContainer surfaceContainer)
{
Logger.d(TAG, "Surface destroyed");
mPresentation.dismiss();
mVirtualDisplay.release();
}
void stopPresenting()
{
if (mPresentation != null)
mPresentation.dismiss();
}
void startPresenting()
{
if (mPresentation != null)
mPresentation.show();
}
@NonNull
private View prepareViewForPresentation(@NonNull View view)
{
final ViewParent parent = view.getParent();
if (parent instanceof ViewGroup)
((ViewGroup) parent).removeView(view);
final FrameLayout container = new FrameLayout(mCarContext);
container.addView(
view, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
return container;
}
}

View File

@@ -1,96 +0,0 @@
package app.organicmaps.car.renderer;
import android.graphics.Rect;
import androidx.annotation.NonNull;
import androidx.car.app.CarContext;
import androidx.car.app.SurfaceCallback;
import app.organicmaps.sdk.Framework;
import app.organicmaps.sdk.Map;
import app.organicmaps.sdk.util.concurrency.UiThread;
import app.organicmaps.sdk.util.log.Logger;
abstract class SurfaceCallbackBase implements SurfaceCallback
{
@NonNull
private final String TAG;
@NonNull
protected final CarContext mCarContext;
@NonNull
protected Rect mVisibleArea = new Rect();
public SurfaceCallbackBase(@NonNull CarContext carContext)
{
TAG = getClass().getSimpleName();
mCarContext = carContext;
}
@Override
public void onVisibleAreaChanged(@NonNull Rect visibleArea)
{
Logger.d(TAG, "Visible area changed. visibleArea: " + visibleArea);
mVisibleArea = visibleArea;
if (!mVisibleArea.isEmpty())
UiThread.runLater(()
-> Framework.nativeSetVisibleRect(mVisibleArea.left, mVisibleArea.top, mVisibleArea.right,
mVisibleArea.bottom));
}
@Override
public void onStableAreaChanged(@NonNull Rect stableArea)
{
Logger.d(TAG, "Stable area changed. stableArea: " + stableArea);
if (!mVisibleArea.isEmpty())
UiThread.runLater(()
-> Framework.nativeSetVisibleRect(mVisibleArea.left, mVisibleArea.top, mVisibleArea.right,
mVisibleArea.bottom));
else if (!stableArea.isEmpty())
UiThread.runLater(
() -> Framework.nativeSetVisibleRect(stableArea.left, stableArea.top, stableArea.right, stableArea.bottom));
}
@Override
public void onScroll(float distanceX, float distanceY)
{
Logger.d(TAG, "distanceX: " + distanceX + ", distanceY: " + distanceY);
Map.onScroll(distanceX, distanceY);
}
@Override
public void onFling(float velocityX, float velocityY)
{
Logger.d(TAG, "velocityX: " + velocityX + ", velocityY: " + velocityY);
// TODO: Implement fling in the native code.
}
@Override
public void onScale(float focusX, float focusY, float scaleFactor)
{
Logger.d(TAG, "focusX: " + focusX + ", focusY: " + focusY + ", scaleFactor: " + scaleFactor);
float x = focusX;
float y = focusY;
if (!mVisibleArea.isEmpty())
{
// If a focal point value is negative, use the center point of the visible area.
if (x < 0)
x = mVisibleArea.centerX();
if (y < 0)
y = mVisibleArea.centerY();
}
final boolean animated = Float.compare(scaleFactor, 2f) == 0;
Map.onScale(scaleFactor, x, y, animated);
}
@Override
public void onClick(float x, float y)
{
Logger.d(TAG, "x: " + x + ", y: " + y);
Map.onClick(x, y);
}
}

View File

@@ -1,60 +0,0 @@
package app.organicmaps.car.renderer;
import android.graphics.Rect;
import android.view.Surface;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.car.app.CarContext;
import androidx.car.app.SurfaceContainer;
import app.organicmaps.sdk.Map;
import app.organicmaps.sdk.location.LocationHelper;
import app.organicmaps.sdk.util.log.Logger;
class SurfaceCallbackLegacy extends SurfaceCallbackBase
{
private static final String TAG = SurfaceCallbackLegacy.class.getSimpleName();
@NonNull
private final Map mMap;
@NonNull
private final LocationHelper mLocationHelper;
@Nullable
private Surface mSurface = null;
public SurfaceCallbackLegacy(@NonNull CarContext carContext, @NonNull Map map, @NonNull LocationHelper locationHelper)
{
super(carContext);
mMap = map;
mLocationHelper = locationHelper;
}
@Override
public void onSurfaceAvailable(@NonNull SurfaceContainer surfaceContainer)
{
Logger.d(TAG, "Surface available " + surfaceContainer);
if (mSurface != null)
mSurface.release();
mSurface = surfaceContainer.getSurface();
mMap.setLocationHelper(mLocationHelper);
mMap.onSurfaceCreated(mCarContext, mSurface,
new Rect(0, 0, surfaceContainer.getWidth(), surfaceContainer.getHeight()),
surfaceContainer.getDpi());
mMap.updateBottomWidgetsOffset(mCarContext, -1, -1);
}
@Override
public void onSurfaceDestroyed(@NonNull SurfaceContainer surfaceContainer)
{
Logger.d(TAG, "Surface destroyed");
if (mSurface != null)
{
mSurface.release();
mSurface = null;
}
mMap.onSurfaceDestroyed(false);
}
}

View File

@@ -1,53 +0,0 @@
package app.organicmaps.car.renderer;
import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.car.app.CarContext;
import androidx.lifecycle.LifecycleOwner;
import app.organicmaps.sdk.MapController;
import app.organicmaps.sdk.MapView;
import app.organicmaps.sdk.display.DisplayManager;
import app.organicmaps.sdk.display.DisplayType;
import app.organicmaps.sdk.location.LocationHelper;
@RequiresApi(23)
class SurfaceRenderer extends Renderer
{
@NonNull
private final MapController mMapController;
@NonNull
private final SurfaceCallback mSurfaceCallback;
public SurfaceRenderer(@NonNull CarContext carContext, @NonNull DisplayManager displayManager,
@NonNull LocationHelper locationHelper, @NonNull LifecycleOwner lifecycleOwner)
{
super(carContext, displayManager, locationHelper, lifecycleOwner);
mMapController = new MapController(new MapView(carContext, DisplayType.Car), locationHelper,
getMapRenderingListener(), null, false);
mLifecycleOwner.getLifecycle().addObserver(mMapController);
mSurfaceCallback = new SurfaceCallback(mCarContext, mMapController);
setSurfaceCallback(mSurfaceCallback);
}
@Override
public void enable()
{
super.enable();
mMapController.onStart(mLifecycleOwner);
mMapController.updateMyPositionRoutingOffset(0);
mSurfaceCallback.startPresenting();
}
@Override
public void disable()
{
super.disable();
mMapController.onPause(mLifecycleOwner);
mSurfaceCallback.stopPresenting();
mMapController.onStop(mLifecycleOwner);
}
}

View File

@@ -1,90 +0,0 @@
package app.organicmaps.car.renderer;
import static app.organicmaps.sdk.display.DisplayType.Car;
import androidx.annotation.NonNull;
import androidx.car.app.CarContext;
import androidx.lifecycle.LifecycleOwner;
import app.organicmaps.sdk.Map;
import app.organicmaps.sdk.display.DisplayManager;
import app.organicmaps.sdk.location.LocationHelper;
import app.organicmaps.sdk.util.log.Logger;
class SurfaceRendererLegacy extends Renderer
{
private static final String TAG = SurfaceRendererLegacy.class.getSimpleName();
@NonNull
private final Map mMap = new Map(Car);
public SurfaceRendererLegacy(@NonNull CarContext carContext, @NonNull DisplayManager displayManager,
@NonNull LocationHelper locationHelper, @NonNull LifecycleOwner lifecycleOwner)
{
super(carContext, displayManager, locationHelper, lifecycleOwner);
setSurfaceCallback(new SurfaceCallbackLegacy(mCarContext, mMap, mLocationHelper));
mMap.setMapRenderingListener(getMapRenderingListener());
}
@Override
public void onCreate(@NonNull LifecycleOwner owner)
{
super.onCreate(owner);
mMap.onCreate(false);
}
@Override
public void onStart(@NonNull LifecycleOwner owner)
{
Logger.d(TAG);
if (mDisplayManager.isCarDisplayUsed())
mMap.onStart();
}
@Override
public void onResume(@NonNull LifecycleOwner owner)
{
Logger.d(TAG);
if (mDisplayManager.isCarDisplayUsed())
{
mMap.onResume();
mMap.updateMyPositionRoutingOffset(0);
}
}
@Override
public void onPause(@NonNull LifecycleOwner owner)
{
Logger.d(TAG);
if (mDisplayManager.isCarDisplayUsed())
mMap.onPause();
}
@Override
public void onStop(@NonNull LifecycleOwner owner)
{
Logger.d(TAG);
if (mDisplayManager.isCarDisplayUsed())
mMap.onStop();
}
@Override
public void enable()
{
super.enable();
mMap.onStart();
mMap.setMapRenderingListener(getMapRenderingListener());
mMap.updateMyPositionRoutingOffset(0);
}
@Override
public void disable()
{
super.disable();
mMap.onPause();
mMap.onSurfaceDestroyed(false);
mMap.onStop();
mMap.setMapRenderingListener(null);
}
}

View File

@@ -15,29 +15,30 @@ import androidx.car.app.model.Template;
import androidx.car.app.navigation.model.MapWithContentTemplate;
import androidx.core.graphics.drawable.IconCompat;
import app.organicmaps.R;
import app.organicmaps.car.renderer.Renderer;
import app.organicmaps.car.SurfaceRenderer;
import app.organicmaps.car.screens.base.BaseMapScreen;
import app.organicmaps.car.screens.search.SearchOnMapScreen;
import app.organicmaps.car.util.ThemeUtils;
import app.organicmaps.car.util.UiHelpers;
import java.util.Arrays;
import java.util.List;
public class CategoriesScreen extends BaseMapScreen
{
private record CategoryData(@StringRes int nameResId, @DrawableRes int iconResId) {}
private record CategoryData(@StringRes int nameResId, @DrawableRes int iconResId, @DrawableRes int iconNightResId) {}
private static final List<CategoryData> CATEGORIES =
Arrays.asList(new CategoryData(R.string.category_fuel, R.drawable.ic_category_fuel),
new CategoryData(R.string.category_parking, R.drawable.ic_category_parking),
new CategoryData(R.string.category_eat, R.drawable.ic_category_eat),
new CategoryData(R.string.category_food, R.drawable.ic_category_food),
new CategoryData(R.string.category_hotel, R.drawable.ic_category_hotel),
new CategoryData(R.string.category_toilet, R.drawable.ic_category_toilet),
new CategoryData(R.string.category_rv, R.drawable.ic_category_rv));
private static final List<CategoryData> CATEGORIES = Arrays.asList(
new CategoryData(R.string.category_fuel, R.drawable.ic_category_fuel, R.drawable.ic_category_fuel_night),
new CategoryData(R.string.category_parking, R.drawable.ic_category_parking, R.drawable.ic_category_parking_night),
new CategoryData(R.string.category_eat, R.drawable.ic_category_eat, R.drawable.ic_category_eat_night),
new CategoryData(R.string.category_food, R.drawable.ic_category_food, R.drawable.ic_category_food_night),
new CategoryData(R.string.category_hotel, R.drawable.ic_category_hotel, R.drawable.ic_category_hotel_night),
new CategoryData(R.string.category_toilet, R.drawable.ic_category_toilet, R.drawable.ic_category_toilet_night),
new CategoryData(R.string.category_rv, R.drawable.ic_category_rv, R.drawable.ic_category_rv_night));
private final int MAX_CATEGORIES_SIZE;
public CategoriesScreen(@NonNull CarContext carContext, @NonNull Renderer surfaceRenderer)
public CategoriesScreen(@NonNull CarContext carContext, @NonNull SurfaceRenderer surfaceRenderer)
{
super(carContext, surfaceRenderer);
final ConstraintManager constraintManager = getCarContext().getCarService(ConstraintManager.class);
@@ -46,7 +47,7 @@ public class CategoriesScreen extends BaseMapScreen
@NonNull
@Override
protected Template onGetTemplateImpl()
public Template onGetTemplate()
{
final MapWithContentTemplate.Builder builder = new MapWithContentTemplate.Builder();
builder.setMapController(UiHelpers.createMapController(getCarContext(), getSurfaceRenderer()));
@@ -66,6 +67,7 @@ public class CategoriesScreen extends BaseMapScreen
@NonNull
private GridTemplate createCategoriesListTemplate()
{
final boolean isNightMode = ThemeUtils.isNightMode(getCarContext());
final ItemList.Builder builder = new ItemList.Builder();
final int categoriesSize = Math.min(CATEGORIES.size(), MAX_CATEGORIES_SIZE);
for (int i = 0; i < categoriesSize; ++i)
@@ -73,7 +75,7 @@ public class CategoriesScreen extends BaseMapScreen
final GridItem.Builder itemBuilder = new GridItem.Builder();
final String title = getCarContext().getString(CATEGORIES.get(i).nameResId);
@DrawableRes
final int iconResId = CATEGORIES.get(i).iconResId;
final int iconResId = isNightMode ? CATEGORIES.get(i).iconNightResId : CATEGORIES.get(i).iconResId;
itemBuilder.setTitle(title);
itemBuilder.setImage(new CarIcon.Builder(IconCompat.createWithResource(getCarContext(), iconResId)).build());

View File

@@ -43,7 +43,7 @@ public class ErrorScreen extends BaseScreen implements UserActionRequired
@NonNull
@Override
protected Template onGetTemplateImpl()
public Template onGetTemplate()
{
final MessageTemplate.Builder builder = new MessageTemplate.Builder(getCarContext().getString(mErrorMessage));

View File

@@ -9,20 +9,20 @@ import androidx.car.app.model.Template;
import androidx.car.app.navigation.model.NavigationTemplate;
import androidx.core.graphics.drawable.IconCompat;
import app.organicmaps.R;
import app.organicmaps.car.renderer.Renderer;
import app.organicmaps.car.SurfaceRenderer;
import app.organicmaps.car.screens.base.BaseMapScreen;
import app.organicmaps.car.util.UiHelpers;
public class FreeDriveScreen extends BaseMapScreen
{
public FreeDriveScreen(@NonNull CarContext carContext, @NonNull Renderer surfaceRenderer)
public FreeDriveScreen(@NonNull CarContext carContext, @NonNull SurfaceRenderer surfaceRenderer)
{
super(carContext, surfaceRenderer);
}
@NonNull
@Override
protected Template onGetTemplateImpl()
public Template onGetTemplate()
{
final NavigationTemplate.Builder builder = new NavigationTemplate.Builder();
builder.setMapActionStrip(UiHelpers.createMapActionStrip(getCarContext(), getSurfaceRenderer()));

View File

@@ -22,7 +22,7 @@ public class MapPlaceholderScreen extends BaseScreen
@NonNull
@Override
protected Template onGetTemplateImpl()
public Template onGetTemplate()
{
final MessageTemplate.Builder builder =
new MessageTemplate.Builder(getCarContext().getString(R.string.car_used_on_the_phone_screen));

View File

@@ -14,7 +14,7 @@ import androidx.car.app.model.Template;
import androidx.car.app.navigation.model.MapWithContentTemplate;
import androidx.core.graphics.drawable.IconCompat;
import app.organicmaps.R;
import app.organicmaps.car.renderer.Renderer;
import app.organicmaps.car.SurfaceRenderer;
import app.organicmaps.car.screens.base.BaseMapScreen;
import app.organicmaps.car.screens.bookmarks.BookmarkCategoriesScreen;
import app.organicmaps.car.screens.search.SearchScreen;
@@ -24,14 +24,14 @@ import app.organicmaps.car.util.UiHelpers;
public class MapScreen extends BaseMapScreen
{
public MapScreen(@NonNull CarContext carContext, @NonNull Renderer surfaceRenderer)
public MapScreen(@NonNull CarContext carContext, @NonNull SurfaceRenderer surfaceRenderer)
{
super(carContext, surfaceRenderer);
}
@NonNull
@Override
protected Template onGetTemplateImpl()
public Template onGetTemplate()
{
SuggestionsHelpers.updateSuggestions(getCarContext());

View File

@@ -20,7 +20,7 @@ import androidx.lifecycle.LifecycleOwner;
import app.organicmaps.MwmApplication;
import app.organicmaps.R;
import app.organicmaps.car.CarAppService;
import app.organicmaps.car.renderer.Renderer;
import app.organicmaps.car.SurfaceRenderer;
import app.organicmaps.car.screens.base.BaseMapScreen;
import app.organicmaps.car.screens.settings.DrivingOptionsScreen;
import app.organicmaps.car.util.Colors;
@@ -70,7 +70,7 @@ public class NavigationScreen extends BaseMapScreen implements RoutingController
@NonNull
@Override
protected Template onGetTemplateImpl()
public Template onGetTemplate()
{
final NavigationTemplate.Builder builder = new NavigationTemplate.Builder();
builder.setBackgroundColor(Colors.NAVIGATION_TEMPLATE_BACKGROUND);
@@ -104,11 +104,7 @@ public class NavigationScreen extends BaseMapScreen implements RoutingController
public void onAutoDriveEnabled()
{
Logger.i(TAG);
/// @todo Pass maxDistM from RouteSimulationProvider?
/// Result speed between points will be in range (25, 50] km/h (for 1 second update interval).
final double kMaxDistM = 13.9; // 13.9 m/s == 50 km/h
final JunctionInfo[] points = Framework.nativeGetRouteJunctionPoints(kMaxDistM);
final JunctionInfo[] points = Framework.nativeGetRouteJunctionPoints();
if (points == null)
{
Logger.e(TAG, "Navigation has not started yet");
@@ -125,8 +121,6 @@ public class NavigationScreen extends BaseMapScreen implements RoutingController
if (!mNavigationCancelled)
CarToast.makeText(getCarContext(), getCarContext().getString(R.string.trip_finished), CarToast.LENGTH_LONG)
.show();
NavigationService.stopService(getCarContext());
ThemeUtils.update(getCarContext());
finish();
getScreenManager().popToRoot();
}
@@ -134,7 +128,7 @@ public class NavigationScreen extends BaseMapScreen implements RoutingController
@Override
public void onCreate(@NonNull LifecycleOwner owner)
{
super.onCreate(owner);
Logger.d(TAG);
mRoutingController.attach(this);
ThemeUtils.update(getCarContext());
mNavigationManager.setNavigationManagerCallback(this);
@@ -150,19 +144,20 @@ public class NavigationScreen extends BaseMapScreen implements RoutingController
@Override
public void onResume(@NonNull LifecycleOwner owner)
{
super.onResume(owner);
Logger.d(TAG);
mRoutingController.attach(this);
}
@Override
public void onDestroy(@NonNull LifecycleOwner owner)
{
super.onDestroy(owner);
NavigationService.stopService(getCarContext());
MwmApplication.from(getCarContext()).getLocationHelper().removeListener(mLocationListener);
if (mRoutingController.isNavigating())
mRoutingController.onSaveState();
mRoutingController.detach();
ThemeUtils.update(getCarContext());
mNavigationManager.navigationEnded();
mNavigationManager.clearNavigationManagerCallback();
}
@@ -262,9 +257,9 @@ public class NavigationScreen extends BaseMapScreen implements RoutingController
@NonNull
private final CarContext mCarContext;
@NonNull
private final Renderer mSurfaceRenderer;
private final SurfaceRenderer mSurfaceRenderer;
public Builder(@NonNull final CarContext carContext, @NonNull final Renderer surfaceRenderer)
public Builder(@NonNull final CarContext carContext, @NonNull final SurfaceRenderer surfaceRenderer)
{
mCarContext = carContext;
mSurfaceRenderer = surfaceRenderer;

View File

@@ -26,7 +26,7 @@ import androidx.core.graphics.drawable.IconCompat;
import androidx.lifecycle.LifecycleOwner;
import app.organicmaps.MwmApplication;
import app.organicmaps.R;
import app.organicmaps.car.renderer.Renderer;
import app.organicmaps.car.SurfaceRenderer;
import app.organicmaps.car.screens.base.BaseMapScreen;
import app.organicmaps.car.screens.download.DownloadMapsScreenBuilder;
import app.organicmaps.car.screens.settings.DrivingOptionsScreen;
@@ -46,7 +46,7 @@ import java.util.Objects;
public class PlaceScreen extends BaseMapScreen implements OnBackPressedCallback.Callback, RoutingController.Container
{
public static final Router ROUTER = Router.Vehicle;
private static final Router ROUTER = Router.Vehicle;
@Nullable
private MapObject mMapObject;
@@ -68,7 +68,7 @@ public class PlaceScreen extends BaseMapScreen implements OnBackPressedCallback.
@NonNull
@Override
protected Template onGetTemplateImpl()
public Template onGetTemplate()
{
final MapWithContentTemplate.Builder builder = new MapWithContentTemplate.Builder();
builder.setMapController(UiHelpers.createMapController(getCarContext(), getSurfaceRenderer()));
@@ -80,7 +80,6 @@ public class PlaceScreen extends BaseMapScreen implements OnBackPressedCallback.
@Override
public void onCreate(@NonNull LifecycleOwner owner)
{
super.onCreate(owner);
mRoutingController.restore();
if (mRoutingController.isNavigating() && mRoutingController.getLastRouterType() == ROUTER)
{
@@ -113,14 +112,12 @@ public class PlaceScreen extends BaseMapScreen implements OnBackPressedCallback.
@Override
public void onResume(@NonNull LifecycleOwner owner)
{
super.onResume(owner);
mRoutingController.attach(this);
}
@Override
public void onDestroy(@NonNull LifecycleOwner owner)
{
super.onDestroy(owner);
if (mRoutingController.isPlanning())
mRoutingController.onSaveState();
if (!mRoutingController.isNavigating())
@@ -343,11 +340,11 @@ public class PlaceScreen extends BaseMapScreen implements OnBackPressedCallback.
@NonNull
private final CarContext mCarContext;
@NonNull
private final Renderer mSurfaceRenderer;
private final SurfaceRenderer mSurfaceRenderer;
@Nullable
private MapObject mMapObject;
public Builder(@NonNull final CarContext carContext, @NonNull final Renderer surfaceRenderer)
public Builder(@NonNull final CarContext carContext, @NonNull final SurfaceRenderer surfaceRenderer)
{
mCarContext = carContext;
mSurfaceRenderer = surfaceRenderer;

View File

@@ -2,21 +2,21 @@ package app.organicmaps.car.screens.base;
import androidx.annotation.NonNull;
import androidx.car.app.CarContext;
import app.organicmaps.car.renderer.Renderer;
import app.organicmaps.car.SurfaceRenderer;
public abstract class BaseMapScreen extends BaseScreen
{
@NonNull
private final Renderer mSurfaceRenderer;
private final SurfaceRenderer mSurfaceRenderer;
public BaseMapScreen(@NonNull CarContext carContext, @NonNull Renderer surfaceRenderer)
public BaseMapScreen(@NonNull CarContext carContext, @NonNull SurfaceRenderer surfaceRenderer)
{
super(carContext);
mSurfaceRenderer = surfaceRenderer;
}
@NonNull
protected Renderer getSurfaceRenderer()
protected SurfaceRenderer getSurfaceRenderer()
{
return mSurfaceRenderer;
}

View File

@@ -1,71 +1,15 @@
package app.organicmaps.car.screens.base;
import androidx.annotation.CallSuper;
import androidx.annotation.NonNull;
import androidx.car.app.CarContext;
import androidx.car.app.Screen;
import androidx.car.app.model.Template;
import androidx.lifecycle.DefaultLifecycleObserver;
import androidx.lifecycle.LifecycleOwner;
import app.organicmaps.sdk.util.log.Logger;
public abstract class BaseScreen extends Screen implements DefaultLifecycleObserver
{
@NonNull
private final String TAG;
public BaseScreen(@NonNull CarContext carContext)
{
super(carContext);
TAG = getClass().getSimpleName();
getLifecycle().addObserver(this);
}
@NonNull
protected abstract Template onGetTemplateImpl();
@Override
@NonNull
public final Template onGetTemplate()
{
Logger.d(TAG);
return onGetTemplateImpl();
}
@CallSuper
public void onCreate(@NonNull LifecycleOwner owner)
{
Logger.d(TAG);
}
@CallSuper
public void onStart(@NonNull LifecycleOwner owner)
{
Logger.d(TAG);
}
@CallSuper
public void onResume(@NonNull LifecycleOwner owner)
{
Logger.d(TAG);
}
@CallSuper
public void onPause(@NonNull LifecycleOwner owner)
{
Logger.d(TAG);
}
@CallSuper
public void onStop(@NonNull LifecycleOwner owner)
{
Logger.d(TAG);
}
@CallSuper
public void onDestroy(@NonNull LifecycleOwner owner)
{
Logger.d(TAG);
}
}

View File

@@ -11,7 +11,7 @@ import androidx.car.app.model.Row;
import androidx.car.app.model.Template;
import androidx.car.app.navigation.model.MapWithContentTemplate;
import app.organicmaps.R;
import app.organicmaps.car.renderer.Renderer;
import app.organicmaps.car.SurfaceRenderer;
import app.organicmaps.car.screens.base.BaseMapScreen;
import app.organicmaps.car.util.UiHelpers;
import app.organicmaps.sdk.bookmarks.data.BookmarkCategory;
@@ -23,7 +23,7 @@ public class BookmarkCategoriesScreen extends BaseMapScreen
{
private final int MAX_CATEGORIES_SIZE;
public BookmarkCategoriesScreen(@NonNull CarContext carContext, @NonNull Renderer surfaceRenderer)
public BookmarkCategoriesScreen(@NonNull CarContext carContext, @NonNull SurfaceRenderer surfaceRenderer)
{
super(carContext, surfaceRenderer);
final ConstraintManager constraintManager = getCarContext().getCarService(ConstraintManager.class);
@@ -32,7 +32,7 @@ public class BookmarkCategoriesScreen extends BaseMapScreen
@NonNull
@Override
protected Template onGetTemplateImpl()
public Template onGetTemplate()
{
final MapWithContentTemplate.Builder builder = new MapWithContentTemplate.Builder();
builder.setMapController(UiHelpers.createMapController(getCarContext(), getSurfaceRenderer()));

View File

@@ -13,7 +13,7 @@ import androidx.car.app.navigation.model.MapWithContentTemplate;
import androidx.core.graphics.drawable.IconCompat;
import androidx.lifecycle.LifecycleOwner;
import app.organicmaps.R;
import app.organicmaps.car.renderer.Renderer;
import app.organicmaps.car.SurfaceRenderer;
import app.organicmaps.car.screens.base.BaseMapScreen;
import app.organicmaps.car.util.UiHelpers;
import app.organicmaps.sdk.bookmarks.data.BookmarkCategory;
@@ -31,7 +31,7 @@ public class BookmarksScreen extends BaseMapScreen
private boolean mIsOnSortingScreen = false;
public BookmarksScreen(@NonNull CarContext carContext, @NonNull Renderer surfaceRenderer,
public BookmarksScreen(@NonNull CarContext carContext, @NonNull SurfaceRenderer surfaceRenderer,
@NonNull BookmarkCategory bookmarkCategory)
{
super(carContext, surfaceRenderer);
@@ -41,7 +41,7 @@ public class BookmarksScreen extends BaseMapScreen
@NonNull
@Override
protected Template onGetTemplateImpl()
public Template onGetTemplate()
{
final MapWithContentTemplate.Builder builder = new MapWithContentTemplate.Builder();
builder.setMapController(UiHelpers.createMapController(getCarContext(), getSurfaceRenderer()));
@@ -52,7 +52,6 @@ public class BookmarksScreen extends BaseMapScreen
@Override
public void onStop(@NonNull LifecycleOwner owner)
{
super.onStop(owner);
if (!mIsOnSortingScreen)
mBookmarksLoader.cancel();
}

View File

@@ -16,7 +16,7 @@ import androidx.core.graphics.drawable.IconCompat;
import androidx.lifecycle.LifecycleOwner;
import app.organicmaps.MwmApplication;
import app.organicmaps.R;
import app.organicmaps.car.renderer.Renderer;
import app.organicmaps.car.SurfaceRenderer;
import app.organicmaps.car.screens.base.BaseMapScreen;
import app.organicmaps.car.util.UiHelpers;
import app.organicmaps.sdk.bookmarks.data.BookmarkCategory;
@@ -38,7 +38,7 @@ class SortingScreen extends BaseMapScreen
private @BookmarkManager.SortingType int mNewSortingType;
public SortingScreen(@NonNull CarContext carContext, @NonNull Renderer surfaceRenderer,
public SortingScreen(@NonNull CarContext carContext, @NonNull SurfaceRenderer surfaceRenderer,
@NonNull BookmarkCategory bookmarkCategory)
{
super(carContext, surfaceRenderer);
@@ -53,7 +53,7 @@ class SortingScreen extends BaseMapScreen
@NonNull
@Override
protected Template onGetTemplateImpl()
public Template onGetTemplate()
{
final MapWithContentTemplate.Builder builder = new MapWithContentTemplate.Builder();
builder.setMapController(UiHelpers.createMapController(getCarContext(), getSurfaceRenderer()));

View File

@@ -23,7 +23,6 @@ class DownloadMapsForFirstLaunchScreen extends DownloadMapsScreen
@Override
public void onResume(@NonNull LifecycleOwner owner)
{
super.onResume(owner);
// Attempting to streamline initial download by including the current country in the list of missing maps for
// simultaneous retrieval.
final Location location = MwmApplication.from(getCarContext()).getLocationHelper().getSavedLocation();

View File

@@ -34,7 +34,7 @@ public abstract class DownloadMapsScreen extends BaseScreen
@NonNull
@Override
protected final Template onGetTemplateImpl()
public final Template onGetTemplate()
{
final MessageTemplate.Builder builder = new MessageTemplate.Builder(getText(getMapsSize(mMissingMaps)));
final Header.Builder headerBuilder = new Header.Builder();

View File

@@ -102,7 +102,6 @@ class DownloaderScreen extends BaseScreen
@Override
public void onResume(@NonNull LifecycleOwner owner)
{
super.onResume(owner);
if (mSubscriptionSlot == 0)
mSubscriptionSlot = MapManager.nativeSubscribe(mStorageCallback);
for (final var item : mMissingMaps.entrySet())
@@ -115,7 +114,6 @@ class DownloaderScreen extends BaseScreen
@Override
public void onPause(@NonNull LifecycleOwner owner)
{
super.onPause(owner);
if (!mIsDownloadFailed)
cancelMapsDownloading();
if (mSubscriptionSlot != 0)
@@ -127,7 +125,7 @@ class DownloaderScreen extends BaseScreen
@NonNull
@Override
protected Template onGetTemplateImpl()
public Template onGetTemplate()
{
final MessageTemplate.Builder builder = new MessageTemplate.Builder(getText());
builder.setLoading(true);

View File

@@ -37,7 +37,7 @@ public class RequestPermissionsScreenWithApi extends BaseScreen implements UserA
@NonNull
@Override
protected Template onGetTemplateImpl()
public Template onGetTemplate()
{
final MessageTemplate.Builder builder =
new MessageTemplate.Builder(getCarContext().getString(R.string.aa_request_permission_activity_text));
@@ -63,7 +63,6 @@ public class RequestPermissionsScreenWithApi extends BaseScreen implements UserA
@Override
public void onResume(@NonNull LifecycleOwner owner)
{
super.onResume(owner);
// Let's review the permissions once more, as we might enter this function following an ErrorScreen situation
// where the user manually enabled location permissions.
if (LocationUtils.checkFineLocationPermission(getCarContext()))

View File

@@ -47,7 +47,7 @@ public class RequestPermissionsScreenWithNotification extends BaseScreen impleme
@NonNull
@Override
protected Template onGetTemplateImpl()
public Template onGetTemplate()
{
final MessageTemplate.Builder builder =
new MessageTemplate.Builder(getCarContext().getString(R.string.aa_location_permissions_request));
@@ -66,7 +66,6 @@ public class RequestPermissionsScreenWithNotification extends BaseScreen impleme
@RequiresPermission(value = Manifest.permission.POST_NOTIFICATIONS)
public void onStart(@NonNull LifecycleOwner owner)
{
super.onStart(owner);
mIsPermissionCheckEnabled = true;
mBackgroundExecutor.execute(this::checkPermissions);
sendPermissionsRequestNotification();
@@ -75,14 +74,12 @@ public class RequestPermissionsScreenWithNotification extends BaseScreen impleme
@Override
public void onStop(@NonNull LifecycleOwner owner)
{
super.onStop(owner);
mIsPermissionCheckEnabled = false;
}
@Override
public void onDestroy(@NonNull LifecycleOwner owner)
{
super.onDestroy(owner);
NotificationManagerCompat.from(getCarContext()).cancel(NOTIFICATION_ID);
}

View File

@@ -17,7 +17,7 @@ import androidx.core.graphics.drawable.IconCompat;
import androidx.lifecycle.LifecycleOwner;
import app.organicmaps.MwmApplication;
import app.organicmaps.R;
import app.organicmaps.car.renderer.Renderer;
import app.organicmaps.car.SurfaceRenderer;
import app.organicmaps.car.screens.base.BaseMapScreen;
import app.organicmaps.car.util.UiHelpers;
import app.organicmaps.sdk.bookmarks.data.MapObject;
@@ -54,7 +54,7 @@ public class SearchOnMapScreen extends BaseMapScreen implements SearchListener
@NonNull
@Override
protected Template onGetTemplateImpl()
public Template onGetTemplate()
{
final MapWithContentTemplate.Builder builder = new MapWithContentTemplate.Builder();
builder.setMapController(UiHelpers.createMapController(getCarContext(), getSurfaceRenderer()));
@@ -136,14 +136,12 @@ public class SearchOnMapScreen extends BaseMapScreen implements SearchListener
@Override
public void onStart(@NonNull LifecycleOwner owner)
{
super.onStart(owner);
SearchEngine.INSTANCE.addListener(this);
}
@Override
public void onResume(@NonNull LifecycleOwner owner)
{
super.onResume(owner);
SearchEngine.INSTANCE.cancel();
final MapObject location = MwmApplication.from(getCarContext()).getLocationHelper().getMyPosition();
@@ -158,7 +156,6 @@ public class SearchOnMapScreen extends BaseMapScreen implements SearchListener
@Override
public void onStop(@NonNull LifecycleOwner owner)
{
super.onStop(owner);
SearchEngine.INSTANCE.removeListener(this);
SearchEngine.INSTANCE.cancel();
}
@@ -180,7 +177,7 @@ public class SearchOnMapScreen extends BaseMapScreen implements SearchListener
@NonNull
private final CarContext mCarContext;
@NonNull
private final Renderer mSurfaceRenderer;
private final SurfaceRenderer mSurfaceRenderer;
@NonNull
private String mQuery = "";
@@ -188,7 +185,7 @@ public class SearchOnMapScreen extends BaseMapScreen implements SearchListener
private String mLocale;
private boolean mIsCategory;
public Builder(@NonNull CarContext carContext, @NonNull Renderer surfaceRenderer)
public Builder(@NonNull CarContext carContext, @NonNull SurfaceRenderer surfaceRenderer)
{
mCarContext = carContext;
mSurfaceRenderer = surfaceRenderer;

View File

@@ -16,7 +16,7 @@ import androidx.core.graphics.drawable.IconCompat;
import androidx.lifecycle.LifecycleOwner;
import app.organicmaps.MwmApplication;
import app.organicmaps.R;
import app.organicmaps.car.renderer.Renderer;
import app.organicmaps.car.SurfaceRenderer;
import app.organicmaps.car.screens.base.BaseMapScreen;
import app.organicmaps.sdk.bookmarks.data.MapObject;
import app.organicmaps.sdk.search.SearchEngine;
@@ -50,7 +50,7 @@ public class SearchScreen extends BaseMapScreen implements SearchTemplate.Search
@NonNull
@Override
protected Template onGetTemplateImpl()
public Template onGetTemplate()
{
final SearchTemplate.Builder builder = new SearchTemplate.Builder(this);
builder.setHeaderAction(Action.BACK);
@@ -106,14 +106,12 @@ public class SearchScreen extends BaseMapScreen implements SearchTemplate.Search
@Override
public void onStart(@NonNull LifecycleOwner owner)
{
super.onStart(owner);
SearchEngine.INSTANCE.addListener(this);
}
@Override
public void onStop(@NonNull LifecycleOwner owner)
{
super.onStop(owner);
SearchEngine.INSTANCE.removeListener(this);
SearchEngine.INSTANCE.cancel();
}
@@ -211,14 +209,14 @@ public class SearchScreen extends BaseMapScreen implements SearchTemplate.Search
@NonNull
private final CarContext mCarContext;
@NonNull
private final Renderer mSurfaceRenderer;
private final SurfaceRenderer mSurfaceRenderer;
@NonNull
private String mQuery = "";
@NonNull
private String mLocale;
public Builder(@NonNull CarContext carContext, @NonNull Renderer surfaceRenderer)
public Builder(@NonNull CarContext carContext, @NonNull SurfaceRenderer surfaceRenderer)
{
mCarContext = carContext;
mSurfaceRenderer = surfaceRenderer;

View File

@@ -13,7 +13,7 @@ import androidx.car.app.model.Template;
import androidx.car.app.navigation.model.MapWithContentTemplate;
import androidx.lifecycle.LifecycleOwner;
import app.organicmaps.R;
import app.organicmaps.car.renderer.Renderer;
import app.organicmaps.car.SurfaceRenderer;
import app.organicmaps.car.screens.base.BaseMapScreen;
import app.organicmaps.car.util.Toggle;
import app.organicmaps.car.util.UiHelpers;
@@ -31,13 +31,12 @@ public class DrivingOptionsScreen extends BaseMapScreen
private final DrivingOption[] mDrivingOptions = {new DrivingOption(RoadType.Toll, R.string.avoid_tolls),
new DrivingOption(RoadType.Dirty, R.string.avoid_unpaved),
new DrivingOption(RoadType.Ferry, R.string.avoid_ferry),
new DrivingOption(RoadType.Motorway, R.string.avoid_motorways),
new DrivingOption(RoadType.Steps, R.string.avoid_steps)};
new DrivingOption(RoadType.Motorway, R.string.avoid_motorways)};
@NonNull
private final Map<RoadType, Boolean> mInitialDrivingOptionsState = new HashMap<>();
public DrivingOptionsScreen(@NonNull CarContext carContext, @NonNull Renderer surfaceRenderer)
public DrivingOptionsScreen(@NonNull CarContext carContext, @NonNull SurfaceRenderer surfaceRenderer)
{
super(carContext, surfaceRenderer);
@@ -46,7 +45,7 @@ public class DrivingOptionsScreen extends BaseMapScreen
@NonNull
@Override
protected Template onGetTemplateImpl()
public Template onGetTemplate()
{
final MapWithContentTemplate.Builder builder = new MapWithContentTemplate.Builder();
builder.setMapController(UiHelpers.createMapController(getCarContext(), getSurfaceRenderer()));
@@ -57,7 +56,6 @@ public class DrivingOptionsScreen extends BaseMapScreen
@Override
public void onStop(@NonNull LifecycleOwner owner)
{
super.onStop(owner);
for (final DrivingOption drivingOption : mDrivingOptions)
{
if (Boolean.TRUE.equals(mInitialDrivingOptionsState.get(drivingOption.roadType))

View File

@@ -12,7 +12,7 @@ import androidx.car.app.model.Template;
import androidx.car.app.navigation.model.MapWithContentTemplate;
import app.organicmaps.BuildConfig;
import app.organicmaps.R;
import app.organicmaps.car.renderer.Renderer;
import app.organicmaps.car.SurfaceRenderer;
import app.organicmaps.car.screens.base.BaseMapScreen;
import app.organicmaps.car.util.UiHelpers;
import app.organicmaps.sdk.Framework;
@@ -20,14 +20,14 @@ import app.organicmaps.sdk.util.DateUtils;
public class HelpScreen extends BaseMapScreen
{
public HelpScreen(@NonNull CarContext carContext, @NonNull Renderer surfaceRenderer)
public HelpScreen(@NonNull CarContext carContext, @NonNull SurfaceRenderer surfaceRenderer)
{
super(carContext, surfaceRenderer);
}
@NonNull
@Override
protected Template onGetTemplateImpl()
public Template onGetTemplate()
{
final MapWithContentTemplate.Builder builder = new MapWithContentTemplate.Builder();
builder.setMapController(UiHelpers.createMapController(getCarContext(), getSurfaceRenderer()));

View File

@@ -13,7 +13,7 @@ import androidx.car.app.model.Row;
import androidx.car.app.model.Template;
import androidx.car.app.navigation.model.MapWithContentTemplate;
import app.organicmaps.R;
import app.organicmaps.car.renderer.Renderer;
import app.organicmaps.car.SurfaceRenderer;
import app.organicmaps.car.screens.base.BaseMapScreen;
import app.organicmaps.car.util.ThemeUtils;
import app.organicmaps.car.util.Toggle;
@@ -33,14 +33,14 @@ public class SettingsScreen extends BaseMapScreen
void set(boolean newValue);
}
public SettingsScreen(@NonNull CarContext carContext, @NonNull Renderer surfaceRenderer)
public SettingsScreen(@NonNull CarContext carContext, @NonNull SurfaceRenderer surfaceRenderer)
{
super(carContext, surfaceRenderer);
}
@NonNull
@Override
protected Template onGetTemplateImpl()
public Template onGetTemplate()
{
final MapWithContentTemplate.Builder builder = new MapWithContentTemplate.Builder();
builder.setMapController(UiHelpers.createMapController(getCarContext(), getSurfaceRenderer()));

View File

@@ -12,7 +12,7 @@ import androidx.car.app.model.Template;
import androidx.car.app.navigation.model.MapWithContentTemplate;
import androidx.core.graphics.drawable.IconCompat;
import app.organicmaps.R;
import app.organicmaps.car.renderer.Renderer;
import app.organicmaps.car.SurfaceRenderer;
import app.organicmaps.car.screens.base.BaseMapScreen;
import app.organicmaps.car.util.ThemeUtils;
import app.organicmaps.car.util.UiHelpers;
@@ -24,7 +24,7 @@ public class ThemeScreen extends BaseMapScreen
@NonNull
private final CarIcon mRadioButtonSelectedIcon;
public ThemeScreen(@NonNull CarContext carContext, @NonNull Renderer surfaceRenderer)
public ThemeScreen(@NonNull CarContext carContext, @NonNull SurfaceRenderer surfaceRenderer)
{
super(carContext, surfaceRenderer);
mRadioButtonIcon =
@@ -35,7 +35,7 @@ public class ThemeScreen extends BaseMapScreen
@NonNull
@Override
protected Template onGetTemplateImpl()
public Template onGetTemplate()
{
final MapWithContentTemplate.Builder builder = new MapWithContentTemplate.Builder();
builder.setMapController(UiHelpers.createMapController(getCarContext(), getSurfaceRenderer()));

View File

@@ -12,7 +12,7 @@ import androidx.car.app.notification.CarPendingIntent;
import app.organicmaps.MwmApplication;
import app.organicmaps.api.Const;
import app.organicmaps.car.CarAppService;
import app.organicmaps.car.renderer.Renderer;
import app.organicmaps.car.SurfaceRenderer;
import app.organicmaps.car.screens.NavigationScreen;
import app.organicmaps.car.screens.search.SearchScreen;
import app.organicmaps.sdk.Framework;
@@ -30,7 +30,7 @@ public final class IntentUtils
private static final int SEARCH_IN_VIEWPORT_ZOOM = 16;
public static void processIntent(@NonNull CarContext carContext, @NonNull Renderer surfaceRenderer,
public static void processIntent(@NonNull CarContext carContext, @NonNull SurfaceRenderer surfaceRenderer,
@NonNull Intent intent)
{
final String action = intent.getAction();
@@ -50,8 +50,8 @@ public final class IntentUtils
}
// https://developer.android.com/reference/androidx/car/app/CarContext#startCarApp(android.content.Intent)
private static void processNavigationIntent(@NonNull CarContext carContext,
@NonNull Renderer surfaceRenderer, @NonNull Intent intent)
private static void processNavigationIntent(@NonNull CarContext carContext, @NonNull SurfaceRenderer surfaceRenderer,
@NonNull Intent intent)
{
// TODO (AndrewShkrob): This logic will need to be revised when we introduce support for adding stops during
// navigation or route planning. Skip navigation intents during navigation

View File

@@ -15,7 +15,7 @@ import androidx.car.app.navigation.model.MapController;
import androidx.core.graphics.drawable.IconCompat;
import app.organicmaps.MwmApplication;
import app.organicmaps.R;
import app.organicmaps.car.renderer.Renderer;
import app.organicmaps.car.SurfaceRenderer;
import app.organicmaps.car.screens.base.BaseMapScreen;
import app.organicmaps.car.screens.settings.SettingsScreen;
import app.organicmaps.sdk.Map;
@@ -33,14 +33,13 @@ public final class UiHelpers
{
@NonNull
public static ActionStrip createSettingsActionStrip(@NonNull BaseMapScreen mapScreen,
@NonNull Renderer surfaceRenderer)
@NonNull SurfaceRenderer surfaceRenderer)
{
return new ActionStrip.Builder().addAction(createSettingsAction(mapScreen, surfaceRenderer)).build();
}
@NonNull
public static ActionStrip createMapActionStrip(@NonNull CarContext context,
@NonNull Renderer surfaceRenderer)
public static ActionStrip createMapActionStrip(@NonNull CarContext context, @NonNull SurfaceRenderer surfaceRenderer)
{
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();
@@ -59,30 +58,27 @@ public final class UiHelpers
}
@NonNull
public static MapController createMapController(@NonNull CarContext context,
@NonNull Renderer surfaceRenderer)
public static MapController createMapController(@NonNull CarContext context, @NonNull SurfaceRenderer surfaceRenderer)
{
return new MapController.Builder().setMapActionStrip(createMapActionStrip(context, surfaceRenderer)).build();
}
@NonNull
public static Action createSettingsAction(@NonNull BaseMapScreen mapScreen,
@NonNull Renderer surfaceRenderer)
public static Action createSettingsAction(@NonNull BaseMapScreen mapScreen, @NonNull SurfaceRenderer surfaceRenderer)
{
return createSettingsAction(mapScreen, surfaceRenderer, null);
}
@NonNull
public static Action createSettingsActionForResult(@NonNull BaseMapScreen mapScreen,
@NonNull Renderer surfaceRenderer,
@NonNull SurfaceRenderer surfaceRenderer,
@NonNull OnScreenResultListener onScreenResultListener)
{
return createSettingsAction(mapScreen, surfaceRenderer, onScreenResultListener);
}
@NonNull
private static Action createSettingsAction(@NonNull BaseMapScreen mapScreen,
@NonNull Renderer surfaceRenderer,
private static Action createSettingsAction(@NonNull BaseMapScreen mapScreen, @NonNull SurfaceRenderer surfaceRenderer,
@Nullable OnScreenResultListener onScreenResultListener)
{
final CarContext context = mapScreen.getCarContext();
@@ -124,7 +120,7 @@ public final class UiHelpers
final Row.Builder builder = new Row.Builder();
builder.setImage(
new CarIcon.Builder(IconCompat.createWithResource(context, R.drawable.ic_opening_hours)).build());
new CarIcon.Builder(IconCompat.createWithResource(context, R.drawable.ic_operating_hours)).build());
if (isEmptyTT)
builder.setTitle(ohStr);

View File

@@ -40,6 +40,7 @@ public class EditTextDialogFragment extends BaseMwmDialogFragment
private String mHint;
private TextInputEditText mEtInput;
private TextInputLayout mEtInputLayout;
private Button mPositiveButton;
private Validator mInputValidator;
private OnTextSaveListener mTextSaveListener;
@@ -116,20 +117,21 @@ public class EditTextDialogFragment extends BaseMwmDialogFragment
AlertDialog editTextDialog = new MaterialAlertDialogBuilder(requireActivity(), R.style.MwmTheme_AlertDialog)
.setView(buildView())
.setNegativeButton(negativeButtonText, null)
.setPositiveButton(positiveButtonText, null)
.setPositiveButton(positiveButtonText,
(dialog, which) -> {
final String result = mEtInput.getText().toString();
processInput(result);
dismiss();
})
.create();
// Set up onClick listener for mPositiveButton.
// Wait till alert is shown to get mPositiveButton.
editTextDialog.setOnShowListener((dialog) -> {
Button positiveButton = editTextDialog.getButton(DialogInterface.BUTTON_POSITIVE);
positiveButton.setOnClickListener(view -> {
final String result = mEtInput.getText().toString();
if (validateInput(requireActivity(), result)) {
processInput(result);
editTextDialog.dismiss();
}
});
mPositiveButton = editTextDialog.getButton(DialogInterface.BUTTON_POSITIVE);
final FragmentActivity activity = getActivity();
if (activity == null)
return;
this.validateInput(activity, mInitialText);
});
// Setup validation on input edit.
@@ -147,16 +149,14 @@ public class EditTextDialogFragment extends BaseMwmDialogFragment
return editTextDialog;
}
private boolean validateInput(@NonNull FragmentActivity activity, @Nullable String input)
private void validateInput(@NonNull FragmentActivity activity, @Nullable String input)
{
if (mInputValidator != null)
if (mPositiveButton != null && mInputValidator != null)
{
final String maybeError = mInputValidator.validate(activity, input);
mPositiveButton.setEnabled(maybeError == null);
mEtInputLayout.getEditText().setError(maybeError);
mEtInputLayout.requestFocus();
return maybeError == null;
}
return false;
}
private void processInput(@Nullable String text)

View File

@@ -1,19 +1,13 @@
package app.organicmaps.editor;
import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Bundle;
import android.text.Editable;
import android.text.InputType;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.text.method.LinkMovementMethod;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AutoCompleteTextView;
import android.widget.GridLayout;
import android.widget.Toast;
import androidx.annotation.CallSuper;
import androidx.annotation.DrawableRes;
import androidx.annotation.IdRes;
@@ -28,7 +22,6 @@ import app.organicmaps.base.BaseMwmFragment;
import app.organicmaps.dialog.EditTextDialogFragment;
import app.organicmaps.editor.data.TimeFormatUtils;
import app.organicmaps.sdk.Framework;
import app.organicmaps.sdk.bookmarks.data.ChargeSocketDescriptor;
import app.organicmaps.sdk.bookmarks.data.Metadata;
import app.organicmaps.sdk.editor.Editor;
import app.organicmaps.sdk.editor.OpeningHours;
@@ -37,33 +30,26 @@ import app.organicmaps.sdk.editor.data.LocalizedStreet;
import app.organicmaps.sdk.editor.data.Timetable;
import app.organicmaps.sdk.util.StringUtils;
import app.organicmaps.sdk.util.Utils;
import app.organicmaps.sdk.util.log.Logger;
import app.organicmaps.util.Graphics;
import app.organicmaps.util.InputUtils;
import app.organicmaps.util.UiUtils;
import com.google.android.material.button.MaterialButton;
import com.google.android.material.card.MaterialCardView;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.imageview.ShapeableImageView;
import com.google.android.material.textfield.TextInputEditText;
import com.google.android.material.textfield.TextInputLayout;
import com.google.android.material.textview.MaterialTextView;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class EditorFragment extends BaseMwmFragment implements View.OnClickListener
{
final static String LAST_INDEX_OF_NAMES_ARRAY = "LastIndexOfNamesArray";
private static final String CHARGE_SOCKETS_TAG = "CHARGE_SOCKETS_TAG";
private MaterialTextView mCategory;
private View mCardName;
private View mCardAddress;
private View mCardChargingStation;
private View mCardDetails;
private View mCardSocialMedia;
private View mCardBuilding;
@@ -144,8 +130,6 @@ public class EditorFragment extends BaseMwmFragment implements View.OnClickListe
private TextInputLayout mInputHouseNumber;
private TextInputLayout mInputBuildingLevels;
private View mChargeSockets;
private View mEmptyOpeningHours;
private MaterialTextView mOpeningHours;
private View mEditOpeningHours;
@@ -222,7 +206,6 @@ public class EditorFragment extends BaseMwmFragment implements View.OnClickListe
mWifi.setChecked(Editor.nativeHasWifi());
// TODO Reimplement this to avoid https://github.com/organicmaps/organicmaps/issues/9049
// mOutdoorSeating.setChecked(Editor.nativeGetSwitchInput(Metadata.MetadataType.FMD_OUTDOOR_SEATING.toInt(),"yes"));
refreshChargeSockets();
refreshOpeningTime();
refreshEditableFields();
refreshResetButton();
@@ -346,14 +329,6 @@ public class EditorFragment extends BaseMwmFragment implements View.OnClickListe
final int[] editableDetails = Editor.nativeGetEditableProperties();
// charge sockets have their own card; check whether we should display it.
boolean hasChargeSockets = false;
for (int type : editableDetails)
{
hasChargeSockets = hasChargeSockets || (type == Metadata.MetadataType.FMD_CHARGE_SOCKETS.toInt());
}
UiUtils.showIf(hasChargeSockets, mCardChargingStation);
setCardVisibility(mCardDetails, mDetailsBlocks, editableDetails);
setCardVisibility(mCardSocialMedia, mSocialMediaBlocks, editableDetails);
}
@@ -376,283 +351,6 @@ public class EditorFragment extends BaseMwmFragment implements View.OnClickListe
UiUtils.showIf(anyBlockElement, card);
}
/**
* Builds a dialog for editing or adding a charge socket.
*
* @param socketIndex The index of the socket to edit, or -1 to add a new socket.
* @param type The current type of the socket (e.g., "type2", "type2_combo").
* @param count The current number of sockets of this type or 0 for new socket.
* @param power The current power output of the socket in kW or 0 for new socket.
* @return A MaterialAlertDialogBuilder instance for the configured dialog.
*/
private MaterialAlertDialogBuilder buildChargeSocketDialog(int socketIndex, String type, int count, double power)
{
LayoutInflater inflater = LayoutInflater.from(getActivity());
View dialogView = inflater.inflate(R.layout.dialog_edit_socket, null);
GridLayout typeBtns = dialogView.findViewById(R.id.edit_socket_type_grid);
typeBtns.removeAllViews();
List<String> SOCKET_TYPES = Arrays.stream(getResources().getStringArray(R.array.charge_socket_types)).toList();
for (String socket : SOCKET_TYPES)
{
MaterialButton btn = (MaterialButton) inflater.inflate(R.layout.button_socket_type, typeBtns, false);
btn.setTag(R.id.socket_type, socket);
// load SVG icon converted into VectorDrawable in res/drawable
@SuppressLint("DiscouragedApi")
int resIconId =
getResources().getIdentifier("ic_charge_socket_" + socket, "drawable", requireContext().getPackageName());
if (resIconId != 0)
{
btn.setIcon(getResources().getDrawable(resIconId));
}
@SuppressLint("DiscouragedApi")
int resTypeId =
getResources().getIdentifier("charge_socket_" + socket, "string", requireContext().getPackageName());
if (resTypeId != 0)
{
btn.setText(getResources().getString(resTypeId));
}
if (socket.equals(type))
{
btn.setChecked(true);
}
typeBtns.addView(btn);
}
// manage the grid of socket type buttons as a single 'radio group'
// (this can not be done with a MaterialButtonToggleGroup because it does
// not support GridLayout)
List<MaterialButton> buttonList = new ArrayList<>();
for (int i = 0; i < typeBtns.getChildCount(); i++)
{
View child = typeBtns.getChildAt(i);
if (child instanceof MaterialButton button)
{
buttonList.add(button);
button.setOnClickListener(view -> {
// deselect all
for (MaterialButton b : buttonList)
{
b.setChecked(false);
}
// select clicked
button.setChecked(true);
});
}
}
TextInputLayout countInputLayout = dialogView.findViewById(R.id.edit_socket_count_layout);
AutoCompleteTextView countView = dialogView.findViewById(R.id.edit_socket_count);
if (count > 0)
{
countView.setText(String.valueOf(count));
}
// Add a TextWatcher to validate on text change
countView.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {}
@Override
public void afterTextChanged(Editable s) {
validatePositiveField(s.toString(), countInputLayout);
}
});
TextInputLayout powerInputLayout = dialogView.findViewById(R.id.edit_socket_power_layout);
AutoCompleteTextView powerView = dialogView.findViewById(R.id.edit_socket_power);
if (power > 0)
{
powerView.setText(String.valueOf(power));
}
// Add a TextWatcher to validate on text change
powerView.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {}
@Override
public void afterTextChanged(Editable s) {
validatePositiveField(s.toString(), powerInputLayout);
}
});
return new MaterialAlertDialogBuilder(requireActivity(), R.style.MwmTheme_AlertDialog)
.setTitle(R.string.editor_socket)
.setView(dialogView)
.setPositiveButton(R.string.save,
(dialog, which) -> {
String socketType = "";
for (MaterialButton b : buttonList)
{
if (b.isChecked())
{
socketType = b.getTag(R.id.socket_type).toString();
break;
}
}
int countValue = 0; // 0 means 'unknown count'
try
{
countValue = Integer.parseInt(countView.getText().toString());
}
catch (NumberFormatException ignored)
{
Logger.w(CHARGE_SOCKETS_TAG, "Invalid count value for socket:" + countView.getText().toString());
}
if (countValue < 0)
{
countValue = 0;
Logger.w(CHARGE_SOCKETS_TAG, "Invalid count value for socket:" + countView.getText().toString());
}
double powerValue = 0; // 0 means 'unknown power'
try
{
powerValue = Double.parseDouble(powerView.getText().toString());
}
catch (NumberFormatException ignored)
{
Logger.w(CHARGE_SOCKETS_TAG, "Invalid power value for socket:" + powerView.getText().toString());
}
if (powerValue < 0)
{
powerValue = 0;
Logger.w(CHARGE_SOCKETS_TAG, "Invalid power value for socket:" + powerView.getText().toString());
}
ChargeSocketDescriptor socket =
new ChargeSocketDescriptor(socketType, countValue, powerValue);
updateChargeSockets(socketIndex, socket);
})
.setNegativeButton(R.string.cancel, (dialog, which) -> { dialog.dismiss(); });
}
// Helper method for validation logic
private boolean validatePositiveField(String text, TextInputLayout layout) {
if (text.isEmpty()) {
layout.setError(null); // No error if empty (assuming 0 is the default)
return true;
}
try {
double value = Double.parseDouble(text);
if (value < 0) {
layout.setError(getString(R.string.error_value_must_be_positive));
return false;
} else {
layout.setError(null);
return true;
}
} catch (NumberFormatException e) {
layout.setError(getString(R.string.error_invalid_number));
return false;
}
}
/**
* Updates the list of charge sockets.
* If socketIndex is >=0, it updates the socket at that index.
* Otherwise, it adds the new socket to the list.
*
* @param socketIndex The index of the socket to update, or -1 to add a new socket.
* @param socket The ChargeSocketDescriptor of the socket to add or update.
*/
private void updateChargeSockets(int socketIndex, ChargeSocketDescriptor socket)
{
ChargeSocketDescriptor[] sockets = Editor.nativeGetChargeSockets();
if (socketIndex >= 0)
{
sockets[socketIndex] = socket;
}
else {
List<ChargeSocketDescriptor> list = new ArrayList<>(Arrays.asList(sockets));
list.add(socket);
sockets = list.toArray(new ChargeSocketDescriptor[0]);
}
Editor.nativeSetChargeSockets(sockets);
refreshChargeSockets();
}
private void refreshChargeSockets()
{
ChargeSocketDescriptor[] sockets = Editor.nativeGetChargeSockets();
LayoutInflater inflater = LayoutInflater.from(requireContext());
GridLayout socketsGrid = mChargeSockets.findViewById(R.id.socket_grid_editor);
socketsGrid.removeAllViews();
for (int i = 0; i < sockets.length; i++)
{
final int currentIndex = i;
ChargeSocketDescriptor socket = sockets[i];
View itemView = inflater.inflate(R.layout.item_charge_socket, socketsGrid, false);
MaterialTextView type = itemView.findViewById(R.id.socket_type);
ShapeableImageView icon = itemView.findViewById(R.id.socket_icon);
MaterialTextView power = itemView.findViewById(R.id.socket_power);
MaterialTextView count = itemView.findViewById(R.id.socket_count);
// load SVG icon converted into VectorDrawable in res/drawable
@SuppressLint("DiscouragedApi")
int resIconId = getResources().getIdentifier("ic_charge_socket_" + socket.type(), "drawable",
requireContext().getPackageName());
if (resIconId != 0)
{
icon.setImageResource(resIconId);
}
@SuppressLint("DiscouragedApi")
int resTypeId =
getResources().getIdentifier("charge_socket_" + socket.type(), "string", requireContext().getPackageName());
if (resTypeId != 0)
{
type.setText(resTypeId);
}
if (socket.power() != 0)
{
DecimalFormat df = new DecimalFormat("#.##");
power.setText(getString(R.string.kw_label, df.format(socket.power())));
}
if (socket.count() != 0)
{
count.setText(getString(R.string.count_label, socket.count()));
}
itemView.setOnClickListener(v -> {
buildChargeSocketDialog(currentIndex, socket.type(), socket.count(), socket.power()).show();
});
socketsGrid.addView(itemView);
}
// add a 'new item' button at the end, to create new sockets
View btnNewItemView = inflater.inflate(R.layout.button_new_item, socketsGrid, false);
btnNewItemView.setOnClickListener(v -> {
buildChargeSocketDialog(-1, "unknown", -1, -1).show();
});
socketsGrid.addView(btnNewItemView);
}
private void refreshOpeningTime()
{
final String openingHours = Editor.nativeGetOpeningHours();
@@ -737,7 +435,6 @@ public class EditorFragment extends BaseMwmFragment implements View.OnClickListe
mCategory = categoryBlock.findViewById(R.id.name);
mCardName = view.findViewById(R.id.cv__name);
mCardAddress = view.findViewById(R.id.cv__address);
mCardChargingStation = view.findViewById(R.id.cv__charging_station);
mCardDetails = view.findViewById(R.id.cv__details);
mCardSocialMedia = view.findViewById(R.id.cv__social_media);
mCardBuilding = view.findViewById(R.id.cv__building);
@@ -810,9 +507,6 @@ public class EditorFragment extends BaseMwmFragment implements View.OnClickListe
View blockOutdoorSeating = view.findViewById(R.id.block_outdoor_seating);
mOutdoorSeating = view.findViewById(R.id.sw__outdoor_seating);
blockOutdoorSeating.setOnClickListener(this);
mChargeSockets = view.findViewById(R.id.block_charge_sockets);
View blockOpeningHours = view.findViewById(R.id.block_opening_hours);
mEditOpeningHours = blockOpeningHours.findViewById(R.id.edit_opening_hours);
mEditOpeningHours.setOnClickListener(this);
@@ -1007,7 +701,7 @@ public class EditorFragment extends BaseMwmFragment implements View.OnClickListe
private void placeDoesntExist()
{
EditTextDialogFragment dialogFragment = EditTextDialogFragment.show(
getString(R.string.editor_place_doesnt_exist), "", getString(R.string.editor_place_doesnt_exist_description),
getString(R.string.editor_place_doesnt_exist), "", getString(R.string.editor_comment_hint),
getString(R.string.editor_report_problem_send_button), getString(R.string.cancel), this,
getDeleteCommentValidator());
dialogFragment.setTextSaveListener(this::commitPlaceDoesntExists);

View File

@@ -13,6 +13,7 @@ import android.widget.TextView;
import android.widget.TimePicker;
import androidx.annotation.IntRange;
import androidx.annotation.NonNull;
import androidx.annotation.StyleRes;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.content.res.AppCompatResources;
import androidx.fragment.app.FragmentManager;
@@ -20,6 +21,7 @@ import app.organicmaps.R;
import app.organicmaps.base.BaseMwmDialogFragment;
import app.organicmaps.sdk.editor.data.HoursMinutes;
import app.organicmaps.sdk.util.DateUtils;
import app.organicmaps.util.ThemeUtils;
import app.organicmaps.util.Utils;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.tabs.TabLayout;
@@ -77,13 +79,15 @@ public class HoursMinutesPickerFragment extends BaseMwmDialogFragment
// noinspection ConstantConditions
mTabs.getTabAt(mSelectedTab).select();
final AlertDialog dialog =
new MaterialAlertDialogBuilder(requireActivity(), R.style.MwmMain_DialogFragment_TimePicker)
.setView(root)
.setNegativeButton(R.string.cancel, null)
.setPositiveButton(R.string.ok, null)
.setCancelable(true)
.create();
@StyleRes
final int theme = ThemeUtils.isNightTheme() ? R.style.MwmMain_DialogFragment_TimePicker_Night
: R.style.MwmMain_DialogFragment_TimePicker;
final AlertDialog dialog = new MaterialAlertDialogBuilder(requireActivity(), theme)
.setView(root)
.setNegativeButton(R.string.cancel, null)
.setPositiveButton(R.string.ok, null)
.setCancelable(true)
.create();
dialog.setOnShowListener(dialogInterface -> {
mOkButton = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
@@ -137,8 +141,9 @@ public class HoursMinutesPickerFragment extends BaseMwmDialogFragment
mTabs = root.findViewById(R.id.tabs);
MaterialTextView tabView = (MaterialTextView) inflater.inflate(R.layout.tab_timepicker, mTabs, false);
tabView.setText(getResources().getString(R.string.editor_time_from));
final ColorStateList textColor =
AppCompatResources.getColorStateList(requireContext(), R.color.accent_color_selector);
final ColorStateList textColor = AppCompatResources.getColorStateList(
requireContext(),
ThemeUtils.isNightTheme() ? R.color.accent_color_selector_night : R.color.accent_color_selector);
tabView.setTextColor(textColor);
mTabs.addTab(mTabs.newTab().setCustomView(tabView), true);
tabView = (MaterialTextView) inflater.inflate(R.layout.tab_timepicker, mTabs, false);

View File

@@ -22,6 +22,7 @@ import app.organicmaps.util.UiUtils;
import app.organicmaps.util.Utils;
import app.organicmaps.util.WindowInsetUtils;
import app.organicmaps.widget.StackedButtonDialogFragment;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.imageview.ShapeableImageView;
import com.google.android.material.textview.MaterialTextView;
import java.text.NumberFormat;
@@ -134,7 +135,14 @@ public class ProfileFragment extends BaseMwmToolbarFragment
private void logout()
{
OsmOAuth.clearAuthorization();
refreshViews();
new MaterialAlertDialogBuilder(requireContext(), R.style.MwmTheme_AlertDialog)
.setMessage(R.string.osm_log_out_confirmation)
.setPositiveButton(R.string.yes,
(dialog, which) -> {
OsmOAuth.clearAuthorization();
refreshViews();
})
.setNegativeButton(R.string.no, null)
.show();
}
}

View File

@@ -1,131 +0,0 @@
package app.organicmaps.location;
import android.util.Base64;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.json.JSONException;
import org.json.JSONObject;
import java.nio.charset.StandardCharsets;
import java.security.SecureRandom;
import javax.crypto.Cipher;
import javax.crypto.spec.GCMParameterSpec;
import javax.crypto.spec.SecretKeySpec;
/**
* AES-256-GCM encryption/decryption for location data.
*/
public class LocationCrypto
{
private static final String ALGORITHM = "AES/GCM/NoPadding";
private static final int GCM_IV_LENGTH = 12; // 96 bits
private static final int GCM_TAG_LENGTH = 128; // 128 bits
/**
* Encrypt plaintext JSON using AES-256-GCM.
* @param base64Key Base64-encoded 256-bit key
* @param plaintextJson JSON string to encrypt
* @return JSON string with encrypted payload: {"iv":"...","ciphertext":"...","authTag":"..."}
*/
@Nullable
public static String encrypt(@NonNull String base64Key, @NonNull String plaintextJson)
{
try
{
// Decode the base64 key
byte[] key = Base64.decode(base64Key, Base64.NO_WRAP);
if (key.length != 32) // 256 bits
{
android.util.Log.e("LocationCrypto", "Invalid key size: " + key.length);
return null;
}
// Generate random IV
byte[] iv = new byte[GCM_IV_LENGTH];
new SecureRandom().nextBytes(iv);
// Create cipher
Cipher cipher = Cipher.getInstance(ALGORITHM);
SecretKeySpec keySpec = new SecretKeySpec(key, "AES");
GCMParameterSpec gcmSpec = new GCMParameterSpec(GCM_TAG_LENGTH, iv);
cipher.init(Cipher.ENCRYPT_MODE, keySpec, gcmSpec);
// Encrypt
byte[] plaintext = plaintextJson.getBytes(StandardCharsets.UTF_8);
byte[] ciphertextWithTag = cipher.doFinal(plaintext);
// Split ciphertext and auth tag
// In GCM mode, doFinal() returns ciphertext + tag
int ciphertextLength = ciphertextWithTag.length - (GCM_TAG_LENGTH / 8);
byte[] ciphertext = new byte[ciphertextLength];
byte[] authTag = new byte[GCM_TAG_LENGTH / 8];
System.arraycopy(ciphertextWithTag, 0, ciphertext, 0, ciphertextLength);
System.arraycopy(ciphertextWithTag, ciphertextLength, authTag, 0, authTag.length);
// Build JSON response
JSONObject result = new JSONObject();
result.put("iv", Base64.encodeToString(iv, Base64.NO_WRAP));
result.put("ciphertext", Base64.encodeToString(ciphertext, Base64.NO_WRAP));
result.put("authTag", Base64.encodeToString(authTag, Base64.NO_WRAP));
return result.toString();
}
catch (Exception e)
{
android.util.Log.e("LocationCrypto", "Encryption failed", e);
return null;
}
}
/**
* Decrypt encrypted payload using AES-256-GCM.
* @param base64Key Base64-encoded 256-bit key
* @param encryptedPayloadJson JSON string with format: {"iv":"...","ciphertext":"...","authTag":"..."}
* @return Decrypted plaintext JSON string
*/
@Nullable
public static String decrypt(@NonNull String base64Key, @NonNull String encryptedPayloadJson)
{
try
{
// Parse encrypted payload
JSONObject payload = new JSONObject(encryptedPayloadJson);
byte[] iv = Base64.decode(payload.getString("iv"), Base64.NO_WRAP);
byte[] ciphertext = Base64.decode(payload.getString("ciphertext"), Base64.NO_WRAP);
byte[] authTag = Base64.decode(payload.getString("authTag"), Base64.NO_WRAP);
// Decode the base64 key
byte[] key = Base64.decode(base64Key, Base64.NO_WRAP);
if (key.length != 32) // 256 bits
{
android.util.Log.e("LocationCrypto", "Invalid key size: " + key.length);
return null;
}
// Combine ciphertext and auth tag for GCM decryption
byte[] ciphertextWithTag = new byte[ciphertext.length + authTag.length];
System.arraycopy(ciphertext, 0, ciphertextWithTag, 0, ciphertext.length);
System.arraycopy(authTag, 0, ciphertextWithTag, ciphertext.length, authTag.length);
// Create cipher
Cipher cipher = Cipher.getInstance(ALGORITHM);
SecretKeySpec keySpec = new SecretKeySpec(key, "AES");
GCMParameterSpec gcmSpec = new GCMParameterSpec(GCM_TAG_LENGTH, iv);
cipher.init(Cipher.DECRYPT_MODE, keySpec, gcmSpec);
// Decrypt
byte[] plaintext = cipher.doFinal(ciphertextWithTag);
return new String(plaintext, StandardCharsets.UTF_8);
}
catch (Exception e)
{
android.util.Log.e("LocationCrypto", "Decryption failed", e);
return null;
}
}
}

View File

@@ -1,220 +0,0 @@
package app.organicmaps.location;
import android.app.Dialog;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.FragmentManager;
import app.organicmaps.R;
import app.organicmaps.util.SharingUtils;
/**
* Dialog for starting/stopping live location sharing and managing the share URL.
*/
public class LocationSharingDialog extends DialogFragment
{
private static final String TAG = LocationSharingDialog.class.getSimpleName();
@Nullable
private TextView mStatusText;
@Nullable
private TextView mShareUrlText;
@Nullable
private Button mStartStopButton;
@Nullable
private Button mCopyButton;
@Nullable
private Button mShareButton;
private LocationSharingManager mManager;
public static void show(@NonNull FragmentManager fragmentManager)
{
LocationSharingDialog dialog = new LocationSharingDialog();
dialog.show(fragmentManager, TAG);
}
@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState)
{
mManager = LocationSharingManager.getInstance();
AlertDialog.Builder builder = new AlertDialog.Builder(requireContext());
View view = LayoutInflater.from(getContext()).inflate(R.layout.dialog_location_sharing, null);
initViews(view);
updateUI();
builder.setView(view);
builder.setTitle(R.string.location_sharing_title);
builder.setNegativeButton(R.string.close, (dialog, which) -> dismiss());
return builder.create();
}
private void initViews(@NonNull View root)
{
mStatusText = root.findViewById(R.id.status_text);
mShareUrlText = root.findViewById(R.id.share_url_text);
mStartStopButton = root.findViewById(R.id.start_stop_button);
mCopyButton = root.findViewById(R.id.copy_button);
mShareButton = root.findViewById(R.id.share_button);
if (mStartStopButton != null)
{
mStartStopButton.setOnClickListener(v -> {
if (mManager.isSharing())
stopSharing();
else
startSharing();
});
}
if (mCopyButton != null)
{
mCopyButton.setOnClickListener(v -> copyUrl());
}
if (mShareButton != null)
{
mShareButton.setOnClickListener(v -> shareUrl());
}
}
private void updateUI()
{
boolean isSharing = mManager.isSharing();
if (mStatusText != null)
{
mStatusText.setText(isSharing
? R.string.location_sharing_status_active
: R.string.location_sharing_status_inactive);
}
if (mShareUrlText != null)
{
String url = mManager.getShareUrl();
if (url != null && isSharing)
{
mShareUrlText.setText(url);
mShareUrlText.setVisibility(View.VISIBLE);
}
else
{
mShareUrlText.setVisibility(View.GONE);
}
}
if (mStartStopButton != null)
{
mStartStopButton.setText(isSharing
? R.string.location_sharing_stop
: R.string.location_sharing_start);
}
// Show/hide copy and share buttons
int visibility = isSharing ? View.VISIBLE : View.GONE;
if (mCopyButton != null)
mCopyButton.setVisibility(visibility);
if (mShareButton != null)
mShareButton.setVisibility(visibility);
}
private void startSharing()
{
String shareUrl = mManager.startSharing();
if (shareUrl != null)
{
Toast.makeText(requireContext(),
R.string.location_sharing_started,
Toast.LENGTH_SHORT).show();
updateUI();
// Notify the activity
if (getActivity() instanceof app.organicmaps.MwmActivity)
{
((app.organicmaps.MwmActivity) getActivity()).onLocationSharingStateChanged(true);
}
// Auto-copy URL to clipboard
copyUrlToClipboard(shareUrl);
}
else
{
Toast.makeText(requireContext(),
R.string.location_sharing_failed_to_start,
Toast.LENGTH_LONG).show();
}
}
private void stopSharing()
{
mManager.stopSharing();
Toast.makeText(requireContext(),
R.string.location_sharing_stopped,
Toast.LENGTH_SHORT).show();
updateUI();
// Notify the activity
if (getActivity() instanceof app.organicmaps.MwmActivity)
{
((app.organicmaps.MwmActivity) getActivity()).onLocationSharingStateChanged(false);
}
}
private void copyUrl()
{
String url = mManager.getShareUrl();
if (url != null)
{
copyUrlToClipboard(url);
}
}
private void copyUrlToClipboard(@NonNull String url)
{
ClipboardManager clipboard = (ClipboardManager)
requireContext().getSystemService(Context.CLIPBOARD_SERVICE);
if (clipboard != null)
{
ClipData clip = ClipData.newPlainText("Location Share URL", url);
clipboard.setPrimaryClip(clip);
Toast.makeText(requireContext(),
R.string.location_sharing_url_copied,
Toast.LENGTH_SHORT).show();
}
}
private void shareUrl()
{
String url = mManager.getShareUrl();
if (url == null)
return;
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_TEXT, getString(R.string.location_sharing_share_message, url));
startActivity(Intent.createChooser(shareIntent, getString(R.string.location_sharing_share_url)));
}
}

View File

@@ -1,205 +0,0 @@
package app.organicmaps.location;
import android.content.Context;
import android.content.Intent;
import android.os.BatteryManager;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import app.organicmaps.MwmApplication;
import app.organicmaps.sdk.routing.RoutingController;
import app.organicmaps.sdk.util.Config;
import app.organicmaps.sdk.util.log.Logger;
/**
* Singleton manager for live location sharing functionality.
* Coordinates between LocationHelper, RoutingController, and LocationSharingService.
*/
public class LocationSharingManager
{
private static final String TAG = LocationSharingManager.class.getSimpleName();
private static LocationSharingManager sInstance;
@Nullable
private String mSessionId;
@Nullable
private String mEncryptionKey;
@Nullable
private String mShareUrl;
private boolean mIsSharing = false;
private final Context mContext;
private LocationSharingManager()
{
mContext = MwmApplication.sInstance;
}
@NonNull
public static synchronized LocationSharingManager getInstance()
{
if (sInstance == null)
sInstance = new LocationSharingManager();
return sInstance;
}
/**
* Start live location sharing.
* @return Share URL that can be sent to others
*/
@Nullable
public String startSharing()
{
if (mIsSharing)
{
Logger.w(TAG, "Location sharing already active");
return mShareUrl;
}
// Generate session credentials via native code
String[] credentials = nativeGenerateSessionCredentials();
if (credentials == null || credentials.length != 2)
{
Logger.e(TAG, "Failed to generate session credentials");
return null;
}
mSessionId = credentials[0];
mEncryptionKey = credentials[1];
// Generate share URL using configured server
String serverUrl = Config.LocationSharing.getServerUrl();
mShareUrl = nativeGenerateShareUrl(mSessionId, mEncryptionKey, serverUrl);
if (mShareUrl == null)
{
Logger.e(TAG, "Failed to generate share URL");
return null;
}
mIsSharing = true;
// Start foreground service
Intent intent = new Intent(mContext, LocationSharingService.class);
intent.putExtra(LocationSharingService.EXTRA_SESSION_ID, mSessionId);
intent.putExtra(LocationSharingService.EXTRA_ENCRYPTION_KEY, mEncryptionKey);
intent.putExtra(LocationSharingService.EXTRA_SERVER_URL, serverUrl);
intent.putExtra(LocationSharingService.EXTRA_UPDATE_INTERVAL, Config.LocationSharing.getUpdateInterval());
mContext.startForegroundService(intent);
Logger.i(TAG, "Location sharing started, session ID: " + mSessionId);
return mShareUrl;
}
/**
* Stop live location sharing.
*/
public void stopSharing()
{
if (!mIsSharing)
{
Logger.w(TAG, "Location sharing not active");
return;
}
// Stop foreground service
Intent intent = new Intent(mContext, LocationSharingService.class);
mContext.stopService(intent);
mIsSharing = false;
mSessionId = null;
mEncryptionKey = null;
mShareUrl = null;
Logger.i(TAG, "Location sharing stopped");
}
public boolean isSharing()
{
return mIsSharing;
}
@Nullable
public String getShareUrl()
{
return mShareUrl;
}
@Nullable
public String getSessionId()
{
return mSessionId;
}
public void setUpdateIntervalSeconds(int seconds)
{
Config.LocationSharing.setUpdateInterval(seconds);
}
public int getUpdateIntervalSeconds()
{
return Config.LocationSharing.getUpdateInterval();
}
public void setServerBaseUrl(@NonNull String url)
{
Config.LocationSharing.setServerUrl(url);
}
@NonNull
public String getServerBaseUrl()
{
return Config.LocationSharing.getServerUrl();
}
/**
* Get current battery level (0-100).
*/
public int getBatteryLevel()
{
BatteryManager bm = (BatteryManager) mContext.getSystemService(Context.BATTERY_SERVICE);
if (bm == null)
return 100;
return bm.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY);
}
/**
* Check if currently navigating with an active route.
*/
public boolean isNavigating()
{
return RoutingController.get().isNavigating();
}
// Native methods (implemented in JNI)
/**
* Generate new session credentials (ID and encryption key).
* @return Array of [sessionId, encryptionKey]
*/
@Nullable
private static native String[] nativeGenerateSessionCredentials();
/**
* Generate shareable URL from credentials.
* @param sessionId Session ID (UUID)
* @param encryptionKey Base64-encoded encryption key
* @param serverBaseUrl Server base URL
* @return Share URL
*/
@Nullable
private static native String nativeGenerateShareUrl(String sessionId, String encryptionKey, String serverBaseUrl);
/**
* Encrypt location payload.
* @param encryptionKey Base64-encoded encryption key
* @param payloadJson JSON payload to encrypt
* @return Encrypted payload JSON (with iv, ciphertext, authTag) or null on failure
*/
@Nullable
public static native String nativeEncryptPayload(String encryptionKey, String payloadJson);
}

View File

@@ -1,146 +0,0 @@
package app.organicmaps.location;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.location.Location;
import android.os.Build;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationManagerCompat;
import app.organicmaps.MwmActivity;
import app.organicmaps.R;
import app.organicmaps.sdk.routing.RoutingInfo;
import java.util.Locale;
/**
* Helper for creating and updating location sharing notifications.
*/
public class LocationSharingNotification
{
public static final String CHANNEL_ID = "LOCATION_SHARING";
private static final String CHANNEL_NAME = "Live Location Sharing";
private final Context mContext;
private final NotificationManagerCompat mNotificationManager;
public LocationSharingNotification(@NonNull Context context)
{
mContext = context;
mNotificationManager = NotificationManagerCompat.from(context);
createNotificationChannel();
}
private void createNotificationChannel()
{
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O)
return;
NotificationChannel channel = new NotificationChannel(
CHANNEL_ID,
CHANNEL_NAME,
NotificationManager.IMPORTANCE_LOW); // Low importance = no sound/vibration
channel.setDescription("Notifications for active live location sharing");
channel.setShowBadge(false);
channel.enableLights(false);
channel.enableVibration(false);
NotificationManager nm = mContext.getSystemService(NotificationManager.class);
if (nm != null)
nm.createNotificationChannel(channel);
}
/**
* Build notification for location sharing service.
* @param stopIntent PendingIntent to stop sharing
* @return Notification object
*/
@NonNull
public Notification buildNotification(@NonNull PendingIntent stopIntent)
{
return buildNotification(stopIntent, null);
}
/**
* Build notification with copy URL action.
* @param stopIntent PendingIntent to stop sharing
* @param copyUrlIntent PendingIntent to copy URL (optional)
* @return Notification object
*/
@NonNull
public Notification buildNotification(
@NonNull PendingIntent stopIntent,
@Nullable PendingIntent copyUrlIntent)
{
Intent notificationIntent = new Intent(mContext, MwmActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(
mContext,
0,
notificationIntent,
PendingIntent.FLAG_IMMUTABLE);
NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext, CHANNEL_ID)
.setSmallIcon(R.drawable.ic_share)
.setContentIntent(pendingIntent)
.setOngoing(true)
.setPriority(NotificationCompat.PRIORITY_LOW)
.setCategory(NotificationCompat.CATEGORY_SERVICE)
.setShowWhen(false)
.setAutoCancel(false);
// Title
builder.setContentTitle(mContext.getString(R.string.location_sharing_active));
// No subtitle - keep it simple
// Copy URL action button (if provided)
if (copyUrlIntent != null)
{
builder.addAction(
R.drawable.ic_share,
mContext.getString(R.string.location_sharing_copy_url),
copyUrlIntent);
}
// Stop action button
builder.addAction(
R.drawable.ic_close,
mContext.getString(R.string.location_sharing_stop),
stopIntent);
// Set foreground service type for Android 10+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)
{
builder.setForegroundServiceBehavior(NotificationCompat.FOREGROUND_SERVICE_IMMEDIATE);
}
return builder.build();
}
/**
* Update existing notification.
* @param notificationId Notification ID
* @param notification Updated notification
*/
public void updateNotification(int notificationId, @NonNull Notification notification)
{
mNotificationManager.notify(notificationId, notification);
}
/**
* Cancel notification.
* @param notificationId Notification ID
*/
public void cancelNotification(int notificationId)
{
mNotificationManager.cancel(notificationId);
}
}

View File

@@ -1,366 +0,0 @@
package app.organicmaps.location;
import android.app.Notification;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Intent;
import android.location.Location;
import android.os.BatteryManager;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.app.NotificationCompat;
import app.organicmaps.MwmActivity;
import app.organicmaps.MwmApplication;
import app.organicmaps.R;
import app.organicmaps.api.LocationSharingApiClient;
import app.organicmaps.sdk.location.LocationHelper;
import app.organicmaps.sdk.location.LocationListener;
import app.organicmaps.sdk.routing.RoutingController;
import app.organicmaps.sdk.routing.RoutingInfo;
import app.organicmaps.sdk.util.log.Logger;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.Locale;
/**
* Foreground service for live GPS location sharing.
* Monitors location updates and posts encrypted data to server at regular intervals.
*/
public class LocationSharingService extends Service implements LocationListener
{
private static final String TAG = LocationSharingService.class.getSimpleName();
private static final int NOTIFICATION_ID = 0x1002; // Unique ID for location sharing
// Intent extras
public static final String EXTRA_SESSION_ID = "session_id";
public static final String EXTRA_ENCRYPTION_KEY = "encryption_key";
public static final String EXTRA_SERVER_URL = "server_url";
public static final String EXTRA_UPDATE_INTERVAL = "update_interval";
// Actions for notification buttons
private static final String ACTION_STOP = "app.organicmaps.ACTION_STOP_LOCATION_SHARING";
private static final String ACTION_COPY_URL = "app.organicmaps.ACTION_COPY_LOCATION_URL";
@Nullable
private String mSessionId;
@Nullable
private String mEncryptionKey;
@Nullable
private String mServerUrl;
private int mUpdateIntervalSeconds = 20;
@Nullable
private Location mLastLocation;
private long mLastUpdateTimestamp = 0;
private final Handler mHandler = new Handler(Looper.getMainLooper());
private final Runnable mUpdateTask = this::processLocationUpdate;
@Nullable
private LocationSharingApiClient mApiClient;
@Nullable
private LocationSharingNotification mNotificationHelper;
@Override
public void onCreate()
{
super.onCreate();
Logger.i(TAG, "Service created");
mNotificationHelper = new LocationSharingNotification(this);
}
@Override
public int onStartCommand(@Nullable Intent intent, int flags, int startId)
{
if (intent == null)
{
Logger.w(TAG, "Null intent, stopping service");
stopSelf();
return START_NOT_STICKY;
}
// Handle stop action from notification
if (ACTION_STOP.equals(intent.getAction()))
{
Logger.i(TAG, "Stop action received from notification");
LocationSharingManager.getInstance().stopSharing();
stopSelf();
return START_NOT_STICKY;
}
// Handle copy URL action from notification
if (ACTION_COPY_URL.equals(intent.getAction()))
{
Logger.i(TAG, "Copy URL action received from notification");
String shareUrl = LocationSharingManager.getInstance().getShareUrl();
if (shareUrl != null)
{
android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
android.content.ClipData clip = android.content.ClipData.newPlainText("Location Share URL", shareUrl);
clipboard.setPrimaryClip(clip);
android.widget.Toast.makeText(this, R.string.location_sharing_url_copied, android.widget.Toast.LENGTH_SHORT).show();
}
return START_STICKY;
}
// Extract session info
mSessionId = intent.getStringExtra(EXTRA_SESSION_ID);
mEncryptionKey = intent.getStringExtra(EXTRA_ENCRYPTION_KEY);
mServerUrl = intent.getStringExtra(EXTRA_SERVER_URL);
mUpdateIntervalSeconds = intent.getIntExtra(EXTRA_UPDATE_INTERVAL, 20);
if (mSessionId == null || mEncryptionKey == null || mServerUrl == null)
{
Logger.e(TAG, "Missing session info, stopping service");
stopSelf();
return START_NOT_STICKY;
}
// Initialize API client
mApiClient = new LocationSharingApiClient(mServerUrl, mSessionId);
// Create session on server
mApiClient.createSession(new LocationSharingApiClient.Callback()
{
@Override
public void onSuccess()
{
Logger.i(TAG, "Session created on server");
}
@Override
public void onFailure(@NonNull String error)
{
Logger.w(TAG, "Failed to create session on server: " + error);
}
});
// Start foreground with notification
Notification notification = mNotificationHelper != null
? mNotificationHelper.buildNotification(getStopIntent(), getCopyUrlIntent())
: buildFallbackNotification();
startForeground(NOTIFICATION_ID, notification);
// Register for location updates
LocationHelper locationHelper = MwmApplication.sInstance.getLocationHelper();
locationHelper.addListener(this);
Logger.i(TAG, "Service started for session: " + mSessionId);
return START_STICKY;
}
@Override
public void onDestroy()
{
Logger.i(TAG, "Service destroyed");
// Unregister location listener
LocationHelper locationHelper = MwmApplication.sInstance.getLocationHelper();
locationHelper.removeListener(this);
// Cancel pending updates
mHandler.removeCallbacks(mUpdateTask);
// Send session end to server (optional)
if (mApiClient != null && mSessionId != null)
mApiClient.endSession();
super.onDestroy();
}
@Nullable
@Override
public IBinder onBind(Intent intent)
{
return null; // Not a bound service
}
// LocationHelper.LocationListener implementation
@Override
public void onLocationUpdated(@NonNull Location location)
{
mLastLocation = location;
// No need to update notification - it's simple and static now
// Schedule update if needed
scheduleUpdate();
}
// Private methods
private void scheduleUpdate()
{
long now = System.currentTimeMillis();
long timeSinceLastUpdate = (now - mLastUpdateTimestamp) / 1000; // Convert to seconds
if (timeSinceLastUpdate >= mUpdateIntervalSeconds)
{
// Remove any pending updates
mHandler.removeCallbacks(mUpdateTask);
// Execute immediately
mHandler.post(mUpdateTask);
}
}
private void processLocationUpdate()
{
if (mLastLocation == null || mEncryptionKey == null || mApiClient == null)
return;
// Check battery level
int batteryLevel = getBatteryLevel();
if (batteryLevel < 10)
{
Logger.w(TAG, "Battery level too low (" + batteryLevel + "%), stopping sharing");
LocationSharingManager.getInstance().stopSharing();
stopSelf();
return;
}
// Build payload JSON
JSONObject payload = buildPayloadJson(mLastLocation, batteryLevel);
if (payload == null)
return;
// Encrypt payload
String encryptedJson = LocationCrypto.encrypt(mEncryptionKey, payload.toString());
if (encryptedJson == null)
{
Logger.e(TAG, "Failed to encrypt payload");
return;
}
// Send to server
mApiClient.updateLocation(encryptedJson, new LocationSharingApiClient.Callback()
{
@Override
public void onSuccess()
{
Logger.d(TAG, "Location update sent successfully");
mLastUpdateTimestamp = System.currentTimeMillis();
}
@Override
public void onFailure(@NonNull String error)
{
Logger.w(TAG, "Failed to send location update: " + error);
}
});
}
@Nullable
private JSONObject buildPayloadJson(@NonNull Location location, int batteryLevel)
{
try
{
JSONObject json = new JSONObject();
json.put("timestamp", System.currentTimeMillis() / 1000); // Unix timestamp
json.put("lat", location.getLatitude());
json.put("lon", location.getLongitude());
json.put("accuracy", location.getAccuracy());
if (location.hasSpeed())
json.put("speed", location.getSpeed());
if (location.hasBearing())
json.put("bearing", location.getBearing());
// Check if navigating
RoutingInfo routingInfo = getNavigationInfo();
if (routingInfo != null && routingInfo.distToTarget != null)
{
json.put("mode", "navigation");
// Calculate ETA (current time + time remaining)
if (routingInfo.totalTimeInSeconds > 0)
{
long etaTimestamp = (System.currentTimeMillis() / 1000) + routingInfo.totalTimeInSeconds;
json.put("eta", etaTimestamp);
}
// Distance remaining in meters
if (routingInfo.distToTarget != null)
{
json.put("distanceRemaining", routingInfo.distToTarget.mDistance);
}
}
else
{
json.put("mode", "standalone");
}
json.put("batteryLevel", batteryLevel);
return json;
}
catch (JSONException e)
{
Logger.e(TAG, "Failed to build payload JSON", e);
return null;
}
}
@Nullable
private RoutingInfo getNavigationInfo()
{
if (!RoutingController.get().isNavigating())
return null;
return RoutingController.get().getCachedRoutingInfo();
}
private int getBatteryLevel()
{
BatteryManager bm = (BatteryManager) getSystemService(BATTERY_SERVICE);
if (bm == null)
return 100;
return bm.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY);
}
@NonNull
private PendingIntent getStopIntent()
{
Intent stopIntent = new Intent(this, LocationSharingService.class);
stopIntent.setAction(ACTION_STOP);
return PendingIntent.getService(this, 0, stopIntent,
PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
}
@NonNull
private PendingIntent getCopyUrlIntent()
{
Intent copyIntent = new Intent(this, LocationSharingService.class);
copyIntent.setAction(ACTION_COPY_URL);
return PendingIntent.getService(this, 1, copyIntent,
PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
}
@NonNull
private Notification buildFallbackNotification()
{
Intent notificationIntent = new Intent(this, MwmActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent,
PendingIntent.FLAG_IMMUTABLE);
return new NotificationCompat.Builder(this, LocationSharingNotification.CHANNEL_ID)
.setContentTitle(getString(R.string.location_sharing_active))
.setSmallIcon(R.drawable.ic_share)
.setContentIntent(pendingIntent)
.setOngoing(true)
.build();
}
}

View File

@@ -2,7 +2,6 @@ package app.organicmaps.maplayer;
import android.content.Context;
import android.view.View;
import androidx.annotation.AttrRes;
import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.annotation.StringRes;
@@ -14,7 +13,9 @@ import app.organicmaps.util.ThemeUtils;
public class LayerBottomSheetItem
{
@DrawableRes
private final int mDrawableResId;
private final int mEnabledStateDrawableResId;
@DrawableRes
private final int mDisabledStateDrawableResId;
@StringRes
private final int mTitleResId;
@NonNull
@@ -22,10 +23,12 @@ public class LayerBottomSheetItem
@NonNull
private final OnItemClickListener<LayerBottomSheetItem> mItemClickListener;
LayerBottomSheetItem(@DrawableRes int drawableResId, @StringRes int titleResId, @NonNull Mode mode,
LayerBottomSheetItem(@DrawableRes int enabledStateDrawableResId, @DrawableRes int disabledStateDrawableResId,
@StringRes int titleResId, @NonNull Mode mode,
@NonNull OnItemClickListener<LayerBottomSheetItem> itemClickListener)
{
mDrawableResId = drawableResId;
mEnabledStateDrawableResId = enabledStateDrawableResId;
mDisabledStateDrawableResId = disabledStateDrawableResId;
mTitleResId = titleResId;
mMode = mode;
mItemClickListener = itemClickListener;
@@ -34,30 +37,35 @@ public class LayerBottomSheetItem
public static LayerBottomSheetItem create(@NonNull Context mContext, Mode mode,
@NonNull OnItemClickListener<LayerBottomSheetItem> layerItemClickListener)
{
@DrawableRes
int drawableResId = 0;
@StringRes
int disabledResource = 0;
int enabledResource = 0;
int buttonTextResource = R.string.layers_title;
switch (mode)
{
case OUTDOORS:
drawableResId = R.drawable.ic_layers_outdoors;
disabledResource = R.attr.outdoorsMenuDisabled;
enabledResource = R.attr.outdoorsMenuEnabled;
buttonTextResource = R.string.button_layer_outdoor;
break;
case SUBWAY:
drawableResId = R.drawable.ic_layers_subway;
disabledResource = R.attr.subwayMenuDisabled;
enabledResource = R.attr.subwayMenuEnabled;
buttonTextResource = R.string.subway;
break;
case ISOLINES:
drawableResId = R.drawable.ic_layers_isoline;
disabledResource = R.attr.isoLinesMenuDisabled;
enabledResource = R.attr.isoLinesMenuEnabled;
buttonTextResource = R.string.button_layer_isolines;
break;
case TRAFFIC:
drawableResId = R.drawable.ic_layers_traffic;
disabledResource = R.attr.trafficMenuDisabled;
enabledResource = R.attr.trafficMenuEnabled;
buttonTextResource = R.string.button_layer_traffic;
break;
}
return new LayerBottomSheetItem(drawableResId, buttonTextResource, mode, layerItemClickListener);
int disabled = ThemeUtils.getResource(mContext, disabledResource);
int enabled = ThemeUtils.getResource(mContext, enabledResource);
return new LayerBottomSheetItem(enabled, disabled, buttonTextResource, mode, layerItemClickListener);
}
@NonNull
@@ -67,9 +75,15 @@ public class LayerBottomSheetItem
}
@DrawableRes
public int getDrawable()
public int getEnabledStateDrawable()
{
return mDrawableResId;
return mEnabledStateDrawableResId;
}
@DrawableRes
public int getDisabledStateDrawable()
{
return mDisabledStateDrawableResId;
}
@StringRes

View File

@@ -45,8 +45,7 @@ public class LayersAdapter extends RecyclerView.Adapter<LayerHolder>
holder.mTitle.setText(item.getTitle());
boolean isNewLayer = SharedPropertiesUtils.shouldShowNewMarkerForLayerMode(item.getMode());
UiUtils.showIf(isNewLayer, holder.mNewMarker);
holder.mButton.setBackgroundResource(item.getDrawable());
holder.mButton.setActivated(isEnabled);
holder.mButton.setImageResource(isEnabled ? item.getEnabledStateDrawable() : item.getDisabledStateDrawable());
holder.mListener = item::onClick;
}

View File

@@ -322,8 +322,7 @@ public class MapButtonsController extends Fragment
mBadgeDrawable.setVisible(count > 0);
BadgeUtils.attachBadgeDrawable(mBadgeDrawable, menuButton);
final boolean isTrackRecording = TrackRecorder.nativeIsTrackRecordingEnabled();
updateMenuBadge(isTrackRecording);
updateMenuBadge(TrackRecorder.nativeIsTrackRecordingEnabled());
}
public void updateLayerButton()

View File

@@ -16,7 +16,6 @@ public class MapButtonsViewModel extends ViewModel
private final MutableLiveData<SearchWheel.SearchOption> mSearchOption = new MutableLiveData<>();
private final MutableLiveData<Boolean> mTrackRecorderState =
new MutableLiveData<>(TrackRecorder.nativeIsTrackRecordingEnabled());
private final MutableLiveData<Boolean> mLocationSharingState = new MutableLiveData<>(false);
public MutableLiveData<Boolean> getButtonsHidden()
{
@@ -87,14 +86,4 @@ public class MapButtonsViewModel extends ViewModel
{
return mTrackRecorderState;
}
public void setLocationSharingState(boolean state)
{
mLocationSharingState.setValue(state);
}
public MutableLiveData<Boolean> getLocationSharingState()
{
return mLocationSharingState;
}
}

View File

@@ -43,19 +43,20 @@ public class TrafficButton
void turnOff()
{
stopWaitingAnimation();
mButton.setImageResource(R.drawable.ic_traffic_on);
mButton.setImageResource(ThemeUtils.isNightTheme() ? R.drawable.ic_traffic_on_night : R.drawable.ic_traffic_on);
}
void turnOn()
{
stopWaitingAnimation();
mButton.setImageResource(R.drawable.ic_traffic_on);
mButton.setImageResource(ThemeUtils.isNightTheme() ? R.drawable.ic_traffic_on_night : R.drawable.ic_traffic_on);
}
void markAsOutdated()
{
stopWaitingAnimation();
mButton.setImageResource(R.drawable.ic_traffic_outdated);
mButton.setImageResource(ThemeUtils.isNightTheme() ? R.drawable.ic_traffic_outdated_night
: R.drawable.ic_traffic_outdated);
}
void startWaitingAnimation()

View File

@@ -205,11 +205,6 @@ public class NavigationController implements TrafficManager.TrafficCallback, Nav
mNavMenu.refreshTts();
}
public void refreshShareLocationColor()
{
mNavMenu.updateShareLocationColor();
}
@Override
public void onEnabled()
{

View File

@@ -26,10 +26,8 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.RecyclerView;
import app.organicmaps.MwmActivity;
import app.organicmaps.MwmApplication;
import app.organicmaps.R;
import app.organicmaps.location.LocationSharingDialog;
import app.organicmaps.sdk.Framework;
import app.organicmaps.sdk.bookmarks.data.DistanceAndAzimut;
import app.organicmaps.sdk.routing.RouteMarkData;
@@ -146,9 +144,6 @@ final class RoutingBottomMenuController implements View.OnClickListener
mActionButton.setOnClickListener(this);
View actionSearchButton = actionFrame.findViewById(R.id.btn__search_point);
actionSearchButton.setOnClickListener(this);
View shareLocationButton = actionFrame.findViewById(R.id.btn__share_location);
if (shareLocationButton != null)
shareLocationButton.setOnClickListener(this);
mActionIcon = mActionButton.findViewById(R.id.iv__icon);
UiUtils.hide(mAltitudeChartFrame, mActionFrame);
mListener = listener;
@@ -477,11 +472,6 @@ final class RoutingBottomMenuController implements View.OnClickListener
final RouteMarkType pointType = (RouteMarkType) mActionMessage.getTag();
mListener.onSearchRoutePoint(pointType);
}
else if (id == R.id.btn__share_location)
{
if (mContext instanceof MwmActivity)
LocationSharingDialog.show(((MwmActivity) mContext).getSupportFragmentManager());
}
else if (id == R.id.btn__manage_route)
mListener.onManageRouteOpen();
else if (id == R.id.btn__save)

View File

@@ -20,6 +20,7 @@ import com.google.android.material.textview.MaterialTextView;
import app.organicmaps.R;
import app.organicmaps.sdk.search.DisplayedCategories;
import app.organicmaps.sdk.util.Language;
import app.organicmaps.util.ThemeUtils;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.Locale;
@@ -90,7 +91,11 @@ class CategoriesAdapter extends RecyclerView.Adapter<CategoriesAdapter.ViewHolde
@DrawableRes
private static int getDrawableResIdByKey(@NonNull Context context, @NonNull String packageName, @NonNull String key)
{
return context.getResources().getIdentifier("ic_" + key, "drawable", packageName);
final boolean isNightTheme = ThemeUtils.isNightTheme();
String iconId = "ic_" + key;
if (isNightTheme)
iconId = iconId + "_night";
return context.getResources().getIdentifier(iconId, "drawable", packageName);
}
@Override

View File

@@ -33,6 +33,13 @@ public class SearchActivity extends BaseMwmFragmentActivity
activity.startActivity(i);
}
@Override
@StyleRes
public int getThemeResourceId(@NonNull String theme)
{
return ThemeUtils.getCardBgThemeResourceId(theme);
}
@Override
protected Class<? extends Fragment> getFragmentClass()
{

View File

@@ -12,6 +12,7 @@ import androidx.preference.Preference;
import androidx.preference.PreferenceFragmentCompat;
import androidx.recyclerview.widget.RecyclerView;
import app.organicmaps.R;
import app.organicmaps.util.ThemeUtils;
import app.organicmaps.util.Utils;
import app.organicmaps.util.WindowInsetUtils.ScrollableContentInsetsListener;
@@ -34,17 +35,24 @@ abstract class BaseXmlSettingsFragment extends PreferenceFragmentCompat
}
@Override
public void onAttach(@NonNull Context context)
public void onAttach(Context context)
{
super.onAttach(context);
Utils.detachFragmentIfCoreNotInitialized(context, this);
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState)
public void onViewCreated(View view, @Nullable Bundle savedInstanceState)
{
super.onViewCreated(view, savedInstanceState);
view.setBackgroundColor(ContextCompat.getColor(requireContext(), R.color.bg_cards));
int color;
if (ThemeUtils.isDefaultTheme())
color = ContextCompat.getColor(requireContext(), R.color.bg_cards);
else
color = ContextCompat.getColor(requireContext(), R.color.bg_cards_night);
view.setBackgroundColor(color);
RecyclerView recyclerView = getListView();
ViewCompat.setOnApplyWindowInsetsListener(recyclerView, new ScrollableContentInsetsListener(recyclerView));
}

View File

@@ -107,11 +107,6 @@ public class DrivingOptionsFragment extends BaseMwmToolbarFragment
dirtyRoadsBtn.setChecked(RoutingOptions.hasOption(RoadType.Dirty));
CompoundButton.OnCheckedChangeListener dirtyBtnListener = new ToggleRoutingOptionListener(RoadType.Dirty);
dirtyRoadsBtn.setOnCheckedChangeListener(dirtyBtnListener);
SwitchCompat stepsBtn = root.findViewById(R.id.avoid_steps_btn);
stepsBtn.setChecked(RoutingOptions.hasOption(RoadType.Steps));
CompoundButton.OnCheckedChangeListener stepsBtnListener = new ToggleRoutingOptionListener(RoadType.Steps);
stepsBtn.setOnCheckedChangeListener(stepsBtnListener);
}
private static class ToggleRoutingOptionListener implements CompoundButton.OnCheckedChangeListener

View File

@@ -8,7 +8,6 @@ import android.os.Bundle;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.preference.EditTextPreference;
import androidx.preference.ListPreference;
import androidx.preference.Preference;
import androidx.preference.PreferenceCategory;
@@ -51,7 +50,7 @@ public class SettingsPrefsFragment extends BaseXmlSettingsFragment implements La
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState)
public void onViewCreated(View view, @Nullable Bundle savedInstanceState)
{
super.onViewCreated(view, savedInstanceState);
@@ -74,7 +73,6 @@ public class SettingsPrefsFragment extends BaseXmlSettingsFragment implements La
initScreenSleepEnabledPrefsCallbacks();
initShowOnLockScreenPrefsCallbacks();
initLeftButtonPrefs();
initLocationSharingPrefsCallbacks();
}
private void initLeftButtonPrefs()
@@ -544,29 +542,6 @@ public class SettingsPrefsFragment extends BaseXmlSettingsFragment implements La
category.removePreference(preference);
}
private void initLocationSharingPrefsCallbacks()
{
// Server URL preference
final EditTextPreference serverUrlPref = getPreference(getString(R.string.pref_location_sharing_server_url));
serverUrlPref.setText(Config.LocationSharing.getServerUrl());
serverUrlPref.setSummary(Config.LocationSharing.getServerUrl());
serverUrlPref.setOnPreferenceChangeListener((preference, newValue) -> {
String url = (String) newValue;
Config.LocationSharing.setServerUrl(url);
serverUrlPref.setSummary(url);
return true;
});
// Update interval preference
final ListPreference intervalPref = getPreference(getString(R.string.pref_location_sharing_update_interval));
intervalPref.setValue(String.valueOf(Config.LocationSharing.getUpdateInterval()));
intervalPref.setOnPreferenceChangeListener((preference, newValue) -> {
int seconds = Integer.parseInt((String) newValue);
Config.LocationSharing.setUpdateInterval(seconds);
return true;
});
}
@Override
public void onLanguageSelected(Language language)
{

View File

@@ -137,7 +137,7 @@ public class VoiceInstructionsSettingsFragment extends BaseXmlSettingsFragment
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState)
public void onViewCreated(View view, @Nullable Bundle savedInstanceState)
{
super.onViewCreated(view, savedInstanceState);

View File

@@ -86,7 +86,7 @@ public enum ThemeSwitcher
String oldTheme = Config.UiTheme.getCurrent();
MapStyle style;
if (Config.UiTheme.isNight(theme))
if (ThemeUtils.isNightTheme())
{
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S)
uiModeManager.setApplicationNightMode(UiModeManager.MODE_NIGHT_YES);

View File

@@ -6,6 +6,8 @@ import android.util.TypedValue;
import androidx.annotation.AttrRes;
import androidx.annotation.ColorInt;
import androidx.annotation.NonNull;
import androidx.annotation.StyleRes;
import app.organicmaps.R;
import app.organicmaps.sdk.util.Config;
public final class ThemeUtils
@@ -62,4 +64,28 @@ public final class ThemeUtils
{
return Config.UiTheme.isNavAuto(Config.UiTheme.getUiThemeSettings());
}
@StyleRes
public static int getCardBgThemeResourceId(@NonNull String theme)
{
if (Config.UiTheme.isDefault(theme))
return R.style.MwmTheme_CardBg;
if (Config.UiTheme.isNight(theme))
return R.style.MwmTheme_Night_CardBg;
throw new IllegalArgumentException("Attempt to apply unsupported theme: " + theme);
}
@StyleRes
public static int getWindowBgThemeResourceId(@NonNull String theme)
{
if (Config.UiTheme.isDefault(theme))
return R.style.MwmTheme_WindowBg;
if (Config.UiTheme.isNight(theme))
return R.style.MwmTheme_Night_WindowBg;
throw new IllegalArgumentException("Attempt to apply unsupported theme: " + theme);
}
}

View File

@@ -35,8 +35,9 @@ public class RoutingToolbarButton extends AppCompatRadioButton
private void initView()
{
setBackgroundResource(R.drawable.routing_toolbar_button);
setButtonTintList(R.color.routing_toolbar_icon_tint);
final boolean isNightTheme = ThemeUtils.isNightTheme();
setBackgroundResource(isNightTheme ? R.drawable.routing_toolbar_button_night : R.drawable.routing_toolbar_button);
setButtonTintList(isNightTheme ? R.color.routing_toolbar_icon_tint_night : R.color.routing_toolbar_icon_tint);
}
public void progress()

View File

@@ -5,7 +5,6 @@ import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import app.organicmaps.R;
import app.organicmaps.location.LocationSharingDialog;
import app.organicmaps.sdk.routing.RoutingInfo;
import app.organicmaps.sdk.sound.TtsPlayer;
import app.organicmaps.sdk.util.DateUtils;
@@ -27,7 +26,6 @@ public class NavMenu
private final View mHeaderFrame;
private final ShapeableImageView mTts;
private final ShapeableImageView mShareLocation;
private final MaterialTextView mEtaValue;
private final MaterialTextView mEtaAmPm;
private final MaterialTextView mTimeHourValue;
@@ -99,16 +97,12 @@ public class NavMenu
mRouteProgress = bottomFrame.findViewById(R.id.navigation_progress);
// Bottom frame buttons
mShareLocation = bottomFrame.findViewById(R.id.share_location);
mShareLocation.setOnClickListener(v -> onShareLocationClicked());
ShapeableImageView mSettings = bottomFrame.findViewById(R.id.settings);
mSettings.setOnClickListener(v -> onSettingsClicked());
mTts = bottomFrame.findViewById(R.id.tts_volume);
mTts.setOnClickListener(v -> onTtsClicked());
MaterialButton stop = bottomFrame.findViewById(R.id.stop);
stop.setOnClickListener(v -> onStopClicked());
updateShareLocationColor();
}
private void onStopClicked()
@@ -116,22 +110,6 @@ public class NavMenu
mNavMenuListener.onStopClicked();
}
private void onShareLocationClicked()
{
LocationSharingDialog.show(mActivity.getSupportFragmentManager());
// Update color after dialog is shown (in case state changes)
mShareLocation.postDelayed(this::updateShareLocationColor, 500);
}
public void updateShareLocationColor()
{
final boolean isLocationSharing = app.organicmaps.location.LocationSharingManager.getInstance().isSharing();
final int color = isLocationSharing
? androidx.core.content.ContextCompat.getColor(mActivity, R.color.active_location_sharing)
: app.organicmaps.util.ThemeUtils.getColor(mActivity, R.attr.iconTint);
mShareLocation.setImageTintList(android.content.res.ColorStateList.valueOf(color));
}
private void onSettingsClicked()
{
mNavMenuListener.onSettingsClicked();

View File

@@ -72,7 +72,6 @@ import app.organicmaps.util.bottomsheet.MenuBottomSheetFragment;
import app.organicmaps.util.bottomsheet.MenuBottomSheetItem;
import app.organicmaps.widget.ArrowView;
import app.organicmaps.widget.placepage.sections.PlacePageBookmarkFragment;
import app.organicmaps.widget.placepage.sections.PlacePageChargeSocketsFragment;
import app.organicmaps.widget.placepage.sections.PlacePageLinksFragment;
import app.organicmaps.widget.placepage.sections.PlacePageOpeningHoursFragment;
import app.organicmaps.widget.placepage.sections.PlacePagePhoneFragment;
@@ -99,7 +98,6 @@ public class PlacePageView extends Fragment
private static final String BOOKMARK_FRAGMENT_TAG = "BOOKMARK_FRAGMENT_TAG";
private static final String TRACK_FRAGMENT_TAG = "TRACK_FRAGMENT_TAG";
private static final String WIKIPEDIA_FRAGMENT_TAG = "WIKIPEDIA_FRAGMENT_TAG";
private static final String CHARGE_SOCKETS_FRAGMENT_TAG = "CHARGE_SOCKETS_FRAGMENT_TAG";
private static final String PHONE_FRAGMENT_TAG = "PHONE_FRAGMENT_TAG";
private static final String OPENING_HOURS_FRAGMENT_TAG = "OPENING_HOURS_FRAGMENT_TAG";
private static final String LINKS_FRAGMENT_TAG = "LINKS_FRAGMENT_TAG";
@@ -148,6 +146,7 @@ public class PlacePageView extends Fragment
private MaterialTextView mTvEntrance;
private MaterialTextView mTvLastChecked;
private View mEditPlace;
private View mAddOrganisation;
private View mAddPlace;
private View mEditTopSpace;
private ShapeableImageView mColorIcon;
@@ -312,6 +311,7 @@ public class PlacePageView extends Fragment
mTvEntrance = mEntrance.findViewById(R.id.tv__place_entrance);
mTvLastChecked = mFrame.findViewById(R.id.place_page_last_checked);
mEditPlace = mFrame.findViewById(R.id.ll__place_editor);
mAddOrganisation = mFrame.findViewById(R.id.ll__add_organisation);
mAddPlace = mFrame.findViewById(R.id.ll__place_add);
mEditTopSpace = mFrame.findViewById(R.id.edit_top_space);
latlon.setOnLongClickListener(this);
@@ -407,12 +407,6 @@ public class PlacePageView extends Fragment
R.id.place_page_opening_hours_fragment, !TextUtils.isEmpty(ohStr));
}
private void updateChargeSocketsView()
{
updateViewFragment(PlacePageChargeSocketsFragment.class, CHARGE_SOCKETS_FRAGMENT_TAG,
R.id.place_page_charge_sockets_fragment, mMapObject.hasChargeSockets());
}
private void updatePhoneView()
{
updateViewFragment(PlacePagePhoneFragment.class, PHONE_FRAGMENT_TAG, R.id.place_page_phone_fragment,
@@ -671,25 +665,28 @@ public class PlacePageView extends Fragment
if (!lastChecked.isEmpty())
{
String periodSinceCheck = DateUtils.getRelativePeriodString(getResources(), lastChecked);
UiUtils.setTextAndShow(mTvLastChecked,
requireContext().getString(R.string.existence_confirmed_time_ago, periodSinceCheck));
UiUtils.setTextAndShow(mTvLastChecked, requireContext().getString(R.string.existence_confirmed_time_ago, periodSinceCheck));
}
else
UiUtils.hide(mTvLastChecked);
if (RoutingController.get().isNavigating() || RoutingController.get().isPlanning())
{
UiUtils.hide(mEditPlace, mAddPlace, mEditTopSpace);
UiUtils.hide(mEditPlace, mAddOrganisation, mAddPlace, mEditTopSpace);
}
else
{
UiUtils.showIf(Editor.nativeShouldShowEditPlace(), mEditPlace);
UiUtils.showIf(Editor.nativeShouldShowAddBusiness(), mAddOrganisation);
UiUtils.showIf(Editor.nativeShouldShowAddPlace(), mAddPlace);
MaterialButton mTvEditPlace = mEditPlace.findViewById(R.id.mb__place_editor);
MaterialButton mTvAddBusiness = mAddOrganisation.findViewById(R.id.mb__add_organisation);
MaterialButton mTvAddPlace = mAddPlace.findViewById(R.id.mb__place_add);
mTvEditPlace.setOnClickListener(this);
mTvAddBusiness.setOnClickListener(this);
mTvAddPlace.setOnClickListener(this);
mTvEditPlace.setEnabled(Editor.nativeShouldEnableEditPlace());
mTvAddBusiness.setEnabled(Editor.nativeShouldEnableAddPlace());
mTvAddPlace.setEnabled(Editor.nativeShouldEnableAddPlace());
final int editPlaceButtonColor =
Editor.nativeShouldEnableEditPlace()
@@ -698,18 +695,19 @@ public class PlacePageView extends Fragment
UiUtils.getStyledResourceId(getContext(), com.google.android.material.R.attr.colorSecondary))
: ContextCompat.getColor(getContext(), R.color.button_accent_text_disabled);
mTvEditPlace.setTextColor(editPlaceButtonColor);
mTvAddBusiness.setTextColor(editPlaceButtonColor);
mTvAddPlace.setTextColor(editPlaceButtonColor);
mTvEditPlace.setStrokeColor(ColorStateList.valueOf(editPlaceButtonColor));
mTvAddBusiness.setStrokeColor(ColorStateList.valueOf(editPlaceButtonColor));
mTvAddPlace.setStrokeColor(ColorStateList.valueOf(editPlaceButtonColor));
UiUtils.showIf(
UiUtils.isVisible(mEditPlace) || UiUtils.isVisible(mAddPlace),
UiUtils.isVisible(mEditPlace) || UiUtils.isVisible(mAddOrganisation) || UiUtils.isVisible(mAddPlace),
mEditTopSpace);
}
updateLinksView();
updateOpeningHoursView();
updateWikipediaView();
updateBookmarkView();
updateChargeSocketsView();
updatePhoneView();
updateTrackView();
}
@@ -839,6 +837,11 @@ public class PlacePageView extends Fragment
UiUtils.hide(mTvOpenState);
}
private void addOrganisation()
{
((MwmActivity) requireActivity()).showPositionChooserForEditor(true, true);
}
private void addPlace()
{
((MwmActivity) requireActivity()).showPositionChooserForEditor(false, true);
@@ -856,6 +859,8 @@ public class PlacePageView extends Fragment
}
else if (id == R.id.mb__place_editor)
((MwmActivity) requireActivity()).showEditor();
else if (id == R.id.mb__add_organisation)
addOrganisation();
else if (id == R.id.mb__place_add)
addPlace();
else if (id == R.id.ll__place_latlon)

View File

@@ -1,121 +0,0 @@
package app.organicmaps.widget.placepage.sections;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridLayout;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import com.google.android.material.imageview.ShapeableImageView;
import com.google.android.material.textview.MaterialTextView;
import app.organicmaps.R;
import app.organicmaps.sdk.Framework;
import app.organicmaps.sdk.bookmarks.data.ChargeSocketDescriptor;
import app.organicmaps.sdk.bookmarks.data.MapObject;
import app.organicmaps.sdk.bookmarks.data.Metadata;
import app.organicmaps.widget.placepage.PlacePageViewModel;
import java.text.DecimalFormat;
public class PlacePageChargeSocketsFragment extends Fragment implements Observer<MapObject>
{
private GridLayout mGrid;
private PlacePageViewModel mViewModel;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState)
{
mViewModel = new ViewModelProvider(requireActivity()).get(PlacePageViewModel.class);
return inflater.inflate(R.layout.place_page_charge_sockets_fragment, container, false);
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState)
{
super.onViewCreated(view, savedInstanceState);
mGrid = view.findViewById(R.id.socket_grid);
}
@Override
public void onStart()
{
super.onStart();
mViewModel.getMapObject().observe(requireActivity(), this);
}
@Override
public void onStop()
{
super.onStop();
mViewModel.getMapObject().removeObserver(this);
}
@Override
public void onChanged(@Nullable MapObject mapObject)
{
if (mapObject == null)
{
return;
}
mGrid.removeAllViews();
ChargeSocketDescriptor[] sockets = Framework.nativeGetActiveObjectChargeSockets();
LayoutInflater inflater = LayoutInflater.from(requireContext());
for (ChargeSocketDescriptor socket : sockets)
{
View itemView = inflater.inflate(R.layout.item_charge_socket, mGrid, false);
itemView.setClickable(false);
itemView.setFocusable(false);
MaterialTextView type = itemView.findViewById(R.id.socket_type);
ShapeableImageView icon = itemView.findViewById(R.id.socket_icon);
MaterialTextView power = itemView.findViewById(R.id.socket_power);
MaterialTextView count = itemView.findViewById(R.id.socket_count);
// load SVG icon converted into VectorDrawable in res/drawable
@SuppressLint("DiscouragedApi")
int resIconId = getResources().getIdentifier("ic_charge_socket_" + socket.type(), "drawable",
requireContext().getPackageName());
if (resIconId != 0)
{
icon.setImageResource(resIconId);
}
@SuppressLint("DiscouragedApi")
int resTypeId =
getResources().getIdentifier("charge_socket_" + socket.type(), "string", requireContext().getPackageName());
if (resTypeId != 0)
{
type.setText(resTypeId);
}
if (socket.power() != 0)
{
DecimalFormat df = new DecimalFormat("#.##");
power.setText(getString(R.string.kw_label, df.format(socket.power())));
}
if (socket.count() != 0)
{
count.setText(getString(R.string.count_label, socket.count()));
}
mGrid.addView(itemView);
}
}
}

View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:color="@color/base_accent_night"
android:state_selected="true"/>
<item android:color="@color/base_accent_night"
android:state_checked="true"/>
<item android:color="@color/base_accent_night"
app:layers_enabled="true"/>
<item android:color="@color/white_secondary"/>
</selector>

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/button_accent_normal_night"
android:state_enabled="true"/>
<item android:color="@color/button_accent_disabled_night"/>
</selector>

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/button_normal_night"
android:state_enabled="true"/>
<item android:color="@color/button_disabled_night"/>
</selector>

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_activated="true"
android:color="@color/routing_button_activated_tint_night"/>
<item
android:state_pressed="true"
android:color="@color/routing_button_pressed_tint"/>
<item
android:color="@color/routing_button_tint"/>
</selector>

Some files were not shown because too many files have changed in this diff Show More