Try authorization when 'enter' is pressed in the touch keyboard
[pub/Android/ownCloud.git] / src / com / owncloud / android / authentication / AuthenticatorActivity.java
index ef5c21b..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
@@ -178,6 +183,8 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
             mStatusText = mStatusIcon = 0;\r
             mStatusCorrect = false;\r
             mIsSslConn = false;\r
+            updateConnStatus();\r
+            updateAuthStatus();\r
             \r
             /// retrieve extras from intent\r
             String tokenType = getIntent().getExtras().getString(AccountAuthenticator.KEY_AUTH_TOKEN_TYPE);\r
@@ -270,7 +277,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
         updateConnStatus();\r
         \r
         /// UI settings depending upon connection\r
-        mOkButton.setEnabled(mStatusCorrect);   // TODO really necessary?\r
+        mOkButton.setEnabled(mStatusCorrect);  \r
         if (!mStatusCorrect)\r
             mRefreshButton.setVisibility(View.VISIBLE); // seems that setting visibility is necessary\r
         else\r
@@ -347,7 +354,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
 \r
         /// GET ACCESS TOKEN to the oAuth server \r
         RemoteOperation operation = new OAuth2GetAccessToken(   getString(R.string.oauth2_client_id), \r
-                                                                getString(R.string.oauth2_redirect_uri), // TODO check - necessary here?      \r
+                                                                getString(R.string.oauth2_redirect_uri),       \r
                                                                 getString(R.string.oauth2_grant_type),\r
                                                                 queryParameters);\r
         //WebdavClient client = OwnCloudClientUtils.createOwnCloudClient(Uri.parse(getString(R.string.oauth2_url_endpoint_access)), getApplicationContext());\r
@@ -964,16 +971,13 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
      * to the last check on the ownCloud server.\r
      */\r
     private void updateConnStatus() {\r
-        ImageView iv = (ImageView) findViewById(R.id.action_indicator);\r
-        TextView tv = (TextView) findViewById(R.id.status_text);\r
+        TextView tv = (TextView) findViewById(R.id.server_status_text);\r
 \r
         if (mStatusIcon == 0 && mStatusText == 0) {\r
-            iv.setVisibility(View.INVISIBLE);\r
             tv.setVisibility(View.INVISIBLE);\r
         } else {\r
-            iv.setImageResource(mStatusIcon);\r
             tv.setText(mStatusText);\r
-            iv.setVisibility(View.VISIBLE);\r
+            tv.setCompoundDrawablesWithIntrinsicBounds(mStatusIcon, 0, 0, 0);\r
             tv.setVisibility(View.VISIBLE);\r
         }\r
     }\r
@@ -1082,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