Search in sources :

Example 1 with KEY_MAPBOX_INITIALIZED

use of org.odk.collect.settings.keys.MetaKeys.KEY_MAPBOX_INITIALIZED in project collect by opendatakit.

the class MapBoxInitializationFragment method initMapBox.

private void initMapBox(View rootView) {
    Settings metaSharedPreferences = settingsProvider.getMetaSettings();
    if (!metaSharedPreferences.getBoolean(KEY_MAPBOX_INITIALIZED) && connectivityProvider.isDeviceOnline()) {
        // most likely to be available. This is annoyingly needed for offline tiles to work.
        try {
            mapView = new MapView(getContext());
            FrameLayout mapBoxContainer = rootView.findViewById(R.id.map_box_container);
            mapBoxContainer.addView(mapView);
            mapView.getMapAsync(mapBoxMap -> mapBoxMap.setStyle(Style.MAPBOX_STREETS, style -> {
                metaSharedPreferences.save(KEY_MAPBOX_INITIALIZED, true);
            }));
        } catch (Exception | Error ignored) {
        // This will crash on devices where the arch for MapBox is not included
        }
    }
}
Also used : Bundle(android.os.Bundle) SettingsProvider(org.odk.collect.settings.SettingsProvider) LayoutInflater(android.view.LayoutInflater) FrameLayout(android.widget.FrameLayout) MapView(com.mapbox.mapboxsdk.maps.MapView) ViewGroup(android.view.ViewGroup) Inject(javax.inject.Inject) KEY_MAPBOX_INITIALIZED(org.odk.collect.settings.keys.MetaKeys.KEY_MAPBOX_INITIALIZED) DaggerUtils(org.odk.collect.android.injection.DaggerUtils) Nullable(androidx.annotation.Nullable) NetworkStateProvider(org.odk.collect.android.network.NetworkStateProvider) Style(com.mapbox.mapboxsdk.maps.Style) Fragment(androidx.fragment.app.Fragment) R(org.odk.collect.android.R) View(android.view.View) Settings(org.odk.collect.shared.settings.Settings) FrameLayout(android.widget.FrameLayout) MapView(com.mapbox.mapboxsdk.maps.MapView) Settings(org.odk.collect.shared.settings.Settings)

Aggregations

Bundle (android.os.Bundle)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 FrameLayout (android.widget.FrameLayout)1 Nullable (androidx.annotation.Nullable)1 Fragment (androidx.fragment.app.Fragment)1 MapView (com.mapbox.mapboxsdk.maps.MapView)1 Style (com.mapbox.mapboxsdk.maps.Style)1 Inject (javax.inject.Inject)1 R (org.odk.collect.android.R)1 DaggerUtils (org.odk.collect.android.injection.DaggerUtils)1 NetworkStateProvider (org.odk.collect.android.network.NetworkStateProvider)1 SettingsProvider (org.odk.collect.settings.SettingsProvider)1 KEY_MAPBOX_INITIALIZED (org.odk.collect.settings.keys.MetaKeys.KEY_MAPBOX_INITIALIZED)1 Settings (org.odk.collect.shared.settings.Settings)1