Skip to content

Instantly share code, notes, and snippets.

View CapnSpellcheck's full-sized avatar

Julian Pellico CapnSpellcheck

View GitHub Profile
@CapnSpellcheck
CapnSpellcheck / NewlineLimitingInputFilter.kt
Last active December 12, 2018 03:09
An InputFilter for Android EditText that limits the number of newlines the user can type into it.
import android.text.InputFilter
import android.text.Spanned
class NewlineLimitingInputFilter(val maxLines: Int) : InputFilter {
var monitor: LimitMonitor? = null
var numNewlines = 0
override fun filter(source: CharSequence, start: Int, end: Int, dest: Spanned, dstart: Int, dend: Int): CharSequence? {
// subtract all newlines in dest range
for (char in dest.subSequence(dstart, dend)) {
@CapnSpellcheck
CapnSpellcheck / IntRangeAdapter.kt
Created January 26, 2017 00:34
IntRangeAdapter: A BaseAdapter that allows for easy handling of an integer range. Allows the minimum or maximum to be changed at any time more easily and efficiently than an ArrayAdapter can.
import android.content.Context
import android.support.annotation.IntegerRes
import android.util.Log
import android.view.*
import android.widget.BaseAdapter
import android.widget.TextView
class IntRangeAdapter(val context: Context,
@IntegerRes var resource: Int,