From 5a3888f35b669ffb3cc785d7dfe4862879a3896c Mon Sep 17 00:00:00 2001 From: Jorge Lugo Date: Wed, 1 Jun 2011 10:09:26 -0700 Subject: [PATCH] Added quick responses. Added "Insert quick response" button to MessageCompose's action bar. Clicking it opens dialog with available quick responses. Selecting one of the responses will insert it into message body at the current cursor location. Also added menu in account preferences to create, edit, and delete quick responses. Change-Id: I85f3f6b36801cf112ec9d7c31135a917456173d7 --- .../emailcommon/provider/EmailContent.java | 7 + .../emailcommon/provider/QuickResponse.java | 217 +++++++++++++ ...settings_edit_quick_responses_fragment.xml | 54 ++++ res/layout/quick_response_item.xml | 46 +++ res/menu/message_compose_option.xml | 5 + res/values/strings.xml | 21 ++ res/xml/account_settings_preferences.xml | 18 +- .../activity/InsertQuickResponseDialog.java | 151 +++++++++ .../email/activity/MessageCompose.java | 20 +- .../email/activity/setup/AccountSettings.java | 32 +- ...untSettingsEditQuickResponsesFragment.java | 287 ++++++++++++++++++ .../setup/AccountSettingsFragment.java | 15 +- .../setup/EditQuickResponseDialog.java | 135 ++++++++ .../android/email/provider/EmailProvider.java | 57 +++- .../provider/QuickResponseTests.java | 79 +++++ 15 files changed, 1133 insertions(+), 11 deletions(-) create mode 100644 emailcommon/src/com/android/emailcommon/provider/QuickResponse.java create mode 100644 res/layout/account_settings_edit_quick_responses_fragment.xml create mode 100644 res/layout/quick_response_item.xml create mode 100644 src/com/android/email/activity/InsertQuickResponseDialog.java create mode 100644 src/com/android/email/activity/setup/AccountSettingsEditQuickResponsesFragment.java create mode 100644 src/com/android/email/activity/setup/EditQuickResponseDialog.java create mode 100644 tests/src/com/android/emailcommon/provider/QuickResponseTests.java diff --git a/emailcommon/src/com/android/emailcommon/provider/EmailContent.java b/emailcommon/src/com/android/emailcommon/provider/EmailContent.java index 670ec1f19..702511cdb 100644 --- a/emailcommon/src/com/android/emailcommon/provider/EmailContent.java +++ b/emailcommon/src/com/android/emailcommon/provider/EmailContent.java @@ -1299,6 +1299,13 @@ public abstract class EmailContent { public static final String POLICY_KEY = "policyKey"; } + public interface QuickResponseColumns { + // The QuickResponse text + static final String TEXT = "quickResponse"; + // A foreign key into the Account table owning the QuickResponse + static final String ACCOUNT_KEY = "accountKey"; + } + public interface MailboxColumns { public static final String ID = "_id"; // The display name of this mailbox [INDEX] diff --git a/emailcommon/src/com/android/emailcommon/provider/QuickResponse.java b/emailcommon/src/com/android/emailcommon/provider/QuickResponse.java new file mode 100644 index 000000000..e88e01d95 --- /dev/null +++ b/emailcommon/src/com/android/emailcommon/provider/QuickResponse.java @@ -0,0 +1,217 @@ +/* + * Copyright (C) 2011 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. + */ + + +package com.android.emailcommon.provider; + +import com.android.emailcommon.provider.EmailContent; +import com.android.emailcommon.provider.EmailContent.QuickResponseColumns; +import com.google.common.base.Objects; + +import android.content.ContentUris; +import android.content.ContentValues; +import android.content.Context; +import android.database.Cursor; +import android.net.Uri; +import android.os.Parcel; +import android.os.Parcelable; + +/** + * A user-modifiable message that may be quickly inserted into the body while user is composing + * a message. Tied to a specific account. + */ +public final class QuickResponse extends EmailContent + implements QuickResponseColumns, Parcelable { + public static final String TABLE_NAME = "QuickResponse"; + @SuppressWarnings("hiding") + public static final Uri CONTENT_URI = Uri.parse(EmailContent.CONTENT_URI + + "/quickresponse"); + public static final Uri ACCOUNT_ID_URI = Uri.parse( + EmailContent.CONTENT_URI + "/quickresponse/account"); + + private String mText; + private long mAccountKey; + + private static final int CONTENT_ID_COLUMN = 0; + private static final int CONTENT_QUICK_RESPONSE_COLUMN = 1; + private static final int CONTENT_ACCOUNT_KEY_COLUMN = 2; + public static final String[] CONTENT_PROJECTION = new String[] { + RECORD_ID, + QuickResponseColumns.TEXT, + QuickResponseColumns.ACCOUNT_KEY + }; + + /** + * Creates an empty QuickResponse. Restore should be called after. + */ + private QuickResponse() { + // empty + } + + /** + * Constructor used by CREATOR for parceling. + */ + private QuickResponse(Parcel in) { + mBaseUri = CONTENT_URI; + mId = in.readLong(); + mText = in.readString(); + mAccountKey = in.readLong(); + } + + /** + * Creates QuickResponse associated with a particular account using the given string. + */ + public QuickResponse(long accountKey, String quickResponse) { + mBaseUri = CONTENT_URI; + mAccountKey = accountKey; + mText = quickResponse; + } + + /** + * @see com.android.emailcommon.provider.EmailContent#restore(android.database.Cursor) + */ + @Override + public void restore(Cursor cursor) { + mBaseUri = CONTENT_URI; + mId = cursor.getLong(CONTENT_ID_COLUMN); + mText = cursor.getString(CONTENT_QUICK_RESPONSE_COLUMN); + mAccountKey = cursor.getLong(CONTENT_ACCOUNT_KEY_COLUMN); + } + + /** + * @see com.android.emailcommon.provider.EmailContent#toContentValues() + */ + @Override + public ContentValues toContentValues() { + ContentValues values = new ContentValues(); + + values.put(QuickResponseColumns.TEXT, mText); + values.put(QuickResponseColumns.ACCOUNT_KEY, mAccountKey); + + return values; + } + + @Override + public String toString() { + return mText; + } + + /** + * Given an array of QuickResponses, returns the an array of the String values + * corresponding to each QuickResponse. + */ + public static String[] getQuickResponseStrings(QuickResponse[] quickResponses) { + int count = quickResponses.length; + String[] quickResponseStrings = new String[count]; + for (int i = 0; i < count; i++) { + quickResponseStrings[i] = quickResponses[i].toString(); + } + + return quickResponseStrings; + } + + /** + * @param context + * @param accountId + * @return array of QuickResponses for the account with id accountId + */ + public static QuickResponse[] restoreQuickResponsesWithAccountId(Context context, + long accountId) { + Uri uri = ContentUris.withAppendedId(ACCOUNT_ID_URI, accountId); + Cursor c = context.getContentResolver().query(uri, CONTENT_PROJECTION, + null, null, null); + + try { + int count = c.getCount(); + QuickResponse[] quickResponses = new QuickResponse[count]; + for (int i = 0; i < count; ++i) { + c.moveToNext(); + QuickResponse quickResponse = new QuickResponse(); + quickResponse.restore(c); + quickResponses[i] = quickResponse; + } + return quickResponses; + } finally { + c.close(); + } + } + + /** + * Returns the base URI for this QuickResponse + */ + public Uri getBaseUri() { + return mBaseUri; + } + + /** + * Returns the unique id for this QuickResponse + */ + public long getId() { + return mId; + } + + @Override + public boolean equals(Object objectThat) { + if (this == objectThat) return true; + if (!(objectThat instanceof QuickResponse)) return false; + + QuickResponse that = (QuickResponse) objectThat; + return + mText.equals(that.mText) && + mId == that.mId && + mAccountKey == that.mAccountKey; + } + + @Override + public int hashCode() { + return Objects.hashCode(mId, mText, mAccountKey); + } + + /** + * Implements Parcelable. Not used. + */ + @Override + public int describeContents() { + return 0; + } + + /** + * Implements Parcelable. + */ + public void writeToParcel(Parcel dest, int flags) { + // mBaseUri is not parceled + dest.writeLong(mId); + dest.writeString(mText); + dest.writeLong(mAccountKey); + } + + /** + * Implements Parcelable + */ + public static final Parcelable.Creator CREATOR + = new Parcelable.Creator() { + @Override + public QuickResponse createFromParcel(Parcel in) { + return new QuickResponse(in); + } + + @Override + public QuickResponse[] newArray(int size) { + return new QuickResponse[size]; + } + }; + +} \ No newline at end of file diff --git a/res/layout/account_settings_edit_quick_responses_fragment.xml b/res/layout/account_settings_edit_quick_responses_fragment.xml new file mode 100644 index 000000000..af9bf6075 --- /dev/null +++ b/res/layout/account_settings_edit_quick_responses_fragment.xml @@ -0,0 +1,54 @@ + + + + + + + + + +