mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 04:43:54 +01:00
* Add option to centre on GPS location for issue #5008 * Rename and add new comments for issue #5008 * Add new comments for issue #5008 * Update comments for issue #5008
This commit is contained in:
parent
7b18c3eeb7
commit
6dec69147f
2 changed files with 56 additions and 0 deletions
|
|
@ -11,6 +11,7 @@ import static fr.free.nrw.commons.upload.mediaDetails.UploadMediaDetailFragment.
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.graphics.BitmapFactory;
|
import android.graphics.BitmapFactory;
|
||||||
|
import android.location.Location;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.text.Html;
|
import android.text.Html;
|
||||||
import android.text.method.LinkMovementMethod;
|
import android.text.method.LinkMovementMethod;
|
||||||
|
|
@ -20,6 +21,7 @@ import android.view.animation.OvershootInterpolator;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.appcompat.app.ActionBar;
|
import androidx.appcompat.app.ActionBar;
|
||||||
|
|
@ -29,6 +31,8 @@ import androidx.constraintlayout.widget.ConstraintLayout;
|
||||||
import androidx.lifecycle.Observer;
|
import androidx.lifecycle.Observer;
|
||||||
import androidx.lifecycle.ViewModelProvider;
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||||
|
import com.mapbox.android.core.location.LocationEngineCallback;
|
||||||
|
import com.mapbox.android.core.location.LocationEngineResult;
|
||||||
import com.mapbox.android.core.permissions.PermissionsManager;
|
import com.mapbox.android.core.permissions.PermissionsManager;
|
||||||
import com.mapbox.geojson.Point;
|
import com.mapbox.geojson.Point;
|
||||||
import com.mapbox.mapboxsdk.camera.CameraPosition;
|
import com.mapbox.mapboxsdk.camera.CameraPosition;
|
||||||
|
|
@ -92,6 +96,10 @@ public class LocationPickerActivity extends BaseActivity implements OnMapReadyCa
|
||||||
* activity : activity key
|
* activity : activity key
|
||||||
*/
|
*/
|
||||||
private String activity;
|
private String activity;
|
||||||
|
/**
|
||||||
|
* location : location
|
||||||
|
*/
|
||||||
|
private Location location;
|
||||||
/**
|
/**
|
||||||
* modifyLocationButton : button for start editing location
|
* modifyLocationButton : button for start editing location
|
||||||
*/
|
*/
|
||||||
|
|
@ -104,6 +112,10 @@ public class LocationPickerActivity extends BaseActivity implements OnMapReadyCa
|
||||||
* placeSelectedButton : fab for selecting location
|
* placeSelectedButton : fab for selecting location
|
||||||
*/
|
*/
|
||||||
FloatingActionButton placeSelectedButton;
|
FloatingActionButton placeSelectedButton;
|
||||||
|
/**
|
||||||
|
* fabCenterOnLocation: button for center on location;
|
||||||
|
*/
|
||||||
|
FloatingActionButton fabCenterOnLocation;
|
||||||
/**
|
/**
|
||||||
* droppedMarkerLayer : Layer for static screen
|
* droppedMarkerLayer : Layer for static screen
|
||||||
*/
|
*/
|
||||||
|
|
@ -154,6 +166,7 @@ public class LocationPickerActivity extends BaseActivity implements OnMapReadyCa
|
||||||
addPlaceSelectedButton();
|
addPlaceSelectedButton();
|
||||||
addCredits();
|
addCredits();
|
||||||
getToolbarUI();
|
getToolbarUI();
|
||||||
|
addCenterOnGPSButton();
|
||||||
|
|
||||||
if ("UploadActivity".equals(activity)) {
|
if ("UploadActivity".equals(activity)) {
|
||||||
placeSelectedButton.setVisibility(View.GONE);
|
placeSelectedButton.setVisibility(View.GONE);
|
||||||
|
|
@ -162,6 +175,7 @@ public class LocationPickerActivity extends BaseActivity implements OnMapReadyCa
|
||||||
largeToolbarText.setText(getResources().getString(R.string.image_location));
|
largeToolbarText.setText(getResources().getString(R.string.image_location));
|
||||||
smallToolbarText.setText(getResources().
|
smallToolbarText.setText(getResources().
|
||||||
getString(R.string.check_whether_location_is_correct));
|
getString(R.string.check_whether_location_is_correct));
|
||||||
|
fabCenterOnLocation.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
mapView.onCreate(savedInstanceState);
|
mapView.onCreate(savedInstanceState);
|
||||||
|
|
@ -275,6 +289,7 @@ public class LocationPickerActivity extends BaseActivity implements OnMapReadyCa
|
||||||
largeToolbarText.setText(getResources().getString(R.string.choose_a_location));
|
largeToolbarText.setText(getResources().getString(R.string.choose_a_location));
|
||||||
smallToolbarText.setText(getResources().getString(R.string.pan_and_zoom_to_adjust));
|
smallToolbarText.setText(getResources().getString(R.string.pan_and_zoom_to_adjust));
|
||||||
bindListeners();
|
bindListeners();
|
||||||
|
fabCenterOnLocation.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -339,6 +354,20 @@ public class LocationPickerActivity extends BaseActivity implements OnMapReadyCa
|
||||||
// Set the component's render mode
|
// Set the component's render mode
|
||||||
locationComponent.setRenderMode(RenderMode.NORMAL);
|
locationComponent.setRenderMode(RenderMode.NORMAL);
|
||||||
|
|
||||||
|
// Get the component's location engine to receive user's last location
|
||||||
|
locationComponent.getLocationEngine().getLastLocation(
|
||||||
|
new LocationEngineCallback<LocationEngineResult>() {
|
||||||
|
@Override
|
||||||
|
public void onSuccess(LocationEngineResult result) {
|
||||||
|
location = result.getLastLocation();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(@NonNull Exception exception) {
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -405,6 +434,19 @@ public class LocationPickerActivity extends BaseActivity implements OnMapReadyCa
|
||||||
setResult(AppCompatActivity.RESULT_OK, returningIntent);
|
setResult(AppCompatActivity.RESULT_OK, returningIntent);
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Center the camera on the last saved location
|
||||||
|
*/
|
||||||
|
private void addCenterOnGPSButton(){
|
||||||
|
fabCenterOnLocation = findViewById(R.id.center_on_gps);
|
||||||
|
fabCenterOnLocation.setOnClickListener(view -> getCenter());
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Animate map to move to desired Latitude and Longitude
|
||||||
|
*/
|
||||||
|
void getCenter() {
|
||||||
|
mapboxMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(location.getLatitude(),location.getLongitude()),15.0));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onStart() {
|
protected void onStart() {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_gravity="bottom">
|
android:layout_gravity="bottom">
|
||||||
|
|
@ -19,6 +20,19 @@
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:srcCompat="@drawable/ic_check_black_24dp" />
|
app:srcCompat="@drawable/ic_check_black_24dp" />
|
||||||
|
|
||||||
|
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||||
|
android:id="@+id/center_on_gps"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginBottom="20dp"
|
||||||
|
android:contentDescription="@string/select_location_location_picker"
|
||||||
|
app:backgroundTint="@color/white"
|
||||||
|
app:elevation="3dp"
|
||||||
|
app:layout_anchorGravity="bottom|end"
|
||||||
|
app:layout_constraintBottom_toTopOf="@+id/location_chosen_button"
|
||||||
|
app:layout_constraintEnd_toEndOf="@id/location_chosen_button"
|
||||||
|
app:srcCompat="@drawable/ic_my_location_black_24dp" />
|
||||||
|
|
||||||
<androidx.appcompat.widget.AppCompatTextView
|
<androidx.appcompat.widget.AppCompatTextView
|
||||||
android:id="@+id/tv_attribution"
|
android:id="@+id/tv_attribution"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue