Preparation skeleton for Offline maps implementation
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
package eu.konggdev.strikemaps.map.offline;
|
||||
|
||||
import java.io.IOException;
|
||||
public final class OfflineTileResolver {
|
||||
public byte[] resolve(String url) throws IOException {
|
||||
|
||||
//byte[] data = getOfflineTile();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package eu.konggdev.strikemaps.map.offline.download;
|
||||
|
||||
import eu.konggdev.strikemaps.map.source.MapSource;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
public final class OfflineDownloader {
|
||||
|
||||
public static String[] fetchAvailableExports(MapSource source) {
|
||||
URI uri = URI.create(source.url);
|
||||
String host = uri.getHost();
|
||||
return new String[0];
|
||||
}
|
||||
|
||||
public static void download(MapSource source, String export) {
|
||||
//TODO
|
||||
}
|
||||
|
||||
public static void download(MapSource source, int[] bounds) {
|
||||
//TODO
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,7 @@ import eu.konggdev.strikemaps.ui.element.region.content.MainContentRegion;
|
||||
import eu.konggdev.strikemaps.ui.element.region.UIRegion;
|
||||
import eu.konggdev.strikemaps.ui.fragment.layout.FragmentLayoutControls;
|
||||
import eu.konggdev.strikemaps.ui.fragment.layout.FragmentLayoutSearch;
|
||||
import eu.konggdev.strikemaps.ui.fragment.layout.content.main.FragmentLayoutContentOfflineMaps;
|
||||
import eu.konggdev.strikemaps.ui.fragment.layout.content.main.FragmentLayoutContentSettings;
|
||||
import eu.konggdev.strikemaps.ui.screen.Screen;
|
||||
import eu.konggdev.strikemaps.ui.screen.definition.DefinedScreen;
|
||||
@@ -51,6 +52,13 @@ public class UIComponent implements Component {
|
||||
Map.of(
|
||||
R.id.mainContentView, new MainContentRegion(new FragmentLayoutContentSettings(app), R.id.mainContentView)
|
||||
)
|
||||
),
|
||||
//Offline maps screen
|
||||
DefinedScreen.OFFLINE, new Screen(
|
||||
app,
|
||||
Map.of(
|
||||
R.id.mainContentView, new MainContentRegion(new FragmentLayoutContentOfflineMaps(app), R.id.mainContentView)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -4,33 +4,36 @@ import android.graphics.Bitmap;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import eu.konggdev.strikemaps.ui.UIComponent;
|
||||
import org.maplibre.geojson.Feature;
|
||||
|
||||
import eu.konggdev.strikemaps.R;
|
||||
public class PreviewItem implements UIItem {
|
||||
public String name;
|
||||
public String type;
|
||||
@NonNull public String name;
|
||||
public String details;
|
||||
public Bitmap image;
|
||||
boolean hasImage;
|
||||
public PreviewItem(String refName, String refType) {
|
||||
this.name = refName;
|
||||
this.type = refType;
|
||||
this.details = refType;
|
||||
hasImage = false;
|
||||
}
|
||||
public PreviewItem(String refName, String refType, Bitmap refImage) {
|
||||
this.name = refName;
|
||||
this.type = refType;
|
||||
this.details = refType;
|
||||
this.image = refImage;
|
||||
hasImage = true;
|
||||
}
|
||||
|
||||
public static PreviewItem fromFeature(Feature feature) {
|
||||
return new PreviewItem(feature.getStringProperty("name"), feature.getStringProperty("class"));
|
||||
}
|
||||
public View makeView(UIComponent spawner) {
|
||||
View view = spawner.inflateUi(R.layout.item_preview);
|
||||
((TextView) view.findViewById(R.id.choiceName)).setText(name);
|
||||
((TextView) view.findViewById(R.id.type)).setText(type);
|
||||
if (details != null)
|
||||
((TextView) view.findViewById(R.id.details)).setText(details);
|
||||
return view;
|
||||
}
|
||||
public View makeView(UIComponent spawner, View.OnClickListener onClick) {
|
||||
|
||||
@@ -12,5 +12,4 @@ public interface UIItem {
|
||||
}
|
||||
|
||||
default View.OnLongClickListener longClick(Runnable action) { return v -> { action.run(); return true; };}
|
||||
|
||||
}
|
||||
|
||||
+39
-3
@@ -1,6 +1,5 @@
|
||||
package eu.konggdev.strikemaps.ui.fragment.layout;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.os.Bundle;
|
||||
@@ -10,7 +9,6 @@ import android.view.ViewGroup;
|
||||
import android.widget.PopupWindow;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import android.widget.PopupMenu;
|
||||
|
||||
import eu.konggdev.strikemaps.R;
|
||||
import eu.konggdev.strikemaps.app.AppController;
|
||||
@@ -41,9 +39,11 @@ public class FragmentLayoutSearch extends Fragment implements Layout {
|
||||
public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
|
||||
|
||||
setupButton(view, R.id.hamburgerButton, click(() -> {
|
||||
|
||||
View menuView = getLayoutInflater().inflate(R.layout.menu_dropdown, null);
|
||||
View menuView = getLayoutInflater().inflate(R.layout.dropdown_main, null);
|
||||
|
||||
PopupWindow popupWindow = new PopupWindow(
|
||||
menuView,
|
||||
@@ -85,5 +85,41 @@ public class FragmentLayoutSearch extends Fragment implements Layout {
|
||||
});
|
||||
|
||||
}));
|
||||
|
||||
setupButton(view, R.id.offlineMapsButton, click(() -> {
|
||||
View offlineMapsPopupView = getLayoutInflater().inflate(R.layout.dropdown_offline, null);
|
||||
|
||||
PopupWindow popupWindow = new PopupWindow(
|
||||
offlineMapsPopupView,
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT,
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT,
|
||||
true
|
||||
);
|
||||
|
||||
popupWindow.setOutsideTouchable(true);
|
||||
popupWindow.setFocusable(true);
|
||||
popupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
|
||||
|
||||
View anchor = view.findViewById(R.id.searchContainer);
|
||||
|
||||
setupButton(offlineMapsPopupView, R.id.offlineMaps, click(() -> {
|
||||
popupWindow.dismiss();
|
||||
app.getUi().swapScreen(DefinedScreen.OFFLINE);
|
||||
}));
|
||||
|
||||
anchor.post(() -> {
|
||||
|
||||
offlineMapsPopupView.measure(
|
||||
View.MeasureSpec.UNSPECIFIED,
|
||||
View.MeasureSpec.UNSPECIFIED
|
||||
);
|
||||
|
||||
int popupWidth = offlineMapsPopupView.getMeasuredWidth();
|
||||
int containerWidth = anchor.getWidth();
|
||||
|
||||
int xOffset = containerWidth - popupWidth;
|
||||
popupWindow.showAsDropDown(anchor, xOffset, 1);
|
||||
});
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
package eu.konggdev.strikemaps.ui.fragment.layout.content.main;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import eu.konggdev.strikemaps.R;
|
||||
import eu.konggdev.strikemaps.app.AppController;
|
||||
import eu.konggdev.strikemaps.data.helper.FileHelper;
|
||||
import eu.konggdev.strikemaps.map.source.MapSource;
|
||||
import eu.konggdev.strikemaps.map.style.MapStyle;
|
||||
import eu.konggdev.strikemaps.ui.element.item.GenericItem;
|
||||
import eu.konggdev.strikemaps.ui.element.item.PreviewItem;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class FragmentLayoutContentOfflineMaps extends Fragment implements MainContentLayout {
|
||||
@NonNull AppController app;
|
||||
|
||||
public FragmentLayoutContentOfflineMaps(AppController app) {
|
||||
super(R.layout.fragment_offline_maps);
|
||||
this.app = app;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Fragment toFragment() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
List<MapSource> sources = 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)));
|
||||
/* Parsing an entire MapStyle is absolutely unnecessary and resource wasteful
|
||||
TODO: A method should be implemented to parse a List<MapSource> directly from the JSON */
|
||||
for (String stylePath : stylePaths) {
|
||||
MapStyle parsedStyle = MapStyle.fromFile(stylePath, app);
|
||||
sources.addAll(parsedStyle.sources.values());
|
||||
}
|
||||
|
||||
LinearLayout sourcesLayout = view.findViewById(R.id.llDownloadContainer);
|
||||
for (MapSource source : sources) {
|
||||
if (!Objects.equals(source.type, "raster"))
|
||||
sourcesLayout.addView(new PreviewItem(source.url, "").makeView(app.getUi()));
|
||||
else
|
||||
sourcesLayout.addView(new PreviewItem(source.tiles.toString(), "").makeView(app.getUi()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package eu.konggdev.strikemaps.ui.screen.definition;
|
||||
public enum DefinedScreen {
|
||||
MAIN,
|
||||
SETTINGS
|
||||
SETTINGS,
|
||||
OFFLINE
|
||||
}
|
||||
Reference in New Issue
Block a user