Skip to content

Commit

Permalink
Feature/qr code detection (#101)
Browse files Browse the repository at this point in the history
* Added scanning QR code

* Added scanning of QRs fetched from taking photo

* Extracted request keys for adding qrs
  • Loading branch information
oleksandrsarapulovgl authored Aug 26, 2021
1 parent ea6266c commit 89002fd
Show file tree
Hide file tree
Showing 39 changed files with 749 additions and 226 deletions.
16 changes: 16 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

75 changes: 75 additions & 0 deletions .idea/sonarIssues.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file.
Empty file.
Empty file.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
30 changes: 6 additions & 24 deletions .idea/sonarlint/issuestore/index.pb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/src/main/java/dgca/wallet/app/android/BitmapExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ fun Bitmap.toFile(parentFile: File, relativePath: String): File {

fun Bitmap.toPdfDocument(): PdfDocument {
val document = PdfDocument()
val pageInfo = PdfDocument.PageInfo.Builder(this.width, this.height, 1).create()
val pageInfo = PdfDocument.PageInfo.Builder(this.width, this.height, 0).create()
val page = document.startPage(pageInfo)

page.canvas.drawPaint(Paint().apply { color = Color.WHITE })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ import androidx.recyclerview.widget.LinearLayoutManager
import dagger.hilt.android.AndroidEntryPoint
import dgca.wallet.app.android.MainActivity
import dgca.wallet.app.android.base.BindingFragment
import dgca.wallet.app.android.certificate.add.ADD_QR_STRING_KEY
import dgca.wallet.app.android.certificate.add.ADD_REQUEST_KEY
import dgca.wallet.app.android.databinding.FragmentCertificatesBinding
import java.io.File

Expand Down Expand Up @@ -83,6 +85,17 @@ class CertificatesFragment : BindingFragment<FragmentCertificatesBinding>(),
else -> throw IllegalStateException()
}
}

setFragmentResultListener(ADD_REQUEST_KEY) { _, bundle ->
showImportDcc(bundle.getString(ADD_QR_STRING_KEY))
}
}

private fun showImportDcc(qr: String?) {
if (!qr.isNullOrBlank()) {
val action = CertificatesFragmentDirections.actionCertificatesFragmentToClaimCertificateFragment(qr)
findNavController().navigate(action)
}
}

private fun setCertificateCards(certificatesCards: List<CertificatesCard>) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* ---license-start
* eu-digital-green-certificates / dgca-wallet-app-android
* ---
* Copyright (C) 2021 T-Systems International GmbH and all other contributors
* ---
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ---license-end
*
* Created by osarapulov on 8/26/21 12:24 PM
*/

package dgca.wallet.app.android.certificate.add

const val ADD_REQUEST_KEY = "ADD_REQUEST"
const val ADD_QR_STRING_KEY = "ADD_QR_STRING"

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* ---license-start
* eu-digital-green-certificates / dgca-wallet-app-android
* ---
* Copyright (C) 2021 T-Systems International GmbH and all other contributors
* ---
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ---license-end
*
* Created by osarapulov on 8/25/21 3:24 PM
*/

package dgca.wallet.app.android.certificate.add

import android.graphics.Bitmap
import android.net.Uri

interface BitmapFetcher {
fun loadBitmapByImageUri(uri: Uri): Bitmap

fun loadBitmapByPdfUri(uri: Uri): Bitmap
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* ---license-start
* eu-digital-green-certificates / dgca-wallet-app-android
* ---
* Copyright (C) 2021 T-Systems International GmbH and all other contributors
* ---
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ---license-end
*
* Created by osarapulov on 8/25/21 3:25 PM
*/

package dgca.wallet.app.android.certificate.add

import android.content.Context
import android.graphics.Bitmap
import android.graphics.ImageDecoder
import android.graphics.pdf.PdfRenderer
import android.net.Uri
import android.os.Build
import android.provider.MediaStore

class DefaultBitmapFetcher(context: Context) : BitmapFetcher {
private val appContext = context.applicationContext

override fun loadBitmapByImageUri(uri: Uri): Bitmap {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
ImageDecoder.decodeBitmap(ImageDecoder.createSource(appContext.contentResolver, uri))
} else {
MediaStore.Images.Media.getBitmap(appContext.contentResolver, uri)
}.copy(Bitmap.Config.ARGB_8888, true)
}

override fun loadBitmapByPdfUri(uri: Uri): Bitmap =
appContext.contentResolver.openFileDescriptor(uri, "r")!!.use { fileDescriptor ->
PdfRenderer(fileDescriptor).use { pdfRenderer ->
pdfRenderer.openPage(0).use { page ->
val bitmap = Bitmap.createBitmap(page.width, page.height, Bitmap.Config.ARGB_8888)
page.render(bitmap, null, null, PdfRenderer.Page.RENDER_MODE_FOR_DISPLAY)
bitmap
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* ---license-start
* eu-digital-green-certificates / dgca-wallet-app-android
* ---
* Copyright (C) 2021 T-Systems International GmbH and all other contributors
* ---
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ---license-end
*
* Created by osarapulov on 8/25/21 12:36 PM
*/

package dgca.wallet.app.android.certificate.add

import android.content.Context
import android.net.Uri
import java.io.File
import java.io.FileOutputStream

class DefaultFileSaver(context: Context) : FileSaver {
private val appContext = context.applicationContext

override fun saveFileFromUri(uri: Uri, targetDirectoryName: String, targetFileName: String): File {
val directory = File(appContext.filesDir, targetDirectoryName).apply { if (!isDirectory || !exists()) mkdirs() }
val file = File(directory, targetFileName)

appContext.contentResolver.openInputStream(uri)?.use { inputStream ->
FileOutputStream(file).use { outputStream ->
val buffer = ByteArray(8 * 1024)
var bytesRead: Int
while (inputStream.read(buffer).also { bytesRead = it } != -1) {
outputStream.write(buffer, 0, bytesRead)
}
}
}

return file
}
}
Loading

0 comments on commit 89002fd

Please sign in to comment.