Search in sources :

Example 1 with ScaleBarOptions

use of com.mapbox.pluginscalebar.ScaleBarOptions in project mapbox-plugins-android by mapbox.

the class ScaleBarTest method testScaleBarColor.

@Test
public void testScaleBarColor() {
    validateTestSetup();
    setupScaleBar();
    invoke(mapboxMap, (uiController, mapboxMap) -> {
        assertEquals(ContextCompat.getColor(activity, android.R.color.black), scaleBarWidget.getTextColor());
        assertEquals(ContextCompat.getColor(activity, android.R.color.black), scaleBarWidget.getPrimaryColor());
        assertEquals(ContextCompat.getColor(activity, android.R.color.white), scaleBarWidget.getSecondaryColor());
        int textColor = R.color.colorAccent;
        int colorPrimary = R.color.colorPrimary;
        int colorSecondary = R.color.colorPrimaryDark;
        ScaleBarOptions option = new ScaleBarOptions(activity);
        option.setTextColor(textColor);
        option.setPrimaryColor(colorPrimary);
        option.setSecondaryColor(colorSecondary);
        scaleBarWidget = scaleBarPlugin.create(option);
        assertNotNull(scaleBarWidget);
        assertEquals(ContextCompat.getColor(activity, textColor), scaleBarWidget.getTextColor());
        assertEquals(ContextCompat.getColor(activity, colorPrimary), scaleBarWidget.getPrimaryColor());
        assertEquals(ContextCompat.getColor(activity, colorSecondary), scaleBarWidget.getSecondaryColor());
    });
}
Also used : ScaleBarOptions(com.mapbox.pluginscalebar.ScaleBarOptions) Test(org.junit.Test) BaseActivityTest(com.mapbox.mapboxsdk.plugins.BaseActivityTest)

Example 2 with ScaleBarOptions

use of com.mapbox.pluginscalebar.ScaleBarOptions in project mapbox-plugins-android by mapbox.

the class ScaleBarTest method testRefreshInterval.

@Test
public void testRefreshInterval() {
    validateTestSetup();
    setupScaleBar();
    invoke(mapboxMap, (uiController, mapboxMap) -> {
        assertEquals(ScaleBarOptions.REFRESH_INTERVAL_DEFAULT, scaleBarWidget.getRefreshInterval(), 0);
        ScaleBarOptions option = new ScaleBarOptions(activity);
        option.setRefreshInterval(1000);
        scaleBarWidget = scaleBarPlugin.create(option);
        assertNotNull(scaleBarWidget);
        assertEquals(1000, scaleBarWidget.getRefreshInterval(), 0);
    });
}
Also used : ScaleBarOptions(com.mapbox.pluginscalebar.ScaleBarOptions) Test(org.junit.Test) BaseActivityTest(com.mapbox.mapboxsdk.plugins.BaseActivityTest)

Example 3 with ScaleBarOptions

use of com.mapbox.pluginscalebar.ScaleBarOptions in project mapbox-plugins-android by mapbox.

the class ScaleBarTest method testMetrics.

@Test
public void testMetrics() {
    validateTestSetup();
    setupScaleBar();
    invoke(mapboxMap, (uiController, mapboxMap) -> {
        assertEquals(ScaleBarOptions.LocaleUnitResolver.isMetricSystem(), scaleBarWidget.isMetricUnit());
        ScaleBarOptions option = new ScaleBarOptions(activity);
        option.setMetricUnit(true);
        scaleBarWidget = scaleBarPlugin.create(option);
        assertNotNull(scaleBarWidget);
        assertTrue(scaleBarWidget.isMetricUnit());
        option = new ScaleBarOptions(activity);
        option.setMetricUnit(false);
        scaleBarWidget = scaleBarPlugin.create(option);
        assertNotNull(scaleBarWidget);
        assertFalse(scaleBarWidget.isMetricUnit());
    });
}
Also used : ScaleBarOptions(com.mapbox.pluginscalebar.ScaleBarOptions) Test(org.junit.Test) BaseActivityTest(com.mapbox.mapboxsdk.plugins.BaseActivityTest)

Example 4 with ScaleBarOptions

use of com.mapbox.pluginscalebar.ScaleBarOptions in project mapbox-plugins-android by mapbox.

the class ScaleBarTest method testBorderWidth.

@Test
public void testBorderWidth() {
    validateTestSetup();
    setupScaleBar();
    invoke(mapboxMap, (uiController, mapboxMap) -> {
        assertEquals(activity.getResources().getDimension(R.dimen.mapbox_scale_bar_border_width), scaleBarWidget.getBorderWidth(), 0);
        ScaleBarOptions option = new ScaleBarOptions(activity);
        option.setBorderWidth(R.dimen.fab_margin);
        scaleBarWidget = scaleBarPlugin.create(option);
        assertNotNull(scaleBarWidget);
        assertEquals(activity.getResources().getDimension(R.dimen.fab_margin), scaleBarWidget.getBorderWidth(), 0);
        option = new ScaleBarOptions(activity);
        option.setBorderWidth(100f);
        scaleBarWidget = scaleBarPlugin.create(option);
        assertNotNull(scaleBarWidget);
        assertEquals(100f, scaleBarWidget.getBorderWidth(), 0);
    });
}
Also used : ScaleBarOptions(com.mapbox.pluginscalebar.ScaleBarOptions) Test(org.junit.Test) BaseActivityTest(com.mapbox.mapboxsdk.plugins.BaseActivityTest)

Example 5 with ScaleBarOptions

use of com.mapbox.pluginscalebar.ScaleBarOptions in project apps-android-commons by commons-app.

the class NearbyParentFragment method onViewCreated.

