Started working on the "Where is my device?" feature
[pub/Android/ownCloud.git] / src / eu / alefzero / owncloud / ui / activity / AuthenticatorActivity.java
index 9db46e0..b6c9dda 100644 (file)
@@ -54,10 +54,15 @@ import eu.alefzero.owncloud.db.ProviderMeta.ProviderTableMeta;
 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 = false;\r
+    }\r
+    \r
     @Override\r
     protected void onCreate(Bundle savedInstanceState) {\r
         super.onCreate(savedInstanceState);\r
@@ -112,10 +117,9 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity {
             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
+            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
@@ -163,12 +167,15 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity {
             url_text.setTextColor(Color.RED);\r
             hasErrors = true;\r
         } else {\r
-            url_text.setTextColor(Color.BLACK);\r
+            url_text.setTextColor(android.R.color.primary_text_light);\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
@@ -183,18 +190,33 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity {
             username_text.setTextColor(Color.RED);\r
             hasErrors = true;\r
         } else {\r
-            username_text.setTextColor(Color.BLACK);\r
+            username_text.setTextColor(android.R.color.primary_text_light);\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.primary_text_light);\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
@@ -206,17 +228,26 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity {
     /**\r
      * Handles the show password checkbox\r
      * @author robstar\r
+     * @author aqu\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
+      switch (view.getId()) {\r
+        case R.id.show_password:\r
+          TextView password_text = (TextView) findViewById(R.id.account_password);\r
+          \r
+          if(((CheckBox)view).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
+        break;\r
+        case R.id.use_ssl:\r
+          mUseSSLConnection = ((CheckBox)view).isChecked();\r
+        break;\r
+        default:\r
+          Log.d("AuthActivity", "Clicked invalid view with id: " + view.getId());\r
+      }\r
        \r
     }\r
 }\r