Added support for MapView in Nearby

This commit is contained in:
maskara 2017-05-12 12:51:39 +02:00
parent 784b51e29d
commit 6118b57295
6 changed files with 120 additions and 5 deletions

View file

@ -17,6 +17,9 @@ dependencies {
compile "com.jakewharton:butterknife:$BUTTERKNIFE_VERSION"
annotationProcessor "com.jakewharton:butterknife-compiler:$BUTTERKNIFE_VERSION"
compile 'com.jakewharton.timber:timber:4.5.1'
compile ('com.mapbox.mapboxsdk:mapbox-android-sdk:5.0.2@aar'){
transitive=true
}
testCompile 'junit:junit:4.12'
androidTestCompile "com.android.support:support-annotations:${project.supportLibVersion}"

View file

@ -2,7 +2,6 @@ package fr.free.nrw.commons.nearby;
import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
@ -12,6 +11,7 @@ import fr.free.nrw.commons.location.LocationServiceManager;
import fr.free.nrw.commons.theme.BaseActivity;
public class NearbyActivity extends BaseActivity {
private boolean isMapViewActive = false;
private LocationServiceManager locationManager;
@ -47,22 +47,33 @@ public class NearbyActivity extends BaseActivity {
refreshView();
return true;
case R.id.action_map:
Log.d("Nearby","map is clicked");
showMapView();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
private void showMapView() {
isMapViewActive = true;
getSupportFragmentManager().beginTransaction()
.replace(R.id.container, new NearbyMapFragment()).commit();
}
@Override
protected void onResume() {
super.onResume();
}
protected void refreshView() {
if (isMapViewActive) {
getSupportFragmentManager().beginTransaction()
.replace(R.id.container, new NearbyMapFragment()).commit();
} else {
getSupportFragmentManager().beginTransaction()
.replace(R.id.container, new NearbyListFragment()).commit();
}
}
public LocationServiceManager getLocationManager() {
return locationManager;

View file

@ -0,0 +1,83 @@
package fr.free.nrw.commons.nearby;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.mapbox.mapboxsdk.Mapbox;
import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.services.android.telemetry.MapboxTelemetry;
import butterknife.BindView;
import butterknife.ButterKnife;
import fr.free.nrw.commons.R;
public class NearbyMapFragment extends android.support.v4.app.Fragment {
@BindView(R.id.mapview) MapView mapView;
public NearbyMapFragment() {
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Mapbox.getInstance(getActivity(),
getString(R.string.mapbox_commons_app_token));
MapboxTelemetry.getInstance().setTelemetryEnabled(false);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_nearby_map, container, false);
ButterKnife.bind(this, view);
mapView.onCreate(savedInstanceState);
setHasOptionsMenu(false);
mapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(MapboxMap mapboxMap) {
}
});
return view;
}
@Override
public void onStart() {
mapView.onStart();
super.onStart();
}
@Override
public void onPause() {
mapView.onPause();
super.onPause();
}
@Override
public void onResume() {
mapView.onResume();
super.onResume();
}
@Override
public void onStop() {
mapView.onStop();
super.onStop();
}
@Override
public void onDestroyView() {
mapView.onDestroy();
super.onDestroyView();
}
}

View file

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:mapbox="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.mapbox.mapboxsdk.maps.MapView
android:id="@+id/mapview"
android:layout_width="match_parent"
android:layout_height="match_parent"
mapbox:mapbox_cameraZoom="11"
mapbox:mapbox_cameraTargetLat="50.0755"
mapbox:mapbox_cameraTargetLng="14.4378"
mapbox:mapbox_styleUrl="@string/style_mapbox_streets" />
</LinearLayout>

View file

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

View file

@ -1,4 +1,4 @@
gradleVersion = 2.3.0
gradleVersion = 2.2.0
supportLibVersion = 25.2.0
@ -13,3 +13,4 @@ android.useDeprecatedNdk=true
# Library dependencies
BUTTERKNIFE_VERSION=8.4.0