[android] #4754 - double map view example
This commit is contained in:
@@ -210,6 +210,14 @@
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_imagegenerator" />
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.maplayout.DoubleMapActivity"
|
||||
android:description="@string/description_doublemap"
|
||||
android:label="@string/activity_double_map">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_maplayout" />
|
||||
</activity>
|
||||
|
||||
<!-- Configuration Settings -->
|
||||
<meta-data
|
||||
|
||||
@@ -46,7 +46,7 @@ public class FeatureOverviewActivity extends AppCompatActivity {
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
ActionBar actionBar = getSupportActionBar();
|
||||
if(actionBar!=null){
|
||||
if (actionBar != null) {
|
||||
actionBar.setElevation(getResources().getDimension(R.dimen.toolbar_shadow));
|
||||
}
|
||||
|
||||
@@ -115,9 +115,10 @@ public class FeatureOverviewActivity extends AppCompatActivity {
|
||||
List<Feature> features = new ArrayList<>();
|
||||
PackageInfo app = params[0];
|
||||
|
||||
String packageName = getApplicationContext().getPackageName();
|
||||
String metaDataKey = getString(R.string.category);
|
||||
for (ActivityInfo info : app.activities) {
|
||||
if (!info.name.equals(FeatureOverviewActivity.class.getName())) {
|
||||
if (info.name.startsWith(packageName) && !info.name.equals(FeatureOverviewActivity.class.getName())) {
|
||||
String label = getString(info.labelRes);
|
||||
String description = getString(info.descriptionRes);
|
||||
String category = resolveMetaData(info.metaData, metaDataKey);
|
||||
|
||||
@@ -0,0 +1,158 @@
|
||||
package com.mapbox.mapboxsdk.testapp.activity.maplayout;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.app.Fragment;
|
||||
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.LayoutInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
|
||||
import com.mapbox.mapboxsdk.constants.MyLocationTracking;
|
||||
import com.mapbox.mapboxsdk.constants.Style;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
|
||||
import com.mapbox.mapboxsdk.maps.TrackingSettings;
|
||||
import com.mapbox.mapboxsdk.maps.UiSettings;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
|
||||
public class DoubleMapActivity extends AppCompatActivity {
|
||||
|
||||
private static final String TAG_FRAGMENT = "map";
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
Fragment mapFragment;
|
||||
if (savedInstanceState == null) {
|
||||
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
|
||||
transaction.add(R.id.fragment_container, mapFragment = new DoubleMapFragment(), TAG_FRAGMENT);
|
||||
transaction.commit();
|
||||
} else {
|
||||
mapFragment = (DoubleMapFragment) getSupportFragmentManager().findFragmentByTag(TAG_FRAGMENT);
|
||||
}
|
||||
}
|
||||
|
||||
public static class DoubleMapFragment extends Fragment {
|
||||
|
||||
private MapView mMapView;
|
||||
private MapView mMapViewMini;
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
return inflater.inflate(R.layout.fragment_double_map, container, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
// MapView large
|
||||
mMapView = (MapView) view.findViewById(R.id.mapView);
|
||||
mMapView.onCreate(savedInstanceState);
|
||||
mMapView.getMapAsync(new OnMapReadyCallback() {
|
||||
@Override
|
||||
public void onMapReady(@NonNull MapboxMap mapboxMap) {
|
||||
mapboxMap.setStyle(Style.DARK);
|
||||
|
||||
mapboxMap.moveCamera(CameraUpdateFactory.zoomTo(18));
|
||||
try {
|
||||
TrackingSettings settings = mapboxMap.getTrackingSettings();
|
||||
settings.setMyLocationTrackingMode(MyLocationTracking.TRACKING_FOLLOW);
|
||||
} catch (SecurityException e) {
|
||||
// permission is handled in MainActivity
|
||||
getActivity().finish();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// MapView mini
|
||||
mMapViewMini = (MapView) view.findViewById(R.id.mini_map);
|
||||
mMapViewMini.onCreate(savedInstanceState);
|
||||
mMapViewMini.getMapAsync(new OnMapReadyCallback() {
|
||||
@Override
|
||||
public void onMapReady(@NonNull MapboxMap mapboxMap) {
|
||||
mapboxMap.setStyle(Style.LIGHT);
|
||||
mapboxMap.moveCamera(CameraUpdateFactory.zoomTo(4));
|
||||
|
||||
UiSettings uiSettings = mapboxMap.getUiSettings();
|
||||
uiSettings.setAllGesturesEnabled(false);
|
||||
uiSettings.setCompassEnabled(false);
|
||||
uiSettings.setAttributionEnabled(false);
|
||||
uiSettings.setLogoEnabled(false);
|
||||
|
||||
try {
|
||||
TrackingSettings settings = mapboxMap.getTrackingSettings();
|
||||
settings.setMyLocationTrackingMode(MyLocationTracking.TRACKING_FOLLOW);
|
||||
} catch (SecurityException e) {
|
||||
// permission is handled in MainActivity
|
||||
getActivity().finish();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
mMapView.onResume();
|
||||
mMapViewMini.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
mMapView.onPause();
|
||||
mMapViewMini.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
mMapView.onDestroy();
|
||||
mMapViewMini.onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLowMemory() {
|
||||
super.onLowMemory();
|
||||
mMapView.onLowMemory();
|
||||
mMapViewMini.onLowMemory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
mMapView.onSaveInstanceState(outState);
|
||||
mMapViewMini.onSaveInstanceState(outState);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
onBackPressed();
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -33,6 +33,7 @@
|
||||
<string name="activity_geocoder">Geocoder</string>
|
||||
|
||||
<!-- Other -->
|
||||
<string name="activity_double_map">Double Map Activity</string>
|
||||
<string name="activity_snapshot">Snapshot Activity</string>
|
||||
<string name="activity_user_tracking_mode">User tracking mode</string>
|
||||
<string name="activity_custom_layer">Custom Layer</string>
|
||||
@@ -67,6 +68,7 @@
|
||||
<string name="description_geocoder">Example with Geocoder API</string>
|
||||
<string name="description_scroll_by">Scroll with pixels in x,y direction</string>
|
||||
<string name="description_snapshot">Example to make a snapshot of the map</string>
|
||||
<string name="description_doublemap">2 maps in a view hierarchy</string>
|
||||
|
||||
<string name="menuitem_title_concurrent_infowindow">Concurrent Open InfoWindows</string>r
|
||||
<string name="menuitem_title_tracking_mode_dismiss_on_gesture">Dismiss on Gesture</string>r
|
||||
|
||||
Reference in New Issue
Block a user