From 7dac9aa038d3ccf45740f832f01b9d3a8247ace2 Mon Sep 17 00:00:00 2001 From: Vlad Golubev Date: Mon, 26 Jan 2015 18:06:16 +0200 Subject: [PATCH] Do login on Done button press --- .../moduleok/fragment/LoginFragment.java | 33 ++++++++++++++----- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/ua/samosfator/moduleok/fragment/LoginFragment.java b/app/src/main/java/ua/samosfator/moduleok/fragment/LoginFragment.java index 58544d8..dfa2b79 100644 --- a/app/src/main/java/ua/samosfator/moduleok/fragment/LoginFragment.java +++ b/app/src/main/java/ua/samosfator/moduleok/fragment/LoginFragment.java @@ -5,9 +5,12 @@ import android.os.Looper; import android.support.v4.app.Fragment; import android.util.Log; +import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.view.inputmethod.EditorInfo; +import android.widget.TextView; import com.dd.CircularProgressButton; import com.rengwuxian.materialedittext.MaterialEditText; @@ -34,23 +37,37 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa final View rootView = inflater.inflate(R.layout.fragment_login, container, false); initViews(rootView); login_button = (CircularProgressButton) rootView.findViewById(R.id.btnWithText); + password_txt.setOnEditorActionListener(new TextView.OnEditorActionListener() { + @Override + public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { + if (actionId == EditorInfo.IME_ACTION_DONE) { + validateAndStartLogin(); + return true; + } + return false; + } + }); login_button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - String login = login_txt.getText().toString(); - String password = password_txt.getText().toString(); - - validateFields(login, password); - - if (isReadyForLogin(login, password)) { - doLogin(login, password); - } + validateAndStartLogin(); } }); return rootView; } + private void validateAndStartLogin() { + String login = login_txt.getText().toString(); + String password = password_txt.getText().toString(); + + validateFields(login, password); + + if (isReadyForLogin(login, password)) { + doLogin(login, password); + } + } + private boolean isReadyForLogin(String login, String password) { return !login.isEmpty() && !password.isEmpty() && App.hasInternetConnection(); }