- Android Studio Flamingo | 2022.2.1
- Build #AI-222.4459.24.2221.9862592, built on March 31, 2023
- Gradle JDK: jbr-17 (JetBrains Runtime version 17.0.6)
- Windows 11 (version 10.0.22000.1817)
| fun String.formatIBAN(): String { | |
| val iban = replace("\\s+".toRegex(), "").uppercase(Locale.getDefault()) | |
| val maxLength = (iban.length * 1.25).roundToInt() | |
| val result = StringBuilder(maxLength) | |
| iban.forEachIndexed { index, c -> | |
| when { | |
| index > 0 && index % 4 == 0 -> result.append(" $c") | |
| else -> result.append(c) | |
| } | |
| } |
| package com.example.test | |
| import androidx.appcompat.app.AppCompatActivity | |
| import android.os.Bundle | |
| import android.text.Editable | |
| import android.text.TextWatcher | |
| import com.example.test.databinding.ActivityMainBinding | |
| class MainActivity : AppCompatActivity() { |
| package com.example.livedatatest | |
| import android.content.Intent | |
| import android.os.Bundle | |
| import android.util.Log | |
| import android.widget.Button | |
| import android.widget.EditText | |
| import androidx.appcompat.app.AppCompatActivity | |
| import androidx.core.widget.addTextChangedListener | |
| import androidx.lifecycle.lifecycleScope |
| fun isTextMoreThan(editText: EditText, charNumber: Int): Boolean { | |
| return if (editText.text.toString().length >= charNumber) { | |
| editText.background = | |
| ContextCompat.getDrawable(requireContext(), R.drawable.shape_edit_text) | |
| editText.background.alpha = 180 | |
| true | |
| } else { | |
| editText.background = ContextCompat.getDrawable( | |
| requireContext(), |
| // activity with android:windowSoftInputMode="stateHidden" | |
| private fun showPasswordDialog() { | |
| val context = this.context ?: return | |
| val editText = EditText(context) | |
| editText.inputType = InputType.TYPE_CLASS_NUMBER or InputType.TYPE_NUMBER_VARIATION_PASSWORD | |
| editText.filters = arrayOf(InputFilter.LengthFilter(4)) | |
| val frame = FrameLayout(context) | |
| frame.addView(editText) |
| import android.text.Editable | |
| import android.text.TextWatcher | |
| import android.view.View | |
| import android.widget.EditText | |
| /** | |
| * Created by Konstantin Tskhovrebov (aka @terrakok) on 18.09.17. | |
| */ | |
| class SmartField<T: Any>( | |
| private val editText: EditText, |
| package com.toastme.widget | |
| import android.text.Editable | |
| import android.text.TextWatcher | |
| import android.widget.EditText | |
| import java.math.BigDecimal | |
| import java.text.DecimalFormat | |
| class NumberTextWatcher(private val editText: EditText) : TextWatcher { |
| interface CircularTimerListener { | |
| fun updateDataOnTick(remainingTimeInMs: Long): String? | |
| fun onTimerFinished() | |
| } |
| data class DownloadItem( | |
| val bytesDownloadedSoFar: Long = -1, | |
| val totalSizeBytes: Long = -1, | |
| val status: Int, | |
| val uri: String | |
| ) | |
| class DownloadProgressLiveData(private val activity: Activity) : | |
| LiveData<List<DownloadItem>>(), | |
| CoroutineScope { |