From 252b406d8ec02e353f68e2bde1d9d0ac053bac12 Mon Sep 17 00:00:00 2001 From: dzan Date: Sun, 24 Jul 2011 18:02:17 +0200 Subject: [PATCH] Implements a very simple and basic view for the confirm screens showing filtered account configuration information. --- res/layout/account_setup_confirm.xml | 44 ++++-- .../setup/AbstractSetupConfirmActivity.java | 140 ++++++++++++++++++ .../setup/AccountSetupConfirmIncoming.java | 102 +------------ .../setup/AccountSetupConfirmOutgoing.java | 68 ++------- .../configxmlparser/AutoconfigInfo.java | 2 +- 5 files changed, 192 insertions(+), 164 deletions(-) create mode 100644 src/com/fsck/k9/activity/setup/AbstractSetupConfirmActivity.java diff --git a/res/layout/account_setup_confirm.xml b/res/layout/account_setup_confirm.xml index cef1b23a1..ae186c0b3 100644 --- a/res/layout/account_setup_confirm.xml +++ b/res/layout/account_setup_confirm.xml @@ -4,21 +4,43 @@ android:layout_width="fill_parent" android:layout_height="fill_parent"> - + android:orientation="horizontal"> + - + + + + android:orientation="horizontal" + android:layout_below="@id/confirm_first_option"> + + + + + \ No newline at end of file diff --git a/src/com/fsck/k9/activity/setup/AbstractSetupConfirmActivity.java b/src/com/fsck/k9/activity/setup/AbstractSetupConfirmActivity.java new file mode 100644 index 000000000..e56b8efcd --- /dev/null +++ b/src/com/fsck/k9/activity/setup/AbstractSetupConfirmActivity.java @@ -0,0 +1,140 @@ +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.AdapterView; +import android.widget.AdapterView.OnItemSelectedListener; +import android.widget.ArrayAdapter; +import android.widget.Spinner; +import android.widget.TextView; +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; +import com.fsck.k9.helper.configxmlparser.AutoconfigInfo.SocketType; +import com.fsck.k9.helper.configxmlparser.AutoconfigInfo.Server; +import java.util.List; + +public abstract class AbstractSetupConfirmActivity extends K9Activity implements View.OnClickListener, OnItemSelectedListener { + + 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; + + // references to current selections ( easier to code with ) + Server mCurrentServer; + ServerType mCurrentType; + SocketType mCurrentSocket; + + // gui elements + Spinner mProtocolSpinner; + Spinner mSocketTypeSpinner; + TextView mServerInfoText; + + // difference between incomming & outgoing + protected abstract List getServers(); + protected abstract List getAvailableServerTypes(); + protected abstract void finishAction(); + + @Override + public void onCreate(Bundle savedInstance){ + super.onCreate(savedInstance); + setContentView(R.layout.account_setup_confirm); + + // initialise gui elements from inflated layout + mSocketTypeSpinner = (Spinner) findViewById(R.id.spinner_sockettype); + mProtocolSpinner = (Spinner) findViewById(R.id.spinner_protocol); + mServerInfoText = (TextView) findViewById(R.id.server_information); + + // 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 + ArrayAdapter protocolAdapter = new ArrayAdapter(this, + R.layout.account_setup_confirm_spinners_item, getAvailableServerTypes()); + mProtocolSpinner.setAdapter(protocolAdapter); + + List matchingSocketTypeList = mConfigInfo.getAvailableSocketTypes( + mConfigInfo.getFilteredServerList(getServers(),protocolAdapter.getItem(0), null, null)); + ArrayAdapter socketTypeAdapter = new ArrayAdapter(this, + R.layout.account_setup_confirm_spinners_item, matchingSocketTypeList); + mSocketTypeSpinner.setAdapter(socketTypeAdapter); + + // attach the listeners + mProtocolSpinner.setOnItemSelectedListener(this); + mSocketTypeSpinner.setOnItemSelectedListener(this); + } + + @Override + public void onClick(View view) { + //To change body of implemented methods use File | Settings | File Templates. + } + + @Override + public void onItemSelected(AdapterView parent, View view, int pos, long id) { + switch( parent.getId() ){ + case R.id.spinner_protocol: + mCurrentType = (ServerType) mProtocolSpinner.getAdapter().getItem(pos); + // now we have to reset the options in sockettype spinner + List newTypes = mConfigInfo.getAvailableSocketTypes( + mConfigInfo.getFilteredServerList(getServers(),(ServerType) mProtocolSpinner.getAdapter().getItem(pos), null, null)); + mSocketTypeSpinner.setAdapter(new ArrayAdapter(this, R.layout.account_setup_confirm_spinners_item, newTypes)); + mSocketTypeSpinner.invalidate(); + break; + case R.id.spinner_sockettype: + // this is called on setup too so it initialises the view too + mCurrentSocket = (SocketType) mSocketTypeSpinner.getAdapter().getItem(pos); + mCurrentServer = mConfigInfo.getFilteredServerList(getServers(),mCurrentType, null, mCurrentSocket).get(0); + setServerInfo(mCurrentServer); + break; + } + } + + private void setServerInfo(Server mCurrentServer) { + // TODO: string resources + mServerInfoText.setText("Host: "+mCurrentServer.hostname+"\n"+ + "Port: "+mCurrentServer.port+"\n"+ + "Authentication: "+mCurrentServer.authentication); + } + + @Override + public void onNothingSelected(AdapterView adapterView) {} +} diff --git a/src/com/fsck/k9/activity/setup/AccountSetupConfirmIncoming.java b/src/com/fsck/k9/activity/setup/AccountSetupConfirmIncoming.java index 16f8fec07..7696292a6 100644 --- a/src/com/fsck/k9/activity/setup/AccountSetupConfirmIncoming.java +++ b/src/com/fsck/k9/activity/setup/AccountSetupConfirmIncoming.java @@ -6,113 +6,23 @@ package com.fsck.k9.activity.setup; the final settings. */ -import android.content.Context; -import android.content.Intent; -import android.os.Bundle; -import android.view.View; -import android.widget.AdapterView; -import android.widget.AdapterView.OnItemSelectedListener; -import android.widget.ArrayAdapter; -import android.widget.Spinner; -import android.widget.Toast; -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; -import com.fsck.k9.helper.configxmlparser.AutoconfigInfo.SocketType; import java.util.List; -public class AccountSetupConfirmIncoming extends K9Activity implements View.OnClickListener, OnItemSelectedListener { - - 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 mSocketTypeSpinner; - +public class AccountSetupConfirmIncoming extends AbstractSetupConfirmActivity{ @Override - public void onCreate(Bundle savedInstance){ - super.onCreate(savedInstance); - setContentView(R.layout.account_setup_confirm); - - // initialise gui elements from inflated layout - mSocketTypeSpinner = (Spinner) findViewById(R.id.spinner_sockettype); - 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 - ArrayAdapter protocolAdapter = new ArrayAdapter(this, - R.layout.account_setup_confirm_spinners_item, mConfigInfo.getAvailableIncomingServerTypes()); - mProtocolSpinner.setAdapter(protocolAdapter); - - List matchingSocketTypeList = mConfigInfo.getAvailableSocketTypes( - mConfigInfo.getIncomingServers(protocolAdapter.getItem(0), null, null)); - ArrayAdapter socketTypeAdapter = new ArrayAdapter(this, - R.layout.account_setup_confirm_spinners_item, matchingSocketTypeList); - mSocketTypeSpinner.setAdapter(socketTypeAdapter); - - // attach the listeners - mProtocolSpinner.setOnItemSelectedListener(this); - mSocketTypeSpinner.setOnItemSelectedListener(this); + protected List getServers() { + return mConfigInfo.incomingServer; } @Override - public void onClick(View view) { - //To change body of implemented methods use File | Settings | File Templates. + protected List getAvailableServerTypes() { + return mConfigInfo.getAvailableIncomingServerTypes(); } @Override - public void onItemSelected(AdapterView parent, View view, int pos, long id) { - switch( parent.getId() ){ - case R.id.spinner_protocol: - // now we have to reset the options in sockettype spinner - List newTypes = mConfigInfo.getAvailableSocketTypes( - mConfigInfo.getIncomingServers((ServerType) mProtocolSpinner.getAdapter().getItem(pos), null, null)); - mSocketTypeSpinner.setAdapter(new ArrayAdapter(this, R.layout.account_setup_confirm_spinners_item, newTypes)); - mSocketTypeSpinner.invalidate(); - break; - case R.id.spinner_sockettype: - - break; - } - } - - @Override - public void onNothingSelected(AdapterView adapterView) { + protected void finishAction() { //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 index 5de2eb71a..65d7ded1c 100644 --- a/src/com/fsck/k9/activity/setup/AccountSetupConfirmOutgoing.java +++ b/src/com/fsck/k9/activity/setup/AccountSetupConfirmOutgoing.java @@ -6,67 +6,23 @@ package com.fsck.k9.activity.setup; 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; +import com.fsck.k9.helper.configxmlparser.AutoconfigInfo.ServerType; +import java.util.List; -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; - +public class AccountSetupConfirmOutgoing extends AbstractSetupConfirmActivity{ @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 - + protected List getServers() { + return mConfigInfo.outgoingServer; } @Override - public void onClick(View view) { + protected List getAvailableServerTypes() { + return mConfigInfo.getAvailableOutgoingServerTypes(); + } + + @Override + protected void finishAction() { //To change body of implemented methods use File | Settings | File Templates. } -} +} \ No newline at end of file diff --git a/src/com/fsck/k9/helper/configxmlparser/AutoconfigInfo.java b/src/com/fsck/k9/helper/configxmlparser/AutoconfigInfo.java index 565dcff04..00f62571e 100644 --- a/src/com/fsck/k9/helper/configxmlparser/AutoconfigInfo.java +++ b/src/com/fsck/k9/helper/configxmlparser/AutoconfigInfo.java @@ -466,7 +466,7 @@ public class AutoconfigInfo implements Parcelable { } // filters the list of servers according to the arguments ( list of allowed specifications ) - private List getFilteredServerList + public List getFilteredServerList (List serverList, ServerType serverType, AuthenticationType authenticationType, SocketType socketType) { ArrayList servers = new ArrayList();