diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 83e421d0cea..df685446b41 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -174,10 +174,6 @@
android:label="@string/AndroidManifest__verify_identity"
android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout|screenSize"/>
-
-
diff --git a/res/layout/receive_key_activity.xml b/res/layout/receive_key_activity.xml
deleted file mode 100644
index 85638cf6f0e..00000000000
--- a/res/layout/receive_key_activity.xml
+++ /dev/null
@@ -1,47 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/res/layout/receive_key_dialog.xml b/res/layout/receive_key_dialog.xml
new file mode 100644
index 00000000000..2971c8dc755
--- /dev/null
+++ b/res/layout/receive_key_dialog.xml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 6aaf6fdae37..cdf80e49772 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -570,8 +570,8 @@
TextSecure requires MMS settings to deliver media and group messages through your wireless carrier. Your device does not make this information available, which is occasionally true for locked devices and other restrictive configurations.
To send media and group messages, click \'OK\' and complete the requested settings. The MMS settings for your carrier can generally be located by searching for \'your carrier APN\'. You will only need to do this once.
-
- Complete
+
+ Complete
diff --git a/src/org/thoughtcrime/securesms/ConversationItem.java b/src/org/thoughtcrime/securesms/ConversationItem.java
index a413c17a51d..1aaa8ddc56f 100644
--- a/src/org/thoughtcrime/securesms/ConversationItem.java
+++ b/src/org/thoughtcrime/securesms/ConversationItem.java
@@ -373,17 +373,7 @@ private void setContactPhotoForRecipient(final Recipient recipient) {
/// Event handlers
private void handleKeyExchangeClicked() {
- Intent intent = new Intent(context, ReceiveKeyActivity.class);
- intent.putExtra("recipient", messageRecord.getIndividualRecipient().getRecipientId());
- intent.putExtra("recipient_device_id", messageRecord.getRecipientDeviceId());
- intent.putExtra("body", messageRecord.getBody().getBody());
- intent.putExtra("thread_id", messageRecord.getThreadId());
- intent.putExtra("message_id", messageRecord.getId());
- intent.putExtra("is_bundle", messageRecord.isBundleKeyExchange());
- intent.putExtra("is_identity_update", messageRecord.isIdentityUpdate());
- intent.putExtra("is_push", messageRecord.isPush());
- intent.putExtra("sent", messageRecord.isOutgoing());
- context.startActivity(intent);
+ new ReceiveKeyDialog(context, masterSecret, messageRecord).show();
}
private class ThumbnailClickListener implements ThumbnailView.ThumbnailClickListener {
diff --git a/src/org/thoughtcrime/securesms/ReceiveKeyActivity.java b/src/org/thoughtcrime/securesms/ReceiveKeyActivity.java
deleted file mode 100644
index 419cd35ee53..00000000000
--- a/src/org/thoughtcrime/securesms/ReceiveKeyActivity.java
+++ /dev/null
@@ -1,206 +0,0 @@
-/**
- * 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 .
- */
-package org.thoughtcrime.securesms;
-
-import android.app.ProgressDialog;
-import android.content.Context;
-import android.content.Intent;
-import android.os.AsyncTask;
-import android.os.Bundle;
-import android.support.annotation.NonNull;
-import android.text.SpannableString;
-import android.text.Spanned;
-import android.text.method.LinkMovementMethod;
-import android.text.style.ClickableSpan;
-import android.util.Log;
-import android.view.View;
-import android.widget.Button;
-import android.widget.TextView;
-
-import org.thoughtcrime.securesms.crypto.IdentityKeyParcelable;
-import org.thoughtcrime.securesms.crypto.MasterSecret;
-import org.thoughtcrime.securesms.database.DatabaseFactory;
-import org.thoughtcrime.securesms.database.IdentityDatabase;
-import org.thoughtcrime.securesms.database.PushDatabase;
-import org.thoughtcrime.securesms.jobs.PushDecryptJob;
-import org.thoughtcrime.securesms.recipients.Recipient;
-import org.thoughtcrime.securesms.recipients.RecipientFactory;
-import org.thoughtcrime.securesms.sms.IncomingPreKeyBundleMessage;
-import org.thoughtcrime.securesms.sms.IncomingTextMessage;
-import org.thoughtcrime.securesms.util.Base64;
-import org.whispersystems.libaxolotl.IdentityKey;
-import org.whispersystems.libaxolotl.InvalidKeyException;
-import org.whispersystems.libaxolotl.InvalidMessageException;
-import org.whispersystems.libaxolotl.InvalidVersionException;
-import org.whispersystems.libaxolotl.LegacyMessageException;
-import org.whispersystems.libaxolotl.protocol.PreKeyWhisperMessage;
-import org.whispersystems.libaxolotl.util.guava.Optional;
-import org.whispersystems.textsecure.api.messages.TextSecureEnvelope;
-import org.whispersystems.textsecure.api.messages.TextSecureGroup;
-
-import java.io.IOException;
-
-/**
- * Activity for displaying sent/received session keys.
- *
- * @author Moxie Marlinspike
- */
-
-public class ReceiveKeyActivity extends PassphraseRequiredActionBarActivity {
-
- private TextView descriptionText;
-
- private Button confirmButton;
- private Button cancelButton;
-
- private Recipient recipient;
- private int recipientDeviceId;
- private long messageId;
-
- private MasterSecret masterSecret;
- private IncomingPreKeyBundleMessage message;
- private IdentityKey identityKey;
-
- @Override
- protected void onCreate(Bundle state, @NonNull MasterSecret masterSecret) {
- this.masterSecret = masterSecret;
- setContentView(R.layout.receive_key_activity);
-
- initializeResources();
-
- try {
- initializeKey();
- initializeText();
- } catch (InvalidKeyException | InvalidVersionException | InvalidMessageException | LegacyMessageException ike) {
- Log.w("ReceiveKeyActivity", ike);
- }
- initializeListeners();
- }
-
- private void initializeText() {
- SpannableString spannableString = new SpannableString(getString(R.string.ReceiveKeyActivity_the_signature_on_this_key_exchange_is_different) + " " +
- getString(R.string.ReceiveKeyActivity_you_may_wish_to_verify_this_contact));
- spannableString.setSpan(new ClickableSpan() {
- @Override
- public void onClick(View widget) {
- Intent intent = new Intent(ReceiveKeyActivity.this, VerifyIdentityActivity.class);
- intent.putExtra("recipient", recipient.getRecipientId());
- intent.putExtra("remote_identity", new IdentityKeyParcelable(identityKey));
- startActivity(intent);
- }
- }, getString(R.string.ReceiveKeyActivity_the_signature_on_this_key_exchange_is_different).length() +1,
- spannableString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
-
- descriptionText.setText(spannableString);
- descriptionText.setMovementMethod(LinkMovementMethod.getInstance());
- }
-
- private void initializeKey()
- throws InvalidKeyException, InvalidVersionException,
- InvalidMessageException, LegacyMessageException
- {
- IncomingTextMessage message = new IncomingTextMessage(recipient.getNumber(),
- recipientDeviceId,
- System.currentTimeMillis(),
- getIntent().getStringExtra("body"),
- Optional.absent());
-
- this.message = new IncomingPreKeyBundleMessage(message, message.getMessageBody());
- this.identityKey = getIdentityKey(this.message);
- }
-
- private void initializeResources() {
- this.descriptionText = (TextView) findViewById(R.id.description_text);
- this.confirmButton = (Button) findViewById(R.id.ok_button);
- this.cancelButton = (Button) findViewById(R.id.cancel_button);
- this.recipient = RecipientFactory.getRecipientForId(this, getIntent().getLongExtra("recipient", -1), true);
- this.recipientDeviceId = getIntent().getIntExtra("recipient_device_id", -1);
- this.messageId = getIntent().getLongExtra("message_id", -1);
- }
-
- private void initializeListeners() {
- this.confirmButton.setOnClickListener(new OkListener());
- this.cancelButton.setOnClickListener(new CancelListener());
- }
-
- private IdentityKey getIdentityKey(IncomingPreKeyBundleMessage message)
- throws InvalidKeyException, InvalidVersionException,
- InvalidMessageException, LegacyMessageException
- {
- try {
- return new PreKeyWhisperMessage(Base64.decode(message.getMessageBody())).getIdentityKey();
- } catch (IOException e) {
- throw new AssertionError(e);
- }
- }
-
- private class OkListener implements View.OnClickListener {
- @Override
- public void onClick(View v) {
- new AsyncTask () {
- private ProgressDialog dialog;
-
- @Override
- protected void onPreExecute() {
- dialog = ProgressDialog.show(ReceiveKeyActivity.this,
- getString(R.string.ReceiveKeyActivity_processing),
- getString(R.string.ReceiveKeyActivity_processing_key_exchange),
- true);
- }
-
- @Override
- protected Void doInBackground(Void... params) {
- Context context = ReceiveKeyActivity.this;
- IdentityDatabase identityDatabase = DatabaseFactory.getIdentityDatabase(context);
- PushDatabase pushDatabase = DatabaseFactory.getPushDatabase(context);
-
- identityDatabase.saveIdentity(masterSecret, recipient.getRecipientId(), identityKey);
- try {
- byte[] body = Base64.decode(message.getMessageBody());
- TextSecureEnvelope envelope = new TextSecureEnvelope(3, message.getSender(),
- message.getSenderDeviceId(), "",
- message.getSentTimestampMillis(),
- body);
-
- long pushId = pushDatabase.insert(envelope);
-
- ApplicationContext.getInstance(context)
- .getJobManager()
- .add(new PushDecryptJob(context, pushId, messageId, message.getSender()));
- } catch (IOException e) {
- throw new AssertionError(e);
- }
-
- return null;
- }
-
- @Override
- protected void onPostExecute(Void result) {
- dialog.dismiss();
- finish();
- }
- }.execute();
- }
- }
-
- private class CancelListener implements View.OnClickListener {
- @Override
- public void onClick(View v) {
- ReceiveKeyActivity.this.finish();
- }
- }
-}
diff --git a/src/org/thoughtcrime/securesms/ReceiveKeyDialog.java b/src/org/thoughtcrime/securesms/ReceiveKeyDialog.java
new file mode 100644
index 00000000000..267294b06ba
--- /dev/null
+++ b/src/org/thoughtcrime/securesms/ReceiveKeyDialog.java
@@ -0,0 +1,204 @@
+/**
+ * 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 .
+ */
+package org.thoughtcrime.securesms;
+
+import android.content.Context;
+import android.content.Intent;
+import android.text.SpannableString;
+import android.text.Spanned;
+import android.text.method.LinkMovementMethod;
+import android.text.style.ClickableSpan;
+import android.util.Log;
+import android.view.View;
+import android.widget.TextView;
+
+import com.afollestad.materialdialogs.MaterialDialog;
+
+import org.thoughtcrime.securesms.crypto.IdentityKeyParcelable;
+import org.thoughtcrime.securesms.crypto.MasterSecret;
+import org.thoughtcrime.securesms.database.DatabaseFactory;
+import org.thoughtcrime.securesms.database.IdentityDatabase;
+import org.thoughtcrime.securesms.database.PushDatabase;
+import org.thoughtcrime.securesms.database.model.MessageRecord;
+import org.thoughtcrime.securesms.jobs.PushDecryptJob;
+import org.thoughtcrime.securesms.sms.IncomingPreKeyBundleMessage;
+import org.thoughtcrime.securesms.sms.IncomingTextMessage;
+import org.thoughtcrime.securesms.util.Base64;
+import org.thoughtcrime.securesms.util.ProgressDialogAsyncTask;
+import org.whispersystems.libaxolotl.IdentityKey;
+import org.whispersystems.libaxolotl.InvalidKeyException;
+import org.whispersystems.libaxolotl.InvalidMessageException;
+import org.whispersystems.libaxolotl.InvalidVersionException;
+import org.whispersystems.libaxolotl.LegacyMessageException;
+import org.whispersystems.libaxolotl.protocol.PreKeyWhisperMessage;
+import org.whispersystems.libaxolotl.util.guava.Optional;
+import org.whispersystems.textsecure.api.messages.TextSecureEnvelope;
+import org.whispersystems.textsecure.api.messages.TextSecureGroup;
+
+import java.io.IOException;
+
+/**
+ * Activity for displaying sent/received session keys.
+ *
+ * @author Moxie Marlinspike
+ */
+
+public class ReceiveKeyDialog extends MaterialDialog {
+ private static final String TAG = ReceiveKeyDialog.class.getSimpleName();
+
+ public ReceiveKeyDialog(final Context context, MasterSecret masterSecret, MessageRecord messageRecord) {
+ super(new Builder(context).customView(R.layout.receive_key_dialog, true)
+ .positiveText(R.string.receive_key_dialog__complete)
+ .negativeText(android.R.string.cancel)
+ .callback(new ReceiveKeyDialogCallback(context, masterSecret, messageRecord)));
+ initializeText(messageRecord);
+ }
+
+ private void initializeText(final MessageRecord messageRecord) {
+ if (getCustomView() == null) {
+ throw new AssertionError("CustomView should not be null in ReceiveKeyDialog.");
+ }
+ TextView descriptionText = (TextView) getCustomView().findViewById(R.id.description_text);
+ String introText = getContext().getString(R.string.ReceiveKeyActivity_the_signature_on_this_key_exchange_is_different);
+ SpannableString spannableString = new SpannableString(introText + " " +
+ getContext().getString(R.string.ReceiveKeyActivity_you_may_wish_to_verify_this_contact));
+ spannableString.setSpan(new ClickableSpan() {
+ @Override
+ public void onClick(View widget) {
+ try {
+ Intent intent = new Intent(getContext(), VerifyIdentityActivity.class);
+ intent.putExtra("recipient", messageRecord.getIndividualRecipient().getRecipientId());
+ intent.putExtra("remote_identity", new IdentityKeyParcelable(getIdentityKey(messageRecord)));
+ getContext().startActivity(intent);
+ } catch (InvalidKeyException | InvalidVersionException | InvalidMessageException | LegacyMessageException e) {
+ Log.w(TAG, e);
+ }
+ }
+ }, introText.length() + 1,
+ spannableString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
+
+ descriptionText.setText(spannableString);
+ descriptionText.setMovementMethod(LinkMovementMethod.getInstance());
+ }
+
+ private static IncomingPreKeyBundleMessage getMessage(MessageRecord messageRecord)
+ throws InvalidKeyException, InvalidVersionException,
+ InvalidMessageException, LegacyMessageException
+ {
+ IncomingTextMessage message = new IncomingTextMessage(messageRecord.getIndividualRecipient().getNumber(),
+ messageRecord.getRecipientDeviceId(),
+ System.currentTimeMillis(),
+ messageRecord.getBody().getBody(),
+ Optional.absent());
+
+ return new IncomingPreKeyBundleMessage(message, message.getMessageBody());
+ }
+
+ private static IdentityKey getIdentityKey(IncomingPreKeyBundleMessage message)
+ throws InvalidKeyException, InvalidVersionException,
+ InvalidMessageException, LegacyMessageException
+ {
+ try {
+ return new PreKeyWhisperMessage(Base64.decode(message.getMessageBody())).getIdentityKey();
+ } catch (IOException e) {
+ throw new AssertionError(e);
+ }
+ }
+
+ private static IdentityKey getIdentityKey(MessageRecord messageRecord)
+ throws InvalidKeyException, InvalidVersionException,
+ InvalidMessageException, LegacyMessageException
+ {
+ return getIdentityKey(getMessage(messageRecord));
+ }
+
+ private static class ReceiveKeyDialogCallback extends ButtonCallback {
+ private Context context;
+ private MasterSecret masterSecret;
+ private MessageRecord messageRecord;
+
+ public ReceiveKeyDialogCallback(Context context,
+ MasterSecret masterSecret,
+ MessageRecord messageRecord)
+ {
+ this.context = context;
+ this.masterSecret = masterSecret;
+ this.messageRecord = messageRecord;
+ }
+
+ @Override public void onPositive(MaterialDialog dialog) {
+ try {
+ IncomingPreKeyBundleMessage message = getMessage(messageRecord);
+ IdentityKey key = getIdentityKey(message);
+ new VerifyAsyncTask(context, masterSecret, messageRecord, message, key).execute();
+ } catch (InvalidKeyException | InvalidVersionException | InvalidMessageException | LegacyMessageException e) {
+ Log.w(TAG, e);
+ dialog.dismiss();
+ }
+ }
+ }
+
+ private static class VerifyAsyncTask extends ProgressDialogAsyncTask {
+
+ private MasterSecret masterSecret;
+ private MessageRecord messageRecord;
+ private IncomingPreKeyBundleMessage message;
+ private IdentityKey identityKey;
+
+ public VerifyAsyncTask(Context context,
+ MasterSecret masterSecret,
+ MessageRecord messageRecord,
+ IncomingPreKeyBundleMessage message,
+ IdentityKey identityKey)
+ {
+ super(context, R.string.ReceiveKeyActivity_processing, R.string.ReceiveKeyActivity_processing_key_exchange);
+ this.masterSecret = masterSecret;
+ this.messageRecord = messageRecord;
+ this.message = message;
+ this.identityKey = identityKey;
+ }
+
+ @Override
+ protected Void doInBackground(Void... params) {
+ if (getContext() == null) return null;
+
+ IdentityDatabase identityDatabase = DatabaseFactory.getIdentityDatabase(getContext());
+ PushDatabase pushDatabase = DatabaseFactory.getPushDatabase(getContext());
+
+ identityDatabase.saveIdentity(masterSecret,
+ messageRecord.getIndividualRecipient().getRecipientId(),
+ identityKey);
+ try {
+ byte[] body = Base64.decode(message.getMessageBody());
+ TextSecureEnvelope envelope = new TextSecureEnvelope(3, message.getSender(),
+ message.getSenderDeviceId(), "",
+ message.getSentTimestampMillis(),
+ body);
+
+ long pushId = pushDatabase.insert(envelope);
+
+ ApplicationContext.getInstance(getContext())
+ .getJobManager()
+ .add(new PushDecryptJob(getContext(), pushId, messageRecord.getId(), message.getSender()));
+ } catch (IOException e) {
+ throw new AssertionError(e);
+ }
+
+ return null;
+ }
+ }
+}
diff --git a/src/org/thoughtcrime/securesms/util/ProgressDialogAsyncTask.java b/src/org/thoughtcrime/securesms/util/ProgressDialogAsyncTask.java
index fc24120f834..c5c22bba0a2 100644
--- a/src/org/thoughtcrime/securesms/util/ProgressDialogAsyncTask.java
+++ b/src/org/thoughtcrime/securesms/util/ProgressDialogAsyncTask.java
@@ -33,5 +33,9 @@ protected void onPreExecute() {
protected void onPostExecute(Result result) {
if (progress != null) progress.dismiss();
}
+
+ protected Context getContext() {
+ return contextReference.get();
+ }
}