mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-28 05:13:53 +01:00
Added support for MapView in Nearby
This commit is contained in:
parent
784b51e29d
commit
6118b57295
6 changed files with 120 additions and 5 deletions
|
|
@ -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,21 +47,32 @@ 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() {
|
||||
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() {
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue