WIP adding map picker
This commit is contained in:
		@@ -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);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										5
									
								
								app/src/main/res/drawable/ic_add_gps.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								app/src/main/res/drawable/ic_add_gps.xml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,5 @@
 | 
			
		||||
<vector android:height="24dp" android:tint="#FFFFFF"
 | 
			
		||||
    android:viewportHeight="24" android:viewportWidth="24"
 | 
			
		||||
    android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
 | 
			
		||||
    <path android:fillColor="@android:color/white" android:pathData="M12,8c-2.21,0 -4,1.79 -4,4s1.79,4 4,4 4,-1.79 4,-4 -1.79,-4 -4,-4zM20.94,11c-0.46,-4.17 -3.77,-7.48 -7.94,-7.94L13,1h-2v2.06C6.83,3.52 3.52,6.83 3.06,11L1,11v2h2.06c0.46,4.17 3.77,7.48 7.94,7.94L11,23h2v-2.06c4.17,-0.46 7.48,-3.77 7.94,-7.94L23,13v-2h-2.06zM12,19c-3.87,0 -7,-3.13 -7,-7s3.13,-7 7,-7 7,3.13 7,7 -3.13,7 -7,7z"/>
 | 
			
		||||
</vector>
 | 
			
		||||
							
								
								
									
										5
									
								
								app/src/main/res/drawable/ic_add_map.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								app/src/main/res/drawable/ic_add_map.xml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,5 @@
 | 
			
		||||
<vector android:height="24dp" android:tint="#FFFFFF"
 | 
			
		||||
    android:viewportHeight="24" android:viewportWidth="24"
 | 
			
		||||
    android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
 | 
			
		||||
    <path android:fillColor="@android:color/white" android:pathData="M20.5,3l-0.16,0.03L15,5.1 9,3 3.36,4.9c-0.21,0.07 -0.36,0.25 -0.36,0.48V20.5c0,0.28 0.22,0.5 0.5,0.5l0.16,-0.03L9,18.9l6,2.1 5.64,-1.9c0.21,-0.07 0.36,-0.25 0.36,-0.48V3.5c0,-0.28 -0.22,-0.5 -0.5,-0.5zM15,19l-6,-2.11V5l6,2.11V19z"/>
 | 
			
		||||
</vector>
 | 
			
		||||
							
								
								
									
										9
									
								
								app/src/main/res/drawable/round_button_background.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								app/src/main/res/drawable/round_button_background.xml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,9 @@
 | 
			
		||||
<?xml version="1.0" encoding="utf-8"?>
 | 
			
		||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
 | 
			
		||||
    <item>
 | 
			
		||||
        <shape
 | 
			
		||||
            android:shape="oval">
 | 
			
		||||
            <solid android:color="@color/defaultBrand"/>
 | 
			
		||||
        </shape>
 | 
			
		||||
    </item>
 | 
			
		||||
</layer-list>
 | 
			
		||||
@@ -11,6 +11,13 @@
 | 
			
		||||
            android:layout_width="match_parent"
 | 
			
		||||
            android:layout_height="match_parent"/>
 | 
			
		||||
 | 
			
		||||
        <ImageView
 | 
			
		||||
            android:layout_width="48dp"
 | 
			
		||||
            android:layout_height="48dp"
 | 
			
		||||
            android:layout_marginBottom="24dp"
 | 
			
		||||
            android:layout_gravity="center"
 | 
			
		||||
            android:src="@drawable/ic_map_pin"/>
 | 
			
		||||
 | 
			
		||||
        <ImageView
 | 
			
		||||
            android:id="@+id/back_bt"
 | 
			
		||||
            android:layout_width="?attr/actionBarSize"
 | 
			
		||||
@@ -41,17 +48,37 @@
 | 
			
		||||
            <EditText
 | 
			
		||||
                android:id="@+id/lat_et"
 | 
			
		||||
                android:layout_width="0dp"
 | 
			
		||||
                android:layout_height="wrap_content"
 | 
			
		||||
                android:layout_height="48dp"
 | 
			
		||||
                android:layout_weight="1"
 | 
			
		||||
                android:layout_marginEnd="10dp"
 | 
			
		||||
                android:background="@color/whiteAlpha"/>
 | 
			
		||||
                android:textAlignment="center"
 | 
			
		||||
                android:background="@color/whiteAlpha"
 | 
			
		||||
                android:lines="1"
 | 
			
		||||
                android:maxLines="1"
 | 
			
		||||
                android:inputType="numberDecimal"/>
 | 
			
		||||
 | 
			
		||||
            <EditText
 | 
			
		||||
                android:id="@+id/lon_et"
 | 
			
		||||
                android:layout_width="0dp"
 | 
			
		||||
                android:layout_height="wrap_content"
 | 
			
		||||
                android:layout_height="48dp"
 | 
			
		||||
                android:layout_weight="1"
 | 
			
		||||
                android:background="@color/whiteAlpha"/>
 | 
			
		||||
                android:textAlignment="center"
 | 
			
		||||
                android:background="@color/whiteAlpha"
 | 
			
		||||
                android:lines="1"
 | 
			
		||||
                android:maxLines="1"
 | 
			
		||||
                android:inputType="numberDecimal"/>
 | 
			
		||||
 | 
			
		||||
            <ImageView
 | 
			
		||||
                android:id="@+id/latlon_confirm_btn"
 | 
			
		||||
                android:layout_width="48dp"
 | 
			
		||||
                android:layout_height="48dp"
 | 
			
		||||
                android:layout_marginLeft="10dp"
 | 
			
		||||
                android:padding="8dp"
 | 
			
		||||
                android:layout_gravity="center_vertical"
 | 
			
		||||
                android:src="@drawable/ic_ok"
 | 
			
		||||
                app:tint="@color/white"
 | 
			
		||||
                android:background="@drawable/round_button_background"
 | 
			
		||||
                android:visibility="gone"/>
 | 
			
		||||
 | 
			
		||||
        </LinearLayout>
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -37,6 +37,6 @@
 | 
			
		||||
    <dimen name="two_line_secondary_text_size">12sp</dimen>
 | 
			
		||||
 | 
			
		||||
    <!-- FAB dimensions -->
 | 
			
		||||
    <dimen name="fab_vertical_offset">55dp</dimen>
 | 
			
		||||
    <dimen name="fab_vertical_offset">75dp</dimen>
 | 
			
		||||
 | 
			
		||||
</resources>
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user