public static void tryRescheduleDownload( Context context, OsmandSettings settings, LocalIndexInfo localIndexInfo) { final OsmandSettings.CommonPreference<Integer> updateFrequencyPreference = preferenceUpdateFrequency(localIndexInfo, settings); final Integer frequencyOrdinal = updateFrequencyPreference.get(); if (LiveUpdatesHelper.UpdateFrequency.values()[frequencyOrdinal] == LiveUpdatesHelper.UpdateFrequency.HOURLY) { return; } final Integer retriesLeft = settings.LIVE_UPDATES_RETRIES.get(); if (retriesLeft > 0) { Intent intent = new Intent(context, LiveUpdatesAlarmReceiver.class); final File file = new File(localIndexInfo.getFileName()); final String fileName = Algorithms.getFileNameWithoutExtension(file); intent.putExtra(LiveUpdatesHelper.LOCAL_INDEX_INFO, localIndexInfo); intent.setAction(fileName); PendingIntent alarmIntent = PendingIntent.getBroadcast(context, 0, intent, 0); long timeToRetry = System.currentTimeMillis() + AlarmManager.INTERVAL_HOUR; AlarmManager alarmMgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); alarmMgr.set(AlarmManager.RTC, timeToRetry, alarmIntent); settings.LIVE_UPDATES_RETRIES.set(retriesLeft - 1); } else { settings.LIVE_UPDATES_RETRIES.resetToDefault(); } }
protected String getDescription(final List<OsmandSettings.CommonPreference<Boolean>> prefs) { int count = 0; int enabled = 0; for (OsmandSettings.CommonPreference<Boolean> p : prefs) { count++; if (p.get()) { enabled++; } } final String descr = enabled + "/" + count; return descr; }
@Override protected void onPreExecute() { if (context instanceof AbstractDownloadActivity) { AbstractDownloadActivity activity = (AbstractDownloadActivity) context; activity.setSupportProgressBarIndeterminateVisibility(true); OsmandSettings settings = activity.getMyApplication().getSettings(); } final OsmandApplication myApplication = getMyApplication(); OsmandSettings.CommonPreference<Long> lastCheckPreference = LiveUpdatesHelper.preferenceLastCheck(localIndexInfo, myApplication.getSettings()); lastCheckPreference.set(System.currentTimeMillis()); }
private void createCustomRenderingProperties( final ContextMenuAdapter adapter, final MapActivity activity, List<RenderingRuleProperty> customRules) { final OsmandMapTileView view = activity.getMapView(); for (final RenderingRuleProperty p : customRules) { if (p.getAttrName().equals(RenderingRuleStorageProperties.A_APP_MODE) || p.getAttrName().equals(RenderingRuleStorageProperties.A_ENGINE_V1)) { continue; } String propertyName = SettingsActivity.getStringPropertyName(view.getContext(), p.getAttrName(), p.getName()); // test old descr as title final String propertyDescr = SettingsActivity.getStringPropertyDescription( view.getContext(), p.getAttrName(), p.getName()); if (p.isBoolean()) { final OsmandSettings.CommonPreference<Boolean> pref = view.getApplication().getSettings().getCustomRenderBooleanProperty(p.getAttrName()); adapter .item(propertyName) .listen( new OnContextMenuClick() { @Override public boolean onContextMenuClick( ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) { pref.set(!pref.get()); refreshMapComplete(activity); return false; } }) .selected(pref.get() ? 1 : 0) .reg(); } else { final OsmandSettings.CommonPreference<String> pref = view.getApplication().getSettings().getCustomRenderProperty(p.getAttrName()); String descr; if (Algorithms.isEmpty(pref.get())) { descr = SettingsActivity.getStringPropertyValue(activity, pref.get()); } else { descr = SettingsActivity.getStringPropertyValue( view.getContext(), p.getDefaultValueDescription()); } adapter .item(propertyName) .listen( new OnContextMenuClick() { @Override public boolean onContextMenuClick( final ArrayAdapter<?> ad, int itemId, final int pos, boolean isChecked) { AlertDialog.Builder b = new AlertDialog.Builder(view.getContext()); // test old descr as title b.setTitle(propertyDescr); int i = Arrays.asList(p.getPossibleValues()).indexOf(pref.get()); if (i >= 0) { i++; } else if (Algorithms.isEmpty(pref.get())) { i = 0; } String[] possibleValuesString = new String[p.getPossibleValues().length + 1]; possibleValuesString[0] = SettingsActivity.getStringPropertyValue( view.getContext(), p.getDefaultValueDescription()); for (int j = 0; j < p.getPossibleValues().length; j++) { possibleValuesString[j + 1] = SettingsActivity.getStringPropertyValue( view.getContext(), p.getPossibleValues()[j]); } b.setSingleChoiceItems( possibleValuesString, i, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (which == 0) { pref.set(""); } else { pref.set(p.getPossibleValues()[which - 1]); } refreshMapComplete(activity); adapter.setItemDescription( pos, SettingsActivity.getStringPropertyValue(activity, pref.get())); dialog.dismiss(); ad.notifyDataSetInvalidated(); } }); b.show(); return false; } }) .description(descr) .layout(R.layout.drawer_list_doubleitem) .reg(); } } }