Skip to content

Commit

Permalink
Added email signature to email account
Browse files Browse the repository at this point in the history
  • Loading branch information
jarrettv committed Apr 14, 2010
1 parent 939d28f commit 8ce3f85
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 3 deletions.
2 changes: 2 additions & 0 deletions res/values/strings.xml
Expand Up @@ -517,6 +517,8 @@
<!-- On Settings screen, setting option name -->
<string name="account_settings_description_label">Account name</string>
<!-- On Settings screen, setting option name -->
<string name="account_settings_signature_label">Signature</string>
<!-- On Settings screen, setting option name -->
<string name="account_settings_name_label">Your name</string>
<!-- On Settings screen, section heading -->
<string name="account_settings_notifications">Notification settings</string>
Expand Down
6 changes: 6 additions & 0 deletions res/xml/account_settings_preferences.xml
Expand Up @@ -49,6 +49,12 @@
android:title="@string/account_settings_default_label"
android:summary="@string/account_settings_default_summary" />

<EditTextPreference
android:order="1"

This comment has been minimized.

Copy link
@jarrettv

jarrettv Apr 14, 2010

Author Owner

order should be different otherwise it is at the top

android:key="account_signature"
android:title="@string/account_settings_signature_label"
android:summary=""
android:dialogTitle="@string/account_settings_signature_label" />
</PreferenceCategory>

