diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2020-03-28 13:50:11 -0600 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2020-03-28 16:26:22 -0600 |
commit | fe6b788f6bdef567e74a208fa69f45d3ebf01300 (patch) | |
tree | ef5683530417b309da57f9e940293d28798c2ee6 /ui/src/main/java/com | |
parent | fb3fec299f57408b0b3b10387561b6fc9fceac9f (diff) |
MonkeyedTextInputEditText: introduce a new horror
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'ui/src/main/java/com')
-rw-r--r-- | ui/src/main/java/com/wireguard/android/widget/MonkeyedTextInputEditText.kt | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/ui/src/main/java/com/wireguard/android/widget/MonkeyedTextInputEditText.kt b/ui/src/main/java/com/wireguard/android/widget/MonkeyedTextInputEditText.kt new file mode 100644 index 00000000..8316d65e --- /dev/null +++ b/ui/src/main/java/com/wireguard/android/widget/MonkeyedTextInputEditText.kt @@ -0,0 +1,30 @@ +/* + * Copyright © 2020 WireGuard LLC. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +package com.wireguard.android.widget + +import android.content.Context +import android.text.Editable +import android.text.SpannableStringBuilder +import android.util.AttributeSet +import com.google.android.material.R +import com.google.android.material.textfield.TextInputEditText +import com.google.android.material.textfield.TextInputLayout + +class MonkeyedTextInputEditText @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = R.attr.editTextStyle) : TextInputEditText(context, attrs, defStyleAttr) { + @Override + override fun getText(): Editable? { + val text = super.getText() + if (!text.isNullOrEmpty()) + return text + /* We want this expression in TextInputLayout.java to be true: + * final boolean hasText = editText != null && !TextUtils.isEmpty(editText.getText()); + * But for everyone else it should return the real value, so we check the caller. + */ + if (Thread.currentThread().stackTrace[3].className == TextInputLayout::class.qualifiedName) + return SpannableStringBuilder(" ") + return text + } +} |