Initial commit
This initial commit includes HUSH specific changes starting at this commit:
d14637012c
This commit is contained in:
4
qrecycler/src/main/AndroidManifest.xml
Normal file
4
qrecycler/src/main/AndroidManifest.xml
Normal file
@@ -0,0 +1,4 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<uses-permission android:name="android.permission.CAMERA" />
|
||||
</manifest>
|
||||
@@ -0,0 +1,62 @@
|
||||
package cash.z.android.qrecycler
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.Color
|
||||
import android.widget.ImageView
|
||||
import androidx.core.view.doOnLayout
|
||||
import com.google.zxing.BarcodeFormat
|
||||
import com.google.zxing.EncodeHintType.ERROR_CORRECTION
|
||||
import com.google.zxing.EncodeHintType.MARGIN
|
||||
import com.google.zxing.qrcode.QRCodeWriter
|
||||
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel
|
||||
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel.*
|
||||
|
||||
|
||||
class QRecycler {
|
||||
fun load(content: String): Builder {
|
||||
return Builder(content)
|
||||
}
|
||||
|
||||
// TODO: make this call async such that action can be taken once it is complete
|
||||
fun encode(builder: Builder) {
|
||||
builder.target.doOnLayout { measuredView ->
|
||||
val w = measuredView.width
|
||||
val h = measuredView.height
|
||||
val hints = mapOf(ERROR_CORRECTION to builder.errorCorrection, MARGIN to builder.quietZone)
|
||||
val bitMatrix = QRCodeWriter().encode(builder.content, BarcodeFormat.QR_CODE, w, h, hints)
|
||||
val pixels = IntArray(w * h)
|
||||
for (y in 0 until h) {
|
||||
val offset = y * w
|
||||
for (x in 0 until w) {
|
||||
pixels[offset + x] = if (bitMatrix.get(x, y)) Color.BLACK else Color.WHITE
|
||||
}
|
||||
}
|
||||
// TODO: RECYCLE THIS BITMAP MEMORY!!! Do it in a way that is lifecycle-aware and disposes of the memory when the fragment is off-screen
|
||||
val bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888)
|
||||
bitmap.setPixels(pixels, 0, w, 0, 0, w, h)
|
||||
(measuredView as ImageView).setImageBitmap(bitmap)
|
||||
}
|
||||
}
|
||||
|
||||
inner class Builder(val content: String) {
|
||||
lateinit var target: ImageView
|
||||
var errorCorrection: ErrorCorrectionLevel = Q
|
||||
var quietZone: Int = 4
|
||||
fun into(imageView: ImageView) {
|
||||
target = imageView
|
||||
encode(this)
|
||||
}
|
||||
fun withQuietZoneSize(customQuietZone: Int): Builder {
|
||||
quietZone = customQuietZone
|
||||
return this
|
||||
}
|
||||
fun withCorrectionLevel(level: CorrectionLevel): Builder {
|
||||
errorCorrection = level.errorCorrectionLevel
|
||||
return this
|
||||
}
|
||||
}
|
||||
|
||||
enum class CorrectionLevel(val errorCorrectionLevel: ErrorCorrectionLevel) {
|
||||
LOW(L), DEFAULT(M), MEDIUM(Q), HIGH(H);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package cash.z.android.qrecycler
|
||||
|
||||
/**
|
||||
* An interface to allow for plugging in any scanner
|
||||
*/
|
||||
interface QScanner {
|
||||
fun scanBarcode(callback: (Result<String>) -> Unit)
|
||||
}
|
||||
23
qrecycler/src/main/res/layout/texture_view.xml
Normal file
23
qrecycler/src/main/res/layout/texture_view.xml
Normal file
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright (C) 2016 The Android Open Source Project
|
||||
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.
|
||||
-->
|
||||
<merge xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<TextureView
|
||||
android:id="@+id/texture_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
/>
|
||||
|
||||
</merge>
|
||||
58
qrecycler/src/main/res/values/attrs.xml
Normal file
58
qrecycler/src/main/res/values/attrs.xml
Normal file
@@ -0,0 +1,58 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright (C) 2016 The Android Open Source Project
|
||||
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.
|
||||
-->
|
||||
<resources>
|
||||
<declare-styleable name="CameraView">
|
||||
<!--
|
||||
Set this to true if you want the CameraView to adjust its bounds to preserve the aspect
|
||||
ratio of its camera preview.
|
||||
-->
|
||||
<attr name="android:adjustViewBounds"/>
|
||||
<!-- Direction the camera faces relative to device screen. -->
|
||||
<attr name="facing" format="enum">
|
||||
<!-- The camera device faces the opposite direction as the device's screen. -->
|
||||
<enum name="back" value="0"/>
|
||||
<!-- The camera device faces the same direction as the device's screen. -->
|
||||
<enum name="front" value="1"/>
|
||||
</attr>
|
||||
<!-- Aspect ratio of camera preview and pictures. -->
|
||||
<attr name="aspectRatio" format="string"/>
|
||||
<!-- Continuous auto focus mode. -->
|
||||
<attr name="autoFocus" format="boolean"/>
|
||||
<!-- The flash mode. -->
|
||||
<attr name="flash" format="enum">
|
||||
<!-- Flash will not be fired. -->
|
||||
<enum name="off" value="0"/>
|
||||
<!--
|
||||
Flash will always be fired during snapshot.
|
||||
The flash may also be fired during preview or auto-focus depending on the driver.
|
||||
-->
|
||||
<enum name="on" value="1"/>
|
||||
<!--
|
||||
Constant emission of light during preview, auto-focus and snapshot.
|
||||
This can also be used for video recording.
|
||||
-->
|
||||
<enum name="torch" value="2"/>
|
||||
<!--
|
||||
Flash will be fired automatically when required.
|
||||
The flash may be fired during preview, auto-focus, or snapshot depending on the
|
||||
driver.
|
||||
-->
|
||||
<enum name="auto" value="3"/>
|
||||
<!--
|
||||
Flash will be fired in red-eye reduction mode.
|
||||
-->
|
||||
<enum name="redEye" value="4"/>
|
||||
</attr>
|
||||
</declare-styleable>
|
||||
</resources>
|
||||
21
qrecycler/src/main/res/values/public.xml
Normal file
21
qrecycler/src/main/res/values/public.xml
Normal file
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright (C) 2016 The Android Open Source Project
|
||||
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.
|
||||
-->
|
||||
<resources>
|
||||
<public name="facing" type="attr"/>
|
||||
<public name="aspectRatio" type="attr"/>
|
||||
<public name="autoFocus" type="attr"/>
|
||||
<public name="flash" type="attr"/>
|
||||
|
||||
<public name="Widget.CameraView" type="style"/>
|
||||
</resources>
|
||||
2
qrecycler/src/main/res/values/strings.xml
Normal file
2
qrecycler/src/main/res/values/strings.xml
Normal file
@@ -0,0 +1,2 @@
|
||||
<resources>
|
||||
</resources>
|
||||
24
qrecycler/src/main/res/values/styles.xml
Normal file
24
qrecycler/src/main/res/values/styles.xml
Normal file
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright (C) 2016 The Android Open Source Project
|
||||
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.
|
||||
-->
|
||||
<resources>
|
||||
|
||||
<style name="Widget.CameraView" parent="android:Widget">
|
||||
<item name="android:adjustViewBounds">false</item>
|
||||
<item name="facing">back</item>
|
||||
<item name="aspectRatio">4:3</item>
|
||||
<item name="autoFocus">true</item>
|
||||
<item name="flash">auto</item>
|
||||
</style>
|
||||
|
||||
</resources>
|
||||
Reference in New Issue
Block a user