2009-12-14 21:50:53 -05:00
|
|
|
package com.fsck.k9.activity.setup;
|
2009-12-09 22:16:42 -05:00
|
|
|
|
2008-11-01 17:32:06 -04:00
|
|
|
import android.app.Activity;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.view.KeyEvent;
|
|
|
|
import android.widget.EditText;
|
2009-05-17 02:02:02 -04:00
|
|
|
import android.widget.RadioButton;
|
2009-12-14 21:50:53 -05:00
|
|
|
import com.fsck.k9.Account;
|
|
|
|
import com.fsck.k9.K9Activity;
|
|
|
|
import com.fsck.k9.Preferences;
|
|
|
|
import com.fsck.k9.R;
|
2008-11-01 17:32:06 -04:00
|
|
|
|
2009-11-24 19:40:29 -05:00
|
|
|
public class AccountSetupComposition extends K9Activity
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
|
|
|
|
private static final String EXTRA_ACCOUNT = "account";
|
|
|
|
|
|
|
|
private Account mAccount;
|
|
|
|
|
|
|
|
private EditText mAccountSignature;
|
|
|
|
private EditText mAccountEmail;
|
|
|
|
private EditText mAccountAlwaysBcc;
|
|
|
|
private EditText mAccountName;
|
2009-05-17 02:02:02 -04:00
|
|
|
private RadioButton mAccountSignatureBeforeLocation;
|
|
|
|
private RadioButton mAccountSignatureAfterLocation;
|
2009-11-21 17:45:39 -05:00
|
|
|
|
2008-11-01 17:32:06 -04:00
|
|
|
|
2009-11-24 19:40:29 -05:00
|
|
|
public static void actionEditCompositionSettings(Activity context, Account account)
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
Intent i = new Intent(context, AccountSetupComposition.class);
|
|
|
|
i.setAction(Intent.ACTION_EDIT);
|
|
|
|
i.putExtra(EXTRA_ACCOUNT, account);
|
|
|
|
context.startActivity(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
2009-11-24 19:40:29 -05:00
|
|
|
public void onCreate(Bundle savedInstanceState)
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
|
|
|
mAccount = (Account)getIntent().getSerializableExtra(EXTRA_ACCOUNT);
|
|
|
|
|
|
|
|
setContentView(R.layout.account_setup_composition);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we're being reloaded we override the original account with the one
|
|
|
|
* we saved
|
|
|
|
*/
|
2009-11-24 19:40:29 -05:00
|
|
|
if (savedInstanceState != null && savedInstanceState.containsKey(EXTRA_ACCOUNT))
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
mAccount = (Account)savedInstanceState.getSerializable(EXTRA_ACCOUNT);
|
|
|
|
}
|
|
|
|
|
|
|
|
mAccountName = (EditText)findViewById(R.id.account_name);
|
|
|
|
mAccountName.setText(mAccount.getName());
|
2009-11-21 17:45:39 -05:00
|
|
|
|
2008-11-01 17:32:06 -04:00
|
|
|
mAccountEmail = (EditText)findViewById(R.id.account_email);
|
|
|
|
mAccountEmail.setText(mAccount.getEmail());
|
|
|
|
|
|
|
|
mAccountAlwaysBcc = (EditText)findViewById(R.id.account_always_bcc);
|
|
|
|
mAccountAlwaysBcc.setText(mAccount.getAlwaysBcc());
|
|
|
|
|
|
|
|
mAccountSignature = (EditText)findViewById(R.id.account_signature);
|
|
|
|
mAccountSignature.setText(mAccount.getSignature());
|
2009-05-17 02:02:02 -04:00
|
|
|
|
|
|
|
mAccountSignatureBeforeLocation = (RadioButton)findViewById(R.id.account_signature_location_before_quoted_text);
|
|
|
|
mAccountSignatureAfterLocation = (RadioButton)findViewById(R.id.account_signature_location_after_quoted_text);
|
|
|
|
boolean isSignatureBeforeQuotedText = mAccount.isSignatureBeforeQuotedText();
|
|
|
|
mAccountSignatureBeforeLocation.setChecked(isSignatureBeforeQuotedText);
|
|
|
|
mAccountSignatureAfterLocation.setChecked(!isSignatureBeforeQuotedText);
|
2008-11-01 17:32:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2009-11-24 19:40:29 -05:00
|
|
|
public void onResume()
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
super.onResume();
|
|
|
|
mAccount.refresh(Preferences.getPreferences(this));
|
|
|
|
}
|
|
|
|
|
2009-11-24 19:40:29 -05:00
|
|
|
private void saveSettings()
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
mAccount.setEmail(mAccountEmail.getText().toString());
|
2009-11-21 17:45:39 -05:00
|
|
|
mAccount.setAlwaysBcc(mAccountAlwaysBcc.getText().toString());
|
2008-11-01 17:32:06 -04:00
|
|
|
mAccount.setName(mAccountName.getText().toString());
|
2009-05-17 02:02:02 -04:00
|
|
|
mAccount.setSignature(mAccountSignature.getText().toString());
|
|
|
|
boolean isSignatureBeforeQuotedText = mAccountSignatureBeforeLocation.isChecked();
|
|
|
|
mAccount.setSignatureBeforeQuotedText(isSignatureBeforeQuotedText);
|
2008-11-01 17:32:06 -04:00
|
|
|
|
|
|
|
mAccount.save(Preferences.getPreferences(this));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2009-11-24 19:40:29 -05:00
|
|
|
public boolean onKeyDown(int keyCode, KeyEvent event)
|
|
|
|
{
|
|
|
|
if (keyCode == KeyEvent.KEYCODE_BACK)
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
saveSettings();
|
|
|
|
}
|
|
|
|
return super.onKeyDown(keyCode, event);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2009-11-24 19:40:29 -05:00
|
|
|
public void onSaveInstanceState(Bundle outState)
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
super.onSaveInstanceState(outState);
|
|
|
|
outState.putSerializable(EXTRA_ACCOUNT, mAccount);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2009-11-24 19:40:29 -05:00
|
|
|
public void onActivityResult(int requestCode, int resultCode, Intent data)
|
|
|
|
{
|
2009-11-21 17:45:39 -05:00
|
|
|
mAccount.save(Preferences.getPreferences(this));
|
|
|
|
finish();
|
2008-11-01 17:32:06 -04:00
|
|
|
}
|
|
|
|
}
|