From c3e249659692b520a4be6da4879df7ccf3a70363 Mon Sep 17 00:00:00 2001 From: "Daniele Verducci (Slimpenguin)" Date: Mon, 10 Jan 2022 20:01:39 +0100 Subject: [PATCH] WIP adding map picker --- .idea/misc.xml | 3 +- .../activity/mappicker/MapPickerActivity.java | 59 ++++++++++++++++++- app/src/main/res/drawable/ic_add_gps.xml | 5 ++ app/src/main/res/drawable/ic_add_map.xml | 5 ++ .../res/drawable/round_button_background.xml | 9 +++ .../main/res/layout/activity_map_picker.xml | 35 +++++++++-- app/src/main/res/values/dimens.xml | 2 +- 7 files changed, 111 insertions(+), 7 deletions(-) create mode 100644 app/src/main/res/drawable/ic_add_gps.xml create mode 100644 app/src/main/res/drawable/ic_add_map.xml create mode 100644 app/src/main/res/drawable/round_button_background.xml diff --git a/.idea/misc.xml b/.idea/misc.xml index 784e5f5..d29dea7 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -10,10 +10,11 @@ + - + diff --git a/app/src/main/java/it/danieleverducci/nextcloudmaps/activity/mappicker/MapPickerActivity.java b/app/src/main/java/it/danieleverducci/nextcloudmaps/activity/mappicker/MapPickerActivity.java index 491bff3..4073757 100644 --- a/app/src/main/java/it/danieleverducci/nextcloudmaps/activity/mappicker/MapPickerActivity.java +++ b/app/src/main/java/it/danieleverducci/nextcloudmaps/activity/mappicker/MapPickerActivity.java @@ -1,6 +1,7 @@ package it.danieleverducci.nextcloudmaps.activity.mappicker; import android.os.Bundle; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; @@ -8,10 +9,22 @@ import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; import androidx.preference.PreferenceManager; +import org.osmdroid.api.IGeoPoint; +import org.osmdroid.api.IMapController; import org.osmdroid.config.Configuration; import org.osmdroid.config.IConfigurationProvider; +import org.osmdroid.events.MapEventsReceiver; +import org.osmdroid.events.MapListener; +import org.osmdroid.events.ScrollEvent; +import org.osmdroid.events.ZoomEvent; +import org.osmdroid.util.GeoPoint; +import org.osmdroid.views.CustomZoomButtonsController; +import org.osmdroid.views.MapView; +import org.osmdroid.views.Projection; +import org.osmdroid.views.overlay.MapEventsOverlay; import it.danieleverducci.nextcloudmaps.BuildConfig; +import it.danieleverducci.nextcloudmaps.R; import it.danieleverducci.nextcloudmaps.databinding.ActivityMapPickerBinding; public class MapPickerActivity extends AppCompatActivity { @@ -34,9 +47,50 @@ public class MapPickerActivity extends AppCompatActivity { private class ViewHolder implements View.OnClickListener { private final ActivityMapPickerBinding binding; + private final MapView map; public ViewHolder(LayoutInflater inflater) { this.binding = ActivityMapPickerBinding.inflate(inflater); + + // Show confirm button on lat/lng edit + View.OnFocusChangeListener latlonFocusListener = new View.OnFocusChangeListener() { + @Override + public void onFocusChange(View view, boolean focused) { + if (!focused) + return; + + (ViewHolder.this).binding.latlonConfirmBtn.setVisibility(View.VISIBLE); + } + }; + this.binding.latEt.setOnFocusChangeListener(latlonFocusListener); + this.binding.lonEt.setOnFocusChangeListener(latlonFocusListener); + + // Setup map + this.map = this.binding.map; + this.map.getZoomController().setVisibility(CustomZoomButtonsController.Visibility.NEVER); + this.map.setMultiTouchControls(true); + IMapController mapController = binding.map.getController(); + mapController.setZoom(7.0f); + this.map.addMapListener(new MapListener() { + @Override + public boolean onScroll(ScrollEvent event) { + // Convert XY coords to LatLng + Projection p = (ViewHolder.this).map.getProjection(); + IGeoPoint igp = p.fromPixels(event.getX(), event.getY()); + (ViewHolder.this).binding.latEt.setText(String.format("%.06f", igp.getLatitude())); + (ViewHolder.this).binding.lonEt.setText(String.format("%.06f", igp.getLongitude())); + return false; + } + + @Override + public boolean onZoom(ZoomEvent event) { + return false; + } + }); + + // Setup onClick + this.binding.latlonConfirmBtn.setOnClickListener(this); + } public View getRootView() { @@ -45,7 +99,10 @@ public class MapPickerActivity extends AppCompatActivity { @Override public void onClick(View view) { - + if (view == this.binding.latlonConfirmBtn) { + // TODO: Move map + view.setVisibility(View.GONE); + } } } diff --git a/app/src/main/res/drawable/ic_add_gps.xml b/app/src/main/res/drawable/ic_add_gps.xml new file mode 100644 index 0000000..8597600 --- /dev/null +++ b/app/src/main/res/drawable/ic_add_gps.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/drawable/ic_add_map.xml b/app/src/main/res/drawable/ic_add_map.xml new file mode 100644 index 0000000..ffd9dd9 --- /dev/null +++ b/app/src/main/res/drawable/ic_add_map.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/drawable/round_button_background.xml b/app/src/main/res/drawable/round_button_background.xml new file mode 100644 index 0000000..31aaf67 --- /dev/null +++ b/app/src/main/res/drawable/round_button_background.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_map_picker.xml b/app/src/main/res/layout/activity_map_picker.xml index 5fbd267..aa20f15 100644 --- a/app/src/main/res/layout/activity_map_picker.xml +++ b/app/src/main/res/layout/activity_map_picker.xml @@ -11,6 +11,13 @@ android:layout_width="match_parent" android:layout_height="match_parent"/> + + + android:textAlignment="center" + android:background="@color/whiteAlpha" + android:lines="1" + android:maxLines="1" + android:inputType="numberDecimal"/> + android:textAlignment="center" + android:background="@color/whiteAlpha" + android:lines="1" + android:maxLines="1" + android:inputType="numberDecimal"/> + + diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index f30ed27..9b077fd 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -37,6 +37,6 @@ 12sp - 55dp + 75dp