From 3d2a37418f8bd7c14bbf5b32224f107515749b6f Mon Sep 17 00:00:00 2001 From: dzan Date: Fri, 22 Jul 2011 15:46:39 +0200 Subject: [PATCH] Start of confirm activity. Now correctly links the two spinners ( protocol and sockettype ) to allow selecting between multiple configuration options. --- res/layout/account_setup_confirm.xml | 6 +-- .../account_setup_confirm_spinners_item.xml | 8 ++++ .../setup/AccountSetupConfirmIncoming.java | 47 +++++++++++++++---- 3 files changed, 50 insertions(+), 11 deletions(-) create mode 100644 res/layout/account_setup_confirm_spinners_item.xml diff --git a/res/layout/account_setup_confirm.xml b/res/layout/account_setup_confirm.xml index 95623ab5b..cef1b23a1 100644 --- a/res/layout/account_setup_confirm.xml +++ b/res/layout/account_setup_confirm.xml @@ -5,7 +5,7 @@ android:layout_height="fill_parent"> \ No newline at end of file diff --git a/res/layout/account_setup_confirm_spinners_item.xml b/res/layout/account_setup_confirm_spinners_item.xml new file mode 100644 index 000000000..044a25bba --- /dev/null +++ b/res/layout/account_setup_confirm_spinners_item.xml @@ -0,0 +1,8 @@ + + + \ No newline at end of file diff --git a/src/com/fsck/k9/activity/setup/AccountSetupConfirmIncoming.java b/src/com/fsck/k9/activity/setup/AccountSetupConfirmIncoming.java index 1aab3fa91..16f8fec07 100644 --- a/src/com/fsck/k9/activity/setup/AccountSetupConfirmIncoming.java +++ b/src/com/fsck/k9/activity/setup/AccountSetupConfirmIncoming.java @@ -10,16 +10,21 @@ 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 { +public class AccountSetupConfirmIncoming extends K9Activity implements View.OnClickListener, OnItemSelectedListener { private static final String EXTRA_ACCOUNT = "account"; private static final String EXTRA_CONFIG_INFO = "configInfo"; @@ -48,7 +53,7 @@ public class AccountSetupConfirmIncoming extends K9Activity implements View.OnCl // gui elements Spinner mProtocolSpinner; - Spinner mHostnameSpinner; + Spinner mSocketTypeSpinner; @Override public void onCreate(Bundle savedInstance){ @@ -56,7 +61,7 @@ public class AccountSetupConfirmIncoming extends K9Activity implements View.OnCl setContentView(R.layout.account_setup_confirm); // initialise gui elements from inflated layout - mHostnameSpinner = (Spinner) findViewById(R.id.spinner_hostname); + mSocketTypeSpinner = (Spinner) findViewById(R.id.spinner_sockettype); mProtocolSpinner = (Spinner) findViewById(R.id.spinner_protocol); // get the data out of our intent @@ -70,13 +75,19 @@ public class AccountSetupConfirmIncoming extends K9Activity implements View.OnCl 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); + 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); } @Override @@ -84,4 +95,24 @@ public class AccountSetupConfirmIncoming extends K9Activity implements View.OnCl //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: + // 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) { + //To change body of implemented methods use File | Settings | File Templates. + } }