Add share button for safety numbers

Fixes #5798
Closes #5854
// FREEBIE
This commit is contained in:
FeuRenard 2016-11-12 12:59:54 +01:00 committed by Moxie Marlinspike
parent 0abe56171a
commit 92aeafc261
8 changed files with 65 additions and 1 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 397 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 268 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 496 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 698 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 938 B

View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" >
<item android:id="@+id/verify_identity__share"
android:title="@string/verify_identity__share_safety_numbers"
android:icon="@drawable/ic_share_white_24dp"
app:showAsAction="ifRoom" />
</menu>

View file

@ -565,6 +565,9 @@
<string name="VerifyIdentityActivity_your_contact_is_running_an_old_version_of_signal">Your contact is running an old version of Signal, please ask them to update before verifying safety numbers.</string>
<string name="VerifyIdentityActivity_you_re_attempting_to_verify_safety_numbers_with">You\'re attempting to verify safety numbers with %1$s, but scanned %2$s instead.</string>
<string name="VerifyIdentityActivity_the_scanned_qr_code_is_not_a_correctly_formatted_safety_number">The scanned QR code is not a correctly formatted safety number verification code. Please try scanning again.</string>
<string name="VerifyIdentityActivity_share_safety_numbers_via">Share safety numbers via...</string>
<string name="VerifyIdentityActivity_our_signal_safety_numbers">Our Signal safety numbers:</string>
<string name="VerifyIdentityActivity_no_app_to_share_to">It looks like you don\'t have any apps to share to.</string>
<!-- KeyExchangeInitiator -->
<string name="KeyExchangeInitiator_initiate_despite_existing_request_question">Initiate despite existing request?</string>
@ -936,6 +939,9 @@
<!-- verify_display_fragment -->
<string name="verify_display_fragment__scan_the_code_on_your_contact_s_phone_or_ask_them_to_scan_your_code_to_verify_that_your_messages_are_end_to_end_encrypted_you_can_alternately_compare_the_number_above">If you wish to verify the security of your end-to-end encryption with %s, compare the numbers above with the numbers on their device. Alternately, you can scan the code on their phone, or ask them to scan your code.</string>
<string name="verify_display_fragment__tap_to_scan">Tap to scan</string>
<!-- verify_identity -->
<string name="verify_identity__share_safety_numbers">Share safety numbers</string>
<!-- message_details_header -->
<string name="message_details_header__issues_need_your_attention">Some issues need your attention.</string>

View file

@ -16,7 +16,9 @@
*/
package org.thoughtcrime.securesms;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
@ -33,6 +35,8 @@ import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
@ -122,10 +126,22 @@ public class VerifyIdentityActivity extends PassphraseRequiredActionBarActivity
}
}
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
super.onPrepareOptionsMenu(menu);
menu.clear();
MenuInflater inflater = this.getMenuInflater();
inflater.inflate(R.menu.verify_identity, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home: finish(); return true;
case R.id.verify_identity__share: handleShare(); return true;
case android.R.id.home: finish(); return true;
}
return false;
@ -173,6 +189,25 @@ public class VerifyIdentityActivity extends PassphraseRequiredActionBarActivity
}
}
private void handleShare() {
String shareString =
getString(R.string.VerifyIdentityActivity_our_signal_safety_numbers) + "\n" +
displayFragment.getFormattedSafetyNumbers() + "\n";
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.VerifyIdentityActivity_our_signal_safety_numbers));
intent.putExtra(Intent.EXTRA_TEXT, shareString);
intent.setType("text/plain");
try {
startActivity(Intent.createChooser(intent, getString(R.string.VerifyIdentityActivity_share_safety_numbers_via)));
} catch (ActivityNotFoundException e) {
Toast.makeText(VerifyIdentityActivity.this, R.string.VerifyIdentityActivity_no_app_to_share_to, Toast.LENGTH_LONG).show();
}
}
public static class VerifyDisplayFragment extends Fragment implements Recipients.RecipientsModifiedListener {
public static final String REMOTE_NUMBER = "remote_number";
@ -294,6 +329,21 @@ public class VerifyIdentityActivity extends PassphraseRequiredActionBarActivity
this.clickListener = listener;
}
public String getFormattedSafetyNumbers() {
StringBuilder result = new StringBuilder();
for (int i = 0; i < codes.length; i++) {
result.append(codes[i].getText());
if (i != codes.length - 1) {
if (((i+1) % 4) == 0) result.append('\n');
else result.append(' ');
}
}
return result.toString();
}
private void setFingerprintViews(Fingerprint fingerprint) {
String digits = fingerprint.getDisplayableFingerprint().getDisplayText();
int partSize = digits.length() / codes.length;