Implement QR code scanning
parent
f3377fe384
commit
5d34314a00
@ -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/overlay"
|
||||
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>
|
@ -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.activity_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.activity_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.activity_new_conversation_title)
|
||||
}
|
||||
}
|
@ -0,0 +1,98 @@
|
||||
package org.thoughtcrime.securesms.loki
|
||||
|
||||
import android.annotation.TargetApi
|
||||
import android.content.res.Configuration
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.support.v4.app.Fragment
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewAnimationUtils
|
||||
import android.view.ViewGroup
|
||||
import android.view.animation.DecelerateInterpolator
|
||||
import android.widget.LinearLayout
|
||||
import network.loki.messenger.R
|
||||
import org.thoughtcrime.securesms.components.camera.CameraView
|
||||
import org.thoughtcrime.securesms.qr.ScanListener
|
||||
import org.thoughtcrime.securesms.qr.ScanningThread
|
||||
import org.thoughtcrime.securesms.util.ViewUtil
|
||||
|
||||
class ScanQRCodeFragment : Fragment() {
|
||||
|
||||
private var container: ViewGroup? = null
|
||||
private var overlay: LinearLayout? = null
|
||||
private var scannerView: CameraView? = null
|
||||
private var scanningThread: ScanningThread? = null
|
||||
private var scanListener: ScanListener? = null
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, viewGroup: ViewGroup?, bundle: Bundle?): View? {
|
||||
this.container = ViewUtil.inflate(inflater, viewGroup!!, R.layout.fragment_scan_qr_code)
|
||||
this.overlay = ViewUtil.findById(this.container!!, R.id.overlay)
|
||||
this.scannerView = ViewUtil.findById(this.container!!, R.id.cameraView)
|
||||
|
||||
if (resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
||||
this.overlay!!.orientation = LinearLayout.HORIZONTAL
|
||||
} else {
|
||||
this.overlay!!.orientation = LinearLayout.VERTICAL
|
||||
}
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
this.container!!.addOnLayoutChangeListener(object : View.OnLayoutChangeListener {
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
override fun onLayoutChange(v: View, left: Int, top: Int, right: Int, bottom: Int,
|
||||
oldLeft: Int, oldTop: Int, oldRight: Int, oldBottom: Int) {
|
||||
v.removeOnLayoutChangeListener(this)
|
||||
|
||||
val reveal = ViewAnimationUtils.createCircularReveal(v, right, bottom, 0f, Math.hypot(right.toDouble(), bottom.toDouble()).toInt().toFloat())
|
||||
reveal.interpolator = DecelerateInterpolator(2f)
|
||||
reveal.duration = 800
|
||||
reveal.start()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
return this.container
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
this.scanningThread = ScanningThread()
|
||||
this.scanningThread!!.setScanListener(scanListener)
|
||||
this.scannerView!!.onResume()
|
||||
this.scannerView!!.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.scannerView!!.onPause()
|
||||
this.scanningThread!!.stopScanning()
|
||||
}
|
||||
|
||||
override fun onConfigurationChanged(newConfiguration: Configuration?) {
|
||||
super.onConfigurationChanged(newConfiguration)
|
||||
|
||||
this.scannerView!!.onPause()
|
||||
|
||||
if (newConfiguration!!.orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
||||
overlay!!.orientation = LinearLayout.HORIZONTAL
|
||||
} else {
|
||||
overlay!!.orientation = LinearLayout.VERTICAL
|
||||
}
|
||||
|
||||
this.scannerView!!.onResume()
|
||||
this.scannerView!!.setPreviewCallback(scanningThread!!)
|
||||
}
|
||||
|
||||
fun setScanListener(scanListener: ScanListener) {
|
||||
this.scanListener = scanListener
|
||||
|
||||
if (this.scanningThread != null) {
|
||||
this.scanningThread!!.setScanListener(scanListener)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue