This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun String.toTransparentColor(num: Int): String { | |
return "#" + when (num) { | |
100 -> "FF" | |
99 -> "FC" | |
98 -> "FA" | |
97 -> "F7" | |
96 -> "F5" | |
95 -> "F2" | |
94 -> "F0" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (manager.hasPermission(device)) { | |
try { | |
val openUsbDevice = manager.openDevice(device) | |
logArray.add( | |
LogItem( | |
"openUsbDevice Connection", | |
"$openUsbDevice" | |
) | |
) | |
try { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
) |
OlderNewer