use of android.content.DialogInterface.OnClickListener in project Osmand by osmandapp.
the class SettingsGeneralActivity method addLocalPrefs.
private void addLocalPrefs(PreferenceGroup screen) {
drivingRegionPreference.setTitle(R.string.driving_region);
drivingRegionPreference.setSummary(R.string.driving_region_descr);
drivingRegionPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
final AlertDialog.Builder b = new AlertDialog.Builder(SettingsGeneralActivity.this);
b.setTitle(getString(R.string.driving_region));
final List<DrivingRegion> drs = new ArrayList<>();
drs.add(null);
drs.addAll(Arrays.asList(DrivingRegion.values()));
int sel = -1;
DrivingRegion selectedDrivingRegion = settings.DRIVING_REGION.get();
if (settings.DRIVING_REGION_AUTOMATIC.get()) {
sel = 0;
}
for (int i = 1; i < drs.size(); i++) {
if (sel == -1 && drs.get(i) == selectedDrivingRegion) {
sel = i;
break;
}
}
final int selected = sel;
final ArrayAdapter<DrivingRegion> singleChoiceAdapter = new ArrayAdapter<DrivingRegion>(SettingsGeneralActivity.this, R.layout.single_choice_description_item, R.id.text1, drs) {
@NonNull
@Override
public View getView(int position, View convertView, @NonNull ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater inflater = SettingsGeneralActivity.this.getLayoutInflater();
v = inflater.inflate(R.layout.single_choice_description_item, parent, false);
}
DrivingRegion item = getItem(position);
AppCompatCheckedTextView title = (AppCompatCheckedTextView) v.findViewById(R.id.text1);
TextView desc = (TextView) v.findViewById(R.id.description);
if (item != null) {
title.setText(getString(item.name));
desc.setVisibility(View.VISIBLE);
desc.setText(item.getDescription(v.getContext()));
} else {
title.setText(getString(R.string.driving_region_automatic));
desc.setVisibility(View.GONE);
}
title.setChecked(position == selected);
return v;
}
};
b.setAdapter(singleChoiceAdapter, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (drs.get(which) == null) {
settings.DRIVING_REGION_AUTOMATIC.set(true);
MapViewTrackingUtilities mapViewTrackingUtilities = MapActivity.getSingleMapViewTrackingUtilities();
if (mapViewTrackingUtilities != null) {
mapViewTrackingUtilities.resetDrivingRegionUpdate();
}
} else {
settings.DRIVING_REGION_AUTOMATIC.set(false);
settings.DRIVING_REGION.set(drs.get(which));
}
updateAllSettings();
}
});
b.setNegativeButton(R.string.shared_string_cancel, null);
b.show();
return true;
}
});
String[] entries;
String[] entrieValues;
MetricsConstants[] mvls = MetricsConstants.values();
entries = new String[mvls.length];
for (int i = 0; i < entries.length; i++) {
entries[i] = mvls[i].toHumanString(getMyApplication());
}
registerListPreference(settings.METRIC_SYSTEM, screen, entries, mvls);
Integer[] cvls = new Integer[5];
cvls[0] = PointDescription.FORMAT_DEGREES;
cvls[1] = PointDescription.FORMAT_MINUTES;
cvls[2] = PointDescription.FORMAT_SECONDS;
cvls[3] = PointDescription.UTM_FORMAT;
cvls[4] = PointDescription.OLC_FORMAT;
entries = new String[5];
entries[0] = PointDescription.formatToHumanString(this, PointDescription.FORMAT_DEGREES);
entries[1] = PointDescription.formatToHumanString(this, PointDescription.FORMAT_MINUTES);
entries[2] = PointDescription.formatToHumanString(this, PointDescription.FORMAT_SECONDS);
entries[3] = PointDescription.formatToHumanString(this, PointDescription.UTM_FORMAT);
entries[4] = PointDescription.formatToHumanString(this, PointDescription.OLC_FORMAT);
registerListPreference(settings.COORDINATES_FORMAT, screen, entries, cvls);
// See language list and statistics at: https://hosted.weblate.org/projects/osmand/main/
// Hardy maintenance 2016-05-29:
// - Include languages if their translation is >= ~10% (but any language will be visible if it is the device's system locale)
// - Mark as "incomplete" if < ~80%
String incompleteSuffix = " (" + getString(R.string.incomplete_locale) + ")";
// Add " (Device language)" to system default entry in Latin letters, so it can be more easily identified if a foreign language has been selected by mistake
String latinSystemDefaultSuffix = " (" + getString(R.string.system_locale_no_translate) + ")";
// getResources().getAssets().getLocales();
entrieValues = new String[] { "", "en", "af", "ar", "ast", "az", "be", "be_BY", "bg", "ca", "cs", "cy", "da", "de", "el", "en_GB", "eo", "es", "es_AR", "es_US", "eu", "fa", "fi", "fr", "gl", "he", "hr", "hsb", "hu", "hy", "is", "it", "ja", "ka", "kab", "kn", "ko", "lt", "lv", "ml", "mr", "nb", "nl", "nn", "pl", "pt", "pt_BR", "ro", "ru", "sc", "sk", "sl", "sr", "sr+Latn", "sv", "tr", "uk", "vi", "zh_CN", "zh_TW" };
entries = new String[] { getString(R.string.system_locale) + latinSystemDefaultSuffix, getString(R.string.lang_en), getString(R.string.lang_af) + incompleteSuffix, getString(R.string.lang_ar), getString(R.string.lang_ast) + incompleteSuffix, getString(R.string.lang_az), getString(R.string.lang_be), getString(R.string.lang_be_by), getString(R.string.lang_bg), getString(R.string.lang_ca), getString(R.string.lang_cs), getString(R.string.lang_cy) + incompleteSuffix, getString(R.string.lang_da), getString(R.string.lang_de), getString(R.string.lang_el) + incompleteSuffix, getString(R.string.lang_en_gb), getString(R.string.lang_eo), getString(R.string.lang_es), getString(R.string.lang_es_ar), getString(R.string.lang_es_us), getString(R.string.lang_eu) + incompleteSuffix, getString(R.string.lang_fa), getString(R.string.lang_fi) + incompleteSuffix, getString(R.string.lang_fr), getString(R.string.lang_gl) + incompleteSuffix, getString(R.string.lang_he) + incompleteSuffix, getString(R.string.lang_hr) + incompleteSuffix, getString(R.string.lang_hsb) + incompleteSuffix, getString(R.string.lang_hu), getString(R.string.lang_hy), getString(R.string.lang_is) + incompleteSuffix, getString(R.string.lang_it), getString(R.string.lang_ja), getString(R.string.lang_ka) + incompleteSuffix, getString(R.string.lang_kab) + incompleteSuffix, getString(R.string.lang_kn) + incompleteSuffix, getString(R.string.lang_ko), getString(R.string.lang_lt), getString(R.string.lang_lv), getString(R.string.lang_ml) + incompleteSuffix, getString(R.string.lang_mr) + incompleteSuffix, getString(R.string.lang_nb), getString(R.string.lang_nl), getString(R.string.lang_nn) + incompleteSuffix, getString(R.string.lang_pl), getString(R.string.lang_pt), getString(R.string.lang_pt_br), getString(R.string.lang_ro) + incompleteSuffix, getString(R.string.lang_ru), getString(R.string.lang_sc), getString(R.string.lang_sk), getString(R.string.lang_sl), getString(R.string.lang_sr) + incompleteSuffix, getString(R.string.lang_sr_latn) + incompleteSuffix, getString(R.string.lang_sv), getString(R.string.lang_tr), getString(R.string.lang_uk), getString(R.string.lang_vi) + incompleteSuffix, getString(R.string.lang_zh_cn) + incompleteSuffix, getString(R.string.lang_zh_tw) };
String[] valuesPl = ConfigureMapMenu.getSortedMapNamesIds(this, entries, entries);
String[] idsPl = ConfigureMapMenu.getSortedMapNamesIds(this, entrieValues, entries);
registerListPreference(settings.PREFERRED_LOCALE, screen, valuesPl, idsPl);
// Add " (Display language)" to menu title in Latin letters for all non-en languages
if (!getResources().getString(R.string.preferred_locale).equals(getResources().getString(R.string.preferred_locale_no_translate))) {
((ListPreference) screen.findPreference(settings.PREFERRED_LOCALE.getId())).setTitle(getString(R.string.preferred_locale) + " (" + getString(R.string.preferred_locale_no_translate) + ")");
}
// This setting now only in "Confgure map" menu
// String[] values = ConfigureMapMenu.getMapNamesValues(this, ConfigureMapMenu.mapNamesIds);
// String[] ids = ConfigureMapMenu.getSortedMapNamesIds(this, ConfigureMapMenu.mapNamesIds, values);
// registerListPreference(settings.MAP_PREFERRED_LOCALE, screen, ConfigureMapMenu.getMapNamesValues(this, ids), ids);
}
use of android.content.DialogInterface.OnClickListener in project Osmand by osmandapp.
the class SettingsGeneralActivity method restartApp.
private void restartApp() {
AlertDialog.Builder bld = new AlertDialog.Builder(this);
bld.setMessage(R.string.restart_is_required);
bld.setPositiveButton(R.string.shared_string_ok, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
android.os.Process.killProcess(android.os.Process.myPid());
// Intent intent = getIntent();
// finish();
// startActivity(intent);
}
});
bld.show();
}
use of android.content.DialogInterface.OnClickListener in project Osmand by osmandapp.
the class GpxUiHelper method createDialog.
private static AlertDialog createDialog(final Activity activity, final boolean showCurrentGpx, final boolean multipleChoice, final boolean showAppearanceSetting, final CallbackWithObject<GPXFile[]> callbackWithObject, final List<GPXInfo> list, final ContextMenuAdapter adapter) {
final OsmandApplication app = (OsmandApplication) activity.getApplication();
final DateFormat dateFormat = android.text.format.DateFormat.getMediumDateFormat(activity);
final File dir = app.getAppPath(IndexConstants.GPX_INDEX_DIR);
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
final int layout = R.layout.gpx_track_item;
final Map<String, String> gpxAppearanceParams = new HashMap<>();
final ArrayAdapter<String> listAdapter = new ArrayAdapter<String>(activity, layout, R.id.title, adapter.getItemNames()) {
List<GpxDataItem> dataItems = null;
@Override
public int getItemViewType(int position) {
return showCurrentGpx && position == 0 ? 1 : 0;
}
@Override
public int getViewTypeCount() {
return 2;
}
private GpxDataItem getDataItem(GPXInfo info) {
if (dataItems != null) {
for (GpxDataItem item : dataItems) {
if (item.getFile().getAbsolutePath().endsWith(info.fileName)) {
return item;
}
}
}
return null;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
// User super class to create the View
View v = convertView;
boolean checkLayout = getItemViewType(position) == 0;
if (v == null) {
v = activity.getLayoutInflater().inflate(layout, null);
}
if (dataItems == null) {
dataItems = app.getGpxDatabase().getItems();
}
final ContextMenuItem item = adapter.getItem(position);
GPXInfo info = list.get(position);
updateGpxInfoView(v, item, info, getDataItem(info), showCurrentGpx && position == 0, app);
if (item.getSelected() == null) {
v.findViewById(R.id.check_item).setVisibility(View.GONE);
v.findViewById(R.id.check_local_index).setVisibility(View.GONE);
} else {
if (checkLayout) {
final CheckBox ch = ((CheckBox) v.findViewById(R.id.check_local_index));
ch.setVisibility(View.VISIBLE);
v.findViewById(R.id.toggle_item).setVisibility(View.GONE);
ch.setOnCheckedChangeListener(null);
ch.setChecked(item.getSelected());
ch.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
item.setSelected(isChecked);
}
});
} else {
final SwitchCompat ch = ((SwitchCompat) v.findViewById(R.id.toggle_item));
ch.setVisibility(View.VISIBLE);
v.findViewById(R.id.toggle_checkbox_item).setVisibility(View.GONE);
ch.setOnCheckedChangeListener(null);
ch.setChecked(item.getSelected());
ch.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
item.setSelected(isChecked);
}
});
}
v.findViewById(R.id.check_item).setVisibility(View.VISIBLE);
}
return v;
}
};
OnClickListener onClickListener = new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int position) {
}
};
builder.setAdapter(listAdapter, onClickListener);
if (multipleChoice) {
if (showAppearanceSetting) {
final RenderingRuleProperty trackWidthProp;
final RenderingRuleProperty trackColorProp;
final RenderingRulesStorage renderer = app.getRendererRegistry().getCurrentSelectedRenderer();
if (renderer != null) {
trackWidthProp = renderer.PROPS.getCustomRule(CURRENT_TRACK_WIDTH_ATTR);
trackColorProp = renderer.PROPS.getCustomRule(CURRENT_TRACK_COLOR_ATTR);
} else {
trackWidthProp = null;
trackColorProp = null;
}
if (trackWidthProp == null || trackColorProp == null) {
builder.setTitle(R.string.show_gpx);
} else {
final View apprTitleView = activity.getLayoutInflater().inflate(R.layout.select_gpx_appearance_title, null);
final OsmandSettings.CommonPreference<String> prefWidth = app.getSettings().getCustomRenderProperty(CURRENT_TRACK_WIDTH_ATTR);
final OsmandSettings.CommonPreference<String> prefColor = app.getSettings().getCustomRenderProperty(CURRENT_TRACK_COLOR_ATTR);
updateAppearanceTitle(activity, app, trackWidthProp, renderer, apprTitleView, prefWidth.get(), prefColor.get());
apprTitleView.findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final ListPopupWindow popup = new ListPopupWindow(activity);
popup.setAnchorView(apprTitleView);
popup.setContentWidth(AndroidUtils.dpToPx(activity, 200f));
popup.setModal(true);
popup.setDropDownGravity(Gravity.RIGHT | Gravity.TOP);
popup.setVerticalOffset(AndroidUtils.dpToPx(activity, -48f));
popup.setHorizontalOffset(AndroidUtils.dpToPx(activity, -6f));
final GpxAppearanceAdapter gpxApprAdapter = new GpxAppearanceAdapter(activity, gpxAppearanceParams.containsKey(CURRENT_TRACK_COLOR_ATTR) ? gpxAppearanceParams.get(CURRENT_TRACK_COLOR_ATTR) : prefColor.get(), GpxAppearanceAdapter.GpxAppearanceAdapterType.TRACK_WIDTH_COLOR);
popup.setAdapter(gpxApprAdapter);
popup.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
AppearanceListItem item = gpxApprAdapter.getItem(position);
if (item != null) {
if (item.getAttrName() == CURRENT_TRACK_WIDTH_ATTR) {
gpxAppearanceParams.put(CURRENT_TRACK_WIDTH_ATTR, item.getValue());
} else if (item.getAttrName() == CURRENT_TRACK_COLOR_ATTR) {
gpxAppearanceParams.put(CURRENT_TRACK_COLOR_ATTR, item.getValue());
}
}
popup.dismiss();
updateAppearanceTitle(activity, app, trackWidthProp, renderer, apprTitleView, gpxAppearanceParams.containsKey(CURRENT_TRACK_WIDTH_ATTR) ? gpxAppearanceParams.get(CURRENT_TRACK_WIDTH_ATTR) : prefWidth.get(), gpxAppearanceParams.containsKey(CURRENT_TRACK_COLOR_ATTR) ? gpxAppearanceParams.get(CURRENT_TRACK_COLOR_ATTR) : prefColor.get());
}
});
popup.show();
}
});
builder.setCustomTitle(apprTitleView);
}
} else {
builder.setTitle(R.string.show_gpx);
}
builder.setPositiveButton(R.string.shared_string_ok, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (gpxAppearanceParams.size() > 0) {
for (Map.Entry<String, String> entry : gpxAppearanceParams.entrySet()) {
final OsmandSettings.CommonPreference<String> pref = app.getSettings().getCustomRenderProperty(entry.getKey());
pref.set(entry.getValue());
}
if (activity instanceof MapActivity) {
ConfigureMapMenu.refreshMapComplete((MapActivity) activity);
}
}
GPXFile currentGPX = null;
// clear all previously selected files before adding new one
OsmandApplication app = (OsmandApplication) activity.getApplication();
if (app != null && app.getSelectedGpxHelper() != null) {
app.getSelectedGpxHelper().clearAllGpxFileToShow();
}
if (app != null && showCurrentGpx && adapter.getItem(0).getSelected()) {
currentGPX = app.getSavingTrackHelper().getCurrentGpx();
}
List<String> s = new ArrayList<>();
for (int i = (showCurrentGpx ? 1 : 0); i < adapter.length(); i++) {
if (adapter.getItem(i).getSelected()) {
s.add(list.get(i).getFileName());
}
}
dialog.dismiss();
loadGPXFileInDifferentThread(activity, callbackWithObject, dir, currentGPX, s.toArray(new String[s.size()]));
}
});
builder.setNegativeButton(R.string.shared_string_cancel, null);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && list.size() > 1 || !showCurrentGpx && list.size() > 0) {
builder.setNeutralButton(R.string.gpx_add_track, null);
}
}
final AlertDialog dlg = builder.create();
dlg.setCanceledOnTouchOutside(true);
if (list.size() == 0 || showCurrentGpx && list.size() == 1) {
final View footerView = activity.getLayoutInflater().inflate(R.layout.no_gpx_files_list_footer, null);
TextView descTextView = (TextView) footerView.findViewById(R.id.descFolder);
String descPrefix = app.getString(R.string.gpx_no_tracks_title_folder);
SpannableString spannableDesc = new SpannableString(descPrefix + ": " + dir.getAbsolutePath());
spannableDesc.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), descPrefix.length() + 1, spannableDesc.length(), 0);
descTextView.setText(spannableDesc);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
footerView.findViewById(R.id.button).setVisibility(View.GONE);
} else {
footerView.findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
addTrack(activity, dlg);
}
});
}
dlg.getListView().addFooterView(footerView, null, false);
}
dlg.getListView().setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (multipleChoice) {
ContextMenuItem item = adapter.getItem(position);
item.setSelected(!item.getSelected());
listAdapter.notifyDataSetInvalidated();
if (position == 0 && showCurrentGpx && item.getSelected()) {
OsmandMonitoringPlugin monitoringPlugin = OsmandPlugin.getEnabledPlugin(OsmandMonitoringPlugin.class);
if (monitoringPlugin == null) {
AlertDialog.Builder confirm = new AlertDialog.Builder(activity);
confirm.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(activity, PluginActivity.class);
intent.putExtra(PluginActivity.EXTRA_PLUGIN_ID, OsmandMonitoringPlugin.ID);
activity.startActivity(intent);
}
});
confirm.setNegativeButton(R.string.shared_string_cancel, null);
confirm.setMessage(activity.getString(R.string.enable_plugin_monitoring_services));
confirm.show();
} else if (!app.getSettings().SAVE_GLOBAL_TRACK_TO_GPX.get()) {
monitoringPlugin.controlDialog(activity, false);
}
}
} else {
dlg.dismiss();
if (showCurrentGpx && position == 0) {
callbackWithObject.processResult(null);
} else {
String fileName = list.get(position).getFileName();
SelectedGpxFile selectedGpxFile = app.getSelectedGpxHelper().getSelectedFileByName(fileName);
if (selectedGpxFile != null) {
callbackWithObject.processResult(new GPXFile[] { selectedGpxFile.getGpxFile() });
} else {
loadGPXFileInDifferentThread(activity, callbackWithObject, dir, null, fileName);
}
}
}
}
});
dlg.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
Button addTrackButton = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_NEUTRAL);
if (addTrackButton != null) {
addTrackButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
addTrack(activity, dlg);
}
});
}
}
});
dlg.show();
try {
dlg.getListView().setFastScrollEnabled(true);
} catch (Exception e) {
// java.lang.ClassCastException: com.android.internal.widget.RoundCornerListAdapter
// Unknown reason but on some devices fail
}
return dlg;
}
use of android.content.DialogInterface.OnClickListener in project Osmand by osmandapp.
the class GpxUiHelper method createSingleChoiceDialog.
private static AlertDialog createSingleChoiceDialog(final Activity activity, final boolean showCurrentGpx, final CallbackWithObject<GPXFile[]> callbackWithObject, final List<GPXInfo> list, final ContextMenuAdapter adapter) {
final OsmandApplication app = (OsmandApplication) activity.getApplication();
final IconsCache iconsCache = app.getIconsCache();
final File dir = app.getAppPath(IndexConstants.GPX_INDEX_DIR);
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
final int layout = R.layout.list_menu_item_native_singlechoice;
final ArrayAdapter<String> listAdapter = new ArrayAdapter<String>(activity, layout, R.id.text1, adapter.getItemNames()) {
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
// User super class to create the View
View v = convertView;
if (v == null) {
v = activity.getLayoutInflater().inflate(layout, null);
}
final ContextMenuItem item = adapter.getItem(position);
TextView tv = (TextView) v.findViewById(R.id.text1);
Drawable icon;
if (showCurrentGpx && position == 0) {
icon = null;
} else {
icon = iconsCache.getThemedIcon(item.getIcon());
}
tv.setCompoundDrawablePadding(AndroidUtils.dpToPx(activity, 10f));
tv.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null);
tv.setText(item.getTitle());
tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
return v;
}
};
int selectedIndex = 0;
String prevSelectedGpx = app.getSettings().LAST_SELECTED_GPX_TRACK_FOR_NEW_POINT.get();
if (prevSelectedGpx != null) {
selectedIndex = list.indexOf(prevSelectedGpx);
}
if (selectedIndex == -1) {
selectedIndex = 0;
}
final int[] selectedPosition = { selectedIndex };
builder.setSingleChoiceItems(listAdapter, selectedIndex, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int position) {
selectedPosition[0] = position;
}
});
builder.setTitle(R.string.select_gpx).setPositiveButton(R.string.shared_string_ok, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
int position = selectedPosition[0];
if (position != -1) {
if (showCurrentGpx && position == 0) {
callbackWithObject.processResult(null);
app.getSettings().LAST_SELECTED_GPX_TRACK_FOR_NEW_POINT.set(null);
} else {
String fileName = list.get(position).getFileName();
app.getSettings().LAST_SELECTED_GPX_TRACK_FOR_NEW_POINT.set(fileName);
SelectedGpxFile selectedGpxFile = app.getSelectedGpxHelper().getSelectedFileByName(fileName);
if (selectedGpxFile != null) {
callbackWithObject.processResult(new GPXFile[] { selectedGpxFile.getGpxFile() });
} else {
loadGPXFileInDifferentThread(activity, callbackWithObject, dir, null, fileName);
}
}
}
}
}).setNegativeButton(R.string.shared_string_cancel, null);
final AlertDialog dlg = builder.create();
dlg.setCanceledOnTouchOutside(false);
dlg.show();
try {
dlg.getListView().setFastScrollEnabled(true);
} catch (Exception e) {
// java.lang.ClassCastException: com.android.internal.widget.RoundCornerListAdapter
// Unknown reason but on some devices fail
}
return dlg;
}
use of android.content.DialogInterface.OnClickListener in project Osmand by osmandapp.
the class WaypointDialogHelper method selectDifferentRadius.
protected void selectDifferentRadius(final int type, final int[] running, final int position, final ArrayAdapter<Object> thisAdapter, Activity ctx) {
int length = WaypointHelper.SEARCH_RADIUS_VALUES.length;
String[] names = new String[length];
int selected = 0;
for (int i = 0; i < length; i++) {
names[i] = OsmAndFormatter.getFormattedDistance(WaypointHelper.SEARCH_RADIUS_VALUES[i], app);
if (WaypointHelper.SEARCH_RADIUS_VALUES[i] == waypointHelper.getSearchDeviationRadius(type)) {
selected = i;
}
}
new AlertDialog.Builder(ctx).setSingleChoiceItems(names, selected, new OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
int value = WaypointHelper.SEARCH_RADIUS_VALUES[i];
if (waypointHelper.getSearchDeviationRadius(type) != value) {
running[0] = position;
waypointHelper.setSearchDeviationRadius(type, value);
recalculatePoints(running, thisAdapter, type);
dialogInterface.dismiss();
thisAdapter.notifyDataSetInvalidated();
}
}
}).setTitle(app.getString(R.string.search_radius_proximity)).setNegativeButton(R.string.shared_string_cancel, null).show();
}
Aggregations