import java.net.MalformedURLException;\r
import java.net.URL;\r
\r
+import com.actionbarsherlock.ActionBarSherlock;\r
+\r
import android.accounts.Account;\r
import android.accounts.AccountAuthenticatorActivity;\r
import android.accounts.AccountManager;\r
import android.content.ContentResolver;\r
import android.content.DialogInterface;\r
import android.content.Intent;\r
+import android.content.SharedPreferences;\r
import android.graphics.Color;\r
import android.os.Bundle;\r
import android.os.Handler;\r
+import android.preference.PreferenceManager;\r
+import android.text.InputType;\r
import android.util.Log;\r
import android.view.View;\r
import android.view.Window;\r
+import android.widget.CheckBox;\r
import android.widget.TextView;\r
import android.widget.Toast;\r
import eu.alefzero.owncloud.R;\r
public class AuthenticatorActivity extends AccountAuthenticatorActivity {\r
private Thread mAuthThread;\r
private final Handler mHandler = new Handler();\r
+ private boolean mUseSSLConnection;\r
\r
public static final String PARAM_USERNAME = "param_Username";\r
public static final String PARAM_HOSTNAME = "param_Hostname";\r
\r
+ public AuthenticatorActivity() {\r
+ mUseSSLConnection = true;\r
+ }\r
+ \r
@Override\r
protected void onCreate(Bundle savedInstanceState) {\r
super.onCreate(savedInstanceState);\r
try {\r
url = new URL(message);\r
} catch (MalformedURLException e) {\r
- // should never happend\r
+ // should never happen\r
Log.e(getClass().getName(), "Malformed URL: " + message);\r
return;\r
}\r
\r
String username = username_text.getText().toString().trim();\r
- Account account = new Account(username + "@" + url.getHost(), AccountAuthenticator.ACCOUNT_TYPE);\r
+ String accountName = username + "@" + url.getHost();\r
+ Account account = new Account(accountName, AccountAuthenticator.ACCOUNT_TYPE);\r
AccountManager accManager = AccountManager.get(this);\r
accManager.addAccountExplicitly(account, password_text.getText().toString(), null);\r
+ \r
+ // Add this account as default in the preferences, if there is none already\r
+ Account defaultAccount = AuthUtils.getCurrentOwnCloudAccount(this);\r
+ if(defaultAccount == null){\r
+ SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(this).edit();\r
+ editor.putString("select_oc_account", accountName);\r
+ editor.commit();\r
+ }\r
\r
final Intent intent = new Intent();\r
intent.putExtra(AccountManager.KEY_ACCOUNT_TYPE, AccountAuthenticator.ACCOUNT_TYPE);\r
intent.putExtra(AccountManager.KEY_AUTHTOKEN, AccountAuthenticator.ACCOUNT_TYPE);\r
accManager.setUserData(account, AccountAuthenticator.KEY_OC_URL, url.toString());\r
\r
- // TODO prepare this URL during a central service\r
+ // TODO prepare this URL using a central service\r
intent.putExtra(AccountManager.KEY_USERDATA, username);\r
accManager.setUserData(account, AccountAuthenticator.KEY_CONTACT_URL,\r
url.toString().replace(AuthUtils.WEBDAV_PATH_2_0, AuthUtils.CARDDAV_PATH_2_0)\r
url_text.setTextColor(Color.RED);\r
hasErrors = true;\r
} else {\r
- url_text.setTextColor(Color.BLACK);\r
+ url_text.setTextColor(android.R.color.black);\r
}\r
try {\r
String url_str = url_text.getText().toString();\r
if (!url_str.startsWith("http://") &&\r
!url_str.startsWith("https://")) {\r
+ if (mUseSSLConnection)\r
+ url_str = "https://" + url_str;\r
+ else\r
url_str = "http://" + url_str;\r
}\r
uri = new URL(url_str);\r
username_text.setTextColor(Color.RED);\r
hasErrors = true;\r
} else {\r
- username_text.setTextColor(Color.BLACK);\r
+ username_text.setTextColor(android.R.color.black);\r
}\r
\r
if (password_text.getText().toString().trim().length() == 0) {\r
password_text.setTextColor(Color.RED);\r
hasErrors = true;\r
} else {\r
- password_text.setTextColor(Color.BLACK);\r
+ password_text.setTextColor(android.R.color.black);\r
}\r
if (hasErrors) {\r
return;\r
}\r
+ \r
+ int new_port = uri.getPort();\r
+ if (new_port == -1) {\r
+ if (mUseSSLConnection)\r
+ new_port = 443;\r
+ else\r
+ new_port = 80;\r
+ }\r
+ \r
+ try {\r
+ uri = new URL(uri.getProtocol(), uri.getHost(), new_port, uri.getPath());\r
+ } catch (MalformedURLException e) {\r
+ e.printStackTrace(); // should not happend\r
+ }\r
+ \r
showDialog(0);\r
mAuthThread = AuthUtils.attemptAuth(uri,\r
username_text.getText().toString(),\r
mHandler,\r
AuthenticatorActivity.this);\r
}\r
+ \r
+ public void sslBadgeClick(View view, String val) {\r
+ mUseSSLConnection = ((TextView)view).getText().equals("SSL");\r
+ }\r
+ \r
+ public void passwordBadgeClick(View view, String val) {\r
+ if(val.equals("Hide")) {\r
+ ((TextView)view).setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);\r
+ } else {\r
+ ((TextView)view).setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);\r
+ }\r
+ }\r
}\r