Skip to content

Instantly share code, notes, and snippets.

View NikCapko's full-sized avatar
🏠
Working from home

Nikolay Capko NikCapko

🏠
Working from home
View GitHub Profile
import android.util.Log
fun Any?.printToLog(tag: String = "DEBUG_LOG") {
Log.d(tag, toString())
}
@NikCapko
NikCapko / CustomDialog.kt
Last active April 25, 2023 19:00
Show custom dialog
Dialog(context).apply {
setContentView(R.layout.dialog)
window?.setBackgroundDrawableResource(R.drawable.bg_dialog)
findViewById<ImageView>(R.id.ivClose).setOnClickListener { dismiss() }
findViewById<Button>(R.id.btnTry).setOnClickListener { dismiss() }
}.show()
@NikCapko
NikCapko / FormatterTextWatcher.kt
Last active April 25, 2023 19:00
Formatting input to edittext
import android.text.Editable
import android.text.TextWatcher
import android.widget.EditText
import kotlin.math.max
import kotlin.math.min
/**
* Класс, предназначенный для форматирования тектового ввода в EditText
* @param editText поле ввода символов
* @param formatter метод форматирования исходной строки
@NikCapko
NikCapko / Iterable viegroup children
Last active November 23, 2022 17:29
Iterable viegroup children
val ViewGroup.children: Iterable<View>
get() = (0 until childCount).map { getChildAt(it) }
// use:
linearLayout.children
.forEachIndexed { _, view ->
view.setOnClickListener {}
}
public class SimpleTextWatcher implements TextWatcher {
private BeforeTextChanged beforeTextChanged;
private OnTextChanged onTextChanged;
private AfterTextChanged afterTextChanged;
public SimpleTextWatcher(BeforeTextChanged beforeTextChanged) {
this.beforeTextChanged = beforeTextChanged;
}