Compare commits
8 Commits
b87d405683
...
2fb62a46fb
| Author | SHA1 | Date | |
|---|---|---|---|
| 2fb62a46fb | |||
| 5715a76c9e | |||
| 044855ea93 | |||
| c851830bf1 | |||
| f4c9374563 | |||
| 1583437b6e | |||
| 22af6a14bc | |||
| 63d41d14d1 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -9,3 +9,4 @@ DS_Store
|
||||
.cxx
|
||||
local.properties
|
||||
/legacy_code/
|
||||
maptiler*
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
## Strike Maps Project Android Client
|
||||
|
||||
Strike Maps is a project hoping to create a multi-platform, <br>
|
||||
user-facing, complete FOSS mapping stack, focusing on style customization <br>
|
||||
and offline features.
|
||||
user-facing, complete FOSS mapping stack, focusing on customization <br>
|
||||
and offline features.
|
||||
<br>
|
||||
|
||||
This Android app has been in development since around January 2026
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -5,6 +5,7 @@
|
||||
"sources": {
|
||||
"satelite": {
|
||||
"type": "raster",
|
||||
"schema" : "raster",
|
||||
"tiles": [
|
||||
"https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}"
|
||||
],
|
||||
@@ -14,8 +15,6 @@
|
||||
"tileSize": 512
|
||||
}
|
||||
},
|
||||
"sprite": "",
|
||||
"glyphs": "https://orangemug.github.io/font-glyphs/glyphs/{fontstack}/{range}.pbf",
|
||||
"layers": [
|
||||
{
|
||||
"id": "satelite",
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package eu.konggdev.strikemaps.helper;
|
||||
package eu.konggdev.strikemaps.data.helper;
|
||||
|
||||
import android.content.res.AssetManager;
|
||||
import android.os.Environment;
|
||||
@@ -106,4 +106,4 @@ public final class FileHelper {
|
||||
|
||||
return fileList.toArray(new String[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package eu.konggdev.strikemaps.helper;
|
||||
package eu.konggdev.strikemaps.data.helper;
|
||||
|
||||
import android.content.SharedPreferences;
|
||||
|
||||
@@ -37,4 +37,4 @@ public final class UserPrefsHelper {
|
||||
public static boolean lastLocationEnabled(SharedPreferences prefs, boolean status) {
|
||||
return prefs.edit().putBoolean(KEY_LAST_LOCATION_ENABLED, status).commit();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package eu.konggdev.strikemaps.provider;
|
||||
package eu.konggdev.strikemaps.data.provider;
|
||||
|
||||
public class HttpDataProvider implements Provider {
|
||||
//TODO
|
||||
@@ -1,4 +1,4 @@
|
||||
package eu.konggdev.strikemaps.provider;
|
||||
package eu.konggdev.strikemaps.data.provider;
|
||||
|
||||
import android.Manifest;
|
||||
import android.content.Context;
|
||||
@@ -0,0 +1,5 @@
|
||||
package eu.konggdev.strikemaps.data.provider;
|
||||
|
||||
public interface Provider {
|
||||
|
||||
}
|
||||
@@ -2,9 +2,10 @@ package eu.konggdev.strikemaps.map;
|
||||
|
||||
import java.util.*;
|
||||
import eu.konggdev.strikemaps.Component;
|
||||
import eu.konggdev.strikemaps.factory.AlertDialogFactory;
|
||||
import eu.konggdev.strikemaps.helper.UserPrefsHelper;
|
||||
import eu.konggdev.strikemaps.ui.factory.AlertDialogFactory;
|
||||
import eu.konggdev.strikemaps.data.helper.UserPrefsHelper;
|
||||
import eu.konggdev.strikemaps.map.renderer.implementation.VtmRenderer;
|
||||
import eu.konggdev.strikemaps.map.style.MapStyle;
|
||||
import org.maplibre.android.geometry.LatLng;
|
||||
import org.maplibre.geojson.Feature;
|
||||
|
||||
@@ -18,7 +19,7 @@ public class MapComponent implements Component {
|
||||
MapRenderer mapRenderer;
|
||||
AppController app;
|
||||
|
||||
public String style;
|
||||
public MapStyle style;
|
||||
public Map<Class<? extends MapOverlay>, MapOverlay> overlays = new HashMap<>();
|
||||
public MapComponent(AppController ref) {
|
||||
this.app = ref;
|
||||
@@ -37,7 +38,7 @@ public class MapComponent implements Component {
|
||||
return new FragmentLayoutContentMap(mapRenderer.getView());
|
||||
}
|
||||
|
||||
public void setStyle(String style) {
|
||||
public void setStyle(MapStyle style) {
|
||||
this.style = style;
|
||||
mapRenderer.reload();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package eu.konggdev.strikemaps.map.layer;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
|
||||
public class MapLayer {
|
||||
public JsonNode layer;
|
||||
|
||||
public MapLayer(JsonNode layer) {
|
||||
this.layer = layer;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package eu.konggdev.strikemaps.map.layer;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import eu.konggdev.strikemaps.map.source.MapSource;
|
||||
|
||||
public class SourcedMapLayer {
|
||||
public String key;
|
||||
public MapSource source;
|
||||
public JsonNode layer;
|
||||
|
||||
public SourcedMapLayer(String key, MapSource source, JsonNode layer) {
|
||||
this.key = key;
|
||||
this.source = source;
|
||||
this.layer = layer;
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
package eu.konggdev.strikemaps.map.overlay;
|
||||
|
||||
import eu.konggdev.strikemaps.map.layer.MapLayer;
|
||||
import eu.konggdev.strikemaps.map.layer.SourcedMapLayer;
|
||||
|
||||
/* More or less a data-driven layer factory */
|
||||
public interface MapOverlay {
|
||||
public MapLayer makeLayer();
|
||||
public SourcedMapLayer makeLayer();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
package eu.konggdev.strikemaps.map.overlay.implementation;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.location.Location;
|
||||
import android.location.LocationListener;
|
||||
import androidx.annotation.NonNull;
|
||||
import eu.konggdev.strikemaps.app.AppController;
|
||||
import eu.konggdev.strikemaps.map.MapComponent;
|
||||
import eu.konggdev.strikemaps.map.layer.SourcedMapLayer;
|
||||
import eu.konggdev.strikemaps.map.overlay.MapOverlay;
|
||||
import eu.konggdev.strikemaps.map.source.MapSource;
|
||||
|
||||
import eu.konggdev.strikemaps.data.provider.LocationDataProvider;
|
||||
import org.maplibre.geojson.Feature;
|
||||
import org.maplibre.geojson.FeatureCollection;
|
||||
import org.maplibre.geojson.Point;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
|
||||
public class LocationOverlay implements MapOverlay, LocationListener {
|
||||
LocationDataProvider locationDataProvider;
|
||||
AppController app;
|
||||
MapComponent map;
|
||||
|
||||
public Location currentLocation = null;
|
||||
|
||||
public LocationOverlay(AppController app) {
|
||||
this.app = app;
|
||||
this.map = app.getMap();
|
||||
this.locationDataProvider = new LocationDataProvider(app.getActivity(), this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SourcedMapLayer makeLayer() {
|
||||
MapSource source = new MapSource();
|
||||
|
||||
source.type = "geojson";
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
try {
|
||||
ObjectNode data = mapper.createObjectNode();
|
||||
data.put("type", "Feature");
|
||||
|
||||
if(currentLocation != null) {
|
||||
ObjectNode geometry = mapper.createObjectNode();
|
||||
geometry.put("type", "Point");
|
||||
|
||||
ArrayNode coordinates = mapper.createArrayNode();
|
||||
coordinates.add(currentLocation.getLongitude());
|
||||
coordinates.add(currentLocation.getLatitude());
|
||||
|
||||
geometry.set("coordinates", coordinates);
|
||||
data.set("geometry", geometry);
|
||||
data.set("properties", mapper.createObjectNode());
|
||||
}
|
||||
source.data = data;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
ObjectNode layer = mapper.createObjectNode();
|
||||
layer.put("id", "location");
|
||||
layer.put("type", "circle");
|
||||
layer.put("source", "location");
|
||||
|
||||
ObjectNode paint = mapper.createObjectNode();
|
||||
paint.put("circle-radius", 5);
|
||||
paint.put("circle-color", "#1E88E5");
|
||||
paint.put("circle-stroke-color", "#FFFFFF");
|
||||
paint.put("circle-stroke-width", 1.5);
|
||||
|
||||
layer.set("paint", paint);
|
||||
|
||||
ObjectNode layout = mapper.createObjectNode();
|
||||
layout.put("circle-pitch-alignment", "map");
|
||||
|
||||
layer.set("layout", layout);
|
||||
|
||||
ArrayNode layers = mapper.createArrayNode();
|
||||
layers.add(layer);
|
||||
|
||||
return new SourcedMapLayer("location", source, layers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLocationChanged(@NonNull Location location) {
|
||||
this.currentLocation = location;
|
||||
map.onOverlayUpdate();
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,12 @@
|
||||
package eu.konggdev.strikemaps.map.overlay.overlay;
|
||||
package eu.konggdev.strikemaps.map.overlay.implementation;
|
||||
|
||||
import eu.konggdev.strikemaps.map.layer.MapLayer;
|
||||
import eu.konggdev.strikemaps.map.layer.SourcedMapLayer;
|
||||
import eu.konggdev.strikemaps.map.overlay.MapOverlay;
|
||||
|
||||
public class PointSelectionOverlay implements MapOverlay {
|
||||
@Override
|
||||
public MapLayer makeLayer() {
|
||||
public SourcedMapLayer makeLayer() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
package eu.konggdev.strikemaps.map.overlay.overlay;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.location.Location;
|
||||
import android.location.LocationListener;
|
||||
import androidx.annotation.NonNull;
|
||||
import eu.konggdev.strikemaps.app.AppController;
|
||||
import eu.konggdev.strikemaps.map.MapComponent;
|
||||
import eu.konggdev.strikemaps.map.layer.MapLayer;
|
||||
|
||||
import eu.konggdev.strikemaps.map.overlay.MapOverlay;
|
||||
import eu.konggdev.strikemaps.provider.LocationDataProvider;
|
||||
import org.maplibre.android.style.layers.CircleLayer;
|
||||
import org.maplibre.android.style.layers.Property;
|
||||
import org.maplibre.android.style.sources.GeoJsonSource;
|
||||
import org.maplibre.geojson.Feature;
|
||||
import org.maplibre.geojson.FeatureCollection;
|
||||
import org.maplibre.geojson.Point;
|
||||
|
||||
import static org.maplibre.android.style.layers.PropertyFactory.*;
|
||||
|
||||
public class LocationOverlay implements MapOverlay, LocationListener {
|
||||
LocationDataProvider locationDataProvider;
|
||||
AppController app;
|
||||
MapComponent map;
|
||||
|
||||
public Location currentLocation = null;
|
||||
|
||||
public LocationOverlay(AppController app) {
|
||||
this.app = app;
|
||||
this.map = app.getMap();
|
||||
this.locationDataProvider = new LocationDataProvider(app.getActivity(), this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MapLayer makeLayer() {
|
||||
GeoJsonSource source = new GeoJsonSource(
|
||||
"location",
|
||||
FeatureCollection.fromFeatures(new Feature[]{}) // empty
|
||||
);
|
||||
|
||||
if (currentLocation != null)
|
||||
source.setGeoJson(Feature.fromGeometry(Point.fromLngLat(currentLocation.getLongitude(), currentLocation.getLatitude())));
|
||||
|
||||
CircleLayer layer = new CircleLayer("location", "location");
|
||||
layer.setProperties(
|
||||
circleRadius(5f),
|
||||
circleColor(Color.parseColor("#1E88E5")),
|
||||
circleStrokeColor(Color.WHITE),
|
||||
circleStrokeWidth(1.5f),
|
||||
circlePitchAlignment(Property.CIRCLE_PITCH_ALIGNMENT_MAP)
|
||||
);
|
||||
|
||||
return new MapLayer(source, layer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLocationChanged(@NonNull Location location) {
|
||||
this.currentLocation = location;
|
||||
map.onOverlayUpdate();
|
||||
}
|
||||
}
|
||||
@@ -15,5 +15,6 @@ public interface MapRenderer {
|
||||
|
||||
View getView();
|
||||
|
||||
//TODO: Get rid of MapLibre Feature class dependence
|
||||
List<Feature> featuresAtPoint(LatLng point);
|
||||
}
|
||||
|
||||
@@ -4,11 +4,15 @@ import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import eu.konggdev.strikemaps.helper.FileHelper;
|
||||
import eu.konggdev.strikemaps.helper.UserPrefsHelper;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import eu.konggdev.strikemaps.data.helper.UserPrefsHelper;
|
||||
import eu.konggdev.strikemaps.map.overlay.MapOverlay;
|
||||
import eu.konggdev.strikemaps.map.layer.MapLayer;
|
||||
import eu.konggdev.strikemaps.map.layer.SourcedMapLayer;
|
||||
import eu.konggdev.strikemaps.map.renderer.MapRenderer;
|
||||
import eu.konggdev.strikemaps.map.style.MapStyle;
|
||||
import org.maplibre.android.MapLibre;
|
||||
import org.maplibre.android.geometry.LatLng;
|
||||
import org.maplibre.android.maps.MapLibreMap;
|
||||
@@ -37,18 +41,40 @@ public class MapLibreNativeRenderer implements MapRenderer, OnMapReadyCallback {
|
||||
mapView.getMapAsync(this);
|
||||
}
|
||||
|
||||
void passLayer(MapLayer layer) {
|
||||
map.getStyle().addSource(layer.source);
|
||||
map.getStyle().addLayer(layer.layer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload() {
|
||||
map.setStyle(new Style.Builder().fromJson(controller.style), style -> {
|
||||
for(MapOverlay overlay : controller.overlays.values()) {
|
||||
passLayer(overlay.makeLayer());
|
||||
}
|
||||
});
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
|
||||
MapStyle style = controller.style;
|
||||
try {
|
||||
/* Take metadata from MapStyle
|
||||
everything outside sources, layers */
|
||||
ObjectNode root = style.metadata.deepCopy();
|
||||
|
||||
//Sources
|
||||
ObjectNode sources = mapper.createObjectNode();
|
||||
style.sources.forEach((k, v) -> sources.set(k, mapper.valueToTree(v)));
|
||||
|
||||
//Layers
|
||||
ArrayNode layers = mapper.createArrayNode();
|
||||
layers.addAll((ArrayNode) style.layerDefinitions);
|
||||
|
||||
//Overlays
|
||||
for (MapOverlay overlay : controller.overlays.values()) {
|
||||
SourcedMapLayer overlayLayer = overlay.makeLayer();
|
||||
sources.set(overlayLayer.key, mapper.valueToTree(overlayLayer.source));
|
||||
layers.addAll((ArrayNode) overlayLayer.layer);
|
||||
}
|
||||
|
||||
//Set all to root
|
||||
root.set("sources", sources);
|
||||
root.set("layers", layers);
|
||||
|
||||
map.setStyle(new Style.Builder().fromJson(mapper.writeValueAsString(root)));
|
||||
} catch (Exception e) {
|
||||
app.logcat("Failed to reload Map");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -65,7 +91,7 @@ public class MapLibreNativeRenderer implements MapRenderer, OnMapReadyCallback {
|
||||
public void onMapReady(@NonNull MapLibreMap maplibreMap) {
|
||||
this.map = maplibreMap;
|
||||
|
||||
controller.style = FileHelper.loadStringFromAssetFile(UserPrefsHelper.startupMapStyle(app.getPrefs()), app);
|
||||
controller.setStyle(MapStyle.fromMapLibreJsonFile(UserPrefsHelper.startupMapStyle(app.getPrefs()), app));
|
||||
|
||||
//I have my own implementation of attribution that credits MapLibre among others, it's not as bad as it looks :)
|
||||
map.getUiSettings().setLogoEnabled(false);
|
||||
@@ -73,6 +99,5 @@ public class MapLibreNativeRenderer implements MapRenderer, OnMapReadyCallback {
|
||||
|
||||
map.addOnMapClickListener(point -> controller.onMapClick(point));
|
||||
map.addOnMapLongClickListener(point -> controller.onMapLongClick(point));
|
||||
this.reload();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,21 @@
|
||||
package eu.konggdev.strikemaps.map.source;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
|
||||
public class MapSource {
|
||||
public final String url;
|
||||
public final String type;
|
||||
public final String schema;
|
||||
public MapSource(String url, String type, String schema) {
|
||||
this.url = url;
|
||||
this.type = type;
|
||||
this.schema = schema;
|
||||
}
|
||||
public String url;
|
||||
public JsonNode data;
|
||||
public String type;
|
||||
public String schema;
|
||||
|
||||
public JsonNode tiles;
|
||||
public int minzoom;
|
||||
public int maxzoom;
|
||||
public String scheme;
|
||||
public int tileSize;
|
||||
|
||||
public String attribution;
|
||||
|
||||
public String encoding;
|
||||
public MapSource() { }
|
||||
}
|
||||
|
||||
@@ -1,25 +1,26 @@
|
||||
package eu.konggdev.strikemaps.map.style;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import eu.konggdev.strikemaps.app.AppController;
|
||||
import eu.konggdev.strikemaps.helper.FileHelper;
|
||||
import eu.konggdev.strikemaps.map.layer.MapLayer;
|
||||
import eu.konggdev.strikemaps.data.helper.FileHelper;
|
||||
import eu.konggdev.strikemaps.map.source.MapSource;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
public class MapStyle {
|
||||
public int version;
|
||||
//Only local data
|
||||
public String name;
|
||||
public String icon;
|
||||
public String description;
|
||||
public Bitmap icon;
|
||||
|
||||
public JsonNode metadata; // everything except layers + sources
|
||||
public Map<String, MapSource> sources;
|
||||
public List<MapLayer> layers;
|
||||
|
||||
public JsonNode raw;
|
||||
public ArrayNode layerDefinitions; // the "layers" array
|
||||
|
||||
//FIXME
|
||||
public static MapStyle fromMapLibreJsonFile(String filename, AppController app) {
|
||||
@@ -30,34 +31,38 @@ public class MapStyle {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
try {
|
||||
JsonNode root = mapper.readTree(styleContents);
|
||||
MapStyle style = new MapStyle();
|
||||
|
||||
style.version = root.path("version").asInt();
|
||||
MapStyle style = new MapStyle();
|
||||
style.name = root.path("name").asText();
|
||||
style.icon = root.path("icon").asText();
|
||||
style.description = root.path("description").asText();
|
||||
style.icon = getIcon(root.path("icon").asText(), app);
|
||||
|
||||
style.sources = mapper.convertValue(
|
||||
root.path("sources"),
|
||||
new TypeReference<Map<String, MapSource>>() {}
|
||||
);
|
||||
|
||||
style.layers = new ArrayList<>();
|
||||
for (JsonNode layerNode : root.path("layers")) {
|
||||
style.layerDefinitions = root.withArray("layers");
|
||||
|
||||
MapLayer layer = mapper.treeToValue(layerNode, MapLayer.class);
|
||||
|
||||
layer.raw = layerNode; // IMPORTANT
|
||||
|
||||
style.layers.add(layer);
|
||||
}
|
||||
|
||||
style.raw = root; // full backup
|
||||
ObjectNode metadata = root.deepCopy();
|
||||
metadata.remove("layers");
|
||||
metadata.remove("sources");
|
||||
style.metadata = metadata;
|
||||
|
||||
return style;
|
||||
} catch ( Exception e ) {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Bitmap getIcon(String iconLocator, AppController app) {
|
||||
switch(iconLocator.split("//")[0]) {
|
||||
//TODO: https
|
||||
case "assets:":
|
||||
return BitmapFactory.decodeStream(FileHelper.openAssetStream("bundled/icon/" + iconLocator.split("//")[1], app));
|
||||
default:
|
||||
app.logcat("Unimplemented icon locator space: " + iconLocator);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
package eu.konggdev.strikemaps.provider;
|
||||
|
||||
public interface Provider {
|
||||
|
||||
}
|
||||
@@ -1,26 +1,22 @@
|
||||
package eu.konggdev.strikemaps.ui.element.item;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.view.View;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import eu.konggdev.strikemaps.R;
|
||||
import eu.konggdev.strikemaps.app.AppController;
|
||||
import eu.konggdev.strikemaps.helper.FileHelper;
|
||||
import eu.konggdev.strikemaps.map.MapComponent;
|
||||
import eu.konggdev.strikemaps.map.style.MapStyle;
|
||||
import eu.konggdev.strikemaps.ui.UIComponent;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
public class GenericItem implements UIItem {
|
||||
@NonNull public String name;
|
||||
public Bitmap image;
|
||||
public Runnable onClick;
|
||||
boolean hasImage;
|
||||
|
||||
public GenericItem(String refName) {
|
||||
this.name = refName;
|
||||
hasImage = false;
|
||||
@@ -42,28 +38,11 @@ public class GenericItem implements UIItem {
|
||||
hasImage = true;
|
||||
}
|
||||
|
||||
//FIXME: Ugly glue static constructor
|
||||
public final static GenericItem fromStyle(String style, AppController app, MapComponent map) {
|
||||
try {
|
||||
JSONObject styleJson = new JSONObject(style);
|
||||
String name = "Unknown"; //Fallback name
|
||||
if (styleJson.has("name")) name = styleJson.getString("name");
|
||||
if (styleJson.has("icon")) {
|
||||
switch(styleJson.getString("icon").split("//")[0]) {
|
||||
//TODO: https
|
||||
case "assets:":
|
||||
Bitmap icon = BitmapFactory.decodeStream(FileHelper.openAssetStream("bundled/icon/" + styleJson.getString("icon").split("//")[1], app));
|
||||
return new GenericItem(name, icon, () -> map.setStyle(style));
|
||||
default:
|
||||
app.logcat("Unimplemented icon source requested in style: " + name);
|
||||
return new GenericItem(name, () -> map.setStyle(style));
|
||||
}
|
||||
}
|
||||
return new GenericItem(name, () -> map.setStyle(style));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return new GenericItem("Exception!", () -> map.setStyle(style));
|
||||
}
|
||||
public final static GenericItem fromStyle(MapStyle style, MapComponent map) {
|
||||
if(style == null) return new GenericItem("Unknown");
|
||||
if(style.icon != null)
|
||||
return new GenericItem(style.name, style.icon, () -> map.setStyle(style));
|
||||
return new GenericItem(style.name, () -> map.setStyle(style));
|
||||
}
|
||||
public View makeView(UIComponent spawner) {
|
||||
View v = spawner.inflateUi(R.layout.item_generic);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package eu.konggdev.strikemaps.factory;
|
||||
package eu.konggdev.strikemaps.ui.factory;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.graphics.Color;
|
||||
@@ -15,8 +15,8 @@ import android.widget.Toast;
|
||||
|
||||
import eu.konggdev.strikemaps.R;
|
||||
import eu.konggdev.strikemaps.app.AppController;
|
||||
import eu.konggdev.strikemaps.helper.UserPrefsHelper;
|
||||
import eu.konggdev.strikemaps.map.overlay.overlay.LocationOverlay;
|
||||
import eu.konggdev.strikemaps.data.helper.UserPrefsHelper;
|
||||
import eu.konggdev.strikemaps.map.overlay.implementation.LocationOverlay;
|
||||
import eu.konggdev.strikemaps.ui.fragment.popup.FragmentMapChangePopup;
|
||||
|
||||
public class FragmentLayoutControls extends Fragment implements Layout {
|
||||
|
||||
@@ -9,15 +9,15 @@ import android.widget.LinearLayout;
|
||||
|
||||
import eu.konggdev.strikemaps.R;
|
||||
import eu.konggdev.strikemaps.app.AppController;
|
||||
import eu.konggdev.strikemaps.helper.FileHelper;
|
||||
import eu.konggdev.strikemaps.factory.AlertDialogFactory;
|
||||
import eu.konggdev.strikemaps.data.helper.FileHelper;
|
||||
import eu.konggdev.strikemaps.map.MapComponent;
|
||||
|
||||
import eu.konggdev.strikemaps.map.style.MapStyle;
|
||||
import eu.konggdev.strikemaps.ui.UIComponent;
|
||||
import eu.konggdev.strikemaps.ui.element.item.GenericItem;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ public class FragmentMapChangePopup extends Fragment implements Popup {
|
||||
this.ui = app.getUi();
|
||||
this.region = region;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getRegion() {
|
||||
return region;
|
||||
@@ -50,12 +51,11 @@ public class FragmentMapChangePopup extends Fragment implements Popup {
|
||||
//FIXME
|
||||
setupButton(view, R.id.closeButton, click(() -> ui.getCurrentScreen().closePopup()));
|
||||
setupDragHandle(view, view, () -> ui.getCurrentScreen().closePopup());
|
||||
String[] stylePaths = ArrayUtils.addAll(FileHelper.getAssetFiles("bundled/style", ".style.json", app), FileHelper.getUserFiles("style", ".style.json", app));
|
||||
List<View> views = new ArrayList<>();
|
||||
List<String> stylePaths = new ArrayList<>();
|
||||
stylePaths.addAll(Arrays.asList(FileHelper.getAssetFiles("bundled/style", ".style.json", app)));
|
||||
stylePaths.addAll(Arrays.asList(FileHelper.getUserFiles("style", ".style.json", app)));
|
||||
LinearLayout stylesLayout = view.findViewById(R.id.stylesLayout);
|
||||
for(String i : stylePaths) {
|
||||
if(i.startsWith("/storage")) stylesLayout.addView(GenericItem.fromStyle(FileHelper.loadStringFromUserFile(i), app, map).makeView(ui));
|
||||
else stylesLayout.addView(GenericItem.fromStyle(FileHelper.loadStringFromAssetFile(i, app), app, map).makeView(ui));
|
||||
}
|
||||
for (String style : stylePaths)
|
||||
stylesLayout.addView(GenericItem.fromStyle(MapStyle.fromMapLibreJsonFile(style, app), map).makeView(ui));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user