X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/52bd01bcedf1b8f13c49b67ee40a848bae1a9d40..4f524a2043b5946791586d1408226f8de33115c0:/src/com/owncloud/android/authentication/AuthenticatorActivity.java diff --git a/src/com/owncloud/android/authentication/AuthenticatorActivity.java b/src/com/owncloud/android/authentication/AuthenticatorActivity.java index ef5c21b5..141cd54b 100644 --- a/src/com/owncloud/android/authentication/AuthenticatorActivity.java +++ b/src/com/owncloud/android/authentication/AuthenticatorActivity.java @@ -42,20 +42,27 @@ import android.content.ContentResolver; import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; +import android.graphics.Rect; +import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Bundle; import android.os.Handler; import android.preference.PreferenceManager; import android.text.InputType; +import android.view.KeyEvent; +import android.view.MotionEvent; import android.view.View; import android.view.View.OnFocusChangeListener; +import android.view.View.OnTouchListener; import android.view.Window; +import android.view.inputmethod.EditorInfo; import android.widget.CheckBox; import android.widget.EditText; import android.widget.Button; import android.widget.ImageView; import android.widget.TextView; import android.widget.Toast; +import android.widget.TextView.OnEditorActionListener; import com.owncloud.android.R; @@ -68,7 +75,7 @@ import eu.alefzero.webdav.WebdavClient; * @author David A. Velasco */ public class AuthenticatorActivity extends AccountAuthenticatorActivity - implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeListener { + implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeListener, OnEditorActionListener { private static final String TAG = AuthenticatorActivity.class.getSimpleName(); @@ -120,7 +127,6 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity private byte mAction; private Account mAccount; - private ImageView mRefreshButton; private ImageView mViewPasswordButton; private EditText mHostUrlInput; private EditText mUsernameInput; @@ -146,7 +152,6 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity /// set view and get references to view elements setContentView(R.layout.account_setup); - mRefreshButton = (ImageView) findViewById(R.id.refreshButton); mViewPasswordButton = (ImageView) findViewById(R.id.viewPasswordButton); mHostUrlInput = (EditText) findViewById(R.id.hostUrlInput); mUsernameInput = (EditText) findViewById(R.id.account_username); @@ -165,7 +170,16 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity /// bind view elements to listeners mHostUrlInput.setOnFocusChangeListener(this); + mHostUrlInput.setOnTouchListener(new RightDrawableOnTouchListener() { + @Override + public boolean onDrawableTouch(final MotionEvent event) { + AuthenticatorActivity.this.onRefreshClick(mHostUrlInput); + return true; + } + }); mPasswordInput.setOnFocusChangeListener(this); + mPasswordInput.setImeOptions(EditorInfo.IME_ACTION_DONE); + mPasswordInput.setOnEditorActionListener(this); /// initialization mAccountMgr = AccountManager.get(this); @@ -178,6 +192,8 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity mStatusText = mStatusIcon = 0; mStatusCorrect = false; mIsSslConn = false; + updateConnStatus(); + updateAuthStatus(); /// retrieve extras from intent String tokenType = getIntent().getExtras().getString(AccountAuthenticator.KEY_AUTH_TOKEN_TYPE); @@ -270,11 +286,12 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity updateConnStatus(); /// UI settings depending upon connection - mOkButton.setEnabled(mStatusCorrect); // TODO really necessary? - if (!mStatusCorrect) - mRefreshButton.setVisibility(View.VISIBLE); // seems that setting visibility is necessary - else - mRefreshButton.setVisibility(View.INVISIBLE); + mOkButton.setEnabled(mStatusCorrect); + if (!mStatusCorrect) { + mHostUrlInput.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_action_refresh_black, 0); + } else { + mHostUrlInput.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); + } /// server data String ocVersion = savedInstanceState.getString(KEY_OC_VERSION); @@ -347,7 +364,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity /// GET ACCESS TOKEN to the oAuth server RemoteOperation operation = new OAuth2GetAccessToken( getString(R.string.oauth2_client_id), - getString(R.string.oauth2_redirect_uri), // TODO check - necessary here? + getString(R.string.oauth2_redirect_uri), getString(R.string.oauth2_grant_type), queryParameters); //WebdavClient client = OwnCloudClientUtils.createOwnCloudClient(Uri.parse(getString(R.string.oauth2_url_endpoint_access)), getApplicationContext()); @@ -409,7 +426,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity mDiscoveredVersion = null; mOperationThread = mOcServerChkOperation.execute(client, this, mHandler); } else { - mRefreshButton.setVisibility(View.INVISIBLE); + mHostUrlInput.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); mStatusText = 0; mStatusIcon = 0; updateConnStatus(); @@ -582,10 +599,11 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity } /// update the visibility of the 'retry connection' button - if (!mStatusCorrect) - mRefreshButton.setVisibility(View.VISIBLE); - else - mRefreshButton.setVisibility(View.INVISIBLE); + if (!mStatusCorrect) { + mHostUrlInput.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_action_refresh_black, 0); + } else { + mHostUrlInput.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); + } /// retrieve discovered version and normalize server URL mDiscoveredVersion = operation.getDiscoveredVersion(); @@ -964,16 +982,13 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity * to the last check on the ownCloud server. */ private void updateConnStatus() { - ImageView iv = (ImageView) findViewById(R.id.action_indicator); - TextView tv = (TextView) findViewById(R.id.status_text); + TextView tv = (TextView) findViewById(R.id.server_status_text); if (mStatusIcon == 0 && mStatusText == 0) { - iv.setVisibility(View.INVISIBLE); tv.setVisibility(View.INVISIBLE); } else { - iv.setImageResource(mStatusIcon); tv.setText(mStatusText); - iv.setVisibility(View.VISIBLE); + tv.setCompoundDrawablesWithIntrinsicBounds(mStatusIcon, 0, 0, 0); tv.setVisibility(View.VISIBLE); } } @@ -1002,7 +1017,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity * @param view Refresh 'button' */ public void onRefreshClick(View view) { - onFocusChange(mRefreshButton, false); + onFocusChange(mHostUrlInput, false); } @@ -1082,4 +1097,56 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity showDialog(DIALOG_CERT_NOT_SAVED); } + + /** + * Called when the 'action' button in an IME is pressed ('enter' in software keyboard). + * + * Used to trigger the authorization check when the user presses 'enter' after writing the password. + */ + @Override + public boolean onEditorAction(TextView inputField, int actionId, KeyEvent event) { + if (inputField != null && inputField.equals(mPasswordInput) && + actionId == EditorInfo.IME_ACTION_DONE) { + if (mOkButton.isEnabled()) { + mOkButton.performClick(); + } + } + return false; // always return false to grant that the software keyboard is hidden anyway + } + + + private abstract static class RightDrawableOnTouchListener implements OnTouchListener { + + private int fuzz = 10; + + /** + * {@inheritDoc} + */ + @Override + public boolean onTouch(View view, MotionEvent event) { + if (event.getAction() == MotionEvent.ACTION_DOWN) { + Drawable rightDrawable = null; + if (view instanceof TextView) { + Drawable[] drawables = ((TextView)view).getCompoundDrawables(); + if (drawables.length > 2) { + rightDrawable = drawables[2]; + } + } + if (rightDrawable != null) { + final int x = (int) event.getX(); + final int y = (int) event.getY(); + final Rect bounds = rightDrawable.getBounds(); + if (x >= (view.getRight() - bounds.width() - fuzz) && x <= (view.getRight() - view.getPaddingRight() + fuzz) + && y >= (view.getPaddingTop() - fuzz) && y <= (view.getHeight() - view.getPaddingBottom()) + fuzz) { + + return onDrawableTouch(event); + } + } + } + return false; + } + + public abstract boolean onDrawableTouch(final MotionEvent event); + } + }