Initial commit

This initial commit includes HUSH specific changes starting at this commit:
d14637012c
This commit is contained in:
fekt
2022-11-29 20:49:44 -05:00
commit 4adbc901a0
355 changed files with 31799 additions and 0 deletions

1
qrecycler/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/build

39
qrecycler/build.gradle Normal file
View File

@@ -0,0 +1,39 @@
import cash.z.ecc.android.Deps
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
android {
compileSdkVersion Deps.compileSdkVersion
defaultConfig {
minSdkVersion Deps.minSdkVersion
targetSdkVersion Deps.targetSdkVersion
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
namespace 'cash.z.android.qrecycler'
}
dependencies {
implementation Deps.AndroidX.CORE_KTX
implementation Deps.Kotlin.STDLIB
// dependencies specific to this module, not shared with other modules
implementation Deps.Misc.Plugins.QR_SCANNER
}

21
qrecycler/proguard-rules.pro vendored Normal file
View File

@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile

View File

@@ -0,0 +1,4 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.CAMERA" />
</manifest>

View File

@@ -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);
}
}

View File

@@ -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)
}

View 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>

View 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>

View 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>

View File

@@ -0,0 +1,2 @@
<resources>
</resources>

View 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>