mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-29 21:22:15 +01:00
Fix QR processing resolution and allow front camera use for device linking.
This commit is contained in:
committed by
Alex Hart
parent
3d14c05114
commit
ea9bf0ccd5
@@ -4,6 +4,8 @@ import android.annotation.SuppressLint
|
||||
import android.graphics.Bitmap
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.widget.EditText
|
||||
import android.widget.TextView
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
@@ -12,16 +14,63 @@ import com.google.zxing.PlanarYUVLuminanceSource
|
||||
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.rxjava3.kotlin.subscribeBy
|
||||
import org.signal.core.util.ThreadUtil
|
||||
import org.signal.core.util.logging.AndroidLogger
|
||||
import org.signal.core.util.logging.Log
|
||||
import org.signal.qr.ImageProxyLuminanceSource
|
||||
import org.signal.qr.QrProcessor
|
||||
import org.signal.qr.QrScannerView
|
||||
|
||||
class QrMainActivity : AppCompatActivity() {
|
||||
|
||||
|
||||
private lateinit var text: EditText
|
||||
|
||||
@SuppressLint("NewApi", "SetTextI18n")
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
Log.initialize(AndroidLogger(), object : Log.Logger() {
|
||||
override fun v(tag: String, message: String?, t: Throwable?, keepLonger: Boolean) {
|
||||
printlnFormatted('v', tag, message, t)
|
||||
}
|
||||
|
||||
override fun d(tag: String, message: String?, t: Throwable?, keepLonger: Boolean) {
|
||||
printlnFormatted('d', tag, message, t)
|
||||
}
|
||||
|
||||
override fun i(tag: String, message: String?, t: Throwable?, keepLonger: Boolean) {
|
||||
printlnFormatted('i', tag, message, t)
|
||||
}
|
||||
|
||||
override fun w(tag: String, message: String?, t: Throwable?, keepLonger: Boolean) {
|
||||
printlnFormatted('w', tag, message, t)
|
||||
}
|
||||
|
||||
override fun e(tag: String, message: String?, t: Throwable?, keepLonger: Boolean) {
|
||||
printlnFormatted('e', tag, message, t)
|
||||
}
|
||||
|
||||
override fun flush() {}
|
||||
|
||||
private fun printlnFormatted(level: Char, tag: String, message: String?, t: Throwable?) {
|
||||
ThreadUtil.runOnMain {
|
||||
val allText = text.text.toString() + "\n" + format(level, tag, message, t)
|
||||
text.setText(allText)
|
||||
}
|
||||
}
|
||||
|
||||
private fun format(level: Char, tag: String, message: String?, t: Throwable?): String {
|
||||
return if (t != null) {
|
||||
String.format("%c[%s] %s %s:%s", level, tag, message, t.javaClass.simpleName, t.message)
|
||||
} else {
|
||||
String.format("%c[%s] %s", level, tag, message)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_main)
|
||||
|
||||
text = findViewById(R.id.log)
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 23) {
|
||||
requestPermissions(arrayOf(android.Manifest.permission.CAMERA), 1)
|
||||
}
|
||||
@@ -56,5 +105,9 @@ class QrMainActivity : AppCompatActivity() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
findViewById<View>(R.id.camera_switch).setOnClickListener {
|
||||
scanner.toggleCamera()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,35 +1,57 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="center"
|
||||
android:gravity="center_horizontal"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
<Button
|
||||
android:id="@+id/camera_switch"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:gravity="center_horizontal"
|
||||
android:orientation="vertical">
|
||||
android:text="Change Camera" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_qr_data"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
<TextView
|
||||
android:id="@+id/text_qr_data"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_size"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
<TextView
|
||||
android:id="@+id/text_size"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/teal_200">
|
||||
|
||||
<org.signal.qr.QrScannerView
|
||||
android:id="@+id/scanner"
|
||||
android:layout_width="240dp"
|
||||
android:layout_height="240dp" />
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/teal_700">
|
||||
|
||||
<androidx.appcompat.widget.AppCompatImageView
|
||||
android:id="@+id/scanner_source"
|
||||
android:layout_width="240dp"
|
||||
android:layout_height="240dp" />
|
||||
android:layout_height="240dp"
|
||||
android:scaleType="fitCenter"
|
||||
android:rotation="90"
|
||||
tools:src="@tools:sample/backgrounds/scenic" />
|
||||
</FrameLayout>
|
||||
|
||||
</LinearLayout>
|
||||
<androidx.appcompat.widget.AppCompatEditText
|
||||
android:id="@+id/log"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="100dp" />
|
||||
|
||||
</FrameLayout>
|
||||
</LinearLayout>
|
||||
|
||||
Reference in New Issue
Block a user