From 51aa34d52b8b40e0325b306f49b5726b879a4c42 Mon Sep 17 00:00:00 2001 From: cketti Date: Sun, 27 Apr 2014 03:29:06 +0200 Subject: [PATCH] Don't use enum ordinal as array index This fixes a crash when setting up WebDAV accounts. --- .../k9/activity/setup/AccountSetupIncoming.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/com/fsck/k9/activity/setup/AccountSetupIncoming.java b/src/com/fsck/k9/activity/setup/AccountSetupIncoming.java index b275e005d..808a046cc 100644 --- a/src/com/fsck/k9/activity/setup/AccountSetupIncoming.java +++ b/src/com/fsck/k9/activity/setup/AccountSetupIncoming.java @@ -261,8 +261,11 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener securityTypesAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mSecurityTypeView.setAdapter(securityTypesAdapter); + int index = getSecurityTypePosition(mConnectionSecurityChoices, + settings.connectionSecurity); + // Select currently configured security type - mSecurityTypeView.setSelection(settings.connectionSecurity.ordinal(), false); + mSecurityTypeView.setSelection(index, false); /* * Updates the port when the user changes the security type. This allows @@ -469,4 +472,13 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener Toast toast = Toast.makeText(getApplication(), toastText, Toast.LENGTH_LONG); toast.show(); } + + private int getSecurityTypePosition(ConnectionSecurity[] haystack, ConnectionSecurity needle) { + for (int i = 0; i < haystack.length; i++) { + if (haystack[i] == needle) { + return i; + } + } + return 0; + } }