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 | |
parent | fb3fec299f57408b0b3b10387561b6fc9fceac9f (diff) |
MonkeyedTextInputEditText: introduce a new horror
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'ui/src')
4 files changed, 48 insertions, 13 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 + } +} diff --git a/ui/src/main/res/layout/tunnel_editor_fragment.xml b/ui/src/main/res/layout/tunnel_editor_fragment.xml index bef3fb25..27d898ef 100644 --- a/ui/src/main/res/layout/tunnel_editor_fragment.xml +++ b/ui/src/main/res/layout/tunnel_editor_fragment.xml @@ -126,6 +126,7 @@ <com.google.android.material.textfield.TextInputLayout android:id="@+id/public_key_label_layout" style="@style/TextInputLayoutBase" + android:hint="@string/public_key" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_margin="4dp" @@ -133,14 +134,14 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/private_key_text_layout"> - <com.google.android.material.textfield.TextInputEditText + <com.wireguard.android.widget.MonkeyedTextInputEditText android:id="@+id/public_key_text" android:layout_width="match_parent" android:layout_height="wrap_content" + android:hint="@string/hint_generated" android:editable="false" android:ellipsize="end" android:focusable="false" - android:hint="@string/public_key" android:onClick="@{ClipboardUtils::copyTextView}" android:singleLine="true" android:text="@{config.interface.publicKey}" /> @@ -170,6 +171,7 @@ <com.google.android.material.textfield.TextInputLayout android:id="@+id/listen_port_label_layout" style="@style/TextInputLayoutBase" + android:hint="@string/listen_port" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_margin="4dp" @@ -178,10 +180,10 @@ app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toEndOf="@id/addresses_label_layout"> - <com.google.android.material.textfield.TextInputEditText + <com.wireguard.android.widget.MonkeyedTextInputEditText android:layout_width="match_parent" android:layout_height="wrap_content" - android:hint="@string/listen_port" + android:hint="@string/hint_random" android:inputType="number" android:text="@={config.interface.listenPort}" android:textAlignment="center" /> @@ -195,7 +197,7 @@ android:layout_height="wrap_content" android:layout_margin="4dp" app:layout_constraintHorizontal_chainStyle="spread" - app:layout_constraintHorizontal_weight="0.8" + app:layout_constraintHorizontal_weight="0.7" app:layout_constraintEnd_toStartOf="@id/mtu_label_layout" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/addresses_label_layout"> @@ -215,17 +217,18 @@ android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginStart="4dp" - app:layout_constraintHorizontal_weight="0.2" + android:hint="@string/mtu" + app:layout_constraintHorizontal_weight="0.3" app:layout_constraintStart_toEndOf="@id/dns_servers_label_layout" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toTopOf="@id/dns_servers_label_layout"> - <com.google.android.material.textfield.TextInputEditText + <com.wireguard.android.widget.MonkeyedTextInputEditText android:id="@+id/mtu_text" android:layout_width="match_parent" android:layout_height="wrap_content" - android:hint="@string/mtu" android:inputType="number" + android:hint="@string/hint_automatic" android:text="@={config.interface.mtu}" android:textAlignment="center" /> </com.google.android.material.textfield.TextInputLayout> diff --git a/ui/src/main/res/layout/tunnel_editor_peer.xml b/ui/src/main/res/layout/tunnel_editor_peer.xml index e37aa564..896d2381 100644 --- a/ui/src/main/res/layout/tunnel_editor_peer.xml +++ b/ui/src/main/res/layout/tunnel_editor_peer.xml @@ -83,15 +83,16 @@ android:layout_width="0dp" android:layout_height="wrap_content" android:layout_margin="4dp" + android:hint="@string/pre_shared_key" app:layout_constraintTop_toBottomOf="@+id/public_key_label_layout" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent"> - <com.google.android.material.textfield.TextInputEditText + <com.wireguard.android.widget.MonkeyedTextInputEditText android:id="@+id/pre_shared_key_text" android:layout_width="match_parent" android:layout_height="wrap_content" - android:hint="@string/pre_shared_key" + android:hint="@string/hint_optional" android:inputType="textNoSuggestions|textVisiblePassword" android:text="@={item.preSharedKey}"/> </com.google.android.material.textfield.TextInputLayout> @@ -102,15 +103,16 @@ android:layout_width="0dp" android:layout_height="wrap_content" android:layout_margin="4dp" + android:hint="@string/persistent_keepalive" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/pre_shared_key_label_layout" app:layout_constraintEnd_toEndOf="parent"> - <com.google.android.material.textfield.TextInputEditText + <com.wireguard.android.widget.MonkeyedTextInputEditText android:id="@+id/persistent_keepalive_text" android:layout_width="match_parent" android:layout_height="wrap_content" - android:hint="@string/persistent_keepalive" + android:hint="@string/hint_optional" android:inputType="number" android:text="@={item.persistentKeepalive}" /> </com.google.android.material.textfield.TextInputLayout> diff --git a/ui/src/main/res/values/styles.xml b/ui/src/main/res/values/styles.xml index fc2f9f0e..c906068a 100644 --- a/ui/src/main/res/values/styles.xml +++ b/ui/src/main/res/values/styles.xml @@ -55,7 +55,7 @@ <style name="DetailText" parent="TextAppearance.MaterialComponents.Body1" /> - <style name="TextInputLayoutBase" parent="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"> + <style name="TextInputLayoutBase" parent="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"> <item name="boxStrokeColor">?attr/colorSecondary</item> <item name="hintTextColor">?attr/colorOnPrimary</item> </style> |