Refactoring: Added comments to every class, as well as a copyright
[pub/Android/ownCloud.git] / src / eu / alefzero / owncloud / ui / activity / LandingActivity.java
diff --git a/src/eu/alefzero/owncloud/ui/activity/LandingActivity.java b/src/eu/alefzero/owncloud/ui/activity/LandingActivity.java
new file mode 100644 (file)
index 0000000..b8f1878
--- /dev/null
@@ -0,0 +1,104 @@
+/* ownCloud Android client application\r
+ *   Copyright (C) 2011 Bartek Przybylski\r
+ *\r
+ *   This program is free software: you can redistribute it and/or modify\r
+ *   it under the terms of the GNU General Public License as published by\r
+ *   the Free Software Foundation, either version 3 of the License, or\r
+ *   (at your option) any later version.\r
+ *\r
+ *   This program is distributed in the hope that it will be useful,\r
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ *   GNU General Public License for more details.\r
+ *\r
+ *   You should have received a copy of the GNU General Public License\r
+ *   along with this program.  If not, see <http://www.gnu.org/licenses/>.\r
+ *\r
+ */\r
+package eu.alefzero.owncloud.ui.activity;\r
+\r
+import android.accounts.Account;\r
+import android.accounts.AccountManager;\r
+import android.app.AlertDialog;\r
+import android.app.Dialog;\r
+import android.content.DialogInterface;\r
+import android.content.Intent;\r
+import android.content.DialogInterface.OnClickListener;\r
+import android.os.Bundle;\r
+import android.support.v4.app.FragmentActivity;\r
+import eu.alefzero.owncloud.R;\r
+import eu.alefzero.owncloud.authenticator.AccountAuthenticator;\r
+\r
+/**\r
+ * This activity is used as a landing page when the user first opens this app.\r
+ * @author Lennart Rosam\r
+ * \r
+ */\r
+public class LandingActivity extends FragmentActivity implements OnClickListener {\r
+\r
+       public static final int DIALOG_SETUP_ACCOUNT = 1;\r
+       \r
+       @Override\r
+       protected void onCreate(Bundle savedInstanceState) {\r
+               super.onCreate(savedInstanceState);\r
+               setContentView(R.layout.main);\r
+               \r
+               // Check, if there are ownCloud accounts\r
+               if(!accountsAreSetup()){\r
+                       showDialog(DIALOG_SETUP_ACCOUNT);\r
+               }\r
+\r
+       }\r
+\r
+       @Override\r
+       protected Dialog onCreateDialog(int id) {\r
+               Dialog dialog;\r
+               switch(id){\r
+               case DIALOG_SETUP_ACCOUNT:\r
+                       AlertDialog.Builder builder = new AlertDialog.Builder(this);\r
+                       builder.setTitle(R.string.main_tit_accsetup);\r
+                       builder.setMessage(R.string.main_wrn_accsetup);\r
+                       builder.setCancelable(false);\r
+                       builder.setPositiveButton(R.string.common_ok, this);\r
+                       builder.setNegativeButton(R.string.common_cancel, this);\r
+                       dialog = builder.create();\r
+                       break;\r
+               default: \r
+                       dialog = null;\r
+               }\r
+                       \r
+               return dialog;\r
+       }\r
+\r
+       @Override\r
+       public void onClick(DialogInterface dialog, int which) {\r
+               // In any case - we won't need it anymore\r
+               dialog.dismiss();\r
+               switch(which){\r
+               case DialogInterface.BUTTON_POSITIVE:\r
+                       Intent intent = new Intent("android.settings.ADD_ACCOUNT_SETTINGS");\r
+                       intent.putExtra("authorities",\r
+                                       new String[] { AccountAuthenticator.AUTH_TOKEN_TYPE });\r
+                       startActivity(intent);\r
+                       break;\r
+               case DialogInterface.BUTTON_NEGATIVE:\r
+                       finish();\r
+               }\r
+               \r
+       }\r
+       \r
+       /**\r
+        * Checks, whether or not there are any ownCloud accounts \r
+        * setup. \r
+        *  \r
+        * @return true, if there is at least one account.\r
+        */\r
+       private boolean accountsAreSetup() {\r
+               AccountManager accMan = AccountManager.get(this);\r
+               Account[] accounts = accMan\r
+                               .getAccountsByType(AccountAuthenticator.ACCOUNT_TYPE); \r
+               return accounts.length > 0;\r
+       }\r
+       \r
+\r
+}\r