mirror of
https://gitlab.futo.org/videostreaming/grayjay.git
synced 2026-05-16 04:52:39 +02:00
Fix TransactionTooLargeException in QRCodeFullscreenActivity
- Remove bitmap from Intent extras to prevent TransactionTooLargeException - Pass only QR text through Intent and regenerate bitmap in fullscreen activity - Add QR code generation logic to QRCodeFullscreenActivity - Update createIntent method signature to only accept QR text - Fixes crash when launching fullscreen QR viewer with large bitmaps This resolves the 800KB+ data parcel size issue that was causing the activity to fail to launch.
This commit is contained in:
@@ -106,7 +106,7 @@ class PolycentricBackupActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
// Add click listener to open QR code in fullscreen
|
// Add click listener to open QR code in fullscreen
|
||||||
_imageQR.setOnClickListener {
|
_imageQR.setOnClickListener {
|
||||||
val intent = QRCodeFullscreenActivity.createIntent(this@PolycentricBackupActivity, pair.second, _exportBundle)
|
val intent = QRCodeFullscreenActivity.createIntent(this@PolycentricBackupActivity, _exportBundle)
|
||||||
startActivity(intent)
|
startActivity(intent)
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
|
|||||||
@@ -2,7 +2,9 @@ package com.futo.platformplayer.activities
|
|||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.graphics.Bitmap
|
import android.graphics.Bitmap
|
||||||
|
import android.graphics.Color
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.util.TypedValue
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.ImageButton
|
import android.widget.ImageButton
|
||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
@@ -10,15 +12,18 @@ import androidx.appcompat.app.AppCompatActivity
|
|||||||
import com.futo.platformplayer.R
|
import com.futo.platformplayer.R
|
||||||
import com.futo.platformplayer.setNavigationBarColorAndIcons
|
import com.futo.platformplayer.setNavigationBarColorAndIcons
|
||||||
import com.futo.platformplayer.states.StateApp
|
import com.futo.platformplayer.states.StateApp
|
||||||
|
import com.google.zxing.BarcodeFormat
|
||||||
|
import com.google.zxing.EncodeHintType
|
||||||
|
import com.google.zxing.MultiFormatWriter
|
||||||
|
import com.google.zxing.common.BitMatrix
|
||||||
|
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel
|
||||||
|
|
||||||
class QRCodeFullscreenActivity : AppCompatActivity() {
|
class QRCodeFullscreenActivity : AppCompatActivity() {
|
||||||
companion object {
|
companion object {
|
||||||
private const val EXTRA_QR_BITMAP = "qr_bitmap"
|
|
||||||
private const val EXTRA_QR_TEXT = "qr_text"
|
private const val EXTRA_QR_TEXT = "qr_text"
|
||||||
|
|
||||||
fun createIntent(context: Context, qrBitmap: Bitmap, qrText: String): android.content.Intent {
|
fun createIntent(context: Context, qrText: String): android.content.Intent {
|
||||||
return android.content.Intent(context, QRCodeFullscreenActivity::class.java).apply {
|
return android.content.Intent(context, QRCodeFullscreenActivity::class.java).apply {
|
||||||
putExtra(EXTRA_QR_BITMAP, qrBitmap)
|
|
||||||
putExtra(EXTRA_QR_TEXT, qrText)
|
putExtra(EXTRA_QR_TEXT, qrText)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -33,16 +38,24 @@ class QRCodeFullscreenActivity : AppCompatActivity() {
|
|||||||
setContentView(R.layout.activity_qr_code_fullscreen)
|
setContentView(R.layout.activity_qr_code_fullscreen)
|
||||||
setNavigationBarColorAndIcons()
|
setNavigationBarColorAndIcons()
|
||||||
|
|
||||||
val qrBitmap = intent.getParcelableExtra<Bitmap>(EXTRA_QR_BITMAP)
|
|
||||||
val qrText = intent.getStringExtra(EXTRA_QR_TEXT)
|
val qrText = intent.getStringExtra(EXTRA_QR_TEXT)
|
||||||
|
|
||||||
val imageQR = findViewById<ImageView>(R.id.image_qr_fullscreen)
|
val imageQR = findViewById<ImageView>(R.id.image_qr_fullscreen)
|
||||||
val buttonBack = findViewById<ImageButton>(R.id.button_back_fullscreen)
|
val buttonBack = findViewById<ImageButton>(R.id.button_back_fullscreen)
|
||||||
val buttonClose = findViewById<ImageButton>(R.id.button_close_fullscreen)
|
val buttonClose = findViewById<ImageButton>(R.id.button_close_fullscreen)
|
||||||
|
|
||||||
// Set the QR code image
|
// Generate QR code bitmap from text
|
||||||
qrBitmap?.let { bitmap ->
|
qrText?.let { text ->
|
||||||
imageQR.setImageBitmap(bitmap)
|
try {
|
||||||
|
val dimension = TypedValue.applyDimension(
|
||||||
|
TypedValue.COMPLEX_UNIT_DIP, 300f, resources.displayMetrics
|
||||||
|
).toInt()
|
||||||
|
val qrBitmap = generateQRCode(text, dimension, dimension)
|
||||||
|
imageQR.setImageBitmap(qrBitmap)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
// If QR generation fails, show error or fallback
|
||||||
|
imageQR.setImageResource(R.drawable.ic_qr)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set click listeners
|
// Set click listeners
|
||||||
@@ -59,4 +72,26 @@ class QRCodeFullscreenActivity : AppCompatActivity() {
|
|||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun generateQRCode(content: String, width: Int, height: Int): Bitmap {
|
||||||
|
val hints = java.util.EnumMap<EncodeHintType, Any>(EncodeHintType::class.java)
|
||||||
|
hints[EncodeHintType.ERROR_CORRECTION] = ErrorCorrectionLevel.M
|
||||||
|
hints[EncodeHintType.MARGIN] = 1
|
||||||
|
|
||||||
|
val bitMatrix = MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, width, height, hints)
|
||||||
|
return bitMatrixToBitmap(bitMatrix)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun bitMatrixToBitmap(matrix: BitMatrix): Bitmap {
|
||||||
|
val width = matrix.width
|
||||||
|
val height = matrix.height
|
||||||
|
val bmp = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565)
|
||||||
|
|
||||||
|
for (x in 0 until width) {
|
||||||
|
for (y in 0 until height) {
|
||||||
|
bmp.setPixel(x, y, if (matrix[x, y]) Color.BLACK else Color.WHITE)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return bmp
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user