Try authorization when 'enter' is pressed in the touch keyboard
authorDavid A. Velasco <dvelasco@solidgear.es>
Tue, 14 May 2013 11:18:21 +0000 (13:18 +0200)
committerDavid A. Velasco <dvelasco@solidgear.es>
Tue, 14 May 2013 11:18:21 +0000 (13:18 +0200)
src/com/owncloud/android/authentication/AuthenticatorActivity.java

index e4787fb..dd3b4a0 100644 (file)
@@ -47,15 +47,18 @@ import android.os.Bundle;
 import android.os.Handler;\r
 import android.preference.PreferenceManager;\r
 import android.text.InputType;\r
+import android.view.KeyEvent;\r
 import android.view.View;\r
 import android.view.View.OnFocusChangeListener;\r
 import android.view.Window;\r
+import android.view.inputmethod.EditorInfo;\r
 import android.widget.CheckBox;\r
 import android.widget.EditText;\r
 import android.widget.Button;\r
 import android.widget.ImageView;\r
 import android.widget.TextView;\r
 import android.widget.Toast;\r
+import android.widget.TextView.OnEditorActionListener;\r
 \r
 import com.owncloud.android.R;\r
 \r
@@ -68,7 +71,7 @@ import eu.alefzero.webdav.WebdavClient;
  * @author David A. Velasco\r
  */\r
 public class AuthenticatorActivity extends AccountAuthenticatorActivity\r
-        implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeListener {\r
+        implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeListener, OnEditorActionListener {\r
 \r
     private static final String TAG = AuthenticatorActivity.class.getSimpleName();\r
 \r
@@ -166,6 +169,8 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
         /// bind view elements to listeners\r
         mHostUrlInput.setOnFocusChangeListener(this);\r
         mPasswordInput.setOnFocusChangeListener(this);\r
+        mPasswordInput.setImeOptions(EditorInfo.IME_ACTION_DONE);\r
+        mPasswordInput.setOnEditorActionListener(this);\r
         \r
         /// initialization\r
         mAccountMgr = AccountManager.get(this);\r
@@ -1081,4 +1086,21 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
         showDialog(DIALOG_CERT_NOT_SAVED);\r
     }\r
 \r
+\r
+    /**\r
+     *  Called when the 'action' button in an IME is pressed ('enter' in software keyboard).\r
+     * \r
+     *  Used to trigger the authorization check when the user presses 'enter' after writing the password.\r
+     */\r
+    @Override\r
+    public boolean onEditorAction(TextView inputField, int actionId, KeyEvent event) {\r
+        if (inputField != null && inputField.equals(mPasswordInput) && \r
+                actionId == EditorInfo.IME_ACTION_DONE) {\r
+            if (mOkButton.isEnabled()) {\r
+                mOkButton.performClick();\r
+            }\r
+        }\r
+        return false;   // always return false to grant that the software keyboard is hidden anyway\r
+    }\r
+\r
 }\r