android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
- android:layout_weight="1"
android:orientation="vertical" >
<ImageView
android:id="@+id/hostUrlInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:layout_weight="1"
android:ems="10"
android:hint="@string/auth_host_url"
android:inputType="textNoSuggestions" >
<requestFocus />
</EditText>
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_weight="1" >
-
- <ImageView
- android:id="@+id/auth2_action_indicator"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginLeft="5dp"
- android:layout_marginRight="5dp"
- android:src="@android:drawable/stat_notify_sync"
- android:visibility="gone" />
-
- <TextView
- android:id="@+id/oauth2_status_text"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="TextView"
- android:visibility="gone" />
- </LinearLayout>
<EditText
android:id="@+id/account_username"
android:layout_width="match_parent"
android:id="@+id/account_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:layout_weight="1"
android:ems="10"
android:hint="@string/auth_password"
android:inputType="textPassword"/>
</FrameLayout>
- </LinearLayout>
+ <!-- LinearLayout
+ android:id="@+id/auth_status_layout"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:visibility="invisible"
+ >
+
+ <ImageView
+ android:id="@+id/auth_status_icon"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginLeft="5dp"
+ android:layout_marginRight="5dp"
+ android:src="@android:drawable/stat_notify_sync"
+ />
+
+ <TextView
+ android:id="@+id/auth_status_text"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/text_placeholder"
+ >
+
+ </LinearLayout -->
+
+ <TextView
+ android:id="@+id/auth_status_text"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:text="@string/text_placeholder"
+ android:layout_marginLeft="5dp"
+ android:layout_marginRight="5dp"
+ android:drawableLeft="@android:drawable/stat_notify_sync"
+ android:drawablePadding="5dip"
+ android:visibility="invisible"
+ />
+
+ </LinearLayout>
</FrameLayout>
import com.owncloud.android.operations.OnRemoteOperationListener;\r
import com.owncloud.android.operations.RemoteOperation;\r
import com.owncloud.android.operations.RemoteOperationResult;\r
+import com.owncloud.android.operations.RemoteOperationResult.ResultCode;\r
\r
import android.accounts.Account;\r
import android.accounts.AccountAuthenticatorActivity;\r
public static final String EXTRA_ACCOUNT = "ACCOUNT";\r
public static final String EXTRA_USER_NAME = "USER_NAME";\r
public static final String EXTRA_HOST_NAME = "HOST_NAME";\r
-\r
+ public static final String EXTRA_ACTION = "ACTION";\r
+ \r
private static final String KEY_HOST_URL_TEXT = "HOST_URL_TEXT";\r
private static final String KEY_OC_VERSION = "OC_VERSION";\r
private static final String KEY_STATUS_TEXT = "STATUS_TEXT";\r
private static final int DIALOG_CERT_NOT_SAVED = 2;\r
private static final int DIALOG_OAUTH2_LOGIN_PROGRESS = 3;\r
\r
+ public static final byte ACTION_CREATE = 0;\r
+ public static final byte ACTION_UPDATE_TOKEN = 1;\r
+ \r
\r
private String mHostBaseUrl;\r
private OwnCloudVersion mDiscoveredVersion;\r
private CheckBox mOAuth2Check;\r
private String mOAuthAccessToken;\r
private View mOkButton;\r
+ private TextView mAuthStatusLayout;\r
\r
private TextView mOAuthAuthEndpointText;\r
private TextView mOAuthTokenEndpointText;\r
mOAuthTokenEndpointText = (TextView)findViewById(R.id.oAuthEntryPoint_2);\r
mOAuth2Check = (CheckBox) findViewById(R.id.oauth_onOff_check);\r
mOkButton = findViewById(R.id.buttonOK);\r
+ mAuthStatusLayout = (TextView) findViewById(R.id.auth_status_text); \r
+ \r
\r
/// complete label for 'register account' button\r
Button b = (Button) findViewById(R.id.account_register);\r
loadSavedInstanceState(savedInstanceState);\r
}\r
\r
+ if (getIntent().getByteExtra(EXTRA_ACTION, ACTION_CREATE) == ACTION_UPDATE_TOKEN) {\r
+ /// lock things that should not change\r
+ mHostUrlInput.setEnabled(false);\r
+ mUsernameInput.setEnabled(false);\r
+ mOAuth2Check.setVisibility(View.GONE);\r
+ checkOcServer(); \r
+ }\r
+ \r
mPasswordInput.setText(""); // clean password to avoid social hacking (disadvantage: password in removed if the device is turned aside)\r
}\r
\r
mIsSslConn = savedInstanceState.getBoolean(KEY_IS_SSL_CONN);\r
mStatusText = savedInstanceState.getInt(KEY_STATUS_TEXT);\r
mStatusIcon = savedInstanceState.getInt(KEY_STATUS_ICON);\r
- updateOcServerCheckIconAndText();\r
+ updateConnStatus();\r
\r
/// UI settings depending upon connection\r
mOkButton.setEnabled(mStatusCorrect); // TODO really necessary?\r
i++;\r
}\r
\r
- /// Updating status widget to OK.\r
- updateOAuth2IconAndText(R.drawable.ic_ok, R.string.auth_connection_established);\r
+ /// Updating status widget to OK. -- TODO REMOVE, UNNECESSARY\r
+ /*\r
+ mStatusIcon = R.drawable.ic_ok;\r
+ mStatusText = R.string.auth_connection_established;\r
+ updateAuthStatus();\r
+ */\r
\r
/// Showing the dialog with instructions for the user.\r
showDialog(DIALOG_OAUTH2_LOGIN_PROGRESS);\r
*/\r
private void onUrlInputFocusChanged(TextView hostInput, boolean hasFocus) {\r
if (!hasFocus) {\r
- String uri = hostInput.getText().toString().trim();\r
- if (uri.length() != 0) {\r
- mStatusText = R.string.auth_testing_connection;\r
- mStatusIcon = R.drawable.progress_small;\r
- updateOcServerCheckIconAndText();\r
- /** TODO cancel previous connection check if the user tries to ammend a wrong URL \r
- if(mConnChkOperation != null) {\r
- mConnChkOperation.cancel();\r
- } */\r
- mOcServerChkOperation = new OwnCloudServerCheckOperation(uri, this);\r
- WebdavClient client = OwnCloudClientUtils.createOwnCloudClient(Uri.parse(uri), this);\r
- mHostBaseUrl = "";\r
- mDiscoveredVersion = null;\r
- mOperationThread = mOcServerChkOperation.execute(client, this, mHandler);\r
- } else {\r
- mRefreshButton.setVisibility(View.INVISIBLE);\r
- mStatusText = 0;\r
- mStatusIcon = 0;\r
- updateOcServerCheckIconAndText();\r
- }\r
+ checkOcServer();\r
+ \r
} else {\r
// avoids that the 'connect' button can be clicked if the test was previously passed\r
mOkButton.setEnabled(false); \r
}\r
\r
\r
+ private void checkOcServer() {\r
+ String uri = mHostUrlInput.getText().toString().trim();\r
+ if (uri.length() != 0) {\r
+ mStatusText = R.string.auth_testing_connection;\r
+ mStatusIcon = R.drawable.progress_small;\r
+ updateConnStatus();\r
+ /** TODO cancel previous connection check if the user tries to ammend a wrong URL \r
+ if(mConnChkOperation != null) {\r
+ mConnChkOperation.cancel();\r
+ } */\r
+ mOcServerChkOperation = new OwnCloudServerCheckOperation(uri, this);\r
+ WebdavClient client = OwnCloudClientUtils.createOwnCloudClient(Uri.parse(uri), this);\r
+ mHostBaseUrl = "";\r
+ mDiscoveredVersion = null;\r
+ mOperationThread = mOcServerChkOperation.execute(client, this, mHandler);\r
+ } else {\r
+ mRefreshButton.setVisibility(View.INVISIBLE);\r
+ mStatusText = 0;\r
+ mStatusIcon = 0;\r
+ updateConnStatus();\r
+ }\r
+ }\r
+\r
+\r
/**\r
* Handles changes in focus on the text input for the password (basic authorization).\r
* \r
if (mDiscoveredVersion == null || !mDiscoveredVersion.isVersionValid() || mHostBaseUrl == null || mHostBaseUrl.length() == 0) {\r
mStatusIcon = R.drawable.common_error;\r
mStatusText = R.string.auth_wtf_reenter_URL;\r
- updateOcServerCheckIconAndText();\r
+ updateConnStatus();\r
mOkButton.setEnabled(false);\r
Log.wtf(TAG, "The user was allowed to click 'connect' to an unchecked server!!");\r
return;\r
*/\r
private void startOauthorization() {\r
// be gentle with the user\r
- updateOAuth2IconAndText(R.drawable.progress_small, R.string.oauth_login_connection);\r
+ mStatusIcon = R.drawable.progress_small;\r
+ mStatusText = R.string.oauth_login_connection;\r
+ updateAuthStatus();\r
\r
// GET AUTHORIZATION request\r
/*\r
* @param result Result of the check.\r
*/\r
private void onOcServerCheckFinish(OwnCloudServerCheckOperation operation, RemoteOperationResult result) {\r
- /// update status connection icon and text\r
- mStatusText = mStatusIcon = 0;\r
- mStatusCorrect = false;\r
+ /// update status icon and text\r
+ updateStatusIconAndText(result);\r
+ updateConnStatus();\r
+\r
+ /// save result state\r
+ mStatusCorrect = result.isSuccess();\r
+ mIsSslConn = (result.getCode() == ResultCode.OK_SSL);\r
\r
- switch (result.getCode()) {\r
- case OK_SSL:\r
- mIsSslConn = true;\r
- mStatusIcon = android.R.drawable.ic_secure;\r
- mStatusText = R.string.auth_secure_connection;\r
- mStatusCorrect = true;\r
- break;\r
- \r
- case OK_NO_SSL:\r
- case OK:\r
- mIsSslConn = false;\r
- mStatusCorrect = true;\r
- if (mHostUrlInput.getText().toString().trim().toLowerCase().startsWith("http://") ) {\r
- mStatusText = R.string.auth_connection_established;\r
- mStatusIcon = R.drawable.ic_ok;\r
- } else {\r
- mStatusText = R.string.auth_nossl_plain_ok_title;\r
- mStatusIcon = android.R.drawable.ic_partial_secure;\r
- }\r
- break;\r
- \r
- /// very special case (TODO: move to a common place for all the remote operations)\r
- case SSL_RECOVERABLE_PEER_UNVERIFIED:\r
- mStatusIcon = R.drawable.common_error;\r
- mStatusText = R.string.auth_ssl_unverified_server_title;\r
- mLastSslUntrustedServerResult = result;\r
- showDialog(DIALOG_SSL_VALIDATOR); \r
- break;\r
- \r
- case BAD_OC_VERSION:\r
- mStatusIcon = R.drawable.common_error;\r
- mStatusText = R.string.auth_bad_oc_version_title;\r
- break;\r
- case WRONG_CONNECTION:\r
- mStatusIcon = R.drawable.common_error;\r
- mStatusText = R.string.auth_wrong_connection_title;\r
- break;\r
- case TIMEOUT:\r
- mStatusIcon = R.drawable.common_error;\r
- mStatusText = R.string.auth_timeout_title;\r
- break;\r
- case INCORRECT_ADDRESS:\r
- mStatusIcon = R.drawable.common_error;\r
- mStatusText = R.string.auth_incorrect_address_title;\r
- break;\r
- \r
- case SSL_ERROR:\r
- mStatusIcon = R.drawable.common_error;\r
- mStatusText = R.string.auth_ssl_general_error_title;\r
- break;\r
- \r
- case HOST_NOT_AVAILABLE:\r
- mStatusIcon = R.drawable.common_error;\r
- mStatusText = R.string.auth_unknown_host_title;\r
- break;\r
- case NO_NETWORK_CONNECTION:\r
- mStatusIcon = R.drawable.no_network;\r
- mStatusText = R.string.auth_no_net_conn_title;\r
- break;\r
- case INSTANCE_NOT_CONFIGURED:\r
- mStatusIcon = R.drawable.common_error;\r
- mStatusText = R.string.auth_not_configured_title;\r
- break;\r
- case FILE_NOT_FOUND:\r
- mStatusIcon = R.drawable.common_error;\r
- mStatusText = R.string.auth_incorrect_path_title;\r
- break;\r
- case UNHANDLED_HTTP_CODE:\r
- case UNKNOWN_ERROR:\r
- mStatusIcon = R.drawable.common_error;\r
- mStatusText = R.string.auth_unknown_error_title;\r
- break;\r
- default:\r
- Log.e(TAG, "Incorrect connection checker result type: " + result.getHttpCode());\r
+ /// very special case (TODO: move to a common place for all the remote operations)\r
+ if (result.getCode() == ResultCode.SSL_RECOVERABLE_PEER_UNVERIFIED) {\r
+ mLastSslUntrustedServerResult = result;\r
+ showDialog(DIALOG_SSL_VALIDATOR); \r
}\r
- updateOcServerCheckIconAndText();\r
\r
/// update the visibility of the 'retry connection' button\r
if (!mStatusCorrect)\r
\r
\r
/**\r
+ * Chooses the right icon and text to show to the user for the received operation result.\r
+ * \r
+ * @param result Result of a remote operation performed in this activity\r
+ */\r
+ private void updateStatusIconAndText(RemoteOperationResult result) {\r
+ mStatusText = mStatusIcon = 0;\r
+\r
+ switch (result.getCode()) {\r
+ case OK_SSL:\r
+ mStatusIcon = android.R.drawable.ic_secure;\r
+ mStatusText = R.string.auth_secure_connection;\r
+ break;\r
+ \r
+ case OK_NO_SSL:\r
+ case OK:\r
+ if (mHostUrlInput.getText().toString().trim().toLowerCase().startsWith("http://") ) {\r
+ mStatusText = R.string.auth_connection_established;\r
+ mStatusIcon = R.drawable.ic_ok;\r
+ } else {\r
+ mStatusText = R.string.auth_nossl_plain_ok_title;\r
+ mStatusIcon = android.R.drawable.ic_partial_secure;\r
+ }\r
+ break;\r
+ \r
+ case SSL_RECOVERABLE_PEER_UNVERIFIED:\r
+ mStatusIcon = R.drawable.common_error;\r
+ mStatusText = R.string.auth_ssl_unverified_server_title;\r
+ break;\r
+ \r
+ case BAD_OC_VERSION:\r
+ mStatusIcon = R.drawable.common_error;\r
+ mStatusText = R.string.auth_bad_oc_version_title;\r
+ break;\r
+ case WRONG_CONNECTION:\r
+ mStatusIcon = R.drawable.common_error;\r
+ mStatusText = R.string.auth_wrong_connection_title;\r
+ break;\r
+ case TIMEOUT:\r
+ mStatusIcon = R.drawable.common_error;\r
+ mStatusText = R.string.auth_timeout_title;\r
+ break;\r
+ case INCORRECT_ADDRESS:\r
+ mStatusIcon = R.drawable.common_error;\r
+ mStatusText = R.string.auth_incorrect_address_title;\r
+ break;\r
+ \r
+ case SSL_ERROR:\r
+ mStatusIcon = R.drawable.common_error;\r
+ mStatusText = R.string.auth_ssl_general_error_title;\r
+ break;\r
+ \r
+ case UNAUTHORIZED:\r
+ mStatusIcon = R.drawable.common_error;\r
+ mStatusText = R.string.auth_unauthorized;\r
+ break;\r
+ case HOST_NOT_AVAILABLE:\r
+ mStatusIcon = R.drawable.common_error;\r
+ mStatusText = R.string.auth_unknown_host_title;\r
+ break;\r
+ case NO_NETWORK_CONNECTION:\r
+ mStatusIcon = R.drawable.no_network;\r
+ mStatusText = R.string.auth_no_net_conn_title;\r
+ break;\r
+ case INSTANCE_NOT_CONFIGURED:\r
+ mStatusIcon = R.drawable.common_error;\r
+ mStatusText = R.string.auth_not_configured_title;\r
+ break;\r
+ case FILE_NOT_FOUND:\r
+ mStatusIcon = R.drawable.common_error;\r
+ mStatusText = R.string.auth_incorrect_path_title;\r
+ break;\r
+ case OAUTH2_ERROR:\r
+ mStatusIcon = R.drawable.common_error;\r
+ mStatusText = R.string.auth_bad_oauth_token;\r
+ break;\r
+ case UNHANDLED_HTTP_CODE:\r
+ case UNKNOWN_ERROR:\r
+ mStatusIcon = R.drawable.common_error;\r
+ mStatusText = R.string.auth_unknown_error_title;\r
+ break;\r
+ \r
+ default:\r
+ break;\r
+ }\r
+ }\r
+\r
+\r
+ /**\r
* Processes the result of the request for and access token send \r
* to an OAuth authorization server.\r
* \r
// NOTHING TO DO ; can't find out what situation that leads to the exception in this code, but user logs signal that it happens\r
}\r
\r
- String webdav_path = AccountUtils.getWebdavPath(mDiscoveredVersion, false);\r
+ String webdav_path = AccountUtils.getWebdavPath(mDiscoveredVersion, true);\r
if (result.isSuccess() && webdav_path != null) {\r
/// be gentle with the user\r
showDialog(DIALOG_LOGIN_PROGRESS);\r
finish();\r
\r
} else {\r
+ /*\r
if (!isOAuth) {\r
mUsernameInput.setError(result.getLogMessage() + " "); \r
// the extra spaces are a workaround for an ugly bug: \r
\r
} else {\r
mOAuthAuthEndpointText.setError(result.getLogMessage() + " ");\r
- }\r
+ }*/\r
+ updateStatusIconAndText(result);\r
+ updateAuthStatus();\r
Log.d(TAG, "Access failed: " + result.getLogMessage());\r
}\r
}\r
* Updates the content and visibility state of the icon and text associated\r
* to the last check on the ownCloud server.\r
*/\r
- private void updateOcServerCheckIconAndText() {\r
+ private void updateConnStatus() {\r
ImageView iv = (ImageView) findViewById(R.id.action_indicator);\r
TextView tv = (TextView) findViewById(R.id.status_text);\r
\r
tv.setVisibility(View.VISIBLE);\r
}\r
}\r
+ \r
+ \r
+ /**\r
+ * Updates the content and visibility state of the icon and text associated\r
+ * to the interactions with the OAuth authorization server.\r
+ */\r
+ private void updateAuthStatus() {\r
+ /*ImageView iv = (ImageView) findViewById(R.id.auth_status_icon);\r
+ TextView tv = (TextView) findViewById(R.id.auth_status_text);*/\r
+\r
+ if (mStatusIcon == 0 && mStatusText == 0) {\r
+ mAuthStatusLayout.setVisibility(View.INVISIBLE);\r
+ /*iv.setVisibility(View.INVISIBLE);\r
+ tv.setVisibility(View.INVISIBLE);*/\r
+ } else {\r
+ mAuthStatusLayout.setText(mStatusText);\r
+ mAuthStatusLayout.setCompoundDrawablesWithIntrinsicBounds(mStatusIcon, 0, 0, 0);\r
+ /*iv.setImageResource(mStatusIcon);\r
+ tv.setText(mStatusText);\r
+ /*iv.setVisibility(View.VISIBLE);\r
+ tv.setVisibility(View.VISIBLE);^*/\r
+ mAuthStatusLayout.setVisibility(View.VISIBLE);\r
+ }\r
+ } \r
\r
\r
/**\r
*/\r
public void changeViewByOAuth2Check(Boolean checked) {\r
\r
- ImageView auth2ActionIndicator = (ImageView) findViewById(R.id.auth2_action_indicator); \r
- TextView oauth2StatusText = (TextView) findViewById(R.id.oauth2_status_text); \r
-\r
if (checked) {\r
mOAuthAuthEndpointText.setVisibility(View.VISIBLE);\r
mOAuthTokenEndpointText.setVisibility(View.VISIBLE);\r
mUsernameInput.setVisibility(View.GONE);\r
mPasswordInput.setVisibility(View.GONE);\r
mViewPasswordButton.setVisibility(View.GONE);\r
- auth2ActionIndicator.setVisibility(View.INVISIBLE);\r
- oauth2StatusText.setVisibility(View.INVISIBLE);\r
} else {\r
mOAuthAuthEndpointText.setVisibility(View.GONE);\r
mOAuthTokenEndpointText.setVisibility(View.GONE);\r
mUsernameInput.setVisibility(View.VISIBLE);\r
mPasswordInput.setVisibility(View.VISIBLE);\r
mViewPasswordButton.setVisibility(View.INVISIBLE);\r
- auth2ActionIndicator.setVisibility(View.GONE);\r
- oauth2StatusText.setVisibility(View.GONE);\r
} \r
\r
} \r
\r
- /**\r
- * Updates the content and visibility state of the icon and text associated\r
- * to the interactions with the OAuth authorization server.\r
- * \r
- * @param drawable_id Resource id for the icon.\r
- * @param text_id Resource id for the text.\r
- */\r
- private void updateOAuth2IconAndText(int drawable_id, int text_id) {\r
- ImageView iv = (ImageView) findViewById(R.id.auth2_action_indicator);\r
- TextView tv = (TextView) findViewById(R.id.oauth2_status_text);\r
-\r
- if (drawable_id == 0 && text_id == 0) {\r
- iv.setVisibility(View.INVISIBLE);\r
- tv.setVisibility(View.INVISIBLE);\r
- } else {\r
- iv.setImageResource(drawable_id);\r
- tv.setText(text_id);\r
- iv.setVisibility(View.VISIBLE);\r
- tv.setVisibility(View.VISIBLE);\r
- }\r
- } \r
- \r
/* Leave the old OAuth flow\r
// Results from the first call to oAuth2 server : getting the user_code and verification_url.\r
@Override\r