handle text from intent
This commit is contained in:
parent
997fcb862b
commit
389562ffbc
6 changed files with 61 additions and 27 deletions
|
|
@ -23,6 +23,14 @@
|
||||||
|
|
||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.SEND" />
|
||||||
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
|
||||||
|
<data android:mimeType="text/*" />
|
||||||
|
<data android:mimeType="message/*" />
|
||||||
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
package org.fnives.android.qrcodetransfer
|
package org.fnives.android.qrcodetransfer
|
||||||
|
|
||||||
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.widget.Toast
|
||||||
import androidx.activity.ComponentActivity
|
import androidx.activity.ComponentActivity
|
||||||
import androidx.activity.compose.setContent
|
import androidx.activity.compose.setContent
|
||||||
import androidx.compose.animation.AnimatedContent
|
import androidx.compose.animation.AnimatedContent
|
||||||
|
|
@ -24,8 +26,10 @@ import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.saveable.rememberSaveable
|
import androidx.compose.runtime.saveable.rememberSaveable
|
||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import org.fnives.android.qrcodetransfer.create.CreateQRCode
|
import org.fnives.android.qrcodetransfer.create.CreateQRCode
|
||||||
|
import org.fnives.android.qrcodetransfer.intent.LocalIntentTextProvider
|
||||||
import org.fnives.android.qrcodetransfer.read.ReadQRCode
|
import org.fnives.android.qrcodetransfer.read.ReadQRCode
|
||||||
import org.fnives.android.qrcodetransfer.ui.theme.QRCodeTransferTheme
|
import org.fnives.android.qrcodetransfer.ui.theme.QRCodeTransferTheme
|
||||||
|
|
||||||
|
|
@ -34,9 +38,8 @@ class MainActivity : ComponentActivity() {
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
setContent {
|
setContent {
|
||||||
|
LocalIntentTextProvider(intent) {
|
||||||
QRCodeTransferTheme {
|
QRCodeTransferTheme {
|
||||||
var writerSelected by rememberSaveable { mutableStateOf(true) }
|
var writerSelected by rememberSaveable { mutableStateOf(true) }
|
||||||
// A surface container using the 'background' color from the theme
|
// A surface container using the 'background' color from the theme
|
||||||
|
|
@ -63,6 +66,14 @@ class MainActivity : ComponentActivity() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onNewIntent(intent: Intent?) {
|
||||||
|
super.onNewIntent(intent)
|
||||||
|
intent?.getStringExtra(Intent.EXTRA_TEXT)?.let { url ->
|
||||||
|
Toast.makeText(this, "onNewIntent: url", Toast.LENGTH_SHORT).show()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
|
|
|
||||||
|
|
@ -49,10 +49,7 @@ object SequenceProtocol {
|
||||||
val formatWithLength = format.replace(formatLength, chunks.size.toChar())
|
val formatWithLength = format.replace(formatLength, chunks.size.toChar())
|
||||||
val messages = chunks.mapIndexed { index, s ->
|
val messages = chunks.mapIndexed { index, s ->
|
||||||
val prefix = formatWithLength.replace(formatCurrent, index.toChar())
|
val prefix = formatWithLength.replace(formatCurrent, index.toChar())
|
||||||
"${prefix}${s}".also {
|
"${prefix}${s}"
|
||||||
println("MYLOG${index} $it")
|
|
||||||
println("MYLOG$it")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return messages.map {
|
return messages.map {
|
||||||
encode(it)
|
encode(it)
|
||||||
|
|
@ -117,7 +114,7 @@ object SequenceProtocol {
|
||||||
EncodeHintType.CHARACTER_SET to CharacterSetECI.ASCII,
|
EncodeHintType.CHARACTER_SET to CharacterSetECI.ASCII,
|
||||||
EncodeHintType.ERROR_CORRECTION to ErrorCorrectionLevel.M,
|
EncodeHintType.ERROR_CORRECTION to ErrorCorrectionLevel.M,
|
||||||
EncodeHintType.QR_VERSION to versionCode,
|
EncodeHintType.QR_VERSION to versionCode,
|
||||||
EncodeHintType.MARGIN to max(versionCode / 2, 3)
|
EncodeHintType.MARGIN to max(versionCode / 3, 3)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,7 @@ import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import org.fnives.android.qrcodetransfer.R
|
import org.fnives.android.qrcodetransfer.R
|
||||||
import org.fnives.android.qrcodetransfer.SequenceProtocol
|
import org.fnives.android.qrcodetransfer.SequenceProtocol
|
||||||
|
import org.fnives.android.qrcodetransfer.intent.LocalIntentText
|
||||||
import org.fnives.android.qrcodetransfer.toBitmap
|
import org.fnives.android.qrcodetransfer.toBitmap
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -148,7 +149,8 @@ fun QRCodeContentInput(
|
||||||
setLoading: (Boolean) -> Unit,
|
setLoading: (Boolean) -> Unit,
|
||||||
setBitmaps: (List<Bitmap>) -> Unit,
|
setBitmaps: (List<Bitmap>) -> Unit,
|
||||||
) {
|
) {
|
||||||
var content by rememberSaveable { mutableStateOf("") }
|
val messageFromIntent = LocalIntentText.current
|
||||||
|
var content by rememberSaveable(messageFromIntent) { mutableStateOf(messageFromIntent.orEmpty()) }
|
||||||
var number by rememberSaveable { mutableStateOf(SequenceProtocol.versionCode) }
|
var number by rememberSaveable { mutableStateOf(SequenceProtocol.versionCode) }
|
||||||
SequenceProtocol.versionCode = number
|
SequenceProtocol.versionCode = number
|
||||||
var encodeBase64 by rememberSaveable { mutableStateOf(SequenceProtocol.encodeBase64) }
|
var encodeBase64 by rememberSaveable { mutableStateOf(SequenceProtocol.encodeBase64) }
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ fun QRCodeVersionNumberDropdown(versionNumber: Int, setVersionNumber: (Int) -> U
|
||||||
}) {
|
}) {
|
||||||
val text = if (versionNumber == value) {
|
val text = if (versionNumber == value) {
|
||||||
stringResource(id = R.string.selected_version_number, value)
|
stringResource(id = R.string.selected_version_number, value)
|
||||||
} else if (value == 14) {
|
} else if (value == 13) {
|
||||||
stringResource(id = R.string.recommended_max, value)
|
stringResource(id = R.string.recommended_max, value)
|
||||||
} else {
|
} else {
|
||||||
"$value"
|
"$value"
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
package org.fnives.android.qrcodetransfer.intent
|
||||||
|
|
||||||
|
import android.content.Intent
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.CompositionLocalProvider
|
||||||
|
import androidx.compose.runtime.compositionLocalOf
|
||||||
|
|
||||||
|
val LocalIntentText = compositionLocalOf<String?> {
|
||||||
|
error("CompositionLocal LocalIntentText not present")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun LocalIntentTextProvider(intent: Intent?, content: @Composable () -> Unit) {
|
||||||
|
val message= intent?.getStringExtra(Intent.EXTRA_TEXT)
|
||||||
|
CompositionLocalProvider(LocalIntentText provides message, content = content)
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue