Search in sources :

Example 1 with DayNightMode

use of net.osmand.plus.settings.enums.DayNightMode in project Osmand by osmandapp.

the class DayNightHelper method isNightModeForProfile.

public boolean isNightModeForProfile(ApplicationMode mode) {
    DayNightMode dayNightMode = app.getSettings().DAYNIGHT_MODE.getModeValue(mode);
    NavigationSession carNavigationSession = app.getCarNavigationSession();
    if (carNavigationSession != null && carNavigationSession.isStateAtLeast(State.CREATED)) {
        boolean carDarkMode = carNavigationSession.getCarContext().isDarkMode();
        dayNightMode = carDarkMode ? DayNightMode.NIGHT : DayNightMode.DAY;
    }
    if (dayNightMode.isDay()) {
        return false;
    } else if (dayNightMode.isNight()) {
        return true;
    } else if (dayNightMode.isAuto()) {
        // We are in auto mode!
        long currentTime = System.currentTimeMillis();
        // allow recalculation each 60 seconds
        if (currentTime - lastTime > 60000) {
            lastTime = System.currentTimeMillis();
            try {
                SunriseSunset daynightSwitch = getSunriseSunset();
                if (daynightSwitch != null) {
                    boolean daytime = daynightSwitch.isDaytime();
                    // $NON-NLS-1$
                    log.debug("Sunrise/sunset setting to day: " + daytime);
                    lastNightMode = !daytime;
                }
            } catch (IllegalArgumentException e) {
                // $NON-NLS-1$
                log.warn("Network location provider not available");
            } catch (SecurityException e) {
                // $NON-NLS-1$
                log.warn("Missing permissions to get actual location!");
            }
        }
        return lastNightMode;
    } else if (dayNightMode.isSensor()) {
        return lastNightMode;
    }
    return false;
}
Also used : SunriseSunset(net.osmand.util.SunriseSunset) DayNightMode(net.osmand.plus.settings.enums.DayNightMode) NavigationSession(net.osmand.plus.auto.NavigationSession)

Example 2 with DayNightMode

use of net.osmand.plus.settings.enums.DayNightMode in project Osmand by osmandapp.

the class DayNightHelper method startSensorIfNeeded.

public void startSensorIfNeeded(StateChangedListener<Boolean> sensorStateListener) {
    this.sensorStateListener = sensorStateListener;
    DayNightMode dayNightMode = app.getSettings().DAYNIGHT_MODE.get();
    if (listener == null && dayNightMode.isSensor()) {
        SensorManager mSensorManager = (SensorManager) app.getSystemService(Context.SENSOR_SERVICE);
        Sensor mLight = mSensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);
        List<Sensor> list = mSensorManager.getSensorList(Sensor.TYPE_LIGHT);
        // $NON-NLS-1$
        log.info("Light sensors:" + list.size());
        mSensorManager.registerListener(this, mLight, SensorManager.SENSOR_DELAY_NORMAL);
        listener = this;
    } else if (listener != null && !dayNightMode.isSensor()) {
        stopSensorIfNeeded();
    }
}
Also used : SensorManager(android.hardware.SensorManager) DayNightMode(net.osmand.plus.settings.enums.DayNightMode) Sensor(android.hardware.Sensor)

Example 3 with DayNightMode

use of net.osmand.plus.settings.enums.DayNightMode in project Osmand by osmandapp.

the class ConfigureMapMenu method createRenderingAttributeItems.

