Ensure, that user switching back using the task switcher also must have
[pub/Android/ownCloud.git] / src / eu / alefzero / owncloud / ui / activity / AuthenticatorActivity.java
index 79781f3..9db46e0 100644 (file)
@@ -29,12 +29,16 @@ import android.app.ProgressDialog;
 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
@@ -96,15 +100,25 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity {
             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
+            SharedPreferences appPreferences = PreferenceManager.getDefaultSharedPreferences(this);\r
+            String defaultAccountName = appPreferences.getString("select_oc_account", null);\r
+            if(defaultAccountName == null){\r
+               SharedPreferences.Editor editor = appPreferences.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
@@ -112,7 +126,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity {
             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
@@ -188,4 +202,21 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity {
                 mHandler,\r
                 AuthenticatorActivity.this);\r
     }\r
+    \r
+    /**\r
+     * Handles the show password checkbox\r
+     * @author robstar\r
+     * @param view\r
+     */\r
+    public void onCheckboxClick(View view) {\r
+       CheckBox checkbox = (CheckBox) findViewById(R.id.show_password);\r
+       TextView password_text = (TextView) findViewById(R.id.account_password);\r
+       \r
+       if(checkbox.isChecked()) {\r
+               password_text.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);\r
+       } else {\r
+               password_text.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);\r
+       }\r
+       \r
+    }\r
 }\r