Search in sources :

Example 1 with SunriseSunset

use of net.osmand.util.SunriseSunset in project Osmand by osmandapp.

the class SettingsDevelopmentActivity method onCreate.

@SuppressLint("SimpleDateFormat")
@Override
public void onCreate(Bundle savedInstanceState) {
    ((OsmandApplication) getApplication()).applyTheme(this);
    super.onCreate(savedInstanceState);
    getToolbar().setTitle(R.string.debugging_and_development);
    PreferenceScreen cat = getPreferenceScreen();
    CheckBoxPreference dbg = createCheckBoxPreference(settings.DEBUG_RENDERING_INFO, R.string.trace_rendering, R.string.trace_rendering_descr);
    cat.addPreference(dbg);
    cat.addPreference(createCheckBoxPreference(settings.DISABLE_COMPLEX_ROUTING, R.string.disable_complex_routing, R.string.disable_complex_routing_descr));
    cat.addPreference(createCheckBoxPreference(settings.USE_FAST_RECALCULATION, R.string.use_fast_recalculation, R.string.use_fast_recalculation_desc));
    final CheckBoxPreference openGlRender = createCheckBoxPreference(settings.USE_OPENGL_RENDER, R.string.use_opengl_render, R.string.use_opengl_render_descr);
    cat.addPreference(openGlRender);
    cat.addPreference(createCheckBoxPreference(settings.USE_OSM_LIVE_FOR_ROUTING, R.string.use_osm_live_routing, R.string.use_osm_live_routing_description));
    cat.addPreference(createCheckBoxPreference(settings.ANIMATE_MY_LOCATION, R.string.animate_my_location, R.string.animate_my_location_desc));
    final Preference firstRunPreference = new Preference(this);
    firstRunPreference.setTitle(R.string.simulate_initial_startup);
    firstRunPreference.setSummary(R.string.simulate_initial_startup_descr);
    firstRunPreference.setSelectable(true);
    firstRunPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            getMyApplication().getAppInitializer().resetFirstTimeRun();
            getMyApplication().getSettings().FIRST_MAP_IS_DOWNLOADED.set(false);
            getMyApplication().getSettings().MAPILLARY_FIRST_DIALOG_SHOWN.set(false);
            getMyApplication().getSettings().WEBGL_SUPPORTED.set(true);
            getMyApplication().getSettings().METRIC_SYSTEM_CHANGED_MANUALLY.set(false);
            getMyApplication().showToastMessage(R.string.shared_string_ok);
            return true;
        }
    });
    cat.addPreference(firstRunPreference);
    cat.addPreference(createCheckBoxPreference(settings.SHOULD_SHOW_FREE_VERSION_BANNER, R.string.show_free_version_banner, R.string.show_free_version_banner_description));
    cat.addPreference(createCheckBoxPreference(settings.NO_DISCOUNT_INFO, R.string.no_update_info, R.string.no_update_info_desc));
    cat.addPreference(createCheckBoxPreference(settings.SHOW_LEGACY_SEARCH, R.string.show_legacy_search, R.string.show_legacy_search_desc));
    // FIXME delete USE_MAP_MARKERS
    // cat.addPreference(createCheckBoxPreference(settings.USE_MAP_MARKERS,
    // R.string.map_markers,
    // R.string.show_map_markers_description));
    Preference pref = new Preference(this);
    final Preference simulate = pref;
    final OsmAndLocationSimulation sim = getMyApplication().getLocationProvider().getLocationSimulation();
    final Runnable updateTitle = new Runnable() {

        @Override
        public void run() {
            simulate.setSummary(sim.isRouteAnimating() ? R.string.simulate_your_location_stop_descr : R.string.simulate_your_location_descr);
        }
    };
    pref.setTitle(R.string.simulate_your_location);
    updateTitle.run();
    pref.setKey("simulate_your_location");
    pref.setOnPreferenceClickListener(new OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            updateTitle.run();
            sim.startStopRouteAnimation(SettingsDevelopmentActivity.this, updateTitle);
            return true;
        }
    });
    cat.addPreference(pref);
    pref = new Preference(this);
    pref.setTitle(R.string.test_voice_prompts);
    pref.setSummary(R.string.play_commands_of_currently_selected_voice);
    pref.setKey("test_voice_commands");
    pref.setOnPreferenceClickListener(new OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            startActivity(new Intent(SettingsDevelopmentActivity.this, TestVoiceActivity.class));
            return true;
        }
    });
    cat.addPreference(pref);
    pref = new Preference(this);
    pref.setTitle(R.string.app_modes_choose);
    pref.setSummary(R.string.app_modes_choose_descr);
    pref.setKey("available_application_modes");
    pref.setOnPreferenceClickListener(new OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            availableProfileDialog();
            return true;
        }
    });
    cat.addPreference(pref);
    PreferenceCategory info = new PreferenceCategory(this);
    info.setTitle(R.string.info_button);
    cat.addPreference(info);
    pref = new Preference(this);
    pref.setTitle(R.string.global_app_allocated_memory);
    long javaAvailMem = (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / (1024 * 1024l);
    long javaTotal = Runtime.getRuntime().totalMemory() / (1024 * 1024l);
    long dalvikSize = android.os.Debug.getNativeHeapAllocatedSize() / (1024 * 1024l);
    pref.setSummary(getString(R.string.global_app_allocated_memory_descr, javaAvailMem, javaTotal, dalvikSize));
    pref.setSelectable(false);
    // setEnabled(false) creates bad readability on some devices
    // pref.setEnabled(false);
    info.addPreference(pref);
    // ActivityManager activityManager = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);
    // ActivityManager.MemoryInfo memoryInfo = new ActivityManager.MemoryInfo();
    // activityManager.getMemoryInfo(memoryInfo);
    // long totalSize = memoryInfo.availMem / (1024*1024l);
    MemoryInfo mem = new Debug.MemoryInfo();
    Debug.getMemoryInfo(mem);
    pref = new Preference(this);
    pref.setTitle(R.string.native_app_allocated_memory);
    pref.setSummary(getString(R.string.native_app_allocated_memory_descr, mem.nativePrivateDirty / 1024, mem.dalvikPrivateDirty / 1024, mem.otherPrivateDirty / 1024, mem.nativePss / 1024, mem.dalvikPss / 1024, mem.otherPss / 1024));
    pref.setSelectable(false);
    // setEnabled(false) creates bad readability on some devices
    // pref.setEnabled(false);
    info.addPreference(pref);
    final Preference agpspref = new Preference(this);
    agpspref.setTitle(R.string.agps_info);
    if (settings.AGPS_DATA_LAST_TIME_DOWNLOADED.get() != 0L) {
        SimpleDateFormat prt = new SimpleDateFormat("yyyy-MM-dd  HH:mm");
        agpspref.setSummary(getString(R.string.agps_data_last_downloaded, prt.format(settings.AGPS_DATA_LAST_TIME_DOWNLOADED.get())));
    } else {
        agpspref.setSummary(getString(R.string.agps_data_last_downloaded, "--"));
    }
    agpspref.setSelectable(true);
    // setEnabled(false) creates bad readability on some devices
    // pref.setEnabled(false);
    agpspref.setOnPreferenceClickListener(new OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            if (getMyApplication().getSettings().isInternetConnectionAvailable(true)) {
                getMyApplication().getLocationProvider().redownloadAGPS();
                SimpleDateFormat prt = new SimpleDateFormat("yyyy-MM-dd  HH:mm");
                agpspref.setSummary(getString(R.string.agps_data_last_downloaded, prt.format(settings.AGPS_DATA_LAST_TIME_DOWNLOADED.get())));
            }
            return true;
        }
    });
    info.addPreference(agpspref);
    SunriseSunset sunriseSunset = getMyApplication().getDaynightHelper().getSunriseSunset();
    pref = new Preference(this);
    pref.setTitle(R.string.day_night_info);
    if (sunriseSunset != null) {
        SimpleDateFormat prt = new SimpleDateFormat("yyyy-MM-dd  HH:mm");
        pref.setSummary(getString(R.string.day_night_info_description, prt.format(sunriseSunset.getSunrise()), prt.format(sunriseSunset.getSunset())));
    } else {
        pref.setSummary(getString(R.string.day_night_info_description, "null", "null"));
    }
    pref.setSelectable(false);
    // setEnabled(false) creates bad readability on some devices
    // pref.setEnabled(false);
    info.addPreference(pref);
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) PreferenceScreen(android.preference.PreferenceScreen) CheckBoxPreference(android.preference.CheckBoxPreference) OsmAndLocationSimulation(net.osmand.plus.OsmAndLocationSimulation) Intent(android.content.Intent) OnPreferenceClickListener(android.preference.Preference.OnPreferenceClickListener) MemoryInfo(android.os.Debug.MemoryInfo) SunriseSunset(net.osmand.util.SunriseSunset) OnPreferenceClickListener(android.preference.Preference.OnPreferenceClickListener) CheckBoxPreference(android.preference.CheckBoxPreference) Preference(android.preference.Preference) PreferenceCategory(android.preference.PreferenceCategory) SimpleDateFormat(java.text.SimpleDateFormat) SuppressLint(android.annotation.SuppressLint)

