2008-11-01 17:32:06 -04:00
|
|
|
|
2008-12-16 18:34:01 -05:00
|
|
|
package com.android.email.activity.setup;
|
2008-11-01 17:32:06 -04:00
|
|
|
|
|
|
|
import android.app.Activity;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.text.Editable;
|
|
|
|
import android.text.TextWatcher;
|
|
|
|
import android.text.method.TextKeyListener;
|
|
|
|
import android.text.method.TextKeyListener.Capitalize;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.View.OnClickListener;
|
|
|
|
import android.widget.Button;
|
|
|
|
import android.widget.EditText;
|
|
|
|
|
2008-12-16 18:34:01 -05:00
|
|
|
import com.android.email.Account;
|
|
|
|
import com.android.email.Email;
|
|
|
|
import com.android.email.Preferences;
|
|
|
|
import com.android.email.R;
|
|
|
|
import com.android.email.Utility;
|
|
|
|
import com.android.email.activity.FolderMessageList;
|
2008-11-01 17:32:06 -04:00
|
|
|
|
|
|
|
public class AccountSetupNames extends Activity implements OnClickListener {
|
|
|
|
private static final String EXTRA_ACCOUNT = "account";
|
|
|
|
|
|
|
|
private EditText mDescription;
|
|
|
|
|
|
|
|
private EditText mName;
|
|
|
|
|
|
|
|
private Account mAccount;
|
|
|
|
|
|
|
|
private Button mDoneButton;
|
|
|
|
|
|
|
|
public static void actionSetNames(Context context, Account account) {
|
|
|
|
Intent i = new Intent(context, AccountSetupNames.class);
|
|
|
|
i.putExtra(EXTRA_ACCOUNT, account);
|
|
|
|
context.startActivity(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
setContentView(R.layout.account_setup_names);
|
|
|
|
mDescription = (EditText)findViewById(R.id.account_description);
|
|
|
|
mName = (EditText)findViewById(R.id.account_name);
|
|
|
|
mDoneButton = (Button)findViewById(R.id.done);
|
|
|
|
mDoneButton.setOnClickListener(this);
|
|
|
|
|
|
|
|
TextWatcher validationTextWatcher = new TextWatcher() {
|
|
|
|
public void afterTextChanged(Editable s) {
|
|
|
|
validateFields();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
|
|
|
}
|
|
|
|
};
|
|
|
|
mName.addTextChangedListener(validationTextWatcher);
|
|
|
|
|
|
|
|
mName.setKeyListener(TextKeyListener.getInstance(false, Capitalize.WORDS));
|
|
|
|
|
|
|
|
mAccount = (Account)getIntent().getSerializableExtra(EXTRA_ACCOUNT);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Since this field is considered optional, we don't set this here. If
|
|
|
|
* the user fills in a value we'll reset the current value, otherwise we
|
|
|
|
* just leave the saved value alone.
|
|
|
|
*/
|
|
|
|
// mDescription.setText(mAccount.getDescription());
|
|
|
|
if (mAccount.getName() != null) {
|
|
|
|
mName.setText(mAccount.getName());
|
|
|
|
}
|
|
|
|
if (!Utility.requiredFieldValid(mName)) {
|
|
|
|
mDoneButton.setEnabled(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void validateFields() {
|
|
|
|
mDoneButton.setEnabled(Utility.requiredFieldValid(mName));
|
|
|
|
Utility.setCompoundDrawablesAlpha(mDoneButton, mDoneButton.isEnabled() ? 255 : 128);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void onNext() {
|
|
|
|
if (Utility.requiredFieldValid(mDescription)) {
|
|
|
|
mAccount.setDescription(mDescription.getText().toString());
|
|
|
|
}
|
|
|
|
mAccount.setName(mName.getText().toString());
|
|
|
|
mAccount.save(Preferences.getPreferences(this));
|
2008-12-16 18:34:01 -05:00
|
|
|
FolderMessageList.actionHandleAccount(this, mAccount, Email.INBOX);
|
2008-11-01 17:32:06 -04:00
|
|
|
finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
switch (v.getId()) {
|
|
|
|
case R.id.done:
|
|
|
|
onNext();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|