Skip to content

Commit 6118b57

Browse files
author
maskara
committed
Added support for MapView in Nearby
1 parent 784b51e commit 6118b57

File tree

6 files changed

+120
-5
lines changed

6 files changed

+120
-5
lines changed

app/build.gradle

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ dependencies {
1717
compile "com.jakewharton:butterknife:$BUTTERKNIFE_VERSION"
1818
annotationProcessor "com.jakewharton:butterknife-compiler:$BUTTERKNIFE_VERSION"
1919
compile 'com.jakewharton.timber:timber:4.5.1'
20+
compile ('com.mapbox.mapboxsdk:mapbox-android-sdk:5.0.2@aar'){
21+
transitive=true
22+
}
2023

2124
testCompile 'junit:junit:4.12'
2225
androidTestCompile "com.android.support:support-annotations:${project.supportLibVersion}"

app/src/main/java/fr/free/nrw/commons/nearby/NearbyActivity.java

+15-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import android.os.Bundle;
44
import android.support.v4.app.FragmentTransaction;
5-
import android.util.Log;
65
import android.view.Menu;
76
import android.view.MenuInflater;
87
import android.view.MenuItem;
@@ -12,6 +11,7 @@
1211
import fr.free.nrw.commons.theme.BaseActivity;
1312

1413
public class NearbyActivity extends BaseActivity {
14+
private boolean isMapViewActive = false;
1515

1616
private LocationServiceManager locationManager;
1717

@@ -47,21 +47,32 @@ public boolean onOptionsItemSelected(MenuItem item) {
4747
refreshView();
4848
return true;
4949
case R.id.action_map:
50-
Log.d("Nearby","map is clicked");
50+
showMapView();
5151
return true;
5252
default:
5353
return super.onOptionsItemSelected(item);
5454
}
5555
}
5656

57+
private void showMapView() {
58+
isMapViewActive = true;
59+
getSupportFragmentManager().beginTransaction()
60+
.replace(R.id.container, new NearbyMapFragment()).commit();
61+
}
62+
5763
@Override
5864
protected void onResume() {
5965
super.onResume();
6066
}
6167

6268
protected void refreshView() {
63-
getSupportFragmentManager().beginTransaction()
64-
.replace(R.id.container, new NearbyListFragment()).commit();
69+
if (isMapViewActive) {
70+
getSupportFragmentManager().beginTransaction()
71+
.replace(R.id.container, new NearbyMapFragment()).commit();
72+
} else {
73+
getSupportFragmentManager().beginTransaction()
74+
.replace(R.id.container, new NearbyListFragment()).commit();
75+
}
6576
}
6677

6778
public LocationServiceManager getLocationManager() {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package fr.free.nrw.commons.nearby;
2+
3+
import android.app.Fragment;
4+
import android.os.Bundle;
5+
import android.view.LayoutInflater;
6+
import android.view.View;
7+
import android.view.ViewGroup;
8+
9+
import com.mapbox.mapboxsdk.Mapbox;
10+
import com.mapbox.mapboxsdk.maps.MapView;
11+
import com.mapbox.mapboxsdk.maps.MapboxMap;
12+
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
13+
import com.mapbox.services.android.telemetry.MapboxTelemetry;
14+
15+
import butterknife.BindView;
16+
import butterknife.ButterKnife;
17+
import fr.free.nrw.commons.R;
18+
19+
public class NearbyMapFragment extends android.support.v4.app.Fragment {
20+
@BindView(R.id.mapview) MapView mapView;
21+
22+
public NearbyMapFragment() {
23+
24+
}
25+
26+
@Override
27+
public void onCreate(Bundle savedInstanceState) {
28+
super.onCreate(savedInstanceState);
29+
30+
Mapbox.getInstance(getActivity(),
31+
getString(R.string.mapbox_commons_app_token));
32+
MapboxTelemetry.getInstance().setTelemetryEnabled(false);
33+
}
34+
35+
@Override
36+
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
37+
View view = inflater.inflate(R.layout.fragment_nearby_map, container, false);
38+
ButterKnife.bind(this, view);
39+
40+
mapView.onCreate(savedInstanceState);
41+
42+
setHasOptionsMenu(false);
43+
44+
mapView.getMapAsync(new OnMapReadyCallback() {
45+
@Override
46+
public void onMapReady(MapboxMap mapboxMap) {
47+
48+
}
49+
});
50+
51+
return view;
52+
}
53+
54+
@Override
55+
public void onStart() {
56+
mapView.onStart();
57+
super.onStart();
58+
}
59+
60+
@Override
61+
public void onPause() {
62+
mapView.onPause();
63+
super.onPause();
64+
}
65+
66+
@Override
67+
public void onResume() {
68+
mapView.onResume();
69+
super.onResume();
70+
}
71+
72+
@Override
73+
public void onStop() {
74+
mapView.onStop();
75+
super.onStop();
76+
}
77+
78+
@Override
79+
public void onDestroyView() {
80+
mapView.onDestroy();
81+
super.onDestroyView();
82+
}
83+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:mapbox="http://schemas.android.com/tools"
4+
android:orientation="vertical"
5+
android:layout_width="match_parent"
6+
android:layout_height="match_parent">
7+
8+
<com.mapbox.mapboxsdk.maps.MapView
9+
android:id="@+id/mapview"
10+
android:layout_width="match_parent"
11+
android:layout_height="match_parent"
12+
mapbox:mapbox_cameraZoom="11"
13+
mapbox:mapbox_cameraTargetLat="50.0755"
14+
mapbox:mapbox_cameraTargetLng="14.4378"
15+
mapbox:mapbox_styleUrl="@string/style_mapbox_streets" />
16+
</LinearLayout>

app/src/main/res/values/strings.xml

+1
Original file line numberDiff line numberDiff line change
@@ -167,4 +167,5 @@ Tap this message (or hit back) to skip this step.</string>
167167
<string name="beta_opt_in_link">https://play.google.com/apps/testing/fr.free.nrw.commons</string>
168168
<string name="use_wikidata">Use Wikidata</string>
169169
<string name="use_wikidata_summary">(Warning: disabling this may cause large mobile data consumption)</string>
170+
<string name="mapbox_commons_app_token">pk.eyJ1IjoibWFza2FyYXZpdmVrIiwiYSI6ImNqMmxvdzFjMTAwMHYzM283ZWM3eW5tcDAifQ.ib5SZ9EVjwJe6GSKve0bcg</string>
170171
</resources>

gradle.properties

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
gradleVersion = 2.3.0
1+
gradleVersion = 2.2.0
22

33
supportLibVersion = 25.2.0
44

@@ -13,3 +13,4 @@ android.useDeprecatedNdk=true
1313

1414
# Library dependencies
1515
BUTTERKNIFE_VERSION=8.4.0
16+

0 commit comments

Comments
 (0)