Example 2 with SunriseSunset

use of net.osmand.util.SunriseSunset in project Osmand by osmandapp.

the class DayNightHelper method isNightMode.

/**
 * @return null if could not be determined (in case of error)
 * @return true if day is supposed to be
 */
public boolean isNightMode() {
    DayNightMode dayNightMode = pref.get();
    if (dayNightMode.isDay()) {
        return false;
    } else if (dayNightMode.isNight()) {
        return true;
    } else // We are in auto mode!
    if (dayNightMode.isAuto()) {
        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.OsmandSettings.DayNightMode)

Example 3 with SunriseSunset

use of net.osmand.util.SunriseSunset in project OsmAnd-tools by osmandapp.

the class TestSunriseSunset method printSunriseSunset.

public static void printSunriseSunset(String date, float lat, float lon, TimeZone tz) throws ParseException {
    SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy");
    SimpleDateFormat prt = new SimpleDateFormat("dd.MM.yyyy HH:mm");
    prt.setTimeZone(TimeZone.getTimeZone("GMT"));
    Date time = sdf.parse(date);
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(time);
    SunriseSunset ss = new SunriseSunset(lat, lon, time, TimeZone.getTimeZone("GMT"));
    // Location location = new Location(lat, lon);
    // SunriseSunsetCalculator calc = new SunriseSunsetCalculator(location, TimeZone.getTimeZone("GMT"));
    System.out.println("Sunrise : " + prt.format(ss.getSunrise()) + " GMT");
    // System.out.println("Sunrise : " + prt.format(calc.getOfficialSunriseCalendarForDate(calendar).getTime()));
    // System.out.println("Sunset  : " + prt.format( calc.getOfficialSunsetCalendarForDate(calendar).getTime()));
    System.out.println("Sunset  : " + prt.format(ss.getSunset()) + " GMT");
}
Also used : SunriseSunset(net.osmand.util.SunriseSunset) Calendar(java.util.Calendar) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 4 with SunriseSunset

use of net.osmand.util.SunriseSunset in project Osmand by osmandapp.

the class DayNightHelper method getSunriseSunset.

public SunriseSunset getSunriseSunset() {
    Location lastKnownLocation = osmandApplication.getLocationProvider().getLastKnownLocation();
    if (lastKnownLocation == null) {
        lastKnownLocation = osmandApplication.getLocationProvider().getFirstTimeRunDefaultLocation();
    }
    if (lastKnownLocation == null) {
        return null;
    }
    double longitude = lastKnownLocation.getLongitude();
    Date actualTime = new Date();
    SunriseSunset daynightSwitch = new SunriseSunset(lastKnownLocation.getLatitude(), longitude < 0 ? 360 + longitude : longitude, actualTime, TimeZone.getDefault());
    return daynightSwitch;
}
Also used : SunriseSunset(net.osmand.util.SunriseSunset) Date(java.util.Date) Location(net.osmand.Location)

Aggregations

SunriseSunset (net.osmand.util.SunriseSunset)4 SimpleDateFormat (java.text.SimpleDateFormat)2 Date (java.util.Date)2 SuppressLint (android.annotation.SuppressLint)1 Intent (android.content.Intent)1 MemoryInfo (android.os.Debug.MemoryInfo)1 CheckBoxPreference (android.preference.CheckBoxPreference)1 Preference (android.preference.Preference)1 OnPreferenceClickListener (android.preference.Preference.OnPreferenceClickListener)1 PreferenceCategory (android.preference.PreferenceCategory)1 PreferenceScreen (android.preference.PreferenceScreen)1 Calendar (java.util.Calendar)1 Location (net.osmand.Location)1 OsmAndLocationSimulation (net.osmand.plus.OsmAndLocationSimulation)1 OsmandApplication (net.osmand.plus.OsmandApplication)1 DayNightMode (net.osmand.plus.OsmandSettings.DayNightMode)1