From cba9ccd416ae33164c4ebbd5326bc2b7881667ec Mon Sep 17 00:00:00 2001 From: dzan Date: Wed, 20 Jul 2011 14:52:42 +0200 Subject: [PATCH] Added two new activities to allow for confirming/choosing the detected settings. Also connected them to the next button in the autoconfiguration activity. --- AndroidManifest.xml | 12 +++ res/layout/account_setup_confirm.xml | 24 +++++ res/values/strings.xml | 2 + .../setup/AccountSetupAutoConfiguration.java | 18 ++-- .../setup/AccountSetupConfirmIncoming.java | 87 +++++++++++++++++++ .../setup/AccountSetupConfirmOutgoing.java | 72 +++++++++++++++ 6 files changed, 207 insertions(+), 8 deletions(-) create mode 100644 res/layout/account_setup_confirm.xml create mode 100644 src/com/fsck/k9/activity/setup/AccountSetupConfirmIncoming.java create mode 100644 src/com/fsck/k9/activity/setup/AccountSetupConfirmOutgoing.java diff --git a/AndroidManifest.xml b/AndroidManifest.xml index e7a566102..539a8433d 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -108,6 +108,18 @@ android:configChanges="keyboardHidden|orientation|locale" > + + + + + + + + + + + + \ No newline at end of file diff --git a/res/values/strings.xml b/res/values/strings.xml index 46444369f..06528342f 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -369,6 +369,8 @@ http://k9mail.googlecode.com/ Canceling\u2026 Autoconfiguration attempt + Confirm incoming server settings + Confirm outgoing server settings Attempting to configure your account... Looking for safe server-side configuration files... Looking for UNSAFE server-side configuration files... diff --git a/src/com/fsck/k9/activity/setup/AccountSetupAutoConfiguration.java b/src/com/fsck/k9/activity/setup/AccountSetupAutoConfiguration.java index 42cba7620..2d1c22912 100644 --- a/src/com/fsck/k9/activity/setup/AccountSetupAutoConfiguration.java +++ b/src/com/fsck/k9/activity/setup/AccountSetupAutoConfiguration.java @@ -14,9 +14,11 @@ import android.widget.TextView; import com.fsck.k9.K9; import com.fsck.k9.R; import com.fsck.k9.activity.K9Activity; +import com.fsck.k9.helper.configxmlparser.AutoconfigInfo; import com.fsck.k9.helper.configxmlparser.ConfigurationXMLHandler; import com.fsck.k9.mail.store.TrustManagerFactory; import org.xml.sax.InputSource; +import org.xml.sax.Parser; import org.xml.sax.SAXException; import org.xml.sax.XMLReader; @@ -85,6 +87,7 @@ public class AccountSetupAutoConfiguration extends K9Activity implements View.On private String mEmailAddress; private String mPassword; private String mLastMessage; + private AutoconfigInfo mAutoConfigInfo; private boolean bForceManual = false; private boolean bDoneSearching = false; private boolean bFound = false; @@ -257,10 +260,12 @@ public class AccountSetupAutoConfiguration extends K9Activity implements View.On Start parsing the xml */ private void parse(String data) throws IOException, SAXException, ParserConfigurationException { + ConfigurationXMLHandler parser = new ConfigurationXMLHandler(); XMLReader xr = SAXParserFactory.newInstance().newSAXParser().getXMLReader(); - xr.setContentHandler(new ConfigurationXMLHandler()); + xr.setContentHandler(parser); // TODO: see if this has performance consequences, otherwise change all so we pass around InputSource not string xr.parse(new InputSource(new StringReader(data))); + mAutoConfigInfo = parser.getAutoconfigInfo(); } /* @@ -367,12 +372,6 @@ public class AccountSetupAutoConfiguration extends K9Activity implements View.On return retParts; } - @Override - public void onActivityResult(int reqCode, int resCode, Intent data) { - setResult(resCode); - finish(); - } - public void onClick(View v) { switch (v.getId()) { case R.id.autoconfig_button_cancel: @@ -384,7 +383,9 @@ public class AccountSetupAutoConfiguration extends K9Activity implements View.On // launch confirm activities }else{ - + AccountSetupConfirmIncoming.actionConfirmIncoming + (this, mEmailAddress, mPassword, mAutoConfigInfo); + finish(); } break; default: return; @@ -394,6 +395,7 @@ public class AccountSetupAutoConfiguration extends K9Activity implements View.On /* Ask the user to accept ssl certificates if they are not trusted already. TODO: Rework this so it changes the url counter, not restart intent + NOTE: It's called but doesn't work right now because for the connection the default sslfactory is yet used */ private void acceptKeyDialog(final int msgResId, final int urlNumber, final Object... args) { mHandler.post(new Runnable() { diff --git a/src/com/fsck/k9/activity/setup/AccountSetupConfirmIncoming.java b/src/com/fsck/k9/activity/setup/AccountSetupConfirmIncoming.java new file mode 100644 index 000000000..1aab3fa91 --- /dev/null +++ b/src/com/fsck/k9/activity/setup/AccountSetupConfirmIncoming.java @@ -0,0 +1,87 @@ +package com.fsck.k9.activity.setup; + +/* + After gathering the necessary information one way or another this activity displays it to the user, eventually warns + him it could be false ( no https ), asks for confirmation, allows selection of protocol,... and then goes on to test + the final settings. + */ + +import android.content.Context; +import android.content.Intent; +import android.os.Bundle; +import android.view.View; +import android.widget.ArrayAdapter; +import android.widget.Spinner; +import com.fsck.k9.Account; +import com.fsck.k9.Preferences; +import com.fsck.k9.R; +import com.fsck.k9.activity.K9Activity; +import com.fsck.k9.helper.configxmlparser.AutoconfigInfo; +import com.fsck.k9.helper.configxmlparser.AutoconfigInfo.ServerType; + +public class AccountSetupConfirmIncoming extends K9Activity implements View.OnClickListener { + + private static final String EXTRA_ACCOUNT = "account"; + private static final String EXTRA_CONFIG_INFO = "configInfo"; + private static final String EXTRA_EMAIL = "email"; + private static final String EXTRA_PASSWORD = "password"; + + + public static void actionConfirmIncoming(Context context, Account account, AutoconfigInfo info) { + Intent i = new Intent(context, AccountSetupConfirmIncoming.class); + i.putExtra(EXTRA_ACCOUNT, account.getUuid()); + i.putExtra(EXTRA_CONFIG_INFO, info); + context.startActivity(i); + } + + public static void actionConfirmIncoming(Context context, String email, String password, AutoconfigInfo info){ + Intent i = new Intent(context, AccountSetupConfirmIncoming.class); + i.putExtra(EXTRA_EMAIL, email); + i.putExtra(EXTRA_PASSWORD, password); + i.putExtra(EXTRA_CONFIG_INFO, info); + context.startActivity(i); + } + + // data + Account mAccount; + AutoconfigInfo mConfigInfo; + + // gui elements + Spinner mProtocolSpinner; + Spinner mHostnameSpinner; + + @Override + public void onCreate(Bundle savedInstance){ + super.onCreate(savedInstance); + setContentView(R.layout.account_setup_confirm); + + // initialise gui elements from inflated layout + mHostnameSpinner = (Spinner) findViewById(R.id.spinner_hostname); + mProtocolSpinner = (Spinner) findViewById(R.id.spinner_protocol); + + // get the data out of our intent + // if no blank account passed make one + String accountUuid = getIntent().getStringExtra(EXTRA_ACCOUNT); + if(accountUuid != null) + mAccount = Preferences.getPreferences(this).getAccount(accountUuid); + else mAccount = Account.getBlankAccount(this, + getIntent().getStringExtra(EXTRA_EMAIL), + getIntent().getStringExtra(EXTRA_PASSWORD)); + mConfigInfo = getIntent().getParcelableExtra(EXTRA_CONFIG_INFO); + + // attach data to gui elements + // TODO: could make it's own layout xml.. + ArrayAdapter protocolAdapter = + new ArrayAdapter(this, R.layout.account_setup_index_list_item, mConfigInfo.getAvailableIncomingServerTypes()); + mHostnameSpinner.setAdapter(protocolAdapter); + + // attach the listeners + + } + + @Override + public void onClick(View view) { + //To change body of implemented methods use File | Settings | File Templates. + } + +} diff --git a/src/com/fsck/k9/activity/setup/AccountSetupConfirmOutgoing.java b/src/com/fsck/k9/activity/setup/AccountSetupConfirmOutgoing.java new file mode 100644 index 000000000..5de2eb71a --- /dev/null +++ b/src/com/fsck/k9/activity/setup/AccountSetupConfirmOutgoing.java @@ -0,0 +1,72 @@ +package com.fsck.k9.activity.setup; + +/* + After gathering the necessary information one way or another this activity displays it to the user, eventually warns + him it could be false ( no https ), asks for confirmation, allows selection of protocol,... and then goes on to test + the final settings. + */ + +import android.app.Activity; +import android.content.Context; +import android.content.Intent; +import android.os.Bundle; +import android.view.View; +import com.fsck.k9.Account; +import com.fsck.k9.Preferences; +import com.fsck.k9.R; +import com.fsck.k9.activity.K9Activity; +import com.fsck.k9.helper.configxmlparser.AutoconfigInfo; + +public class AccountSetupConfirmOutgoing extends K9Activity implements View.OnClickListener{ + + private static final String EXTRA_ACCOUNT = "account"; + private static final String EXTRA_CONFIG_INFO = "configInfo"; + private static final String EXTRA_EMAIL = "email"; + private static final String EXTRA_PASSWORD = "password"; + + + public static void actionConfirmOutgoing(Context context, Account account, AutoconfigInfo info) { + Intent i = new Intent(context, AccountSetupConfirmOutgoing.class); + i.putExtra(EXTRA_ACCOUNT, account.getUuid()); + i.putExtra(EXTRA_CONFIG_INFO, info); + context.startActivity(i); + } + + public static void actionConfirmOutgoing(Context context, String email, String password, AutoconfigInfo info){ + Intent i = new Intent(context, AccountSetupConfirmOutgoing.class); + i.putExtra(EXTRA_EMAIL, email); + i.putExtra(EXTRA_PASSWORD, password); + i.putExtra(EXTRA_CONFIG_INFO, info); + context.startActivity(i); + } + + // data + Account mAccount; + AutoconfigInfo mConfigInfo; + + @Override + public void onCreate(Bundle savedInstance){ + super.onCreate(savedInstance); + setContentView(R.layout.account_setup_confirm); + + // initialise gui elements from inflated layout + + // get the data out of our intent + // if no blank account passed make one + String accountUuid = getIntent().getStringExtra(EXTRA_ACCOUNT); + if(accountUuid != null) + mAccount = Preferences.getPreferences(this).getAccount(accountUuid); + else mAccount = Account.getBlankAccount(this, + getIntent().getStringExtra(EXTRA_EMAIL), + getIntent().getStringExtra(EXTRA_PASSWORD)); + mConfigInfo = getIntent().getParcelableExtra(EXTRA_CONFIG_INFO); + + // attach the listeners + + } + + @Override + public void onClick(View view) { + //To change body of implemented methods use File | Settings | File Templates. + } +}