diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/NearbyTestActivity.java b/app/src/main/java/fr/free/nrw/commons/nearby/NearbyTestActivity.java index 4d6d28e92..952347e75 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/NearbyTestActivity.java +++ b/app/src/main/java/fr/free/nrw/commons/nearby/NearbyTestActivity.java @@ -1,6 +1,96 @@ package fr.free.nrw.commons.nearby; -import fr.free.nrw.commons.theme.NavigationBaseActivity; +import android.os.Bundle; +import android.util.Log; -public class NearbyTestActivity extends NavigationBaseActivity { +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.mapboxsdk.maps.Style; + +import androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatActivity; + +import fr.free.nrw.commons.R; + + +/** + * The most basic example of adding a map to an activity. + */ +public class NearbyTestActivity extends AppCompatActivity { + + private MapView mapView; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + // Mapbox access token is configured here. This needs to be called either in your application + // object or in the same activity which contains the mapview. + Mapbox.getInstance(this, getString(R.string.mapbox_commons_app_token)); + + + // This contains the MapView in XML and needs to be called after the access token is configured. + setContentView(R.layout.activity_nearby_test); + + mapView = findViewById(R.id.mapView); + mapView.onCreate(savedInstanceState); + mapView.getMapAsync(new OnMapReadyCallback() { + @Override + public void onMapReady(@NonNull MapboxMap mapboxMap) { + mapboxMap.setStyle(Style.MAPBOX_STREETS, new Style.OnStyleLoaded() { + @Override + public void onStyleLoaded(@NonNull Style style) { + Log.d("NearbyTestActivity","onStyleLoaded"); + // Map is set up and the style has loaded. Now you can add data or make other map adjustments. + } + }); + } + }); + } + + // Add the mapView lifecycle to the activity's lifecycle methods + @Override + public void onResume() { + super.onResume(); + mapView.onResume(); + } + + @Override + protected void onStart() { + super.onStart(); + mapView.onStart(); + } + + @Override + protected void onStop() { + super.onStop(); + mapView.onStop(); + } + + @Override + public void onPause() { + super.onPause(); + mapView.onPause(); + } + + @Override + public void onLowMemory() { + super.onLowMemory(); + mapView.onLowMemory(); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + mapView.onDestroy(); + } + + @Override + protected void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + mapView.onSaveInstanceState(outState); + } } + diff --git a/app/src/main/res/layout/activity_nearby_test.xml b/app/src/main/res/layout/activity_nearby_test.xml new file mode 100644 index 000000000..5e5c82d1b --- /dev/null +++ b/app/src/main/res/layout/activity_nearby_test.xml @@ -0,0 +1,22 @@ + + + + + + \ No newline at end of file