2008-11-01 17:32:06 -04:00
|
|
|
|
|
|
|
package com.fsck.k9.activity.setup;
|
|
|
|
|
|
|
|
import android.app.Activity;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.View.OnClickListener;
|
|
|
|
import android.widget.ArrayAdapter;
|
|
|
|
import android.widget.CheckBox;
|
|
|
|
import android.widget.Spinner;
|
|
|
|
|
|
|
|
import com.fsck.k9.Account;
|
|
|
|
import com.fsck.k9.k9;
|
|
|
|
import com.fsck.k9.Preferences;
|
|
|
|
import com.fsck.k9.R;
|
|
|
|
|
|
|
|
public class AccountSetupOptions extends Activity implements OnClickListener {
|
|
|
|
private static final String EXTRA_ACCOUNT = "account";
|
|
|
|
|
|
|
|
private static final String EXTRA_MAKE_DEFAULT = "makeDefault";
|
|
|
|
|
|
|
|
private Spinner mCheckFrequencyView;
|
|
|
|
|
2008-12-11 00:25:59 -05:00
|
|
|
private Spinner mDisplayCountView;
|
|
|
|
|
2008-11-01 17:32:06 -04:00
|
|
|
private CheckBox mDefaultView;
|
|
|
|
|
|
|
|
private CheckBox mNotifyView;
|
|
|
|
|
|
|
|
private Account mAccount;
|
|
|
|
|
|
|
|
public static void actionOptions(Context context, Account account, boolean makeDefault) {
|
|
|
|
Intent i = new Intent(context, AccountSetupOptions.class);
|
|
|
|
i.putExtra(EXTRA_ACCOUNT, account);
|
|
|
|
i.putExtra(EXTRA_MAKE_DEFAULT, makeDefault);
|
|
|
|
context.startActivity(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
setContentView(R.layout.account_setup_options);
|
|
|
|
|
|
|
|
mCheckFrequencyView = (Spinner)findViewById(R.id.account_check_frequency);
|
2008-12-11 00:25:59 -05:00
|
|
|
mDisplayCountView = (Spinner)findViewById(R.id.account_display_count);
|
2008-11-01 17:32:06 -04:00
|
|
|
mDefaultView = (CheckBox)findViewById(R.id.account_default);
|
|
|
|
mNotifyView = (CheckBox)findViewById(R.id.account_notify);
|
|
|
|
|
|
|
|
findViewById(R.id.next).setOnClickListener(this);
|
|
|
|
|
|
|
|
SpinnerOption checkFrequencies[] = {
|
|
|
|
new SpinnerOption(-1,
|
|
|
|
getString(R.string.account_setup_options_mail_check_frequency_never)),
|
|
|
|
new SpinnerOption(5,
|
|
|
|
getString(R.string.account_setup_options_mail_check_frequency_5min)),
|
|
|
|
new SpinnerOption(10,
|
|
|
|
getString(R.string.account_setup_options_mail_check_frequency_10min)),
|
|
|
|
new SpinnerOption(15,
|
|
|
|
getString(R.string.account_setup_options_mail_check_frequency_15min)),
|
|
|
|
new SpinnerOption(30,
|
|
|
|
getString(R.string.account_setup_options_mail_check_frequency_30min)),
|
|
|
|
new SpinnerOption(60,
|
|
|
|
getString(R.string.account_setup_options_mail_check_frequency_1hour)),
|
|
|
|
};
|
|
|
|
|
|
|
|
ArrayAdapter<SpinnerOption> checkFrequenciesAdapter = new ArrayAdapter<SpinnerOption>(this,
|
|
|
|
android.R.layout.simple_spinner_item, checkFrequencies);
|
|
|
|
checkFrequenciesAdapter
|
|
|
|
.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
|
|
|
mCheckFrequencyView.setAdapter(checkFrequenciesAdapter);
|
|
|
|
|
2008-12-11 00:25:59 -05:00
|
|
|
SpinnerOption displayCounts[] = {
|
|
|
|
new SpinnerOption(10,
|
|
|
|
getString(R.string.account_setup_options_mail_display_count_10)),
|
|
|
|
new SpinnerOption(25,
|
|
|
|
getString(R.string.account_setup_options_mail_display_count_25)),
|
|
|
|
new SpinnerOption(50,
|
|
|
|
getString(R.string.account_setup_options_mail_display_count_50)),
|
|
|
|
new SpinnerOption(100,
|
|
|
|
getString(R.string.account_setup_options_mail_display_count_100)),
|
|
|
|
};
|
|
|
|
|
|
|
|
ArrayAdapter<SpinnerOption> displayCountsAdapter = new ArrayAdapter<SpinnerOption>(this,
|
|
|
|
android.R.layout.simple_spinner_item, displayCounts);
|
|
|
|
displayCountsAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
|
|
|
mDisplayCountView.setAdapter(displayCountsAdapter);
|
|
|
|
|
2008-11-01 17:32:06 -04:00
|
|
|
mAccount = (Account)getIntent().getSerializableExtra(EXTRA_ACCOUNT);
|
|
|
|
boolean makeDefault = getIntent().getBooleanExtra(EXTRA_MAKE_DEFAULT, false);
|
|
|
|
|
|
|
|
if (mAccount.equals(Preferences.getPreferences(this).getDefaultAccount()) || makeDefault) {
|
|
|
|
mDefaultView.setChecked(true);
|
|
|
|
}
|
|
|
|
mNotifyView.setChecked(mAccount.isNotifyNewMail());
|
|
|
|
SpinnerOption.setSpinnerOptionValue(mCheckFrequencyView, mAccount
|
|
|
|
.getAutomaticCheckIntervalMinutes());
|
2008-12-11 00:25:59 -05:00
|
|
|
SpinnerOption.setSpinnerOptionValue(mDisplayCountView, mAccount
|
|
|
|
.getDisplayCount());
|
2008-11-01 17:32:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
private void onDone() {
|
|
|
|
mAccount.setDescription(mAccount.getEmail());
|
|
|
|
mAccount.setNotifyNewMail(mNotifyView.isChecked());
|
|
|
|
mAccount.setAutomaticCheckIntervalMinutes((Integer)((SpinnerOption)mCheckFrequencyView
|
|
|
|
.getSelectedItem()).value);
|
2008-12-11 00:25:59 -05:00
|
|
|
mAccount.setDisplayCount((Integer)((SpinnerOption)mDisplayCountView
|
|
|
|
.getSelectedItem()).value);
|
2008-11-01 17:32:06 -04:00
|
|
|
mAccount.save(Preferences.getPreferences(this));
|
|
|
|
if (mDefaultView.isChecked()) {
|
|
|
|
Preferences.getPreferences(this).setDefaultAccount(mAccount);
|
|
|
|
}
|
|
|
|
k9.setServicesEnabled(this);
|
|
|
|
AccountSetupNames.actionSetNames(this, mAccount);
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
switch (v.getId()) {
|
|
|
|
case R.id.next:
|
|
|
|
onDone();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|