mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-24 00:37:47 +00:00
Add show QR code button to settings
This commit is contained in:
parent
67b7a1d8c2
commit
f3377fe384
@ -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" />
|
||||
|
||||
<activity android:name="org.thoughtcrime.securesms.loki.SeedActivity"
|
||||
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" />
|
||||
|
||||
<activity android:name="org.thoughtcrime.securesms.loki.NewConversationActivity"
|
||||
android:windowSoftInputMode="stateAlwaysVisible"
|
||||
android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout|screenSize"/>
|
||||
android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout|screenSize" />
|
||||
<!-- Loki -->
|
||||
|
||||
<service android:enabled="true" android:name="org.thoughtcrime.securesms.service.WebRtcCallService"/>
|
||||
|
9
res/drawable/icon_qr_code.xml
Normal file
9
res/drawable/icon_qr_code.xml
Normal file
@ -0,0 +1,9 @@
|
||||
<vector android:height="24dp" android:viewportHeight="512"
|
||||
android:viewportWidth="448" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<group
|
||||
android:scaleX="0.88"
|
||||
android:scaleY="0.88"
|
||||
android:translateX="64">
|
||||
<path android:fillColor="?attr/pref_icon_tint" android:pathData="M0,224h192L192,32L0,32v192zM64,96h64v64L64,160L64,96zM256,32v192h192L448,32L256,32zM384,160h-64L320,96h64v64zM0,480h192L192,288L0,288v192zM64,352h64v64L64,416v-64zM416,288h32v128h-96v-32h-32v96h-64L256,288h96v32h64v-32zM416,448h32v32h-32v-32zM352,448h32v32h-32v-32z"/>
|
||||
</group>
|
||||
</vector>
|
33
res/layout/fragment_qr_code.xml
Normal file
33
res/layout/fragment_qr_code.xml
Normal file
@ -0,0 +1,33 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ScrollView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="32dp"
|
||||
android:layout_marginEnd="32dp"
|
||||
android:orientation="vertical"
|
||||
android:gravity="center_horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/explanationTextView"
|
||||
style="@style/Signal.Text.Body"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="32dp"
|
||||
android:text="@string/fragment_qr_code_explanation" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/qrCodeImageView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="24dp"
|
||||
android:background="@color/white" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</ScrollView>
|
@ -1569,6 +1569,7 @@
|
||||
<!-- Settings activity -->
|
||||
<string name="activity_settings_public_key_copied_message">Copied to Clipboard</string>
|
||||
<string name="activity_settings_share_public_key_button_title">Share Public Key</string>
|
||||
<string name="activity_settings_show_qr_code_button_title">Show QR Code</string>
|
||||
<string name="activity_settings_show_seed_button_title">Show Seed</string>
|
||||
<string name="activity_settings_seed_dialog_title">Your Seed</string>
|
||||
<string name="activity_settings_seed_dialog_copy_button_title">Copy</string>
|
||||
@ -1602,5 +1603,8 @@
|
||||
<!-- Conversation activity -->
|
||||
<string name="activity_conversation_pending_friend_request_hint">Pending Friend Request…</string>
|
||||
<string name="activity_conversation_default_hint">New Message</string>
|
||||
<!-- QR code fragment -->
|
||||
<string name="fragment_qr_code_title">Your QR Code</string>
|
||||
<string name="fragment_qr_code_explanation">This is your personal QR code. Other people can scan it to start a secure conversation with you.</string>
|
||||
|
||||
</resources>
|
||||
|
@ -37,6 +37,10 @@
|
||||
android:title="@string/activity_settings_share_public_key_button_title"
|
||||
android:icon="@drawable/icon_share"/>
|
||||
|
||||
<Preference android:key="preference_category_qr_code"
|
||||
android:title="@string/activity_settings_show_qr_code_button_title"
|
||||
android:icon="@drawable/icon_qr_code"/>
|
||||
|
||||
<Preference android:key="preference_category_seed"
|
||||
android:title="@string/activity_settings_show_seed_button_title"
|
||||
android:icon="@drawable/icon_seedling"/>
|
||||
|
@ -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 {
|
||||
|
32
src/org/thoughtcrime/securesms/loki/QRCodeFragment.kt
Normal file
32
src/org/thoughtcrime/securesms/loki/QRCodeFragment.kt
Normal file
@ -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)
|
||||
}
|
||||
}
|
@ -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++) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user