Skip to content

Instantly share code, notes, and snippets.

View Sardorbekcyber's full-sized avatar
🎯
Growing

Sardor Narziyev Sardorbekcyber

🎯
Growing
View GitHub Profile
@Sardorbekcyber
Sardorbekcyber / fadeTo.kt
Created May 21, 2021 18:18 — forked from gpeal/fadeTo.kt
Fade To
/**
* Fade a view to visible or gone. This function is idempotent - it can be called over and over again with the same
* value without affecting an in-progress animation.
*/
fun View.fadeTo(visible: Boolean, duration: Long = 500, startDelay: Long = 0, toAlpha: Float = 1f) {
// Make this idempotent.
val tagKey = "fadeTo".hashCode()
if (visible == isVisible && animation == null && getTag(tagKey) == null) return
if (getTag(tagKey) == visible) return
@Sardorbekcyber
Sardorbekcyber / colorUtils.kt
Created May 28, 2021 06:10 — forked from karangoel16/colorUtils.kt
ColorWithTransparency
fun String.toTransparentColor(num: Int): String {
return "#" + when (num) {
100 -> "FF"
99 -> "FC"
98 -> "FA"
97 -> "F7"
96 -> "F5"
95 -> "F2"
94 -> "F0"
@Sardorbekcyber
Sardorbekcyber / usb
Created September 24, 2021 12:50
E-Java token
UsbDevice[
mName=/dev/bus/usb/001/014,
mVendorId=2414,
mProductId=1539,
mClass=0,
mSubclass=0,
mProtocol=0,
mManufacturerName=FeiTian Ltd,
mProductName=JavaCard Token V1.0,
mVersion=1.06,
@Sardorbekcyber
Sardorbekcyber / UsbDeviceHelper.kt
Created September 24, 2021 12:52
get endpoint by direction
class UsbDeviceHelper {
/**
* Returns first interface on USB Smart Card Device or throws an UsbInterfaceNotFound
* exception if device is not Smart Card or Interface does not exist
*
* @param usbDevice
* @return UsbEndpoint
* @throws UsbEndpointNotFound
*/
@Sardorbekcyber
Sardorbekcyber / MainActivity.kt
Created September 28, 2021 11:34
gist read bulk transfer
if (manager.hasPermission(device)) {
try {
val openUsbDevice = manager.openDevice(device)
logArray.add(
LogItem(
"openUsbDevice Connection",
"$openUsbDevice"
)
)
try {
@Sardorbekcyber
Sardorbekcyber / textChangedDebounce.kt
Created October 7, 2021 13:16
This example demonstrates how to override TextWatcher's only after text changed method
fun TextInputEditText.textChangedDebounce(debounceTime: Long = 100L, action: (text: String) -> Unit) {
this.addTextChangedListener(object : TextWatcher {
private var lastTextChangedTime: Long = 0
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {}
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {}
override fun afterTextChanged(s: Editable?) {
if (SystemClock.elapsedRealtime() - lastTextChangedTime < debounceTime) return
else action(s.toString())
inline fun View.snack(
@StringRes messageRes: Int,
length: Int = Snackbar.LENGTH_LONG,
f: Snackbar.() -> Unit
) {
snack(resources.getString(messageRes), length, f)
}
inline fun View.snack(message: String, length: Int = Snackbar.LENGTH_LONG, f: Snackbar.() -> Unit) {
val snack = Snackbar.make(this, message, length)
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
fun View.hide() {
// get the center for the clipping circle
val cx = this.width / 2
val cy = this.height / 2
// get the initial radius for the clipping circle
val initialRadius = hypot(cx.toDouble(), cy.toDouble()).toFloat()
// create the animation (the final radius is zero)
val anim = ViewAnimationUtils.createCircularReveal(this, cx, cy, initialRadius, 0f)
private class ColorWheel(diameter: Int) {
private val radius = diameter / 2f
private val sweepGradient = SweepGradientShader(
colors = listOf(
Color.Red, Color.Magenta, Color.Blue,
Color.Cyan, Color.Green, Color.Yellow, Color.Red
),
center = Offset(radius, radius)
)
<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:orientation="vertical">
<include