am eadb55b0: Implement hooks from Settings->Accounts to Exchange account setu

Merge commit 'eadb55b04eae126fdef442bae6d72c804df735d0' into eclair-plus-aosp

* commit 'eadb55b04eae126fdef442bae6d72c804df735d0':
  Implement hooks from Settings->Accounts to Exchange account setu
This commit is contained in:
Marc Blank 2009-09-18 10:33:05 -07:00 committed by Android Git Automerger
commit 83954a28fe
5 changed files with 99 additions and 23 deletions

View File

@ -453,6 +453,8 @@
<string name="account_settings_default_summary">Send email from this account by default</string>
<!-- On Settings screen, setting option name -->
<string name="account_settings_notify_label">Email notifications</string>
<!-- On Settings screen, summary line when called via AccountManager for Exchange accounts -->
<string name="account_settings_exchange_summary">Sync frequency, notifications, etc.</string>
<!-- On Settings screen, setting summary text -->
<string name="account_settings_notify_summary">Notify in status bar when email arrives</string>
<!-- On Settings screen, setting option name and title of dialog box that opens -->

View File

@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2009 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!-- NOTE: The string in android:action must match the one in AccountSettings.java -->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory
android:title="@string/account_settings_title_fmt" />
<PreferenceScreen
android:key="account_settings"
android:title="@string/account_settings_action"
android:summary="@string/account_settings_exchange_summary">
<intent
android:action="com.android.email.activity.setup.ACCOUNT_MANAGER_ENTRY"
android:targetPackage="com.android.email"
android:targetClass="com.android.email.activity.setup.AccountSettings" />
</PreferenceScreen>
</PreferenceScreen>

View File

@ -95,11 +95,6 @@
android:defaultValue="true"
android:title="@string/account_settings_sync_contacts_enable"
android:summary="@string/account_settings_sync_contacts_summary" />
<PreferenceScreen
android:key="add_account"
android:title="@string/account_settings_add_account_label" />
</PreferenceCategory>
</PreferenceScreen>

View File

@ -24,4 +24,5 @@
android:accountType="com.android.exchange"
android:icon="@drawable/ic_exchange_accounts"
android:label="@string/exchange_name"
android:accountPreferences="@xml/account_preferences"
/>

View File

@ -22,13 +22,16 @@ import com.android.email.mail.MessagingException;
import com.android.email.mail.Sender;
import com.android.email.mail.Store;
import com.android.email.provider.EmailContent.Account;
import com.android.email.provider.EmailContent.AccountColumns;
import com.android.email.provider.EmailContent.HostAuth;
import com.android.email.provider.EmailContent.HostAuthColumns;
import com.android.exchange.Eas;
import android.app.Activity;
import android.content.ContentResolver;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.EditTextPreference;
@ -42,8 +45,6 @@ import android.util.Log;
import android.view.KeyEvent;
public class AccountSettings extends PreferenceActivity {
private static final String EXTRA_ACCOUNT_ID = "account_id";
private static final String PREFERENCE_TOP_CATEGORY = "account_settings";
private static final String PREFERENCE_DESCRIPTION = "account_description";
private static final String PREFERENCE_NAME = "account_name";
@ -55,10 +56,17 @@ public class AccountSettings extends PreferenceActivity {
private static final String PREFERENCE_SERVER_CATERGORY = "account_servers";
private static final String PREFERENCE_INCOMING = "incoming";
private static final String PREFERENCE_OUTGOING = "outgoing";
private static final String PREFERENCE_ADD_ACCOUNT = "add_account";
private static final String PREFERENCE_SYNC_CONTACTS = "account_sync_contacts";
private long mAccountId;
// NOTE: This string must match the one in res/xml/account_preferences.xml
public static final String ACTION_ACCOUNT_MANAGER_ENTRY =
"com.android.email.activity.setup.ACCOUNT_MANAGER_ENTRY";
// NOTE: This constant should eventually be defined in android.accounts.Constants, but for
// now we define it here
private static final String ACCOUNT_MANAGER_EXTRA_ACCOUNT = "account";
private static final String EXTRA_ACCOUNT_ID = "account_id";
private long mAccountId = -1;
private Account mAccount;
private boolean mAccountDirty;
@ -86,14 +94,29 @@ public class AccountSettings extends PreferenceActivity {
super.onCreate(savedInstanceState);
Intent i = getIntent();
mAccountId = i.getLongExtra(EXTRA_ACCOUNT_ID, -1);
if (i.getAction().equals(ACTION_ACCOUNT_MANAGER_ENTRY)) {
// This case occurs if we're changing account settings from Settings -> Accounts
setAccountIdFromAccountManagerIntent();
} else {
// Otherwise, we're called from within the Email app and look for our extra
mAccountId = i.getLongExtra(EXTRA_ACCOUNT_ID, -1);
}
// If there's no accountId, we're done
if (mAccountId == -1) {
finish();
return;
}
mAccount = Account.restoreAccountWithId(this, mAccountId);
// Similarly, if the account has been deleted
if (mAccount == null) {
finish();
return;
}
mAccount.mHostAuthRecv = HostAuth.restoreHostAuthWithId(this, mAccount.mHostAuthKeyRecv);
mAccount.mHostAuthSend = HostAuth.restoreHostAuthWithId(this, mAccount.mHostAuthKeySend);
// Or if HostAuth's have been deleted
if (mAccount.mHostAuthRecv == null || mAccount.mHostAuthSend == null) {
finish();
return;
@ -235,16 +258,42 @@ public class AccountSettings extends PreferenceActivity {
PREFERENCE_SERVER_CATERGORY);
serverCategory.removePreference(mSyncContacts);
}
findPreference(PREFERENCE_ADD_ACCOUNT).setOnPreferenceClickListener(
new Preference.OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
onAddNewAccount();
return true;
}
});
}
private void setAccountIdFromAccountManagerIntent() {
// First, get the AccountManager account that we've been ask to handle
android.accounts.Account acct =
(android.accounts.Account)getIntent()
.getParcelableExtra(ACCOUNT_MANAGER_EXTRA_ACCOUNT);
// Find a HostAuth using eas and whose login is the name of the AccountManager account
Cursor c = getContentResolver().query(HostAuth.CONTENT_URI,
new String[] {HostAuthColumns.ID}, HostAuth.LOGIN + "=? AND "
+ HostAuthColumns.PROTOCOL + "=?",
new String[] {acct.name, "eas"}, null);
try {
if (c.moveToFirst()) {
// This gives us the HostAuth's id
String hostAuthId = c.getString(0);
// Now, find the EmailProvider Account for this HostAuth
Cursor ac = getContentResolver().query(Account.CONTENT_URI,
new String[] {AccountColumns.ID},
AccountColumns.HOST_AUTH_KEY_RECV + "=? OR "
+ AccountColumns.HOST_AUTH_KEY_SEND + "=?",
new String[] {hostAuthId, hostAuthId}, null);
try {
// And if we find one, set mAccountId accordingly
if (ac.moveToFirst()) {
mAccountId = ac.getLong(0);
}
} finally {
ac.close();
}
}
} finally {
c.close();
}
}
@Override
public void onResume() {
super.onResume();
@ -339,9 +388,4 @@ public class AccountSettings extends PreferenceActivity {
Log.d(Email.LOG_TAG, "Error while trying to invoke sender settings.", e);
}
}
private void onAddNewAccount() {
AccountSetupBasics.actionNewAccount(this);
finish();
}
}