From 92aeafc26172fbbce036cdf99b82f8313acb204b Mon Sep 17 00:00:00 2001 From: FeuRenard Date: Sat, 12 Nov 2016 12:59:54 +0100 Subject: [PATCH] Add share button for safety numbers Fixes #5798 Closes #5854 // FREEBIE --- res/drawable-hdpi/ic_share_white_24dp.png | Bin 0 -> 397 bytes res/drawable-mdpi/ic_share_white_24dp.png | Bin 0 -> 268 bytes res/drawable-xhdpi/ic_share_white_24dp.png | Bin 0 -> 496 bytes res/drawable-xxhdpi/ic_share_white_24dp.png | Bin 0 -> 698 bytes res/drawable-xxxhdpi/ic_share_white_24dp.png | Bin 0 -> 938 bytes res/menu/verify_identity.xml | 8 +++ res/values/strings.xml | 6 ++ .../securesms/VerifyIdentityActivity.java | 52 +++++++++++++++++- 8 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 res/drawable-hdpi/ic_share_white_24dp.png create mode 100644 res/drawable-mdpi/ic_share_white_24dp.png create mode 100644 res/drawable-xhdpi/ic_share_white_24dp.png create mode 100644 res/drawable-xxhdpi/ic_share_white_24dp.png create mode 100644 res/drawable-xxxhdpi/ic_share_white_24dp.png create mode 100644 res/menu/verify_identity.xml diff --git a/res/drawable-hdpi/ic_share_white_24dp.png b/res/drawable-hdpi/ic_share_white_24dp.png new file mode 100644 index 0000000000000000000000000000000000000000..b09a6926de5aa48dee59265aadac32da236f9e1c GIT binary patch literal 397 zcmV;80doF{P)>pxai;{B2*!N!D>LzNpR^R2)fik{R2|aH0bP5 z*MdarD7a}-Ez;H;8^R0acFB7?>Nyer70h^N-MY7?BcJR3C~UbFc^uKRQ`h0hp&@lM za=0&bFUnK#Sn5WUrS5~&57j8c2`}{x^lU0@xf-K$z+Gzw`kpzeuI-nfmQ2OyT(N5C zy>l@-b#t1gVw*GChQ69riBYL)DYQJYY2deq4n`STc6((!%2Aj4=wg&-PHHZ4XiD9R z9L`I1T#6jpc6)6i%2KtYuxQ?fferHxMOo@@yJIr8nefKYHw~583zvN|v}`i=!hTIX z1AQ+XH*Uda9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=nuF(+%t;UXt%$l)REk1CR+@t5HZYGfZVddcE%mgiK277p?u!wk{S zAzEYsZHy7*0=xAuo@I(+(gP_7Qy#3 + + + diff --git a/res/values/strings.xml b/res/values/strings.xml index 5e8b5230b..66ebac6b0 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -565,6 +565,9 @@ Your contact is running an old version of Signal, please ask them to update before verifying safety numbers. You\'re attempting to verify safety numbers with %1$s, but scanned %2$s instead. The scanned QR code is not a correctly formatted safety number verification code. Please try scanning again. + Share safety numbers via... + Our Signal safety numbers: + It looks like you don\'t have any apps to share to. Initiate despite existing request? @@ -936,6 +939,9 @@ 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. Tap to scan + + + Share safety numbers Some issues need your attention. diff --git a/src/org/thoughtcrime/securesms/VerifyIdentityActivity.java b/src/org/thoughtcrime/securesms/VerifyIdentityActivity.java index ed7c4ce2a..960d24343 100644 --- a/src/org/thoughtcrime/securesms/VerifyIdentityActivity.java +++ b/src/org/thoughtcrime/securesms/VerifyIdentityActivity.java @@ -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;