<PreferenceCategory android:title="@string/account_settings_notifications">
Expand Down
12 changes: 12 additions & 0 deletions src/com/android/email/Account.java
Expand Up @@ -61,6 +61,7 @@ public class Account {
String mDescription;
String mName;
String mEmail;
String mSignature;
int mAutomaticCheckIntervalMinutes;
long mLastAutomaticCheckTime;
boolean mNotifyNewMail;
Expand Down Expand Up @@ -131,6 +132,7 @@ public void refresh(Preferences preferences) {
mDescription = preferences.mSharedPreferences.getString(mUuid + ".description", null);
mName = preferences.mSharedPreferences.getString(mUuid + ".name", mName);
mEmail = preferences.mSharedPreferences.getString(mUuid + ".email", mEmail);
mSignature = preferences.mSharedPreferences.getString(mUuid + ".signature", mSignature);
mAutomaticCheckIntervalMinutes = preferences.mSharedPreferences.getInt(mUuid
+ ".automaticCheckIntervalMinutes", -1);
mLastAutomaticCheckTime = preferences.mSharedPreferences.getLong(mUuid
Expand Down Expand Up @@ -211,6 +213,14 @@ public void setEmail(String email) {
this.mEmail = email;
}

public String getSignature() {
return mSignature;
}

public void setSignature(String signature) {
this.mSignature = signature;
}

public boolean isVibrate() {
return mVibrate;
}
Expand Down Expand Up @@ -248,6 +258,7 @@ public void delete(Preferences preferences) {
editor.remove(mUuid + ".description");
editor.remove(mUuid + ".name");
editor.remove(mUuid + ".email");
editor.remove(mUuid + ".signature");
editor.remove(mUuid + ".automaticCheckIntervalMinutes");
editor.remove(mUuid + ".lastAutomaticCheckTime");
editor.remove(mUuid + ".notifyNewMail");
Expand Down Expand Up @@ -313,6 +324,7 @@ public void save(Preferences preferences) {
editor.putString(mUuid + ".description", mDescription);
editor.putString(mUuid + ".name", mName);
editor.putString(mUuid + ".email", mEmail);
editor.putString(mUuid + ".signature", mSignature);
editor.putInt(mUuid + ".automaticCheckIntervalMinutes", mAutomaticCheckIntervalMinutes);
editor.putLong(mUuid + ".lastAutomaticCheckTime", mLastAutomaticCheckTime);
editor.putBoolean(mUuid + ".notifyNewMail", mNotifyNewMail);
Expand Down
6 changes: 6 additions & 0 deletions src/com/android/email/activity/MessageCompose.java
Expand Up @@ -321,6 +321,12 @@ public void onCreate(Bundle savedInstanceState) {
// But we DO need to set mMessageLoaded to indicate the message can be sent
mMessageLoaded = true;
mSourceMessageProcessed = true;

// Add the signature to the new message
final String sig = mAccount.getSignature();
if (sig != null && sig.length() > 0) {
mMessageContentView.setText("\n\n" + sig);
}
}
}

Expand Down
17 changes: 16 additions & 1 deletion src/com/android/email/activity/setup/AccountSettings.java
Expand Up @@ -47,6 +47,7 @@ public class AccountSettings extends PreferenceActivity {
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";
private static final String PREFERENCE_SIGNATURE = "account_signature";
private static final String PREFERENCE_FREQUENCY = "account_check_frequency";
private static final String PREFERENCE_DEFAULT = "account_default";
private static final String PREFERENCE_NOTIFY = "account_notify";
Expand Down Expand Up @@ -74,6 +75,7 @@ public class AccountSettings extends PreferenceActivity {
private ListPreference mCheckFrequency;
private ListPreference mSyncWindow;
private CheckBoxPreference mAccountDefault;
private EditTextPreference mSignature;
private CheckBoxPreference mAccountNotify;
private CheckBoxPreference mAccountVibrate;
private RingtonePreference mAccountRingtone;
Expand Down Expand Up @@ -196,7 +198,19 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {

mAccountDefault = (CheckBoxPreference) findPreference(PREFERENCE_DEFAULT);
mAccountDefault.setChecked(mAccount.mId == Account.getDefaultAccountId(this));


mSignature = (EditTextPreference) findPreference(PREFERENCE_SIGNATURE);
mSignature.setSummary(mAccount.getSignature());
mSignature.setText(mAccount.getSignature());
mSignature.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
final String summary = newValue.toString();
mSignature.setSummary(summary);
mSignature.setText(summary);
return false;
}
});

mAccountNotify = (CheckBoxPreference) findPreference(PREFERENCE_NOTIFY);
mAccountNotify.setChecked(0 != (mAccount.getFlags() & Account.FLAGS_NOTIFY_NEW_MAIL));

Expand Down Expand Up @@ -307,6 +321,7 @@ private void saveSettings() {
mAccount.setDefaultAccount(mAccountDefault.isChecked());
mAccount.setDisplayName(mAccountDescription.getText());
mAccount.setSenderName(mAccountName.getText());
mAccount.setSignature(mSignature.getText());
newFlags |= mAccountNotify.isChecked() ? Account.FLAGS_NOTIFY_NEW_MAIL : 0;
mAccount.setSyncInterval(Integer.parseInt(mCheckFrequency.getValue()));
if (mSyncWindow != null) {
Expand Down
Expand Up @@ -44,6 +44,7 @@ public static void commitSettings(Context context, EmailContent.Account account)
cv.put(AccountColumns.RINGTONE_URI, account.mRingtoneUri);
cv.put(AccountColumns.FLAGS, account.mFlags);
cv.put(AccountColumns.SYNC_LOOKBACK, account.mSyncLookback);
cv.put(AccountColumns.SIGNATURE, account.mSignature);
account.update(context, cv);
}
// Update the backup (side copy) of the accounts
Expand Down
27 changes: 26 additions & 1 deletion src/com/android/email/provider/EmailContent.java
Expand Up @@ -766,6 +766,8 @@ public interface AccountColumns {
public static final String PROTOCOL_VERSION = "protocolVersion";
// The number of new messages (reported by the sync/download engines
public static final String NEW_MESSAGE_COUNT = "newMessageCount";
// The signature to append to each email
public static final String SIGNATURE = "signature";
}

public static final class Account extends EmailContent implements AccountColumns, Parcelable {
Expand Down Expand Up @@ -803,6 +805,7 @@ public static final class Account extends EmailContent implements AccountColumns
public String mRingtoneUri;
public String mProtocolVersion;
public int mNewMessageCount;
public String mSignature;

// Convenience for creating an account
public transient HostAuth mHostAuthRecv;
Expand All @@ -823,6 +826,7 @@ public static final class Account extends EmailContent implements AccountColumns
public static final int CONTENT_RINGTONE_URI_COLUMN = 12;
public static final int CONTENT_PROTOCOL_VERSION_COLUMN = 13;
public static final int CONTENT_NEW_MESSAGE_COUNT_COLUMN = 14;
public static final int CONTENT_SIGNATURE_COLUMN = 15;

public static final String[] CONTENT_PROJECTION = new String[] {
RECORD_ID, AccountColumns.DISPLAY_NAME,
Expand All @@ -831,7 +835,7 @@ public static final class Account extends EmailContent implements AccountColumns
AccountColumns.HOST_AUTH_KEY_SEND, AccountColumns.FLAGS, AccountColumns.IS_DEFAULT,
AccountColumns.COMPATIBILITY_UUID, AccountColumns.SENDER_NAME,
AccountColumns.RINGTONE_URI, AccountColumns.PROTOCOL_VERSION,
AccountColumns.NEW_MESSAGE_COUNT
AccountColumns.NEW_MESSAGE_COUNT, AccountColumns.SIGNATURE
};

public static final int CONTENT_MAILBOX_TYPE_COLUMN = 1;
Expand Down Expand Up @@ -922,6 +926,8 @@ public EmailContent.Account restore(Cursor cursor) {
mRingtoneUri = cursor.getString(CONTENT_RINGTONE_URI_COLUMN);
mProtocolVersion = cursor.getString(CONTENT_PROTOCOL_VERSION_COLUMN);
mNewMessageCount = cursor.getInt(CONTENT_NEW_MESSAGE_COUNT_COLUMN);
if (cursor.getColumnCount() > CONTENT_SIGNATURE_COLUMN)
mSignature = cursor.getString(CONTENT_SIGNATURE_COLUMN);
return this;
}

Expand Down Expand Up @@ -959,6 +965,20 @@ public void setEmailAddress(String emailAddress) {
mEmailAddress = emailAddress;
}

/**
* @return the signature for this account
*/
public String getSignature() {
return mSignature;
}

/**
* Set the signature for this account. Be sure to call save() to commit to database.
* @param signature the signature for this account
*/
public void setSignature(String signature) {
mSignature = signature;
}
/**
* @return the sender's name for this account
*/
Expand Down Expand Up @@ -1341,6 +1361,7 @@ public ContentValues toContentValues() {
values.put(AccountColumns.RINGTONE_URI, mRingtoneUri);
values.put(AccountColumns.PROTOCOL_VERSION, mProtocolVersion);
values.put(AccountColumns.NEW_MESSAGE_COUNT, mNewMessageCount);
values.put(AccountColumns.SIGNATURE, mSignature);
return values;
}

Expand Down Expand Up @@ -1399,6 +1420,8 @@ public void writeToParcel(Parcel dest, int flags) {
} else {
dest.writeByte((byte)0);
}

dest.writeString(mSignature);
}

/**
Expand Down Expand Up @@ -1431,6 +1454,8 @@ public Account(Parcel in) {
if (in.readByte() == 1) {
mHostAuthSend = new EmailContent.HostAuth(in);
}

mSignature = in.readString();
}

/**
Expand Down
14 changes: 13 additions & 1 deletion src/com/android/email/provider/EmailProvider.java
Expand Up @@ -62,7 +62,8 @@ public class EmailProvider extends ContentProvider {
// Version 4: Database wipe required; changing AccountManager interface w/Exchange
// Version 5: Database wipe required; changing AccountManager interface w/Exchange
// Version 6: Adding Message.mServerTimeStamp column
public static final int DATABASE_VERSION = 6;
// Version 7: Adding Account.mSignature column
public static final int DATABASE_VERSION = 7;

// Any changes to the database format *must* include update-in-place code.
// Original version: 2
Expand Down Expand Up @@ -384,6 +385,7 @@ static void createAccountTable(SQLiteDatabase db) {
+ AccountColumns.RINGTONE_URI + " text, "
+ AccountColumns.PROTOCOL_VERSION + " text, "
+ AccountColumns.NEW_MESSAGE_COUNT + " integer"
+ AccountColumns.SIGNATURE + " text, "
+ ");";
db.execSQL("create table " + Account.TABLE_NAME + s);
// Deleting an account deletes associated Mailboxes and HostAuth's
Expand Down Expand Up @@ -614,6 +616,16 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
oldVersion = 6;
}
if (oldVersion == 6) {
try {
db.execSQL("alter table " + Account.TABLE_NAME
+ " add column " + AccountColumns.SIGNATURE + " text" + ";");
} catch (SQLException e) {
// Shouldn't be needed unless we're debugging and interrupt the process
Log.w(TAG, "Exception upgrading EmailProvider.db from v6 to v7", e);
}
oldVersion = 7;
}
}

@Override
Expand Down

0 comments on commit 8ce3f85

Please sign in to comment.