mirror of
https://github.com/oxen-io/session-android.git
synced 2025-01-12 07:53:38 +00:00
commit
2a7e07c34d
@ -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>
|
@ -18,7 +18,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="32dp"
|
||||
app:labeledEditText_background="@color/loki_darkest_gray"
|
||||
app:labeledEditText_label="@string/activity_new_conversation_public_key_edit_text_label"/>
|
||||
app:labeledEditText_label="@string/fragment_new_conversation_public_key_edit_text_label"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/explanationTextView"
|
||||
@ -26,7 +26,18 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="24dp"
|
||||
android:text="@string/activity_new_conversation_public_key_explanation" />
|
||||
android:text="@string/fragment_new_conversation_public_key_explanation" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/qrCodeButton"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="50dp"
|
||||
android:layout_marginTop="20dp"
|
||||
android:background="@color/transparent"
|
||||
android:textColor="@color/signal_primary"
|
||||
android:text="@string/fragment_new_conversation_qr_code_button_title"
|
||||
android:elevation="0dp"
|
||||
android:stateListAnimator="@null" />
|
||||
|
||||
<com.dd.CircularProgressButton
|
||||
android:id="@+id/nextButton"
|
||||
@ -41,7 +52,7 @@
|
||||
app:cpb_colorProgress="@color/textsecure_primary"
|
||||
app:cpb_cornerRadius="4dp"
|
||||
app:cpb_selectorIdle="@drawable/progress_button_state"
|
||||
app:cpb_textIdle="@string/activity_new_conversation_button_title" />
|
||||
app:cpb_textIdle="@string/fragment_new_conversation_next_button_title" />
|
||||
|
||||
</LinearLayout>
|
||||
|
32
res/layout/fragment_qr_code.xml
Normal file
32
res/layout/fragment_qr_code.xml
Normal file
@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ScrollView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
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>
|
38
res/layout/fragment_scan_qr_code.xml
Normal file
38
res/layout/fragment_scan_qr_code.xml
Normal file
@ -0,0 +1,38 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<org.thoughtcrime.securesms.components.camera.CameraView
|
||||
android:id="@+id/cameraView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:camera="0" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/overlayView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:weightSum="2" >
|
||||
|
||||
<org.thoughtcrime.securesms.components.ShapeScrim
|
||||
android:layout_weight="1"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:padding="32dp"
|
||||
android:gravity="center"
|
||||
android:background="@color/loki_darkest_gray"
|
||||
android:text="@string/fragment_scan_qr_code_explanation"
|
||||
android:textColor="?android:textColorPrimary" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</FrameLayout>
|
@ -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>
|
||||
@ -1584,11 +1585,12 @@
|
||||
<!-- Contact selection activity -->
|
||||
<string name="activity_contact_selection_search_bar_placeholder">Search by name or public key</string>
|
||||
<!-- New conversation activity -->
|
||||
<string name="activity_new_conversation_title">New Conversation</string>
|
||||
<string name="activity_new_conversation_public_key_edit_text_label">Public Key</string>
|
||||
<string name="activity_new_conversation_public_key_explanation">Enter the public key of the person you\'d like to securely message. They can share their public key with you by going into Loki Messenger\'s in-app settings and clicking \"Share Public Key\".</string>
|
||||
<string name="activity_new_conversation_button_title">Next</string>
|
||||
<string name="activity_new_conversation_invalid_public_key_message">Invalid Public Key</string>
|
||||
<string name="fragment_new_conversation_title">New Conversation</string>
|
||||
<string name="fragment_new_conversation_public_key_edit_text_label">Public Key</string>
|
||||
<string name="fragment_new_conversation_public_key_explanation">Enter the public key of the person you\'d like to securely message. They can share their public key with you by going into Loki Messenger\'s in-app settings and clicking \"Share Public Key\".</string>
|
||||
<string name="fragment_new_conversation_qr_code_button_title">Scan a QR Code Instead</string>
|
||||
<string name="fragment_new_conversation_next_button_title">Next</string>
|
||||
<string name="fragment_new_conversation_invalid_public_key_message">Invalid Public Key</string>
|
||||
<!-- Friend request view -->
|
||||
<string name="view_friend_request_accept_button_title">Accept</string>
|
||||
<string name="view_friend_request_reject_button_title">Reject</string>
|
||||
@ -1602,5 +1604,13 @@
|
||||
<!-- 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>
|
||||
<string name="fragment_qr_code_camera_permission_dialog_message">Loki Messenger needs camera access to scan QR codes.</string>
|
||||
<string name="fragment_qr_code_camera_permission_denied_message">Loki Messenger can\'t scan QR codes without camera access.</string>
|
||||
<!-- Scan QR code fragment -->
|
||||
<string name="fragment_scan_qr_code_title">Scan QR Code</string>
|
||||
<string name="fragment_scan_qr_code_explanation">Scan the QR code of the person you\'d like to securely message. They can find their QR code by going into Loki Messenger\'s in-app settings and clicking \"Show QR Code\".</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 {
|
||||
|
@ -71,11 +71,11 @@ public class DeviceActivity extends PassphraseRequiredActionBarActivity
|
||||
this.deviceListFragment.setAddDeviceButtonListener(this);
|
||||
this.deviceAddFragment.setScanListener(this);
|
||||
|
||||
if (getIntent().getBooleanExtra("add", false)) {
|
||||
// if (getIntent().getBooleanExtra("add", false)) {
|
||||
initFragment(android.R.id.content, deviceAddFragment, dynamicLanguage.getCurrentLocale());
|
||||
} else {
|
||||
initFragment(android.R.id.content, deviceListFragment, dynamicLanguage.getCurrentLocale());
|
||||
}
|
||||
// } else {
|
||||
// initFragment(android.R.id.content, deviceListFragment, dynamicLanguage.getCurrentLocale());
|
||||
// }
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -53,7 +53,7 @@ public class NewConversationActivity extends ContactSelectionActivity {
|
||||
boolean isValid = PublicKeyValidation.isValid(number);
|
||||
|
||||
if (!isValid) {
|
||||
Toast.makeText(this, R.string.activity_new_conversation_invalid_public_key_message, Toast.LENGTH_SHORT).show();
|
||||
Toast.makeText(this, R.string.fragment_new_conversation_invalid_public_key_message, Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1,21 +1,23 @@
|
||||
package org.thoughtcrime.securesms.loki
|
||||
|
||||
import android.Manifest
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.view.MenuItem
|
||||
import android.widget.Toast
|
||||
import kotlinx.android.synthetic.main.activity_new_conversation.*
|
||||
import network.loki.messenger.R;
|
||||
import network.loki.messenger.R
|
||||
import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity
|
||||
import org.thoughtcrime.securesms.conversation.ConversationActivity
|
||||
import org.thoughtcrime.securesms.database.Address
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory
|
||||
import org.thoughtcrime.securesms.database.ThreadDatabase
|
||||
import org.thoughtcrime.securesms.permissions.Permissions
|
||||
import org.thoughtcrime.securesms.qr.ScanListener
|
||||
import org.thoughtcrime.securesms.recipients.Recipient
|
||||
import org.thoughtcrime.securesms.util.DynamicTheme
|
||||
import org.whispersystems.signalservice.loki.utilities.PublicKeyValidation
|
||||
|
||||
class NewConversationActivity : PassphraseRequiredActionBarActivity() {
|
||||
class NewConversationActivity : PassphraseRequiredActionBarActivity(), ScanListener {
|
||||
private val dynamicTheme = DynamicTheme()
|
||||
|
||||
override fun onPreCreate() {
|
||||
@ -23,10 +25,10 @@ class NewConversationActivity : PassphraseRequiredActionBarActivity() {
|
||||
}
|
||||
|
||||
override fun onCreate(bundle: Bundle?, isReady: Boolean) {
|
||||
setContentView(R.layout.activity_new_conversation)
|
||||
supportActionBar!!.setTitle(R.string.activity_new_conversation_title)
|
||||
supportActionBar!!.setTitle(R.string.fragment_new_conversation_title)
|
||||
supportActionBar!!.setDisplayHomeAsUpEnabled(true)
|
||||
nextButton.setOnClickListener { startNewConversationIfPossible() }
|
||||
val fragment = NewConversationFragment()
|
||||
initFragment(android.R.id.content, fragment, null)
|
||||
}
|
||||
|
||||
public override fun onResume() {
|
||||
@ -42,8 +44,25 @@ class NewConversationActivity : PassphraseRequiredActionBarActivity() {
|
||||
return super.onOptionsItemSelected(item)
|
||||
}
|
||||
|
||||
private fun startNewConversationIfPossible() {
|
||||
val hexEncodedPublicKey = publicKeyEditText.text.toString().trim()
|
||||
fun scanQRCode() {
|
||||
Permissions.with(this)
|
||||
.request(Manifest.permission.CAMERA)
|
||||
.ifNecessary()
|
||||
.withPermanentDenialDialog(getString(R.string.fragment_qr_code_camera_permission_dialog_message))
|
||||
.onAllGranted {
|
||||
val fragment = ScanQRCodeFragment()
|
||||
fragment.scanListener = this
|
||||
supportFragmentManager.beginTransaction().replace(android.R.id.content, fragment).addToBackStack(null).commitAllowingStateLoss()
|
||||
}
|
||||
.onAnyDenied { Toast.makeText(this, R.string.fragment_qr_code_camera_permission_denied_message, Toast.LENGTH_SHORT).show() }
|
||||
.execute()
|
||||
}
|
||||
|
||||
override fun onQrDataFound(hexEncodedPublicKey: String) {
|
||||
startNewConversationIfPossible(hexEncodedPublicKey)
|
||||
}
|
||||
|
||||
fun startNewConversationIfPossible(hexEncodedPublicKey: String) {
|
||||
if (PublicKeyValidation.isValid(hexEncodedPublicKey)) {
|
||||
val contact = Recipient.from(this, Address.fromSerialized(hexEncodedPublicKey), true)
|
||||
val intent = Intent(this, ConversationActivity::class.java)
|
||||
@ -56,7 +75,7 @@ class NewConversationActivity : PassphraseRequiredActionBarActivity() {
|
||||
startActivity(intent)
|
||||
finish()
|
||||
} else {
|
||||
Toast.makeText(this, R.string.activity_new_conversation_invalid_public_key_message, Toast.LENGTH_SHORT).show()
|
||||
Toast.makeText(this, R.string.fragment_new_conversation_invalid_public_key_message, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
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_new_conversation.*
|
||||
import network.loki.messenger.R
|
||||
|
||||
class NewConversationFragment() : Fragment() {
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
return inflater.inflate(R.layout.fragment_new_conversation, container, false)
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
qrCodeButton.setOnClickListener {
|
||||
val activity = activity as NewConversationActivity
|
||||
activity.scanQRCode()
|
||||
}
|
||||
nextButton.setOnClickListener {
|
||||
val activity = activity as NewConversationActivity
|
||||
val hexEncodedPublicKey = publicKeyEditText.text.toString().trim()
|
||||
activity.startNewConversationIfPossible(hexEncodedPublicKey)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
val activity = activity as NewConversationActivity
|
||||
activity.supportActionBar!!.setTitle(R.string.fragment_new_conversation_title)
|
||||
}
|
||||
}
|
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)
|
||||
}
|
||||
}
|
58
src/org/thoughtcrime/securesms/loki/ScanQRCodeFragment.kt
Normal file
58
src/org/thoughtcrime/securesms/loki/ScanQRCodeFragment.kt
Normal file
@ -0,0 +1,58 @@
|
||||
package org.thoughtcrime.securesms.loki
|
||||
|
||||
import android.content.res.Configuration
|
||||
import android.os.Bundle
|
||||
import android.support.v4.app.Fragment
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.LinearLayout
|
||||
import kotlinx.android.synthetic.main.fragment_scan_qr_code.*
|
||||
import network.loki.messenger.R
|
||||
import org.thoughtcrime.securesms.qr.ScanListener
|
||||
import org.thoughtcrime.securesms.qr.ScanningThread
|
||||
|
||||
class ScanQRCodeFragment : Fragment() {
|
||||
private val scanningThread = ScanningThread()
|
||||
var scanListener: ScanListener? = null
|
||||
set(value) { field = value; scanningThread.setScanListener(scanListener) }
|
||||
|
||||
override fun onCreateView(layoutInflater: LayoutInflater, viewGroup: ViewGroup?, bundle: Bundle?): View? {
|
||||
return layoutInflater.inflate(R.layout.fragment_scan_qr_code, viewGroup, false)
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, bundle: Bundle?) {
|
||||
super.onViewCreated(view, bundle)
|
||||
when (resources.configuration.orientation) {
|
||||
Configuration.ORIENTATION_LANDSCAPE -> overlayView.orientation = LinearLayout.HORIZONTAL
|
||||
else -> overlayView.orientation = LinearLayout.VERTICAL
|
||||
}
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
this.scanningThread.setScanListener(scanListener)
|
||||
this.cameraView.onResume()
|
||||
this.cameraView.setPreviewCallback(scanningThread)
|
||||
this.scanningThread.start()
|
||||
val activity = activity as NewConversationActivity
|
||||
activity.supportActionBar!!.setTitle(R.string.fragment_scan_qr_code_title)
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
this.cameraView.onPause()
|
||||
this.scanningThread.stopScanning()
|
||||
}
|
||||
|
||||
override fun onConfigurationChanged(newConfiguration: Configuration) {
|
||||
super.onConfigurationChanged(newConfiguration)
|
||||
this.cameraView.onPause()
|
||||
when (newConfiguration.orientation) {
|
||||
Configuration.ORIENTATION_LANDSCAPE -> overlayView.orientation = LinearLayout.HORIZONTAL
|
||||
else -> overlayView.orientation = LinearLayout.VERTICAL
|
||||
}
|
||||
cameraView.onResume()
|
||||
cameraView.setPreviewCallback(scanningThread)
|
||||
}
|
||||
}
|
@ -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