Email代码结构
源码地址http://download.csdn.net/detail/wds1181977/5623927
入口处为com.android.email.activity.Welcome
初始化操作,判断是否有账户信息,如果没有账户信息跳转入登录界面AccountSetupBasics,如果已登录则去主界面EmailActivity
private void resolveAccount() {
final int numAccount = EmailContent.count(this, Account.CONTENT_URI);
if (numAccount == 0) {
AccountSetupBasics.actionNewAccount(this);
finish();
return;
} else {
mAccountId = resolveAccountId(this, mAccountId, mAccountUuid);
if (Account.isNormalAccount(mAccountId) &&
Mailbox.findMailboxOfType(this, mAccountId, Mailbox.TYPE_INBOX)
== Mailbox.NO_MAILBOX) {
startInboxLookup();
return;
}
}
startEmailActivity();
}
邮箱账户类型分为POP3 IMAP.Exchange这几种类型,登录邮箱需要配置接受设置和外发设置,下面是源码中的各个国家邮箱的接受设置和外发设置,当你点击下一步后会解析R.xml.providers.xml,如果你输入的账户能匹配到,就不需要手动配置邮箱,自动会导入配置(当你想新增邮箱你可以把配置加到这里就可以了)
当你输了了账户密码点击下一步,
代码根据你输入类型查找xml匹配
/**
* When "next" button is clicked
*/
private void onNext() {
// Try auto-configuration from XML providers (unless in EAS mode, we can skip it)
if (SetupData.getFlowMode() != SetupData.FLOW_MODE_ACCOUNT_MANAGER_EAS) {
String email = mEmailView.getText().toString().trim();
String[] emailParts = email.split("@");
String domain = emailParts[1].trim();
mProvider = AccountSettingsUtils.findProviderForDomain(this, domain);
if (mProvider != null) {
if (mProvider.note != null) {
NoteDialogFragment dialogFragment =
NoteDialogFragment.newInstance(mProvider.note);
dialogFragment.show(getFragmentManager(), NoteDialogFragment.TAG);
} else {
finishAutoSetup();
}
return;
}
}
// Can't use auto setup (although EAS accounts may still be able to AutoDiscover)
onManualSetup(true);
}
/*package*/ static Provider findProviderForDomain(
Context context, String domain, int resourceId) {
try {
XmlResourceParser xml = context.getResources().getXml(resourceId);
int xmlEventType;
Provider provider = null;
while ((xmlEventType = xml.next()) != XmlResourceParser.END_DOCUMENT) {
if (xmlEventType == XmlResourceParser.START_TAG
&& "provider".equals(xml.getName())) {
String providerDomain = getXmlAttribute(context, xml, "domain");
try {
if (matchProvider(domain, providerDomain)) {
provider = new Provider();
provider.id = getXmlAttribute(context, xml, "id");
provider.label = getXmlAttribute(context, xml, "label");
provider.domain = domain.toLowerCase();
provider.note = getXmlAttribute(context, xml, "note");
}
} catch (IllegalArgumentException e) {
Log.w(Logging.LOG_TAG, "providers line: " + xml.getLineNumber() +
"; Domain contains multiple globals");
}
}
else if (xmlEventType == XmlResourceParser.START_TAG
&& "incoming".equals(xml.getName())
&& provider != null) {
provider.incomingUriTemplate = getXmlAttribute(context, xml, "uri");
provider.incomingUsernameTemplate = getXmlAttribute(context, xml, "username");
}
else if (xmlEventType == XmlResourceParser.START_TAG
&& "outgoing".equals(xml.getName())
&& provider != null) {
provider.outgoingUriTemplate = getXmlAttribute(context, xml, "uri");
provider.outgoingUsernameTemplate = getXmlAttribute(context, xml, "username");
}
else if (xmlEventType == XmlResourceParser.END_TAG
&& "provider".equals(xml.getName())
&& provider != null) {
return provider;
}
}
}
catch (Exception e) {
Log.e(Logging.LOG_TAG, "Error while trying to load provider settings.", e);
}
return null;
}