mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 04:43:54 +01:00
Add codes from mapbox demo repository to test support fragment, map works in a single layer fragment
This commit is contained in:
parent
dbd1ad2ff1
commit
5575d42df2
7 changed files with 114 additions and 14 deletions
|
|
@ -143,7 +143,7 @@
|
|||
android:label="@string/title_activity_nearby_test_activity" />
|
||||
|
||||
<activity
|
||||
android:name=".nearby.NearbyTestFragment"
|
||||
android:name=".nearby.NearbyTestFragmentActivity"
|
||||
android:label="@string/title_activity_nearby_test_fragment" />
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ import fr.free.nrw.commons.explore.SearchActivity;
|
|||
|
||||
import fr.free.nrw.commons.explore.categories.ExploreActivity;
|
||||
import fr.free.nrw.commons.nearby.NearbyTestActivity;
|
||||
import fr.free.nrw.commons.nearby.NearbyTestFragment;
|
||||
import fr.free.nrw.commons.nearby.NearbyTestFragmentActivity;
|
||||
import fr.free.nrw.commons.notification.NotificationActivity;
|
||||
import fr.free.nrw.commons.review.ReviewActivity;
|
||||
import fr.free.nrw.commons.settings.SettingsActivity;
|
||||
|
|
@ -74,5 +74,5 @@ public abstract class ActivityBuilderModule {
|
|||
abstract NearbyTestActivity bindNearbyTestActivity();
|
||||
|
||||
@ContributesAndroidInjector
|
||||
abstract NearbyTestFragment bindNearbyTestFragment();
|
||||
abstract NearbyTestFragmentActivity bindNearbyTestFragment();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ public class NearbyTestActivity extends AppCompatActivity {
|
|||
mapboxMap.setStyle(Style.MAPBOX_STREETS, new Style.OnStyleLoaded() {
|
||||
@Override
|
||||
public void onStyleLoaded(@NonNull Style style) {
|
||||
Log.d("NearbyTestActivity","onStyleLoaded");
|
||||
Log.d("NearbyTests","Map inside activity is ready, works");
|
||||
// Map is set up and the style has loaded. Now you can add data or make other map adjustments.
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,6 +0,0 @@
|
|||
package fr.free.nrw.commons.nearby;
|
||||
|
||||
import fr.free.nrw.commons.theme.NavigationBaseActivity;
|
||||
|
||||
public class NearbyTestFragment extends NavigationBaseActivity {
|
||||
}
|
||||
|
|
@ -0,0 +1,71 @@
|
|||
package fr.free.nrw.commons.nearby;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
|
||||
import com.mapbox.mapboxsdk.Mapbox;
|
||||
import com.mapbox.mapboxsdk.camera.CameraPosition;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMapOptions;
|
||||
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.maps.SupportMapFragment;
|
||||
|
||||
import fr.free.nrw.commons.R;
|
||||
import fr.free.nrw.commons.theme.NavigationBaseActivity;
|
||||
|
||||
public class NearbyTestFragmentActivity extends NavigationBaseActivity {
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_nearby_test_fragment);
|
||||
|
||||
// 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));
|
||||
|
||||
// Create supportMapFragment
|
||||
SupportMapFragment mapFragment;
|
||||
if (savedInstanceState == null) {
|
||||
|
||||
// Create fragment
|
||||
final FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
|
||||
|
||||
// Build mapboxMap
|
||||
MapboxMapOptions options = MapboxMapOptions.createFromAttributes(this, null);
|
||||
options.camera(new CameraPosition.Builder()
|
||||
.target(new LatLng(-52.6885, -70.1395))
|
||||
.zoom(9)
|
||||
.build());
|
||||
|
||||
// Create map fragment
|
||||
mapFragment = SupportMapFragment.newInstance(options);
|
||||
|
||||
// Add map fragment to parent container
|
||||
transaction.add(R.id.container, mapFragment, "com.mapbox.map");
|
||||
transaction.commit();
|
||||
} else {
|
||||
mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentByTag("com.mapbox.map");
|
||||
}
|
||||
|
||||
mapFragment.getMapAsync(new OnMapReadyCallback() {
|
||||
@Override
|
||||
public void onMapReady(@NonNull MapboxMap mapboxMap) {
|
||||
|
||||
mapboxMap.setStyle(Style.SATELLITE, new Style.OnStyleLoaded() {
|
||||
@Override
|
||||
public void onStyleLoaded(@NonNull Style style) {
|
||||
Log.d("NearbyTests","Map inside support fragment is ready, works");
|
||||
// Map is set up and the style has loaded. Now you can add data or make other map adjustments
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -18,7 +18,6 @@ import androidx.appcompat.widget.Toolbar;
|
|||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
|
@ -40,8 +39,7 @@ import fr.free.nrw.commons.explore.categories.ExploreActivity;
|
|||
import fr.free.nrw.commons.kvstore.JsonKvStore;
|
||||
import fr.free.nrw.commons.logging.CommonsLogSender;
|
||||
import fr.free.nrw.commons.nearby.NearbyTestActivity;
|
||||
import fr.free.nrw.commons.nearby.NearbyTestFragment;
|
||||
import fr.free.nrw.commons.notification.NotificationActivity;
|
||||
import fr.free.nrw.commons.nearby.NearbyTestFragmentActivity;
|
||||
import fr.free.nrw.commons.review.ReviewActivity;
|
||||
import fr.free.nrw.commons.settings.SettingsActivity;
|
||||
import timber.log.Timber;
|
||||
|
|
@ -187,7 +185,7 @@ public abstract class NavigationBaseActivity extends BaseActivity
|
|||
return true;
|
||||
case R.id.action_nearby_test_fragment:
|
||||
drawerLayout.closeDrawer(navigationView);
|
||||
startActivityWithFlags(this, NearbyTestFragment.class, Intent.FLAG_ACTIVITY_REORDER_TO_FRONT,
|
||||
startActivityWithFlags(this, NearbyTestFragmentActivity.class, Intent.FLAG_ACTIVITY_REORDER_TO_FRONT,
|
||||
Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
||||
return true;
|
||||
case R.id.action_feedback:
|
||||
|
|
|
|||
37
app/src/main/res/layout/activity_nearby_test_fragment.xml
Normal file
37
app/src/main/res/layout/activity_nearby_test_fragment.xml
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/fragment_below_textview"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:gravity="center_horizontal" />
|
||||
|
||||
<androidx.cardview.widget.CardView
|
||||
android:id="@+id/cardview"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_below="@id/fragment_below_textview"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:layout_marginLeft="8dp"
|
||||
android:layout_marginRight="8dp"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginTop="8dp"
|
||||
app:cardCornerRadius="2dp"
|
||||
app:cardElevation="@dimen/cardview_default_elevation">
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"/>
|
||||
</androidx.cardview.widget.CardView>
|
||||
|
||||
|
||||
</RelativeLayout>
|
||||
Loading…
Add table
Add a link
Reference in a new issue