Use TextInputLayout in setup incoming

Adds the show password eye to setup incoming screen. Layout adjustments to account for the difference in TextInputEditText
This commit is contained in:
MonkeyMatt 2020-12-21 13:53:02 +13:00
parent 84557da148
commit c889259707
4 changed files with 149 additions and 143 deletions

View file

@ -17,7 +17,6 @@ import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
@ -51,6 +50,8 @@ import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.Map;
import com.google.android.material.textfield.TextInputEditText;
import com.google.android.material.textfield.TextInputLayout;
import timber.log.Timber;
public class AccountSetupIncoming extends K9Activity implements OnClickListener {
@ -65,23 +66,23 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
private final AccountCreator accountCreator = DI.get(AccountCreator.class);
private String mStoreType;
private EditText mUsernameView;
private EditText mPasswordView;
private TextInputEditText mUsernameView;
private TextInputEditText mPasswordView;
private ClientCertificateSpinner mClientCertificateSpinner;
private TextView mClientCertificateLabelView;
private TextView mPasswordLabelView;
private EditText mServerView;
private EditText mPortView;
private TextInputLayout mPasswordLayoutView;
private TextInputEditText mServerView;
private TextInputEditText mPortView;
private String mCurrentPortViewSetting;
private Spinner mSecurityTypeView;
private int mCurrentSecurityTypeViewPosition;
private Spinner mAuthTypeView;
private int mCurrentAuthTypeViewPosition;
private CheckBox mImapAutoDetectNamespaceView;
private EditText mImapPathPrefixView;
private EditText mWebdavPathPrefixView;
private EditText mWebdavAuthPathView;
private EditText mWebdavMailboxPathView;
private TextInputEditText mImapPathPrefixView;
private TextInputEditText mWebdavPathPrefixView;
private TextInputEditText mWebdavAuthPathView;
private TextInputEditText mWebdavMailboxPathView;
private Button mNextButton;
private Account mAccount;
private boolean mMakeDefault;
@ -123,8 +124,7 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
mPasswordView = findViewById(R.id.account_password);
mClientCertificateSpinner = findViewById(R.id.account_client_certificate_spinner);
mClientCertificateLabelView = findViewById(R.id.account_client_certificate_label);
mPasswordLabelView = findViewById(R.id.account_password_label);
TextView serverLabelView = findViewById(R.id.account_server_label);
mPasswordLayoutView = findViewById(R.id.account_password_layout);
mServerView = findViewById(R.id.account_server);
mPortView = findViewById(R.id.account_port);
mSecurityTypeView = findViewById(R.id.account_security_type);
@ -139,6 +139,7 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
mCompressionWifi = findViewById(R.id.compression_wifi);
mCompressionOther = findViewById(R.id.compression_other);
mSubscribedFoldersOnly = findViewById(R.id.subscribed_folders_only);
TextInputLayout serverLayoutView = findViewById(R.id.account_server_layout);
mNextButton.setOnClickListener(this);
@ -203,7 +204,7 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
mStoreType = settings.type;
if (settings.type.equals(Protocols.POP3)) {
serverLabelView.setText(R.string.account_setup_incoming_pop_server_label);
serverLayoutView.setHint(getString(R.string.account_setup_incoming_pop_server_label));
findViewById(R.id.imap_path_prefix_section).setVisibility(View.GONE);
findViewById(R.id.webdav_advanced_header).setVisibility(View.GONE);
findViewById(R.id.webdav_mailbox_alias_section).setVisibility(View.GONE);
@ -213,7 +214,7 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
findViewById(R.id.compression_label).setVisibility(View.GONE);
mSubscribedFoldersOnly.setVisibility(View.GONE);
} else if (settings.type.equals(Protocols.IMAP)) {
serverLabelView.setText(R.string.account_setup_incoming_imap_server_label);
serverLayoutView.setHint(getString(R.string.account_setup_incoming_imap_server_label));
ImapStoreSettings imapSettings = (ImapStoreSettings) settings;
@ -231,7 +232,7 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
findViewById(R.id.imap_folder_setup_section).setVisibility(View.GONE);
}
} else if (settings.type.equals(Protocols.WEBDAV)) {
serverLabelView.setText(R.string.account_setup_incoming_webdav_server_label);
serverLayoutView.setHint(getString(R.string.account_setup_incoming_webdav_server_label));
mConnectionSecurityChoices = new ConnectionSecurity[] {
ConnectionSecurity.NONE,
ConnectionSecurity.SSL_TLS_REQUIRED };
@ -410,15 +411,13 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
if (isAuthTypeExternal) {
// hide password fields, show client certificate fields
mPasswordView.setVisibility(View.GONE);
mPasswordLabelView.setVisibility(View.GONE);
mPasswordLayoutView.setVisibility(View.GONE);
mClientCertificateLabelView.setVisibility(View.VISIBLE);
mClientCertificateSpinner.setVisibility(View.VISIBLE);
} else {
// show password fields, hide client certificate fields
mPasswordView.setVisibility(View.VISIBLE);
mPasswordLabelView.setVisibility(View.VISIBLE);
mPasswordLayoutView.setVisibility(View.VISIBLE);
mClientCertificateLabelView.setVisibility(View.GONE);
mClientCertificateSpinner.setVisibility(View.GONE);
}

View file

@ -1,14 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_height="match_parent"
android:layout_width="match_parent">
<include layout="@layout/toolbar"/>
<ScrollView
android:layout_width="fill_parent"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:padding="6dip"
@ -19,29 +20,29 @@
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!-- This text may be changed in code if the server is IMAP, etc. -->
<TextView
android:id="@+id/account_server_label"
android:text="@string/account_setup_incoming_pop_server_label"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="?android:attr/textColorPrimary"
android:contentDescription="@string/account_setup_incoming_password_label"/>
<EditText
android:id="@+id/account_server"
android:singleLine="true"
android:inputType="textUri"
<!-- The hint text may be changed in code if the server is IMAP, etc. -->
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/account_server_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_width="fill_parent"/>
android:layout_marginTop="@dimen/account_setup_margin_between_items_incoming_and_outgoing">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/account_server"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textUri"
android:hint="@string/account_setup_incoming_pop_server_label"
android:singleLine="true" />
</com.google.android.material.textfield.TextInputLayout>
<TextView
android:text="@string/account_setup_incoming_security_label"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="?android:attr/textColorPrimary"/>
style="@style/InputLabel"
android:layout_marginTop="6dp"/>
<Spinner
android:id="@+id/account_security_type"
@ -49,84 +50,87 @@
android:layout_width="fill_parent"
android:contentDescription="@string/account_setup_incoming_security_label"/>
<TextView
android:text="@string/account_setup_incoming_port_label"
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="?android:attr/textColorPrimary"/>
android:layout_marginTop="@dimen/account_setup_margin_between_items_incoming_and_outgoing">
<EditText
android:id="@+id/account_port"
android:singleLine="true"
android:inputType="number"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:contentDescription="@string/account_setup_incoming_port_label"/>
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/account_port"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"
android:hint="@string/account_setup_incoming_port_label"
android:singleLine="true" />
</com.google.android.material.textfield.TextInputLayout>
<TextView
android:text="@string/account_setup_incoming_username_label"
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="?android:attr/textColorPrimary"/>
android:layout_marginTop="@dimen/account_setup_margin_between_items_incoming_and_outgoing">
<EditText
android:id="@+id/account_username"
android:singleLine="true"
android:inputType="textEmailAddress"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:contentDescription="@string/account_setup_incoming_username_label"/>
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/account_username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:hint="@string/account_setup_incoming_username_label"
android:singleLine="true" />
</com.google.android.material.textfield.TextInputLayout>
<TextView
android:id="@+id/account_auth_type_label"
android:text="@string/account_setup_incoming_auth_type_label"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="?android:attr/textColorPrimary"/>
android:layout_width="match_parent"
android:layout_marginTop="6dp"
style="@style/InputLabel"/>
<Spinner
android:id="@+id/account_auth_type"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_width="match_parent"
android:contentDescription="@string/account_setup_incoming_auth_type_label"/>
<TextView
android:id="@+id/account_password_label"
android:text="@string/account_setup_incoming_password_label"
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/account_password_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="?android:attr/textColorPrimary"/>
android:layout_marginTop="@dimen/account_setup_margin_between_items_incoming_and_outgoing"
app:passwordToggleEnabled="true">
<EditText
android:id="@+id/account_password"
android:inputType="textPassword"
android:singleLine="true"
android:layout_height="wrap_content"
android:layout_width="fill_parent"/>
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/account_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/account_setup_incoming_password_label"
android:singleLine="true"
android:inputType="textPassword"
android:nextFocusDown="@+id/next"/>
</com.google.android.material.textfield.TextInputLayout>
<TextView
android:id="@+id/account_client_certificate_label"
android:text="@string/account_setup_incoming_client_certificate_label"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="?android:attr/textColorPrimary"
android:visibility="gone"/>
android:layout_width="match_parent"
android:layout_marginTop="6dp"
style="@style/InputLabel"
android:visibility="gone"
tools:visibility="visible"/>
<com.fsck.k9.view.ClientCertificateSpinner
android:id="@+id/account_client_certificate_spinner"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:visibility="gone"/>
android:layout_width="match_parent"
android:visibility="gone"
tools:visibility="visible"/>
<LinearLayout
android:id="@+id/imap_path_prefix_section"
android:layout_width="fill_parent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:orientation="vertical">
<CheckBox
@ -135,23 +139,21 @@
android:layout_width="wrap_content"
android:text="@string/account_setup_incoming_autodetect_namespace_label"/>
<TextView
android:text="@string/account_setup_incoming_imap_path_prefix_label"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="?android:attr/textColorPrimary"/>
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/imap_path_prefix"
android:singleLine="true"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:contentDescription="@string/account_setup_incoming_imap_path_prefix_label"/>
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/imap_path_prefix"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/account_setup_incoming_imap_path_prefix_label"
android:singleLine="true" />
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/imap_folder_setup_section"
android:orientation="vertical">
@ -166,14 +168,14 @@
<LinearLayout
android:id="@+id/webdav_advanced_header"
android:layout_width="fill_parent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:text="@string/advanced"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_width="match_parent"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="?android:attr/textColorPrimary"
android:textStyle="bold"
@ -186,20 +188,17 @@
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:text="@string/account_setup_incoming_webdav_mailbox_path_label"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="?android:attr/textColorPrimary"/>
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/webdav_mailbox_path"
android:hint="@string/account_setup_incoming_webdav_mailbox_path_hint"
android:singleLine="true"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:contentDescription="@string/account_setup_incoming_webdav_mailbox_path_label"/>
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/webdav_mailbox_path"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/account_setup_incoming_webdav_mailbox_path_label"
android:singleLine="true" />
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout>
<LinearLayout
@ -208,20 +207,18 @@
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:text="@string/account_setup_incoming_webdav_path_prefix_label"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="?android:attr/textColorPrimary"/>
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/account_setup_margin_between_items_incoming_and_outgoing">
<EditText
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/webdav_path_prefix"
android:hint="@string/account_setup_incoming_webdav_path_prefix_hint"
android:singleLine="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:contentDescription="@string/account_setup_incoming_webdav_path_prefix_label"/>
android:hint="@string/account_setup_incoming_webdav_path_prefix_label"
android:singleLine="true" />
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout>
<LinearLayout
@ -230,33 +227,31 @@
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:text="@string/account_setup_incoming_webdav_auth_path_label"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="?android:attr/textColorPrimary"/>
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/account_setup_margin_between_items_incoming_and_outgoing">
<EditText
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/webdav_auth_path"
android:hint="@string/account_setup_incoming_webdav_auth_path_hint"
android:singleLine="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:contentDescription="@string/account_setup_incoming_webdav_auth_path_label"/>
android:hint="@string/account_setup_incoming_webdav_auth_path_label"
android:singleLine="true" />
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout>
<TextView
android:id="@+id/compression_label"
android:text="@string/account_setup_incoming_compression_label"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="?android:attr/textColorPrimary"/>
android:layout_width="match_parent"
android:layout_marginTop="6dp"
style="@style/InputLabel"/>
<LinearLayout
android:id="@+id/compression_section"
android:layout_width="fill_parent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
@ -285,7 +280,7 @@
</LinearLayout>
<View
android:layout_width="fill_parent"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1"/>
</LinearLayout>

View file

@ -3,4 +3,8 @@
<dimen name="button_minWidth">100sp</dimen>
<dimen name="widget_padding">8dp</dimen>
<dimen name="highlight_radius">48dp</dimen>
<dimen name="input_label_vertical_spacing">8dp</dimen>
<dimen name="input_label_horizontal_spacing">4dp</dimen>
<dimen name="account_setup_margin_between_items_incoming_and_outgoing">12dp</dimen>
</resources>

View file

@ -39,5 +39,13 @@
<item name="android:button">?attr/messageStar</item>
</style>
<style name="InputLabel" parent="TextAppearance.AppCompat.Caption">
<item name="android:paddingBottom">@dimen/input_label_vertical_spacing</item>
<item name="android:paddingLeft">@dimen/input_label_horizontal_spacing</item>
<item name="android:paddingRight">@dimen/input_label_horizontal_spacing</item>
<item name="android:textColor">?android:attr/textColorHint</item>
</style>
</resources>