This file contains 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 DateEditText : AppCompatEditText(context, attrs, defStyleAttr) { | |
private var canChange: Boolean = false | |
private var actualText: StringBuilder = StringBuilder() | |
override fun onSelectionChanged(selStart: Int, selEnd: Int) { | |
super.onSelectionChanged(selStart, selEnd) | |
if (!canChange) return | |
canChange = false | |
setSelection(actualText.length) | |
canChange = true |
This file contains 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
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) { | |
if (edited) { | |
edited = false | |
return | |
} | |
var working = getEditText() | |
working = manageDateDivider(working, 2, start, before) | |
working = manageDateDivider(working, 5, start, before) | |
edited = true | |
input.setText(working) |
This file contains 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 DigitsTrimStartFilter(private val max: Int) : InputFilter { | |
override fun filter(...): CharSequence? { | |
val s = source.subSequence(start, end).filter { it.isDigit() } | |
val keep = max - (dest.length - (dend - dstart)) | |
return when { | |
keep <= 0 -> "" | |
keep >= s.length -> null // keep original | |
else -> s.subSequence(s.length - keep, s.length) | |
} | |
} |
This file contains 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
phoneNumber.setOnFocusChangeListener { _, hasFocus -> | |
countryCode.setBackgroundResource(background(hasFocus)) | |
} | |
private fun background(hasFocus: Boolean) = | |
when (hasFocus) { | |
true -> R.drawable.phone_input_active | |
false -> R.drawable.phone_input_inactive | |
} |
This file contains 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
<merge xmlns:android="http://schemas.android.com/apk/res/android" | |
tools:parentTag="android.widget.LinearLayout"> | |
<TextView | |
android:id="@+id/country_code" /> | |
<EditText | |
android:id="@+id/phone_number" /> | |
</merge> |
This file contains 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 getBackground(goal: GoalInProgress) = | |
when (goal.progress) { | |
in 0.0..0.5 -> R.drawable.ic_not_filled | |
in 0.5..0.99 -> R.drawable.ic_half_filled | |
else -> R.drawable.ic_full_filled | |
} |
This file contains 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
data class GoalInProgress(val progress: Float) | |
private val unchargedPaint = Paint().apply { | |
xfermode = PorterDuffXfermode(PorterDuff.Mode.MULTIPLY) | |
} | |
private fun mixChargedAndUncharged(canvas: Canvas) { | |
drawFullyCharged(canvas) | |
drawUnchargedPart(canvas) | |
} |
This file contains 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
maxSum xs = maximum $ zipWith (+) xs (tail xs) |
This file contains 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 maxSum(xs: List<Int>) = zipWith(xs, xs.tail, {a, b -> a + b}).max() |
This file contains 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
public Integer maxSum(List<Integer> array) { | |
Integer max = array.get(0) + array.get(1); | |
for (int i = 2; i < array.size(); i++) | |
if (array.get(i) + array.get(i-1) > max) | |
max = array.get(i) + array.get(i-1); | |
return max; | |
} |