• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2013, Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.email.activity;
18 
19 import android.text.Editable;
20 import android.text.SpannableStringBuilder;
21 import android.view.Menu;
22 import android.view.MenuItem;
23 import android.widget.EditText;
24 
25 import com.android.email.R;
26 import com.android.emailcommon.provider.EmailContent;
27 import com.android.mail.compose.ComposeActivity;
28 import com.android.mail.utils.LogUtils;
29 
30 public class ComposeActivityEmail extends ComposeActivity
31         implements InsertQuickResponseDialog.Callback {
32     static final String insertQuickResponseDialogTag = "insertQuickResponseDialog";
33     @Override
onCreateOptionsMenu(Menu menu)34     public boolean onCreateOptionsMenu(Menu menu) {
35         final boolean superCreated = super.onCreateOptionsMenu(menu);
36         if (mReplyFromAccount != null) {
37             getMenuInflater().inflate(R.menu.email_compose_menu_extras, menu);
38             return true;
39         } else {
40             LogUtils.d(LogUtils.TAG, "mReplyFromAccount is null, not adding Quick Response menu");
41             return superCreated;
42         }
43     }
44 
45     @Override
onOptionsItemSelected(MenuItem item)46     public boolean onOptionsItemSelected(MenuItem item) {
47         if (item.getItemId() == R.id.insert_quick_response_menu_item) {
48             InsertQuickResponseDialog dialog = InsertQuickResponseDialog.newInstance(null,
49                     mReplyFromAccount.account);
50             dialog.show(getFragmentManager(), insertQuickResponseDialogTag);
51         }
52         return super.onOptionsItemSelected(item);
53     }
54 
onQuickResponseSelected(CharSequence quickResponse)55     public void onQuickResponseSelected(CharSequence quickResponse) {
56         final int selEnd = mBodyView.getSelectionEnd();
57         final int selStart = mBodyView.getSelectionStart();
58 
59         if (selEnd >= 0 && selStart >= 0) {
60             final SpannableStringBuilder messageBody =
61                     new SpannableStringBuilder(mBodyView.getText());
62             final int replaceStart = selStart < selEnd ? selStart : selEnd;
63             final int replaceEnd = selStart < selEnd ? selEnd : selStart;
64             messageBody.replace(replaceStart, replaceEnd, quickResponse);
65             mBodyView.setText(messageBody);
66             mBodyView.setSelection(replaceStart + quickResponse.length());
67         } else {
68             mBodyView.append(quickResponse);
69             mBodyView.setSelection(mBodyView.getText().length());
70         }
71     }
72 
73     @Override
74     protected String getEmailProviderAuthority() {
75         return EmailContent.AUTHORITY;
76     }
77 
78     @Override
79     protected String getEmailAttachmentProviderAuthority() {
80         return EmailContent.Attachment.ATTACHMENT_PROVIDER_AUTHORITY;
81     }
82 }
83