2012-07-19 21:22:03 +00:00
|
|
|
/**
|
|
|
|
* Copyright (C) 2011 Whisper Systems
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
package org.thoughtcrime.securesms;
|
|
|
|
|
2013-03-06 03:32:15 +00:00
|
|
|
import android.app.AlertDialog;
|
2013-06-18 21:43:27 +00:00
|
|
|
import android.content.ActivityNotFoundException;
|
2013-03-06 03:32:15 +00:00
|
|
|
import android.content.BroadcastReceiver;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.DialogInterface;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.IntentFilter;
|
2013-06-21 18:56:59 +00:00
|
|
|
import android.content.res.TypedArray;
|
2014-02-18 05:42:30 +00:00
|
|
|
import android.graphics.Bitmap;
|
|
|
|
import android.graphics.drawable.BitmapDrawable;
|
2013-03-06 03:32:15 +00:00
|
|
|
import android.net.Uri;
|
|
|
|
import android.os.AsyncTask;
|
|
|
|
import android.os.Build;
|
|
|
|
import android.os.Bundle;
|
2013-10-17 00:28:36 +00:00
|
|
|
import android.provider.ContactsContract;
|
2013-03-06 03:32:15 +00:00
|
|
|
import android.telephony.PhoneNumberUtils;
|
|
|
|
import android.text.Editable;
|
2013-06-29 22:34:43 +00:00
|
|
|
import android.text.InputType;
|
2014-02-18 05:42:30 +00:00
|
|
|
import android.text.TextUtils;
|
2013-03-06 03:32:15 +00:00
|
|
|
import android.text.TextWatcher;
|
|
|
|
import android.util.Log;
|
|
|
|
import android.view.ContextMenu;
|
2014-01-08 22:29:05 +00:00
|
|
|
import android.view.ContextThemeWrapper;
|
2013-03-06 03:32:15 +00:00
|
|
|
import android.view.KeyEvent;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.View.OnClickListener;
|
|
|
|
import android.view.View.OnKeyListener;
|
|
|
|
import android.view.WindowManager;
|
|
|
|
import android.view.inputmethod.EditorInfo;
|
2013-06-28 03:57:27 +00:00
|
|
|
import android.view.inputmethod.InputMethodManager;
|
2013-03-06 03:32:15 +00:00
|
|
|
import android.widget.EditText;
|
|
|
|
import android.widget.ImageButton;
|
|
|
|
import android.widget.TextView;
|
|
|
|
import android.widget.Toast;
|
2012-07-19 21:22:03 +00:00
|
|
|
|
2013-02-03 04:37:40 +00:00
|
|
|
import com.actionbarsherlock.view.Menu;
|
|
|
|
import com.actionbarsherlock.view.MenuInflater;
|
|
|
|
import com.actionbarsherlock.view.MenuItem;
|
2014-02-22 18:54:43 +00:00
|
|
|
import com.google.protobuf.ByteString;
|
2013-11-26 01:00:20 +00:00
|
|
|
|
2013-06-28 03:57:27 +00:00
|
|
|
import org.thoughtcrime.securesms.components.EmojiDrawer;
|
|
|
|
import org.thoughtcrime.securesms.components.EmojiToggle;
|
Major storage layer refactoring to set the stage for clean GCM.
1) We now try to hand out cursors at a minimum. There has always been
a fairly clean insertion layer that handles encrypting message bodies,
but the process of decrypting message bodies has always been less than
ideal. Here we introduce a "Reader" interface that will decrypt message
bodies when appropriate and return objects that encapsulate record state.
No more MessageDisplayHelper. The MmsSmsDatabase interface is also more
sane.
2) We finally rid ourselves of the technical debt associated with TextSecure's
initial usage of the default SMS DB. In that world, we weren't able to use
anything other than the default "Inbox, Outbox, Sent" types to describe a
message, and had to overload the message content itself with a set of
local "prefixes" to describe what it was (encrypted, asymetric encrypted,
remote encrypted, a key exchange, procssed key exchange), and so on.
This includes a major schema update that transforms the "type" field into
a bitmask that describes everything that used to be encoded in a prefix,
and prefixes have been completely eliminated from the system.
No more Prefix.java
3) Refactoring of the MultipartMessageHandler code. It's less of a mess, and
hopefully more clear as to what's going on.
The next step is to remove what we can from SmsTransportDetails and genericize
that interface for a GCM equivalent.
2013-04-20 19:22:04 +00:00
|
|
|
import org.thoughtcrime.securesms.components.RecipientsPanel;
|
2013-10-17 00:28:36 +00:00
|
|
|
import org.thoughtcrime.securesms.contacts.ContactAccessor;
|
|
|
|
import org.thoughtcrime.securesms.contacts.ContactAccessor.ContactData;
|
Major storage layer refactoring to set the stage for clean GCM.
1) We now try to hand out cursors at a minimum. There has always been
a fairly clean insertion layer that handles encrypting message bodies,
but the process of decrypting message bodies has always been less than
ideal. Here we introduce a "Reader" interface that will decrypt message
bodies when appropriate and return objects that encapsulate record state.
No more MessageDisplayHelper. The MmsSmsDatabase interface is also more
sane.
2) We finally rid ourselves of the technical debt associated with TextSecure's
initial usage of the default SMS DB. In that world, we weren't able to use
anything other than the default "Inbox, Outbox, Sent" types to describe a
message, and had to overload the message content itself with a set of
local "prefixes" to describe what it was (encrypted, asymetric encrypted,
remote encrypted, a key exchange, procssed key exchange), and so on.
This includes a major schema update that transforms the "type" field into
a bitmask that describes everything that used to be encoded in a prefix,
and prefixes have been completely eliminated from the system.
No more Prefix.java
3) Refactoring of the MultipartMessageHandler code. It's less of a mess, and
hopefully more clear as to what's going on.
The next step is to remove what we can from SmsTransportDetails and genericize
that interface for a GCM equivalent.
2013-04-20 19:22:04 +00:00
|
|
|
import org.thoughtcrime.securesms.crypto.KeyExchangeInitiator;
|
|
|
|
import org.thoughtcrime.securesms.crypto.KeyExchangeProcessor;
|
|
|
|
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
|
|
|
import org.thoughtcrime.securesms.database.DraftDatabase;
|
|
|
|
import org.thoughtcrime.securesms.database.DraftDatabase.Draft;
|
2014-02-22 18:54:43 +00:00
|
|
|
import org.thoughtcrime.securesms.database.GroupDatabase;
|
2013-04-26 01:59:49 +00:00
|
|
|
import org.thoughtcrime.securesms.database.ThreadDatabase;
|
Major storage layer refactoring to set the stage for clean GCM.
1) We now try to hand out cursors at a minimum. There has always been
a fairly clean insertion layer that handles encrypting message bodies,
but the process of decrypting message bodies has always been less than
ideal. Here we introduce a "Reader" interface that will decrypt message
bodies when appropriate and return objects that encapsulate record state.
No more MessageDisplayHelper. The MmsSmsDatabase interface is also more
sane.
2) We finally rid ourselves of the technical debt associated with TextSecure's
initial usage of the default SMS DB. In that world, we weren't able to use
anything other than the default "Inbox, Outbox, Sent" types to describe a
message, and had to overload the message content itself with a set of
local "prefixes" to describe what it was (encrypted, asymetric encrypted,
remote encrypted, a key exchange, procssed key exchange), and so on.
This includes a major schema update that transforms the "type" field into
a bitmask that describes everything that used to be encoded in a prefix,
and prefixes have been completely eliminated from the system.
No more Prefix.java
3) Refactoring of the MultipartMessageHandler code. It's less of a mess, and
hopefully more clear as to what's going on.
The next step is to remove what we can from SmsTransportDetails and genericize
that interface for a GCM equivalent.
2013-04-20 19:22:04 +00:00
|
|
|
import org.thoughtcrime.securesms.mms.AttachmentManager;
|
|
|
|
import org.thoughtcrime.securesms.mms.AttachmentTypeSelectorAdapter;
|
|
|
|
import org.thoughtcrime.securesms.mms.MediaTooLargeException;
|
|
|
|
import org.thoughtcrime.securesms.mms.MmsSendHelper;
|
2014-02-22 18:54:43 +00:00
|
|
|
import org.thoughtcrime.securesms.mms.OutgoingGroupMediaMessage;
|
2014-02-24 08:19:54 +00:00
|
|
|
import org.thoughtcrime.securesms.mms.OutgoingMediaMessage;
|
|
|
|
import org.thoughtcrime.securesms.mms.OutgoingSecureMediaMessage;
|
Major storage layer refactoring to set the stage for clean GCM.
1) We now try to hand out cursors at a minimum. There has always been
a fairly clean insertion layer that handles encrypting message bodies,
but the process of decrypting message bodies has always been less than
ideal. Here we introduce a "Reader" interface that will decrypt message
bodies when appropriate and return objects that encapsulate record state.
No more MessageDisplayHelper. The MmsSmsDatabase interface is also more
sane.
2) We finally rid ourselves of the technical debt associated with TextSecure's
initial usage of the default SMS DB. In that world, we weren't able to use
anything other than the default "Inbox, Outbox, Sent" types to describe a
message, and had to overload the message content itself with a set of
local "prefixes" to describe what it was (encrypted, asymetric encrypted,
remote encrypted, a key exchange, procssed key exchange), and so on.
This includes a major schema update that transforms the "type" field into
a bitmask that describes everything that used to be encoded in a prefix,
and prefixes have been completely eliminated from the system.
No more Prefix.java
3) Refactoring of the MultipartMessageHandler code. It's less of a mess, and
hopefully more clear as to what's going on.
The next step is to remove what we can from SmsTransportDetails and genericize
that interface for a GCM equivalent.
2013-04-20 19:22:04 +00:00
|
|
|
import org.thoughtcrime.securesms.mms.Slide;
|
|
|
|
import org.thoughtcrime.securesms.mms.SlideDeck;
|
|
|
|
import org.thoughtcrime.securesms.notifications.MessageNotifier;
|
|
|
|
import org.thoughtcrime.securesms.protocol.Tag;
|
|
|
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
2014-02-20 23:41:52 +00:00
|
|
|
import org.thoughtcrime.securesms.recipients.RecipientFactory;
|
Major storage layer refactoring to set the stage for clean GCM.
1) We now try to hand out cursors at a minimum. There has always been
a fairly clean insertion layer that handles encrypting message bodies,
but the process of decrypting message bodies has always been less than
ideal. Here we introduce a "Reader" interface that will decrypt message
bodies when appropriate and return objects that encapsulate record state.
No more MessageDisplayHelper. The MmsSmsDatabase interface is also more
sane.
2) We finally rid ourselves of the technical debt associated with TextSecure's
initial usage of the default SMS DB. In that world, we weren't able to use
anything other than the default "Inbox, Outbox, Sent" types to describe a
message, and had to overload the message content itself with a set of
local "prefixes" to describe what it was (encrypted, asymetric encrypted,
remote encrypted, a key exchange, procssed key exchange), and so on.
This includes a major schema update that transforms the "type" field into
a bitmask that describes everything that used to be encoded in a prefix,
and prefixes have been completely eliminated from the system.
No more Prefix.java
3) Refactoring of the MultipartMessageHandler code. It's less of a mess, and
hopefully more clear as to what's going on.
The next step is to remove what we can from SmsTransportDetails and genericize
that interface for a GCM equivalent.
2013-04-20 19:22:04 +00:00
|
|
|
import org.thoughtcrime.securesms.recipients.RecipientFormattingException;
|
|
|
|
import org.thoughtcrime.securesms.recipients.Recipients;
|
|
|
|
import org.thoughtcrime.securesms.service.KeyCachingService;
|
|
|
|
import org.thoughtcrime.securesms.sms.MessageSender;
|
|
|
|
import org.thoughtcrime.securesms.sms.OutgoingEncryptedMessage;
|
2014-02-19 21:46:49 +00:00
|
|
|
import org.thoughtcrime.securesms.sms.OutgoingEndSessionMessage;
|
Major storage layer refactoring to set the stage for clean GCM.
1) We now try to hand out cursors at a minimum. There has always been
a fairly clean insertion layer that handles encrypting message bodies,
but the process of decrypting message bodies has always been less than
ideal. Here we introduce a "Reader" interface that will decrypt message
bodies when appropriate and return objects that encapsulate record state.
No more MessageDisplayHelper. The MmsSmsDatabase interface is also more
sane.
2) We finally rid ourselves of the technical debt associated with TextSecure's
initial usage of the default SMS DB. In that world, we weren't able to use
anything other than the default "Inbox, Outbox, Sent" types to describe a
message, and had to overload the message content itself with a set of
local "prefixes" to describe what it was (encrypted, asymetric encrypted,
remote encrypted, a key exchange, procssed key exchange), and so on.
This includes a major schema update that transforms the "type" field into
a bitmask that describes everything that used to be encoded in a prefix,
and prefixes have been completely eliminated from the system.
No more Prefix.java
3) Refactoring of the MultipartMessageHandler code. It's less of a mess, and
hopefully more clear as to what's going on.
The next step is to remove what we can from SmsTransportDetails and genericize
that interface for a GCM equivalent.
2013-04-20 19:22:04 +00:00
|
|
|
import org.thoughtcrime.securesms.sms.OutgoingTextMessage;
|
2014-01-08 22:29:05 +00:00
|
|
|
import org.thoughtcrime.securesms.util.ActionBarUtil;
|
2013-05-21 17:32:48 +00:00
|
|
|
import org.thoughtcrime.securesms.util.BitmapDecodingException;
|
2014-02-18 05:42:30 +00:00
|
|
|
import org.thoughtcrime.securesms.util.BitmapUtil;
|
Major storage layer refactoring to set the stage for clean GCM.
1) We now try to hand out cursors at a minimum. There has always been
a fairly clean insertion layer that handles encrypting message bodies,
but the process of decrypting message bodies has always been less than
ideal. Here we introduce a "Reader" interface that will decrypt message
bodies when appropriate and return objects that encapsulate record state.
No more MessageDisplayHelper. The MmsSmsDatabase interface is also more
sane.
2) We finally rid ourselves of the technical debt associated with TextSecure's
initial usage of the default SMS DB. In that world, we weren't able to use
anything other than the default "Inbox, Outbox, Sent" types to describe a
message, and had to overload the message content itself with a set of
local "prefixes" to describe what it was (encrypted, asymetric encrypted,
remote encrypted, a key exchange, procssed key exchange), and so on.
This includes a major schema update that transforms the "type" field into
a bitmask that describes everything that used to be encoded in a prefix,
and prefixes have been completely eliminated from the system.
No more Prefix.java
3) Refactoring of the MultipartMessageHandler code. It's less of a mess, and
hopefully more clear as to what's going on.
The next step is to remove what we can from SmsTransportDetails and genericize
that interface for a GCM equivalent.
2013-04-20 19:22:04 +00:00
|
|
|
import org.thoughtcrime.securesms.util.CharacterCalculator;
|
2014-03-01 00:32:00 +00:00
|
|
|
import org.thoughtcrime.securesms.util.Dialogs;
|
2014-03-26 21:49:40 +00:00
|
|
|
import org.thoughtcrime.securesms.util.DirectoryHelper;
|
2013-06-30 01:03:55 +00:00
|
|
|
import org.thoughtcrime.securesms.util.DynamicLanguage;
|
2013-06-21 18:56:59 +00:00
|
|
|
import org.thoughtcrime.securesms.util.DynamicTheme;
|
Major storage layer refactoring to set the stage for clean GCM.
1) We now try to hand out cursors at a minimum. There has always been
a fairly clean insertion layer that handles encrypting message bodies,
but the process of decrypting message bodies has always been less than
ideal. Here we introduce a "Reader" interface that will decrypt message
bodies when appropriate and return objects that encapsulate record state.
No more MessageDisplayHelper. The MmsSmsDatabase interface is also more
sane.
2) We finally rid ourselves of the technical debt associated with TextSecure's
initial usage of the default SMS DB. In that world, we weren't able to use
anything other than the default "Inbox, Outbox, Sent" types to describe a
message, and had to overload the message content itself with a set of
local "prefixes" to describe what it was (encrypted, asymetric encrypted,
remote encrypted, a key exchange, procssed key exchange), and so on.
This includes a major schema update that transforms the "type" field into
a bitmask that describes everything that used to be encoded in a prefix,
and prefixes have been completely eliminated from the system.
No more Prefix.java
3) Refactoring of the MultipartMessageHandler code. It's less of a mess, and
hopefully more clear as to what's going on.
The next step is to remove what we can from SmsTransportDetails and genericize
that interface for a GCM equivalent.
2013-04-20 19:22:04 +00:00
|
|
|
import org.thoughtcrime.securesms.util.EncryptedCharacterCalculator;
|
2014-02-22 18:54:43 +00:00
|
|
|
import org.thoughtcrime.securesms.util.GroupUtil;
|
Major storage layer refactoring to set the stage for clean GCM.
1) We now try to hand out cursors at a minimum. There has always been
a fairly clean insertion layer that handles encrypting message bodies,
but the process of decrypting message bodies has always been less than
ideal. Here we introduce a "Reader" interface that will decrypt message
bodies when appropriate and return objects that encapsulate record state.
No more MessageDisplayHelper. The MmsSmsDatabase interface is also more
sane.
2) We finally rid ourselves of the technical debt associated with TextSecure's
initial usage of the default SMS DB. In that world, we weren't able to use
anything other than the default "Inbox, Outbox, Sent" types to describe a
message, and had to overload the message content itself with a set of
local "prefixes" to describe what it was (encrypted, asymetric encrypted,
remote encrypted, a key exchange, procssed key exchange), and so on.
This includes a major schema update that transforms the "type" field into
a bitmask that describes everything that used to be encoded in a prefix,
and prefixes have been completely eliminated from the system.
No more Prefix.java
3) Refactoring of the MultipartMessageHandler code. It's less of a mess, and
hopefully more clear as to what's going on.
The next step is to remove what we can from SmsTransportDetails and genericize
that interface for a GCM equivalent.
2013-04-20 19:22:04 +00:00
|
|
|
import org.thoughtcrime.securesms.util.MemoryCleaner;
|
2013-07-10 01:26:18 +00:00
|
|
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
2013-11-26 01:00:20 +00:00
|
|
|
import org.whispersystems.textsecure.crypto.InvalidMessageException;
|
|
|
|
import org.whispersystems.textsecure.crypto.MasterCipher;
|
|
|
|
import org.whispersystems.textsecure.crypto.MasterSecret;
|
2014-02-19 21:46:49 +00:00
|
|
|
import org.whispersystems.textsecure.storage.RecipientDevice;
|
2013-11-26 01:00:20 +00:00
|
|
|
import org.whispersystems.textsecure.storage.Session;
|
2014-02-19 21:46:49 +00:00
|
|
|
import org.whispersystems.textsecure.storage.SessionRecordV2;
|
2013-07-10 02:48:33 +00:00
|
|
|
import org.whispersystems.textsecure.util.Util;
|
Major storage layer refactoring to set the stage for clean GCM.
1) We now try to hand out cursors at a minimum. There has always been
a fairly clean insertion layer that handles encrypting message bodies,
but the process of decrypting message bodies has always been less than
ideal. Here we introduce a "Reader" interface that will decrypt message
bodies when appropriate and return objects that encapsulate record state.
No more MessageDisplayHelper. The MmsSmsDatabase interface is also more
sane.
2) We finally rid ourselves of the technical debt associated with TextSecure's
initial usage of the default SMS DB. In that world, we weren't able to use
anything other than the default "Inbox, Outbox, Sent" types to describe a
message, and had to overload the message content itself with a set of
local "prefixes" to describe what it was (encrypted, asymetric encrypted,
remote encrypted, a key exchange, procssed key exchange), and so on.
This includes a major schema update that transforms the "type" field into
a bitmask that describes everything that used to be encoded in a prefix,
and prefixes have been completely eliminated from the system.
No more Prefix.java
3) Refactoring of the MultipartMessageHandler code. It's less of a mess, and
hopefully more clear as to what's going on.
The next step is to remove what we can from SmsTransportDetails and genericize
that interface for a GCM equivalent.
2013-04-20 19:22:04 +00:00
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.util.LinkedList;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import ws.com.google.android.mms.MmsException;
|
2013-02-03 04:37:40 +00:00
|
|
|
|
2014-02-22 18:54:43 +00:00
|
|
|
import static org.thoughtcrime.securesms.database.GroupDatabase.GroupRecord;
|
2014-02-24 08:19:54 +00:00
|
|
|
import static org.thoughtcrime.securesms.recipients.Recipient.RecipientModifiedListener;
|
2014-02-22 18:54:43 +00:00
|
|
|
import static org.whispersystems.textsecure.push.PushMessageProtos.PushMessageContent.GroupContext;
|
|
|
|
|
2012-07-19 21:22:03 +00:00
|
|
|
/**
|
|
|
|
* Activity for displaying a message thread, as well as
|
|
|
|
* composing/sending a new message into that thread.
|
|
|
|
*
|
|
|
|
* @author Moxie Marlinspike
|
|
|
|
*
|
|
|
|
*/
|
2013-02-11 01:30:51 +00:00
|
|
|
public class ConversationActivity extends PassphraseRequiredSherlockFragmentActivity
|
2012-08-04 00:34:09 +00:00
|
|
|
implements ConversationFragment.ConversationFragmentListener
|
2013-04-26 01:59:49 +00:00
|
|
|
{
|
2014-02-19 00:28:54 +00:00
|
|
|
private static final String TAG = ConversationActivity.class.getSimpleName();
|
2012-07-19 21:22:03 +00:00
|
|
|
|
2013-04-26 01:59:49 +00:00
|
|
|
public static final String RECIPIENTS_EXTRA = "recipients";
|
|
|
|
public static final String THREAD_ID_EXTRA = "thread_id";
|
|
|
|
public static final String MASTER_SECRET_EXTRA = "master_secret";
|
|
|
|
public static final String DRAFT_TEXT_EXTRA = "draft_text";
|
|
|
|
public static final String DRAFT_IMAGE_EXTRA = "draft_image";
|
|
|
|
public static final String DRAFT_AUDIO_EXTRA = "draft_audio";
|
2014-03-03 16:55:34 +00:00
|
|
|
public static final String DRAFT_VIDEO_EXTRA = "draft_video";
|
2013-04-26 01:59:49 +00:00
|
|
|
public static final String DISTRIBUTION_TYPE_EXTRA = "distribution_type";
|
2013-02-03 04:37:40 +00:00
|
|
|
|
2014-02-18 04:25:40 +00:00
|
|
|
private static final int PICK_CONTACT = 1;
|
|
|
|
private static final int PICK_IMAGE = 2;
|
|
|
|
private static final int PICK_VIDEO = 3;
|
|
|
|
private static final int PICK_AUDIO = 4;
|
|
|
|
private static final int PICK_CONTACT_INFO = 5;
|
2014-02-20 23:41:52 +00:00
|
|
|
private static final int GROUP_EDIT = 6;
|
2012-07-19 21:22:03 +00:00
|
|
|
|
2014-03-20 07:54:05 +00:00
|
|
|
private static final int SEND_ATTRIBUTES[] = new int[]{R.attr.conversation_send_button_push,
|
|
|
|
R.attr.conversation_send_button_sms_secure,
|
|
|
|
R.attr.conversation_send_button_sms_insecure};
|
|
|
|
|
2014-02-18 04:25:40 +00:00
|
|
|
private MasterSecret masterSecret;
|
2012-07-19 21:22:03 +00:00
|
|
|
private RecipientsPanel recipientsPanel;
|
2014-02-18 04:25:40 +00:00
|
|
|
private EditText composeText;
|
|
|
|
private ImageButton addContactButton;
|
|
|
|
private ImageButton sendButton;
|
|
|
|
private TextView charactersLeft;
|
2012-07-19 21:22:03 +00:00
|
|
|
|
|
|
|
private AttachmentTypeSelectorAdapter attachmentAdapter;
|
2014-02-18 04:25:40 +00:00
|
|
|
private AttachmentManager attachmentManager;
|
|
|
|
private BroadcastReceiver securityUpdateReceiver;
|
2014-02-24 08:19:54 +00:00
|
|
|
private BroadcastReceiver groupUpdateReceiver;
|
2014-02-18 04:25:40 +00:00
|
|
|
private EmojiDrawer emojiDrawer;
|
|
|
|
private EmojiToggle emojiToggle;
|
2012-07-19 21:22:03 +00:00
|
|
|
|
|
|
|
private Recipients recipients;
|
2014-02-18 04:25:40 +00:00
|
|
|
private long threadId;
|
|
|
|
private int distributionType;
|
|
|
|
private boolean isEncryptedConversation;
|
|
|
|
private boolean isAuthenticatedConversation;
|
|
|
|
private boolean isMmsEnabled = true;
|
2014-02-26 21:28:46 +00:00
|
|
|
private boolean isCharactersLeftViewEnabled;
|
2012-07-19 21:22:03 +00:00
|
|
|
|
|
|
|
private CharacterCalculator characterCalculator = new CharacterCalculator();
|
2013-06-21 18:56:59 +00:00
|
|
|
private DynamicTheme dynamicTheme = new DynamicTheme();
|
2013-06-30 01:03:55 +00:00
|
|
|
private DynamicLanguage dynamicLanguage = new DynamicLanguage();
|
2012-07-19 21:22:03 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle state) {
|
2014-03-18 06:25:09 +00:00
|
|
|
overridePendingTransition(R.anim.slide_from_right, R.anim.fade_scale_out);
|
2013-06-21 18:56:59 +00:00
|
|
|
dynamicTheme.onCreate(this);
|
2013-06-30 01:03:55 +00:00
|
|
|
dynamicLanguage.onCreate(this);
|
2012-07-19 21:22:03 +00:00
|
|
|
super.onCreate(state);
|
|
|
|
|
|
|
|
setContentView(R.layout.conversation_activity);
|
|
|
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
2014-01-08 22:29:05 +00:00
|
|
|
ActionBarUtil.initializeDefaultActionBar(this, getSupportActionBar());
|
2012-07-19 21:22:03 +00:00
|
|
|
|
|
|
|
initializeReceivers();
|
|
|
|
initializeResources();
|
2013-02-03 04:37:40 +00:00
|
|
|
initializeDraft();
|
2012-07-19 21:22:03 +00:00
|
|
|
initializeTitleBar();
|
|
|
|
}
|
|
|
|
|
2013-02-04 02:41:34 +00:00
|
|
|
@Override
|
2013-03-05 01:43:04 +00:00
|
|
|
protected void onStart() {
|
|
|
|
super.onStart();
|
2013-02-04 02:41:34 +00:00
|
|
|
}
|
|
|
|
|
2012-07-19 21:22:03 +00:00
|
|
|
@Override
|
|
|
|
protected void onResume() {
|
2014-02-17 23:47:58 +00:00
|
|
|
initializeRecipientsInput();
|
2014-02-13 09:35:08 +00:00
|
|
|
|
2012-07-19 21:22:03 +00:00
|
|
|
super.onResume();
|
2013-06-21 18:56:59 +00:00
|
|
|
dynamicTheme.onResume(this);
|
2013-06-30 01:03:55 +00:00
|
|
|
dynamicLanguage.onResume(this);
|
2013-06-21 18:56:59 +00:00
|
|
|
|
2012-08-02 00:39:36 +00:00
|
|
|
initializeSecurity();
|
2012-07-19 21:22:03 +00:00
|
|
|
initializeTitleBar();
|
2014-02-22 18:54:43 +00:00
|
|
|
initializeEnabledCheck();
|
2013-03-05 01:43:04 +00:00
|
|
|
initializeMmsEnabledCheck();
|
2013-06-29 22:34:43 +00:00
|
|
|
initializeIme();
|
2014-02-26 21:28:46 +00:00
|
|
|
initializeCharactersLeftViewEnabledCheck();
|
2012-07-19 21:22:03 +00:00
|
|
|
calculateCharactersRemaining();
|
2013-02-04 02:41:34 +00:00
|
|
|
|
|
|
|
MessageNotifier.setVisibleThread(threadId);
|
|
|
|
markThreadAsRead();
|
2012-07-19 21:22:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2013-03-05 01:43:04 +00:00
|
|
|
protected void onPause() {
|
|
|
|
super.onPause();
|
|
|
|
MessageNotifier.setVisibleThread(-1L);
|
2014-04-08 17:45:55 +00:00
|
|
|
if (isFinishing()) overridePendingTransition(R.anim.fade_scale_in, R.anim.slide_to_right);
|
2012-07-19 21:22:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onDestroy() {
|
|
|
|
unregisterReceiver(securityUpdateReceiver);
|
2014-02-24 08:19:54 +00:00
|
|
|
unregisterReceiver(groupUpdateReceiver);
|
2013-02-04 08:13:07 +00:00
|
|
|
saveDraft();
|
2012-07-19 21:22:03 +00:00
|
|
|
MemoryCleaner.clean(masterSecret);
|
|
|
|
super.onDestroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onActivityResult(int reqCode, int resultCode, Intent data) {
|
2014-02-24 05:18:08 +00:00
|
|
|
Log.w(TAG, "onActivityResult called: " + reqCode + ", " + resultCode + " , " + data);
|
2012-07-19 21:22:03 +00:00
|
|
|
super.onActivityResult(reqCode, resultCode, data);
|
|
|
|
|
2014-02-17 23:47:58 +00:00
|
|
|
if (data == null || resultCode != RESULT_OK) return;
|
2012-07-19 21:22:03 +00:00
|
|
|
switch (reqCode) {
|
2014-02-17 23:47:58 +00:00
|
|
|
case PICK_CONTACT:
|
|
|
|
Recipients recipients = data.getParcelableExtra("recipients");
|
|
|
|
if (recipients != null)
|
2014-02-18 04:25:40 +00:00
|
|
|
recipientsPanel.addRecipients(recipients);
|
2014-02-17 23:47:58 +00:00
|
|
|
break;
|
2012-07-19 21:22:03 +00:00
|
|
|
case PICK_IMAGE:
|
2014-02-17 23:47:58 +00:00
|
|
|
addAttachmentImage(data.getData());
|
2012-07-19 21:22:03 +00:00
|
|
|
break;
|
|
|
|
case PICK_VIDEO:
|
2014-02-17 23:47:58 +00:00
|
|
|
addAttachmentVideo(data.getData());
|
2012-07-19 21:22:03 +00:00
|
|
|
break;
|
|
|
|
case PICK_AUDIO:
|
2014-02-17 23:47:58 +00:00
|
|
|
addAttachmentAudio(data.getData());
|
2012-07-19 21:22:03 +00:00
|
|
|
break;
|
2013-10-17 00:28:36 +00:00
|
|
|
case PICK_CONTACT_INFO:
|
2014-02-17 23:47:58 +00:00
|
|
|
addContactInfo(data.getData());
|
2013-10-17 00:28:36 +00:00
|
|
|
break;
|
2014-02-20 23:41:52 +00:00
|
|
|
case GROUP_EDIT:
|
2014-02-24 05:18:08 +00:00
|
|
|
this.recipients = data.getParcelableExtra(GroupCreateActivity.GROUP_RECIPIENT_EXTRA);
|
2014-02-20 23:41:52 +00:00
|
|
|
initializeTitleBar();
|
|
|
|
break;
|
2012-07-19 21:22:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onPrepareOptionsMenu(Menu menu) {
|
|
|
|
MenuInflater inflater = this.getSupportMenuInflater();
|
|
|
|
menu.clear();
|
|
|
|
|
2014-02-20 23:41:52 +00:00
|
|
|
boolean pushRegistered = TextSecurePreferences.isPushRegistered(this);
|
|
|
|
|
2014-02-18 04:25:40 +00:00
|
|
|
if (isSingleConversation() && isEncryptedConversation) {
|
2013-05-23 23:36:24 +00:00
|
|
|
if (isAuthenticatedConversation) {
|
|
|
|
inflater.inflate(R.menu.conversation_secure_identity, menu);
|
2012-07-19 21:22:03 +00:00
|
|
|
} else {
|
2013-05-23 23:36:24 +00:00
|
|
|
inflater.inflate(R.menu.conversation_secure_no_identity, menu);
|
2012-07-19 21:22:03 +00:00
|
|
|
}
|
2014-02-26 21:15:45 +00:00
|
|
|
|
2014-02-26 01:38:55 +00:00
|
|
|
inflater.inflate(R.menu.conversation_secure_sms, menu.findItem(R.id.menu_security).getSubMenu());
|
2014-02-20 23:41:52 +00:00
|
|
|
} else if (isSingleConversation() && !pushRegistered) {
|
2012-07-19 21:22:03 +00:00
|
|
|
inflater.inflate(R.menu.conversation_insecure, menu);
|
|
|
|
}
|
|
|
|
|
2012-08-08 02:03:28 +00:00
|
|
|
if (isSingleConversation()) {
|
|
|
|
inflater.inflate(R.menu.conversation_callable, menu);
|
2012-10-21 21:34:09 +00:00
|
|
|
} else if (isGroupConversation()) {
|
|
|
|
inflater.inflate(R.menu.conversation_group_options, menu);
|
2013-04-26 01:59:49 +00:00
|
|
|
|
2014-02-18 04:25:40 +00:00
|
|
|
if (!isPushGroupConversation()) {
|
|
|
|
inflater.inflate(R.menu.conversation_mms_group_options, menu);
|
|
|
|
if (distributionType == ThreadDatabase.DistributionTypes.BROADCAST) {
|
|
|
|
menu.findItem(R.id.menu_distribution_broadcast).setChecked(true);
|
|
|
|
} else {
|
|
|
|
menu.findItem(R.id.menu_distribution_conversation).setChecked(true);
|
|
|
|
}
|
2014-02-22 18:54:43 +00:00
|
|
|
} else if (isActiveGroup()) {
|
2014-02-20 23:41:52 +00:00
|
|
|
inflater.inflate(R.menu.conversation_push_group_options, menu);
|
2013-04-26 01:59:49 +00:00
|
|
|
}
|
2012-08-08 02:03:28 +00:00
|
|
|
}
|
|
|
|
|
2012-07-19 21:22:03 +00:00
|
|
|
inflater.inflate(R.menu.conversation, menu);
|
|
|
|
super.onPrepareOptionsMenu(menu);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
super.onOptionsItemSelected(item);
|
|
|
|
switch (item.getItemId()) {
|
2013-04-26 01:59:49 +00:00
|
|
|
case R.id.menu_call: handleDial(getRecipients().getPrimaryRecipient()); return true;
|
|
|
|
case R.id.menu_delete_thread: handleDeleteThread(); return true;
|
2013-10-17 00:28:36 +00:00
|
|
|
case R.id.menu_add_contact_info: handleAddContactInfo(); return true;
|
2013-04-26 01:59:49 +00:00
|
|
|
case R.id.menu_add_attachment: handleAddAttachment(); return true;
|
|
|
|
case R.id.menu_start_secure_session: handleStartSecureSession(); return true;
|
|
|
|
case R.id.menu_abort_session: handleAbortSecureSession(); return true;
|
2014-03-04 14:55:45 +00:00
|
|
|
case R.id.menu_verify_identity: handleVerifyIdentity(); return true;
|
2013-04-26 01:59:49 +00:00
|
|
|
case R.id.menu_group_recipients: handleDisplayGroupRecipients(); return true;
|
|
|
|
case R.id.menu_distribution_broadcast: handleDistributionBroadcastEnabled(item); return true;
|
|
|
|
case R.id.menu_distribution_conversation: handleDistributionConversationEnabled(item); return true;
|
2014-02-20 23:41:52 +00:00
|
|
|
case R.id.menu_edit_group: handleEditPushGroup(); return true;
|
|
|
|
case R.id.menu_leave: handleLeavePushGroup(); return true;
|
2013-04-26 01:59:49 +00:00
|
|
|
case android.R.id.home: handleReturnToConversationList(); return true;
|
2012-07-19 21:22:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-02-18 04:25:40 +00:00
|
|
|
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
|
2012-10-22 00:41:44 +00:00
|
|
|
if (isEncryptedConversation) {
|
2012-07-19 21:22:03 +00:00
|
|
|
android.view.MenuInflater inflater = getMenuInflater();
|
|
|
|
inflater.inflate(R.menu.conversation_button_context, menu);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onContextItemSelected(android.view.MenuItem item) {
|
|
|
|
switch (item.getItemId()) {
|
2012-10-22 00:41:44 +00:00
|
|
|
case R.id.menu_context_send_unencrypted: sendMessage(true); return true;
|
2012-07-19 21:22:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-06-28 03:57:27 +00:00
|
|
|
@Override
|
|
|
|
public void onBackPressed() {
|
|
|
|
if (emojiDrawer.getVisibility() == View.VISIBLE) {
|
|
|
|
emojiDrawer.setVisibility(View.GONE);
|
|
|
|
emojiToggle.toggle();
|
|
|
|
} else {
|
|
|
|
super.onBackPressed();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-19 21:22:03 +00:00
|
|
|
//////// Event Handlers
|
|
|
|
|
2013-02-17 19:42:30 +00:00
|
|
|
private void handleReturnToConversationList() {
|
|
|
|
Intent intent = new Intent(this, ConversationListActivity.class);
|
|
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
|
|
|
intent.putExtra("master_secret", masterSecret);
|
|
|
|
startActivity(intent);
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
|
2014-03-04 14:55:45 +00:00
|
|
|
private void handleVerifyIdentity() {
|
2012-07-19 21:22:03 +00:00
|
|
|
Intent verifyIdentityIntent = new Intent(this, VerifyIdentityActivity.class);
|
2012-08-02 00:39:36 +00:00
|
|
|
verifyIdentityIntent.putExtra("recipient", getRecipients().getPrimaryRecipient());
|
2012-07-19 21:22:03 +00:00
|
|
|
verifyIdentityIntent.putExtra("master_secret", masterSecret);
|
|
|
|
startActivity(verifyIdentityIntent);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void handleStartSecureSession() {
|
2013-06-01 19:42:21 +00:00
|
|
|
if (getRecipients() == null) {
|
|
|
|
Toast.makeText(this, getString(R.string.ConversationActivity_invalid_recipient),
|
|
|
|
Toast.LENGTH_LONG).show();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-08-02 00:39:36 +00:00
|
|
|
final Recipient recipient = getRecipients().getPrimaryRecipient();
|
2012-07-19 21:22:03 +00:00
|
|
|
String recipientName = (recipient.getName() == null ? recipient.getNumber() : recipient.getName());
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
2012-09-20 02:56:04 +00:00
|
|
|
builder.setTitle(R.string.ConversationActivity_initiate_secure_session_question);
|
2014-03-01 00:32:00 +00:00
|
|
|
builder.setIcon(Dialogs.resolveIcon(this, R.attr.dialog_info_icon));
|
2012-07-19 21:22:03 +00:00
|
|
|
builder.setCancelable(true);
|
2012-09-20 02:56:04 +00:00
|
|
|
builder.setMessage(String.format(getString(R.string.ConversationActivity_initiate_secure_session_with_s_question),
|
|
|
|
recipientName));
|
2012-07-19 21:22:03 +00:00
|
|
|
builder.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
KeyExchangeInitiator.initiate(ConversationActivity.this, masterSecret,
|
2012-08-02 00:39:36 +00:00
|
|
|
recipient, true);
|
2012-07-19 21:22:03 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
builder.setNegativeButton(R.string.no, null);
|
|
|
|
builder.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void handleAbortSecureSession() {
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
2012-09-20 02:56:04 +00:00
|
|
|
builder.setTitle(R.string.ConversationActivity_abort_secure_session_confirmation);
|
2014-03-01 00:32:00 +00:00
|
|
|
builder.setIcon(Dialogs.resolveIcon(this, R.attr.dialog_alert_icon));
|
2012-07-19 21:22:03 +00:00
|
|
|
builder.setCancelable(true);
|
2012-09-20 02:56:04 +00:00
|
|
|
builder.setMessage(R.string.ConversationActivity_are_you_sure_that_you_want_to_abort_this_secure_session_question);
|
2012-07-19 21:22:03 +00:00
|
|
|
builder.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
2012-08-02 00:39:36 +00:00
|
|
|
if (isSingleConversation()) {
|
2014-02-19 21:46:49 +00:00
|
|
|
ConversationActivity self = ConversationActivity.this;
|
|
|
|
Recipient recipient = getRecipients().getPrimaryRecipient();
|
|
|
|
|
|
|
|
if (SessionRecordV2.hasSession(self, masterSecret,
|
|
|
|
recipient.getRecipientId(),
|
|
|
|
RecipientDevice.DEFAULT_DEVICE_ID))
|
|
|
|
{
|
|
|
|
OutgoingEndSessionMessage endSessionMessage =
|
|
|
|
new OutgoingEndSessionMessage(new OutgoingTextMessage(getRecipients(), "TERMINATE"));
|
|
|
|
|
|
|
|
long allocatedThreadId = MessageSender.send(self, masterSecret,
|
|
|
|
endSessionMessage, threadId);
|
|
|
|
|
|
|
|
sendComplete(recipients, allocatedThreadId, allocatedThreadId != self.threadId);
|
|
|
|
} else {
|
|
|
|
Session.abortSessionFor(self, recipient);
|
2014-02-20 20:05:47 +00:00
|
|
|
initializeSecurity();
|
|
|
|
initializeTitleBar();
|
2014-02-19 21:46:49 +00:00
|
|
|
}
|
2012-07-19 21:22:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
builder.setNegativeButton(R.string.no, null);
|
|
|
|
builder.show();
|
|
|
|
}
|
|
|
|
|
2014-02-22 18:54:43 +00:00
|
|
|
private void handleLeavePushGroup() {
|
|
|
|
if (getRecipients() == null) {
|
|
|
|
Toast.makeText(this, getString(R.string.ConversationActivity_invalid_recipient),
|
|
|
|
Toast.LENGTH_LONG).show();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
|
|
|
builder.setTitle(getString(R.string.ConversationActivity_leave_group));
|
2014-03-01 00:32:00 +00:00
|
|
|
builder.setIcon(Dialogs.resolveIcon(this, R.attr.dialog_info_icon));
|
2014-02-22 18:54:43 +00:00
|
|
|
builder.setCancelable(true);
|
|
|
|
builder.setMessage(getString(R.string.ConversationActivity_are_you_sure_you_want_to_leave_this_group));
|
|
|
|
builder.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
try {
|
|
|
|
Context self = ConversationActivity.this;
|
|
|
|
byte[] groupId = GroupUtil.getDecodedId(getRecipients().getPrimaryRecipient().getNumber());
|
|
|
|
DatabaseFactory.getGroupDatabase(self).setActive(groupId, false);
|
|
|
|
|
|
|
|
GroupContext context = GroupContext.newBuilder()
|
|
|
|
.setId(ByteString.copyFrom(groupId))
|
|
|
|
.setType(GroupContext.Type.QUIT)
|
|
|
|
.build();
|
|
|
|
|
|
|
|
OutgoingGroupMediaMessage outgoingMessage = new OutgoingGroupMediaMessage(self, getRecipients(),
|
|
|
|
context, null);
|
|
|
|
MessageSender.send(self, masterSecret, outgoingMessage, threadId);
|
|
|
|
initializeEnabledCheck();
|
|
|
|
} catch (IOException e) {
|
|
|
|
Log.w(TAG, e);
|
2014-02-24 08:19:54 +00:00
|
|
|
Toast.makeText(ConversationActivity.this, "Error leaving group....", Toast.LENGTH_LONG).show();
|
2014-02-22 18:54:43 +00:00
|
|
|
} catch (MmsException e) {
|
|
|
|
Log.w(TAG, e);
|
2014-02-24 08:19:54 +00:00
|
|
|
Toast.makeText(ConversationActivity.this, "Error leaving group...", Toast.LENGTH_LONG).show();
|
2014-02-22 18:54:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
builder.setNegativeButton(R.string.no, null);
|
|
|
|
builder.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void handleEditPushGroup() {
|
|
|
|
Intent intent = new Intent(ConversationActivity.this, GroupCreateActivity.class);
|
|
|
|
intent.putExtra(GroupCreateActivity.MASTER_SECRET_EXTRA, masterSecret);
|
|
|
|
intent.putExtra(GroupCreateActivity.GROUP_RECIPIENT_EXTRA, recipients);
|
|
|
|
startActivityForResult(intent, GROUP_EDIT);
|
|
|
|
}
|
|
|
|
|
2013-04-26 01:59:49 +00:00
|
|
|
private void handleDistributionBroadcastEnabled(MenuItem item) {
|
|
|
|
distributionType = ThreadDatabase.DistributionTypes.BROADCAST;
|
|
|
|
item.setChecked(true);
|
|
|
|
|
|
|
|
if (threadId != -1) {
|
|
|
|
new AsyncTask<Void, Void, Void>() {
|
|
|
|
@Override
|
|
|
|
protected Void doInBackground(Void... params) {
|
|
|
|
DatabaseFactory.getThreadDatabase(ConversationActivity.this)
|
|
|
|
.setDistributionType(threadId, ThreadDatabase.DistributionTypes.BROADCAST);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}.execute();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void handleDistributionConversationEnabled(MenuItem item) {
|
|
|
|
distributionType = ThreadDatabase.DistributionTypes.CONVERSATION;
|
|
|
|
item.setChecked(true);
|
|
|
|
|
|
|
|
if (threadId != -1) {
|
|
|
|
new AsyncTask<Void, Void, Void>() {
|
|
|
|
@Override
|
|
|
|
protected Void doInBackground(Void... params) {
|
|
|
|
DatabaseFactory.getThreadDatabase(ConversationActivity.this)
|
|
|
|
.setDistributionType(threadId, ThreadDatabase.DistributionTypes.CONVERSATION);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}.execute();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-19 21:22:03 +00:00
|
|
|
private void handleDial(Recipient recipient) {
|
2013-06-18 21:43:27 +00:00
|
|
|
try {
|
|
|
|
if (recipient == null) return;
|
|
|
|
|
|
|
|
Intent dialIntent = new Intent(Intent.ACTION_DIAL,
|
|
|
|
Uri.parse("tel:" + recipient.getNumber()));
|
|
|
|
startActivity(dialIntent);
|
|
|
|
} catch (ActivityNotFoundException anfe) {
|
2014-02-18 04:25:40 +00:00
|
|
|
Log.w(TAG, anfe);
|
2014-03-01 00:32:00 +00:00
|
|
|
Dialogs.showAlertDialog(this,
|
2013-06-18 21:43:27 +00:00
|
|
|
getString(R.string.ConversationActivity_calls_not_supported),
|
|
|
|
getString(R.string.ConversationActivity_this_device_does_not_appear_to_support_dial_actions));
|
|
|
|
}
|
2012-07-19 21:22:03 +00:00
|
|
|
}
|
|
|
|
|
2012-10-21 21:34:09 +00:00
|
|
|
private void handleDisplayGroupRecipients() {
|
2014-02-15 19:28:07 +00:00
|
|
|
new GroupMembersDialog(this, getRecipients()).display();
|
2012-10-21 21:34:09 +00:00
|
|
|
}
|
|
|
|
|
2012-07-19 21:22:03 +00:00
|
|
|
private void handleDeleteThread() {
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
2012-09-20 02:56:04 +00:00
|
|
|
builder.setTitle(R.string.ConversationActivity_delete_thread_confirmation);
|
2014-03-01 00:32:00 +00:00
|
|
|
builder.setIcon(Dialogs.resolveIcon(this, R.attr.dialog_alert_icon));
|
2012-07-19 21:22:03 +00:00
|
|
|
builder.setCancelable(true);
|
2012-09-20 02:56:04 +00:00
|
|
|
builder.setMessage(R.string.ConversationActivity_are_you_sure_that_you_want_to_permanently_delete_this_conversation_question);
|
2012-07-19 21:22:03 +00:00
|
|
|
builder.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
if (threadId > 0) {
|
|
|
|
DatabaseFactory.getThreadDatabase(ConversationActivity.this).deleteConversation(threadId);
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
builder.setNegativeButton(R.string.no, null);
|
|
|
|
builder.show();
|
|
|
|
}
|
|
|
|
|
2013-10-17 00:28:36 +00:00
|
|
|
private void handleAddContactInfo() {
|
|
|
|
Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
|
|
|
|
startActivityForResult(intent, PICK_CONTACT_INFO);
|
|
|
|
}
|
|
|
|
|
2012-07-19 21:22:03 +00:00
|
|
|
private void handleAddAttachment() {
|
2014-03-26 21:49:40 +00:00
|
|
|
if (this.isMmsEnabled || DirectoryHelper.isPushDestination(this, getRecipients())) {
|
2014-01-08 22:29:05 +00:00
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(this, R.style.TextSecure_Light_Dialog));
|
2013-03-05 01:43:04 +00:00
|
|
|
builder.setIcon(R.drawable.ic_dialog_attach);
|
|
|
|
builder.setTitle(R.string.ConversationActivity_add_attachment);
|
|
|
|
builder.setAdapter(attachmentAdapter, new AttachmentTypeListener());
|
|
|
|
builder.show();
|
|
|
|
} else {
|
2013-09-16 07:55:01 +00:00
|
|
|
handleManualMmsRequired();
|
2013-03-05 01:43:04 +00:00
|
|
|
}
|
2012-07-19 21:22:03 +00:00
|
|
|
}
|
|
|
|
|
2013-09-16 07:55:01 +00:00
|
|
|
private void handleManualMmsRequired() {
|
|
|
|
Toast.makeText(this, R.string.MmsDownloader_error_reading_mms_settings, Toast.LENGTH_LONG).show();
|
|
|
|
|
|
|
|
Intent intent = new Intent(this, PromptMmsActivity.class);
|
|
|
|
intent.putExtras(getIntent().getExtras());
|
|
|
|
startActivity(intent);
|
|
|
|
}
|
|
|
|
|
2012-07-19 21:22:03 +00:00
|
|
|
///// Initializers
|
|
|
|
|
|
|
|
private void initializeTitleBar() {
|
|
|
|
String title = null;
|
|
|
|
String subtitle = null;
|
|
|
|
|
2012-08-02 00:39:36 +00:00
|
|
|
if (isSingleConversation()) {
|
2013-05-23 23:36:24 +00:00
|
|
|
title = getRecipients().getPrimaryRecipient().getName();
|
2012-07-19 21:22:03 +00:00
|
|
|
|
|
|
|
if (title == null || title.trim().length() == 0) {
|
2012-08-02 00:39:36 +00:00
|
|
|
title = getRecipients().getPrimaryRecipient().getNumber();
|
2012-07-19 21:22:03 +00:00
|
|
|
} else {
|
2012-08-02 00:39:36 +00:00
|
|
|
subtitle = getRecipients().getPrimaryRecipient().getNumber();
|
2012-07-19 21:22:03 +00:00
|
|
|
}
|
2012-10-21 21:34:09 +00:00
|
|
|
} else if (isGroupConversation()) {
|
2014-02-18 04:25:40 +00:00
|
|
|
if (isPushGroupConversation()) {
|
2014-02-18 05:42:30 +00:00
|
|
|
final String groupName = getRecipients().getPrimaryRecipient().getName();
|
|
|
|
title = (!TextUtils.isEmpty(groupName)) ? groupName : getString(R.string.ConversationActivity_unnamed_group);
|
|
|
|
final Bitmap avatar = getRecipients().getPrimaryRecipient().getContactPhoto();
|
|
|
|
if (avatar != null) {
|
2014-02-19 06:08:24 +00:00
|
|
|
getSupportActionBar().setIcon(new BitmapDrawable(getResources(), BitmapUtil.getCircleCroppedBitmap(avatar)));
|
2014-02-18 05:42:30 +00:00
|
|
|
}
|
2014-02-19 00:28:54 +00:00
|
|
|
} else {
|
2014-02-18 04:25:40 +00:00
|
|
|
title = getString(R.string.ConversationActivity_group_conversation);
|
2014-02-24 07:58:16 +00:00
|
|
|
int size = getRecipients().getRecipientsList().size();
|
|
|
|
subtitle = (size == 1) ? getString(R.string.ConversationActivity_d_recipients_in_group_singular)
|
|
|
|
: String.format(getString(R.string.ConversationActivity_d_recipients_in_group), size);
|
2014-02-18 04:25:40 +00:00
|
|
|
}
|
2012-07-19 21:22:03 +00:00
|
|
|
} else {
|
2012-09-20 02:56:04 +00:00
|
|
|
title = getString(R.string.ConversationActivity_compose_message);
|
2012-08-02 00:39:36 +00:00
|
|
|
subtitle = "";
|
2012-07-19 21:22:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.getSupportActionBar().setTitle(title);
|
|
|
|
|
2014-01-08 22:29:05 +00:00
|
|
|
if (subtitle != null && !Util.isEmpty(subtitle))
|
2012-07-19 21:22:03 +00:00
|
|
|
this.getSupportActionBar().setSubtitle(PhoneNumberUtils.formatNumber(subtitle));
|
|
|
|
|
|
|
|
this.invalidateOptionsMenu();
|
|
|
|
}
|
|
|
|
|
2013-02-03 04:37:40 +00:00
|
|
|
private void initializeDraft() {
|
|
|
|
String draftText = getIntent().getStringExtra(DRAFT_TEXT_EXTRA);
|
|
|
|
Uri draftImage = getIntent().getParcelableExtra(DRAFT_IMAGE_EXTRA);
|
|
|
|
Uri draftAudio = getIntent().getParcelableExtra(DRAFT_AUDIO_EXTRA);
|
2014-03-03 16:55:34 +00:00
|
|
|
Uri draftVideo = getIntent().getParcelableExtra(DRAFT_VIDEO_EXTRA);
|
2013-02-03 04:37:40 +00:00
|
|
|
|
|
|
|
if (draftText != null) composeText.setText(draftText);
|
|
|
|
if (draftImage != null) addAttachmentImage(draftImage);
|
|
|
|
if (draftAudio != null) addAttachmentAudio(draftAudio);
|
2014-03-03 16:55:34 +00:00
|
|
|
if (draftVideo != null) addAttachmentVideo(draftVideo);
|
2013-02-04 08:13:07 +00:00
|
|
|
|
2014-03-03 16:55:34 +00:00
|
|
|
if (draftText == null && draftImage == null && draftAudio == null && draftVideo == null) {
|
2013-02-04 08:13:07 +00:00
|
|
|
initializeDraftFromDatabase();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-22 18:54:43 +00:00
|
|
|
private void initializeEnabledCheck() {
|
2014-02-23 22:37:41 +00:00
|
|
|
boolean enabled = !(isPushGroupConversation() && !isActiveGroup());
|
2014-02-22 18:54:43 +00:00
|
|
|
composeText.setEnabled(enabled);
|
|
|
|
sendButton.setEnabled(enabled);
|
|
|
|
}
|
|
|
|
|
2014-02-26 21:28:46 +00:00
|
|
|
private void initializeCharactersLeftViewEnabledCheck() {
|
|
|
|
isCharactersLeftViewEnabled = !(isPushGroupConversation() ||
|
|
|
|
(TextSecurePreferences.isPushRegistered(this) && !TextSecurePreferences.isSmsFallbackEnabled(this)));
|
|
|
|
}
|
|
|
|
|
2013-02-04 08:13:07 +00:00
|
|
|
private void initializeDraftFromDatabase() {
|
|
|
|
new AsyncTask<Void, Void, List<Draft>>() {
|
|
|
|
@Override
|
|
|
|
protected List<Draft> doInBackground(Void... params) {
|
|
|
|
MasterCipher masterCipher = new MasterCipher(masterSecret);
|
|
|
|
DraftDatabase draftDatabase = DatabaseFactory.getDraftDatabase(ConversationActivity.this);
|
|
|
|
List<Draft> results = draftDatabase.getDrafts(masterCipher, threadId);
|
|
|
|
|
|
|
|
draftDatabase.clearDrafts(threadId);
|
|
|
|
|
|
|
|
return results;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onPostExecute(List<Draft> drafts) {
|
|
|
|
for (Draft draft : drafts) {
|
|
|
|
if (draft.getType().equals(Draft.TEXT)) composeText.setText(draft.getValue());
|
|
|
|
else if (draft.getType().equals(Draft.IMAGE)) addAttachmentImage(Uri.parse(draft.getValue()));
|
|
|
|
else if (draft.getType().equals(Draft.AUDIO)) addAttachmentAudio(Uri.parse(draft.getValue()));
|
|
|
|
else if (draft.getType().equals(Draft.VIDEO)) addAttachmentVideo(Uri.parse(draft.getValue()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}.execute();
|
2013-02-03 04:37:40 +00:00
|
|
|
}
|
|
|
|
|
2012-08-02 00:39:36 +00:00
|
|
|
private void initializeSecurity() {
|
2014-04-03 17:47:51 +00:00
|
|
|
TypedArray drawables = obtainStyledAttributes(SEND_ATTRIBUTES);
|
|
|
|
boolean isPushDestination = DirectoryHelper.isPushDestination(this, getRecipients());
|
|
|
|
Recipient primaryRecipient = getRecipients() == null ? null : getRecipients().getPrimaryRecipient();
|
2013-06-21 18:56:59 +00:00
|
|
|
|
2014-04-03 17:47:51 +00:00
|
|
|
if (isPushDestination ||
|
|
|
|
(isSingleConversation() && Session.hasSession(this, masterSecret, primaryRecipient)))
|
2012-07-19 21:22:03 +00:00
|
|
|
{
|
2013-05-23 23:36:24 +00:00
|
|
|
this.isEncryptedConversation = true;
|
2014-04-03 17:47:51 +00:00
|
|
|
this.isAuthenticatedConversation = Session.hasRemoteIdentityKey(this, masterSecret, primaryRecipient);
|
2013-05-23 23:36:24 +00:00
|
|
|
this.characterCalculator = new EncryptedCharacterCalculator();
|
2014-04-03 17:47:51 +00:00
|
|
|
|
|
|
|
if (isPushDestination) sendButton.setImageDrawable(drawables.getDrawable(0));
|
|
|
|
else sendButton.setImageDrawable(drawables.getDrawable(1));
|
2012-07-19 21:22:03 +00:00
|
|
|
} else {
|
2013-05-23 23:36:24 +00:00
|
|
|
this.isEncryptedConversation = false;
|
|
|
|
this.isAuthenticatedConversation = false;
|
|
|
|
this.characterCalculator = new CharacterCalculator();
|
2014-03-20 07:54:05 +00:00
|
|
|
sendButton.setImageDrawable(drawables.getDrawable(2));
|
|
|
|
}
|
|
|
|
|
2013-06-21 18:56:59 +00:00
|
|
|
drawables.recycle();
|
2014-03-20 07:54:05 +00:00
|
|
|
|
|
|
|
calculateCharactersRemaining();
|
2012-07-19 21:22:03 +00:00
|
|
|
}
|
|
|
|
|
2013-03-05 01:43:04 +00:00
|
|
|
private void initializeMmsEnabledCheck() {
|
|
|
|
new AsyncTask<Void, Void, Boolean>() {
|
|
|
|
@Override
|
|
|
|
protected Boolean doInBackground(Void... params) {
|
|
|
|
return MmsSendHelper.hasNecessaryApnDetails(ConversationActivity.this);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onPostExecute(Boolean isMmsEnabled) {
|
|
|
|
ConversationActivity.this.isMmsEnabled = isMmsEnabled;
|
|
|
|
}
|
|
|
|
}.execute();
|
|
|
|
}
|
|
|
|
|
2013-06-29 22:34:43 +00:00
|
|
|
private void initializeIme() {
|
2013-07-10 01:26:18 +00:00
|
|
|
if (TextSecurePreferences.isEnterImeKeyEnabled(this)) {
|
2013-06-29 22:34:43 +00:00
|
|
|
composeText.setInputType(composeText.getInputType() & (~InputType.TYPE_TEXT_VARIATION_SHORT_MESSAGE));
|
|
|
|
} else {
|
|
|
|
composeText.setInputType(composeText.getInputType() | (InputType.TYPE_TEXT_VARIATION_SHORT_MESSAGE));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-19 21:22:03 +00:00
|
|
|
private void initializeResources() {
|
2014-02-17 23:47:58 +00:00
|
|
|
recipientsPanel = (RecipientsPanel)findViewById(R.id.recipients);
|
2014-02-24 08:19:54 +00:00
|
|
|
recipients = RecipientFactory.getRecipientsForIds(this, getIntent().getStringExtra(RECIPIENTS_EXTRA), true);
|
2013-04-26 01:59:49 +00:00
|
|
|
threadId = getIntent().getLongExtra(THREAD_ID_EXTRA, -1);
|
|
|
|
distributionType = getIntent().getIntExtra(DISTRIBUTION_TYPE_EXTRA,
|
|
|
|
ThreadDatabase.DistributionTypes.DEFAULT);
|
2012-07-19 21:22:03 +00:00
|
|
|
addContactButton = (ImageButton)findViewById(R.id.contacts_button);
|
2013-03-06 03:32:15 +00:00
|
|
|
sendButton = (ImageButton)findViewById(R.id.send_button);
|
2012-07-19 21:22:03 +00:00
|
|
|
composeText = (EditText)findViewById(R.id.embedded_text_editor);
|
2013-04-26 01:59:49 +00:00
|
|
|
masterSecret = getIntent().getParcelableExtra(MASTER_SECRET_EXTRA);
|
2012-07-19 21:22:03 +00:00
|
|
|
charactersLeft = (TextView)findViewById(R.id.space_left);
|
2013-06-28 03:57:27 +00:00
|
|
|
emojiDrawer = (EmojiDrawer)findViewById(R.id.emoji_drawer);
|
|
|
|
emojiToggle = (EmojiToggle)findViewById(R.id.emoji_toggle);
|
2012-07-19 21:22:03 +00:00
|
|
|
|
2014-01-08 22:29:05 +00:00
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
|
|
|
emojiToggle.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
|
2012-07-19 21:22:03 +00:00
|
|
|
attachmentAdapter = new AttachmentTypeSelectorAdapter(this);
|
|
|
|
attachmentManager = new AttachmentManager(this);
|
|
|
|
|
2013-06-28 03:57:27 +00:00
|
|
|
SendButtonListener sendButtonListener = new SendButtonListener();
|
|
|
|
ComposeKeyPressedListener composeKeyPressedListener = new ComposeKeyPressedListener();
|
2012-07-19 21:22:03 +00:00
|
|
|
|
|
|
|
recipientsPanel.setPanelChangeListener(new RecipientsPanelChangeListener());
|
|
|
|
sendButton.setOnClickListener(sendButtonListener);
|
2013-03-14 00:45:32 +00:00
|
|
|
sendButton.setEnabled(true);
|
2012-07-19 21:22:03 +00:00
|
|
|
addContactButton.setOnClickListener(new AddRecipientButtonListener());
|
2013-06-28 03:57:27 +00:00
|
|
|
composeText.setOnKeyListener(composeKeyPressedListener);
|
|
|
|
composeText.addTextChangedListener(composeKeyPressedListener);
|
2012-07-19 21:22:03 +00:00
|
|
|
composeText.setOnEditorActionListener(sendButtonListener);
|
2013-06-28 03:57:27 +00:00
|
|
|
composeText.setOnClickListener(composeKeyPressedListener);
|
|
|
|
emojiDrawer.setComposeEditText(composeText);
|
|
|
|
emojiToggle.setOnClickListener(new EmojiToggleListener());
|
2012-07-19 21:22:03 +00:00
|
|
|
|
2014-02-24 08:19:54 +00:00
|
|
|
recipients.addListener(new RecipientModifiedListener() {
|
|
|
|
@Override
|
|
|
|
public void onModified(Recipient recipient) {
|
|
|
|
initializeTitleBar();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-07-19 21:22:03 +00:00
|
|
|
registerForContextMenu(sendButton);
|
|
|
|
|
2014-02-26 21:15:45 +00:00
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB && TextSecurePreferences.isScreenSecurityEnabled(this)) {
|
2012-11-21 02:49:56 +00:00
|
|
|
getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
|
|
|
|
}
|
|
|
|
|
2013-06-29 22:34:43 +00:00
|
|
|
if (getIntent().getStringExtra("forwarded_message") != null) {
|
|
|
|
composeText.setText(getString(R.string.ConversationActivity_forward_message_prefix) + ": " +
|
|
|
|
getIntent().getStringExtra("forwarded_message"));
|
|
|
|
}
|
2014-03-20 07:54:05 +00:00
|
|
|
|
2012-07-19 21:22:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void initializeRecipientsInput() {
|
2014-02-18 00:19:38 +00:00
|
|
|
if (recipients == null || recipients.isEmpty()) {
|
2014-02-17 23:47:58 +00:00
|
|
|
recipientsPanel.setVisibility(View.VISIBLE);
|
2014-02-18 00:19:38 +00:00
|
|
|
} else if (recipients != null) {
|
2014-02-17 23:47:58 +00:00
|
|
|
recipientsPanel.addRecipients(this.recipients);
|
|
|
|
} else {
|
|
|
|
InputMethodManager input = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
|
|
|
|
input.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, 0);
|
|
|
|
}
|
2012-07-19 21:22:03 +00:00
|
|
|
}
|
2014-02-16 02:40:08 +00:00
|
|
|
|
2012-07-19 21:22:03 +00:00
|
|
|
private void initializeReceivers() {
|
|
|
|
securityUpdateReceiver = new BroadcastReceiver() {
|
|
|
|
@Override
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
|
|
|
if (intent.getLongExtra("thread_id", -1) == -1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (intent.getLongExtra("thread_id", -1) == threadId) {
|
2012-08-02 00:39:36 +00:00
|
|
|
initializeSecurity();
|
2012-07-19 21:22:03 +00:00
|
|
|
initializeTitleBar();
|
|
|
|
calculateCharactersRemaining();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-02-24 08:19:54 +00:00
|
|
|
groupUpdateReceiver = new BroadcastReceiver() {
|
|
|
|
@Override
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
|
|
|
Log.w("ConversationActivity", "Group update received...");
|
|
|
|
if (recipients != null) {
|
|
|
|
String ids = recipients.toIdString();
|
|
|
|
Log.w("ConversationActivity", "Looking up new recipients...");
|
2014-02-24 08:37:11 +00:00
|
|
|
recipients = RecipientFactory.getRecipientsForIds(context, ids, false);
|
|
|
|
initializeTitleBar();
|
2014-02-24 08:19:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-07-19 21:22:03 +00:00
|
|
|
registerReceiver(securityUpdateReceiver,
|
|
|
|
new IntentFilter(KeyExchangeProcessor.SECURITY_UPDATE_EVENT),
|
|
|
|
KeyCachingService.KEY_PERMISSION, null);
|
2014-02-24 08:19:54 +00:00
|
|
|
|
|
|
|
registerReceiver(groupUpdateReceiver,
|
|
|
|
new IntentFilter(GroupDatabase.DATABASE_UPDATE_ACTION));
|
2012-07-19 21:22:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////// Helper Methods
|
|
|
|
|
|
|
|
private void addAttachment(int type) {
|
|
|
|
Log.w("ComposeMessageActivity", "Selected: " + type);
|
|
|
|
switch (type) {
|
|
|
|
case AttachmentTypeSelectorAdapter.ADD_IMAGE:
|
|
|
|
AttachmentManager.selectImage(this, PICK_IMAGE); break;
|
|
|
|
case AttachmentTypeSelectorAdapter.ADD_VIDEO:
|
|
|
|
AttachmentManager.selectVideo(this, PICK_VIDEO); break;
|
|
|
|
case AttachmentTypeSelectorAdapter.ADD_SOUND:
|
|
|
|
AttachmentManager.selectAudio(this, PICK_AUDIO); break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void addAttachmentImage(Uri imageUri) {
|
|
|
|
try {
|
|
|
|
attachmentManager.setImage(imageUri);
|
|
|
|
} catch (IOException e) {
|
2014-02-18 04:25:40 +00:00
|
|
|
Log.w(TAG, e);
|
2013-05-21 17:32:48 +00:00
|
|
|
attachmentManager.clear();
|
|
|
|
Toast.makeText(this, R.string.ConversationActivity_sorry_there_was_an_error_setting_your_attachment,
|
|
|
|
Toast.LENGTH_LONG).show();
|
|
|
|
} catch (BitmapDecodingException e) {
|
2014-02-18 04:25:40 +00:00
|
|
|
Log.w(TAG, e);
|
2012-07-19 21:22:03 +00:00
|
|
|
attachmentManager.clear();
|
2012-09-20 02:56:04 +00:00
|
|
|
Toast.makeText(this, R.string.ConversationActivity_sorry_there_was_an_error_setting_your_attachment,
|
2012-07-19 21:22:03 +00:00
|
|
|
Toast.LENGTH_LONG).show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void addAttachmentVideo(Uri videoUri) {
|
|
|
|
try {
|
|
|
|
attachmentManager.setVideo(videoUri);
|
|
|
|
} catch (IOException e) {
|
|
|
|
attachmentManager.clear();
|
2012-09-20 02:56:04 +00:00
|
|
|
Toast.makeText(this, R.string.ConversationActivity_sorry_there_was_an_error_setting_your_attachment,
|
2012-07-19 21:22:03 +00:00
|
|
|
Toast.LENGTH_LONG).show();
|
|
|
|
Log.w("ComposeMessageActivity", e);
|
|
|
|
} catch (MediaTooLargeException e) {
|
|
|
|
attachmentManager.clear();
|
2012-09-20 02:56:04 +00:00
|
|
|
Toast.makeText(this, R.string.ConversationActivity_sorry_the_selected_video_exceeds_message_size_restrictions,
|
2012-07-19 21:22:03 +00:00
|
|
|
Toast.LENGTH_LONG).show();
|
|
|
|
Log.w("ComposeMessageActivity", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void addAttachmentAudio(Uri audioUri) {
|
|
|
|
try {
|
|
|
|
attachmentManager.setAudio(audioUri);
|
|
|
|
} catch (IOException e) {
|
|
|
|
attachmentManager.clear();
|
2012-09-20 02:56:04 +00:00
|
|
|
Toast.makeText(this, R.string.ConversationActivity_sorry_there_was_an_error_setting_your_attachment,
|
2012-07-19 21:22:03 +00:00
|
|
|
Toast.LENGTH_LONG).show();
|
|
|
|
Log.w("ComposeMessageActivity", e);
|
|
|
|
} catch (MediaTooLargeException e) {
|
|
|
|
attachmentManager.clear();
|
2012-09-20 02:56:04 +00:00
|
|
|
Toast.makeText(this, R.string.ConversationActivity_sorry_the_selected_audio_exceeds_message_size_restrictions,
|
2012-07-19 21:22:03 +00:00
|
|
|
Toast.LENGTH_LONG).show();
|
|
|
|
Log.w("ComposeMessageActivity", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-17 00:28:36 +00:00
|
|
|
private void addContactInfo(Uri contactUri) {
|
|
|
|
ContactAccessor contactDataList = ContactAccessor.getInstance();
|
|
|
|
ContactData contactData = contactDataList.getContactData(this, contactUri);
|
|
|
|
|
|
|
|
if (contactData.numbers.size() == 1) composeText.append(contactData.numbers.get(0).number);
|
|
|
|
else if (contactData.numbers.size() > 1) selectContactInfo(contactData);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void selectContactInfo(ContactData contactData) {
|
|
|
|
final CharSequence[] numbers = new CharSequence[contactData.numbers.size()];
|
|
|
|
final CharSequence[] numberItems = new CharSequence[contactData.numbers.size()];
|
|
|
|
for (int i = 0; i < contactData.numbers.size(); i++) {
|
|
|
|
numbers[i] = contactData.numbers.get(i).number;
|
|
|
|
numberItems[i] = contactData.numbers.get(i).type + ": " + contactData.numbers.get(i).number;
|
|
|
|
}
|
|
|
|
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
|
|
|
builder.setIcon(R.drawable.ic_contact_picture);
|
|
|
|
builder.setTitle(R.string.ConversationActivity_select_contact_info);
|
|
|
|
|
|
|
|
builder.setItems(numberItems, new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
composeText.append(numbers[which]);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
builder.show();
|
|
|
|
}
|
|
|
|
|
2013-02-04 08:13:07 +00:00
|
|
|
private List<Draft> getDraftsForCurrentState() {
|
|
|
|
List<Draft> drafts = new LinkedList<Draft>();
|
|
|
|
|
|
|
|
if (!Util.isEmpty(composeText)) {
|
|
|
|
drafts.add(new Draft(Draft.TEXT, composeText.getText().toString()));
|
|
|
|
}
|
|
|
|
|
|
|
|
for (Slide slide : attachmentManager.getSlideDeck().getSlides()) {
|
|
|
|
if (slide.hasImage()) drafts.add(new Draft(Draft.IMAGE, slide.getUri().toString()));
|
|
|
|
else if (slide.hasAudio()) drafts.add(new Draft(Draft.AUDIO, slide.getUri().toString()));
|
|
|
|
else if (slide.hasVideo()) drafts.add(new Draft(Draft.VIDEO, slide.getUri().toString()));
|
|
|
|
}
|
|
|
|
|
|
|
|
return drafts;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void saveDraft() {
|
|
|
|
if (this.threadId <= 0 || this.recipients == null || this.recipients.isEmpty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
final List<Draft> drafts = getDraftsForCurrentState();
|
|
|
|
|
|
|
|
if (drafts.size() <= 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
final long thisThreadId = this.threadId;
|
|
|
|
final MasterSecret thisMasterSecret = this.masterSecret.parcelClone();
|
|
|
|
|
|
|
|
new AsyncTask<Void, Void, Void>() {
|
|
|
|
@Override
|
|
|
|
protected void onPreExecute() {
|
2013-02-04 19:12:03 +00:00
|
|
|
Toast.makeText(ConversationActivity.this,
|
|
|
|
R.string.ConversationActivity_saving_draft,
|
|
|
|
Toast.LENGTH_SHORT).show();
|
2013-02-04 08:13:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected Void doInBackground(Void... params) {
|
|
|
|
MasterCipher masterCipher = new MasterCipher(thisMasterSecret);
|
|
|
|
DatabaseFactory.getDraftDatabase(ConversationActivity.this).insertDrafts(masterCipher, thisThreadId, drafts);
|
|
|
|
MemoryCleaner.clean(thisMasterSecret);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}.execute();
|
|
|
|
}
|
|
|
|
|
2012-07-19 21:22:03 +00:00
|
|
|
private void calculateCharactersRemaining() {
|
2013-06-28 03:57:27 +00:00
|
|
|
int charactersSpent = composeText.getText().toString().length();
|
2012-07-19 21:22:03 +00:00
|
|
|
CharacterCalculator.CharacterState characterState = characterCalculator.calculateCharacters(charactersSpent);
|
2014-02-26 21:28:46 +00:00
|
|
|
if (characterState.charactersRemaining <= 15 && charactersLeft.getVisibility() != View.VISIBLE && isCharactersLeftViewEnabled) {
|
2014-01-08 22:29:05 +00:00
|
|
|
charactersLeft.setVisibility(View.VISIBLE);
|
|
|
|
} else if (characterState.charactersRemaining > 15 && charactersLeft.getVisibility() != View.GONE) {
|
|
|
|
charactersLeft.setVisibility(View.GONE);
|
|
|
|
}
|
2012-07-19 21:22:03 +00:00
|
|
|
charactersLeft.setText(characterState.charactersRemaining + "/" + characterState.maxMessageSize + " (" + characterState.messagesSpent + ")");
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean isExistingConversation() {
|
|
|
|
return this.recipients != null && this.threadId != -1;
|
|
|
|
}
|
|
|
|
|
2012-08-02 00:39:36 +00:00
|
|
|
private boolean isSingleConversation() {
|
2014-02-14 23:59:57 +00:00
|
|
|
return getRecipients() != null && getRecipients().isSingleRecipient() && !getRecipients().isGroupRecipient();
|
2012-10-21 21:34:09 +00:00
|
|
|
}
|
|
|
|
|
2014-02-22 18:54:43 +00:00
|
|
|
private boolean isActiveGroup() {
|
|
|
|
if (!isGroupConversation()) return false;
|
|
|
|
|
|
|
|
try {
|
|
|
|
byte[] groupId = GroupUtil.getDecodedId(getRecipients().getPrimaryRecipient().getNumber());
|
|
|
|
GroupRecord record = DatabaseFactory.getGroupDatabase(this).getGroup(groupId);
|
|
|
|
|
2014-02-24 05:18:08 +00:00
|
|
|
return record != null && record.isActive();
|
2014-02-22 18:54:43 +00:00
|
|
|
} catch (IOException e) {
|
|
|
|
Log.w("ConversationActivity", e);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-21 21:34:09 +00:00
|
|
|
private boolean isGroupConversation() {
|
2014-02-14 23:59:57 +00:00
|
|
|
return getRecipients() != null &&
|
|
|
|
(!getRecipients().isSingleRecipient() || getRecipients().isGroupRecipient());
|
2012-07-19 21:22:03 +00:00
|
|
|
}
|
|
|
|
|
2014-02-18 04:25:40 +00:00
|
|
|
private boolean isPushGroupConversation() {
|
2014-02-24 08:19:54 +00:00
|
|
|
return getRecipients() != null && getRecipients().isGroupRecipient();
|
2014-02-18 04:25:40 +00:00
|
|
|
}
|
|
|
|
|
2012-08-02 00:39:36 +00:00
|
|
|
private Recipients getRecipients() {
|
|
|
|
try {
|
|
|
|
if (isExistingConversation()) return this.recipients;
|
|
|
|
else return recipientsPanel.getRecipients();
|
|
|
|
} catch (RecipientFormattingException rfe) {
|
2014-02-18 04:25:40 +00:00
|
|
|
Log.d(TAG, "Empty list of recipients retrieved from RecipientsPanel.");
|
2012-08-02 00:39:36 +00:00
|
|
|
return null;
|
|
|
|
}
|
2012-07-19 21:22:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private String getMessage() throws InvalidMessageException {
|
2012-09-08 04:21:12 +00:00
|
|
|
String rawText = composeText.getText().toString();
|
2012-07-19 21:22:03 +00:00
|
|
|
|
|
|
|
if (rawText.length() < 1 && !attachmentManager.isAttachmentPresent())
|
2012-09-20 02:56:04 +00:00
|
|
|
throw new InvalidMessageException(getString(R.string.ConversationActivity_message_is_empty_exclamation));
|
2012-07-19 21:22:03 +00:00
|
|
|
|
2013-07-10 01:26:18 +00:00
|
|
|
if (!isEncryptedConversation && Tag.isTaggable(rawText))
|
2012-09-08 04:21:12 +00:00
|
|
|
rawText = Tag.getTaggedMessage(rawText);
|
2012-07-19 21:22:03 +00:00
|
|
|
|
|
|
|
return rawText;
|
|
|
|
}
|
|
|
|
|
2013-02-04 02:41:34 +00:00
|
|
|
private void markThreadAsRead() {
|
|
|
|
new AsyncTask<Long, Void, Void>() {
|
|
|
|
@Override
|
|
|
|
protected Void doInBackground(Long... params) {
|
|
|
|
DatabaseFactory.getThreadDatabase(ConversationActivity.this).setRead(params[0]);
|
2013-02-08 19:57:54 +00:00
|
|
|
MessageNotifier.updateNotification(ConversationActivity.this, masterSecret);
|
2013-02-04 02:41:34 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}.execute(threadId);
|
|
|
|
}
|
|
|
|
|
2014-02-17 23:47:58 +00:00
|
|
|
private void sendComplete(Recipients recipients, long threadId, boolean refreshFragment) {
|
2012-07-19 21:22:03 +00:00
|
|
|
attachmentManager.clear();
|
|
|
|
recipientsPanel.disable();
|
|
|
|
composeText.setText("");
|
|
|
|
|
|
|
|
this.recipients = recipients;
|
|
|
|
this.threadId = threadId;
|
|
|
|
|
2014-03-26 22:11:56 +00:00
|
|
|
ConversationFragment fragment = (ConversationFragment) getSupportFragmentManager()
|
|
|
|
.findFragmentById(R.id.fragment_content);
|
2014-02-17 23:47:58 +00:00
|
|
|
if (refreshFragment) {
|
2012-07-31 23:27:58 +00:00
|
|
|
fragment.reload(recipients, threadId);
|
2012-07-19 21:22:03 +00:00
|
|
|
|
|
|
|
this.recipientsPanel.setVisibility(View.GONE);
|
|
|
|
initializeTitleBar();
|
2012-08-02 00:39:36 +00:00
|
|
|
initializeSecurity();
|
2012-07-19 21:22:03 +00:00
|
|
|
}
|
2014-03-26 22:11:56 +00:00
|
|
|
fragment.scrollToBottom();
|
2012-07-19 21:22:03 +00:00
|
|
|
}
|
|
|
|
|
2012-10-22 00:41:44 +00:00
|
|
|
private void sendMessage(boolean forcePlaintext) {
|
2012-07-19 21:22:03 +00:00
|
|
|
try {
|
2014-04-01 01:47:24 +00:00
|
|
|
Recipients recipients = getRecipients();
|
2012-08-02 00:39:36 +00:00
|
|
|
|
|
|
|
if (recipients == null)
|
|
|
|
throw new RecipientFormattingException("Badly formatted");
|
|
|
|
|
2014-02-20 05:06:54 +00:00
|
|
|
String body = getMessage();
|
2012-07-19 21:22:03 +00:00
|
|
|
long allocatedThreadId;
|
|
|
|
|
2013-09-16 07:55:01 +00:00
|
|
|
if ((!recipients.isSingleRecipient() || recipients.isEmailRecipient()) && !isMmsEnabled) {
|
|
|
|
handleManualMmsRequired();
|
|
|
|
return;
|
2014-02-20 05:06:54 +00:00
|
|
|
} else if (attachmentManager.isAttachmentPresent() || !recipients.isSingleRecipient() || recipients.isGroupRecipient()) {
|
|
|
|
SlideDeck slideDeck;
|
|
|
|
|
|
|
|
if (attachmentManager.isAttachmentPresent()) slideDeck = attachmentManager.getSlideDeck();
|
|
|
|
else slideDeck = new SlideDeck();
|
|
|
|
|
|
|
|
OutgoingMediaMessage outgoingMessage = new OutgoingMediaMessage(this, recipients, slideDeck,
|
|
|
|
body, distributionType);
|
|
|
|
|
|
|
|
if (isEncryptedConversation && !forcePlaintext) {
|
|
|
|
outgoingMessage = new OutgoingSecureMediaMessage(outgoingMessage);
|
|
|
|
}
|
|
|
|
|
|
|
|
allocatedThreadId = MessageSender.send(this, masterSecret, outgoingMessage, threadId);
|
2012-07-19 21:22:03 +00:00
|
|
|
} else {
|
Major storage layer refactoring to set the stage for clean GCM.
1) We now try to hand out cursors at a minimum. There has always been
a fairly clean insertion layer that handles encrypting message bodies,
but the process of decrypting message bodies has always been less than
ideal. Here we introduce a "Reader" interface that will decrypt message
bodies when appropriate and return objects that encapsulate record state.
No more MessageDisplayHelper. The MmsSmsDatabase interface is also more
sane.
2) We finally rid ourselves of the technical debt associated with TextSecure's
initial usage of the default SMS DB. In that world, we weren't able to use
anything other than the default "Inbox, Outbox, Sent" types to describe a
message, and had to overload the message content itself with a set of
local "prefixes" to describe what it was (encrypted, asymetric encrypted,
remote encrypted, a key exchange, procssed key exchange), and so on.
This includes a major schema update that transforms the "type" field into
a bitmask that describes everything that used to be encoded in a prefix,
and prefixes have been completely eliminated from the system.
No more Prefix.java
3) Refactoring of the MultipartMessageHandler code. It's less of a mess, and
hopefully more clear as to what's going on.
The next step is to remove what we can from SmsTransportDetails and genericize
that interface for a GCM equivalent.
2013-04-20 19:22:04 +00:00
|
|
|
OutgoingTextMessage message;
|
|
|
|
|
|
|
|
if (isEncryptedConversation && !forcePlaintext) {
|
|
|
|
message = new OutgoingEncryptedMessage(recipients, body);
|
|
|
|
} else {
|
|
|
|
message = new OutgoingTextMessage(recipients, body);
|
|
|
|
}
|
|
|
|
|
2014-02-18 04:25:40 +00:00
|
|
|
Log.w(TAG, "Sending message...");
|
Major storage layer refactoring to set the stage for clean GCM.
1) We now try to hand out cursors at a minimum. There has always been
a fairly clean insertion layer that handles encrypting message bodies,
but the process of decrypting message bodies has always been less than
ideal. Here we introduce a "Reader" interface that will decrypt message
bodies when appropriate and return objects that encapsulate record state.
No more MessageDisplayHelper. The MmsSmsDatabase interface is also more
sane.
2) We finally rid ourselves of the technical debt associated with TextSecure's
initial usage of the default SMS DB. In that world, we weren't able to use
anything other than the default "Inbox, Outbox, Sent" types to describe a
message, and had to overload the message content itself with a set of
local "prefixes" to describe what it was (encrypted, asymetric encrypted,
remote encrypted, a key exchange, procssed key exchange), and so on.
This includes a major schema update that transforms the "type" field into
a bitmask that describes everything that used to be encoded in a prefix,
and prefixes have been completely eliminated from the system.
No more Prefix.java
3) Refactoring of the MultipartMessageHandler code. It's less of a mess, and
hopefully more clear as to what's going on.
The next step is to remove what we can from SmsTransportDetails and genericize
that interface for a GCM equivalent.
2013-04-20 19:22:04 +00:00
|
|
|
allocatedThreadId = MessageSender.send(ConversationActivity.this, masterSecret,
|
|
|
|
message, threadId);
|
2012-07-19 21:22:03 +00:00
|
|
|
}
|
2014-02-20 05:06:54 +00:00
|
|
|
|
2014-02-17 23:47:58 +00:00
|
|
|
sendComplete(recipients, allocatedThreadId, allocatedThreadId != this.threadId);
|
2012-07-19 21:22:03 +00:00
|
|
|
} catch (RecipientFormattingException ex) {
|
2012-09-08 03:03:23 +00:00
|
|
|
Toast.makeText(ConversationActivity.this,
|
2012-09-20 02:56:04 +00:00
|
|
|
R.string.ConversationActivity_recipient_is_not_a_valid_sms_or_email_address_exclamation,
|
2012-09-08 03:03:23 +00:00
|
|
|
Toast.LENGTH_LONG).show();
|
2014-02-18 04:25:40 +00:00
|
|
|
Log.w(TAG, ex);
|
2012-07-19 21:22:03 +00:00
|
|
|
} catch (InvalidMessageException ex) {
|
2012-09-20 02:56:04 +00:00
|
|
|
Toast.makeText(ConversationActivity.this, R.string.ConversationActivity_message_is_empty_exclamation,
|
2012-09-08 03:03:23 +00:00
|
|
|
Toast.LENGTH_SHORT).show();
|
2014-02-18 04:25:40 +00:00
|
|
|
Log.w(TAG, ex);
|
2012-07-19 21:22:03 +00:00
|
|
|
} catch (MmsException e) {
|
2014-02-18 04:25:40 +00:00
|
|
|
Log.w(TAG, e);
|
2012-07-19 21:22:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Listeners
|
|
|
|
|
|
|
|
private class AddRecipientButtonListener implements OnClickListener {
|
2013-02-03 04:37:40 +00:00
|
|
|
@Override
|
2012-07-19 21:22:03 +00:00
|
|
|
public void onClick(View v) {
|
|
|
|
Intent intent = new Intent(ConversationActivity.this, ContactSelectionActivity.class);
|
|
|
|
startActivityForResult(intent, PICK_CONTACT);
|
|
|
|
}
|
2013-04-26 01:59:49 +00:00
|
|
|
}
|
2012-07-19 21:22:03 +00:00
|
|
|
|
|
|
|
private class AttachmentTypeListener implements DialogInterface.OnClickListener {
|
2013-02-03 04:37:40 +00:00
|
|
|
@Override
|
2012-07-19 21:22:03 +00:00
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
addAttachment(attachmentAdapter.buttonToCommand(which));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private class RecipientsPanelChangeListener implements RecipientsPanel.RecipientsPanelChangedListener {
|
2013-02-03 04:37:40 +00:00
|
|
|
@Override
|
2012-07-19 21:22:03 +00:00
|
|
|
public void onRecipientsPanelUpdate(Recipients recipients) {
|
2012-08-02 00:39:36 +00:00
|
|
|
initializeSecurity();
|
|
|
|
initializeTitleBar();
|
|
|
|
calculateCharactersRemaining();
|
2012-07-19 21:22:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-28 03:57:27 +00:00
|
|
|
private class EmojiToggleListener implements OnClickListener {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
InputMethodManager input = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
|
|
|
|
|
|
|
|
if (emojiDrawer.getVisibility() == View.VISIBLE) {
|
|
|
|
input.showSoftInput(composeText, 0);
|
|
|
|
emojiDrawer.setVisibility(View.GONE);
|
|
|
|
} else {
|
|
|
|
input.hideSoftInputFromWindow(composeText.getWindowToken(), 0);
|
|
|
|
emojiDrawer.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-19 21:22:03 +00:00
|
|
|
private class SendButtonListener implements OnClickListener, TextView.OnEditorActionListener {
|
2013-02-03 04:37:40 +00:00
|
|
|
@Override
|
2012-07-19 21:22:03 +00:00
|
|
|
public void onClick(View v) {
|
2012-10-22 00:41:44 +00:00
|
|
|
sendMessage(false);
|
2012-07-19 21:22:03 +00:00
|
|
|
}
|
|
|
|
|
2013-02-03 04:37:40 +00:00
|
|
|
@Override
|
2012-07-19 21:22:03 +00:00
|
|
|
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
|
|
|
if (actionId == EditorInfo.IME_ACTION_SEND) {
|
|
|
|
sendButton.performClick();
|
|
|
|
composeText.clearFocus();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2013-04-26 01:59:49 +00:00
|
|
|
}
|
2012-07-19 21:22:03 +00:00
|
|
|
|
2013-06-28 03:57:27 +00:00
|
|
|
private class ComposeKeyPressedListener implements OnKeyListener, OnClickListener, TextWatcher {
|
|
|
|
@Override
|
|
|
|
public boolean onKey(View v, int keyCode, KeyEvent event) {
|
|
|
|
if (event.getAction() == KeyEvent.ACTION_DOWN) {
|
|
|
|
if (keyCode == KeyEvent.KEYCODE_ENTER) {
|
2013-07-10 01:26:18 +00:00
|
|
|
if (TextSecurePreferences.isEnterSendsEnabled(ConversationActivity.this)) {
|
2013-06-28 03:57:27 +00:00
|
|
|
sendButton.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_ENTER));
|
|
|
|
sendButton.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_ENTER));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
if (emojiDrawer.isOpen()) {
|
|
|
|
emojiToggle.performClick();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-03 04:37:40 +00:00
|
|
|
@Override
|
2012-07-19 21:22:03 +00:00
|
|
|
public void afterTextChanged(Editable s) {
|
|
|
|
calculateCharactersRemaining();
|
|
|
|
}
|
2013-02-03 04:37:40 +00:00
|
|
|
@Override
|
2012-07-19 21:22:03 +00:00
|
|
|
public void beforeTextChanged(CharSequence s, int start, int count,int after) {}
|
2013-02-03 04:37:40 +00:00
|
|
|
@Override
|
2012-07-19 21:22:03 +00:00
|
|
|
public void onTextChanged(CharSequence s, int start, int before,int count) {}
|
|
|
|
}
|
2012-08-04 00:34:09 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setComposeText(String text) {
|
|
|
|
this.composeText.setText(text);
|
|
|
|
}
|
2013-06-28 03:57:27 +00:00
|
|
|
|
2012-07-19 21:22:03 +00:00
|
|
|
}
|