private void createRenderingAttributeItems(List<RenderingRuleProperty> customRules, final ContextMenuAdapter adapter, final MapActivity activity, final boolean nightMode) {
    final OsmandApplication app = activity.getMyApplication();
    final OsmandSettings settings = app.getSettings();
    final int selectedProfileColor = settings.APPLICATION_MODE.get().getProfileColor(nightMode);
    final int themeRes = getThemeRes(nightMode);
    adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.map_widget_map_rendering, activity).setId(MAP_RENDERING_CATEGORY_ID).setCategory(true).setLayout(R.layout.list_group_title_with_switch).createItem());
    adapter.addItem(new ContextMenuItem.ItemBuilder().setId(MAP_STYLE_ID).setTitleId(R.string.map_widget_renderer, activity).setLayout(R.layout.list_item_single_line_descrition_narrow).setIcon(R.drawable.ic_map).setListener(new ContextMenuAdapter.ItemClickListener() {

        @Override
        public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> ad, int itemId, final int pos, boolean isChecked, int[] viewCoordinates) {
            SelectMapStyleBottomSheetDialogFragment.showInstance(activity.getSupportFragmentManager());
            return false;
        }
    }).setItemDeleteAction(makeDeleteAction(settings.RENDERER)).setOnUpdateCallback(new ContextMenuItem.OnUpdateCallback() {

        @Override
        public void onUpdateMenuItem(ContextMenuItem item) {
            String renderDescr = ConfigureMapUtils.getRenderDescr(app);
            item.setDescription(renderDescr);
        }
    }).createItem());
    String description = "";
    SunriseSunset sunriseSunset = activity.getMyApplication().getDaynightHelper().getSunriseSunset();
    if (sunriseSunset != null && sunriseSunset.getSunrise() != null && sunriseSunset.getSunset() != null) {
        DateFormat dateFormat = DateFormat.getTimeInstance(DateFormat.SHORT);
        String sunriseTime = dateFormat.format(sunriseSunset.getSunrise());
        String sunsetTime = dateFormat.format(sunriseSunset.getSunset());
        DayNightMode dayNightMode = activity.getMyApplication().getSettings().DAYNIGHT_MODE.get();
        if (dayNightMode.isDay() || dayNightMode.isNight()) {
            if (sunriseSunset.isDaytime()) {
                description = String.format(app.getString(R.string.sunset_at), sunsetTime);
            } else {
                description = String.format(app.getString(R.string.sunrise_at), sunriseTime);
            }
        } else if (dayNightMode.isAuto() || dayNightMode.isSensor()) {
            description = String.format(app.getString(R.string.ltr_or_rtl_combine_via_slash), sunriseTime, sunsetTime);
        }
        description = String.format(app.getString(R.string.ltr_or_rtl_combine_via_bold_point), ConfigureMapUtils.getDayNightDescr(activity), description);
    } else {
        description = ConfigureMapUtils.getDayNightDescr(activity);
    }
    adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.map_mode, activity).setId(MAP_MODE_ID).setDescription(description).setIcon(ConfigureMapUtils.getDayNightIcon(activity)).setListener((ad, itemId, pos, isChecked, viewCoordinates) -> {
        if (AndroidUtils.isActivityNotDestroyed(activity)) {
            ConfigureMapDialogs.showMapModeDialog(activity, themeRes, nightMode);
        }
        return false;
    }).setItemDeleteAction(makeDeleteAction(settings.DAYNIGHT_MODE)).createItem());
    adapter.addItem(new ContextMenuItem.ItemBuilder().setId(MAP_MAGNIFIER_ID).setTitleId(R.string.map_magnifier, activity).setDescription(String.format(Locale.UK, "%.0f", 100f * activity.getMyApplication().getSettings().MAP_DENSITY.get()) + " %").setLayout(R.layout.list_item_single_line_descrition_narrow).setIcon(R.drawable.ic_action_map_magnifier).setListener((ad, itemId, pos, isChecked, viewCoordinates) -> {
        if (AndroidUtils.isActivityNotDestroyed(activity)) {
            ConfigureMapDialogs.showMapMagnifierDialog(activity, adapter, themeRes, nightMode, pos, ad);
        }
        return false;
    }).setItemDeleteAction(makeDeleteAction(settings.MAP_DENSITY)).createItem());
    ContextMenuItem props = createRenderingProperty(customRules, adapter, activity, R.drawable.ic_action_intersection, ROAD_STYLE_ATTR, ROAD_STYLE_ID, nightMode);
    if (props != null) {
        adapter.addItem(props);
    }
    adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.text_size, activity).setId(TEXT_SIZE_ID).setDescription(ConfigureMapUtils.getScale(activity)).setLayout(R.layout.list_item_single_line_descrition_narrow).setIcon(R.drawable.ic_action_map_text_size).setListener((ad, itemId, pos, isChecked, viewCoordinates) -> {
        if (AndroidUtils.isActivityNotDestroyed(activity)) {
            ConfigureMapDialogs.showTextSizeDialog(activity, adapter, themeRes, nightMode, pos, ad);
        }
        return false;
    }).setItemDeleteAction(makeDeleteAction(settings.TEXT_SCALE)).createItem());
    String localeDescr = activity.getMyApplication().getSettings().MAP_PREFERRED_LOCALE.get();
    localeDescr = localeDescr == null || localeDescr.isEmpty() ? activity.getString(R.string.local_map_names) : localeDescr;
    adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.map_locale, activity).setId(MAP_LANGUAGE_ID).setDescription(localeDescr).setLayout(R.layout.list_item_single_line_descrition_narrow).setIcon(R.drawable.ic_action_map_language).setListener((ad, itemId, pos, isChecked, viewCoordinates) -> {
        if (AndroidUtils.isActivityNotDestroyed(activity)) {
            ConfigureMapDialogs.showMapLanguageDialog(activity, adapter, themeRes, nightMode, pos, ad);
        }
        return false;
    }).setItemDeleteAction(makeDeleteAction(settings.MAP_PREFERRED_LOCALE)).createItem());
    props = createProperties(customRules, R.string.rendering_category_details, R.drawable.ic_action_layers, UI_CATEGORY_DETAILS, adapter, activity, true, DETAILS_ID, nightMode, selectedProfileColor);
    if (props != null) {
        adapter.addItem(props);
    }
    props = createProperties(customRules, R.string.rendering_category_hide, R.drawable.ic_action_hide, UI_CATEGORY_HIDE, adapter, activity, true, HIDE_ID, nightMode, selectedProfileColor);
    if (props != null) {
        adapter.addItem(props);
    }
    props = createProperties(customRules, R.string.rendering_category_routes, R.drawable.ic_action_map_routes, UI_CATEGORY_ROUTES, adapter, activity, true, CUSTOM_RENDERING_ITEMS_ID_SCHEME + UI_CATEGORY_ROUTES, nightMode, selectedProfileColor);
    if (props != null) {
        adapter.addItem(props);
    }
    if (getCustomRenderingPropertiesSize(customRules) > 0) {
        adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.rendering_category_others, activity).setCategory(true).setLayout(R.layout.list_group_title_with_switch).createItem());
        createCustomRenderingProperties(adapter, activity, customRules, nightMode);
    }
}
Also used : PoiUIFilter(net.osmand.plus.poi.PoiUIFilter) Arrays(java.util.Arrays) A_ENGINE_V1(net.osmand.render.RenderingRuleStorageProperties.A_ENGINE_V1) NonNull(androidx.annotation.NonNull) HIDE_ID(net.osmand.aidlapi.OsmAndCustomizationConstants.HIDE_ID) ItemClickListener(net.osmand.plus.ContextMenuAdapter.ItemClickListener) APP_PROFILES_ID(net.osmand.aidlapi.OsmAndCustomizationConstants.APP_PROFILES_ID) R(net.osmand.plus.R) FAVORITES_ID(net.osmand.aidlapi.OsmAndCustomizationConstants.FAVORITES_ID) INVALID_ID(net.osmand.plus.ContextMenuItem.INVALID_ID) DrawableRes(androidx.annotation.DrawableRes) RenderingRulesStorage(net.osmand.render.RenderingRulesStorage) MAP_RENDERING_CATEGORY_ID(net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_RENDERING_CATEGORY_ID) CUSTOM_RENDERING_ITEMS_ID_SCHEME(net.osmand.aidlapi.OsmAndCustomizationConstants.CUSTOM_RENDERING_ITEMS_ID_SCHEME) POI_OVERLAY_ID(net.osmand.aidlapi.OsmAndCustomizationConstants.POI_OVERLAY_ID) ColorInt(androidx.annotation.ColorInt) ContextMenuAdapter.makeDeleteAction(net.osmand.plus.ContextMenuAdapter.makeDeleteAction) UiUtilities(net.osmand.plus.utils.UiUtilities) CallbackWithObject(net.osmand.CallbackWithObject) IndexConstants(net.osmand.IndexConstants) Locale(java.util.Locale) Map(java.util.Map) MAP_LANGUAGE_ID(net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_LANGUAGE_ID) View(android.view.View) TRANSPORT_ID(net.osmand.aidlapi.OsmAndCustomizationConstants.TRANSPORT_ID) RENDERING_CATEGORY_OSM_ASSISTANT(net.osmand.plus.plugins.osmedit.OsmEditingPlugin.RENDERING_CATEGORY_OSM_ASSISTANT) DateFormat(java.text.DateFormat) TEXT_SIZE_ID(net.osmand.aidlapi.OsmAndCustomizationConstants.TEXT_SIZE_ID) OsmandSettings(net.osmand.plus.settings.backend.OsmandSettings) OnRowItemClick(net.osmand.plus.ContextMenuAdapter.OnRowItemClick) OsmandApplication(net.osmand.plus.OsmandApplication) StyleRes(androidx.annotation.StyleRes) OsmandPlugin(net.osmand.plus.plugins.OsmandPlugin) DETAILS_ID(net.osmand.aidlapi.OsmAndCustomizationConstants.DETAILS_ID) MAP_SOURCE_ID(net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_SOURCE_ID) StringRes(androidx.annotation.StringRes) List(java.util.List) Nullable(androidx.annotation.Nullable) A_APP_MODE(net.osmand.render.RenderingRuleStorageProperties.A_APP_MODE) DashboardType(net.osmand.plus.dashboard.DashboardOnMap.DashboardType) GPX_FILES_ID(net.osmand.aidlapi.OsmAndCustomizationConstants.GPX_FILES_ID) CONTOUR_DENSITY_ATTR(net.osmand.plus.plugins.srtm.SRTMPlugin.CONTOUR_DENSITY_ATTR) ContextMenuAdapter(net.osmand.plus.ContextMenuAdapter) RENDERING_CATEGORY_TRANSPORT(net.osmand.plus.transport.TransportLinesMenu.RENDERING_CATEGORY_TRANSPORT) Snackbar(com.google.android.material.snackbar.Snackbar) ResourceManager(net.osmand.plus.resources.ResourceManager) MAP_MAGNIFIER_ID(net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_MAGNIFIER_ID) SunriseSunset(net.osmand.util.SunriseSunset) RendererRegistry(net.osmand.plus.render.RendererRegistry) SHOW_CATEGORY_ID(net.osmand.aidlapi.OsmAndCustomizationConstants.SHOW_CATEGORY_ID) CommonPreference(net.osmand.plus.settings.backend.preferences.CommonPreference) ROAD_STYLE_ID(net.osmand.aidlapi.OsmAndCustomizationConstants.ROAD_STYLE_ID) POI_OVERLAY_LABELS_ID(net.osmand.aidlapi.OsmAndCustomizationConstants.POI_OVERLAY_LABELS_ID) ArrayList(java.util.ArrayList) MAP_MARKERS_ID(net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_MARKERS_ID) RenderingRuleProperty(net.osmand.render.RenderingRuleProperty) LinkedHashMap(java.util.LinkedHashMap) CONTOUR_WIDTH_ATTR(net.osmand.plus.plugins.srtm.SRTMPlugin.CONTOUR_WIDTH_ATTR) A_BASE_APP_MODE(net.osmand.render.RenderingRuleStorageProperties.A_BASE_APP_MODE) PlatformUtil(net.osmand.PlatformUtil) Algorithms(net.osmand.util.Algorithms) TransportLinesMenu(net.osmand.plus.transport.TransportLinesMenu) UI_CATEGORY_HIDE(net.osmand.render.RenderingRuleStorageProperties.UI_CATEGORY_HIDE) UI_CATEGORY_ROUTES(net.osmand.render.RenderingRuleStorageProperties.UI_CATEGORY_ROUTES) AndroidUtils(net.osmand.plus.utils.AndroidUtils) Iterator(java.util.Iterator) MAP_MODE_ID(net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_MODE_ID) ItemBuilder(net.osmand.plus.ContextMenuItem.ItemBuilder) DayNightMode(net.osmand.plus.settings.enums.DayNightMode) CONTOUR_LINES_SCHEME_ATTR(net.osmand.plus.plugins.srtm.SRTMPlugin.CONTOUR_LINES_SCHEME_ATTR) MAP_STYLE_ID(net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_STYLE_ID) ROUTES_ID(net.osmand.aidlapi.OsmAndCustomizationConstants.ROUTES_ID) UI_CATEGORY_HIDDEN(net.osmand.render.RenderingRuleStorageProperties.UI_CATEGORY_HIDDEN) ArrayAdapter(android.widget.ArrayAdapter) ContextMenuItem(net.osmand.plus.ContextMenuItem) UI_CATEGORY_DETAILS(net.osmand.render.RenderingRuleStorageProperties.UI_CATEGORY_DETAILS) Log(org.apache.commons.logging.Log) CONTOUR_LINES_ATTR(net.osmand.plus.plugins.srtm.SRTMPlugin.CONTOUR_LINES_ATTR) MapActivity(net.osmand.plus.activities.MapActivity) OsmandApplication(net.osmand.plus.OsmandApplication) ContextMenuItem(net.osmand.plus.ContextMenuItem) ItemClickListener(net.osmand.plus.ContextMenuAdapter.ItemClickListener) OsmandSettings(net.osmand.plus.settings.backend.OsmandSettings) ItemBuilder(net.osmand.plus.ContextMenuItem.ItemBuilder) ContextMenuAdapter(net.osmand.plus.ContextMenuAdapter) SunriseSunset(net.osmand.util.SunriseSunset) DateFormat(java.text.DateFormat) DayNightMode(net.osmand.plus.settings.enums.DayNightMode) ItemBuilder(net.osmand.plus.ContextMenuItem.ItemBuilder)

Aggregations

DayNightMode (net.osmand.plus.settings.enums.DayNightMode)2 Sensor (android.hardware.Sensor)1 SensorManager (android.hardware.SensorManager)1 View (android.view.View)1 ArrayAdapter (android.widget.ArrayAdapter)1 ColorInt (androidx.annotation.ColorInt)1 DrawableRes (androidx.annotation.DrawableRes)1 NonNull (androidx.annotation.NonNull)1 Nullable (androidx.annotation.Nullable)1 StringRes (androidx.annotation.StringRes)1 StyleRes (androidx.annotation.StyleRes)1 Snackbar (com.google.android.material.snackbar.Snackbar)1 DateFormat (java.text.DateFormat)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Iterator (java.util.Iterator)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Locale (java.util.Locale)1 Map (java.util.Map)1