Skip to content

Commit d112be0

Browse files
authored
Removed MapBox related imports (commons-app#5631)
* Fixed Grey empty screen at Upload wizard caption step after denying files permission * Empty commit * Fixed loop issue * Created docs for earlier commits * Fixed javadoc * Fixed spaces * Added added basic features to OSM Maps * Added search ___location feature * Added filter to Open Street Maps * Fixed chipGroup in Open Street Maps * Removed mapBox code * Removed mapBox's code * Reformat code * Reformatted code * Removed rotation feature to map * Removed rotation files and Fixed Marker click problem * Ignored failing tests * Added voice input feature * Fixed test cases * Changed caption and description text * Replaced mapbox to osmdroid in upload activity * Fixed Unit Tests * Made selected marker to be fixed on map * Changed color of map marker * Fixes commons-app#5439 by capitalizing first letter of voice input * Removed mapbox code1 * Removed mapbox code2 * Fixed failing tests * Fixed failing due to merging
1 parent 9041e1b commit d112be0

33 files changed

+261
-831
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package fr.free.nrw.commons
2+
3+
import android.content.Context
4+
import android.graphics.Bitmap
5+
import android.graphics.Canvas
6+
import android.graphics.drawable.BitmapDrawable
7+
import android.graphics.drawable.Drawable
8+
import fr.free.nrw.commons.___location.LatLng
9+
import fr.free.nrw.commons.nearby.Place
10+
11+
class BaseMarker {
12+
private var _position: LatLng = LatLng(0.0, 0.0, 0f)
13+
private var _title: String = ""
14+
private var _place: Place = Place()
15+
private var _icon: Bitmap? = null
16+
17+
var position: LatLng
18+
get() = _position
19+
set(value) {
20+
_position = value
21+
}
22+
var title: String
23+
get() = _title
24+
set(value) {
25+
_title = value
26+
}
27+
28+
var place: Place
29+
get() = _place
30+
set(value) {
31+
_place = value
32+
}
33+
var icon: Bitmap?
34+
get() = _icon
35+
set(value) {
36+
_icon = value
37+
}
38+
39+
constructor() {
40+
}
41+
42+
fun fromResource(context: Context, drawableResId: Int) {
43+
val drawable: Drawable = context.resources.getDrawable(drawableResId)
44+
icon = if (drawable is BitmapDrawable) {
45+
(drawable as BitmapDrawable).bitmap
46+
} else {
47+
val bitmap = Bitmap.createBitmap(
48+
drawable.intrinsicWidth,
49+
drawable.intrinsicHeight, Bitmap.Config.ARGB_8888
50+
)
51+
val canvas = Canvas(bitmap)
52+
drawable.setBounds(0, 0, canvas.width, canvas.height)
53+
drawable.draw(canvas)
54+
bitmap
55+
}
56+
}
57+
}
58+
59+
60+
61+
62+
63+
64+
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package fr.free.nrw.commons
2+
3+
import android.os.Parcel
4+
import android.os.Parcelable
5+
6+
class CameraPosition(val latitude: Double, val longitude: Double, val zoom: Double) : Parcelable {
7+
8+
constructor(parcel: Parcel) : this(
9+
parcel.readDouble(),
10+
parcel.readDouble(),
11+
parcel.readDouble()
12+
)
13+
14+
override fun writeToParcel(parcel: Parcel, flags: Int) {
15+
parcel.writeDouble(latitude)
16+
parcel.writeDouble(longitude)
17+
parcel.writeDouble(zoom)
18+
}
19+
20+
override fun describeContents(): Int {
21+
return 0
22+
}
23+
24+
companion object CREATOR : Parcelable.Creator<CameraPosition> {
25+
override fun createFromParcel(parcel: Parcel): CameraPosition {
26+
return CameraPosition(parcel)
27+
}
28+
29+
override fun newArray(size: Int): Array<CameraPosition?> {
30+
return arrayOfNulls(size)
31+
}
32+
}
33+
}

app/src/main/java/fr/free/nrw/commons/LocationPicker/LocationPicker.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import android.app.Activity;
44
import android.content.Intent;
5-
import com.mapbox.mapboxsdk.camera.CameraPosition;
5+
import fr.free.nrw.commons.CameraPosition;
66
import fr.free.nrw.commons.Media;
77

88
/**

app/src/main/java/fr/free/nrw/commons/LocationPicker/LocationPickerActivity.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@
2929
import androidx.constraintlayout.widget.ConstraintLayout;
3030
import androidx.core.content.ContextCompat;
3131
import com.google.android.material.floatingactionbutton.FloatingActionButton;
32-
import com.mapbox.mapboxsdk.camera.CameraPosition;
33-
import com.mapbox.mapboxsdk.geometry.LatLng;
32+
import fr.free.nrw.commons.CameraPosition;
3433
import fr.free.nrw.commons.Media;
3534
import fr.free.nrw.commons.R;
3635
import fr.free.nrw.commons.Utils;
@@ -43,7 +42,6 @@
4342
import fr.free.nrw.commons.___location.LocationServiceManager;
4443
import fr.free.nrw.commons.theme.BaseActivity;
4544
import fr.free.nrw.commons.utils.SystemThemeUtils;
46-
import fr.free.nrw.commons.utils.ViewUtilWrapper;
4745
import io.reactivex.android.schedulers.AndroidSchedulers;
4846
import io.reactivex.schedulers.Schedulers;
4947
import java.util.List;
@@ -214,9 +212,9 @@ protected void onCreate(@Nullable final Bundle savedInstanceState) {
214212
fabCenterOnLocation.setVisibility(View.GONE);
215213
markerImage.setVisibility(View.GONE);
216214
shadow.setVisibility(View.GONE);
217-
assert cameraPosition.target != null;
218-
showSelectedLocationMarker(new GeoPoint(cameraPosition.target.getLatitude(),
219-
cameraPosition.target.getLongitude()));
215+
assert cameraPosition != null;
216+
showSelectedLocationMarker(new GeoPoint(cameraPosition.getLatitude(),
217+
cameraPosition.getLongitude()));
220218
}
221219
setupMapView();
222220
}
@@ -295,9 +293,11 @@ private void onClickModifyLocation() {
295293
smallToolbarText.setText(getResources().getString(R.string.pan_and_zoom_to_adjust));
296294
fabCenterOnLocation.setVisibility(View.VISIBLE);
297295
removeSelectedLocationMarker();
298-
if (cameraPosition.target != null) {
299-
mapView.getController().animateTo(new GeoPoint(cameraPosition.target.getLatitude(),
300-
cameraPosition.target.getLongitude()));
296+
if (cameraPosition != null && mapView != null) {
297+
if (mapView.getController() != null) {
298+
mapView.getController().animateTo(new GeoPoint(cameraPosition.getLatitude(),
299+
cameraPosition.getLongitude()));
300+
}
301301
}
302302
}
303303

@@ -314,9 +314,9 @@ public void showInMap() {
314314
* move the ___location to the current media coordinates
315315
*/
316316
private void adjustCameraBasedOnOptions() {
317-
if (cameraPosition.target != null) {
318-
mapView.getController().setCenter(new GeoPoint(cameraPosition.target.getLatitude(),
319-
cameraPosition.target.getLongitude()));
317+
if (cameraPosition != null) {
318+
mapView.getController().setCenter(new GeoPoint(cameraPosition.getLatitude(),
319+
cameraPosition.getLongitude()));
320320
}
321321
}
322322

@@ -343,8 +343,8 @@ void placeSelected() {
343343
if (media == null) {
344344
final Intent returningIntent = new Intent();
345345
returningIntent.putExtra(LocationPickerConstants.MAP_CAMERA_POSITION,
346-
new CameraPosition(new LatLng(mapView.getMapCenter().getLatitude(),
347-
mapView.getMapCenter().getLongitude()), 14f, 0, 0));
346+
new CameraPosition(mapView.getMapCenter().getLatitude(),
347+
mapView.getMapCenter().getLongitude(), 14.0));
348348
setResult(AppCompatActivity.RESULT_OK, returningIntent);
349349
} else {
350350
updateCoordinates(String.valueOf(mapView.getMapCenter().getLatitude()),
@@ -408,8 +408,8 @@ private void removeSelectedLocationMarker() {
408408
for (int i = 0; i < overlays.size(); i++) {
409409
if (overlays.get(i) instanceof Marker) {
410410
Marker item = (Marker) overlays.get(i);
411-
if (cameraPosition.target.getLatitude() == item.getPosition().getLatitude()
412-
&& cameraPosition.target.getLongitude() == item.getPosition().getLongitude()) {
411+
if (cameraPosition.getLatitude() == item.getPosition().getLatitude()
412+
&& cameraPosition.getLongitude() == item.getPosition().getLongitude()) {
413413
mapView.getOverlays().remove(i);
414414
mapView.invalidate();
415415
break;

app/src/main/java/fr/free/nrw/commons/LocationPicker/LocationPickerViewModel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import androidx.annotation.NonNull;
55
import androidx.lifecycle.AndroidViewModel;
66
import androidx.lifecycle.MutableLiveData;
7-
import com.mapbox.mapboxsdk.camera.CameraPosition;
7+
import fr.free.nrw.commons.CameraPosition;
88
import org.jetbrains.annotations.NotNull;
99
import retrofit2.Call;
1010
import retrofit2.Callback;

app/src/main/java/fr/free/nrw/commons/MapStyle.java

Lines changed: 0 additions & 12 deletions
This file was deleted.

app/src/main/java/fr/free/nrw/commons/contributions/MainActivity.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,8 +427,6 @@ public void toggleLimitedConnectionMode() {
427427
public void centerMapToPlace(Place place) {
428428
setSelectedItemId(NavTab.NEARBY.code());
429429
nearbyParentFragment.setNearbyParentFragmentInstanceReadyCallback(new NearbyParentFragmentInstanceReadyCallback() {
430-
// if mapBox initialize in nearbyParentFragment then MapReady() function called
431-
// so that nearbyParentFragemt.centerMaptoPlace(place) not throw any null pointer exception
432430
@Override
433431
public void onReady() {
434432
nearbyParentFragment.centerMapToPlace(place);

app/src/main/java/fr/free/nrw/commons/explore/map/ExploreMapContract.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
package fr.free.nrw.commons.explore.map;
22

33
import android.content.Context;
4-
import com.mapbox.mapboxsdk.annotations.Marker;
4+
import fr.free.nrw.commons.BaseMarker;
55
import fr.free.nrw.commons.kvstore.JsonKvStore;
66
import fr.free.nrw.commons.___location.LatLng;
77
import fr.free.nrw.commons.___location.LocationServiceManager;
8-
import fr.free.nrw.commons.nearby.NearbyBaseMarker;
98
import java.util.List;
109

1110
public class ExploreMapContract {
@@ -18,11 +17,10 @@ interface View {
1817
void showLocationOffDialog();
1918
void openLocationSettings();
2019
void hideBottomDetailsSheet();
21-
void displayBottomSheetWithInfo(Marker marker);
2220
LatLng getMapCenter();
2321
LatLng getMapFocus();
2422
LatLng getLastMapFocus();
25-
void addMarkersToMap(final List<NearbyBaseMarker> nearbyBaseMarkers);
23+
void addMarkersToMap(final List<BaseMarker> nearbyBaseMarkers);
2624
void clearAllMarkers();
2725
void addSearchThisAreaButtonAction();
2826
void setSearchThisAreaButtonVisibility(boolean isVisible);

app/src/main/java/fr/free/nrw/commons/explore/map/ExploreMapController.java

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,11 @@
1414
import com.bumptech.glide.request.RequestOptions;
1515
import com.bumptech.glide.request.target.CustomTarget;
1616
import com.bumptech.glide.request.transition.Transition;
17-
import com.mapbox.mapboxsdk.annotations.IconFactory;
18-
import com.mapbox.mapboxsdk.annotations.Marker;
17+
import fr.free.nrw.commons.BaseMarker;
1918
import fr.free.nrw.commons.MapController;
2019
import fr.free.nrw.commons.Media;
2120
import fr.free.nrw.commons.R;
2221
import fr.free.nrw.commons.___location.LatLng;
23-
import fr.free.nrw.commons.nearby.NearbyBaseMarker;
2422
import fr.free.nrw.commons.nearby.Place;
2523
import fr.free.nrw.commons.utils.ImageUtils;
2624
import fr.free.nrw.commons.utils.LocationUtils;
@@ -107,8 +105,8 @@ public ExplorePlacesInfo loadAttractionsFromLocation(LatLng curLatLng, LatLng se
107105

108106
// Sets latestSearchRadius to maximum distance among boundaries and search ___location
109107
for (LatLng bound : boundaryCoordinates) {
110-
double distance = LocationUtils.commonsLatLngToMapBoxLatLng(bound)
111-
.distanceTo(LocationUtils.commonsLatLngToMapBoxLatLng(latestSearchLocation));
108+
double distance = LocationUtils.calculateDistance(bound.getLatitude(),
109+
bound.getLongitude(), searchLatLng.getLatitude(), searchLatLng.getLongitude());
112110
if (distance > latestSearchRadius) {
113111
latestSearchRadius = distance;
114112
}
@@ -130,17 +128,16 @@ public ExplorePlacesInfo loadAttractionsFromLocation(LatLng curLatLng, LatLng se
130128
*
131129
* @return baseMarkerOptions list that holds nearby places with their icons
132130
*/
133-
public static List<NearbyBaseMarker> loadAttractionsFromLocationToBaseMarkerOptions(
131+
public static List<BaseMarker> loadAttractionsFromLocationToBaseMarkerOptions(
134132
LatLng curLatLng,
135133
final List<Place> placeList,
136134
Context context,
137135
NearbyBaseMarkerThumbCallback callback,
138-
Marker selectedMarker,
139136
ExplorePlacesInfo explorePlacesInfo) {
140-
List<NearbyBaseMarker> baseMarkerOptions = new ArrayList<>();
137+
List<BaseMarker> baseMarkerList = new ArrayList<>();
141138

142139
if (placeList == null) {
143-
return baseMarkerOptions;
140+
return baseMarkerList;
144141
}
145142

146143
VectorDrawableCompat vectorDrawable = null;
@@ -153,17 +150,17 @@ public static List<NearbyBaseMarker> loadAttractionsFromLocationToBaseMarkerOpti
153150
}
154151
if (vectorDrawable != null) {
155152
for (Place explorePlace : placeList) {
156-
final NearbyBaseMarker nearbyBaseMarker = new NearbyBaseMarker();
153+
final BaseMarker baseMarker = new BaseMarker();
157154
String distance = formatDistanceBetween(curLatLng, explorePlace.___location);
158155
explorePlace.setDistance(distance);
159156

160-
nearbyBaseMarker.title(
157+
baseMarker.setTitle(
161158
explorePlace.name.substring(5, explorePlace.name.lastIndexOf(".")));
162-
nearbyBaseMarker.position(
163-
new com.mapbox.mapboxsdk.geometry.LatLng(
159+
baseMarker.setPosition(
160+
new fr.free.nrw.commons.___location.LatLng(
164161
explorePlace.___location.getLatitude(),
165-
explorePlace.___location.getLongitude()));
166-
nearbyBaseMarker.place(explorePlace);
162+
explorePlace.___location.getLongitude(), 0));
163+
baseMarker.setPlace(explorePlace);
167164

168165
Glide.with(context)
169166
.asBitmap()
@@ -175,13 +172,13 @@ public static List<NearbyBaseMarker> loadAttractionsFromLocationToBaseMarkerOpti
175172
@Override
176173
public void onResourceReady(@NonNull Bitmap resource,
177174
@Nullable Transition<? super Bitmap> transition) {
178-
nearbyBaseMarker.setIcon(IconFactory.getInstance(context).fromBitmap(
179-
ImageUtils.addRedBorder(resource, 6, context)));
180-
baseMarkerOptions.add(nearbyBaseMarker);
181-
if (baseMarkerOptions.size()
175+
baseMarker.setIcon(
176+
ImageUtils.addRedBorder(resource, 6, context));
177+
baseMarkerList.add(baseMarker);
178+
if (baseMarkerList.size()
182179
== placeList.size()) { // if true, we added all markers to list and can trigger thumbs ready callback
183-
callback.onNearbyBaseMarkerThumbsReady(baseMarkerOptions,
184-
explorePlacesInfo, selectedMarker);
180+
callback.onNearbyBaseMarkerThumbsReady(baseMarkerList,
181+
explorePlacesInfo);
185182
}
186183
}
187184

@@ -193,25 +190,24 @@ public void onLoadCleared(@Nullable Drawable placeholder) {
193190
@Override
194191
public void onLoadFailed(@Nullable final Drawable errorDrawable) {
195192
super.onLoadFailed(errorDrawable);
196-
nearbyBaseMarker.setIcon(IconFactory.getInstance(context)
197-
.fromResource(R.drawable.image_placeholder_96));
198-
baseMarkerOptions.add(nearbyBaseMarker);
199-
if (baseMarkerOptions.size()
193+
baseMarker.fromResource(context, R.drawable.image_placeholder_96);
194+
baseMarkerList.add(baseMarker);
195+
if (baseMarkerList.size()
200196
== placeList.size()) { // if true, we added all markers to list and can trigger thumbs ready callback
201-
callback.onNearbyBaseMarkerThumbsReady(baseMarkerOptions,
202-
explorePlacesInfo, selectedMarker);
197+
callback.onNearbyBaseMarkerThumbsReady(baseMarkerList,
198+
explorePlacesInfo);
203199
}
204200
}
205201
});
206202
}
207203
}
208-
return baseMarkerOptions;
204+
return baseMarkerList;
209205
}
210206

211207
interface NearbyBaseMarkerThumbCallback {
212208

213209
// Callback to notify thumbnails of explore markers are added as icons and ready
214-
void onNearbyBaseMarkerThumbsReady(List<NearbyBaseMarker> baseMarkers,
215-
ExplorePlacesInfo explorePlacesInfo, Marker selectedMarker);
210+
void onNearbyBaseMarkerThumbsReady(List<BaseMarker> baseMarkers,
211+
ExplorePlacesInfo explorePlacesInfo);
216212
}
217213
}

0 commit comments

Comments
 (0)