From ff9246168bd4f9f75dd95178486db0cd8ac83200 Mon Sep 17 00:00:00 2001 From: Emux Date: Mon, 17 Apr 2023 13:37:02 +0300 Subject: [PATCH] Android Gradle plugin 8 preparation (#1034) --- docs/Integration.md | 4 +- .../oscim/android/test/BaseMapActivity.java | 70 ++++----- .../oscim/android/test/MapsforgeActivity.java | 119 +++++++-------- .../android/test/MapsforgeStyleActivity.java | 30 ++-- .../android/test/ThemeStylerActivity.java | 17 +-- vtm-app/src/org/oscim/app/MapLayers.java | 22 ++- vtm-app/src/org/oscim/app/POISearch.java | 29 ++-- vtm-app/src/org/oscim/app/RouteSearch.java | 52 +++---- vtm-app/src/org/oscim/app/TileMap.java | 138 +++++++----------- vtm-desktop/build.gradle | 3 +- vtm/build.gradle | 2 +- 11 files changed, 217 insertions(+), 269 deletions(-) diff --git a/docs/Integration.md b/docs/Integration.md index 374acd3ec..ff6762cf3 100644 --- a/docs/Integration.md +++ b/docs/Integration.md @@ -10,7 +10,6 @@ Current version is [![Maven Central](https://img.shields.io/maven-central/v/org. ```groovy implementation 'org.mapsforge:vtm:[CURRENT-VERSION]' implementation 'org.mapsforge:vtm-themes:[CURRENT-VERSION]' -implementation 'net.sf.kxml:kxml2:2.3.0' implementation 'org.slf4j:slf4j-api:1.7.28' ``` @@ -55,7 +54,8 @@ runtimeOnly 'org.mapsforge:vtm-desktop:[CURRENT-VERSION]:natives-osx' runtimeOnly 'org.mapsforge:vtm-desktop:[CURRENT-VERSION]:natives-windows' implementation 'com.badlogicgames.gdx:gdx:1.11.0' runtimeOnly 'com.badlogicgames.gdx:gdx-platform:1.11.0:natives-desktop' -implementation 'com.formdev:svgSalamander:1.1.3' +implementation 'guru.nidi.com.kitfox:svgSalamander:1.1.3' +implementation 'net.sf.kxml:kxml2:2.3.0' ``` ### Desktop (LWJGL) diff --git a/vtm-android-example/src/org/oscim/android/test/BaseMapActivity.java b/vtm-android-example/src/org/oscim/android/test/BaseMapActivity.java index af290f52b..15db28ac9 100644 --- a/vtm-android-example/src/org/oscim/android/test/BaseMapActivity.java +++ b/vtm-android-example/src/org/oscim/android/test/BaseMapActivity.java @@ -75,46 +75,40 @@ public void onCreate(Bundle savedInstanceState) { @Override public boolean onOptionsItemSelected(MenuItem item) { - - switch (item.getItemId()) { - case R.id.theme_default: - mMap.setTheme(VtmThemes.DEFAULT); - item.setChecked(true); - return true; - - case R.id.theme_osmarender: - mMap.setTheme(VtmThemes.OSMARENDER); - item.setChecked(true); - return true; - - case R.id.theme_osmagray: - mMap.setTheme(VtmThemes.OSMAGRAY); - item.setChecked(true); - return true; - - case R.id.theme_tubes: - mMap.setTheme(VtmThemes.TRONRENDER); + int itemId = item.getItemId(); + if (itemId == R.id.theme_default) { + mMap.setTheme(VtmThemes.DEFAULT); + item.setChecked(true); + return true; + } else if (itemId == R.id.theme_osmarender) { + mMap.setTheme(VtmThemes.OSMARENDER); + item.setChecked(true); + return true; + } else if (itemId == R.id.theme_osmagray) { + mMap.setTheme(VtmThemes.OSMAGRAY); + item.setChecked(true); + return true; + } else if (itemId == R.id.theme_tubes) { + mMap.setTheme(VtmThemes.TRONRENDER); + item.setChecked(true); + return true; + } else if (itemId == R.id.theme_newtron) { + mMap.setTheme(VtmThemes.NEWTRON); + item.setChecked(true); + return true; + } else if (itemId == R.id.gridlayer) { + if (item.isChecked()) { + item.setChecked(false); + mMap.layers().remove(mGridLayer); + } else { item.setChecked(true); - return true; + if (mGridLayer == null) + mGridLayer = new TileGridLayer(mMap); - case R.id.theme_newtron: - mMap.setTheme(VtmThemes.NEWTRON); - item.setChecked(true); - return true; - - case R.id.gridlayer: - if (item.isChecked()) { - item.setChecked(false); - mMap.layers().remove(mGridLayer); - } else { - item.setChecked(true); - if (mGridLayer == null) - mGridLayer = new TileGridLayer(mMap); - - mMap.layers().add(mGridLayer); - } - mMap.updateMap(true); - return true; + mMap.layers().add(mGridLayer); + } + mMap.updateMap(true); + return true; } return false; diff --git a/vtm-android-example/src/org/oscim/android/test/MapsforgeActivity.java b/vtm-android-example/src/org/oscim/android/test/MapsforgeActivity.java index 0f4692371..2761f10ca 100644 --- a/vtm-android-example/src/org/oscim/android/test/MapsforgeActivity.java +++ b/vtm-android-example/src/org/oscim/android/test/MapsforgeActivity.java @@ -114,71 +114,64 @@ public boolean onCreateOptionsMenu(Menu menu) { @Override public boolean onOptionsItemSelected(MenuItem item) { - - switch (item.getItemId()) { - case R.id.theme_default: - if (mTheme != null) - mTheme.dispose(); - mTheme = mMap.setTheme(VtmThemes.DEFAULT); - item.setChecked(true); - return true; - - case R.id.theme_osmarender: - if (mTheme != null) - mTheme.dispose(); - mTheme = mMap.setTheme(VtmThemes.OSMARENDER); - item.setChecked(true); - return true; - - case R.id.theme_osmagray: - if (mTheme != null) - mTheme.dispose(); - mTheme = mMap.setTheme(VtmThemes.OSMAGRAY); - item.setChecked(true); - return true; - - case R.id.theme_tubes: - if (mTheme != null) - mTheme.dispose(); - mTheme = mMap.setTheme(VtmThemes.TRONRENDER); + int itemId = item.getItemId(); + if (itemId == R.id.theme_default) { + if (mTheme != null) + mTheme.dispose(); + mTheme = mMap.setTheme(VtmThemes.DEFAULT); + item.setChecked(true); + return true; + } else if (itemId == R.id.theme_osmarender) { + if (mTheme != null) + mTheme.dispose(); + mTheme = mMap.setTheme(VtmThemes.OSMARENDER); + item.setChecked(true); + return true; + } else if (itemId == R.id.theme_osmagray) { + if (mTheme != null) + mTheme.dispose(); + mTheme = mMap.setTheme(VtmThemes.OSMAGRAY); + item.setChecked(true); + return true; + } else if (itemId == R.id.theme_tubes) { + if (mTheme != null) + mTheme.dispose(); + mTheme = mMap.setTheme(VtmThemes.TRONRENDER); + item.setChecked(true); + return true; + } else if (itemId == R.id.theme_newtron) { + if (mTheme != null) + mTheme.dispose(); + mTheme = mMap.setTheme(VtmThemes.NEWTRON); + item.setChecked(true); + return true; + } else if (itemId == R.id.theme_external_archive) { + Intent intent = new Intent(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT ? Intent.ACTION_OPEN_DOCUMENT : Intent.ACTION_GET_CONTENT); + intent.addCategory(Intent.CATEGORY_OPENABLE); + intent.setType("*/*"); + startActivityForResult(intent, SELECT_THEME_ARCHIVE); + return true; + } else if (itemId == R.id.theme_external) { + Intent intent; + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) + return false; + intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE); + intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); + startActivityForResult(intent, SELECT_THEME_DIR); + return true; + } else if (itemId == R.id.gridlayer) { + if (item.isChecked()) { + item.setChecked(false); + mMap.layers().remove(mGridLayer); + } else { item.setChecked(true); - return true; + if (mGridLayer == null) + mGridLayer = new TileGridLayer(mMap); - case R.id.theme_newtron: - if (mTheme != null) - mTheme.dispose(); - mTheme = mMap.setTheme(VtmThemes.NEWTRON); - item.setChecked(true); - return true; - - case R.id.theme_external_archive: - Intent intent = new Intent(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT ? Intent.ACTION_OPEN_DOCUMENT : Intent.ACTION_GET_CONTENT); - intent.addCategory(Intent.CATEGORY_OPENABLE); - intent.setType("*/*"); - startActivityForResult(intent, SELECT_THEME_ARCHIVE); - return true; - - case R.id.theme_external: - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) - return false; - intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE); - intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); - startActivityForResult(intent, SELECT_THEME_DIR); - return true; - - case R.id.gridlayer: - if (item.isChecked()) { - item.setChecked(false); - mMap.layers().remove(mGridLayer); - } else { - item.setChecked(true); - if (mGridLayer == null) - mGridLayer = new TileGridLayer(mMap); - - mMap.layers().add(mGridLayer); - } - mMap.updateMap(true); - return true; + mMap.layers().add(mGridLayer); + } + mMap.updateMap(true); + return true; } return false; diff --git a/vtm-android-example/src/org/oscim/android/test/MapsforgeStyleActivity.java b/vtm-android-example/src/org/oscim/android/test/MapsforgeStyleActivity.java index 152222c1e..007b0f4ee 100644 --- a/vtm-android-example/src/org/oscim/android/test/MapsforgeStyleActivity.java +++ b/vtm-android-example/src/org/oscim/android/test/MapsforgeStyleActivity.java @@ -37,22 +37,22 @@ public boolean onCreateOptionsMenu(Menu menu) { @Override public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case R.id.style_1: - item.setChecked(true); - loadTheme("1"); - mMap.clearMap(); - Toast.makeText(this, "Show nature layers", Toast.LENGTH_SHORT).show(); - return true; - case R.id.style_2: - item.setChecked(true); - loadTheme("2"); - mMap.clearMap(); - Toast.makeText(this, "Hide nature layers", Toast.LENGTH_SHORT).show(); - return true; - default: - return false; + int itemId = item.getItemId(); + if (itemId == R.id.style_1) { + item.setChecked(true); + loadTheme("1"); + mMap.clearMap(); + Toast.makeText(this, "Show nature layers", Toast.LENGTH_SHORT).show(); + return true; + } else if (itemId == R.id.style_2) { + item.setChecked(true); + loadTheme("2"); + mMap.clearMap(); + Toast.makeText(this, "Hide nature layers", Toast.LENGTH_SHORT).show(); + return true; } + + return false; } @Override diff --git a/vtm-android-example/src/org/oscim/android/test/ThemeStylerActivity.java b/vtm-android-example/src/org/oscim/android/test/ThemeStylerActivity.java index 65584b002..5413d9c4c 100644 --- a/vtm-android-example/src/org/oscim/android/test/ThemeStylerActivity.java +++ b/vtm-android-example/src/org/oscim/android/test/ThemeStylerActivity.java @@ -163,16 +163,13 @@ public void onRadioButtonClicked(View view) { return; HSV c = null; - switch (view.getId()) { - case R.id.checkBoxArea: - c = areaColor; - break; - case R.id.checkBoxLine: - c = lineColor; - break; - case R.id.checkBoxOutline: - c = outlineColor; - break; + int id = view.getId(); + if (id == R.id.checkBoxArea) { + c = areaColor; + } else if (id == R.id.checkBoxLine) { + c = lineColor; + } else if (id == R.id.checkBoxOutline) { + c = outlineColor; } if (c == null) return; diff --git a/vtm-app/src/org/oscim/app/MapLayers.java b/vtm-app/src/org/oscim/app/MapLayers.java index 56e7cf0b1..ecacbf39e 100644 --- a/vtm-app/src/org/oscim/app/MapLayers.java +++ b/vtm-app/src/org/oscim/app/MapLayers.java @@ -182,19 +182,15 @@ void setBackgroundMap(int id) { App.map.layers().remove(mBackgroundLayer); mBackgroundLayer = null; - switch (id) { - case R.id.menu_layer_openstreetmap: - UrlTileSource tileSource = DefaultSources.OPENSTREETMAP.build(); - tileSource.setHttpRequestHeaders(Collections.singletonMap("User-Agent", "vtm-playground")); - mBackgroundLayer = new BitmapTileLayer(App.map, tileSource); - break; - - case R.id.menu_layer_naturalearth: - mBackgroundLayer = new BitmapTileLayer(App.map, DefaultSources.NE_LANDCOVER.build()); - break; - default: - mBackgroundLayer = mBackroundPlaceholder; - id = -1; + if (id == R.id.menu_layer_openstreetmap) { + UrlTileSource tileSource = DefaultSources.OPENSTREETMAP.build(); + tileSource.setHttpRequestHeaders(Collections.singletonMap("User-Agent", "vtm-playground")); + mBackgroundLayer = new BitmapTileLayer(App.map, tileSource); + } else if (id == R.id.menu_layer_naturalearth) { + mBackgroundLayer = new BitmapTileLayer(App.map, DefaultSources.NE_LANDCOVER.build()); + } else { + mBackgroundLayer = mBackroundPlaceholder; + id = -1; } if (mBackgroundLayer instanceof BitmapTileLayer) diff --git a/vtm-app/src/org/oscim/app/POISearch.java b/vtm-app/src/org/oscim/app/POISearch.java index 2924a3d04..95aaebaaf 100644 --- a/vtm-app/src/org/oscim/app/POISearch.java +++ b/vtm-app/src/org/oscim/app/POISearch.java @@ -293,23 +293,20 @@ public void onOpen(ExtendedMarkerItem item) { } public boolean onContextItemSelected(MenuItem item, GeoPoint geoPoint) { - switch (item.getItemId()) { - case R.id.menu_poi_nearby: - Intent intent = new Intent(App.activity, POIActivity.class); - intent.putExtra("ID", poiMarkers.getBubbledItemId()); - App.activity.startActivityForResult(intent, TileMap.POIS_REQUEST); - return true; - - case R.id.menu_poi_clear: - poiMarkers.removeAllItems(); - mPOIs.clear(); - App.map.updateMap(true); - - return true; - default: + int itemId = item.getItemId(); + if (itemId == R.id.menu_poi_nearby) { + Intent intent = new Intent(App.activity, POIActivity.class); + intent.putExtra("ID", poiMarkers.getBubbledItemId()); + App.activity.startActivityForResult(intent, TileMap.POIS_REQUEST); + return true; + } else if (itemId == R.id.menu_poi_clear) { + poiMarkers.removeAllItems(); + mPOIs.clear(); + App.map.updateMap(true); + + return true; } - return false; + return false; } - } diff --git a/vtm-app/src/org/oscim/app/RouteSearch.java b/vtm-app/src/org/oscim/app/RouteSearch.java index cb2e47a5e..e7a466d16 100644 --- a/vtm-app/src/org/oscim/app/RouteSearch.java +++ b/vtm-app/src/org/oscim/app/RouteSearch.java @@ -321,39 +321,35 @@ public void getRouteAsync() { } boolean onContextItemSelected(MenuItem item, GeoPoint geoPoint) { - switch (item.getItemId()) { - case R.id.menu_route_departure: - mStartPoint = geoPoint; + int itemId = item.getItemId(); + if (itemId == R.id.menu_route_departure) { + mStartPoint = geoPoint; - markerStart = putMarkerItem(markerStart, mStartPoint, START_INDEX, - R.string.departure, R.drawable.marker_departure, -1); - - getRouteAsync(); - return true; - - case R.id.menu_route_destination: - mDestinationPoint = geoPoint; - - markerDestination = putMarkerItem(markerDestination, mDestinationPoint, DEST_INDEX, - R.string.destination, - R.drawable.marker_destination, -1); - - getRouteAsync(); - return true; - - case R.id.menu_route_viapoint: - GeoPoint viaPoint = geoPoint; - addViaPoint(viaPoint); + markerStart = putMarkerItem(markerStart, mStartPoint, START_INDEX, + R.string.departure, R.drawable.marker_departure, -1); - getRouteAsync(); - return true; + getRouteAsync(); + return true; + } else if (itemId == R.id.menu_route_destination) { + mDestinationPoint = geoPoint; - case R.id.menu_route_clear: - clearOverlays(); - return true; + markerDestination = putMarkerItem(markerDestination, mDestinationPoint, DEST_INDEX, + R.string.destination, + R.drawable.marker_destination, -1); - default: + getRouteAsync(); + return true; + } else if (itemId == R.id.menu_route_viapoint) { + GeoPoint viaPoint = geoPoint; + addViaPoint(viaPoint); + + getRouteAsync(); + return true; + } else if (itemId == R.id.menu_route_clear) { + clearOverlays(); + return true; } + return false; } diff --git a/vtm-app/src/org/oscim/app/TileMap.java b/vtm-app/src/org/oscim/app/TileMap.java index 7b72475cd..fd8784780 100755 --- a/vtm-app/src/org/oscim/app/TileMap.java +++ b/vtm-app/src/org/oscim/app/TileMap.java @@ -149,88 +149,62 @@ public boolean onCreateOptionsMenu(Menu menu) { @SuppressWarnings("deprecation") @Override public boolean onOptionsItemSelected(MenuItem item) { - - switch (item.getItemId()) { - case R.id.menu_info_about: - startActivity(new Intent(this, InfoView.class)); - break; - - case R.id.menu_position: - break; - - case R.id.menu_poi_nearby: - Intent intent = new Intent(this, POIActivity.class); - startActivityForResult(intent, TileMap.POIS_REQUEST); - break; - - case R.id.menu_compass_2d: - if (!item.isChecked()) { - // FIXME - //mMapView.getMapViewPosition().setTilt(0); - mCompass.setMode(Compass.Mode.C2D); - } else { - mCompass.setMode(Compass.Mode.OFF); - } - break; - - case R.id.menu_compass_3d: - if (!item.isChecked()) { - mCompass.setMode(Compass.Mode.C3D); - } else { - mCompass.setMode(Compass.Mode.OFF); - } - break; - - case R.id.menu_position_my_location_enable: - if (!item.isChecked()) { - mLocation.setMode(LocationHandler.Mode.SHOW); - mLocation.setCenterOnFirstFix(); - } else { - mLocation.setMode(LocationHandler.Mode.OFF); - } - break; - - case R.id.menu_position_follow_location: - if (!item.isChecked()) { - mLocation.setMode(LocationHandler.Mode.SNAP); - } else { - mLocation.setMode(LocationHandler.Mode.OFF); - } - break; - - case R.id.menu_layer_openstreetmap: - case R.id.menu_layer_naturalearth: - int bgId = item.getItemId(); - // toggle if already enabled - if (bgId == mMapLayers.getBackgroundId()) - bgId = -1; - - mMapLayers.setBackgroundMap(bgId); - mMap.updateMap(true); - break; - - case R.id.menu_layer_grid: - mMapLayers.enableGridOverlay(this, !mMapLayers.isGridEnabled()); - mMap.updateMap(true); - break; - - case R.id.menu_position_enter_coordinates: - showDialog(DIALOG_ENTER_COORDINATES); - break; - - //case R.id.menu_position_map_center: - // MapPosition mapCenter = mBaseLayer.getMapFileCenter(); - // if (mapCenter != null) - // mMap.setCenter(mapCenter.getGeoPoint()); - // break; - - case R.id.menu_preferences: - startActivity(new Intent(this, EditPreferences.class)); - overridePendingTransition(R.anim.slide_right, R.anim.slide_left2); - break; - - default: - return false; + int itemId = item.getItemId(); + if (itemId == R.id.menu_info_about) { + startActivity(new Intent(this, InfoView.class)); + } else if (itemId == R.id.menu_position) { + } else if (itemId == R.id.menu_poi_nearby) { + Intent intent = new Intent(this, POIActivity.class); + startActivityForResult(intent, TileMap.POIS_REQUEST); + } else if (itemId == R.id.menu_compass_2d) { + if (!item.isChecked()) { + // FIXME + //mMapView.getMapViewPosition().setTilt(0); + mCompass.setMode(Compass.Mode.C2D); + } else { + mCompass.setMode(Compass.Mode.OFF); + } + } else if (itemId == R.id.menu_compass_3d) { + if (!item.isChecked()) { + mCompass.setMode(Compass.Mode.C3D); + } else { + mCompass.setMode(Compass.Mode.OFF); + } + } else if (itemId == R.id.menu_position_my_location_enable) { + if (!item.isChecked()) { + mLocation.setMode(LocationHandler.Mode.SHOW); + mLocation.setCenterOnFirstFix(); + } else { + mLocation.setMode(LocationHandler.Mode.OFF); + } + } else if (itemId == R.id.menu_position_follow_location) { + if (!item.isChecked()) { + mLocation.setMode(LocationHandler.Mode.SNAP); + } else { + mLocation.setMode(LocationHandler.Mode.OFF); + } + } else if (itemId == R.id.menu_layer_openstreetmap || itemId == R.id.menu_layer_naturalearth) { + int bgId = item.getItemId(); + // toggle if already enabled + if (bgId == mMapLayers.getBackgroundId()) + bgId = -1; + + mMapLayers.setBackgroundMap(bgId); + mMap.updateMap(true); + } else if (itemId == R.id.menu_layer_grid) { + mMapLayers.enableGridOverlay(this, !mMapLayers.isGridEnabled()); + mMap.updateMap(true); + } else if (itemId == R.id.menu_position_enter_coordinates) { + showDialog(DIALOG_ENTER_COORDINATES); + /*} else if (itemId == R.id.menu_position_map_center) { + MapPosition mapCenter = mBaseLayer.getMapFileCenter(); + if (mapCenter != null) + mMap.setCenter(mapCenter.getGeoPoint());*/ + } else if (itemId == R.id.menu_preferences) { + startActivity(new Intent(this, EditPreferences.class)); + overridePendingTransition(R.anim.slide_right, R.anim.slide_left2); + } else { + return false; } toggleMenuCheck(); diff --git a/vtm-desktop/build.gradle b/vtm-desktop/build.gradle index edf637807..4e105820e 100644 --- a/vtm-desktop/build.gradle +++ b/vtm-desktop/build.gradle @@ -3,7 +3,8 @@ apply plugin: 'maven-publish' dependencies { api project(':vtm-gdx') - api 'com.formdev:svgSalamander:1.1.3' + api 'guru.nidi.com.kitfox:svgSalamander:1.1.3' + api 'net.sf.kxml:kxml2:2.3.0' } sourceSets { diff --git a/vtm/build.gradle b/vtm/build.gradle index 17ff45ddd..943142b30 100644 --- a/vtm/build.gradle +++ b/vtm/build.gradle @@ -2,7 +2,7 @@ apply plugin: 'java-library' apply plugin: 'maven-publish' dependencies { - api 'net.sf.kxml:kxml2:2.3.0' + compileOnly 'net.sf.kxml:kxml2:2.3.0' api "org.slf4j:slf4j-api:$slf4jVersion" compileOnly 'com.google.code.findbugs:jsr305:3.0.2' }