@Override
public void onViewCreated(@NonNull final View view, @Nullable final Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    isDarkTheme = systemThemeUtils.isDeviceInNightMode();
    if (Utils.isMonumentsEnabled(new Date())) {
        rlContainerWLMMonthMessage.setVisibility(View.VISIBLE);
    } else {
        rlContainerWLMMonthMessage.setVisibility(View.GONE);
    }
    cameraMoveListener = () -> presenter.onCameraMove(mapBox.getCameraPosition().target);
    addCheckBoxCallback();
    presenter.attachView(this);
    isPermissionDenied = false;
    recenterToUserLocation = false;
    initRvNearbyList();
    initThemePreferences();
    mapView.onCreate(savedInstanceState);
    mapView.getMapAsync(mapBoxMap -> {
        mapBox = mapBoxMap;
        initViews();
        presenter.setActionListeners(applicationKvStore);
        initNearbyFilter();
        mapBoxMap.setStyle(isDarkTheme ? Style.DARK : Style.OUTDOORS, style -> {
            final UiSettings uiSettings = mapBoxMap.getUiSettings();
            uiSettings.setCompassGravity(Gravity.BOTTOM | Gravity.LEFT);
            uiSettings.setCompassMargins(12, 0, 0, 24);
            uiSettings.setLogoEnabled(false);
            uiSettings.setAttributionEnabled(false);
            uiSettings.setRotateGesturesEnabled(false);
            isMapBoxReady = true;
            if (nearbyParentFragmentInstanceReadyCallback != null) {
                nearbyParentFragmentInstanceReadyCallback.onReady();
            }
            performMapReadyActions();
            final CameraPosition cameraPosition;
            if (applicationKvStore.getString("LastLocation") != null) {
                // Checking for last searched location
                String[] locationLatLng = applicationKvStore.getString("LastLocation").split(",");
                cameraPosition = new CameraPosition.Builder().target(new LatLng(Double.valueOf(locationLatLng[0]), Double.valueOf(locationLatLng[1]))).zoom(ZOOM_LEVEL).build();
            } else {
                cameraPosition = new CameraPosition.Builder().target(new LatLng(51.50550, -0.07520)).zoom(ZOOM_OUT).build();
            }
            mapBoxMap.setCameraPosition(cameraPosition);
            final ScaleBarPlugin scaleBarPlugin = new ScaleBarPlugin(mapView, mapBoxMap);
            final int color = isDarkTheme ? R.color.bottom_bar_light : R.color.bottom_bar_dark;
            final ScaleBarOptions scaleBarOptions = new ScaleBarOptions(getContext()).setTextColor(color).setTextSize(R.dimen.description_text_size).setBarHeight(R.dimen.tiny_gap).setBorderWidth(R.dimen.miniscule_margin).setMarginTop(R.dimen.tiny_padding).setMarginLeft(R.dimen.tiny_padding).setTextBarMargin(R.dimen.tiny_padding);
            scaleBarPlugin.create(scaleBarOptions);
            onResume();
        });
    });
    tvAttribution.setText(Html.fromHtml(getString(R.string.map_attribution)));
    tvAttribution.setMovementMethod(LinkMovementMethod.getInstance());
    btnAdvancedOptions.setOnClickListener(v -> {
        searchView.clearFocus();
        showHideAdvancedQueryFragment(true);
        final AdvanceQueryFragment fragment = new AdvanceQueryFragment();
        final Bundle bundle = new Bundle();
        try {
            bundle.putString("query", FileUtils.readFromResource("/queries/nearby_query.rq"));
        } catch (IOException e) {
            Timber.e(e);
        }
        fragment.setArguments(bundle);
        fragment.callback = new Callback() {

            @Override
            public void close() {
                showHideAdvancedQueryFragment(false);
            }

            @Override
            public void reset() {
                presenter.setAdvancedQuery(null);
                presenter.updateMapAndList(LOCATION_SIGNIFICANTLY_CHANGED);
                showHideAdvancedQueryFragment(false);
            }

            @Override
            public void apply(@NotNull final String query) {
                presenter.setAdvancedQuery(query);
                presenter.updateMapAndList(CUSTOM_QUERY);
                showHideAdvancedQueryFragment(false);
            }
        };
        getChildFragmentManager().beginTransaction().replace(R.id.fl_container_nearby_children, fragment).commit();
    });
}
Also used : UiSettings(com.mapbox.mapboxsdk.maps.UiSettings) Bundle(android.os.Bundle) ScaleBarOptions(com.mapbox.pluginscalebar.ScaleBarOptions) IOException(java.io.IOException) Date(java.util.Date) SuppressLint(android.annotation.SuppressLint) CameraPosition(com.mapbox.mapboxsdk.camera.CameraPosition) Callback(fr.free.nrw.commons.nearby.fragments.AdvanceQueryFragment.Callback) LatLng(com.mapbox.mapboxsdk.geometry.LatLng) ScaleBarPlugin(com.mapbox.pluginscalebar.ScaleBarPlugin)

Aggregations

ScaleBarOptions (com.mapbox.pluginscalebar.ScaleBarOptions)11 BaseActivityTest (com.mapbox.mapboxsdk.plugins.BaseActivityTest)9 Test (org.junit.Test)9 ScaleBarPlugin (com.mapbox.pluginscalebar.ScaleBarPlugin)2 SuppressLint (android.annotation.SuppressLint)1 Bundle (android.os.Bundle)1 CameraPosition (com.mapbox.mapboxsdk.camera.CameraPosition)1 LatLng (com.mapbox.mapboxsdk.geometry.LatLng)1 UiSettings (com.mapbox.mapboxsdk.maps.UiSettings)1 Callback (fr.free.nrw.commons.nearby.fragments.AdvanceQueryFragment.Callback)1 IOException (java.io.IOException)1 Date (java.util.Date)1