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
An implementation of SMS Retriever API using Kotlin Delegates to simplify the usage. |
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 PaddingRightSpan(private val mPadding: Int) : ReplacementSpan() { | |
override fun getSize( | |
paint: Paint, text: CharSequence, | |
start: Int, end: Int, | |
fm: Paint.FontMetricsInt? | |
): Int { | |
val widths = FloatArray(end - start) | |
paint.getTextWidths(text, start, end, widths) | |
var sum = 0 | |
for (i in widths.indices) { |
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 fun formatDebitCard(editable: Editable, paddingPx: Int) { | |
val textLength = editable.length | |
// first remove any previous span | |
val spans = editable.getSpans( | |
0, editable.length, | |
PaddingRightSpan::class.java | |
) | |
for (i in spans.indices) { | |
editable.removeSpan(spans[i]) | |
} |
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
etCardNumber.doAfterTextChanged { editable -> | |
if (editable == null) return | |
val paddingPx = etCardNumber.paint.measureText("X").toInt() | |
formatDebitCard(editable, paddingPx) | |
} |
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 PaddingRightSpan(private val mPadding: Int) : ReplacementSpan() { | |
override fun getSize( | |
paint: Paint, text: CharSequence, | |
start: Int, end: Int, | |
fm: Paint.FontMetricsInt? | |
): Int { | |
val widths = FloatArray(end - start) | |
paint.getTextWidths(text, start, end, widths) | |
var sum = 0 | |
for (i in widths.indices) { |
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
package com.your.package | |
import android.graphics.Canvas | |
import android.graphics.Paint | |
import android.text.Editable | |
import android.text.Spannable | |
import android.text.TextWatcher | |
import android.text.style.ReplacementSpan | |
import android.widget.TextView | |
import java.text.DecimalFormatSymbols |
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
package mkn.libs.otp | |
import android.content.res.Resources | |
import kotlin.math.ceil | |
fun Int.dpf(): Float { | |
return this.dp().toFloat() | |
} |
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 PaddingRightSpan(private val mPadding: Int) : ReplacementSpan() { | |
override fun getSize( | |
paint: Paint, text: CharSequence, | |
start: Int, end: Int, | |
fm: Paint.FontMetricsInt? | |
): Int { | |
val widths = FloatArray(end - start) | |
paint.getTextWidths(text, start, end, widths) | |
var sum = 0 | |
for (i in widths.indices) { |
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 fun formatDebitCard(editable: Editable, paddingPx: Int) { | |
val textLength = editable.length | |
// first remove any previous span | |
val spans = editable.getSpans( | |
0, editable.length, | |
PaddingRightSpan::class.java | |
) | |
for (i in spans.indices) { | |
editable.removeSpan(spans[i]) | |
} |
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
etCardNumber.doAfterTextChanged { editable -> | |
if (editable == null) return | |
val paddingPx = etCardNumber.paint.measureText("X").toInt() | |
formatDebitCard(editable, paddingPx) | |
} |
NewerOlder