[android] #3759 - Add SupportMapFragment, test app integration, cleanup old fragment implementation

This commit is contained in:
Tobrun
2016-02-01 16:45:41 +01:00
parent 7694eebe88
commit a699690c16
9 changed files with 201 additions and 27 deletions

View File

@@ -50,6 +50,9 @@
<activity
android:name=".MapFragmentActivity"
android:label="@string/activity_map_fragment" />
<activity
android:name=".SupportMapFragmentActivity"
android:label="@string/activity_map_fragment_suport" />
<activity
android:name=".PressForMarkerActivity"
android:label="@string/activity_press_for_marker" />

View File

@@ -38,6 +38,7 @@ import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.layers.CustomLayer;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.maps.SupportMapFragment;
import com.mapbox.mapboxsdk.maps.UiSettings;
import com.mapbox.mapboxsdk.testapp.layers.ExampleCustomLayer;
import com.mapbox.mapboxsdk.testapp.utils.GeoParseUtil;
@@ -225,10 +226,6 @@ public class MainActivity extends AppCompatActivity {
});
}
/**
* Dispatch onStart() to all fragments. Ensure any created loaders are
* now started.
*/
@Override
protected void onStart() {
super.onStart();
@@ -373,6 +370,10 @@ public class MainActivity extends AppCompatActivity {
startActivity(new Intent(getApplicationContext(), MapFragmentActivity.class));
return true;
case R.id.action_support_map_fragment:
startActivity(new Intent(getApplicationContext(), SupportMapFragmentActivity.class));
return true;
case R.id.action_press_for_marker:
startActivity(new Intent(getApplicationContext(), PressForMarkerActivity.class));
return true;

View File

@@ -1,8 +1,8 @@
package com.mapbox.mapboxsdk.testapp;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
@@ -34,11 +34,11 @@ public class MapFragmentActivity extends AppCompatActivity {
MapFragment mapFragment;
if (savedInstanceState == null) {
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.add(R.id.fragment_container, mapFragment = new MapFragment(), "com.mapbox.map");
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.add(R.id.fragment_container, mapFragment = MapFragment.newInstance(), "com.mapbox.map");
transaction.commit();
} else {
mapFragment = (MapFragment) getSupportFragmentManager().findFragmentByTag("com.mapbox.map");
mapFragment = (MapFragment) getFragmentManager().findFragmentByTag("com.mapbox.map");
}
mapFragment.getMapAsync(new OnMapReadyCallback() {

View File

@@ -0,0 +1,69 @@
package com.mapbox.mapboxsdk.testapp;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.maps.SupportMapFragment;
public class SupportMapFragmentActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map_fragment);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowHomeEnabled(true);
}
SupportMapFragment mapFragment;
if (savedInstanceState == null) {
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.add(R.id.fragment_container, mapFragment = SupportMapFragment.newInstance(), "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.setStyleUrl(Style.SATELLITE_STREETS);
mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(
new CameraPosition.Builder()
.target(new LatLng(48.861431, 2.334166))
.zoom(10)
.bearing(0)
.tilt(0)
.build()));
}
});
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
onBackPressed();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}

View File

@@ -95,6 +95,12 @@
android:icon="@drawable/ic_now_widgets_24dp"
android:title="@string/action_map_fragment" />
<item
android:id="@+id/action_support_map_fragment"
android:checkable="false"
android:icon="@drawable/ic_now_widgets_24dp"
android:title="@string/action_map_fragment_support" />
<item
android:id="@+id/action_info_window"
android:checkable="false"

View File

@@ -7,6 +7,7 @@
<string name="activity_mapboxmap">MapboxMap</string>
<string name="activity_tilt">Map Tilt</string>
<string name="activity_infowindow_adapter">InfoWindow Adapter</string>
<string name="activity_map_fragment_suport">Support Map Fragment Activity</string>
<string name="activity_map_fragment">Map Fragment Activity</string>
<string name="activity_press_for_marker">Press For Marker Activity</string>
<string name="activity_marker_in_bulk">Add Bulk Markers Activity</string>
@@ -37,6 +38,7 @@
<string name="action_info_window_adapter">InfoWindow Adapter</string>
<string name="action_tilt">Tilt</string>
<string name="action_map_fragment">MapFragment</string>
<string name="action_map_fragment_support">SupportMapFragment</string>
<string name="action_press_for_marker">Press For Marker</string>
<string name="action_manual_zoom">Manual Zoom</string>
<string name="action_minmax_zoom">Min/Max Zoom</string>