From f3377fe384a74463d2d2ea408e9716bebd886c86 Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Fri, 23 Aug 2019 11:00:07 +1000 Subject: [PATCH] Add show QR code button to settings --- AndroidManifest.xml | 6 ++-- res/drawable/icon_qr_code.xml | 9 +++++ res/layout/fragment_qr_code.xml | 33 +++++++++++++++++++ res/values/strings.xml | 4 +++ res/xml/preferences.xml | 4 +++ .../ApplicationPreferencesActivity.java | 12 ++++++- .../securesms/loki/QRCodeFragment.kt | 32 ++++++++++++++++++ src/org/thoughtcrime/securesms/qr/QrCode.java | 5 +-- 8 files changed, 99 insertions(+), 6 deletions(-) create mode 100644 res/drawable/icon_qr_code.xml create mode 100644 res/layout/fragment_qr_code.xml create mode 100644 src/org/thoughtcrime/securesms/loki/QRCodeFragment.kt diff --git a/AndroidManifest.xml b/AndroidManifest.xml index ea47964fea..fc425f5c2d 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -463,17 +463,17 @@ android:launchMode="singleTask" android:theme="@style/TextSecure.DarkRegistrationTheme" android:windowSoftInputMode="stateUnchanged" - android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout|screenSize"/> + android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout|screenSize" /> + android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout|screenSize" /> + android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout|screenSize" /> diff --git a/res/drawable/icon_qr_code.xml b/res/drawable/icon_qr_code.xml new file mode 100644 index 0000000000..f1a095221e --- /dev/null +++ b/res/drawable/icon_qr_code.xml @@ -0,0 +1,9 @@ + + + + + diff --git a/res/layout/fragment_qr_code.xml b/res/layout/fragment_qr_code.xml new file mode 100644 index 0000000000..98093f215b --- /dev/null +++ b/res/layout/fragment_qr_code.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/res/values/strings.xml b/res/values/strings.xml index 63379f6db0..59b20c7c58 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -1569,6 +1569,7 @@ Copied to Clipboard Share Public Key + Show QR Code Show Seed Your Seed Copy @@ -1602,5 +1603,8 @@ Pending Friend Request… New Message + + Your QR Code + This is your personal QR code. Other people can scan it to start a secure conversation with you. diff --git a/res/xml/preferences.xml b/res/xml/preferences.xml index 6dd209dc70..850e9c2734 100644 --- a/res/xml/preferences.xml +++ b/res/xml/preferences.xml @@ -37,6 +37,10 @@ android:title="@string/activity_settings_share_public_key_button_title" android:icon="@drawable/icon_share"/> + + diff --git a/src/org/thoughtcrime/securesms/ApplicationPreferencesActivity.java b/src/org/thoughtcrime/securesms/ApplicationPreferencesActivity.java index d33ffbeaad..89df173c6f 100644 --- a/src/org/thoughtcrime/securesms/ApplicationPreferencesActivity.java +++ b/src/org/thoughtcrime/securesms/ApplicationPreferencesActivity.java @@ -40,6 +40,7 @@ import android.support.v7.preference.Preference; import android.widget.Toast; import org.thoughtcrime.securesms.crypto.IdentityKeyUtil; +import org.thoughtcrime.securesms.loki.QRCodeFragment; import org.thoughtcrime.securesms.preferences.AppProtectionPreferenceFragment; import org.thoughtcrime.securesms.preferences.ChatsPreferenceFragment; import org.thoughtcrime.securesms.preferences.CorrectedPreferenceFragment; @@ -78,6 +79,7 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredActionBarA // private static final String PREFERENCE_CATEGORY_DEVICES = "preference_category_devices"; // private static final String PREFERENCE_CATEGORY_ADVANCED = "preference_category_advanced"; private static final String PREFERENCE_CATEGORY_PUBLIC_KEY = "preference_category_public_key"; + private static final String PREFERENCE_CATEGORY_QR_CODE = "preference_category_qr_code"; private static final String PREFERENCE_CATEGORY_SEED = "preference_category_seed"; private final DynamicTheme dynamicTheme = new DynamicTheme(); @@ -173,6 +175,8 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredActionBarA */ this.findPreference(PREFERENCE_CATEGORY_PUBLIC_KEY) .setOnPreferenceClickListener(new CategoryClickListener(PREFERENCE_CATEGORY_PUBLIC_KEY)); + this.findPreference(PREFERENCE_CATEGORY_QR_CODE) + .setOnPreferenceClickListener(new CategoryClickListener(PREFERENCE_CATEGORY_QR_CODE)); this.findPreference(PREFERENCE_CATEGORY_SEED) .setOnPreferenceClickListener(new CategoryClickListener((PREFERENCE_CATEGORY_SEED))); @@ -233,7 +237,8 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredActionBarA Drawable devices = DrawableCompat.wrap(ContextCompat.getDrawable(context, R.drawable.ic_laptop_white_24dp)); Drawable advanced = DrawableCompat.wrap(ContextCompat.getDrawable(context, R.drawable.ic_advanced_white_24dp)); Drawable publicKey = DrawableCompat.wrap(ContextCompat.getDrawable(context, R.drawable.ic_textsms_24dp)); - Drawable seed = DrawableCompat.wrap(ContextCompat.getDrawable(context, R.drawable.ic_security_24dp)); + Drawable qrCode = DrawableCompat.wrap(ContextCompat.getDrawable(context, R.drawable.icon_qr_code)); + Drawable seed = DrawableCompat.wrap(ContextCompat.getDrawable(context, R.drawable.icon_seedling)); int[] tintAttr = new int[]{R.attr.pref_icon_tint}; TypedArray typedArray = context.obtainStyledAttributes(tintAttr); @@ -248,6 +253,7 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredActionBarA DrawableCompat.setTint(devices, color); DrawableCompat.setTint(advanced, color); DrawableCompat.setTint(publicKey, color); + DrawableCompat.setTint(qrCode, color); DrawableCompat.setTint(seed, color); // this.findPreference(PREFERENCE_CATEGORY_SMS_MMS).setIcon(sms); @@ -258,6 +264,7 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredActionBarA // this.findPreference(PREFERENCE_CATEGORY_DEVICES).setIcon(devices); // this.findPreference(PREFERENCE_CATEGORY_ADVANCED).setIcon(advanced); this.findPreference(PREFERENCE_CATEGORY_PUBLIC_KEY).setIcon(publicKey); + this.findPreference(PREFERENCE_CATEGORY_QR_CODE).setIcon(qrCode); this.findPreference(PREFERENCE_CATEGORY_SEED).setIcon(seed); } @@ -309,6 +316,9 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredActionBarA shareIntent.setType("text/plain"); startActivity(shareIntent); break; + case PREFERENCE_CATEGORY_QR_CODE: + fragment = new QRCodeFragment(); + break; case PREFERENCE_CATEGORY_SEED: File languageFileDirectory = new File(getContext().getApplicationInfo().dataDir); try { diff --git a/src/org/thoughtcrime/securesms/loki/QRCodeFragment.kt b/src/org/thoughtcrime/securesms/loki/QRCodeFragment.kt new file mode 100644 index 0000000000..ae3b36f3c7 --- /dev/null +++ b/src/org/thoughtcrime/securesms/loki/QRCodeFragment.kt @@ -0,0 +1,32 @@ +package org.thoughtcrime.securesms.loki + +import android.os.Bundle +import android.support.v4.app.Fragment +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import kotlinx.android.synthetic.main.fragment_qr_code.* +import network.loki.messenger.R +import org.thoughtcrime.securesms.ApplicationPreferencesActivity +import org.thoughtcrime.securesms.qr.QrCode +import org.thoughtcrime.securesms.util.TextSecurePreferences + +class QRCodeFragment : Fragment() { + + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { + return inflater.inflate(R.layout.fragment_qr_code, container, false) + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + val hexEncodedPublicKey = TextSecurePreferences.getLocalNumber(context) + val qrCode = QrCode.create(hexEncodedPublicKey) + qrCodeImageView.setImageBitmap(qrCode) + } + + override fun onResume() { + super.onResume() + val activity = activity as ApplicationPreferencesActivity + activity.supportActionBar!!.setTitle(R.string.fragment_qr_code_title) + } +} \ No newline at end of file diff --git a/src/org/thoughtcrime/securesms/qr/QrCode.java b/src/org/thoughtcrime/securesms/qr/QrCode.java index 691d7fec1f..0917ec105d 100644 --- a/src/org/thoughtcrime/securesms/qr/QrCode.java +++ b/src/org/thoughtcrime/securesms/qr/QrCode.java @@ -3,20 +3,21 @@ package org.thoughtcrime.securesms.qr; import android.graphics.Bitmap; import android.graphics.Color; import android.support.annotation.NonNull; -import org.thoughtcrime.securesms.logging.Log; import com.google.zxing.BarcodeFormat; import com.google.zxing.WriterException; import com.google.zxing.common.BitMatrix; import com.google.zxing.qrcode.QRCodeWriter; +import org.thoughtcrime.securesms.logging.Log; + public class QrCode { public static final String TAG = QrCode.class.getSimpleName(); public static @NonNull Bitmap create(String data) { try { - BitMatrix result = new QRCodeWriter().encode(data, BarcodeFormat.QR_CODE, 512, 512); + BitMatrix result = new QRCodeWriter().encode(data, BarcodeFormat.QR_CODE, 1024, 1024); Bitmap bitmap = Bitmap.createBitmap(result.getWidth(), result.getHeight(), Bitmap.Config.ARGB_8888); for (int y = 0; y < result.getHeight(); y++) {