Skip to content

Commit

Permalink
Added support for MapView in Nearby
Browse files Browse the repository at this point in the history
  • Loading branch information
maskara committed May 12, 2017
1 parent 784b51e commit 6118b57
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 5 deletions.
3 changes: 3 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
19 changes: 15 additions & 4 deletions app/src/main/java/fr/free/nrw/commons/nearby/NearbyActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

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;
Expand All @@ -12,6 +11,7 @@
import fr.free.nrw.commons.theme.BaseActivity;

public class NearbyActivity extends BaseActivity {
private boolean isMapViewActive = false;

private LocationServiceManager locationManager;

Expand Down Expand Up @@ -47,21 +47,32 @@ public boolean onOptionsItemSelected(MenuItem item) {
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() {
getSupportFragmentManager().beginTransaction()
.replace(R.id.container, new NearbyListFragment()).commit();
if (isMapViewActive) {
getSupportFragmentManager().beginTransaction()
.replace(R.id.container, new NearbyMapFragment()).commit();
} else {
getSupportFragmentManager().beginTransaction()
.replace(R.id.container, new NearbyListFragment()).commit();
}
}

public LocationServiceManager getLocationManager() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
}
16 changes: 16 additions & 0 deletions app/src/main/res/layout/fragment_nearby_map.xml
Original file line number Diff line number Diff line change
@@ -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>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
gradleVersion = 2.3.0
gradleVersion = 2.2.0

supportLibVersion = 25.2.0

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

# Library dependencies
BUTTERKNIFE_VERSION=8.4.0

0 comments on commit 6118b57

Please sign in to comment.